diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/FixKeyAlreadyExistsErrorOnAchievementPatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/FixKeyAlreadyExistsErrorOnAchievementPatch.cs new file mode 100644 index 0000000..885a655 --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/RaidFix/FixKeyAlreadyExistsErrorOnAchievementPatch.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using HarmonyLib; +using SPT.Reflection.Patching; + +namespace SPT.SinglePlayer.Patches.RaidFix +{ + public class FixKeyAlreadyExistsErrorOnAchievementPatch: ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(AbstractAchievementControllerClass), nameof(AbstractAchievementControllerClass.OnConditionalStatusChangedEvent)); + } + + [PatchPrefix] + public static bool Prefix(GClass1368 achievement, bool notify, AbstractAchievementControllerClass __instance) + { + if (achievement.IsDone() && __instance.Profile.AchievementsData.ContainsKey(achievement.Id)) + { + // Tries to add same achievement key a second time, throwing a "An item with the same key has already been added" error + return false; // Skip original + } + + return true; // Do original + } + } +} diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index ff907d3..3c1c143 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -63,7 +63,9 @@ namespace SPT.SinglePlayer new ScavIsPlayerEnemyPatch().Enable(); new BotOwnerManualUpdatePatch().Enable(); new FirearmControllerShowIncompatibleNotificationClass().Enable(); - } + new FixKeyAlreadyExistsErrorOnAchievementPatch().Enable(); + + } catch (Exception ex) { Logger.LogError($"A PATCH IN {GetType().Name} FAILED. SUBSEQUENT PATCHES HAVE NOT LOADED");