Skip to content

Commit

Permalink
Do encrypted DS rom detection better
Browse files Browse the repository at this point in the history
  • Loading branch information
CasualPokePlayer committed Oct 19, 2024
1 parent 2ddfc5f commit c954e8c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -192,12 +193,13 @@ public NDS(CoreLoadParameters<NDSSettings, NDSSyncSettings> lp)

if (!_activeSyncSettings.UseRealBIOS)
{
// check if the user is using an encrypted rom
// if they are, they need to be using real bios files
Span<byte> decryptedBytePattern = stackalloc byte[] { 0xFF, 0xDE, 0xFF, 0xE7, 0xFF, 0xDE, 0xFF, 0xE7 };
if (!roms[0].AsSpan(0x4000, 8).SequenceEqual(decryptedBytePattern))
var arm9RomOffset = BinaryPrimitives.ReadInt32LittleEndian(roms[0].AsSpan(0x20, 4));
if (arm9RomOffset is >= 0x4000 and < 0x8000)
{
_activeSyncSettings.UseRealBIOS = true;
// check if the user is using an encrypted rom
// if they are, they need to be using real bios files
var secureAreaId = BinaryPrimitives.ReadUInt64LittleEndian(roms[0].AsSpan(arm9RomOffset, 8));
_activeSyncSettings.UseRealBIOS = secureAreaId != 0xE7FFDEFF_E7FFDEFF;
}
}

Expand Down

0 comments on commit c954e8c

Please sign in to comment.