public void WriteSfromHeader1(SfromHeader1 sfromHeader1) { foreach (var f in Directory.GetFiles(basePath, "*.sfrom")) { var sfrom = File.ReadAllBytes(f); var data = sfromHeader1.GetBytes(); Array.Copy(data, 0, sfrom, 0, data.Length); File.WriteAllBytes(f, sfrom); return; } throw new Exception(".sfrom file not found"); }
private static void MakeSfrom(ref byte[] rawRomData, ref byte saveCount) { var romHeaderLoRom = SnesRomHeader.Read(rawRomData, 0x7FC0); var romHeaderHiRom = SnesRomHeader.Read(rawRomData, 0xFFC0); SnesRomHeader romHeader; bool loRom = true; bool hiRom = true; if (romHeaderLoRom.GameTitle.Length == 0) { loRom = false; } foreach (char c in romHeaderLoRom.GameTitle) { if (c < 31 || c > 127) { loRom = false; } } if (romHeaderHiRom.GameTitle.Length == 0) { hiRom = false; } foreach (char c in romHeaderHiRom.GameTitle) { if (c < 31 || c > 127) { hiRom = false; } } SnesRomType romType; if (loRom && !hiRom) { romType = SnesRomType.LoRom; romHeader = romHeaderLoRom; } else if (!loRom && hiRom) { romType = SnesRomType.HiRom; romHeader = romHeaderHiRom; } else if (((romHeaderLoRom.RomMakeup & 1) == 0) && ((romHeaderHiRom.RomMakeup & 1) == 0)) { romType = SnesRomType.LoRom; romHeader = romHeaderLoRom; } else if (((romHeaderLoRom.RomMakeup & 1) == 1) && ((romHeaderHiRom.RomMakeup & 1) == 1)) { romType = SnesRomType.HiRom; romHeader = romHeaderHiRom; } else { // WTF is it? romType = SnesRomType.HiRom; romHeader = romHeaderHiRom; } string gameTitle = romHeader.GameTitle.Trim(); Debug.WriteLine($"Game title: {gameTitle}"); ushort presetId = 0; // 0x1011; ushort chip = 0; if (SfxTypes.Contains(romHeader.RomType)) // Super FX chip { Debug.WriteLine($"Super FX chip detected"); chip = 0x0C; } if (!knownPresets.TryGetValue(gameTitle, out presetId)) // Known codes { if (Dsp1Types.Contains(romHeader.RomType)) { Debug.WriteLine($"DSP-1 chip detected"); presetId = 0x10BD; // ID from Mario Kard, DSP1 } if (SA1Types.Contains(romHeader.RomType)) { Debug.WriteLine($"SA1 chip detected"); presetId = 0x109C; // ID from Super Mario RPG, SA1 } } Debug.WriteLine(string.Format("PresetID: 0x{0:X2}{1:X2}, extra byte: {2:X2}", presetId & 0xFF, (presetId >> 8) & 0xFF, chip)); var sfromHeader1 = new SfromHeader1((uint)rawRomData.Length); var sfromHeader2 = new SfromHeader2((uint)rawRomData.Length, presetId, romType, chip); var sfromHeader1Raw = sfromHeader1.GetBytes(); var sfromHeader2Raw = sfromHeader2.GetBytes(); var result = new byte[sfromHeader1Raw.Length + rawRomData.Length + sfromHeader2Raw.Length]; Array.Copy(sfromHeader1Raw, 0, result, 0, sfromHeader1Raw.Length); Array.Copy(rawRomData, 0, result, sfromHeader1Raw.Length, rawRomData.Length); Array.Copy(sfromHeader2Raw, 0, result, sfromHeader1Raw.Length + rawRomData.Length, sfromHeader2Raw.Length); if (romHeader.SramSize > 0) { saveCount = 3; } rawRomData = result; }
private static void MakeSfrom(ref byte[] rawRomData, ref byte saveCount, out bool problemGame) { SnesRomType romType; string gameTitle; SnesRomHeader romHeader = GetCorrectHeader(rawRomData, out romType, out gameTitle); /* * if (romType == SnesRomType.LoRom) * rawRomData[0x7FD9] = 0x01; // Force NTSC * else * rawRomData[0xFFD9] = 0x01; // Force NTSC */ Trace.WriteLine($"Game title: {gameTitle}"); Trace.WriteLine($"ROM type: {romType}"); ushort presetId = 0; byte chip = 0; if (SfxTypes.Contains(romHeader.RomType)) // Super FX chip { Trace.WriteLine($"Super FX chip detected"); chip = 0x0C; } if (!knownPresets.TryGetValue(gameTitle, out presetId)) // Known codes { if (Dsp1Types.Contains(romHeader.RomType)) { Trace.WriteLine($"DSP-1 chip detected"); presetId = 0x10BD; // ID from Mario Kard, DSP1 } if (SA1Types.Contains(romHeader.RomType)) { Trace.WriteLine($"SA1 chip detected"); presetId = 0x109C; // ID from Super Mario RPG, SA1 } } else { Trace.WriteLine($"We have preset for this game"); } Trace.WriteLine(string.Format("PresetID: 0x{0:X2}{1:X2}, extra byte: {2:X2}", presetId & 0xFF, (presetId >> 8) & 0xFF, chip)); var sfromHeader1 = new SfromHeader1((uint)rawRomData.Length); var sfromHeader2 = new SfromHeader2((uint)rawRomData.Length, presetId, romType, chip); var sfromHeader1Raw = sfromHeader1.GetBytes(); var sfromHeader2Raw = sfromHeader2.GetBytes(); var result = new byte[sfromHeader1Raw.Length + rawRomData.Length + sfromHeader2Raw.Length]; Array.Copy(sfromHeader1Raw, 0, result, 0, sfromHeader1Raw.Length); Array.Copy(rawRomData, 0, result, sfromHeader1Raw.Length, rawRomData.Length); Array.Copy(sfromHeader2Raw, 0, result, sfromHeader1Raw.Length + rawRomData.Length, sfromHeader2Raw.Length); if (romHeader.SramSize > 0) { saveCount = 3; } else { saveCount = 0; } problemGame = problemGames.Contains(gameTitle); rawRomData = result; }
private static void MakeSfrom(ref byte[] rawRomData) { var romHeaderLoRom = SnesRomHeader.Read(rawRomData, 0x7FC0); var romHeaderHiRom = SnesRomHeader.Read(rawRomData, 0xFFC0); SnesRomHeader romHeader; bool loRom = true; bool hiRom = true; if (romHeaderLoRom.GameTitle.Length == 0) { loRom = false; } foreach (char c in romHeaderLoRom.GameTitle) { if (c < 31 || c > 127) { loRom = false; } } if (romHeaderHiRom.GameTitle.Length == 0) { hiRom = false; } foreach (char c in romHeaderHiRom.GameTitle) { if (c < 31 || c > 127) { hiRom = false; } } SnesRomType romType; if (loRom && !hiRom) { romType = SnesRomType.LoRom; romHeader = romHeaderLoRom; } else if (!loRom && hiRom) { romType = SnesRomType.HiRom; romHeader = romHeaderHiRom; } else if ((romHeaderLoRom.RomMakeup & 1) == 0) { romType = SnesRomType.LoRom; romHeader = romHeaderLoRom; } else { romType = SnesRomType.HiRom; romHeader = romHeaderHiRom; } string gameTitle = romHeader.GameTitle.Trim(); ushort presetId = 0; // 0x1011; ushort chip = 0; if (SfxTypes.Contains(romHeader.RomType)) // Super FX chip { chip = 0x0C; } if (!knownPresets.TryGetValue(gameTitle, out presetId)) // Known codes { if (Dsp1Types.Contains(romHeader.RomType)) { presetId = 0x10BD; // ID from Mario Kard, DSP1 } if (SA1Types.Contains(romHeader.RomType)) { presetId = 0x109C; // ID from Super Mario RPG, SA1 } } var sfromHeader1 = new SfromHeader1((uint)rawRomData.Length); var sfromHeader2 = new SfromHeader2((uint)rawRomData.Length, presetId, romType, chip); var sfromHeader1Raw = sfromHeader1.GetBytes(); var sfromHeader2Raw = sfromHeader2.GetBytes(); var result = new byte[sfromHeader1Raw.Length + rawRomData.Length + sfromHeader2Raw.Length]; Array.Copy(sfromHeader1Raw, 0, result, 0, sfromHeader1Raw.Length); Array.Copy(rawRomData, 0, result, sfromHeader1Raw.Length, rawRomData.Length); Array.Copy(sfromHeader2Raw, 0, result, sfromHeader1Raw.Length + rawRomData.Length, sfromHeader2Raw.Length); rawRomData = result; }