public CollisionBody(Ptr pointer) { Address = (int)pointer; Instance = pointer.ReadInt32(0); ActorId = pointer.Deref().ReadInt16(0); CollidingInstance1 = pointer.ReadInt32(0x04); CollidingInstance2 = pointer.ReadInt32(0x08); CollidingInstance3 = pointer.ReadInt32(0x0C); flags1 = pointer.ReadInt32(0x10); flags2 = pointer.ReadInt32(0x14); }
public bool IsWithinCode(N64Ptr ptr) { foreach (var item in Values) { if (item.IsWithin(ptr)) { return(item.IsCode); } } return(false); }
private void Initialize(int index, BinaryReader br) { RamStart = br.ReadBigUInt32(); VRom = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32()); VRam = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32()); unknown2 = br.ReadBigUInt32(); InitFunc = br.ReadBigUInt32(); DestFunc = br.ReadBigUInt32(); br.BaseStream.Position += 0xC; AllocateSize = br.ReadBigInt32(); }
/// <summary> /// Reads a 4 byte aligned block of emulated ram /// </summary> /// <param name="process"></param> /// <param name="address"></param> /// <param name="bytes"></param> /// <param name="bytesRead"></param> /// <param name="BigEndian"></param> /// <returns></returns> private static byte[] ReadN64Rdram(N64Ptr pointer, int bytes, out int bytesRead, bool BigEndian) { if (usePrefetchedRam) { bytesRead = bytes; if (BigEndian == true) { byte[] buffer = new byte[bytes]; Array.Copy(prefetchedRam, pointer.Offset, buffer, 0, bytes); return(buffer); } else { if ((pointer.Offset & 3) != 0) { throw new NotImplementedException("can't prefetch misaligned address"); } int numBytes = (bytes + 3) & -4; byte[] buffer = new byte[numBytes]; Array.Copy(prefetchedRam, pointer.Offset, buffer, 0, numBytes); buffer.Reverse32(); return(buffer); } } else { Process process = Emulator.Process; //addr read start long addrStart = IntPtr.Add(RamPointer, pointer.Offset).ToInt64(); int off = (int)(addrStart & 0x3); //addr read start clamped to address divisible by 4 addrStart &= -4; // read a number of bytes divisible by 4 int numOfBytes = (off + bytes + 3) & -4; IntPtr hProc = NativeMethods.OpenProcess(ProcessAccessFlags.All, false, process.Id); byte[] buffer = new byte[numOfBytes]; NativeMethods.ReadProcessMemory(hProc, (IntPtr)addrStart, buffer, (IntPtr)numOfBytes, out bytesRead); NativeMethods.CloseHandle(hProc); var bigEndian = Emulator.Stats.BigEndian > 0; if (bigEndian != BigEndian) { buffer.Reverse32(); } if (off != 0) { Array.Copy(buffer, off, buffer, 0, bytes); } return(buffer); } }
public Room(Ptr p) { Num = p.ReadSByte(0x00); unk_01 = p.ReadByte(0x01); unk_02 = p.ReadByte(0x02); unk_03 = p.ReadByte(0x03); Echo = p.ReadSByte(0x04); ShowInvisActors = p.ReadByte(0x05); mesh = p.ReadInt32(0x08); segment = p.ReadInt32(0x0C); unk_10 = p.ReadInt32(0x10); }
private List <ModelViewerDlist> GetDlistBranches(N64Ptr topDlist) { List <ModelViewerDlist> result = new List <ModelViewerDlist>(); var data = Zpr.ReadRam(0, 0x400000); //bool foundProjection = false; List <(N64Ptr ptr, bool check)> stack = new List <(N64Ptr, bool)>(); List <int> endDlists = gfxDList.Select(x => (int)x.StartPtr).ToList(); using (BinaryReader br = new BinaryReader(new MemoryStream(data))) { foreach (var item in MicrocodeParser.DeepTrace(br, (int)topDlist)) { //if (item.Item2.Name == G_.G_MTX) //{ // if ((item.Item2.EncodingHigh & 0x4) > 0) // foundProjection = true; //} //if (!foundProjection) // continue; if (item.gbi.Name == G_.G_DL) { if (endDlists.Contains((int)item.gbi.EncodingLow)) { break; } bool check = (item.gbi.EncodingLow >> 24) != 0x80; var list = stack.Where(x => x.check == check).Select(y => y.ptr).ToList(); if (check) { result.Add(new ModelViewerDlist(item.ptr, list)); } stack.Add((item.ptr, check)); } if (item.gbi.Name == G_.G_ENDDL) { var remove = stack.Count - 1; if (remove >= 0) { stack.RemoveAt(remove); } } } } return(result); }
private void Initialize(int index, BinaryReader br) { Actor = index; VRom = new FileAddress(br.ReadBigUInt32(), br.ReadBigUInt32()); VRam = new N64PtrRange(br.ReadBigUInt32(), br.ReadBigUInt32()); RamStart = br.ReadBigUInt32(); VRamActorInfo = br.ReadBigUInt32(); RamFileName = br.ReadBigUInt32(); AllocationType = br.ReadBigUInt16(); NumSpawned = br.ReadSByte(); }
private void Initialize(int index, Ptr recordPtr) { Actor = index; VRom = new FileAddress(recordPtr.ReadUInt32(0x00), recordPtr.ReadUInt32(0x04)); VRam = new N64PtrRange(recordPtr.ReadUInt32(0x08), recordPtr.ReadUInt32(0x0C)); RamStart = recordPtr.ReadUInt32(0x10); VRamActorInfo = recordPtr.ReadUInt32(0x14); RamFileName = recordPtr.ReadUInt32(0x18); AllocationType = recordPtr.ReadUInt16(0x1C); NumSpawned = (sbyte)recordPtr.ReadByte(0x1E); }
public static bool TryGetRam(RomFileToken file, RomVersion version, out N64Ptr v) { var block = GetBlock(version, file.ToString()); if (TryGetStart(block, version, Domain.RAM, out int value)) { v = value | 0x8000_0000; return(true); } v = 0; return(false); }
public ActorOverlayRecord(ActorOverlayRecord a) { Actor = a.Actor; VRom = a.VRom; VRam = a.VRam; RamStart = a.RamStart; VRamActorInit = a.VRamActorInit; RamFileName = a.RamFileName; AllocationType = a.AllocationType; NumSpawned = a.NumSpawned; }
private static void InitRelocationLabels(BinaryReader br, DisassemblyTask task) { N64Ptr hi_addr = 0; Rel_Parse = true; N64Ptr start = task.VRam.Start; List <(N64Ptr start, N64Ptr end)> textSections = GetTextSectionRanges(task); foreach (var reloc in task.Relocations) { N64Ptr relAddr = task.VRam.Start + reloc.Offset; br.BaseStream.Position = reloc.Offset; if (reloc.RelocType == Reloc.R_MIPS_HI16 || reloc.RelocType == Reloc.R_MIPS_LO16) { GetOP(br.ReadBigInt32()); if (reloc.RelocType == Reloc.R_MIPS_HI16) { hi_addr = relAddr; } else if (reloc.RelocType == Reloc.R_MIPS_LO16) { //Fixes bug where gcc generates a R_MIPS_HI16 //after LO16 that is part of the same chain of LO16s if (!RelocationLabels.ContainsKey(hi_addr)) { RelocationLabels[hi_addr] = Rel_Label_Addr; } RelocationLabels[relAddr] = Rel_Label_Addr; } } else if (reloc.RelocType == Reloc.R_MIPS32) { N64Ptr ptr = br.ReadBigInt32(); if (textSections.Exists(x => x.start >= ptr && ptr < x.end)) { AddLabel(ptr, false); } else { Symbols[ptr] = new Label(Label.Type.VAR, ptr); } } } Rel_Parse = false; br.BaseStream.Position = 0; }
public ColliderBody(Ptr p) { toucher = new ColliderTouch(p); bumper = new ColliderBump(p.RelOff(0x08)); flags = p.ReadByte(0x14); toucher_flags = p.ReadByte(0x15); bumper_flags = p.ReadByte(0x16); flags_2 = p.ReadByte(0x17); unk_0x18 = p.ReadInt32(0x18); colliderPtr = p.ReadInt32(0x1C); unk_0x20 = p.ReadInt32(0x20); collidingPtr = p.ReadInt32(0x24); }
public Collider(Ptr pointer) { Address = (int)pointer; Instance = pointer.ReadInt32(0); ActorId = pointer.Deref().ReadInt16(0); CollidingInstance1 = pointer.ReadInt32(0x04); CollidingInstance2 = pointer.ReadInt32(0x08); CollidingInstance3 = pointer.ReadInt32(0x0C); flags1 = pointer.ReadInt32(0x10); unk_0x14 = pointer.ReadByte(0x14); Shape = pointer.ReadByte(0x15); flags2 = pointer.ReadInt16(0x16); }
public ActorInit(BinaryReader br) { number = br.ReadBigInt16(); type = br.ReadByte(); room = br.ReadByte(); flags = br.ReadBigInt32(); object_number = br.ReadBigInt16(); br.BaseStream.Position += 2; instance_size = br.ReadBigUInt32(); init_func = br.ReadBigUInt32(); dest_func = br.ReadBigUInt32(); update_func = br.ReadBigUInt32(); draw_func = br.ReadBigUInt32(); }
private void Create(int index, List <uint> data) { N64Ptr ramFileStart; Actor = index; VRom = new FileAddress(data[0], data[1]); VRam = new FileAddress(data[2], data[3]); ramFileStart = data[4]; VRamActorInfo = data[5]; RamFileName = data[6]; Unknown = data[7]; Ram = new FileAddress(ramFileStart, ramFileStart + VRam.Size); }
OSThreadContext c; //register/interrupt mask public OSThread(Ptr ptr) { address = ptr; OSThread_next = ptr.ReadUInt32(0); priority = ptr.ReadInt32(4); OSThread_queue = ptr.ReadUInt32(8); OSThread_tlnext = ptr.ReadUInt32(0x0C); state = ptr.ReadUInt16(0x10); flags = ptr.ReadUInt16(0x12); OSId = ptr.ReadInt32(0x14); fp = ptr.ReadInt32(0x18); c = new OSThreadContext(ptr.RelOff(0x20)); }
public static IEnumerable <string> DeepParse(BinaryReader memory, N64Ptr address) { bool keepParsing = true; MicrocodeParserTask task = new(address); memory.BaseStream.Position = address.Offset; while (keepParsing) { var microcode = new Microcode(memory); yield return($"{memory.BaseStream.Position - 8:X6}: {PrintMicrocode(memory, microcode, false)}"); keepParsing = TraceNext(memory, task, microcode); } }
public BgActor(Ptr pointer) { Address = (int)pointer; ActorInstance = pointer.Deref(0); ActorId = pointer.Deref().ReadInt16(0); MeshPtr = pointer.Deref(4); dynaLookup = new DynaLookup(pointer.RelOff(0x08)); vtxStartIndex = pointer.ReadUInt16(0x10); waterBoxStartIndex = pointer.ReadUInt16(0x12); Prev = new Moment(pointer.RelOff(0x14)); Current = new Moment(pointer.RelOff(0x34)); boundingSphere = new Sphere16(pointer.RelOff(0x54)); minY = pointer.ReadFloat(0x5C); maxY = pointer.ReadFloat(0x60); }
public List <string> GetList(int max = 40) { List <string> output = new List <string>(); if (Data.Count > max) { return(output); } foreach (var item in Data) { N64Ptr ptr = Options.StartPtr + item.off; output.Add($"{ptr}: {item.cur:X8} {item.prev:X8} {item.initial:X8}"); } return(output); }
public override bool Equals(object obj) { if (obj == null) { return(false); } N64Ptr p = obj as N64Ptr; if ((object)p == null) { return(false); } return(Pointer == p.Pointer); }
public static bool TryGetRom(RomFileToken file, RomVersion version, N64Ptr ramAddr, out int v) { ramAddr &= 0xFFFFFF; var block = GetBlock(version, file.ToString()); if (!TryGetStart(block, version, Domain.ROM, out int romStart) || !TryGetStart(block, version, Domain.RAM, out int ramStart) || ramAddr < ramStart) { v = 0; return(false); } v = romStart + ramAddr - ramStart; return(true); }
public ColliderTris(Ptr ptr, Collider col) { collider = col; count = ptr.ReadInt32(0x18); listPtr = ptr.ReadInt32(0x1C); if (listPtr.IsInRDRAM()) { ptr = ptr.Deref(0x1C); int loop = Math.Min(count, 0x40); //prevent malformed data hanging program for (int i = 0; i < loop; i++) { items.Add(new ColliderTriElement(ptr.RelOff(i * 0x5C))); } } }
static void Main(string[] args) { var info = SymbolMapParser.Parse(TestPath); PrintData(info.Map); while (true) { Console.Write("Input:"); var input = Console.ReadLine(); var romAddr = int.Parse(input, System.Globalization.NumberStyles.HexNumber); foreach (Segment segment in info.Map) { if (!segment.HasLoadAddress) { continue; } FileAddress fileAddr = new(segment.LoadAddress, segment.LoadAddress + segment.Size); if (fileAddr.Start <= romAddr && romAddr < fileAddr.End) { int offset = romAddr - fileAddr.Start; N64Ptr addr = segment.Address + offset; Section section = segment.Sections.SingleOrDefault(x => x.Address <= addr && addr < (x.Address + x.Size)); Symbol sym = section.Symbols.SingleOrDefault(x => x.Address == addr); if (sym != null) { Console.WriteLine($"{sym.Address}"); Console.WriteLine( $"<MapBinding>\n" + $" <Segment>{segment.Name}</Segment>\n" + $" <File>{section.File}</File>\n" + $" <Symbol>{sym.Name}</Symbol>\n" + $"</MapBinding>"); } else { Console.WriteLine($"NOT FOUND: {addr} {segment.Name} {section.File}"); } break; } } } }
private static void ElfToOverlay(string file, N64Ptr addr) { if (!File.Exists(file)) { Console.WriteLine($"Cannot find file {Path.GetFullPath(file)}"); return; } if (ElfUtil.TryConvertToOverlay(file, $"{file}.z64", addr)) { Console.WriteLine("Conversion success"); } else { Console.WriteLine("A dumb error occurred"); Console.ReadKey(); } }
public static RamScene GetSceneInfo(RomVersion ver, Ptr globalCtx, Ptr sceneTable) { short sceneId = globalCtx.ReadInt16(0xA4); N64Ptr ramStart = globalCtx.ReadInt32(0xB0); int recordSize = (ver.Game == Game.OcarinaOfTime) ? 0x14 : 0x10; Ptr sceneRecord = sceneTable.RelOff(recordSize * sceneId); FileAddress vrom = new FileAddress(sceneRecord.ReadInt32(0), sceneRecord.ReadInt32(4)); N64Ptr ramEnd = ramStart + vrom.Size; RamScene result = new RamScene { VRom = vrom, Ram = new N64PtrRange(ramStart, ramEnd), Id = sceneId }; return(result); }
public IEnumerable <(short, short)> YieldPolyChain(int[] colsec, int index) { N64Ptr colsecAddr = GetColSecDataPtr(colsec); Ptr colsecPtr = SPtr.New(colsecAddr); int depthLimit = 800; short topLinkId = colsecPtr.ReadInt16(index * 2); short linkId = topLinkId; while (depthLimit > 0 && linkId != -1) { depthLimit--; //Get Next Link Record short polyId = Links.ReadInt16(linkId * 4); linkId = Links.ReadInt16(linkId * 4 + 2); yield return(polyId, linkId); } }
public ThreadStack(N64Ptr addr) { Ram = new N64PtrRange(addr, addr + 0x20); Ptr ptr = SPtr.New(addr); NextPtr = ptr.ReadInt32(0x00); PrevPtr = ptr.ReadInt32(0x04); N64Ptr StartPtr = ptr.ReadInt32(0x08); N64Ptr EndPtr = ptr.ReadInt32(0x0C); Unknown = ptr.ReadInt32(0x14); //NamePtr = ptr.ReadInt32(0x18); Unknown2 = ptr.ReadInt32(0x1C); byte[] nameBuff = ptr.Deref(0x18).ReadBytes(0, 0x20); Name = CStr.Get(nameBuff, Encoding.GetEncoding("EUC-JP"), 0x20); StackAddr = new NamedBuffer(new N64PtrRange(StartPtr, EndPtr), $"{Name,-13} STACK"); }
public static List <BlockNode> GetBlockList(N64Ptr address) { List <BlockNode> list = new List <BlockNode>(); BlockNode working; if (address == 0) { return(list); } N64Ptr addr = (int)(address | 0x80000000); do { working = new BlockNode(addr); list.Add(working); addr = working.Next; }while (working.Next != 0); return(list); }
private static List <List <DungeonMinimap> > GetDungeonMinimaps(Rom rom, int dung_mark_vrom, N64Ptr dung_mark_vram) { //uint map_mark_vram_n0 = 0x808567F0; //uint map_mark_rom_n0 = 0xBF40D0; //uint map_mark_table_n0 = 0xBFABBC; //uint minimaps_per_dungeon_n0 = 0xB6C794; List <List <DungeonMinimap> > result = new List <List <DungeonMinimap> >(); var map_mark_record = rom.Files.GetFileStart(dung_mark_vrom).VRom; var map_mark_file = rom.Files.GetFile(map_mark_record); var dung_mark_off = map_mark_file.Record.GetRelativeAddress(dung_mark_vrom); N64Ptr map_mark_vram_start = (dung_mark_vram - dung_mark_off); List <N64Ptr> dung_ptr_data = new List <N64Ptr>(); using (BinaryReader br = new BinaryReader(map_mark_file)) { br.BaseStream.Position = dung_mark_off; for (int i = 0; i < 10; i++) { dung_ptr_data.Add(br.ReadBigInt32()); } dung_ptr_data.Add(dung_mark_vram); for (int i = 0; i < 10; i++) { List <DungeonMinimap> m = new List <DungeonMinimap>(); var minimaps = (dung_ptr_data[i + 1] - dung_ptr_data[i]) / 0x72; br.BaseStream.Position = dung_ptr_data[i] - map_mark_vram_start; for (int j = 0; j < minimaps; j++) { m.Add(new DungeonMinimap(br)); } result.Add(m); } } return(result); }
public CollisionCtx(Ptr ctx) { SceneMeshPtr = ctx.ReadInt32(0); boxmin = new Vector3 <float>( ctx.ReadFloat(0x04), ctx.ReadFloat(0x08), ctx.ReadFloat(0x0C) ); boxmax = new Vector3 <float>( ctx.ReadFloat(0x10), ctx.ReadFloat(0x14), ctx.ReadFloat(0x18) ); max = new Vector3 <int>( ctx.ReadInt32(0x1C), ctx.ReadInt32(0x20), ctx.ReadInt32(0x24) ); unitSize = new Vector3 <float>( ctx.ReadFloat(0x28), ctx.ReadFloat(0x2C), ctx.ReadFloat(0x30) ); factor = new Vector3 <float>( ctx.ReadFloat(0x34), ctx.ReadFloat(0x38), ctx.ReadFloat(0x3C) ); Table = ctx.Deref(0x40); LinksMax = ctx.ReadInt16(0x44); LinksAlloc = ctx.ReadInt16(0x46); Links = ctx.Deref(0x48); Checks = ctx.Deref(0x4C); }