From c954e8c189597320059e1986a794cd8f463daa04 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:41:13 -0700 Subject: [PATCH] Do encrypted DS rom detection better --- .../Consoles/Nintendo/NDS/MelonDS.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs index 7c43369b9bf..e82c6d139ef 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs @@ -1,3 +1,4 @@ +using System.Buffers.Binary; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -192,12 +193,13 @@ public NDS(CoreLoadParameters 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 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; } }