Пример #1
0
        private static void AddSceneAndRooms(int sceneId, ref int NextWriteAddress, string fileLocation, BinaryWriter bw)
        {
            Scene scene;
            int   roomCount;
            List <FileAddress> roomAddresses = new List <FileAddress>();
            FileAddress        fileAddr;

            //get scene file from mqd folder
            using (FileStream fs_s = new FileStream(string.Format("{0}/{1:D2}_h", fileLocation, sceneId),
                                                    FileMode.Open, FileAccess.Read))
            {
                scene = SceneRoomReader.InitializeScene(Game.OcarinaOfTime, sceneId, new BinaryReader(fs_s));
                //add the file to the rom
                fileAddr = AddFile(bw, fs_s, ref NextWriteAddress);

                //pass the new file address to the scene for later
                scene.VirtualAddress = fileAddr;

                UpdateSceneTable(bw, sceneId, fileAddr);
            }
            roomCount = scene.Header.GetRoomAddresses().Count;

            for (int i = 0; i < roomCount; i++)
            {
                using (FileStream fs_m = new FileStream(string.Format("{0}/{1:D2}_{2:D2}", fileLocation, sceneId, i),
                                                        FileMode.Open, FileAccess.Read))
                {
                    roomAddresses.Add(AddFile(bw, fs_m, ref NextWriteAddress));
                }
            }
            UpdateRoomList(bw, scene, roomAddresses);
        }
Пример #2
0
        private void evalButton_Click(object sender, EventArgs e)
        {
            if (rom == null)
            {
                return;
            }
            Scene         scene = null;
            StringBuilder sb    = new StringBuilder();
            Room          room  = null;

            for (int sceneNumber = 0; sceneNumber < rom.Scenes; sceneNumber++)
            {
                scene = null;
                room  = null;

                var sceneFile = rom.Files.GetSceneFile(sceneNumber);
                if (sceneFile == null)
                {
                    sb.AppendLine($"Warning: Scene {sceneNumber} not found");
                    continue;
                }
                try
                {
                    scene = SceneRoomReader.InitializeScene(sceneFile, sceneNumber);
                }
                catch (Exception ex)
                {
                    var va = sceneFile.Record.VirtualAddress;
                    sb.AppendLine($"ParseError: Scene {sceneNumber} {va.Start:X8}-{va.End:X8}");
                    sb.AppendLine(ex.TargetSite.ToString());
                }

                var roomAddrs = scene.Header.GetRoomAddresses();
                for (int i = 0; i < roomAddrs.Count; i++)
                {
                    FileAddress addr     = roomAddrs[i];
                    RomFile     roomFile = null;

                    try
                    {
                        roomFile = rom.Files.GetFile(addr);
                        room     = SceneRoomReader.InitializeRoom(roomFile);
                    }
                    catch //(Exception ex)
                    {
                        if (roomFile == null)
                        {
                            sb.AppendLine($"Exception: Scene {sceneNumber}, room {addr.Start:X8}:{addr.End:X8} not found");
                        }
                        else
                        {
                            sb.AppendLine($"ParseError: Scene {sceneNumber}, room {addr.Start:X8}:{addr.End:X8}");
                            //sb.AppendLine(ex.StackTrace.ToString());
                        }
                    }
                }
            }
            sb.AppendLine("Evaluation Complete");
            outputRichTextBox.Text = sb.ToString();
        }
Пример #3
0
        private static void DumpSceneAndRooms(Rom rom, int i, string folderLocation)
        {
            Scene        scene;
            StreamWriter sw;
            Stream       br;
            RomFile      file;

            file = rom.Files.GetSceneFile(i);

            scene = SceneRoomReader.InitializeScene(file, i);
            br    = file;
            sw    = new StreamWriter(Path.Combine(folderLocation, string.Format("{0:D2}_h", i)));

            br.CopyTo(sw.BaseStream);
            sw.Close();

            int rNum = 0;

            foreach (FileAddress addr in scene.Header.GetRoomAddresses())
            {
                br = rom.Files.GetFile(addr.Start);
                sw = new StreamWriter(Path.Combine(folderLocation, string.Format("{0:D2}_{1:D2}", i, rNum)));
                br.CopyTo(sw.BaseStream);
                sw.Close();
                rNum++;
            }
        }
Пример #4
0
        public static void MQJsonImportAndPatch(IExperimentFace face, List <string> filePath)
        {
            Rom n0 = new ORom(filePath[0], ORom.Build.N0);
            Rom mq = new ORom(filePath[1], ORom.Build.MQU);

            List <Scene_MQJson> scenes = Load_Scene_MQJson();

            foreach (var scene in scenes)
            {
                if (!MQRandoScenes.Contains(scene.Id))
                {
                    continue;
                }

                var n0_scene = SceneRoomReader.InitializeScene(n0, scene.Id);
                var mq_scene = SceneRoomReader.InitializeScene(mq, scene.Id);

                CollisionMesh n0_mesh = ((CollisionCommand)n0_scene.Header[HeaderCommands.Collision]).Mesh;
                CollisionMesh mq_mesh = ((CollisionCommand)mq_scene.Header[HeaderCommands.Collision]).Mesh;

                var delta = new Col_MQJson(n0_mesh, mq_mesh);
                scene.ColDelta = delta;
            }
            MemoryStream s  = SerializeScenes(scenes);
            StreamReader sr = new StreamReader(s);

            face.OutputText(sr.ReadToEnd());
        }
Пример #5
0
        private void PrintScene(int sceneId, StringBuilder sb)
        {
            Scene       scene = null;
            List <Room> rooms = new List <Room>();

            //try
            //{
            scene = SceneRoomReader.InitializeScene(rom.Files.GetSceneFile(sceneId), sceneId);
            //}
            //catch { }
            if (scene == null)
            {
                sb.AppendFormat("Exception: Scene not found");
                sb.AppendLine();
                return;
            }

            var roomAddrs = scene.Header.GetRoomAddresses();

            for (int i = 0; i < roomAddrs.Count; i++)
            {
                FileAddress addr = roomAddrs[i];

                //if (scene.ID == 6 && rom.Version == ORom.Build.N0)
                //{
                //    rooms.Add(SceneRoomReader.LoadSpiritRoom(addr, i));
                //}
                //else

                try
                {
                    RomFile file = rom.Files.GetFile(addr);
                    rooms.Add(SceneRoomReader.InitializeRoom(file));
                }
                catch
                {
                    sb.AppendLine($"Exception: room {addr.Start:X8} not found");
                }
            }

            sb.Append(SceneRoomReader.ReadScene(scene));
            for (int i = 0; i < rooms.Count; i++)
            {
                sb.AppendLine($"Room {i}");
                sb.Append(SceneRoomReader.ReadRoom(rooms[i]));
            }
        }
Пример #6
0
        public void Script(string path)
        {
            ORom         rom = new ORom(path, ORom.Build.DBGMQ);
            MemoryStream ms  = new MemoryStream(new byte[0x4000000]);

            //clone rom's files by DMA
            foreach (var item in rom.Files)
            {
                var rfile = rom.Files.GetFile(item.VRom);
                CopyToOutputRom(ms, rfile);
            }

            //clone scene and room files

            for (int i = 0; i < rom.Scenes; i++)
            {
                var sceneFile = rom.Files.GetSceneFile(i);
                if (sceneFile == null)
                {
                    continue;
                }
                var sceneFileMeta = SceneRoomReader.InitializeScene(sceneFile, i);
                RemoveActor0001FromFile(ms, sceneFile, sceneFileMeta.Header);
                CopyToOutputRom(ms, sceneFile);

                foreach (var roomAddr in sceneFileMeta.Header.GetRoomAddresses())
                {
                    var roomFile     = rom.Files.GetFile(roomAddr);
                    var roomFileMeta = SceneRoomReader.InitializeRoom(roomFile);
                    RemoveActor0001FromFile(ms, roomFile, roomFileMeta.Header);
                    CopyToOutputRom(ms, roomFile);
                }
            }

            //save
            using (Stream sw = new FileStream("ZeldosBirthday.z64", FileMode.Create))
            {
                ms.Position = 0;
                ms.CopyTo(sw);
            }
            //using (BinaryWriter bw = new BinaryWriter(new StreamWriter()))
        }
Пример #7
0
        private void GetMMSceneData()
        {
            List <string> file;

            if (!int.TryParse(inputTextBox.Text, out int sceneIndex))
            {
                return;
            }

            file = SingleDialog();
            if (file == null)
            {
                return;
            }

            Rom r = new MRom(file[0], MRom.Build.U0);

            mzxrules.OcaLib.SceneRoom.Scene scene = SceneRoomReader.InitializeScene(r.Files.GetSceneFile(sceneIndex), sceneIndex);
            outRichTextBox.Text = SceneRoomReader.ReadScene(scene);
        }
Пример #8
0
        private static void MatchRooms(VFileTable sourceFileList, VFileTable targetFileList,
                                       Dictionary <long, FOut> fOut, Dictionary <long, FileRecord> unmatched)
        {
            var sourceT = sourceFileList.Tables.GetTable(TableInfo.Type.Scenes);
            var targetT = targetFileList.Tables.GetTable(TableInfo.Type.Scenes);

            int scenes = Math.Min(sourceT.Records, targetT.Records);


            for (int i = 0; i < scenes; i++)
            {
                var sR = sourceFileList.GetSceneFile(i);
                var tR = targetFileList.GetSceneFile(i);
                if (sR == null)
                {
                    continue;
                }
                if (tR == null)
                {
                    continue;
                }

                Scene s = SceneRoomReader.InitializeScene(sR, i);
                Scene t = SceneRoomReader.InitializeScene(tR, i);

                List <FileAddress> sourceRooms = s.Header.GetRoomAddresses();
                List <FileAddress> targetRooms = t.Header.GetRoomAddresses();

                int rooms = Math.Min(sourceRooms.Count, targetRooms.Count);

                for (int j = 0; j < rooms; j++)
                {
                    TestMatch(sourceRooms[j], targetRooms[j], fOut, unmatched);
                }
            }
        }
Пример #9
0
        public static void AssSkulls(IExperimentFace face, List <string> filePath)
        {
            ORom r = new ORom(filePath[0], ORom.Build.N0);
            List <(FileAddress addr, int scene, int room, Room info)> lookup = new List <(FileAddress addr, int scene, int room, Room info)>();

            for (int sceneId = 0; sceneId < r.Scenes; sceneId++)
            {
                var   sceneFile = r.Files.GetSceneFile(sceneId);
                Scene scene     = SceneRoomReader.InitializeScene(sceneFile, sceneId);
                scene.Header.InitializeAssets(new BinaryReader(sceneFile.Stream));

                int roomId = -1;
                foreach (var roomAddr in scene.Header.GetRoomAddresses())
                {
                    roomId++;
                    var  roomFile = r.Files.GetFile(roomAddr);
                    Room room     = SceneRoomReader.InitializeRoom(roomFile);
                    lookup.Add((roomAddr, sceneId, roomId, room));
                }
            }
            //now for some ass

            StringBuilder sb = new StringBuilder();

            for (int i = ass.GetLowerBound(0); i <= ass.GetUpperBound(0); i++)
            {
                for (int j = ass.GetLowerBound(1); j <= ass.GetUpperBound(1); j++)
                {
                    foreach (var item in ass[i, j])
                    {
                        if (item is ACTOR actor)
                        {
                            var(addr, scene, room, info) = lookup.Where(x => x.addr.Start <= actor.addr && x.addr.End > actor.addr).Single();

                            int setup = 0;
                            if (info.Header.HasAlternateHeaders())
                            {
                                for (int hId = 0; hId < info.Header.Alternate.Headers.Count; hId++)
                                {
                                    var alt = info.Header.Alternate.Headers[hId];
                                    if (alt == null)
                                    {
                                        continue;
                                    }
                                    var actorList = alt[HeaderCommands.ActorList];
                                    if (actorList == null)
                                    {
                                        continue;
                                    }
                                    int            actors      = actorList.Command.Data1;
                                    SegmentAddress loc         = actorList.Command.Data2;
                                    int            actorsStart = addr.Start + loc.Offset;
                                    int            actorsEnd   = addr.End + loc.Offset + (0x10 * actors);

                                    if (actor.addr >= actorsStart && actor.addr < actorsEnd)
                                    {
                                        setup = hId + 1;
                                        break;
                                    }
                                }
                            }

                            sb.AppendLine($"{i}\t{j}\t{scene}\t{room}\t{setup}\t{item.ToString()}");
                        }
                    }
                }
            }

            face.OutputText(sb.ToString());
        }
Пример #10
0
        public static void CompareCollision(IExperimentFace face, List <string> filePath)
        {
            Rom n0 = new ORom(filePath[0], ORom.Build.N0);
            Rom mq = new ORom(filePath[1], ORom.Build.MQU);

            StringBuilder sb_n0 = new StringBuilder();
            StringBuilder sb_mq = new StringBuilder();

            foreach (int id in MQRandoScenes)
            {
                var n0_scene = SceneRoomReader.InitializeScene(n0, id);
                var mq_scene = SceneRoomReader.InitializeScene(mq, id);

                CollisionMesh n0_mesh = ((CollisionCommand)n0_scene.Header[HeaderCommands.Collision]).Mesh;
                CollisionMesh mq_mesh = ((CollisionCommand)mq_scene.Header[HeaderCommands.Collision]).Mesh;

                sb_n0.AppendLine($"Scene {id}");
                sb_mq.AppendLine($"Scene {id}");

                sb_n0.AppendLine(n0_mesh.Print());
                sb_n0.AppendLine();

                sb_n0.AppendLine(mq_mesh.Print());
                sb_n0.AppendLine();

                //PrintList(sb_n0, n0_mesh.CameraDataList);
                //PrintList(sb_n0, mq_mesh.CameraDataList);

                //PrintList(sb_n0, n0_mesh.WaterBoxList);
                //PrintList(sb_n0, mq_mesh.WaterBoxList);


                //for (int i = 0; i < n0_mesh.VertexList.Count; i++)
                //{
                //    var vertN0 = n0_mesh.VertexList[i];
                //    var vertMQ = mq_mesh.VertexList[i];

                //    if (vertN0 != vertMQ)
                //    {
                //        sb_n0.AppendLine($"{i:X4}: {vertN0}");
                //        sb_mq.AppendLine($"{i:X4}: {vertMQ}");
                //    }
                //}

                //for (int i = 0; i < n0_mesh.Polys; i++)
                //{
                //    var n0poly = n0_mesh.PolyList[i];
                //    var mqpoly = mq_mesh.PolyList[i];
                //    if (!n0poly.Equals(mqpoly))
                //    {
                //        if (n0poly.VertexFlagsC != mqpoly.VertexFlagsC
                //            || n0poly.VertexFlagsB != mqpoly.VertexFlagsB)
                //        {
                //            sb_n0.AppendLine($"{i:X4}: {n0poly}");
                //            sb_mq.AppendLine($"{i:X4}: {mqpoly}");
                //        }
                //    }
                //}

                //sb_mq.AppendLine();
            }
            string result = sb_n0.ToString()
                            + $"{Environment.NewLine}~SPLIT{Environment.NewLine}"
                            + sb_mq.ToString();

            face.OutputText(result);
        }