/// <summary> /// Replaces the tryToDepositThisItem method in Stardew Valley's Bundle.cs with this file's NewTryToDepositItem method /// NOTE: THIS IS UNSAFE CODE, CHANGE WITH EXTREME CAUTION /// </summary> public static void ReplaceTryToDepositMethod() { SVBundle bundle = Globals.ModRef.Helper.Reflection .GetField <SVBundle>(_currentActiveBundleMenu, "currentPageBundle", true) .GetValue(); if (bundle == null) { return; } MethodInfo methodToReplace = Globals.ModRef.Helper.Reflection.GetMethod(bundle, "tryToDepositThisItem", true).MethodInfo; MethodInfo methodToInject = typeof(BundleMenuAdjustments).GetMethod("NewTryToDepositItem"); Globals.RepointMethod(methodToReplace, methodToInject); }
/// <summary> /// Replaces the canAcceptThisItem method in Stardew Valley's Bundle.cs with this file's NewCanAcceptThisItem method /// NOTE: THIS IS UNSAFE CODE, CHANGE WITH EXTREME CAUTION /// </summary> public static void ReplaceCanAcceptThisItemMethod() { SVBundle bundle = Globals.ModRef.Helper.Reflection .GetField <SVBundle>(_currentActiveBundleMenu, "currentPageBundle", true) .GetValue(); if (bundle == null) { return; } var signature = new[] { typeof(SVItem), typeof(ClickableTextureComponent), typeof(bool) }; MethodInfo methodToReplace = bundle.GetType().GetMethod("canAcceptThisItem", signature); MethodInfo methodToInject = typeof(BundleMenuAdjustments).GetMethod("NewCanAcceptThisItem"); Globals.RepointMethod(methodToReplace, methodToInject); }