From cf5a21aff156810722823dc309d80226fa66a104 Mon Sep 17 00:00:00 2001 From: AdAstra-LD <76622070+AdAstra-LD@users.noreply.github.com> Date: Thu, 9 Dec 2021 19:11:10 +0100 Subject: [PATCH 1/2] Table Editor can now read entries from the synthOverlay --- DS_Map/DSUtils.cs | 33 +++++++++-------- DS_Map/Main Window.cs | 56 +++++++++++++++++++++-------- DS_Map/ROMToolboxDialog.Designer.cs | 17 +++++---- DS_Map/ROMToolboxDialog.cs | 13 +++---- DS_Map/RomInfo.cs | 1 + 5 files changed, 77 insertions(+), 43 deletions(-) diff --git a/DS_Map/DSUtils.cs b/DS_Map/DSUtils.cs index 8cf7b3d..f0de2e4 100644 --- a/DS_Map/DSUtils.cs +++ b/DS_Map/DSUtils.cs @@ -13,6 +13,17 @@ using static DSPRE.RomInfo; namespace DSPRE { public static class DSUtils { public static class ARM9 { + public static uint address = 0x02000000; + public class Reader : BinaryReader { + public Reader(long pos = 0) : base(File.OpenRead(arm9Path)) { + this.BaseStream.Position = pos; + } + } + public class Writer : BinaryWriter { + public Writer(long pos = 0) : base(File.OpenWrite(arm9Path)) { + this.BaseStream.Position = pos; + } + } public static bool Decompress(string path) { Process decompress = new Process(); decompress.StartInfo.FileName = @"Tools\blz.exe"; @@ -56,23 +67,17 @@ namespace DSPRE { public static void WriteByte(byte value, uint destOffset) { WriteToFile(RomInfo.arm9Path, BitConverter.GetBytes(value), destOffset, 0); } + } - - public class Reader : BinaryReader { - public Reader(string path, long pos = 0) : base(File.OpenRead(path)) { - this.BaseStream.Position = pos; - } - public Reader(long pos = 0) : this(arm9Path, pos) { - } + public class EasyReader : BinaryReader { + public EasyReader(string path, long pos = 0) : base(File.OpenRead(path)) { + this.BaseStream.Position = pos; } - public class Writer : BinaryWriter { - public Writer(string path, long pos = 0) : base(File.OpenWrite(path)) { - this.BaseStream.Position = pos; - } - public Writer(long pos = 0) : this(arm9Path, pos) { - } + } + public class EasyWriter : BinaryWriter { + public EasyWriter(string path, long pos = 0) : base(File.OpenWrite(path)) { + this.BaseStream.Position = pos; } - } public const int NSBMD_DOESNTHAVE_TEXTURE = 0; diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index ca109d6..10be85b 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -8255,10 +8255,18 @@ namespace DSPRE { vsPokemonEffectsList = new List<(int pokemonID, int comboID)>(); effectsComboTable = new List<(ushort vsGraph, ushort battleSSEQ)>(); - vsTrainerTableStartAddress = BitConverter.ToUInt32(DSUtils.ARM9.ReadBytes(RomInfo.vsTrainerEntryTableOffsetToRAMAddress, 4), 0) - 0x02000000; - vsPokemonTableStartAddress = BitConverter.ToUInt32(DSUtils.ARM9.ReadBytes(RomInfo.vsPokemonEntryTableOffsetToRAMAddress, 4), 0) - 0x02000000; - effectsComboMainTableStartAddress = BitConverter.ToUInt32(DSUtils.ARM9.ReadBytes(RomInfo.effectsComboTableOffsetToRAMAddress, 4), 0) - 0x02000000; - + vsTrainerTableStartAddress = BitConverter.ToUInt32(DSUtils.ARM9.ReadBytes(RomInfo.vsTrainerEntryTableOffsetToRAMAddress, 4), 0); + ROMToolboxDialog.flag_TrainerClassBattleTableRepointed = (vsTrainerTableStartAddress >= ROMToolboxDialog.synthOverlayLoadAddress); + vsTrainerTableStartAddress -= ROMToolboxDialog.flag_TrainerClassBattleTableRepointed ? ROMToolboxDialog.synthOverlayLoadAddress : DSUtils.ARM9.address; + + vsPokemonTableStartAddress = BitConverter.ToUInt32(DSUtils.ARM9.ReadBytes(RomInfo.vsPokemonEntryTableOffsetToRAMAddress, 4), 0); + ROMToolboxDialog.flag_PokemonBattleTableRepointed = (vsPokemonTableStartAddress >= ROMToolboxDialog.synthOverlayLoadAddress); + vsPokemonTableStartAddress -= ROMToolboxDialog.flag_PokemonBattleTableRepointed ? ROMToolboxDialog.synthOverlayLoadAddress : DSUtils.ARM9.address; + + effectsComboMainTableStartAddress = BitConverter.ToUInt32(DSUtils.ARM9.ReadBytes(RomInfo.effectsComboTableOffsetToRAMAddress, 4), 0); + ROMToolboxDialog.flag_MainComboTableRepointed = (effectsComboMainTableStartAddress >= ROMToolboxDialog.synthOverlayLoadAddress); + effectsComboMainTableStartAddress -= ROMToolboxDialog.flag_MainComboTableRepointed ? ROMToolboxDialog.synthOverlayLoadAddress : DSUtils.ARM9.address; + byte trainerTableEntriesCount = DSUtils.ARM9.ReadByte(RomInfo.vsTrainerEntryTableOffsetToSizeLimiter); byte pokemonTableEntriesCount = DSUtils.ARM9.ReadByte(RomInfo.vsPokemonEntryTableOffsetToSizeLimiter); byte comboTableEntriesCount = DSUtils.ARM9.ReadByte(RomInfo.effectsComboTableOffsetToSizeLimiter); @@ -8278,26 +8286,37 @@ namespace DSPRE { pbEffectsVsTrainerListbox.Items.Clear(); pbEffectsVsPokemonListbox.Items.Clear(); pbEffectsCombosListbox.Items.Clear(); - using (DSUtils.ARM9.Reader ar = new DSUtils.ARM9.Reader(vsTrainerTableStartAddress) ) { - for (int i = 0; i < trainerTableEntriesCount; i++) { + String expArmPath = RomInfo.gameDirs[DirNames.synthOverlay].unpackedDir + '\\' + ROMToolboxDialog.expandedARMfileID.ToString("D4"); + + using(DSUtils.EasyReader ar = new DSUtils.EasyReader(ROMToolboxDialog.flag_TrainerClassBattleTableRepointed ? expArmPath : RomInfo.arm9Path, vsTrainerTableStartAddress)) { + for (int i = 0; i < trainerTableEntriesCount; i++) { ushort entry = ar.ReadUInt16(); int classID = entry & 1023; int comboID = entry >> 10; vsTrainerEffectsList.Add((classID, comboID)); pbEffectsVsTrainerListbox.Items.Add("[" + classID.ToString("D3") + "]" + " " + trcNames[classID] + " uses Combo #" + comboID); } + } - ar.BaseStream.Position = vsPokemonTableStartAddress; + using (DSUtils.EasyReader ar = new DSUtils.EasyReader(ROMToolboxDialog.flag_PokemonBattleTableRepointed ? expArmPath : RomInfo.arm9Path, vsPokemonTableStartAddress)) { for (int i = 0; i < pokemonTableEntriesCount; i++) { ushort entry = ar.ReadUInt16(); int pokeID = entry & 1023; int comboID = entry >> 10; vsPokemonEffectsList.Add((pokeID, comboID)); - pbEffectsVsPokemonListbox.Items.Add("[" + pokeID.ToString("D3") + "]" + " " + pokeNames[pokeID] + " uses Combo #" + comboID); - } - ar.BaseStream.Position = effectsComboMainTableStartAddress; + string pokeName; + try { + pokeName = pokeNames[pokeID]; + } catch (IndexOutOfRangeException) { + pokeName = "UNKNOWN_" + pokeID.ToString("D3"); + } + pbEffectsVsPokemonListbox.Items.Add("[" + pokeID.ToString("D3") + "]" + " " + pokeName + " uses Combo #" + comboID); + } + } + + using (DSUtils.EasyReader ar = new DSUtils.EasyReader(ROMToolboxDialog.flag_MainComboTableRepointed ? expArmPath : RomInfo.arm9Path, effectsComboMainTableStartAddress)) { for (int i = 0; i < comboTableEntriesCount; i++) { ushort battleIntroEffect = ar.ReadUInt16(); ushort battleMusic = ar.ReadUInt16(); @@ -8399,7 +8418,8 @@ namespace DSPRE { effectsComboTable[index] = (battleIntroEffect, battleMusic); - using (DSUtils.ARM9.Writer wr = new DSUtils.ARM9.Writer(effectsComboMainTableStartAddress + 4 * index)) { + String expArmPath = RomInfo.gameDirs[DirNames.synthOverlay].unpackedDir + '\\' + ROMToolboxDialog.expandedARMfileID.ToString("D4"); + using (DSUtils.EasyWriter wr = new DSUtils.EasyWriter(ROMToolboxDialog.flag_MainComboTableRepointed ? expArmPath : RomInfo.arm9Path, effectsComboMainTableStartAddress + 4 * index)) { wr.Write(battleIntroEffect); wr.Write(battleMusic); }; @@ -8415,7 +8435,9 @@ namespace DSPRE { ushort comboID = (ushort)pbEffectsPokemonChooseMainCombobox.SelectedIndex; vsPokemonEffectsList[index] = (pokemonID, comboID); - using (DSUtils.ARM9.Writer wr = new DSUtils.ARM9.Writer(vsPokemonTableStartAddress + 2 * index)) { + + String expArmPath = RomInfo.gameDirs[DirNames.synthOverlay].unpackedDir + '\\' + ROMToolboxDialog.expandedARMfileID.ToString("D4"); + using (DSUtils.EasyWriter wr = new DSUtils.EasyWriter(ROMToolboxDialog.flag_PokemonBattleTableRepointed ? expArmPath : RomInfo.arm9Path, vsPokemonTableStartAddress + 2 * index)) { wr.Write((ushort)((pokemonID & 1023) + (comboID << 10))); //PokemonID }; @@ -8430,7 +8452,8 @@ namespace DSPRE { ushort comboID = (ushort)pbEffectsTrainerChooseMainCombobox.SelectedIndex; vsTrainerEffectsList[index] = (trainerClass, comboID); - using (DSUtils.ARM9.Writer wr = new DSUtils.ARM9.Writer(vsTrainerTableStartAddress + 2 * index)) { + String expArmPath = RomInfo.gameDirs[DirNames.synthOverlay].unpackedDir + '\\' + ROMToolboxDialog.expandedARMfileID.ToString("D4"); + using (DSUtils.EasyWriter wr = new DSUtils.EasyWriter(ROMToolboxDialog.flag_TrainerClassBattleTableRepointed ? expArmPath : RomInfo.arm9Path, vsTrainerTableStartAddress + 2 * index)) { wr.Write((ushort)((trainerClass & 1023) + (comboID << 10))); }; @@ -8470,7 +8493,12 @@ namespace DSPRE { return; } (int pokemonID, int comboID) entry = vsPokemonEffectsList[pbEffectsVsPokemonListbox.SelectedIndex]; - pbEffectsPokemonCombobox.SelectedIndex = entry.pokemonID; + + try { + pbEffectsPokemonCombobox.SelectedIndex = entry.pokemonID; + } catch (ArgumentOutOfRangeException) { + pbEffectsPokemonCombobox.SelectedIndex = 0; + } pbEffectsCombosListbox.SelectedIndex = pbEffectsPokemonChooseMainCombobox.SelectedIndex = entry.comboID; } diff --git a/DS_Map/ROMToolboxDialog.Designer.cs b/DS_Map/ROMToolboxDialog.Designer.cs index e588e1f..6bd0167 100644 --- a/DS_Map/ROMToolboxDialog.Designer.cs +++ b/DS_Map/ROMToolboxDialog.Designer.cs @@ -340,7 +340,7 @@ // // repointScrcmdTextLBL // - this.repointScrcmdTextLBL.Location = new System.Drawing.Point(509, 48); + this.repointScrcmdTextLBL.Location = new System.Drawing.Point(481, 48); this.repointScrcmdTextLBL.Name = "repointScrcmdTextLBL"; this.repointScrcmdTextLBL.Size = new System.Drawing.Size(288, 37); this.repointScrcmdTextLBL.TabIndex = 27; @@ -352,7 +352,7 @@ // this.repointScrcmdLBL.AutoSize = true; this.repointScrcmdLBL.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.repointScrcmdLBL.Location = new System.Drawing.Point(509, 31); + this.repointScrcmdLBL.Location = new System.Drawing.Point(481, 31); this.repointScrcmdLBL.Name = "repointScrcmdLBL"; this.repointScrcmdLBL.Size = new System.Drawing.Size(157, 13); this.repointScrcmdLBL.TabIndex = 26; @@ -364,16 +364,15 @@ this.repointScrcmdButton.Name = "repointScrcmdButton"; this.repointScrcmdButton.Size = new System.Drawing.Size(100, 50); this.repointScrcmdButton.TabIndex = 25; - this.repointScrcmdButton.Text = "Expand ARM9"; + this.repointScrcmdButton.Text = "Repoint Table"; this.repointScrcmdButton.UseVisualStyleBackColor = true; - this.repointScrcmdButton.Click += new System.EventHandler(this.repointScrcmdButton_Click); // // scrcmdARM9requiredLBL // this.scrcmdARM9requiredLBL.AutoSize = true; this.scrcmdARM9requiredLBL.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.scrcmdARM9requiredLBL.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0))))); - this.scrcmdARM9requiredLBL.Location = new System.Drawing.Point(663, 30); + this.scrcmdARM9requiredLBL.Location = new System.Drawing.Point(635, 30); this.scrcmdARM9requiredLBL.Name = "scrcmdARM9requiredLBL"; this.scrcmdARM9requiredLBL.Size = new System.Drawing.Size(165, 13); this.scrcmdARM9requiredLBL.TabIndex = 29; @@ -381,7 +380,7 @@ // // label1 // - this.label1.Location = new System.Drawing.Point(509, 81); + this.label1.Location = new System.Drawing.Point(481, 81); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(288, 37); this.label1.TabIndex = 30; @@ -390,7 +389,7 @@ // // label2 // - this.label2.Location = new System.Drawing.Point(509, 188); + this.label2.Location = new System.Drawing.Point(481, 188); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(288, 37); this.label2.TabIndex = 34; @@ -410,7 +409,7 @@ // // dynamicHeadersTextLBL // - this.dynamicHeadersTextLBL.Location = new System.Drawing.Point(509, 139); + this.dynamicHeadersTextLBL.Location = new System.Drawing.Point(481, 139); this.dynamicHeadersTextLBL.Name = "dynamicHeadersTextLBL"; this.dynamicHeadersTextLBL.Size = new System.Drawing.Size(288, 59); this.dynamicHeadersTextLBL.TabIndex = 32; @@ -422,7 +421,7 @@ // this.dynamicHeadersLBL.AutoSize = true; this.dynamicHeadersLBL.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.dynamicHeadersLBL.Location = new System.Drawing.Point(509, 122); + this.dynamicHeadersLBL.Location = new System.Drawing.Point(481, 122); this.dynamicHeadersLBL.Name = "dynamicHeadersLBL"; this.dynamicHeadersLBL.Size = new System.Drawing.Size(160, 13); this.dynamicHeadersLBL.TabIndex = 31; diff --git a/DS_Map/ROMToolboxDialog.cs b/DS_Map/ROMToolboxDialog.cs index a412ecf..4e10d77 100644 --- a/DS_Map/ROMToolboxDialog.cs +++ b/DS_Map/ROMToolboxDialog.cs @@ -15,11 +15,18 @@ using static DSPRE.Resources.ROMToolboxDB.ToolboxDB; namespace DSPRE { public partial class ROMToolboxDialog : Form { public static uint expandedARMfileID = ToolboxDB.syntheticOverlayFileNumbersDB[RomInfo.gameFamily]; + public static uint synthOverlayLoadAddress = 0x023C8000; + public static bool flag_standardizedItems { get; private set; } = false; public static bool flag_arm9Expanded { get; private set; } = false; public static bool flag_BDHCamPatchApplied { get; private set; } = false; public static bool flag_DynamicHeadersPatchApplied { get; private set; } = false; public static bool flag_MatrixExpansionApplied { get; private set; } = false; + + public static bool flag_MainComboTableRepointed { get; set; } = false; + public static bool flag_TrainerClassBattleTableRepointed { get; set; } = false; + public static bool flag_PokemonBattleTableRepointed { get; set; } = false; + public static bool overlay1MustBeRestoredFromBackup { get; private set; } = true; #region Constructor @@ -818,11 +825,5 @@ namespace DSPRE { MessageBox.Show("This patch has already been applied.", "Can't reapply patch", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion - - private void repointScrcmdButton_Click(object sender, EventArgs e) { - - } - - } } \ No newline at end of file diff --git a/DS_Map/RomInfo.cs b/DS_Map/RomInfo.cs index ad7071d..6947f53 100644 --- a/DS_Map/RomInfo.cs +++ b/DS_Map/RomInfo.cs @@ -21,6 +21,7 @@ namespace DSPRE { public static string arm9Path { get; private set; } public static string overlayTablePath { get; set; } public static string overlayPath { get; set; } + public static gLangEnum gameLanguage { get; private set; } public static gVerEnum gameVersion { get; private set; } public static gFamEnum gameFamily { get; private set; } From e6924a3ea185a376b21dcc2561f2afaf66058734 Mon Sep 17 00:00:00 2001 From: AdAstra-LD <76622070+AdAstra-LD@users.noreply.github.com> Date: Thu, 9 Dec 2021 20:39:01 +0100 Subject: [PATCH 2/2] Misc GUI improvements - Textures list dropdown in map editor autoupdates after adding new texture pack with NSBTX editor - Location names dropdown in Header editor autoupdates after saving locations text - Pokemon Combo dropdown in Table Editor autoupdates after editing Table combos - Trainer Class name changes are automatically reflected everywhere - Fixed exception popping up when user double-clicks a nonexistent Map file on the matrix --- DS_Map/Main Window.cs | 90 +++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 20 deletions(-) diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 10be85b..9b1e100 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -926,8 +926,9 @@ namespace DSPRE { } /*Add list of options to each control */ - locationNameComboBox.Items.Clear(); - locationNameComboBox.Items.AddRange(new TextArchive(RomInfo.locationNamesTextNumber).messages.ToArray()); + currentTextArchive = new TextArchive(RomInfo.locationNamesTextNumber); + ReloadHeaderEditorLocationsList(); + switch (RomInfo.gameFamily) { case gFamEnum.DP: areaIconComboBox.Enabled = false; @@ -2382,20 +2383,27 @@ namespace DSPRE { statusLabel.Text = "Ready"; } private void mapFilesGridView_CellMouseDoubleClick(object sender, DataGridViewCellEventArgs e) { - if (!mapEditorIsReady) { - SetupMapEditor(); - mapEditorIsReady = true; - } - if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { if (currentMatrix.maps[e.RowIndex, e.ColumnIndex] == GameMatrix.EMPTY) { - MessageBox.Show("You can't load an empty map.\nSelect a valid map and try again.\n" + + MessageBox.Show("You can't load an empty map.\nSelect a valid map and try again.\n\n" + "If you only meant to change the value of this cell, wait some time between one mouse click and the other.\n" + "Alternatively, highlight the cell and press F2 on your keyboard.", "User attempted to load VOID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (!mapEditorIsReady) { + SetupMapEditor(); + mapEditorIsReady = true; + } + + int mapCount = romInfo.GetMapCount(); + if ( currentMatrix.maps[e.RowIndex, e.ColumnIndex] >= mapCount) { + MessageBox.Show("This matrix cell points to a map file that doesn't exist.", + "There " + ((mapCount > 1) ? "are only " + mapCount + " map files." : "is only 1 map file."), MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + /* Determine area data */ ushort headerID = 0; if (currentMatrix.hasHeadersSection) { @@ -6836,9 +6844,22 @@ namespace DSPRE { } private void exportTextFileButton_Click(object sender, EventArgs e) { currentTextArchive.SaveToFileExplorePath("Text Archive " + selectTextFileComboBox.SelectedIndex); + if (selectTextFileComboBox.SelectedIndex == RomInfo.locationNamesTextNumber) { + ReloadHeaderEditorLocationsList(); + } } + private void saveTextArchiveButton_Click(object sender, EventArgs e) { currentTextArchive.SaveToFileDefaultDir(selectTextFileComboBox.SelectedIndex); + if (selectTextFileComboBox.SelectedIndex == RomInfo.locationNamesTextNumber) { + ReloadHeaderEditorLocationsList(); + } + } + private void ReloadHeaderEditorLocationsList() { + int selection = locationNameComboBox.SelectedIndex; + locationNameComboBox.Items.Clear(); + locationNameComboBox.Items.AddRange(currentTextArchive.messages.ToArray()); + locationNameComboBox.SelectedIndex = selection; } private void importTextFileButton_Click(object sender, EventArgs e) { /* Prompt user to select .msg file */ @@ -7364,9 +7385,17 @@ namespace DSPRE { /* Add new NSBTX file to the correct folder */ if (mapTilesetRadioButton.Checked) { File.Copy(RomInfo.gameDirs[DirNames.mapTextures].unpackedDir + "\\" + 0.ToString("D4"), RomInfo.gameDirs[DirNames.mapTextures].unpackedDir + "\\" + texturePacksListBox.Items.Count.ToString("D4")); + + if (mapEditorIsReady) { + mapTextureComboBox.Items.Add("Map Texture Pack [" + mapTextureComboBox.Items.Count.ToString("D2") + "]"); + } } else { File.Copy(RomInfo.gameDirs[DirNames.buildingTextures].unpackedDir + "\\" + 0.ToString("D4"), RomInfo.gameDirs[DirNames.buildingTextures].unpackedDir + "\\" + texturePacksListBox.Items.Count.ToString("D4")); File.Copy(RomInfo.gameDirs[DirNames.buildingConfigFiles].unpackedDir + "\\" + 0.ToString("D4"), RomInfo.gameDirs[DirNames.buildingConfigFiles].unpackedDir + "\\" + texturePacksListBox.Items.Count.ToString("D4")); + + if (mapEditorIsReady) { + buildTextureComboBox.Items.Add("Building Texture Pack [" + buildTextureComboBox.Items.Count.ToString("D2") + "]"); + } } /* Update ComboBox and select new file */ @@ -7376,23 +7405,31 @@ namespace DSPRE { private void removeNSBTXButton_Click(object sender, EventArgs e) { if (texturePacksListBox.Items.Count > 1) { /* Delete NSBTX file */ - if (mapTilesetRadioButton.Checked) + if (mapTilesetRadioButton.Checked) { File.Delete(RomInfo.gameDirs[DirNames.mapTextures].unpackedDir + "\\" + (texturePacksListBox.Items.Count - 1).ToString("D4")); - else { + + if (mapEditorIsReady) { + mapTextureComboBox.Items.RemoveAt(mapTextureComboBox.Items.Count - 1); + } + } else { File.Delete(RomInfo.gameDirs[DirNames.buildingTextures].unpackedDir + "\\" + (texturePacksListBox.Items.Count - 1).ToString("D4")); File.Delete(RomInfo.gameDirs[DirNames.buildingConfigFiles].unpackedDir + "\\" + (texturePacksListBox.Items.Count - 1).ToString("D4")); + + if (mapEditorIsReady) { + buildTextureComboBox.Items.RemoveAt(buildTextureComboBox.Items.Count - 1); + } } /* Check if currently selected file is the last one, and in that case select the one before it */ int lastIndex = texturePacksListBox.Items.Count - 1; - if (texturePacksListBox.SelectedIndex == lastIndex) + if (texturePacksListBox.SelectedIndex == lastIndex) { texturePacksListBox.SelectedIndex--; + } /* Remove item from ComboBox */ texturePacksListBox.Items.RemoveAt(lastIndex); } else { MessageBox.Show("At least one tileset must be kept.", "Can't delete tileset", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; } } private void addAreaDataButton_Click(object sender, EventArgs e) { @@ -8188,6 +8225,14 @@ namespace DSPRE { disableHandlers = false; //trainerClassListBox_SelectedIndexChanged(null, null); + if ( gameFamily.Equals(gFamEnum.HGSS) && tableEditorIsReady ) { + pbEffectsTrainerCombobox.Items[selectedTrClass] = trainerClassListBox.Items[selectedTrClass]; + for (int i = 0; i < vsTrainerEffectsList.Count; i++) { + if (vsTrainerEffectsList[i].trainerClass == selectedTrClass) { + pbEffectsVsTrainerListbox.Items[i] = pbEffectsTrainerCombobox.Items[selectedTrClass] + " uses Combo #" + vsTrainerEffectsList[i].comboID; + } + } + } MessageBox.Show("Trainer Class settings saved.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } @@ -8277,11 +8322,7 @@ namespace DSPRE { pbEffectsPokemonCombobox.Items.Add("[" + i + "]" + " " + pokeNames[i]); } - pbEffectsTrainerCombobox.Items.Clear(); - trcNames = RomInfo.GetTrainerClassNames(); - for (int i = 0; i < trcNames.Length; i++) { - pbEffectsTrainerCombobox.Items.Add("[" + i + "]" + " " + trcNames[i]); - } + RepopulateTableEditorTrainerClasses(); pbEffectsVsTrainerListbox.Items.Clear(); pbEffectsVsPokemonListbox.Items.Clear(); @@ -8295,7 +8336,7 @@ namespace DSPRE { int classID = entry & 1023; int comboID = entry >> 10; vsTrainerEffectsList.Add((classID, comboID)); - pbEffectsVsTrainerListbox.Items.Add("[" + classID.ToString("D3") + "]" + " " + trcNames[classID] + " uses Combo #" + comboID); + pbEffectsVsTrainerListbox.Items.Add(pbEffectsTrainerCombobox.Items[classID] + " uses Combo #" + comboID); } } @@ -8310,7 +8351,7 @@ namespace DSPRE { try { pokeName = pokeNames[pokeID]; } catch (IndexOutOfRangeException) { - pokeName = "UNKNOWN_" + pokeID.ToString("D3"); + pokeName = "UNKNOWN"; } pbEffectsVsPokemonListbox.Items.Add("[" + pokeID.ToString("D3") + "]" + " " + pokeName + " uses Combo #" + comboID); } @@ -8345,6 +8386,15 @@ namespace DSPRE { pbEffectsGroupBox.Enabled = false; } } + + private void RepopulateTableEditorTrainerClasses() { + pbEffectsTrainerCombobox.Items.Clear(); + trcNames = RomInfo.GetTrainerClassNames(); + for (int i = 0; i < trcNames.Length; i++) { + pbEffectsTrainerCombobox.Items.Add("[" + i.ToString("D3") + "]" + " " + trcNames[i]); + } + } + private void conditionalMusicTableListBox_SelectedIndexChanged(object sender, EventArgs e) { int selection = conditionalMusicTableListBox.SelectedIndex; headerConditionalMusicComboBox.SelectedIndex = conditionalMusicTable[selection].header; @@ -8425,7 +8475,7 @@ namespace DSPRE { }; disableHandlers = true; - pbEffectsCombosListbox.Items[index] = "Combo " + index.ToString("D2") + " - " + "Effect #" + battleIntroEffect + ", " + "Music #" + battleMusic; + pbEffectsCombosListbox.Items[index] = pbEffectsTrainerChooseMainCombobox.Items[index] = pbEffectsPokemonChooseMainCombobox.Items[index] = "Combo " + index.ToString("D2") + " - " + "Effect #" + battleIntroEffect + ", " + "Music #" + battleMusic; disableHandlers = false; }