示例#1
0
        static void BindSegment(RomVersion version, ORom.FileList fileO, MRom.FileList fileM, ref Ptr ram, ref Ptr rom)
        {
            RomFileToken token = RomFileToken.Select(version, fileO, fileM);

            if (Options.MapfileOptions.CanUseMap(version))
            {
                Segment seg = Options.MapfileOptions.SymbolMap.GetSegment(token.ToString());
                if (seg != null)
                {
                    ram = SPtr.New(seg.Address);
                    rom = SPtr.New(seg.LoadAddress);
                }
                else
                {
                    Console.WriteLine($"Segment {token} not found.");
                }
            }
            else
            {
                Addresser.TryGetRam(token, version, out var t1);
                ram = SPtr.New(t1);
                Addresser.TryGetRom(token, version, t1, out var t2);
                rom = SPtr.New(t2);
            }
        }
示例#2
0
        private static void GetActorSymbolNames(DisassemblyTask task, Rom rom, ActorOverlayRecord ovlRec)
        {
            ActorInit actorInfo = new ActorInit();

            if (ovlRec.VRamActorInfo == 0)
            {
                return;
            }

            N64Ptr  startAddr;
            RomFile file;

            if (ovlRec.VRom.Size == 0)
            {
                file = rom.Files.GetFile(ORom.FileList.code);
                Addresser.TryGetRam(ORom.FileList.code, rom.Version, out int code_start);
                startAddr = (code_start | 0x80000000);
            }
            else
            {
                file      = rom.Files.GetFile(ovlRec.VRom);
                startAddr = ovlRec.VRam.Start;
            }

            file.Stream.Position = ovlRec.VRamActorInfo - startAddr;
            actorInfo            = new ActorInit(new BinaryReader(file));

            BindSymbol(ovlRec.VRamActorInfo, Label.Type.VAR, "InitVars");
            BindSymbol(actorInfo.init_func, Label.Type.FUNC, "Init");
            BindSymbol(actorInfo.draw_func, Label.Type.FUNC, "Draw");
            BindSymbol(actorInfo.update_func, Label.Type.FUNC, "Update");
            BindSymbol(actorInfo.dest_func, Label.Type.FUNC, "Destructor");

            void BindSymbol(N64Ptr ptr, Label.Type type, string name)
            {
                if (ptr != 0)
                {
                    var func = new Label(type, ptr, true)
                    {
                        Name = $"{task.Name}_{name}"
                    };
                    task.Functions.Add(func);
                }
            }
        }
示例#3
0
 public static void SetGfxContext(RomVersion version)
 {
     if (!Addresser.TryGetRam(AddressToken.GFX_START, version, out int temp))
     {
         if (GlobalContext != 0)
         {
             Gfx = GlobalContext.Deref();
         }
         else
         {
             Gfx = SPtr.New(0);
         }
     }
     else
     {
         Gfx = SPtr.New(temp);
     }
 }
示例#4
0
 static Ptr BindPtr(AddressToken token, RomVersion version, Func <int, Ptr> func)
 {
     if (Options.MapfileOptions.CanUseMap(version))
     {
         if (Addresser.TryGetSymbolRef(token, version, out MapBinding binding) && binding != null &&
             Options.MapfileOptions.SymbolMap.TryGetSymbolAddress(binding, out N64Ptr ptr))
         {
             return(func(ptr));
         }
         Console.WriteLine($"{token} symbol not found");
         return(SPtr.New(0));
     }
     else if (Addresser.TryGetRam(token, version, out int temp))
     {
         return(func(temp));
     }
     else
     {
         return(SPtr.New(0));
     }
 }
        private static void GetActorSymbolNames(DisassemblyTask task, Rom rom, ActorOverlayRecord ovlRec)
        {
            if (ovlRec.VRamActorInit == 0)
            {
                return;
            }

            if (ovlRec.VRom.Size == 0)
            {
                RomFile file = rom.Files.GetFile(ORom.FileList.code);
                Addresser.TryGetRam(ORom.FileList.code, rom.Version, out N64Ptr code_start);
                N64Ptr startAddr = code_start;

                GetActorInfoSymbols(task, startAddr, ovlRec.VRamActorInit, file);
            }
            else
            {
                task.PreparseActions.Add(file => {
                    GetActorInfoSymbols(task, ovlRec.VRam.Start, ovlRec.VRamActorInit, file);
                });
            }
        }
示例#6
0
        public static string ActorTable(Rom r, bool dumpActorInit = true)
        {
            StringBuilder sb = new StringBuilder();

            RomFileToken codeFileToken = RomFileToken.Select(r.Version, ORom.FileList.code, MRom.FileList.code);

            RomFile      codeFile       = r.Files.GetFile(codeFileToken);
            BinaryReader codeFileReader = new BinaryReader(codeFile);

            Addresser.TryGetRam(codeFileToken, r.Version, out N64Ptr codePtr);

            List <ActorOverlayRecord> records = new List <ActorOverlayRecord>();

            for (int i = 0; i < r.Files.Tables.Actors.Records; i++)
            {
                records.Add(r.Files.GetActorOverlayRecord(i));
            }
            string header = $"Id,VROM Start,VROM End,VROM Size,VRAM Start,VRAM End,VRAM Size,Actor Init,Alloc";

            if (dumpActorInit)
            {
                header +=
                    ",number,type,room,flags,object_number,instance_size," +
                    "init_func,dest_func,update_func,draw_func";
            }
            sb.AppendLine(header);
            foreach (var item in records)
            {
                string entry = $"{item.Actor:X4}," +
                               $"{item.VRom.Start:X8},{item.VRom.End:X8},{item.VRom.Size:X8}," +
                               $"{item.VRam.Start:X8},{item.VRam.End:X8},{item.VRam.Size:X8}," +
                               $"{item.VRamActorInit}," +
                               $"{item.AllocationType}";

                sb.Append(entry);
                if (dumpActorInit)
                {
                    ActorInit stats;
                    if (item.VRamActorInit.IsNull())
                    {
                        stats = new ActorInit();
                    }
                    else
                    {
                        BinaryReader reader;
                        N64Ptr       basePtr;
                        if (item.VRamActorInit < 0x8080_0000)
                        {
                            basePtr = codePtr;
                            reader  = codeFileReader;
                        }
                        else
                        {
                            basePtr = item.VRam.Start;
                            var fileRecord = r.Files.GetFileByTable(TableInfo.Type.Actors, item.Actor);
                            reader = new BinaryReader(r.Files.GetFile(fileRecord));
                        }
                        reader.BaseStream.Position = item.VRamActorInit - basePtr;
                        stats = new ActorInit(reader);
                    }
                    sb.Append($",{stats}");
                }
                sb.AppendLine();
            }
            codeFileReader.Dispose();
            return(sb.ToString());
        }
示例#7
0
        internal static void ChangeVersion(RomVersion version, bool setGctx = true)
        {
            RomFileToken fileToken;

            //dma data
            fileToken = RomFileToken.Select(version, ORom.FileList.dmadata, MRom.FileList.dmadata);
            Addresser.TryGetRam(fileToken, version, out N64Ptr dmadataStart);
            Dmadata_Addr = SPtr.New(dmadataStart);

            //code
            fileToken = RomFileToken.Select(version, ORom.FileList.code, MRom.FileList.code);
            Addresser.TryGetRam(fileToken, version, out Code_Addr);
            Addresser.TryGetRom(fileToken, version, Code_Addr.Offset, out Code_VRom);


            int temp;

            //Global Context
            if (setGctx)
            {
                Addresser.TryGetRam(AddressToken.RAM_GLOBAL_CONTEXT, version, out temp);
                if (version == ORom.Build.IQUEC || version == ORom.Build.IQUET)
                {
                    GlobalContext = SPtr.New(temp);
                }
                else
                {
                    GlobalContext = SPtr.New(temp).Deref();
                }
            }

            SetGfxContext(version);

            //Heap
            Addresser.TryGetRam(AddressToken.RAM_ARENA_MAIN, version, out temp);
            Main_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam(AddressToken.RAM_ARENA_SCENES, version, out temp);
            Scene_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam(AddressToken.RAM_ARENA_DEBUG, version, out temp);
            if (temp == 0)
            {
                Debug_Heap_Ptr = SPtr.New(0);
            }
            else
            {
                Debug_Heap_Ptr = SPtr.New(temp).Deref();
            }


            Addresser.TryGetOffset(AddressToken.ACTOR_CAT_LL_Start, version, out temp);
            Actor_Category_Table = GlobalContext.RelOff(temp);

            //Overlay Tables
            Addresser.TryGetRam(AddressToken.ActorTable_Start, ORom.FileList.code, version, out Actor_Ovl_Table);
            Addresser.TryGetRam(AddressToken.PlayerPauseOverlayTable_Start, ORom.FileList.code, version, out Player_Pause_Ovl_Table);
            Addresser.TryGetRam(AddressToken.ParticleTable_Start, ORom.FileList.code, version, out ParticleEffect_Ovl_Table);
            Addresser.TryGetRam(AddressToken.ObjectTable_Start, ORom.FileList.code, version, out Object_File_Table);


            Addresser.TryGetOffset(AddressToken.OBJ_ALLOC_TABLE, version, out temp);
            Object_Allocation_Table = GlobalContext.RelOff(temp);

            Addresser.TryGetOffset(AddressToken.ROOM_ALLOC_ADDR, version, out temp);
            Room_Allocation_Table = GlobalContext.RelOff(temp);


            Addresser.TryGetRam(AddressToken.SRAM_START, version, out temp);
            SaveContext = SPtr.New(temp);

            Addresser.TryGetRam(AddressToken.RAM_SEGMENT_TABLE, version, out temp);
            Segment_Table = temp;

            if (Addresser.TryGetRam(AddressToken.SceneTable_Start, version, out temp))
            {
                SceneTable = SPtr.New(temp);
            }
            else
            {
                SceneTable = null;
            }

            if (Addresser.TryGetRam(AddressToken.EntranceIndexTable_Start, version, out temp))
            {
                EntranceTable = SPtr.New(temp);
            }
            else
            {
                EntranceTable = null;
            }

            Addresser.TryGetRam(AddressToken.QUEUE_THREAD, version, out temp);
            Queue_Thread_Ptr = SPtr.New(temp);

            Addresser.TryGetRam(AddressToken.STACK_LIST, version, out temp);
            Stack_List_Ptr = SPtr.New(temp);
        }
示例#8
0
        internal static void ChangeVersion(RomVersion version, bool setGctx = true)
        {
            RomFileToken fileToken;

            //dma data
            fileToken = (version == Game.OcarinaOfTime) ?
                        (RomFileToken)ORom.FileList.dmadata : (RomFileToken)MRom.FileList.dmadata;
            Addresser.TryGetRam(fileToken, version, out int temp);
            Dmadata_Addr = SPtr.New(temp);

            //code
            fileToken = (version == Game.OcarinaOfTime) ?
                        (RomFileToken)ORom.FileList.code : (RomFileToken)MRom.FileList.code;
            Addresser.TryGetRam(fileToken, version, out Code_Addr);
            Addresser.TryGetRom(fileToken, version, (uint)Code_Addr, out Code_VRom);

            //Global Context
            if (setGctx)
            {
                Addresser.TryGetRam("RAM_GLOBAL_CONTEXT", version, out temp);
                if (version == ORom.Build.IQUEC || version == ORom.Build.IQUET)
                {
                    GlobalContext = SPtr.New(temp);
                }
                else
                {
                    GlobalContext = SPtr.New(temp).Deref();
                }
            }

            SetGfxContext(version);

            //Heap
            Addresser.TryGetRam("RAM_ARENA_MAIN", version, out temp);
            Main_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam("RAM_ARENA_SCENES", version, out temp);
            Scene_Heap_Ptr = SPtr.New(temp).Deref();

            Addresser.TryGetRam("RAM_ARENA_DEBUG", version, out temp);
            if (temp == 0)
            {
                Debug_Heap_Ptr = SPtr.New(0);
            }
            else
            {
                Debug_Heap_Ptr = SPtr.New(temp).Deref();
            }


            Addresser.TryGetOffset("ACTOR_CAT_LL_Start", version, out temp);
            Actor_Category_Table = GlobalContext.RelOff(temp);

            //Overlay Tables
            Addresser.TryGetRam("ActorTable_Start", ORom.FileList.code, version, out Actor_Ovl_Table);
            Addresser.TryGetRam("PlayerPauseOverlayTable_Start", ORom.FileList.code, version, out Player_Pause_Ovl_Table);
            Addresser.TryGetRam("ParticleTable_Start", ORom.FileList.code, version, out ParticleEffect_Ovl_Table);
            Addresser.TryGetRam("ObjectTable_Start", ORom.FileList.code, version, out Object_File_Table);


            Addresser.TryGetOffset("OBJ_ALLOC_TABLE", version, out temp);
            Object_Allocation_Table = GlobalContext.RelOff(temp);

            Addresser.TryGetOffset("ROOM_ALLOC_ADDR", version, out temp);
            Room_Allocation_Table = GlobalContext.RelOff(temp);


            Addresser.TryGetRam("SRAM_START", version, out temp);
            SaveContext = SPtr.New(temp);

            Addresser.TryGetRam("RAM_SEGMENT_TABLE", version, out temp);
            Segment_Table = temp;

            if (Addresser.TryGetRam("SceneTable_Start", version, out temp))
            {
                SceneTable = SPtr.New(temp);
            }
            else
            {
                SceneTable = null;
            }

            if (Addresser.TryGetRam("EntranceIndexTable_Start", version, out temp))
            {
                EntranceTable = SPtr.New(temp);
            }
            else
            {
                EntranceTable = null;
            }

            Addresser.TryGetRam("QUEUE_THREAD", version, out temp);
            Queue_Thread_Ptr = SPtr.New(temp);

            Addresser.TryGetRam("STACK_LIST", version, out temp);
            Stack_List_Ptr = SPtr.New(temp);
        }