public void makeBinBackup(int file)
        {
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(ASMDir + "/bak");
            //Console.Out.WriteLine("Backing up " + file + " "+dir.FullName);
            if (!dir.Exists)
            {
                dir.Create();
            }

            dir = new System.IO.DirectoryInfo(ASMDir);
            System.IO.FileStream fs;

            string filename;

            if (file == -1)
            {
                filename = dir.FullName + "/bak/" + "main.bin";
            }
            else
            {
                filename = dir.FullName + "/bak/" + file + ".bin";
            }

            if (System.IO.File.Exists(filename))
            {
                return;
            }

            fs = new System.IO.FileStream(filename, System.IO.FileMode.CreateNew);

            NitroFile f = Program.m_ROM.GetFileFromName("arm9.bin");

            if (file != -1)
            {
                NitroOverlay ov = new NitroOverlay(Program.m_ROM, (uint)file);
                ov.SaveChanges();
                fs.Write(ov.m_Data, 0, f.m_Data.Length);
                fs.Close();
            }
            else
            {
                fs.Write(f.m_Data, 0, f.m_Data.Length);
                fs.Close();
            }
        }
Ejemplo n.º 2
0
        private void btnSave_ButtonClick(object sender, EventArgs e)
        {
            MemoryStream src = new MemoryStream(no.m_Data);
            BinaryReader br  = new BinaryReader(src);

            byte[] oldData = br.ReadBytes((int)tableAddr);

            MemoryStream o  = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(o);

            bw.Write(oldData);
            bw.Write((UInt16)currentTree.Nodes.Count);
            foreach (TreeNode n in currentTree.Nodes)
            {
                bw.Write(Program.m_ROM.GetFileEntries()[Program.m_ROM.GetFileIDFromName(n.Text)].InternalID);
            }
            no.m_Data = o.ToArray();
            no.SaveChanges();
        }
Ejemplo n.º 3
0
        public static bool PatchToSupportBigASMHacks()
        {
            bool autorw = Program.m_ROM.CanRW();

            if (!autorw)
            {
                Program.m_ROM.BeginRW();
            }
            if (Program.m_ROM.Read32(0x6590) != 0) //the patch makes this not 0
            {
                if (!autorw)
                {
                    Program.m_ROM.EndRW();
                }
                return(true);
            }
            if (!autorw)
            {
                Program.m_ROM.EndRW();
            }

            if (MessageBox.Show("This requires the ROM to be further patched. " +
                                "Continue with the patch?", "Table Shifting Patch", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return(false);
            }

            if (!autorw)
            {
                Program.m_ROM.BeginRW();
            }
            NitroOverlay ov2 = new NitroOverlay(Program.m_ROM, 2);

            //Move the ACTOR_SPAWN_TABLE so it can expand
            Program.m_ROM.WriteBlock(0x6590, Program.m_ROM.ReadBlock(0x90864, 0x61c));
            Program.m_ROM.WriteBlock(0x90864, new byte[0x61c]);

            //Adjust pointers
            Program.m_ROM.Write32(0x1a198, 0x02006590);

            //Move the OBJ_TO_ACTOR_TABLE so it can expand
            Program.m_ROM.WriteBlock(0x4b00, ov2.ReadBlock(0x0210cbf4 - ov2.GetRAMAddr(), 0x28c));
            ov2.WriteBlock(0x0210cbf4 - ov2.GetRAMAddr(), new byte[0x28c]);

            //Adjust pointers
            ov2.Write32(0x020fe890 - ov2.GetRAMAddr(), 0x02004b00);
            ov2.Write32(0x020fe958 - ov2.GetRAMAddr(), 0x02004b00);
            ov2.Write32(0x020fea44 - ov2.GetRAMAddr(), 0x02004b00);

            //Add the dynamic library loading and cleanup code
            Program.m_ROM.WriteBlock(0x90864, Properties.Resources.dynamic_library_loader);

            //Add the hooks (by replacing LoadObjBankOverlays())
            Program.m_ROM.WriteBlock(0x2df70, Properties.Resources.static_overlay_loader);

            if (!autorw)
            {
                Program.m_ROM.EndRW();
            }
            ov2.SaveChanges();

            return(true);
        }
Ejemplo n.º 4
0
        public void makeOverlay(uint overlayID)
        {
            FileInfo f = new FileInfo(romdir.FullName + "/newcode.bin");

            if (!f.Exists)
            {
                return;
            }
            FileStream   fs      = f.OpenRead();
            FileInfo     symFile = new FileInfo(romdir.FullName + "/newcode.sym");
            StreamReader symStr  = symFile.OpenText();

            byte[] newdata = new byte[fs.Length];
            fs.Read(newdata, 0, (int)fs.Length);
            fs.Close();


            BinaryWriter newOvl  = new BinaryWriter(new MemoryStream());
            BinaryReader newOvlR = new BinaryReader(newOvl.BaseStream);

            try
            {
                newOvl.Write(newdata);
                alignStream(newOvl.BaseStream, 4);

                uint staticInitCount = 0;

                while (!symStr.EndOfStream)
                {
                    string line = symStr.ReadLine();

                    if (line.Contains("_Z4initv")) //gcc name mangling of init()
                    {
                        uint addr = (uint)parseHex(line.Substring(0, 8));
                        newOvl.Write(addr);
                        ++staticInitCount;
                    }
                }

                /*if (newOvl.BaseStream.Length > 0x4d20)
                 *  throw new InvalidDataException
                 *      ("The overlay must have no more than 19776 bytes; this one will have " + newOvl.BaseStream.Length);*/

                NitroOverlay ovl = new NitroOverlay(Program.m_ROM, overlayID);
                newOvl.BaseStream.Position = 0;
                ovl.SetInitializer(ovl.GetRAMAddr() + (uint)newOvl.BaseStream.Length - 4 * staticInitCount,
                                   4 * staticInitCount);
                ovl.SetSize((uint)newOvl.BaseStream.Length);
                ovl.WriteBlock(0, newOvlR.ReadBytes((int)newOvl.BaseStream.Length));
                ovl.SaveChanges();
            }
            catch (Exception ex)
            {
                new ExceptionMessageBox("Error", ex).ShowDialog();
                return;
            }
            finally
            {
                symStr.Close();
                newOvl.Dispose();
                newOvlR.Close();
            }
        }