Exemplo n.º 1
0
 public byte[] GetDecompressedARM9()
 {
     if (StaticFooter != null)
     {
         return(ARM9.Decompress(MainRom, StaticFooter._start_ModuleParamsOffset));
     }
     else
     {
         return(ARM9.Decompress(MainRom));
     }
 }
Exemplo n.º 2
0
        public void Insert(String Path, ARM9 Arm9)
        {
            ASMHackInfo Info = ASMHackInfo.FromByteArray(File.ReadAllBytes(Path + "\\config.xml"));

            UInt32 ArenaLoOffset = Info.ArenaLo;            //UInt32.Parse(File.ReadAllText(CodeDir + "\\arenaoffs.txt"), System.Globalization.NumberStyles.HexNumber);
            UInt32 ArenaLo       = Arm9.ReadU32LE(ArenaLoOffset);

            Compile(Path, ArenaLo);
            if (!File.Exists(Path + "\\newcode.bin"))
            {
                MessageBox.Show("An compile error occurred!");
                return;
            }
            byte[] NewCode = File.ReadAllBytes(Path + "\\newcode.bin");

            StreamReader r = new StreamReader(Path + "\\newcode.sym");
            string       CurrentLine;

            while ((CurrentLine = r.ReadLine()) != null)
            {
                string[] Line = CurrentLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (Line.Length == 4)
                {
                    if (Line[3].Length < 7)
                    {
                        continue;
                    }
                    switch (Line[3].Remove(6))
                    {
                    case "arepl_":
                    {
                        String ReplaceOffsetString       = Line[3].Replace("arepl_", "");
                        UInt32 ReplaceOffset             = UInt32.Parse(ReplaceOffsetString, System.Globalization.NumberStyles.HexNumber);
                        UInt32 Replace                   = 0xEB000000;                      //BL Instruction
                        UInt32 DestinationOffset         = UInt32.Parse(Line[0], System.Globalization.NumberStyles.HexNumber);
                        UInt32 RelativeDestinationOffset = (DestinationOffset / 4) - (ReplaceOffset / 4) - 2;
                        RelativeDestinationOffset &= 0x00FFFFFF;
                        Replace |= RelativeDestinationOffset;
                        if (!Arm9.WriteU32LE(ReplaceOffset, Replace))
                        {
                            System.Windows.Forms.MessageBox.Show("The offset of function " + Line[3] + " is invalid. Maybe your code is inside an overlay or you wrote the wrong offset.");
                        }
                        break;
                    }

                    case "ansub_":
                    {
                        String ReplaceOffsetString       = Line[3].Replace("ansub_", "");
                        UInt32 ReplaceOffset             = UInt32.Parse(ReplaceOffsetString, System.Globalization.NumberStyles.HexNumber);
                        UInt32 Replace                   = 0xEA000000;                      //B Instruction
                        UInt32 DestinationOffset         = UInt32.Parse(Line[0], System.Globalization.NumberStyles.HexNumber);
                        UInt32 RelativeDestinationOffset = (DestinationOffset / 4) - (ReplaceOffset / 4) - 2;
                        RelativeDestinationOffset &= 0x00FFFFFF;
                        Replace |= RelativeDestinationOffset;
                        if (!Arm9.WriteU32LE(ReplaceOffset, Replace))
                        {
                            System.Windows.Forms.MessageBox.Show("The offset of function " + Line[3] + " is invalid. Maybe your code is inside an overlay or you wrote the wrong offset.");
                        }
                        break;
                    }

                    case "trepl_":
                    {
                        String ReplaceOffsetString       = Line[3].Replace("trepl_", "");
                        UInt32 ReplaceOffset             = UInt32.Parse(ReplaceOffsetString, System.Globalization.NumberStyles.HexNumber);
                        UInt16 Replace1                  = 0xF000;                       //BLX Instruction (Part 1)
                        UInt16 Replace2                  = 0xE800;                       //BLX Instruction (Part 2)
                        UInt32 DestinationOffset         = UInt32.Parse(Line[0], System.Globalization.NumberStyles.HexNumber);
                        UInt32 RelativeDestinationOffset = DestinationOffset - ReplaceOffset - 2;
                        RelativeDestinationOffset >>= 1;
                        RelativeDestinationOffset  &= 0x003FFFFF;
                        Replace1 |= (UInt16)((RelativeDestinationOffset >> 11) & 0x7FF);
                        Replace2 |= (UInt16)((RelativeDestinationOffset >> 0) & 0x7FE);
                        if (!Arm9.WriteU16LE(ReplaceOffset, Replace1))
                        {
                            MessageBox.Show("The offset of function " + Line[3] + " is invalid. Maybe your code is inside an overlay or you wrote the wrong offset.\r\nIf your code is inside an overlay, this is an action replay code to let your asm hack still work:\r\n1" + string.Format("{0:X7}", ReplaceOffset) + " 0000" + string.Format("{0:X4}", Replace1) + "\r\n1" + string.Format("{0:X7}", ReplaceOffset + 2) + " 0000" + string.Format("{0:X4}", Replace2)); break;
                        }
                        else
                        {
                            Arm9.WriteU16LE(ReplaceOffset + 2, Replace2);
                        }
                        break;
                    }
                    }
                }
            }
            r.Close();
            Arm9.WriteU32LE(ArenaLoOffset, ArenaLo + (uint)NewCode.Length);
            Arm9.AddAutoLoadEntry(ArenaLo, NewCode);
            File.Delete(Path + "\\newcode.bin");
            File.Delete(Path + "\\newcode.elf");
            File.Delete(Path + "\\newcode.sym");
            Directory.Delete(Path + "\\build", true);
        }
Exemplo n.º 3
0
        public void Insert(String Path, ARM9 Arm9)
        {
            ASMHackInfo Info = ASMHackInfo.FromByteArray(File.ReadAllBytes(Path + "\\config.xml"));

            UInt32 ArenaLoOffset = Info.ArenaLo;//UInt32.Parse(File.ReadAllText(CodeDir + "\\arenaoffs.txt"), System.Globalization.NumberStyles.HexNumber);
            UInt32 ArenaLo = Arm9.ReadU32LE(ArenaLoOffset);
            Compile(Path, ArenaLo);
            if (!File.Exists(Path + "\\newcode.bin"))
            {
                MessageBox.Show("An compile error occurred!");
                return;
            }
            byte[] NewCode = File.ReadAllBytes(Path + "\\newcode.bin");

            StreamReader r = new StreamReader(Path + "\\newcode.sym");
            string CurrentLine;
            while ((CurrentLine = r.ReadLine()) != null)
            {
                string[] Line = CurrentLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (Line.Length == 4)
                {
                    if (Line[3].Length < 7) continue;
                    switch (Line[3].Remove(6))
                    {
                        case "arepl_":
                            {
                                String ReplaceOffsetString = Line[3].Replace("arepl_", "");
                                UInt32 ReplaceOffset = UInt32.Parse(ReplaceOffsetString, System.Globalization.NumberStyles.HexNumber);
                                UInt32 Replace = 0xEB000000;//BL Instruction
                                UInt32 DestinationOffset = UInt32.Parse(Line[0], System.Globalization.NumberStyles.HexNumber);
                                UInt32 RelativeDestinationOffset = (DestinationOffset / 4) - (ReplaceOffset / 4) - 2;
                                RelativeDestinationOffset &= 0x00FFFFFF;
                                Replace |= RelativeDestinationOffset;
                                if (!Arm9.WriteU32LE(ReplaceOffset, Replace)) System.Windows.Forms.MessageBox.Show("The offset of function " + Line[3] + " is invalid. Maybe your code is inside an overlay or you wrote the wrong offset.");
                                break;
                            }
                        case "ansub_":
                            {
                                String ReplaceOffsetString = Line[3].Replace("ansub_", "");
                                UInt32 ReplaceOffset = UInt32.Parse(ReplaceOffsetString, System.Globalization.NumberStyles.HexNumber);
                                UInt32 Replace = 0xEA000000;//B Instruction
                                UInt32 DestinationOffset = UInt32.Parse(Line[0], System.Globalization.NumberStyles.HexNumber);
                                UInt32 RelativeDestinationOffset = (DestinationOffset / 4) - (ReplaceOffset / 4) - 2;
                                RelativeDestinationOffset &= 0x00FFFFFF;
                                Replace |= RelativeDestinationOffset;
                                if (!Arm9.WriteU32LE(ReplaceOffset, Replace)) System.Windows.Forms.MessageBox.Show("The offset of function " + Line[3] + " is invalid. Maybe your code is inside an overlay or you wrote the wrong offset.");
                                break;
                            }
                        case "trepl_":
                            {
                                String ReplaceOffsetString = Line[3].Replace("trepl_", "");
                                UInt32 ReplaceOffset = UInt32.Parse(ReplaceOffsetString, System.Globalization.NumberStyles.HexNumber);
                                UInt16 Replace1 = 0xF000;//BLX Instruction (Part 1)
                                UInt16 Replace2 = 0xE800;//BLX Instruction (Part 2)
                                UInt32 DestinationOffset = UInt32.Parse(Line[0], System.Globalization.NumberStyles.HexNumber);
                                UInt32 RelativeDestinationOffset = DestinationOffset - ReplaceOffset - 2;
                                RelativeDestinationOffset >>= 1;
                                RelativeDestinationOffset &= 0x003FFFFF;
                                Replace1 |= (UInt16)((RelativeDestinationOffset >> 11) & 0x7FF);
                                Replace2 |= (UInt16)((RelativeDestinationOffset >> 0) & 0x7FE);
                                if (!Arm9.WriteU16LE(ReplaceOffset, Replace1)) { MessageBox.Show("The offset of function " + Line[3] + " is invalid. Maybe your code is inside an overlay or you wrote the wrong offset.\r\nIf your code is inside an overlay, this is an action replay code to let your asm hack still work:\r\n1" + string.Format("{0:X7}", ReplaceOffset) + " 0000" + string.Format("{0:X4}", Replace1) + "\r\n1" + string.Format("{0:X7}", ReplaceOffset + 2) + " 0000" + string.Format("{0:X4}", Replace2)); break; }
                                else Arm9.WriteU16LE(ReplaceOffset + 2, Replace2);
                                break;
                            }
                    }
                }
            }
            r.Close();
            Arm9.WriteU32LE(ArenaLoOffset, ArenaLo + (uint)NewCode.Length);
            Arm9.AddAutoLoadEntry(ArenaLo, NewCode);
            File.Delete(Path + "\\newcode.bin");
            File.Delete(Path + "\\newcode.elf");
            File.Delete(Path + "\\newcode.sym");
            Directory.Delete(Path + "\\build", true);
        }