Fix crash on duplicate Build IDs in ModLoader.LoadCheats

Multiple executables may report the same Build ID, causing ToDictionary to throw an ArgumentException while creating the executable lookup.

Build the lookup incrementally and keep the first code address when duplicate Build IDs are encountered. Log a warning if a duplicate Build ID is associated with a different code address.
This commit is contained in:
avan
2026-09-08 15:54:22 -05:00
committed by KeatonTheBot
parent ef14467d1f
commit 93b4c53c8a
+22 -2
View File
@@ -783,8 +783,28 @@ namespace Ryujinx.HLE.HOS
}
List<Cheat> cheats = mods.Cheats;
Dictionary<string, ulong> processExes = tamperInfo.BuildIds.Zip(tamperInfo.CodeAddresses, (k, v) => new { k, v })
.ToDictionary(x => x.k[..Math.Min(Cheat.CheatIdSize, x.k.Length)], x => x.v);
Dictionary<string, ulong> processExes = new();
foreach ((string buildId, ulong codeAddress) in tamperInfo.BuildIds.Zip(tamperInfo.CodeAddresses))
{
string normalizedBuildId = buildId[..Math.Min(Cheat.CheatIdSize, buildId.Length)];
if (processExes.TryGetValue(normalizedBuildId, out ulong existingAddress))
{
if (existingAddress != codeAddress)
{
Logger.Warning?.Print(
LogClass.ModLoader,
$"Duplicate BuildId prefix '{normalizedBuildId}' has different code addresses. " +
$"Existing: 0x{existingAddress:X}, duplicate: 0x{codeAddress:X}. " +
$"Keeping the first one.");
}
continue;
}
processExes.Add(normalizedBuildId, codeAddress);
}
foreach (Cheat cheat in cheats)
{