Пример #1
0
        public static string GetEntranceCount(FileStream sr)
        {
            List <byte[]> list = new List <byte[]>();

            byte[]        word = new byte[4];
            int           foundIndex;
            StringBuilder result = new StringBuilder();

            sr.Seek(Addresser.GetRom(ORom.FileList.code, ORom.Build.DBGMQ, "EntranceIndexTable_Start"),
                    SeekOrigin.Begin);
            for (int i = 0; i < 0x614; i++)
            {
                sr.Read(word, 0, 4);
                foundIndex = list.FindIndex(item => item[0] == word[0]);
                if (foundIndex == -1)
                {
                    list.Add(new byte[] { word[0], word[1] });
                }
                else if (list[foundIndex][1] < word[1])
                {
                    list[foundIndex][1] = word[1];
                }
            }
            foreach (byte[] item in list)
            {
                result.AppendLine($"{item[0]}, {(item[1] + 1)}");
            }
            return(result.ToString());
        }
Пример #2
0
        //get scene file from mqd folder
        //get file size
        //add file to location ref by FileTable_Open
        //update file table record after FileTable_Open
        //add rooms
        //update root scene's room addresses

        /// <summary>
        /// Imports a select set of scenes into a designated rom
        /// </summary>
        /// <param name="romfile">The rom being modified</param>
        /// <param name="scenesLocation">The location of the scene/room files</param>
        /// <param name="version">The target version of the rom</param>
        /// <param name="importScenes">the scenes to import</param>
        public static void ImportToUncompressedRom(string romfile, RomVersion version, string sceneFilesLocation, List <int> importScenes)
        {
            FileTable_Off    = Addresser.GetRom(ORom.FileList.dmadata, version, "Scenes_Start");
            SceneTable_Start = Addresser.GetRom(ORom.FileList.code, version, "SceneTable_Start");

            int NextWriteAddress;

            using (FileStream fs_r = new FileStream(romfile, FileMode.Open, FileAccess.ReadWrite))
            {
                BinaryReader addrReader = new BinaryReader(fs_r);
                addrReader.BaseStream.Position = FileTable_Off;
                NextWriteAddress = addrReader.ReadBigInt32();
                BinaryWriter bw = new BinaryWriter(fs_r);

                //wipe the scene table
                for (int i = 0; i < 101; i++)
                {
                    UpdateSceneTable(bw, i, new FileAddress(0, 0));
                }

                foreach (int sceneIndex in importScenes)
                {
                    AddSceneAndRooms(sceneIndex, ref NextWriteAddress, sceneFilesLocation, bw);
                }
            }
        }
Пример #3
0
        public static void MMEntranceTable(IExperimentFace face, List <string> file)
        {
            MRom rom = new(file[0], MRom.Build.U0);

            //scenes (7 bits, 0x6E max)
            //entrance sets (5 bits, 32 max)

            //entrance setups(32 max)
            StringBuilder sb   = new();
            RomFile       code = rom.Files.GetFile(MRom.FileList.code);
            BinaryReader  br   = new(code);
            int           sceneBase;

            //Sets of entrance records per scene
            int  entranceSetsPointerAddr;
            uint entranceSetsPointer;
            int  entranceSetsAddr;

            //Single set of entrance records (single entrance)
            int  eNumPointerAddr;
            uint eNumPointer;
            int  eNumAddr;

            //get rom address of sceneTableBase
            sceneBase = Addresser.GetRom(MRom.FileList.code, rom.Version, AddressToken.EntranceIndexTable_Start);

            //for every scene
            for (int scene = 0; scene < 0x6E; scene++)
            {
                //get offset of pointer to the entrance sets
                entranceSetsPointerAddr = sceneBase + (sizeof(int) * 3) * scene + 4;

                //move the stream to the entrance sets pointer
                br.BaseStream.Position = code.Record.GetRelativeAddress(entranceSetsPointerAddr);

                //read the entranceSetsPointer (scene)
                entranceSetsPointer = br.ReadBigUInt32();

                //if invalid
                if (!IsPointer(entranceSetsPointer) ||
                    !Addresser.TryGetRom
                        (MRom.FileList.code, rom.Version, entranceSetsPointer, out entranceSetsAddr) ||
                    code.Record.GetRelativeAddress(entranceSetsAddr) >= code.Record.VRom.End)
                {
                    //entrance index base, offset, sptr, eptr, entb1,2,3,4
                    sb.AppendFormat("{0:X4},{1},{2:X8},{3:X8},{4:X2},{5:X2},{6:X2},{7:X2}",
                                    GetEntranceIndex(scene, 0),
                                    0,
                                    entranceSetsPointer,
                                    0,
                                    255, 0, 0, 0);
                    sb.AppendLine();
                    continue;
                }

                //entranceSetsAddr now contains the rom address to the first entrance set pointer

                //for every theoretical entrance set
                for (int entranceSet = 0; entranceSet < 32; entranceSet++)
                {
                    eNumPointerAddr = entranceSetsAddr + (sizeof(UInt32) * entranceSet);

                    //move the stream to the entrance set pointer
                    br.BaseStream.Position = code.Record.GetRelativeAddress(eNumPointerAddr);

                    //read the entranceSetPointer (entrance set)
                    eNumPointer = br.ReadBigUInt32();

                    //if invalid
                    if (!IsPointer(eNumPointer) ||
                        !Addresser.TryGetRom
                            (MRom.FileList.code, rom.Version, eNumPointer, out eNumAddr) ||
                        code.Record.GetRelativeAddress(eNumAddr) >= code.Record.VRom.End)
                    {
                        //entrance index base, offset, sptr, eptr, entb1,2,3,4
                        sb.AppendFormat("{0:X4},{1},{2:X8},{3:X8},{4:X2},{5:X2},{6:X2},{7:X2}",
                                        GetEntranceIndex(scene, entranceSet),
                                        0,
                                        entranceSetsPointer,
                                        eNumPointer,
                                        255, 0, 0, 0);
                        sb.AppendLine();
                        continue;
                    }
                    //eNumAddr is valid

                    br.BaseStream.Position = code.Record.GetRelativeAddress(eNumAddr);
                    for (int entrance = 0; entrance < 32; entrance++)
                    {
                        //entrance index base, offset, sptr, eptr, entb1,2,3,4
                        sb.AppendFormat("{0:X4},{1},{2:X8},{3:X8},{4:X2},{5:X2},{6:X2},{7:X2}",
                                        GetEntranceIndex(scene, entranceSet),
                                        entrance,
                                        entranceSetsPointer,
                                        eNumPointer,
                                        br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte());
                        sb.AppendLine();
                    }
                }
            }
            face.OutputText(sb.ToString());
        }