示例#1
0
        private void BDHCAMPatchButton_Click(object sender, EventArgs e)
        {
            BDHCAMPatchData data = new BDHCAMPatchData();

            if (RomInfo.gameVersion == "HG" || RomInfo.gameVersion == "SS")
            {
                if (DSUtils.CheckOverlayHasCompressionFlag(data.overlayNumber))
                {
                    DialogResult d1;
                    d1 = MessageBox.Show("It is STRONGLY recommended to configure Overlay1 as uncompressed before proceeding.\n\n" +
                                         "More details in the following dialog.\n\n" + "Do you want to know more?",
                                         "Confirm to proceed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (d1 == DialogResult.Yes)
                    {
                        overlay1uncomprButton_Click(null, null);
                    }
                }
            }

            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" +
                                 "- 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" +
                                 "- Modify file #" + expandedARMfileID + " inside " + '\n' + RomInfo.syntheticOverlayPath + '\n' + "to insert the BDHCAM routine (any data between 0x" + data.subroutineOffset.ToString("X") + " and 0x" + data.subroutineOffset + data.subroutine.Length.ToString("X") + " will be overwritten)." + "\n\n" +
                                 "Do you wish to continue?",
                                 "Confirm to proceed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (d2 == DialogResult.Yes)
            {
                File.Copy(RomInfo.arm9Path, RomInfo.arm9Path + ".backup", overwrite: true);

                try {
                    DSUtils.WriteToArm9(data.branchOffset, HexStringtoByteArray(data.branchString)); //Write new branchOffset

                    /* Write to overlayfile */
                    string overlayFilePath = RomInfo.workDir + "overlay" + "\\" + "overlay_" + data.overlayNumber.ToString("D4") + ".bin";
                    if (DSUtils.OverlayIsCompressed(data.overlayNumber))
                    {
                        DSUtils.DecompressOverlay(data.overlayNumber, true);
                    }

                    DSUtils.WriteToFile(overlayFilePath, data.overlayOffset1, HexStringtoByteArray(data.overlayString1)); //Write new overlayCode1
                    DSUtils.WriteToFile(overlayFilePath, data.overlayOffset2, HexStringtoByteArray(data.overlayString2)); //Write new overlayCode2
                    overlay1MustBeRestoredFromBackup = false;

                    String fullFilePath = RomInfo.syntheticOverlayPath + '\\' + expandedARMfileID.ToString("D4");

                    /*Write Expanded ARM9 File*/
                    DSUtils.WriteToFile(fullFilePath, data.subroutineOffset, data.subroutine);
                } catch {
                    MessageBox.Show("Operation failed. It is strongly advised that you restore the arm9 and overlay from their respective backups.", "Something went wrong",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                flag_BDHCAMpatchApplied          = true;
                overlay1MustBeRestoredFromBackup = false;

                disableBDHCAMpatch();
                bdhcamCB.Visible       = true;
                BDHCAMpatchButton.Text = "Already applied";

                MessageBox.Show("The BDHCAM patch has been applied.", "Operation successful.", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("No changes have been made.", "Operation canceled", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#2
0
        private int CheckFilesBDHCAMpatchApplied()
        {
            if (!flag_arm9Expanded)
            {
                bdhcamARM9requiredLBL.Visible = true;
                disableBDHCAMpatch();
                return(0);
            }

            if (!flag_BDHCAMpatchApplied)
            {
                BDHCAMPatchData data = new BDHCAMPatchData();
                try {
                    byte[] branchCode     = HexStringtoByteArray(data.branchString);
                    byte[] branchCodeRead = DSUtils.ReadFromArm9(data.branchOffset, branchCode.Length);

                    if (branchCode.Length != branchCodeRead.Length)
                    {
                        return(0); //0 means BDHCAM patch has not been applied
                    }
                    if (!branchCode.SequenceEqual(branchCodeRead))
                    {
                        return(0);
                    }


                    string overlayFilePath = RomInfo.workDir + "overlay" + "\\" + "overlay_" + data.overlayNumber.ToString("D4") + ".bin";
                    DSUtils.DecompressOverlay(data.overlayNumber, true);

                    byte[] overlayCode1     = HexStringtoByteArray(data.overlayString1);
                    byte[] overlayCode1Read = DSUtils.ReadFromFile(overlayFilePath, data.overlayOffset1, overlayCode1.Length);
                    if (overlayCode1.Length != overlayCode1Read.Length)
                    {
                        return(0); //0 means BDHCAM patch has not been applied
                    }
                    if (!overlayCode1.SequenceEqual(overlayCode1Read))
                    {
                        return(0);
                    }


                    byte[] overlayCode2     = HexStringtoByteArray(data.overlayString2);
                    byte[] overlayCode2Read = DSUtils.ReadFromFile(overlayFilePath, data.overlayOffset2, overlayCode2.Length); //Write new overlayCode1
                    if (overlayCode2.Length != overlayCode2Read.Length)
                    {
                        return(0); //0 means BDHCAM patch has not been applied
                    }
                    if (!overlayCode2.SequenceEqual(overlayCode2Read))
                    {
                        return(0);
                    }

                    String fullFilePath   = RomInfo.syntheticOverlayPath + '\\' + expandedARMfileID.ToString("D4");
                    byte[] subroutineRead = DSUtils.ReadFromFile(fullFilePath, data.subroutineOffset, data.subroutine.Length); //Write new overlayCode1
                    if (data.subroutine.Length != subroutineRead.Length)
                    {
                        return(0); //0 means BDHCAM patch has not been applied
                    }
                    if (!data.subroutine.SequenceEqual(subroutineRead))
                    {
                        return(0);
                    }
                } catch {
                    return(-1);
                }
            }
            flag_BDHCAMpatchApplied = true;
            bdhcamCB.Visible        = true;

            disableBDHCAMpatch();
            BDHCAMpatchButton.Text = "Already applied";
            return(0);
        }