private void DumpActorTable() { List <RomVersion> versions = new List <RomVersion>(); versions.AddRange(ORom.GetSupportedBuilds()); versions.AddRange(MRom.GetSupportedBuilds()); StringBuilder sb = new StringBuilder(); foreach (var version in versions) { string outFile = $"actor_dlf_{version.ShortUniqueKey}.txt"; if (PathUtil.TryGetRomLocation(version, out string file)) { var txt = Get.ActorTable(Rom.New(file, version)); System.IO.File.WriteAllText(outFile, txt); sb.AppendLine($"Created {outFile}"); } else { sb.AppendLine($"{outFile} failed; no rom found"); } } outRichTextBox.Text = sb.ToString(); }
static void DisassembleRom(RomVersion version, string path, Func <DisassemblyTask, bool> filter) { Console.WriteLine($"{version} {path}"); Console.Write("Initializing task list: "); Rom rom = Rom.New(path, version); List <DisassemblyTask> taskList = DisassemblyTask.CreateTaskList(rom); taskList = taskList.Where(filter).Where(x => x.VRom.End > 0).ToList(); if (taskList.Count == 0) { Console.WriteLine("Error: No tasks to process!"); return; } Console.WriteLine("DONE!"); Console.Write($"Loading symbol table from file: "); LoadFunctionDatabase(version); Console.WriteLine("DONE!"); Console.WriteLine("Disassembling files: "); Stream getFile(FileAddress x) => rom.Files.GetFile(x); DisassembleTasks(rom.Version, taskList, getFile); DumpFoundFunctions(rom.Version, Disassemble.GetFunctions()); }
private static void DecompressRom(string[] args) { if (args.Length != 4) { return; } string inRom = args[0]; string outRom = args[1]; string gameStr = args[2]; string buildStr = args[3]; if (!FileExists(inRom)) { return; } RomVersion version = new(gameStr, buildStr); if (version.Game == Game.Undefined) { return; } using (FileStream fw = File.Create(outRom)) { Rom rom = Rom.New(inRom, version); RomBuilder.DecompressRom(rom, fw); } }
private static void CompressRom(string[] args) { if (args.Length != 5) { return; } string inRom = args[0]; string outRom = args[1]; string gameId = args[2]; string build = args[3]; string inRefRom = args[4]; if (!FileExists(inRom)) { Console.WriteLine($"Cannot find file {inRom}"); return; } RomVersion version = new(gameId, build); if (version.Game == Game.Undefined) { Console.WriteLine($"Unrecognized game and version: {gameId} {build}"); return; } using (var fw = File.Create(outRom)) { RomBuilder.CompressRom(Rom.New(inRom, version), new ORom(inRefRom, version), fw); } }
static void OverlayTest(RomVersion ver, string testOvl) { PathUtil.TryGetRomLocation(ver, out string path); Rom rom = Rom.New(path, ver); var tasks = DisassemblyTask.CreateTaskList(rom); Disassemble.PrintRelocations = true; Disassemble.GccOutput = true; var task = tasks.SingleOrDefault(x => x.Name == testOvl || x.Name == $"ovl_{testOvl}"); if (task == null) { Console.WriteLine("Cannot find overlay"); return; } //var taskbss = tasks.Where(x => x.Sections["bss"]?.Size > 0).ToList(); var reader = new BinaryReader(rom.Files.GetFile(task.VRom)); //using (StreamWriter sw = new StreamWriter("__test.txt")) //{ // foreach (var rel in task.Map.Relocations.Where(x => x.SectionId == Overlay.RelocationWord.Section.text)) // { // reader.BaseStream.Position = rel.Offset; // sw.WriteLine($"{rel.Offset:X6}: {rel.RelocType} {GetOP(reader.ReadBigInt32())}"); // } //} using (StreamWriter sw = new StreamWriter($"__{testOvl}.txt")) { BinaryReader br = new BinaryReader(rom.Files.GetFile(task.VRom)); Disassemble.FirstParse(br, task); if (Disassemble.GccOutput) { sw.WriteLine("#include <mips.h>"); sw.WriteLine(".set noreorder"); sw.WriteLine(".set noat"); sw.WriteLine(); } Disassemble.Task(sw, br, task); } using (StreamWriter sw = new StreamWriter($"__{testOvl}_f.txt")) { foreach (var item in Disassemble.Symbols.OrderBy(x => x.Key)) { sw.WriteLine($"{item.Value.ToString()} = 0x{item.Key}"); } } }
private void SetRomTypeSettings(RomVersion version) { OpenFileDialog openFile = new OpenFileDialog(); DialogResult result = DialogResult.OK; RomVersion inputVersion = version; //Set openFile title in case we need to look for a rom openFile.Title = $"Open {version} rom"; string romLocation; if (!version.IsCustomBuild()) { if (!PathUtil.TryGetRomLocation(version, out romLocation)) { result = openFile.ShowDialog(); if (result == DialogResult.OK) { PathUtil.SetRomLocation(version, openFile.FileName); PathUtil.TryGetRomLocation(version, out romLocation); } } } else { result = openFile.ShowDialog(); romLocation = openFile.FileName; if (result == DialogResult.OK) { using (VersionSelector vs = new VersionSelector()) { vs.Game = version.Game; result = vs.ShowDialog(); version = vs.Version; } } } openFile.Dispose(); rom = result == DialogResult.OK ? Rom.New(romLocation, version) : null; //update string romStats = rom == null ? $"Error: No Rom!" : $"{inputVersion.Game}, File Stats Mode: {version}{Environment.NewLine}{romLocation}"; outputRichTextBox.Clear(); outputRichTextBox.AppendText(romStats); }
private static Func <DisassemblyTask, bool> GetDisassembleOverlayFilter(DisassembleFileOptions opts, RomVersion version, string path) { Func <DisassemblyTask, bool> filter = x => false; if (opts.FileStart != null) { if (int.TryParse(opts.FileStart, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int fileStart)) { filter = x => x.VRom.Start == fileStart; } else { Console.WriteLine($"invalid start address {opts.FileStart}"); return(null); } } else if (opts.File != null) { filter = x => x.Name == opts.File || x.Name == $"ovl_{opts.File}"; } else { Rom rom = Rom.New(path, version); OverlayRecord dlf_record; if (!int.TryParse(opts.ActorIndex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int actorIndex)) { Console.WriteLine($"actor index {actorIndex} is invalid"); return(null); } if (actorIndex == 0) { dlf_record = rom.Files.GetPlayPauseOverlayRecord(1); } else { dlf_record = rom.Files.GetActorOverlayRecord(actorIndex); if (dlf_record.VRom.Size == 0) { Console.WriteLine($"actor 0x{opts.ActorIndex:X4} does not have an overlay file"); return(null); } } filter = x => x.VRom.Start == dlf_record.VRom.Start; } return(filter); }
private static void CompressRom(string[] args) { string inRom; string outRom; string gameId; string build; if (args.Length != 5) { return; } inRom = args[0]; outRom = args[1]; gameId = args[2]; build = args[3]; string inRefRom = args[4]; if (!FileExists(inRom)) { Console.WriteLine($"Cannot find file {inRom}"); return; } RomVersion version = new RomVersion(gameId, build); if (version.Game == Game.Undefined) { Console.WriteLine($"Unrecognized game and version: {gameId} {build}"); return; } using (FileStream fw = new FileStream(outRom, FileMode.Create)) { RomBuilder.CompressRom(Rom.New(inRom, version), new ORom(inRefRom, version), fw); //using (FileStream fs = new FileStream(inRom, FileMode.Open, FileAccess.Read)) //{ // RomBuilder.CompressRom(fs, version, new ORom(inRefRom, version), fw); //} } }