public void PopulateFields(SAV1 s) { sav = s; L_Save.Text = "SAV: " + Path.GetFileNameWithoutExtension(sav.FileName); // more descriptive CB_BoxSelect.SelectedIndex = sav.Current_Box_Index; PLC_Party.SetList(sav.Party); PLC_DayCare.SetList(sav.Daycare); getBox(null, null); TB_SaveName.Text = sav.OT_Name; TB_Rival.Text = sav.Rival_Name; for (int i = 0; i < CLB_Badges.Items.Count; i++) { CLB_Badges.SetItemChecked(i, sav.Badges[i]); } changingFields = true; MT_Hours.Text = sav.Time_Played[0].ToString(); MT_Minutes.Text = sav.Time_Played[1].ToString(); MT_Seconds.Text = sav.Time_Played[2].ToString(); changingFields = false; TB_Money.Text = sav.Money; TB_Coins.Text = sav.Coins; TB_SaveTID.Text = sav.TID.ToString("00000"); TB_PikaFriend.Text = sav.Pika_Friendship.ToString("000"); }
private void openFile(byte[] input, string path, string ext) { // Fix case sensitivity with extensions ext = ext.ToLower(); #region PK1 if (input.Length == PokemonList.GetDataLength(PokemonList.CapacityType.Single)) { if (new[] { ".pk1", "" }.Contains(ext) && input[0] == 1 && input[2] == 0xFF && input[1] == input[3]) { if (!saveLoaded && JP_Mode) { JP_Mode = false; pk1_wrapper = new PokemonList(PokemonList.CapacityType.Single, JP_Mode); } if (!JP_Mode) { PopulateFields(new PokemonList(input)[0]); } else { Util.Error("Cannot open a PK1 with a JP save open."); } } else { Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .pk1/.bin supported.", string.Format($"File Loaded:{Environment.NewLine}{path}")); } } else if (input.Length == PokemonList.GetDataLength(PokemonList.CapacityType.Single, true)) { if (new[] { ".jpk1", "" }.Contains(ext) && input[0] == 1 && input[2] == 0xFF && input[1] == input[3]) { if (!saveLoaded && !JP_Mode) { JP_Mode = true; pk1_wrapper = new PokemonList(PokemonList.CapacityType.Single, JP_Mode); } if (JP_Mode) { PopulateFields(new PokemonList(input, PokemonList.CapacityType.Single, true)[0]); } else { Util.Error("Cannot open a JPK1 with a non-JP save open."); } } else { Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .jpk1/.bin supported.", string.Format($"File Loaded:{Environment.NewLine}{path}")); } } else if (input.Length == 0x8000 || input.Length == 0x802C) { if (ext != ".dat" && ext != ".sav") { Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .sav/.dat supported.", string.Format($"File Loaded:{Environment.NewLine}{path}")); } if (input.Length == 0x802C) // Support Emulator saves { Array.Resize(ref input, 0x8000); } saveLoaded = Menu_ExportSAV.Enabled = false; B_Apply.Enabled = false; Menu_JapaneseMode.Enabled = true; foreach (TabPage tp in tabBoxMulti.TabPages) { tp.Enabled = false; } if (SAV1.IsAmerican(input)) { if (JP_Mode) { JP_Mode = false; pk1_wrapper = new PokemonList(PokemonList.CapacityType.Single, JP_Mode); InitializeFields(); } CB_BoxSelect.Items.Clear(); CB_BoxSelect.Items.AddRange(Enumerable.Range(1, 12).Select(d => string.Format("Box {0}", d)).ToArray()); PopulateFields(new USAV1(input) { FilePath = Path.GetDirectoryName(path), FileName = Path.GetFileName(path) }); SetStringLengths(); } else if (SAV1.IsJapanese(input)) { if (!JP_Mode) { JP_Mode = true; pk1_wrapper = new PokemonList(PokemonList.CapacityType.Single, JP_Mode); InitializeFields(); } CB_BoxSelect.Items.Clear(); CB_BoxSelect.Items.AddRange(Enumerable.Range(1, 8).Select(d => string.Format("Box {0}", d)).ToArray()); PopulateFields(new JSAV1(input) { FilePath = Path.GetDirectoryName(path), FileName = Path.GetFileName(path) }); SetStringLengths(); } else { Util.Error("Unable to recognize file." + Environment.NewLine + "Save file may be corrupted."); return; } foreach (TabPage tp in tabBoxMulti.TabPages) { tp.Enabled = true; } saveLoaded = Menu_ExportSAV.Enabled = true; B_Apply.Enabled = true; Menu_JapaneseMode.Enabled = false; // Indicate audibly the save is loaded SystemSounds.Beep.Play(); } else { { Util.Error("Unable to recognize file.", string.Format($"File Loaded:{Environment.NewLine}{path}")); } } #endregion }