/// <summary>Intended to be invoked once during the mod entry</summary> /// <param name="ModDataKeys">The Keys of the ModData KeyValuePairs that should be maintained.</param> internal static void Entry(IModHelper helper, params string[] ModDataKeys) { TrackedKeys = ModDataKeys.Distinct().ToList().AsReadOnly(); // EDIT: These 2 event listeners probably aren't needed anymore? I think a hotfix update added similar logic to the vanilla game somewhere around Update 1.5.1 or 1.5.2 // EDIT2: This logic seems like it's still needed for sub-types of StardewValley.Object // Decompile StardewValley.exe, and look at StardewValley.Object.placementAction, which seems to be creating new instances of // certain sub-types like CrabPot/Cask/WoodChipper, without also calling Item._getOneFrom(Item source) to retain the modData helper.Events.GameLoop.UpdateTicking += GameLoop_UpdateTicking; helper.Events.World.ObjectListChanged += World_ObjectListChanged; HarmonyInstance Harmony = HarmonyInstance.Create(ModEntry.ModInstance.ModManifest.UniqueID); // EDIT: These patches probably aren't needed anymore? I think a hotfix update added similar logic to the vanilla game somewhere around Update 1.5.1 or 1.5.2 // Patch Item.getOne to copy the modData to the return value Harmony.Patch( original: AccessTools.Method(typeof(SObject), nameof(SObject.getOne)), postfix: new HarmonyMethod(typeof(GetOnePatch), nameof(GetOnePatch.Postfix)) ); //Harmony.Patch( // original: AccessTools.Method(typeof(WoodChipper), nameof(WoodChipper.getOne)), // postfix: new HarmonyMethod(typeof(GetOnePatch), nameof(GetOnePatch.WoodChipper_Postfix)) //); //Harmony.Patch( // original: AccessTools.Method(typeof(Cask), nameof(Cask.getOne)), // postfix: new HarmonyMethod(typeof(GetOnePatch), nameof(GetOnePatch.Cask_Postfix)) //); //Harmony.Patch( // original: AccessTools.Method(typeof(CrabPot), nameof(CrabPot.getOne)), // postfix: new HarmonyMethod(typeof(GetOnePatch), nameof(GetOnePatch.CrabPot_Postfix)) //); }
/// <summary>Intended to be invoked once during the mod entry</summary> /// <param name="ModDataKeys">The Keys of the ModData KeyValuePairs that should be maintained.</param> internal static void Entry(IModHelper helper, params string[] ModDataKeys) { TrackedKeys = ModDataKeys.Distinct().ToList().AsReadOnly(); helper.Events.GameLoop.UpdateTicking += GameLoop_UpdateTicking; helper.Events.World.ObjectListChanged += World_ObjectListChanged; HarmonyInstance Harmony = HarmonyInstance.Create(ModEntry.ModInstance.ModManifest.UniqueID); // Patch Item.getOne to copy the modData to the return value Harmony.Patch( original: AccessTools.Method(typeof(SObject), nameof(SObject.getOne)), postfix: new HarmonyMethod(typeof(GetOnePatch), nameof(GetOnePatch.Postfix)) ); }