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); } } }
private static DisassemblyTask New(List <JOcaBase.JDmaData> dmadata, Rom rom, int index, OverlayRecord ovlInfo, OvlType nameClass) { RomFile file; //what we're going to disassemble BinaryReader FileReader; ActorInit actorInfo = new ActorInit(); var overlay = new Overlay(); var dmaRecord = dmadata.SingleOrDefault(x => x.VRomStart == ovlInfo.VRom.Start && ovlInfo.VRom.Start != 0); string name = (dmaRecord != null)? dmaRecord.Filename : $"{nameClass}_{index:X4}"; if (ovlInfo.VRom.Size != 0) { file = rom.Files.GetFile(ovlInfo.VRom); FileReader = new BinaryReader(file); overlay = new Overlay(FileReader); } DisassemblyTask task = new DisassemblyTask() { Name = name, VRam = ovlInfo.VRam, VRom = ovlInfo.VRom, Relocations = overlay.Relocations }; N64Ptr fstart = task.VRam.Start; Section text = new Section("text", fstart, fstart, overlay.TextSize, 0, true); Section data = new Section("data", fstart, text.VRam + text.Size, overlay.DataSize, 0); Section rodata = new Section("rodata", fstart, data.VRam + data.Size, overlay.RodataSize, 0); long off = ovlInfo.VRam.Start + ovlInfo.VRom.Size; Section bss = new Section("bss", fstart, off, overlay.BssSize, 0); task.Sections.Values.Add(text); task.Sections.Values.Add(data); task.Sections.Values.Add(rodata); task.Sections.Values.Add(bss); return(task); }
private static void GetActorInfoSymbols(DisassemblyTask task, N64Ptr startAddr, N64Ptr vramActorInfo, Stream file) { file.Position = vramActorInfo - startAddr; ActorInit actorInfo = new ActorInit(new BinaryReader(file)); BindSymbol(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, Disassemble.MipsToC) { Name = $"{task.Name}_{name}" }; task.Functions.Add(func); } } }
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()); }