Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ToolRefund v1.0.0
ToolRefund.dll
Decompiled 8 months agousing System; using System.Collections; 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 Microsoft.CodeAnalysis; using MonoMod.RuntimeDetour; using MonoMod.Utils; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("ToolRefund")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ToolRefund")] [assembly: AssemblyTitle("ToolRefund")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 ToolRefund { [BepInPlugin("pseudopulse.ToolRefund", "ToolRefund", "1.0.0")] public class ToolRefund : BaseUnityPlugin { public delegate bool orig_TryReplenishSingle(ToolItem self, bool doReplenish, float inCost, out float outCost, out int reserveCost); public delegate void orig_OnWasUsed(ToolItem self, bool isEmpty); public delegate IEnumerator orig_Respawn(HeroController self, Transform point); public const string GUID = "pseudopulse.ToolRefund"; public const string NAME = "ToolRefund"; public const string VERSION = "1.0.0"; public static Dictionary<string, int> ToolMapBuffer = new Dictionary<string, int>(); public static Dictionary<string, int> ToolMap = new Dictionary<string, int>(); private void Awake() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) new Hook((MethodBase)typeof(ToolItem).GetMethod("TryReplenishSingle", (BindingFlags)(-1)), typeof(ToolRefund).GetMethod("RefundTool", (BindingFlags)(-1))); new Hook((MethodBase)typeof(ToolItem).GetMethod("OnWasUsed", (BindingFlags)(-1)), typeof(ToolRefund).GetMethod("MarkForRefund", (BindingFlags)(-1))); new Hook((MethodBase)typeof(HeroController).GetMethod("Respawn", (BindingFlags)(-1)), typeof(ToolRefund).GetMethod("Reset", (BindingFlags)(-1))); } public static bool RefundTool(orig_TryReplenishSingle orig, ToolItem self, bool doReplenish, float inCost, out float outCost, out int reserveCost) { bool result = orig(self, doReplenish, inCost, out outCost, out reserveCost); ToolMapBuffer.Clear(); Debug.Log((object)self.name); Debug.Log((object)("contains?: " + ToolMap.ContainsKey(self.name))); if (ToolMap.ContainsKey(self.name) && ToolMap[self.name] > 0) { Debug.Log((object)ToolMap[self.name]); outCost = 0f; if (!doReplenish) { return true; } ToolMap[self.name]--; return true; } return result; } public static void MarkForRefund(orig_OnWasUsed orig, ToolItem self, bool isEmpty) { orig(self, isEmpty); if (!ToolMapBuffer.ContainsKey(self.name)) { Debug.Log((object)("added " + self.name + " to buffer")); ToolMapBuffer.Add(self.name, 0); } ToolMapBuffer[self.name]++; Debug.Log((object)$"{self.name} count is {ToolMapBuffer[self.name]}"); } public static IEnumerator Reset(orig_Respawn orig, HeroController self, Transform point) { ToolMap.Clear(); Extensions.AddRange<string, int>(ToolMap, ToolMapBuffer); Debug.Log((object)"copying buffer"); return orig(self, point); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }