From 182eec2f978d32a081d8ee0ec1341ffedf0d71fb Mon Sep 17 00:00:00 2001
From: AdAstra-LD <76622070+AdAstra-LD@users.noreply.github.com>
Date: Sun, 25 Jul 2021 18:31:03 +0200
Subject: [PATCH] Created SetHeaderTableOffset function in RomInfo, to replace
HeaderOffsets dictionary in PokeDatabase
---
DS_Map/Main Window.Designer.cs | 86 ++++++++++++++++++++++++++++++-
DS_Map/Main Window.cs | 25 +++++++--
DS_Map/Main Window.resx | 11 +++-
DS_Map/ROMFiles/MapHeader.cs | 2 +-
DS_Map/ROMToolboxDialog.cs | 2 +-
DS_Map/Resources/PokeDatabase.cs | 46 +----------------
DS_Map/RomInfo.cs | 88 +++++++++++++++++++++++++++++---
7 files changed, 199 insertions(+), 61 deletions(-)
diff --git a/DS_Map/Main Window.Designer.cs b/DS_Map/Main Window.Designer.cs
index 4fff21b..202c0b4 100644
--- a/DS_Map/Main Window.Designer.cs
+++ b/DS_Map/Main Window.Designer.cs
@@ -711,6 +711,9 @@
this.trainerClassListBox = new System.Windows.Forms.ListBox();
this.label42 = new System.Windows.Forms.Label();
this.trainerComboBox = new System.Windows.Forms.ComboBox();
+ this.tableEditorTabPage = new System.Windows.Forms.TabPage();
+ this.ConditionalMusicGroupBox = new System.Windows.Forms.GroupBox();
+ this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.mainTabImageList = new System.Windows.Forms.ImageList(this.components);
this.gameIcon = new System.Windows.Forms.PictureBox();
this.languageLabel = new System.Windows.Forms.Label();
@@ -752,6 +755,9 @@
this.spawnEditorToolStripButton = new System.Windows.Forms.ToolStripButton();
this.versionLabel = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
+ this.LocationCol = new System.Windows.Forms.DataGridViewComboBoxColumn();
+ this.FlagCol = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.MusicIDcol = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.mainTabControl.SuspendLayout();
this.headerEditorTabPage.SuspendLayout();
this.worldmapCoordsGroupBox.SuspendLayout();
@@ -959,6 +965,9 @@
this.groupBox25.SuspendLayout();
this.TrainerAIGroupBox.SuspendLayout();
this.trainerItemsGroupBox.SuspendLayout();
+ this.tableEditorTabPage.SuspendLayout();
+ this.ConditionalMusicGroupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.gameIcon)).BeginInit();
this.menuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
@@ -977,6 +986,7 @@
this.mainTabControl.Controls.Add(this.textEditorTabPage);
this.mainTabControl.Controls.Add(this.cameraEditorTabPage);
this.mainTabControl.Controls.Add(this.trainerEditorTabPage);
+ this.mainTabControl.Controls.Add(this.tableEditorTabPage);
this.mainTabControl.ImageList = this.mainTabImageList;
this.mainTabControl.Location = new System.Drawing.Point(11, 72);
this.mainTabControl.Name = "mainTabControl";
@@ -9070,6 +9080,42 @@
this.trainerComboBox.TabIndex = 27;
this.trainerComboBox.SelectedIndexChanged += new System.EventHandler(this.trainerComboBox_SelectedIndexChanged);
//
+ // tableEditorTabPage
+ //
+ this.tableEditorTabPage.Controls.Add(this.ConditionalMusicGroupBox);
+ this.tableEditorTabPage.Location = new System.Drawing.Point(4, 23);
+ this.tableEditorTabPage.Name = "tableEditorTabPage";
+ this.tableEditorTabPage.Padding = new System.Windows.Forms.Padding(3);
+ this.tableEditorTabPage.Size = new System.Drawing.Size(1185, 619);
+ this.tableEditorTabPage.TabIndex = 9;
+ this.tableEditorTabPage.Text = "Table Editor";
+ this.tableEditorTabPage.UseVisualStyleBackColor = true;
+ //
+ // ConditionalMusicGroupBox
+ //
+ this.ConditionalMusicGroupBox.Controls.Add(this.dataGridView1);
+ this.ConditionalMusicGroupBox.Location = new System.Drawing.Point(16, 7);
+ this.ConditionalMusicGroupBox.Name = "ConditionalMusicGroupBox";
+ this.ConditionalMusicGroupBox.Size = new System.Drawing.Size(393, 257);
+ this.ConditionalMusicGroupBox.TabIndex = 0;
+ this.ConditionalMusicGroupBox.TabStop = false;
+ this.ConditionalMusicGroupBox.Text = "groupBox26";
+ //
+ // dataGridView1
+ //
+ this.dataGridView1.AllowUserToAddRows = false;
+ this.dataGridView1.AllowUserToDeleteRows = false;
+ this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.LocationCol,
+ this.FlagCol,
+ this.MusicIDcol});
+ this.dataGridView1.Location = new System.Drawing.Point(7, 20);
+ this.dataGridView1.Name = "dataGridView1";
+ this.dataGridView1.RowHeadersVisible = false;
+ this.dataGridView1.Size = new System.Drawing.Size(380, 231);
+ this.dataGridView1.TabIndex = 0;
+ //
// mainTabImageList
//
this.mainTabImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("mainTabImageList.ImageStream")));
@@ -9295,14 +9341,14 @@
this.mainToolStrip.TabIndex = 16;
this.mainToolStrip.Text = "mainToolStrip";
//
- // openFolderWithoutRomButton
+ // readDataFromFolderButton
//
this.readDataFromFolderButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.readDataFromFolderButton.Image = global::DSPRE.Properties.Resources.open_file;
this.readDataFromFolderButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
this.readDataFromFolderButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.readDataFromFolderButton.Margin = new System.Windows.Forms.Padding(0, 6, 0, 2);
- this.readDataFromFolderButton.Name = "openFolderWithoutRomButton";
+ this.readDataFromFolderButton.Name = "readDataFromFolderButton";
this.readDataFromFolderButton.Size = new System.Drawing.Size(36, 36);
this.readDataFromFolderButton.Text = "Open Extracted Data";
this.readDataFromFolderButton.ToolTipText = "Open Extracted Data";
@@ -9489,6 +9535,33 @@
this.versionLabel.TabIndex = 9;
this.versionLabel.Text = "ROM:";
//
+ // LocationCol
+ //
+ this.LocationCol.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.LocationCol.FillWeight = 60F;
+ this.LocationCol.HeaderText = "Header";
+ this.LocationCol.Name = "LocationCol";
+ this.LocationCol.Resizable = System.Windows.Forms.DataGridViewTriState.False;
+ this.LocationCol.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
+ //
+ // FlagCol
+ //
+ this.FlagCol.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.FlagCol.FillWeight = 20F;
+ this.FlagCol.HeaderText = "Flag";
+ this.FlagCol.MinimumWidth = 30;
+ this.FlagCol.Name = "FlagCol";
+ this.FlagCol.Resizable = System.Windows.Forms.DataGridViewTriState.False;
+ //
+ // MusicIDcol
+ //
+ this.MusicIDcol.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.MusicIDcol.FillWeight = 20F;
+ this.MusicIDcol.HeaderText = "Music";
+ this.MusicIDcol.MinimumWidth = 30;
+ this.MusicIDcol.Name = "MusicIDcol";
+ this.MusicIDcol.Resizable = System.Windows.Forms.DataGridViewTriState.False;
+ //
// MainProgram
//
this.AllowDrop = true;
@@ -9774,6 +9847,9 @@
this.TrainerAIGroupBox.ResumeLayout(false);
this.TrainerAIGroupBox.PerformLayout();
this.trainerItemsGroupBox.ResumeLayout(false);
+ this.tableEditorTabPage.ResumeLayout(false);
+ this.ConditionalMusicGroupBox.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.gameIcon)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
@@ -10492,6 +10568,12 @@
private System.Windows.Forms.NumericUpDown trClassFramePreviewUpDown;
private System.Windows.Forms.Label trainerClassFrameMaxLabel;
private System.Windows.Forms.ToolStripButton readDataFromFolderButton;
+ private System.Windows.Forms.TabPage tableEditorTabPage;
+ private System.Windows.Forms.GroupBox ConditionalMusicGroupBox;
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.DataGridViewComboBoxColumn LocationCol;
+ private System.Windows.Forms.DataGridViewTextBoxColumn FlagCol;
+ private System.Windows.Forms.DataGridViewTextBoxColumn MusicIDcol;
}
}
diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs
index ac48fd1..edc360a 100644
--- a/DS_Map/Main Window.cs
+++ b/DS_Map/Main Window.cs
@@ -44,6 +44,7 @@ namespace DSPRE {
public bool textEditorIsReady { get; private set; } = false;
public bool cameraEditorIsReady { get; private set; } = false;
public bool trainerEditorIsReady { get; private set; } = false;
+ public bool tableEditorIsReady { get; private set; } = false;
public const ushort MAPMODEL_CRITICALSIZE = 61000;
@@ -782,9 +783,15 @@ namespace DSPRE {
SetupTrainerEditor();
trainerEditorIsReady = true;
}
+ } else if (mainTabControl.SelectedTab == tableEditorTabPage) {
+ if(!tableEditorIsReady) {
+ SetupTableEditor();
+ tableEditorIsReady = true;
+ }
}
statusLabel.Text = "Ready";
}
+
private void spawnEditorToolStripButton_Click(object sender, EventArgs e) {
if (!matrixEditorIsReady) {
SetupMatrixEditor();
@@ -1491,7 +1498,7 @@ namespace DSPRE {
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
DSUtils.WriteToFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + currentHeader.ID.ToString("D4"), currentHeader.ToByteArray(), 0, 0, true);
} else {
- uint headerOffset = (uint)(PokeDatabase.System.headerOffsetsDict[RomInfo.romID] + MapHeader.length * currentHeader.ID);
+ uint headerOffset = (uint)(RomInfo.headerTableOffset + MapHeader.length * currentHeader.ID);
DSUtils.WriteToArm9(currentHeader.ToByteArray(), headerOffset);
}
disableHandlers = true;
@@ -1649,7 +1656,7 @@ namespace DSPRE {
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
DSUtils.WriteToFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + currentHeader.ID.ToString("D4"), currentHeader.ToByteArray(), 0, 0, true);
} else {
- uint headerOffset = (uint)(PokeDatabase.System.headerOffsetsDict[RomInfo.romID] + MapHeader.length * currentHeader.ID);
+ uint headerOffset = (uint)(RomInfo.headerTableOffset + MapHeader.length * currentHeader.ID);
DSUtils.WriteToArm9(currentHeader.ToByteArray(), headerOffset);
}
@@ -7301,10 +7308,12 @@ namespace DSPRE {
private void importReplacePropertiesButton_Click(object sender, EventArgs e) {
/* Prompt user to select .evt file */
- OpenFileDialog of = new OpenFileDialog();
- of.Filter = "Gen IV Trainer Properties (*.trp)|*.trp";
- if (of.ShowDialog(this) != DialogResult.OK)
+ OpenFileDialog of = new OpenFileDialog {
+ Filter = "Gen IV Trainer Properties (*.trp)|*.trp"
+ };
+ if (of.ShowDialog(this) != DialogResult.OK) {
return;
+ }
/* Update trp object in memory */
currentTrainerFile.trp = new TrainerProperties((ushort)trainerComboBox.SelectedIndex, new FileStream(of.FileName, FileMode.Open));
@@ -7341,6 +7350,12 @@ namespace DSPRE {
UpdateTrainerClassPic((int)((NumericUpDown)sender).Value);
}
#endregion
+
+ #region Table Editor
+ private void SetupTableEditor() {
+
+ }
+ #endregion
private void ExclusiveCBInvert(CheckBox cb) {
if (disableHandlers)
return;
diff --git a/DS_Map/Main Window.resx b/DS_Map/Main Window.resx
index d02d61b..387c0e7 100644
--- a/DS_Map/Main Window.resx
+++ b/DS_Map/Main Window.resx
@@ -845,6 +845,15 @@
True
+
+ True
+
+
+ True
+
+
+ True
+
239, 17
@@ -853,7 +862,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABy
- EQAAAk1TRnQBSQFMAgEBCQEAAZQBFAGUARQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
+ EQAAAk1TRnQBSQFMAgEBCQEAAaQBFAGkARQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAATADAAEBAQABCAYAAQwYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
diff --git a/DS_Map/ROMFiles/MapHeader.cs b/DS_Map/ROMFiles/MapHeader.cs
index 3694ce6..89876cb 100644
--- a/DS_Map/ROMFiles/MapHeader.cs
+++ b/DS_Map/ROMFiles/MapHeader.cs
@@ -146,7 +146,7 @@ namespace DSPRE.ROMFiles {
return LoadFromByteArray(headerData, headerNumber);
}
public static MapHeader LoadFromARM9(ushort headerNumber) {
- long headerOffset = Resources.PokeDatabase.System.headerOffsetsDict[RomInfo.romID] + MapHeader.length * headerNumber;
+ long headerOffset = RomInfo.headerTableOffset + MapHeader.length * headerNumber;
return LoadFromFile(RomInfo.arm9Path, headerNumber, headerOffset);
}
diff --git a/DS_Map/ROMToolboxDialog.cs b/DS_Map/ROMToolboxDialog.cs
index a418279..d8316f1 100644
--- a/DS_Map/ROMToolboxDialog.cs
+++ b/DS_Map/ROMToolboxDialog.cs
@@ -718,7 +718,7 @@ namespace DSPRE {
foreach (Tuple reference in ToolboxDB.dynamicHeadersPointersDB [RomInfo.gameFamily]) {
DSUtils.WriteToArm9(DSUtils.HexStringToByteArray(data.REFERENCE_STRING), (uint)(reference.Item1 + data.pointerDiff));
- uint pointerValue = BitConverter.ToUInt32(DSUtils.ReadFromArm9((uint)(reference.Item2 + data.pointerDiff), 4), 0) - PokeDatabase.System.headerOffsetsDict[RomInfo.romID] - 0x02000000;
+ uint pointerValue = BitConverter.ToUInt32(DSUtils.ReadFromArm9((uint)(reference.Item2 + data.pointerDiff), 4), 0) - RomInfo.headerTableOffset - 0x02000000;
DSUtils.WriteToArm9(BitConverter.GetBytes(pointerValue), (uint)(reference.Item2 + data.pointerDiff));
}
diff --git a/DS_Map/Resources/PokeDatabase.cs b/DS_Map/Resources/PokeDatabase.cs
index f753cc0..d3b84fb 100644
--- a/DS_Map/Resources/PokeDatabase.cs
+++ b/DS_Map/Resources/PokeDatabase.cs
@@ -3402,7 +3402,7 @@ namespace DSPRE.Resources {
[0x036E] = "TextPocketWhite",
[0x036F] = "SetLayerVisibility",
[0x0370] = "StopWeatherAlphaBlend",
- [0x0371] = "SetRepelSteps",
+ [0x0371] = "SetRepelSteps"
};
public static Dictionary CustomScrCmdParameters = new Dictionary() {
[0x0357] = new byte[] { 2, 2 },
@@ -3425,50 +3425,6 @@ namespace DSPRE.Resources {
};
}
public static class System {
- public static Dictionary headerOffsetsDict = new Dictionary() {
- ["ADAE"] = 0xEEDBC,
- ["APAE"] = 0xEEDBC,
-
- ["ADAS"] = 0xEEE08,
- ["APAS"] = 0xEEE08,
-
- ["ADAI"] = 0xEED70,
- ["APAI"] = 0xEED70,
-
- ["ADAF"] = 0xEEDFC,
- ["APAF"] = 0xEEDFC,
-
- ["ADAD"] = 0xEEDCC,
- ["APAD"] = 0xEEDCC,
-
- ["ADAJ"] = 0xF0D68,
- ["APAJ"] = 0xF0D6C,
-
- ["CPUE"] = 0xE601C,
- ["CPUS"] = 0xE60B0,
- ["CPUI"] = 0xE6038,
- ["CPUF"] = 0xE60A4,
- ["CPUD"] = 0xE6074,
- ["CPUJ"] = 0xE56F0,
-
- ["IPKE"] = 0xF6BE0,
- ["IPGE"] = 0xF6BE0,
-
- ["IPKS"] = 0xF6BC8,
- ["IPGS"] = 0xF6BD0,
-
- ["IPKI"] = 0xF6B58,
- ["IPGI"] = 0xF6B58,
-
- ["IPKF"] = 0xF6BC4,
- ["IPGF"] = 0xF6BC4,
-
- ["IPKD"] = 0xF6B94,
- ["IPGD"] = 0xF6B94,
-
- ["IPKJ"] = 0xF6390,
- ["IPGJ"] = 0xF6390
- };
public static Dictionary versionsDict = new Dictionary() {
["ADAE"] = "D",
["ADAS"] = "D",
diff --git a/DS_Map/RomInfo.cs b/DS_Map/RomInfo.cs
index c099b87..4ebc26b 100644
--- a/DS_Map/RomInfo.cs
+++ b/DS_Map/RomInfo.cs
@@ -33,8 +33,11 @@ namespace DSPRE {
public static int cameraTblOverlayNumber { get; private set; }
public static uint[] cameraTblOffsetsToRAMaddress { get; private set; }
+ public static uint headerTableOffset { get; private set; }
+ public static uint conditionalMusicTableOffset { get; internal set; }
public static uint OWTableOffset { get; internal set; }
public static string OWtablePath { get; private set; }
+
public static int nullEncounterID { get; private set; }
public static int attackNamesTextNumber { get; private set; }
public static int[] pokemonNamesTextNumbers { get; private set; }
@@ -96,6 +99,10 @@ namespace DSPRE {
}
workDir = Path.GetDirectoryName(romName) + "\\" + Path.GetFileNameWithoutExtension(romName) + folderSuffix + "\\";
+ arm9Path = workDir + @"arm9.bin";
+ overlayTablePath = workDir + @"y9.bin";
+ overlayPath = workDir + "overlay";
+ internalNamesLocation = workDir + @"data\fielddata\maptable\mapname.bin";
LoadGameVersion();
if (gameVersion is null)
@@ -105,13 +112,8 @@ namespace DSPRE {
LoadGameName();
LoadGameLanguage();
- arm9Path = workDir + @"arm9.bin";
- overlayTablePath = workDir + @"y9.bin";
- overlayPath = workDir + "overlay";
-
- internalNamesLocation = workDir + @"data\fielddata\maptable\mapname.bin";
SetNarcDirs();
-
+ SetHeaderTableOffset();
SetNullEncounterID();
SetAttackNamesTextNumber();
@@ -143,6 +145,80 @@ namespace DSPRE {
//[174] = "dppt_suitcase",
};
}
+ public static void SetHeaderTableOffset() {
+ switch (gameFamily) {
+ case "DP":
+ switch (gameLanguage) {
+ case "ENG":
+ headerTableOffset = 0xEEDBC;
+ break;
+ case "ESP":
+ headerTableOffset = 0xEEE08;
+ break;
+ case "ITA":
+ headerTableOffset = 0xEED70;
+ break;
+ case "FRA":
+ headerTableOffset = 0xEEDFC;
+ break;
+ case "GER":
+ headerTableOffset = 0xEEDCC;
+ break;
+ case "JAP":
+ headerTableOffset = 0xF0D68;
+ break;
+ }
+ break;
+ case "Plat":
+ switch (gameLanguage) {
+ case "ENG":
+ headerTableOffset = 0xE601C;
+ break;
+ case "ESP":
+ headerTableOffset = 0xE60B0;
+ break;
+ case "ITA":
+ headerTableOffset = 0xE6038;
+ break;
+ case "FRA":
+ headerTableOffset = 0xE60A4;
+ break;
+ case "GER":
+ headerTableOffset = 0xE6074;
+ break;
+ case "JAP":
+ headerTableOffset = 0xE56F0;
+ break;
+ }
+ break;
+ case "HGSS":
+ switch (gameLanguage) {
+ case "ENG":
+ headerTableOffset = 0xF6BE0;
+ break;
+ case "ESP":
+ if (gameVersion == "HG") {
+ headerTableOffset = 0xF6BC8;
+ } else {
+ headerTableOffset = 0xF6BD0;
+ }
+ break;
+ case "ITA":
+ headerTableOffset = 0xF6B58;
+ break;
+ case "FRA":
+ headerTableOffset = 0xF6BC4;
+ break;
+ case "GER":
+ headerTableOffset = 0xF6B94;
+ break;
+ case "JAP":
+ headerTableOffset = 0xF6390;
+ break;
+ }
+ break;
+ }
+ }
public static void SetupSpawnSettings() {
switch (gameFamily) {
case "DP":