private void ApplyARM9ExpansionButton_Click(object sender, EventArgs e) { ARM9PatchData data = new ARM9PatchData(); 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" + "- 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.syntheticOverlayPath + '\n' + " to accommodate for 88KB of data (no backup)." + "\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); try { DSUtils.WriteToArm9(data.branchOffset, HexStringtoByteArray(data.branchString)); //Write new branchOffset DSUtils.WriteToArm9(data.initOffset, HexStringtoByteArray(data.initString)); //Write new initOffset string fullFilePath = RomInfo.syntheticOverlayPath + '\\' + expandedARMfileID.ToString("D4"); File.Delete(fullFilePath); using (BinaryWriter f = new BinaryWriter(File.Create(fullFilePath))) { for (int i = 0; i < 0x16000; i++) { f.Write((byte)0x00); // Write Expanded ARM9 File } } arm9patchCB.Visible = true; flag_arm9Expanded = true; disableARM9patch(); applyARM9ExpansionButton.Text = "Already applied"; switch (RomInfo.gameVersion) { case "Plat": case "HG": case "SS": bdhcamARM9requiredLBL.Visible = false; BDHCAMpatchButton.Enabled = true; BDHCAMpatchLBL.Enabled = true; BDHCAMpatchTextLBL.Enabled = true; break; } 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", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No changes have been made.", "Operation canceled", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private int CheckARM9Expansion() { if (!flag_arm9Expanded) { ARM9PatchData data = new ARM9PatchData(); try { byte[] branchCode = HexStringtoByteArray(data.branchString); byte[] branchCodeRead = DSUtils.ReadFromArm9(data.branchOffset, data.branchString.Length / 3 + 1); //Read branchCode if (branchCodeRead.Length != branchCode.Length) { return(0); //0 means ARM9 Expansion has never been applied } if (!branchCodeRead.SequenceEqual(branchCode)) { return(0); } byte[] initCode = HexStringtoByteArray(data.initString); byte[] initCodeRead = DSUtils.ReadFromArm9(data.initOffset, data.initString.Length / 3 + 1); //Read initCode if (initCodeRead.Length != initCode.Length) { return(0); } if (!initCodeRead.SequenceEqual(initCode)) { return(0); } } catch { return(-1); //1 means Check failure } } applyARM9ExpansionButton.Enabled = false; arm9expansionTextLBL.Enabled = false; arm9expansionLBL.Enabled = false; arm9patchCB.Visible = true; applyARM9ExpansionButton.Text = "Already applied"; flag_arm9Expanded = true; switch (RomInfo.gameVersion) { case "Plat": case "HG": case "SS": bdhcamARM9requiredLBL.Visible = false; BDHCAMpatchButton.Enabled = true; BDHCAMpatchLBL.Enabled = true; BDHCAMpatchTextLBL.Enabled = true; break; } return(1); //arm9 Expansion has already been applied }