private void UpdateAsmFile(AsmFile fileObj) { // Local Variables var objectsFile = (ObjectsFile)_objectsFiles.Peek(); // Update current offset. AsmFile.CurrentFileOffset = RomFile.TotalOffset; _subOffArray.Add((uint)(RomFile.TotalOffset + _subOffsets[fileObj.Id] + _baseRam)); // Create a local byte[] and pass it decompressed file info. byte[] asmFile = DecompressFile(fileObj); // Get _upperRAM value byte[] objFile = DecompressFile(objectsFile); _upperRAM = (uint)(_BASERAM + asmFile.Length + objFile.Length + objectsFile.ReservedLength); // Update JAL and LUI commands. ProcessCommands(asmFile); // Update F39F90 JALs UpdateF37F90(fileObj); RomFile.UpdateTotalsOffset(asmFile.Length, 0); // Update file buffer. _fileBuffer.Add(asmFile); }
internal static void Show() { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form = new BrowserForm(); Form.Text = "Vortex"; var romNode = Form.TreeView.Nodes.Add("Rom", "Vortex"); var apuNode = romNode.Nodes.Add("APU", "APU Data"); var songsNode = romNode.Nodes.Add("Songs", "Songs"); for (var song = 0; song < VortexRom.SongCount; song++) { var songNode = songsNode.Nodes.Add(song.ToString(), "Song " + song); songNode.Nodes.Add("Loading..."); } Form.TreeView.AfterSelect += TreeView_AfterSelect; Form.TreeView.BeforeExpand += TreeView_BeforeExpand; Form.ListView.MouseDoubleClick += ListView_MouseDoubleClick; RomFile.Load(@"C:\Games\Super Nintendo\Roms\Vortex (U) [!].smc"); Application.Run(Form); }
public static void TestYazDecompress(IExperimentFace face, List <string> filePath) { StringBuilder sb = new StringBuilder(); ORom compRom = new ORom(filePath[0], ORom.Build.N0); ORom decompRom = new ORom(@"C:\Users\mzxrules\Documents\Roms\N64\Games\Ocarina\Ocarina (U10)\Ocarina (U10) (d).z64", ORom.Build.N0); RomFile compFile = compRom.Files.GetFile(ORom.FileList.code); RomFile decompFile = decompRom.Files.GetFile(ORom.FileList.code); BinaryReader compReader = new BinaryReader(compFile); BinaryReader decompReader = new BinaryReader(decompFile); byte[] compText = compReader.ReadBytes(compFile.Record.VRom.Size); byte[] decompText = decompReader.ReadBytes(decompFile.Record.VRom.Size); for (int i = 0; i < compFile.Record.VRom.Size; i++) { byte a = decompText[i]; byte b = compText[i]; if (a == b) { continue; } sb.AppendLine($"DECOMPRESS MISMATCH {i:X6}: {a:X2} {b:X2}"); break; } sb.AppendLine("Test Complete"); face.OutputText(sb.ToString()); }
private List <RomFile> GetContainingRomFiles(RomFile romFile) { var romFiles = new List <RomFile>(); using (var archive = GetArchiveReader(romFile.CompressionType, romFile.SourceFile)) { var files = archive.Entries.ToList(); foreach (var file in files) { var newRomFile = new RomFile { CompressionType = romFile.CompressionType, SourceFile = romFile.SourceFile, SourceFileName = Path.GetFileName(romFile.SourceFile), System = romFile.System, FileName = file.Key, IsInCompressedFile = true, FileNameWiped = "" }; romFiles.Add(newRomFile); } } return(romFiles); }
static void Main(string[] args) { if (args.Length <= 0) { Console.WriteLine("Usage:\nExtractor.exe [path]"); return; } var arg = args[0]; var file = new RomFile(arg); var buf = Console.OutputEncoding.GetBytes($"Possible access keys (the correct key is usually one of the first){Environment.NewLine}"); Console.OpenStandardError().Write(buf, 0, buf.Length); var ogcolor = Console.ForegroundColor; var keys = file.GetKeys(); if (keys.Length <= 0) { Console.WriteLine("No possible access keys found."); return; } Console.Write("[ "); Console.ForegroundColor = ConsoleColor.Green; Console.Write("'"); for (int i = 0; i < (keys.Length - 1); i++) { Console.Write($"{keys[i]}'"); Console.ForegroundColor = ogcolor; Console.Write(", "); Console.ForegroundColor = ConsoleColor.Green; Console.Write("'"); } Console.Write($"{keys[^1]}'");
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(); }
public static Scene InitializeScene(RomFile file, int id) { Scene scene = null; if (file == null) { return(scene); } scene = new Scene(file.Version.Game, id, file.Record.VirtualAddress); BinaryReader br = new BinaryReader(file); //if (LocalFileTable.Version == ORom.Build.N0 // && number == 6) // SpiritHack.LoadSpiritSceneHeader(br, scene); //else //try //{ LoadISceneRoomHeader(br, scene); //} //catch //{ // scene = null; //} return(scene); }
public void GlobalSetup() { Rom = RomFile.From(PathUtil.GetInputRomFilePath()); CodeFile = Rom.Files.First(x => x.VirtualStart == CodeVirtualStart); var slice = Rom.Slice(CodeFile); CodeBytes = Yaz.Decode(slice); }
public static Room InitializeRoom(RomFile file) { BinaryReader br; Room newRoom = new Room(file.Version.Game, file.Record.VirtualAddress); br = new BinaryReader(file); LoadISceneRoomHeader(br, newRoom); return(newRoom); }
public static Room LoadSpiritRoom(RomFile file, int roomNo) { BinaryReader br; Room room = new Room(file.Version.Game, file.Record.VRom); br = new BinaryReader(file); SpiritHack.LoadSpiritRoomHeader(br, room, roomNo); return(room); }
public void TestEncoding() { var rom = RomFile.From(RomFilename); var compressedFiles = rom.Files.Where(x => x.IsCompressed).ToArray(); foreach (var entry in compressedFiles) { PerformCompression(rom, entry); } }
static void PerformCompression(RomFile rom, VirtualFile entry) { var slice = rom.Slice(entry); var decoded = Yaz.Decode(slice); var encoded = Yaz.EncodeWithHeader(decoded, slice); // Yaz.EncodeAndCopy(decoded); var aligned = Yaz.AlignTo16(encoded); // Currently only compares compressed lengths, as compressed output is likely slightly different due to optimization. Assert.AreEqual(slice.Length, aligned); }
private void RomUp_Click(object sender, RoutedEventArgs e) { var selectedIndex = romList.SelectedIndex; if (selectedIndex > 0) { RomFile itemToMoveUp = roms[selectedIndex]; roms.RemoveAt(selectedIndex); roms.Insert(selectedIndex - 1, itemToMoveUp); romList.SelectedIndex = selectedIndex - 1; } }
private void RomDown_Click(object sender, RoutedEventArgs e) { var selectedIndex = romList.SelectedIndex; if (selectedIndex + 1 < roms.Count & selectedIndex >= 0) { RomFile itemToMoveDown = roms[selectedIndex]; roms.RemoveAt(selectedIndex); roms.Insert(selectedIndex + 1, itemToMoveDown); romList.SelectedIndex = selectedIndex + 1; } }
private void RemoveActor0001FromHeader(SceneHeader header, RomFile sceneFile) { var item = header[HeaderCommands.TransitionActorList]; if (item != null) { RemoveActor0001(sceneFile, item); } item = header[HeaderCommands.ActorList]; if (item != null) { RemoveActor0001(sceneFile, item); } }
private void RemoveActor0001FromFile(MemoryStream ms, RomFile sceneFile, SceneHeader header) { RemoveActor0001FromHeader(header, sceneFile); if (header.HasAlternateHeaders()) { foreach (var item in header.Alternate.Headers) { if (item != null) { RemoveActor0001FromHeader(item, sceneFile); } } } }
private static Cutscene GetCutscene(List <string> file, int csAddr) { Cutscene cs; FileRecord record; ORom rom = new ORom(file[0], ORom.Build.N0); record = rom.Files.GetFileStart(csAddr); RomFile f = rom.Files.GetFile(record.VRom); f.Stream.Position = f.Record.GetRelativeAddress(csAddr); cs = new Cutscene(f); return(cs); }
public void GlobalSetup() { Rom = RomFile.From(PathUtil.GetInputRomFilePath()); var samples = new List <byte[]>(); foreach (var entry in Rom.Files) { if (entry.IsCompressed) { var slice = Rom.Slice(entry); var bytes = slice.ToArray(); samples.Add(bytes); } } Samples = samples.ToArray(); }
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])); } }
/// <summary> /// Disassemble and reassemble the given ROM and assert the reassembled copy /// is bitwise identical to the original. /// </summary> private static void TestRom(string romToTest) { //arrange: files and disassembler var rom = new RomFile(romToTest); var asmFile = Path.ChangeExtension(romToTest, ".asm"); var objectFile = Path.ChangeExtension(romToTest, ".o"); var reassembledRom = Path.GetFileNameWithoutExtension(romToTest) + "_Reassembled" + Path.GetExtension(romToTest); var dasm = new Disassembler(rom, new Decoder()); //act: disassemble, reassemble, hash and compare try { dasm.Disassemble(asmFile); if (!Process.Start(new ProcessStartInfo() { FileName = Assembler, Arguments = $"{AssemblerFlags} -o \"{objectFile}\" \"{asmFile}\"" }).WaitForExit(WaitMilliseconds)) { Assert.Fail($"Assembling \"{asmFile}\" failed or took longer than the allowed {WaitMilliseconds} milliseconds."); } if (!Process.Start(new ProcessStartInfo() { FileName = Linker, Arguments = $"-o \"{reassembledRom}\" \"{objectFile}\"" }).WaitForExit(WaitMilliseconds)) { Assert.Fail($"Linking \"{reassembledRom}\" failed or took longer than the allowed {WaitMilliseconds} milliseconds."); } //assert: re-assembled ROMs are identical to originals Assert.AreEqual(ComputeHash(romToTest), ComputeHash(reassembledRom), $"Reassembled ROM differs from original ({romToTest})!"); //Process.Start(new ProcessStartInfo() { FileName = "bgb", Arguments = $"\"{reassembledRom}\"" }); } catch (Win32Exception ex) { if (ex.Message.Contains("cannot find the file specified") || ex.Message.Contains("No such file or directory")) { Assert.Fail("Unable to find RGBDS (is it installed and in your PATH?)"); } else { throw; } } }
private static void RemoveActor0001(RomFile sceneFile, SceneCommand item) { BinaryWriter bw = new BinaryWriter(sceneFile.Stream); var addr = (IDataCommand)item; var actors = ((IActorList)item).GetActors(); var reducedList = actors.Where(x => x.Actor != 1).ToList(); bw.BaseStream.Position = item.OffsetFromFile + 1; bw.Write((byte)reducedList.Count); bw.BaseStream.Position = addr.SegmentAddress.Offset; foreach (var actor in reducedList) { actor.Serialize(bw); } }
public static Scene InitializeScene(RomFile file, int id) { Scene scene = null; if (file == null) { return(scene); } scene = new Scene(file.Version.Game, id, file.Record.VRom); BinaryReader br = new BinaryReader(file); //if (file.Version == ORom.Build.N0 // && id == 6) // SpiritHack.LoadSpiritSceneHeader(br, scene); //else LoadISceneRoomHeader(br, scene); return(scene); }
public static void Main(string[] args) { ParseCommandLineArgs(args, out string outFile, out string inFile); if (inFile == null || outFile == null) { return; } var rom = new RomFile(inFile); var dasm = new Disassembler(rom, new Decoder()); Console.WriteLine($"Disassembling \"{inFile}\"..."); dasm.Disassemble(outFile); Console.WriteLine($"Wrote \"{outFile}\""); Process.Start(new ProcessStartInfo() { FileName = outFile, UseShellExecute = true }); }
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); }); } }
public void NewProject() { if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { RomProject.Instance.Reset(); UnknownData data = new UnknownData(0, File.ReadAllBytes(openFileDialog.FileName)); RomFile file = new RomFile(Path.GetFileNameWithoutExtension(openFileDialog.FileName), RomProject.Instance.Files.Count + 1, data); RomProject.Instance.AddRomFile(file); statusBarFile.Text = "New Project"; this.Enabled = false; MarioKart64Reader.ReadingFinished += ReadingFinished; MarioKart64Reader.ReadRom(); UpdateSelectedModule(); } }
private static ResultData GetData(_Scene scene, RomFile file, InCutsceneData inData) { ResultData outdata = new(scene, inData); if (!scene.TryConvertToRom(inData.RamStart, out int romAddr)) { outdata.result = ResultData.ResultType.Limit_UnallocatedSpace; return(outdata); } outdata.cutsceneRomAddress = romAddr; //else in range file.Stream.Position = file.Record.GetRelativeAddress(romAddr); try { Cutscene cs = new(file); if (cs.CommandCount < 0 || cs.Frames < 0) { outdata.result = ResultData.ResultType.Success_InvalidCutscene; } else if (cs.CommandCapReached) { outdata.result = ResultData.ResultType.Error_CutsceneParserLimitReached; } else { outdata.result = ResultData.ResultType.Success_ValidCutscene; } } catch { outdata.result = ResultData.ResultType.Exception; } return(outdata); }
private void UpdateObjectsFile(ObjectsFile fileObj) { byte[] objectsFile = DecompressFile(fileObj); byte[] reservedSpace = new byte[fileObj.ReservedLength]; byte[] reservedSpaceConstants = (byte[])_variableSpaceArrays.Dequeue(); // Scan for RAM addresses. for (int i = 0; i < objectsFile.Length; i += 4) { uint ramAddress = ASM.GetObjectsRamAddress(objectsFile, i); if (ramAddress < _BASERAM) { continue; } if (ramAddress > _upperRAM) { continue; } if (!((ramAddress & 0xFF000000) == 0x80000000)) { continue; } // Update RAM address. WriteObjectsAddress(objectsFile, ramAddress, i); } RomFile.UpdateTotalsOffset(objectsFile.Length, reservedSpace.Length); Array.Copy(reservedSpaceConstants, reservedSpace, reservedSpaceConstants.Length); // Update file buffer. _fileBuffer.Add(objectsFile); _fileBuffer.Add(reservedSpace); }
public IActionResult OnPostUpload() { if (SmallDropPool.Any(x => x.Selected)) { SettingsModel.SmallEnemyPool = SmallDropPool.Where(x => x.Selected).Select(x => x.Enum).ToList(); } if (LargeDropPool.Any(x => x.Selected)) { SettingsModel.LargeEnemyPool = LargeDropPool.Where(x => x.Selected).Select(x => x.Enum).ToList(); } //disabled values don't post if (!SettingsModel.ShufflePalaceRooms && !SettingsModel.ThunderbirdRequired) { SettingsModel.ThunderbirdRequired = true; } if (SettingsModel.ShuffleAllExperienceNeeded) { SettingsModel.ShuffleAttackExperienceNeeded = true; SettingsModel.ShuffleMagicExperienceNeeded = true; SettingsModel.ShuffleLifeExperienceNeeded = true; } using (var fileStream = RomFile.OpenReadStream()) { //generate rom, json var romGenerator = new Hyrule(SettingsModel.GetRandomizerProperties(RomFile.FileName, fileStream)); var rom = romGenerator.GenerateRomStream(); return(new FileStreamResult(rom.OutputStream, "application/octet-stream") { FileDownloadName = rom.FileName }); } }
public List <RomFile> Read(string sourceFile) { var directory = Path.GetDirectoryName(sourceFile); var romFile = new RomFile { CompressionType = GetCompressionType(sourceFile), SourceFile = sourceFile, SourceFileName = Path.GetFileName(sourceFile), System = Path.GetFileName(directory) }; if (romFile.CompressionType == CompressionType.None || KeepCompressed(romFile.System)) //no compression or file should not be decompressed. { romFile.IsInCompressedFile = false; romFile.FileName = Path.GetFileName(sourceFile); return(new List <RomFile> { romFile }); } return(GetContainingRomFiles(romFile)); }
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()); }