mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-20 09:41:14 +02:00
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.
(cherry picked from commit 93b4c53c8a)
This commit is contained in:
@@ -749,8 +749,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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user