//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); } } }
public void TestMessageTransactionBuilder() { var builder = new MessageTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"; builder.StepLimit = NumericsHelper.ICX2Loop("0.1"); builder.Value = NumericsHelper.ICX2Loop("1"); builder.Timestamp = 100000000000; builder.Message = "testMessage"; var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["stepLimit"] = "0x16345785d8a0000", ["value"] = "0xde0b6b3a7640000", ["timestamp"] = "0x174876e800", ["dataType"] = "message", ["data"] = new Bytes(Encoding.UTF8.GetBytes(builder.Message)).ToString() }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }
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); } }
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()); }
public Transaction Build() { Address from = Addresser.Create(PrivateKey); Hash32 hash = BuildHash(from); Signature signature = Signer.Sign(hash, PrivateKey); return(new Transaction( Version, from, To, Value, StepLimit, Nonce, NID, Timestamp, DataType, Data, hash, signature )); }
static void AddInfo() { string name, num; Console.Write("이름: "); name = Console.ReadLine(); Console.Write("전화번호: "); num = Console.ReadLine(); Console.Clear(); Addresser.Add(new Info(name, num)); Console.WriteLine($"{Addresser[Addresser.Count - 1].Name} {Addresser[Addresser.Count - 1].Number}가 정상적으로 등록되었습니다."); Console.WriteLine("계속 하려면 아무 키나 눌러주세요."); Console.ReadLine(); Console.Clear(); }
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); } } }
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); } }
public void TestCallTransactionBuilder() { var builder = new CallTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "cx54f7853dc6481b670caf69c5a27c7c8fe5be8269"; builder.StepLimit = NumericsHelper.ICX2Loop("0.10000000000"); builder.Value = NumericsHelper.ICX2Loop("1.00000"); builder.Timestamp = 100000000000; builder.Method = "transfer"; builder.Params["to"] = new ExternalAddress("hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"); builder.Params["value"] = new BigInteger(10); var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "cx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["stepLimit"] = "0x16345785d8a0000", ["value"] = "0xde0b6b3a7640000", ["timestamp"] = "0x174876e800", ["dataType"] = "call", ["data"] = new Dictionary <string, object>() { ["method"] = "transfer", ["params"] = new Dictionary <string, object>() { ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["value"] = "0xa" } } }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }
public void TestDelopyTransaction() { var builder = new DeployTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "cx0000000000000000000000000000000000000000"; builder.StepLimit = NumericsHelper.ICX2Loop("0.1"); builder.Timestamp = 100000000000; builder.ContentType = "application/zip"; builder.Content = new Bytes("0x1212121212"); builder.Params["to"] = new ExternalAddress("hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"); builder.Params["value"] = new BigInteger(10); var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "cx0000000000000000000000000000000000000000", ["stepLimit"] = "0x16345785d8a0000", ["timestamp"] = "0x174876e800", ["dataType"] = "deploy", ["data"] = new Dictionary <string, object>() { ["contentType"] = "application/zip", ["content"] = "0x1212121212", ["params"] = new Dictionary <string, object>() { ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["value"] = "0xa" } } }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }
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)); } }
public void Test_KeyStore() { Random random = new Random(); byte[] passwordBytes = new byte[random.Next() % 256]; random.NextBytes(passwordBytes); string password = Convert.ToBase64String(passwordBytes); PrivateKey privateKey = PrivateKey.Random(); ExternalAddress address = Addresser.Create(privateKey); KeyStore keyStore = KeyStore.Create(privateKey, address); string fileName = keyStore.Store(password); keyStore = KeyStore.Load(password, fileName); File.Delete(fileName); Assert.AreEqual(privateKey, keyStore.PrivateKey); Assert.AreEqual(address, keyStore.Address); }
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); }); } }
/// <summary> /// Loads all mutual friends of all friends and saves them into a graph /// </summary> public void LoadConnections(FriendList fl, BackgroundWorker worker = null) { data = new FriendGraph(); friends = new Dictionary <string, Friend>(); // creates id->friend addresser foreach (Friend f in fl) { friends.Add(f.id, f); data.Add(f, new List <Friend>()); } // downloades mutual friends of every friend in the list int i = 0; foreach (KeyValuePair <string, Friend> pair in friends) { if (worker != null && worker.CancellationPending) { throw new InterruptedException(); } FriendList mutualFriends = GraphAPI.GetData <FriendList>(pair.Key + "/mutualfriends"); foreach (Friend f in mutualFriends) { if (!data[pair.Value].Contains(f)) { data[pair.Value].Add(f); } } // reporting progress if (worker != null) { worker.ReportProgress((++i * 100) / friends.Count, i); } } }
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()); }
public async Task Test_Call() { var getScoreApi = new GetScoreApi(Consts.ApiUrl.TestNet); var scoreApi = await getScoreApi.Invoke("cx0000000000000000000000000000000000000001"); Console.WriteLine(JsonConvert.SerializeObject(scoreApi, Formatting.Indented)); var privateKey = PrivateKey.Random(); var address = Addresser.Create(privateKey); var call = new Call(Consts.ApiUrl.TestNet); var result = await call.Invoke( address, "cx0000000000000000000000000000000000000001", "isDeployer", ("address", address) ); // 0x0 Console.WriteLine(result); var call0 = new Call <bool>(Consts.ApiUrl.TestNet); var result0 = await call0.Invoke( address, "cx0000000000000000000000000000000000000001", "isDeployer", ("address", address) ); // false Console.WriteLine(result0); var call1 = new Call <IsDeployerRequestParam, bool>(Consts.ApiUrl.TestNet); var result1 = await call1.Invoke( address, "cx0000000000000000000000000000000000000001", "isDeployer", new IsDeployerRequestParam() { Address = address } ); // false Console.WriteLine(result1); var call2 = new Call <BigInteger>(Consts.ApiUrl.TestNet); var result2 = await call2.Invoke( address, "cx0000000000000000000000000000000000000001", "getStepPrice" ); Console.WriteLine(result2); var call3 = new Call <GetRevisionResponseParam>(Consts.ApiUrl.TestNet); var result3 = await call3.Invoke( address, "cx0000000000000000000000000000000000000001", "getRevision" ); Console.WriteLine(result3.Code); Console.WriteLine(result3.Name); var call4 = new Call <Dictionary <string, BigInteger> >(Consts.ApiUrl.TestNet); var result4 = await call4.Invoke( address, "cx0000000000000000000000000000000000000001", "getStepCosts" ); Console.WriteLine(JsonConvert.SerializeObject(result4)); }
/// <summary> /// Loads saved connection out of a file /// </summary> public void LoadConnections(string filename, BackgroundWorker worker = null) { Dictionary <string, List <Friend> > parsedData; data = new FriendGraph(); friends = new Addresser(); // loading raw data about friends to an object in an undesired format using (FileStream fs = File.Open(filename, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) using (JsonTextReader jr = new JsonTextReader(sr)) { JsonSerializer serializer = new JsonSerializer(); parsedData = serializer.Deserialize <Dictionary <string, List <Friend> > >(jr); } // reporting progress if (worker != null) { worker.ReportProgress(15); } int i = 0; // find all distinct friends and create id->friend addresser // friends with no mutual friends with us will get lost (but what would they do inside the graph anyway) foreach (KeyValuePair <string, List <Friend> > pair in parsedData) { if (worker != null && worker.CancellationPending) { throw new InterruptedException(); } foreach (Friend f in pair.Value) { if (!friends.ContainsKey(f.id)) { friends.Add(f.id, f); data.Add(f, new List <Friend>()); } } // reporting progress if (worker != null) { worker.ReportProgress(15 + (++i * 70) / parsedData.Count); } } i = 0; // create the real graph out of the list of connections (connect our addresser) foreach (KeyValuePair <string, List <Friend> > pair in parsedData) { foreach (Friend f in pair.Value) { data[friends[pair.Key]].Add(friends[f.id]); // we add inside friends[f.id] not f so we unify the pointers } // (and actually toss away a lot of redundant data) // reporting progress if (worker != null) { worker.ReportProgress(85 + (++i * 15) / parsedData.Count); } } }
public static StringBuilder Calculate(IExperimentFace face, List <string> files) { StringBuilder result = new StringBuilder(); int N0_SceneEndAddr = 0x384980; int N0_CodeAddr = 0x110A0; SegmentAddress[] SegmentTable = new SegmentAddress[16]; Dictionary <short, EntranceTableRecord> EntranceTableSimplified = new Dictionary <short, EntranceTableRecord>(); Rom N0 = new ORom(files[0], ORom.Build.N0); Addresser.TryGetRom(ORom.FileList.code, N0.Version, AddressToken.EntranceIndexTable_Start, out int entranceTableAddress); Addresser.TryGetRom(ORom.FileList.code, N0.Version, AddressToken.ActorTable_Start, out int actorTableRomAddress); var code_File = N0.Files.GetFile(ORom.FileList.code); var codeStr = new BinaryReader(code_File); codeStr.BaseStream.Position = code_File.Record.GetRelativeAddress(entranceTableAddress); //remove redundant entrance table records for (int i = 0; i < 0x614; i++) { var record = new EntranceTableRecord(codeStr); short key = (short)((record.Scene << 8) + record.Spawn); if (!EntranceTableSimplified.ContainsKey(key)) { EntranceTableSimplified.Add(key, record); } } int lastScene = -1; RomFile scene_File = null; BinaryReader sceneStr = null; foreach (EntranceTableRecord record in EntranceTableSimplified.Values.OrderBy(x => x.Scene)) { if (sceneStr != null) { sceneStr.BaseStream.Position = 0; } if (record.Scene != lastScene) { if (record.Scene >= 101) { WriteResult(result, record, -1, ResultType.Crash, "No Scene"); continue; } scene_File = N0.Files.GetSceneFile(record.Scene); sceneStr = new BinaryReader(scene_File.Stream); SegmentTable[2] = N0_SceneEndAddr - scene_File.Record.VRom.Size; } //First, 0x18 command byte cmdId = sceneStr.ReadByte(); sceneStr.BaseStream.Position--; List <AlternateSetup> setups = new List <AlternateSetup>(); if (cmdId == 0x18) { sceneStr.BaseStream.Position += 4; int headerListOffset = sceneStr.ReadBigInt32() & 0xFFFFFF; sceneStr.BaseStream.Position = headerListOffset + 0xC; for (int i = 0; i < 0xD; i++) { int data = sceneStr.ReadBigInt32(); setups.Add(new AlternateSetup(i, data)); } } else { setups.Add(new AlternateSetup(-1, 0x02000000)); } //parse headers foreach (var setup in setups) { SceneHeader sceneHeader = new SceneHeader(); FaroresTest ft = FaroresTest.NA; //resolve header start if (setup.SegmentAddress.Segment != 2 || !(setup.SegmentAddress.Offset < scene_File.Record.VRom.Size)) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash_Likely, UnresolvedAddress("Scene Setup", setup.SegmentAddress)); continue; } //set header start sceneStr.BaseStream.Position = setup.SegmentAddress.Offset; int loop = 32; while (loop > 0) { loop--; cmdId = sceneStr.ReadByte(); sceneStr.BaseStream.Position--; switch (cmdId) { case 0x14: if (sceneHeader.Cutscene == 0) { WriteResult(result, record, setup.SceneSetup, ResultType.Cutscene_Pointer, "No Known Issues", ft); } else { WriteResult(result, record, setup.SceneSetup, ResultType.Cutscene, "No Known Issues", ft); } loop = -1; break; case 0x04: //room definitions { sceneStr.BaseStream.Position += 1; sceneHeader.Rooms = sceneStr.ReadByte(); sceneStr.BaseStream.Position += 2; sceneHeader.RoomsAddress = sceneStr.ReadBigInt32(); break; } case 0x06: //entrance index definitions { sceneStr.BaseStream.Position += 4; sceneHeader.EntranceIndexDefinitionsAddress = sceneStr.ReadBigInt32(); break; } case 0x00: //Link spawns definitions { long seekBack; sceneStr.BaseStream.Position += 1; sceneHeader.LinkSpawns = sceneStr.ReadByte(); sceneStr.BaseStream.Position += 2; sceneHeader.LinkSpawnsAddress = sceneStr.ReadBigInt32(); //start resolving things here I guess SegmentAddress selectEntDefAddr = sceneHeader.EntranceIndexDefinitionsAddress + (record.Spawn << 1); if (selectEntDefAddr.Segment != 2 && selectEntDefAddr.Offset > scene_File.Record.VRom.Size) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash_Likely, UnresolvedAddress("Entrance Definitions", selectEntDefAddr)); loop = -1; break; } seekBack = sceneStr.BaseStream.Position; sceneStr.BaseStream.Position = selectEntDefAddr.Offset; int spawnId = sceneStr.ReadByte(); int mapId = sceneStr.ReadByte(); //test if Link Spawn is invalid (phase 1) SegmentAddress selectSpawnAddr = sceneHeader.LinkSpawnsAddress + (spawnId << 4); if (selectSpawnAddr.Segment != 2 && selectSpawnAddr.Offset > scene_File.Record.VRom.Size) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash_Likely, UnresolvedAddress("Link Spawn", selectSpawnAddr), ft); loop = -1; break; } //test if Map Id is invalid, making FW mandatory if (!(mapId < sceneHeader.Rooms)) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash, string.Format("Invalid Room Id ({0})", mapId), FaroresTest.Without); ft = FaroresTest.With; //Don't break because we can continue parsing for FW purposes } //Check if Link spawn is valid (phase 2) sceneStr.BaseStream.Position = selectSpawnAddr.Offset; var actorId = sceneStr.ReadBigInt16(); int linkActorVarsRomAddr = actorId * 0x20 + 0x14; linkActorVarsRomAddr += actorTableRomAddress; var linkActorVarsRelOff = code_File.Record.GetRelativeAddress(linkActorVarsRomAddr); //pointer to Link's Actor vars can't be resolved if (linkActorVarsRelOff < 0 || !(linkActorVarsRelOff < code_File.Record.VRom.Size)) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash_Likely, UnresolvedAddress("Link Actor Var Pointer", (int)(linkActorVarsRelOff + N0_CodeAddr)), ft); loop = -1; break; } codeStr.BaseStream.Position = linkActorVarsRelOff; int linkActorVarsWriteAddr = codeStr.ReadBigInt32(); int linkActorVarsWriteOff = (linkActorVarsWriteAddr - N0_CodeAddr + 8) & 0xFFFFFF; //pointer to where to update Link's object number can't be resolved if (linkActorVarsWriteOff < 0 || !(linkActorVarsWriteOff < code_File.Record.VRom.Size)) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash_Likely, UnresolvedAddress("Link Object Dependency Write", linkActorVarsWriteAddr + 8), ft); loop = -1; break; } //check if pointer is going to do an unaligned write if (linkActorVarsWriteAddr % 2 == 1) { WriteResult(result, record, setup.SceneSetup, ResultType.Crash, string.Format("N64: Unaligned SH write to address {0:X8}", linkActorVarsWriteAddr + 8), ft); } sceneStr.BaseStream.Position = seekBack; break; } case 0x17: { sceneStr.BaseStream.Position += 4; sceneHeader.Cutscene = sceneStr.ReadBigInt32(); break; } default: sceneStr.BaseStream.Position += 8; break; } if (loop == 0) { WriteResult(result, record, setup.SceneSetup, ResultType.Error, "Header Parse Error"); } } } } face.OutputText(result.ToString()); return(result); }
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); }
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); }
static Ptr BindOff(AddressToken token, RomVersion version, Func <int, Ptr> func) { Addresser.TryGetOffset(token, version, out int temp); return(func(temp)); }
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()); }
public static Wallet Create(PrivateKey privateKey) { return(new Wallet(privateKey, Addresser.Create(privateKey))); }