Fixed dynamic headers patch not reading/writing from/to the correct place

- misc improvements
- remove last header button is now fully functional
This commit is contained in:
AdAstra-LD
2021-07-07 06:12:21 +02:00
parent e2cb1891f3
commit 57548c6000
6 changed files with 136 additions and 83 deletions

View File

@@ -18,7 +18,7 @@ namespace DSPRE {
public const int ERR_OVERLAY_NOTFOUND = -1;
public const int ERR_OVERLAY_ALREADY_UNCOMPRESSED = -2;
public const string backupSuffix = ".compressedBackup";
public const string backupSuffix = ".backup";
public static void WriteToFile(string filepath, byte[] bytesToWrite, uint writeAt = 0, int readFrom = 0, bool fromScratch = false) {
if (fromScratch)

View File

@@ -835,6 +835,7 @@
this.removeLastHeaderBTN.TabIndex = 52;
this.removeLastHeaderBTN.Text = "Remove Last";
this.removeLastHeaderBTN.UseVisualStyleBackColor = true;
this.removeLastHeaderBTN.Click += new System.EventHandler(this.removeLastHeaderBTN_Click);
//
// addHeaderBTN
//
@@ -2282,7 +2283,7 @@
this.addHeadersButton.TabIndex = 23;
this.addHeadersButton.Text = "Add \r\nHeader Tab";
this.addHeadersButton.UseVisualStyleBackColor = true;
this.addHeadersButton.Click += new System.EventHandler(this.addHeadersButton_Click);
this.addHeadersButton.Click += new System.EventHandler(this.addHeaderSectionButton_Click);
//
// saveMatrixButton
//
@@ -2699,7 +2700,7 @@
this.removeMapFileButton.Text = "Remove \r\nLast Map";
this.removeMapFileButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.removeMapFileButton.UseVisualStyleBackColor = true;
this.removeMapFileButton.Click += new System.EventHandler(this.removeMapFileButton_Click);
this.removeMapFileButton.Click += new System.EventHandler(this.removeLastMapFileButton_Click);
//
// mapRenderPanel
//

View File

@@ -285,6 +285,7 @@ namespace DSPRE {
}
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied) {
addHeaderBTN.Enabled = true;
removeLastHeaderBTN.Enabled = true;
}
}
}
@@ -802,12 +803,21 @@ namespace DSPRE {
statusLabel.Text = "Reading internal names... Please wait.";
Update();
/* Read Header internal names */
internalNames = new List<string>();
headerListBoxNames = new List<string>();
int headerCount;
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
addHeaderBTN.Enabled = true;
removeLastHeaderBTN.Enabled = true;
headerCount = Directory.GetFiles(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir).Length;
} else {
headerCount = RomInfo.GetHeaderCount();
}
/* Read Header internal names */
try {
using (BinaryReader reader = new BinaryReader(File.OpenRead(RomInfo.internalNamesLocation))) {
int headerCount = RomInfo.GetHeaderCount();
for (int i = 0; i < headerCount; i++) {
byte[] row = reader.ReadBytes(RomInfo.internalNameLength);
@@ -878,9 +888,6 @@ namespace DSPRE {
}
if (headerListBox.Items.Count > 0)
headerListBox.SelectedIndex = 0;
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied())
addHeaderBTN.Enabled = true;
}
private void addHeaderBTN_Click(object sender, EventArgs e) {
// Add new file in the dynamic headers directory
@@ -900,6 +907,26 @@ namespace DSPRE {
// Select new header
headerListBox.SelectedIndex = headerListBox.Items.Count - 1;
}
private void removeLastHeaderBTN_Click(object sender, EventArgs e) {
/* Check if currently selected file is the last one, and in that case select the one before it */
int lastIndex = headerListBox.Items.Count - 1;
if (lastIndex > 0) { //there are at least 2 elements
if (headerListBox.SelectedIndex == lastIndex) {
headerListBox.SelectedIndex--;
}
/* Physically delete last header file */
File.Delete(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + lastIndex.ToString("D4"));
/* Remove item from collections */
headerListBox.Items.RemoveAt(lastIndex);
internalNames.RemoveAt(lastIndex);
headerListBoxNames.RemoveAt(lastIndex);
} else {
MessageBox.Show("You must have at least one header!", "Can't delete last header", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void areaDataUpDown_ValueChanged(object sender, EventArgs e) {
if (disableHandlers)
return;
@@ -1006,7 +1033,7 @@ namespace DSPRE {
/* Check if dynamic headers patch has been applied, and load header from arm9 or a/0/5/0 accordingly */
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
currentHeader = MapHeader.BuildFromFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + headerNumber.ToString("D4"), headerNumber, 0);
currentHeader = MapHeader.LoadFromFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + headerNumber.ToString("D4"), headerNumber, 0);
} else {
currentHeader = MapHeader.LoadFromARM9(headerNumber);
}
@@ -1318,7 +1345,7 @@ namespace DSPRE {
selectEventComboBox.SelectedIndex = (int)eventFileUpDown.Value; // Select event file
mainTabControl.SelectedTab = eventEditorTabPage;
CenterEventviewOnEntities();
CenterEventViewOnEntities();
eventMatrixXUpDown_ValueChanged(null, null);
}
private void openMatrixButton_Click(object sender, EventArgs e) {
@@ -1391,35 +1418,35 @@ namespace DSPRE {
headerListBox.Items.Clear();
bool noResult = true;
switch (RomInfo.gameFamily) {
case "DP":
for (ushort i = 0; i < internalNames.Count; i++) {
String locationName = locationNameComboBox.Items[((HeaderDP)MapHeader.LoadFromARM9(i)).locationName].ToString();
if (locationName.IndexOf(searchLocationTextBox.Text, StringComparison.InvariantCultureIgnoreCase) >= 0) {
headerListBox.Items.Add(i.ToString("D3") + MapHeader.nameSeparator + internalNames[i]);
noResult = false;
}
}
break;
case "Plat":
for (ushort i = 0; i < internalNames.Count; i++) {
String locationName = locationNameComboBox.Items[((HeaderPt)MapHeader.LoadFromARM9(i)).locationName].ToString();
if (locationName.IndexOf(searchLocationTextBox.Text, StringComparison.InvariantCultureIgnoreCase) >= 0) {
headerListBox.Items.Add(i.ToString("D3") + MapHeader.nameSeparator + internalNames[i]);
noResult = false;
}
}
break;
case "HGSS":
for (ushort i = 0; i < internalNames.Count; i++) {
String locationName = locationNameComboBox.Items[((HeaderHGSS)MapHeader.LoadFromARM9(i)).locationName].ToString();
if (locationName.IndexOf(searchLocationTextBox.Text, StringComparison.InvariantCultureIgnoreCase) >= 0) {
headerListBox.Items.Add(i.ToString("D3") + MapHeader.nameSeparator + internalNames[i]);
noResult = false;
}
}
break;
/* Check if dynamic headers patch has been applied, and load header from arm9 or a/0/5/0 accordingly */
for (ushort i = 0; i < internalNames.Count; i++) {
MapHeader h;
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
h = MapHeader.LoadFromFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + i.ToString("D4"), i, 0);
} else {
h = MapHeader.LoadFromARM9(i);
}
string locationName = "";
switch (RomInfo.gameFamily) {
case "DP":
locationName = locationNameComboBox.Items[((HeaderDP)h).locationName].ToString();
break;
case "Plat":
locationName = locationNameComboBox.Items[((HeaderPt)h).locationName].ToString();
break;
case "HGSS":
locationName = locationNameComboBox.Items[((HeaderHGSS)h).locationName].ToString();
break;
}
if (locationName.IndexOf(searchLocationTextBox.Text, StringComparison.InvariantCultureIgnoreCase) >= 0) {
headerListBox.Items.Add(i.ToString("D3") + MapHeader.nameSeparator + internalNames[i]);
noResult = false;
}
}
if (noResult) {
headerListBox.Items.Add("No result for " + '"' + searchLocationTextBox.Text + '"');
headerListBox.Enabled = false;
@@ -1494,8 +1521,8 @@ namespace DSPRE {
if (new FileInfo(of.FileName).Length > 48)
throw new FileFormatException();
h = MapHeader.BuildFromFile(of.FileName, currentHeader.ID, 0);
if (h.ID == ushort.MaxValue)
h = MapHeader.LoadFromFile(of.FileName, currentHeader.ID, 0);
if (h == null)
throw new FileFormatException();
} catch (FileFormatException) {
@@ -1505,8 +1532,14 @@ namespace DSPRE {
}
currentHeader = h;
uint headerOffset = (uint)(PokeDatabase.System.headerOffsetsDict[RomInfo.romID] + MapHeader.length * currentHeader.ID);
DSUtils.WriteToArm9(currentHeader.ToByteArray(), headerOffset);
/* Check if dynamic headers patch has been applied, and save header to arm9 or a/0/5/0 accordingly */
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);
DSUtils.WriteToArm9(currentHeader.ToByteArray(), headerOffset);
}
try {
using (BinaryReader reader = new BinaryReader(new FileStream(of.FileName, FileMode.Open))) {
reader.BaseStream.Position = MapHeader.length + 8;
@@ -1884,7 +1917,7 @@ namespace DSPRE {
selectMatrixComboBox.SelectedIndex = 0;
statusLabel.Text = "Ready";
}
private void addHeadersButton_Click(object sender, EventArgs e) {
private void addHeaderSectionButton_Click(object sender, EventArgs e) {
if (!currentMatrix.hasHeadersSection) {
currentMatrix.hasHeadersSection = true;
matrixTabControl.TabPages.Add(headersTabPage);
@@ -2132,22 +2165,29 @@ namespace DSPRE {
}
/* Determine area data */
ushort header;
ushort headerID;
if (currentMatrix.hasHeadersSection) {
header = currentMatrix.headers[e.RowIndex, e.ColumnIndex];
headerID = currentMatrix.headers[e.RowIndex, e.ColumnIndex];
} else {
header = currentHeader.ID;
headerID = currentHeader.ID;
}
AreaData areaData;
if (header > internalNames.Count) {
if (headerID > internalNames.Count) {
MessageBox.Show("This map is associated to a non-existent header.\nThis will lead to unpredictable behaviour and, possibily, problems, if you attempt to load it in game.",
"Invalid header", MessageBoxButtons.OK, MessageBoxIcon.Information);
header = 0;
headerID = 0;
}
/* get texture file numbers from area data */
areaData = new AreaData((MapHeader.LoadFromARM9(header).areaDataID));
MapHeader h;
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
h = MapHeader.LoadFromFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + headerID.ToString("D4"), headerID, 0);
} else {
h = MapHeader.LoadFromARM9(headerID);
}
areaData = new AreaData(h.areaDataID);
/* Load Map File and switch to Map Editor tab */
disableHandlers = true;
@@ -2920,7 +2960,7 @@ namespace DSPRE {
ang, dist, elev, perspective,
mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, showBuildingTextures);
}
private void removeMapFileButton_Click(object sender, EventArgs e) {
private void removeLastMapFileButton_Click(object sender, EventArgs e) {
/* Delete last map file */
File.Delete(RomInfo.gameDirs[DirNames.maps].unpackedDir + "\\" + (selectMapComboBox.Items.Count - 1).ToString("D4"));
@@ -3890,7 +3930,7 @@ namespace DSPRE {
#endregion
#region Subroutines
private void CenterEventviewOnEntities() {
private void CenterEventViewOnEntities() {
disableHandlers = true;
try {
if (currentEvFile.overworlds.Count > 0) {
@@ -4037,8 +4077,15 @@ namespace DSPRE {
/* Determine area data */
byte areaDataID;
if (eventMatrix.hasHeadersSection) {
ushort header = (ushort)eventMatrix.headers[(short)eventMatrixYUpDown.Value, (short)eventMatrixXUpDown.Value];
areaDataID = MapHeader.LoadFromARM9(header).areaDataID;
ushort headerID = (ushort)eventMatrix.headers[(short)eventMatrixYUpDown.Value, (short)eventMatrixXUpDown.Value];
MapHeader h;
if (ROMToolboxDialog.flag_DynamicHeadersPatchApplied || ROMToolboxDialog.CheckFilesDynamicHeadersPatchApplied()) {
h = MapHeader.LoadFromFile(RomInfo.gameDirs[DirNames.dynamicHeaders].unpackedDir + "\\" + headerID.ToString("D4"), headerID, 0);
} else {
h = MapHeader.LoadFromARM9(headerID);
}
areaDataID = h.areaDataID;
} else {
areaDataID = (byte)eventAreaDataUpDown.Value;
}
@@ -5116,26 +5163,26 @@ namespace DSPRE {
}
private void goToWarpDestination_Click(object sender, EventArgs e) {
int destAnchor = (int)warpAnchorUpDown.Value;
ushort destHeader = (ushort)warpHeaderUpDown.Value;
ushort destEventID = MapHeader.LoadFromARM9(destHeader).eventFileID;
EventFile destEvent = new EventFile(destEventID);
ushort destHeaderID = (ushort)warpHeaderUpDown.Value;
MapHeader destHeader = MapHeader.LoadFromARM9(destHeaderID);
if (destEvent.warps.Count < destAnchor + 1) {
if (new EventFile(destHeader.eventFileID).warps.Count < destAnchor + 1) {
DialogResult d = MessageBox.Show("The selected warp's destination anchor doesn't exist.\n" +
"Do you want to open the destination map anyway?", "Warp is not connected", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (d == DialogResult.No)
return;
else {
eventMatrixUpDown.Value = MapHeader.LoadFromARM9((ushort)warpHeaderUpDown.Value).matrixID;
eventAreaDataUpDown.Value = MapHeader.LoadFromARM9((ushort)warpHeaderUpDown.Value).areaDataID;
selectEventComboBox.SelectedIndex = destEventID;
CenterEventviewOnEntities();
eventMatrixUpDown.Value = destHeader.matrixID;
eventAreaDataUpDown.Value = destHeader.areaDataID;
selectEventComboBox.SelectedIndex = destHeader.eventFileID;
CenterEventViewOnEntities();
return;
}
}
eventMatrixUpDown.Value = MapHeader.LoadFromARM9((ushort)warpHeaderUpDown.Value).matrixID;
eventAreaDataUpDown.Value = MapHeader.LoadFromARM9((ushort)warpHeaderUpDown.Value).areaDataID;
selectEventComboBox.SelectedIndex = destEventID;
eventMatrixUpDown.Value = destHeader.matrixID;
eventAreaDataUpDown.Value = destHeader.areaDataID;
selectEventComboBox.SelectedIndex = destHeader.eventFileID;
warpsListBox.SelectedIndex = destAnchor;
centerEventViewOnSelectedEvent_Click(sender, e);
}

View File

@@ -865,7 +865,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABk
EAAAAk1TRnQBSQFMAgEBCAEAAawBEgGsARIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
EAAAAk1TRnQBSQFMAgEBCAEAAbQBEgG0ARIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAATADAAEBAQABCAYAAQwYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
@@ -107,13 +108,10 @@ namespace DSPRE.ROMFiles {
#endregion<EFBFBD>Fields
#region Methods (1)
public static MapHeader BuildFromFile(string filename, ushort headerNumber, long offsetInFile) {
/* Calculate header offset and load data */
byte[] headerData = DSUtils.ReadFromFile(filename, offsetInFile, MapHeader.length);
public static MapHeader LoadFromByteArray(byte[] headerData, ushort headerNumber) {
/* Encapsulate header data into the class appropriate for the gameVersion */
if (headerData.Length < MapHeader.length) {
MessageBox.Show(filename + " is too small and can't store header data.", "Header file too small", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("File of header " + headerNumber + " is too small and can't store header data.", "Header file too small", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
@@ -126,10 +124,17 @@ namespace DSPRE.ROMFiles {
return new HeaderHGSS(headerNumber, new MemoryStream(headerData));
}
}
public static MapHeader LoadFromFile(string filename, ushort headerNumber, long offsetInFile) {
/* Calculate header offset and load data */
byte[] headerData = DSUtils.ReadFromFile(filename, offsetInFile, MapHeader.length);
return LoadFromByteArray(headerData, headerNumber);
}
public static MapHeader LoadFromARM9(ushort headerNumber) {
long headerOffset = Resources.PokeDatabase.System.headerOffsetsDict[RomInfo.romID] + MapHeader.length * headerNumber;
return BuildFromFile(RomInfo.arm9Path, headerNumber, headerOffset);
return LoadFromFile(RomInfo.arm9Path, headerNumber, headerOffset);
}
#endregion
}

View File

@@ -294,6 +294,7 @@ namespace DSPRE {
expandedMatrixCB.Visible = true;
return true;
}
public string backupSuffix = ".backup";
private bool CheckARM9ExpansionApplied() {
if (!ROMToolboxDialog.flag_arm9Expanded) {
if (!ROMToolboxDialog.CheckFilesArm9ExpansionApplied())
@@ -401,8 +402,8 @@ namespace DSPRE {
DialogResult d2;
d2 = MessageBox.Show("This process will apply the following changes:\n\n" +
"- Backup ARM9 file (arm9.bin.backup will be created)." + "\n\n" +
"- Backup Overlay" + data.overlayNumber + " file (overlay" + data.overlayNumber + ".bin.backup will be created)." + "\n\n" +
"- Backup ARM9 file (arm9.bin" + backupSuffix + " will be created)." + "\n\n" +
"- Backup Overlay" + data.overlayNumber + " file (overlay" + data.overlayNumber + ".bin" + backupSuffix + " will be created)." + "\n\n" +
"- Replace " + (data.branchString.Length / 3 + 1) + " bytes of data at arm9 offset 0x" + data.branchOffset.ToString("X") + " with " + '\n' + data.branchString + "\n\n" +
"- Replace " + (data.overlayString1.Length / 3 + 1) + " bytes of data at overlay" + data.overlayNumber + " offset 0x" + data.overlayOffset1.ToString("X") + " with " + '\n' + data.overlayString1 + "\n\n" +
"- Replace " + (data.overlayString2.Length / 3 + 1) + " bytes of data at overlay" + data.overlayNumber + " offset 0x" + data.overlayOffset2.ToString("X") + " with " + '\n' + data.overlayString2 + "\n\n" +
@@ -411,7 +412,7 @@ namespace DSPRE {
"Confirm to proceed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (d2 == DialogResult.Yes) {
File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + ".backup", overwrite: true);
File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + backupSuffix, overwrite: true);
try {
DSUtils.WriteToArm9(DSUtils.HexStringToByteArray(data.branchString), data.branchOffset); //Write new branchOffset
@@ -512,7 +513,7 @@ namespace DSPRE {
DialogResult d;
d = MessageBox.Show("Confirming this process will apply the following changes:\n\n" +
"- Backup ARM9 file (arm9.bin.backup will be created)." + "\n\n" +
"- Backup ARM9 file (arm9.bin" + backupSuffix + " will be created)." + "\n\n" +
"- Replace " + (data.branchString.Length / 3 + 1) + " bytes of data at arm9 offset 0x" + data.branchOffset.ToString("X") + " with " + '\n' + data.branchString + "\n\n" +
"- Replace " + (data.initString.Length / 3 + 1) + " bytes of data at arm9 offset 0x" + data.initOffset.ToString("X") + " with " + '\n' + data.initString + "\n\n" +
"- Modify file #" + expandedARMfileID + " inside " + '\n' + RomInfo.gameDirs[DirNames.synthOverlay].unpackedDir + '\n' + " to accommodate for 88KB of data (no backup)." + "\n\n" +
@@ -520,7 +521,7 @@ namespace DSPRE {
"Confirm to proceed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (d == DialogResult.Yes) {
File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + ".backup", overwrite: true);
File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + backupSuffix, overwrite: true);
try {
DSUtils.WriteToArm9(DSUtils.HexStringToByteArray(data.branchString), data.branchOffset); //Write new branchOffset
@@ -550,7 +551,7 @@ namespace DSPRE {
MessageBox.Show("The ARM9's usable memory has been expanded.", "Operation successful.", MessageBoxButtons.OK, MessageBoxIcon.Information);
} catch {
MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 backup (arm9.bin.backup).", "Something went wrong",
MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 backup (arm9.bin" + backupSuffix + ").", "Something went wrong",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} else {
@@ -592,7 +593,7 @@ namespace DSPRE {
}
}
} catch {
MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 backup (arm9.bin.backup).", "Something went wrong",
MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 backup (arm9.bin" + backupSuffix + ").", "Something went wrong",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
DisableMatrixExpansionPatch("Already applied");
@@ -608,13 +609,13 @@ namespace DSPRE {
DialogResult d;
d = MessageBox.Show("Confirming this process will apply the following changes:\n\n" +
"- Backup ARM9 file (arm9.bin.backup will be created)." + "\n\n" +
"- Backup ARM9 file (arm9.bin" + backupSuffix + " will be created)." + "\n\n" +
"- Non ho sbatti di listare i cambiamenti" + "\n\n" +
"Do you wish to continue?",
"Confirm to proceed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (d == DialogResult.Yes) {
File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + ".backup", overwrite: true);
File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + backupSuffix, overwrite: true);
try {
/* Write main routine (HG USA):
@@ -677,12 +678,11 @@ namespace DSPRE {
foreach (Tuple<uint, uint> 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;
DSUtils.WriteToArm9(BitConverter.GetBytes(pointerValue), (uint)(reference.Item2 + data.pointerDiff));
}
if (RomInfo.gameFamily == "HGSS") {
if (RomInfo.gameFamily == "HGSS" && RomInfo.gameLanguage != "JAP" && RomInfo.gameLanguage != "ESP") {
/* Special case: at 0x3B522 (non-JAP and non-Spanish HG offset) there is an instruction
between the mov r1, #0x18 and mul r1, r0 commands, so we must handle this separately */
@@ -711,7 +711,7 @@ namespace DSPRE {
MessageBox.Show("The headers are now dynamically allocated in memory.", "Operation successful.", MessageBoxButtons.OK, MessageBoxIcon.Information);
} catch {
MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 backup (arm9.bin.backup).", "Something went wrong",
MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 backup (arm9.bin" + backupSuffix + ").", "Something went wrong",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} else {