コード例 #1
0
        private INitroROMBlock InitialiseDataForObject(LevelObject.Type type)
        {
            INitroROMBlock data = new INitroROMBlock();

            data.m_Data = new byte[k_LevelObjTypeSizes[(int)type]]; //of zeros
            return(data);
        }
コード例 #2
0
        private INitroROMBlock InitialiseDataForObject(LevelObject.Type type, ushort id)
        {
            INitroROMBlock data = InitialiseDataForObject(type);

            data.Write16(0, id);
            return(data);
        }
コード例 #3
0
        public void RemovePatch(NitroROM rom)
        {
            List <AddressDataPair> addressDataPairs = null;

            switch (rom.m_Version)
            {
            case NitroROM.Version.EUR:
                addressDataPairs = m_EURRestoreData;
                break;

            case NitroROM.Version.USA_v1:
                addressDataPairs = m_USv1RestoreData;
                break;

            case NitroROM.Version.USA_v2:
                addressDataPairs = m_USv2RestoreData;
                break;

            case NitroROM.Version.JAP:
                addressDataPairs = m_JAPRestoreData;
                break;
            }

            INitroROMBlock fileToPatch = null;

            if (m_FileToPatch != null)
            {
                fileToPatch = Program.m_ROM.GetFileFromName(m_FileToPatch);
            }
            else if (m_OverlayID != null)
            {
                fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(m_OverlayID));
            }

            foreach (AddressDataPair addressDataPair in addressDataPairs)
            {
                for (int i = 0; i < addressDataPair.m_Data.Length; i++)
                {
                    if (fileToPatch == null)
                    {
                        rom.Write8(addressDataPair.m_Address + (uint)i, addressDataPair.m_Data[i]);
                    }
                    else
                    {
                        fileToPatch.Write8(addressDataPair.m_Address + (uint)i, addressDataPair.m_Data[i]);
                    }
                }
            }

            if (fileToPatch != null)
            {
                fileToPatch.SaveChanges();
            }
        }
コード例 #4
0
        public static List <AddressDataPair> GenerateRestoreData(List <AddressDataPair> patchData, string fileName = null, string overlayID = null)
        {
            List <AddressDataPair> restoreDataList = new List <AddressDataPair>();

            INitroROMBlock fileToPatch = null;

            if (fileName != null)
            {
                fileToPatch = Program.m_ROM.GetFileFromName(fileName);
            }
            else if (overlayID != null)
            {
                fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(overlayID));
            }

            foreach (AddressDataPair addressDataPair in patchData)
            {
                AddressDataPair restoreData = new AddressDataPair();
                restoreData.m_Address = addressDataPair.m_Address;

                List <byte> data = new List <byte>();
                for (int i = 0; i < addressDataPair.m_Data.Length; i++)
                {
                    if (fileToPatch == null)
                    {
                        if (Program.m_IsROMFolder)
                        {
                            Program.m_ROM.arm9R.BaseStream.Position = addressDataPair.m_Address + (uint)i - Program.m_ROM.headerSize;
                            data.Add(Program.m_ROM.arm9R.ReadByte());
                        }
                        else
                        {
                            data.Add(Program.m_ROM.Read8(addressDataPair.m_Address + (uint)i));
                        }
                    }
                    else
                    {
                        data.Add(fileToPatch.Read8(addressDataPair.m_Address + (uint)i));
                    }
                }
                restoreData.m_Data = data.ToArray();

                restoreDataList.Add(restoreData);
            }

            return(restoreDataList);
        }
コード例 #5
0
        private void ReadObjectTable(NitroOverlay ovl, uint offset, int area)
        {
            uint subtbl_num    = ovl.Read32(offset);
            uint subtbl_offset = ovl.ReadPointer(offset + 0x4);

            for (uint st = 0; st < subtbl_num; st++)
            {
                uint curoffset = subtbl_offset + (st * 8);

                byte flags          = ovl.Read8(curoffset);
                byte entries_num    = ovl.Read8(curoffset + 0x1);
                uint entries_offset = ovl.ReadPointer(curoffset + 0x4);

                byte type  = (byte)(flags & 0x1F);
                byte layer = (byte)(flags >> 5);

                if (type == 11)
                {
                    m_MinimapFileIDs = new ushort[entries_num];
                }

                for (byte e = 0; e < entries_num; ++e)
                {
                    LevelObject    obj;
                    INitroROMBlock objData = new INitroROMBlock();
                    objData.m_Data = ovl.ReadBlock((uint)(entries_offset + e * k_LevelObjTypeSizes[type]), (uint)k_LevelObjTypeSizes[type]);
                    switch (type)
                    {
                    case 0:
                        obj = new StandardObject(objData, m_LevelObjects.Count, layer, area);
                        break;

                    case 1:
                        obj = new EntranceObject(objData, m_LevelObjects.Count, layer, m_EntranceID++);
                        break;

                    case 2:     // Path Node
                        obj = new PathPointObject(objData, m_LevelObjects.Count, m_PathNodeID++);
                        break;

                    case 3:     // Path
                        obj = new PathObject(objData, m_LevelObjects.Count, (ushort)m_PathID++);
                        break;

                    case 4:
                        obj = new ViewObject(objData, m_LevelObjects.Count, m_ViewID++);
                        break;

                    case 5:
                        obj = new SimpleObject(objData, m_LevelObjects.Count, layer, area);
                        break;

                    case 6:
                        obj = new TpSrcObject(objData, m_LevelObjects.Count, layer);
                        break;

                    case 7:
                        obj = new TpDstObject(objData, m_LevelObjects.Count, layer);
                        break;

                    case 8:
                        // Fog
                        obj = new FogObject(objData, m_LevelObjects.Count, layer, area);
                        break;

                    case 9:
                        obj = new DoorObject(objData, m_LevelObjects.Count, layer);
                        break;

                    case 10:
                        obj = new ExitObject(objData, m_LevelObjects.Count, layer);
                        break;

                    case 11:
                        obj = new MinimapTileIDObject(objData, m_LevelObjects.Count, layer, m_MinimapTileIDNum++);
                        // This is still used by Minimap Editor
                        m_MinimapFileIDs[e] = ovl.Read16((uint)(entries_offset + (e * 2)));
                        break;

                    case 12:
                        // per-area minimap scale factors
                        obj = new MinimapScaleObject(objData, m_LevelObjects.Count, layer, area);
                        break;

                    case 14:
                        // ??? Unknown
                        obj = new Type14Object(objData, m_LevelObjects.Count, layer, area);
                        break;

                    default:
                        throw new InvalidDataException("Bad object type: " + type);
                    }

                    m_LevelObjects.Add(obj.m_UniqueID, obj);
                }
            }
        }
コード例 #6
0
        public void ApplyPatch(NitroROM rom)
        {
            Program.m_ROM.BeginRW();
            List <AddressDataPair> addressDataPairs = null;

            switch (rom.m_Version)
            {
            case NitroROM.Version.EUR:
                addressDataPairs = m_EURPatch;
                m_EURRestoreData = GenerateRestoreData(m_EURPatch);
                break;

            case NitroROM.Version.USA_v1:
                addressDataPairs  = m_USv1Patch;
                m_USv1RestoreData = GenerateRestoreData(m_USv1Patch);
                break;

            case NitroROM.Version.USA_v2:
                addressDataPairs  = m_USv2Patch;
                m_USv2RestoreData = GenerateRestoreData(m_USv2Patch);
                break;

            case NitroROM.Version.JAP:
                addressDataPairs = m_JAPPatch;
                m_JAPRestoreData = GenerateRestoreData(m_JAPPatch);
                break;
            }

            if (m_DecompressAllOverlays)
            {
                Helper.DecompressOverlaysWithinGame();
            }

            if (m_FileToPatch != null)
            {
                NitroFile myFile = Program.m_ROM.GetFileFromName(m_FileToPatch);

                foreach (AddressDataPair addressDataPair in addressDataPairs)
                {
                    for (int i = 0; i < addressDataPair.m_Data.Length; i++)
                    {
                        myFile.Write8(addressDataPair.m_Address + (uint)i, addressDataPair.m_Data[i]);
                    }
                }

                Program.m_ROM.EndRW();
                myFile.SaveChanges();
                return;
            }

            INitroROMBlock fileToPatch = null;

            if (m_FileToPatch != null)
            {
                fileToPatch = Program.m_ROM.GetFileFromName(m_FileToPatch);
            }
            else if (m_OverlayID != null)
            {
                fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(m_OverlayID));
            }

            foreach (AddressDataPair addressDataPair in addressDataPairs)
            {
                for (int i = 0; i < addressDataPair.m_Data.Length; i++)
                {
                    if (fileToPatch == null)
                    {
                        if (Program.m_IsROMFolder)
                        {
                            Program.m_ROM.arm9W.BaseStream.Position = addressDataPair.m_Address + (uint)i - Program.m_ROM.headerSize;
                            Program.m_ROM.arm9W.Write(addressDataPair.m_Data[i]);
                        }
                        else
                        {
                            rom.Write8(addressDataPair.m_Address + (uint)i, addressDataPair.m_Data[i]);
                        }
                    }
                    else
                    {
                        fileToPatch.Write8(addressDataPair.m_Address + (uint)i, addressDataPair.m_Data[i]);
                    }
                }
            }

            Program.m_ROM.EndRW();

            if (fileToPatch != null)
            {
                fileToPatch.SaveChanges();
            }
        }
コード例 #7
0
        /*
         * This method takes the first Address and Data from the patch and tests if the current values in the
         * ROM match the values of the patch - if they match the patch is already applied. This doesn't test
         * all values to speed things up.
         */
        public bool CheckIsApplied(NitroROM rom)
        {
            if (m_DecompressAllOverlays && Helper.CheckAllOverlaysDecompressed() == false)
            {
                m_IsApplied = false;
                return(false);
            }

            INitroROMBlock fileToPatch = null;

            if (m_FileToPatch != null)
            {
                fileToPatch = Program.m_ROM.GetFileFromName(m_FileToPatch);
            }
            else if (m_OverlayID != null)
            {
                fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(m_OverlayID));
            }

            AddressDataPair testAddressDataPair = null;

            switch (rom.m_Version)
            {
            case NitroROM.Version.EUR:
                testAddressDataPair = (m_EURPatch.Count == 0) ? null : m_EURPatch.ElementAt(0);
                break;

            case NitroROM.Version.USA_v1:
                testAddressDataPair = (m_USv1Patch.Count == 0) ? null : m_USv1Patch.ElementAt(0);
                break;

            case NitroROM.Version.USA_v2:
                testAddressDataPair = (m_USv2Patch.Count == 0) ? null : m_USv2Patch.ElementAt(0);
                break;

            case NitroROM.Version.JAP:
                testAddressDataPair = (m_JAPPatch.Count == 0) ? null : m_JAPPatch.ElementAt(0);
                break;
            }

            if (testAddressDataPair == null || testAddressDataPair.m_Data == null || testAddressDataPair.m_Data.Length == 0)
            {
                m_IsApplied = false;
                return(false);
            }

            for (int i = 0; i < testAddressDataPair.m_Data.Length; i++)
            {
                if (fileToPatch == null)
                {
                    if (Program.m_IsROMFolder)
                    {
                        Program.m_ROM.arm9R.BaseStream.Position = testAddressDataPair.m_Address + (uint)i - Program.m_ROM.headerSize;
                        if (Program.m_ROM.arm9R.ReadByte() != testAddressDataPair.m_Data[i])
                        {
                            m_IsApplied = false;
                            return(false);
                        }
                    }
                    else
                    {
                        if (rom.Read8(testAddressDataPair.m_Address + (uint)i) != testAddressDataPair.m_Data[i])
                        {
                            m_IsApplied = false;
                            return(false);
                        }
                    }
                }
                else if (fileToPatch != null && fileToPatch.Read8(testAddressDataPair.m_Address + (uint)i) != testAddressDataPair.m_Data[i])
                {
                    m_IsApplied = false;
                    return(false);
                }
            }

            //If it reaches here, the patch has already been applied
            m_IsApplied = true;
            return(true);
        }