Exemplo n.º 1
0
        public static byte[] WriteSramToSavestate(this Stream source, GameRegion region, byte[] sram)
        {
            var unchangedSavestate = SavestateReader.Load(source, true);
            var changedSavestate   = SavestateWramHelper.CopySramToSavestate(unchangedSavestate, region, sram);

            return(SavestateWriter.Save(source, changedSavestate));
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.BufferHeight = 1000;
            Console.WindowHeight = 50;

            try
            {
                if (args.Length == 0)
                {
                    throw new ArgumentException("Pass a file as argument.");
                }

                var filePath = args[0];

                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Reading file:");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(filePath);
                Console.WriteLine();

                var savestateFile = SavestateReader.Load(filePath);
                var sramFile      = SavestateWramHelper.CreateSramFileFromSavestate(savestateFile, GameRegion.EnglishNtsc);

                var fileName    = Path.GetFileNameWithoutExtension(filePath);
                var srmFilePath = Path.Join(Path.GetDirectoryName(filePath), fileName + ".srm");

                if (File.Exists(srmFilePath))
                {
                    File.Copy(srmFilePath, srmFilePath + ".backup", true);
                }

                sramFile.Save(srmFilePath);

                DumpWram();
                DumpWSram();

                ShowCommands(filePath);

                Console.ForegroundColor = ConsoleColor.Gray;

                while (true)
                {
                    var key = Console.ReadLine();

                    try
                    {
                        switch (key)
                        {
                        case "":
                            continue;

                        case "q":
                            return;

                        case "?":
                            ShowCommands(filePath);
                            break;

                        case "cls":
                            Console.Clear();
                            break;

                        case "vars":
                            ShowVariables();
                            break;

                        case "slot":
                            Console.WriteLine(sramFile.GetSegment(0).ToString());
                            break;

                        case { } when key.StartsWith("var "):
                            ShowVariable(sramFile.GetSegment(0).Data, key);

                            break;

                        case { } when key.StartsWith("byte"):
                            ShowOffsetNumber(sramFile.GetSegmentBytes(0), key);

                            break;

                        case { } when key.StartsWith("char"):
                            ShowOffsetCharacters(sramFile.GetSegmentBytes(0), key);

                            break;

                        case { } when key.StartsWith("string"):
                            ShowOffsetString(sramFile.GetSegmentBytes(0), key);

                            break;

                        default:
                            Console.WriteLine(@$ "Unknown command name: " "{key}" "");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR:" + ex.Message);
                        Console.WriteLine();
                        Console.ReadKey();
                    }
                }

                void DumpWSram()
                {
                    Console.ForegroundColor = ConsoleColor.Green;

                    var file = $"2_W-SramDump_{sramFile.Size}_bytes.txt";

                    File.WriteAllBytes(file, sramFile.Buffer);
                    Console.WriteLine($"Dumped W-S-RAM ({sramFile.Size} bytes): {file}");

                    var bytes = sramFile.GetSegmentBytes(0);

                    file = $"3_SaveSlot0Dump_{bytes.Length}_bytes.txt";
                    File.WriteAllBytes(file, bytes);
                    Console.WriteLine($"Dumped SaveSlot0 ({bytes.Length} bytes): {file}");
                    Console.WriteLine();
                    Console.ResetColor();
                }

                void DumpWram()
                {
                    Console.ForegroundColor = ConsoleColor.Green;

                    var data = savestateFile.RAM.Data;
                    var file = $"1_WramDump_{data.Length}_bytes.txt";

                    File.WriteAllBytes(file, data);

                    Console.WriteLine($"Dumped WRAM ({data.Length} bytes): {file}");
                    Console.ResetColor();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR:" + ex.Message);
                Console.WriteLine();
                Console.ReadKey();
            }
        }
Exemplo n.º 3
0
 public static byte[] ReadSramFromSavestate(this Stream source, GameRegion region) => SavestateWramHelper.CreateSramFileFromSavestate(SavestateReader.Load(source), region).Buffer;