using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ShopDuplicateFix { [BepInPlugin("benjamin.shopduplicatefix", "ShopDuplicateFix", "1.0.0")] [BepInProcess("REPO.exe")] public class Plugin : BaseUnityPlugin { public const string Guid = "benjamin.shopduplicatefix"; public const string Name = "ShopDuplicateFix"; public const string Version = "1.0.0"; internal static ManualLogSource Log; private Harmony _harmony; internal static ConfigEntry Enabled; internal static ConfigEntry Verbose; private void Awake() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Master switch."); Verbose = ((BaseUnityPlugin)this).Config.Bind("Debug", "Verbose", true, "Log every purchase call with the count before and after. ON by default for the first release - the log is the proof of what the game is doing underneath. Turn off once you've seen it working."); _harmony = new Harmony("benjamin.shopduplicatefix"); _harmony.PatchAll(typeof(PurchaseCountPatch)); _harmony.PatchAll(typeof(SessionResetPatch)); Log.LogInfo((object)"ShopDuplicateFix v1.0.0 loaded. Two paid = two delivered."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } internal static void Trace(string msg) { if (Verbose != null && Verbose.Value) { Log.LogInfo((object)msg); } } } [HarmonyPatch(typeof(StatsManager))] internal static class PurchaseCountPatch { internal static readonly Dictionary SessionCalls = new Dictionary(); [HarmonyPostfix] [HarmonyPatch("ItemPurchase")] private static void AfterItemPurchase(StatsManager __instance, string itemName) { if (!Plugin.Enabled.Value || !SemiFunc.IsMasterClientOrSingleplayer() || string.IsNullOrEmpty(itemName)) { return; } SessionCalls.TryGetValue(itemName, out var value); value++; SessionCalls[itemName] = value; if (__instance.itemsPurchased != null) { __instance.itemsPurchased.TryGetValue(itemName, out var value2); if (value2 < value) { __instance.itemsPurchased[itemName] = value; Plugin.Log.LogInfo((object)$"[ShopDuplicateFix] '{itemName}': paid for {value}, game recorded {value2} - corrected to {value}."); } else { Plugin.Trace($"[ShopDuplicateFix] '{itemName}': call {value}, recorded {value2} - vanilla counted correctly, no fix needed."); } } } } [HarmonyPatch(typeof(RunManager))] internal static class SessionResetPatch { [HarmonyPostfix] [HarmonyPatch("ChangeLevel")] private static void AfterChangeLevel() { if (PurchaseCountPatch.SessionCalls.Count > 0) { Plugin.Trace($"[ShopDuplicateFix] Level changed - session tally cleared ({PurchaseCountPatch.SessionCalls.Count} item name(s))."); } PurchaseCountPatch.SessionCalls.Clear(); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "ShopDuplicateFix"; public const string PLUGIN_NAME = "ShopDuplicateFix"; public const string PLUGIN_VERSION = "1.0.0"; } }