using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using TeamCherry.Localization; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("InfiniteTools")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("InfiniteTools")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("0d2eaa2c-42c1-4097-aabe-487d3c5656f0")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] [BepInPlugin("com.dream.InfiniteTools", "Infinite Tools", "1.3.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class InfiniteTools : BaseUnityPlugin { private enum TypeOfReplenishment { EveryUse, OnBench, OnHeal } private static ConfigEntry CfgEnableInfiniteAllToolsUse; private static Dictionary ToolNamesDict = new Dictionary(); private static readonly Dictionary> ToolConfigDict = new Dictionary>(); private static ConfigEntry CfgReplenishmentMethod; private EventRegister HeroHealedRegister; private bool HasFoundTools = false; private void Awake() { SceneManager.sceneLoaded += OnSceneLoaded; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Invalid comparison between Unknown and I4 //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Expected O, but got Unknown if (HasFoundTools || ToolItemManager.GetAllTools().ToList().Count == 0) { return; } HasFoundTools = true; SceneManager.sceneLoaded -= OnSceneLoaded; CfgReplenishmentMethod = ((BaseUnityPlugin)this).Config.Bind("Tools", "Replenishment Method", TypeOfReplenishment.EveryUse, new ConfigDescription("Choose when the tools get refilled :\n• EveryUse = After each use\n• OnBench = When you sit on a bench\n• OnHeal = When you get healed and when you sit on a bench", (AcceptableValueBase)null, Array.Empty())); CfgEnableInfiniteAllToolsUse = ((BaseUnityPlugin)this).Config.Bind("Tools", "Enable Infinite Use for All Tools", true, "Enable infinite use for all tools."); ToolNamesDict = GetDictionnaryTool(); List list = ToolItemManager.GetAllTools().ToList(); for (int i = 0; i < list.Count; i++) { if ((int)list[i].Type <= 0) { ToolConfigDict.Add(list[i].name, ((BaseUnityPlugin)this).Config.Bind("Tools", "Enable Infinite Use for " + ToolNamesDict[list[i].name], false, "Enable or disable infinite use for the " + ToolNamesDict[list[i].name] + " tool.")); } } if ((Object)(object)HeroController.instance != (Object)null) { RegisterHeroHealed(HeroController.instance); } else { HeroController.OnHeroInstanceSet += new HeroSetDelegate(RegisterHeroHealed); } Harmony.CreateAndPatchAll(typeof(InfiniteTools), (string)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"InfiniteTools is loaded!"); } private Dictionary GetDictionnaryTool() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Invalid comparison between Unknown and I4 //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = new Dictionary(); List list = ToolItemManager.GetAllTools().ToList(); LanguageCode val = Language.CurrentLanguage(); Language.SwitchLanguage((LanguageCode)44); Language.LoadLanguage(); for (int i = 0; i < list.Count; i++) { if ((int)list[i].Type == 0) { dictionary.Add(list[i].name, LocalisedString.op_Implicit(list[i].DisplayName)); } } Language.SwitchLanguage(val); Language.LoadLanguage(); return dictionary; } public static void ReplenishTool(ToolItem tool) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)tool != (Object)null && ((ToolBase)tool).IsEquipped) { Data savedData = tool.SavedData; savedData.AmountLeft = ToolItemManager.GetToolStorageAmount(tool); tool.SavedData = savedData; } } public static void ReplenishAllEquippedTools() { foreach (ToolItem equippedTool in GetEquippedTools()) { if (!((Object)(object)equippedTool != (Object)null) || !((ToolBase)equippedTool).IsEquipped) { continue; } try { if (CfgEnableInfiniteAllToolsUse.Value || ToolConfigDict[equippedTool.name].Value) { ReplenishTool(equippedTool); } } catch (Exception arg) { Debug.LogError((object)$"[UsageWatcher] Exception: {arg}"); } } ToolItemManager.ReportAllBoundAttackToolsUpdated(); } public static List GetEquippedTools() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Invalid comparison between Unknown and I4 List list = new List(); List list2 = new List { (AttackToolBinding)2, (AttackToolBinding)0, (AttackToolBinding)1 }; foreach (AttackToolBinding item in list2) { ToolItem boundAttackTool = ToolItemManager.GetBoundAttackTool(item, (ToolEquippedReadSource)0); if ((Object)(object)boundAttackTool != (Object)null && (int)boundAttackTool.Type == 0) { list.Add(boundAttackTool); } } return list; } private void RegisterHeroHealed(HeroController hero) { if ((Object)(object)hero != (Object)null) { HeroHealedRegister = EventRegister.GetRegisterGuaranteed(((Component)hero).gameObject, "HERO HEALED"); ((EventBase)HeroHealedRegister).ReceivedEvent += OnHeroHealed; } } private void OnHeroHealed() { if (CfgReplenishmentMethod.Value == TypeOfReplenishment.OnHeal) { ReplenishAllEquippedTools(); } } [HarmonyPostfix] [HarmonyPatch(typeof(ToolItemManager), "ReportBoundAttackToolUsed")] public static void PostfixReportBoundAttackToolUsed(ToolItemManager __instance, AttackToolBinding binding) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (CfgReplenishmentMethod.Value != 0) { return; } try { ToolItem boundAttackTool = ToolItemManager.GetBoundAttackTool(binding, (ToolEquippedReadSource)0); if ((Object)(object)boundAttackTool != (Object)null && (CfgEnableInfiniteAllToolsUse.Value || ToolConfigDict[boundAttackTool.name].Value)) { ReplenishTool(boundAttackTool); } } catch (Exception arg) { Debug.LogError((object)$"[UsageWatcher] Exception: {arg}"); } } [HarmonyPostfix] [HarmonyPatch(typeof(RestBenchHelper), "SetOnBench")] public static void SetOnBench(RestBenchHelper __instance, bool onBench) { if (onBench) { ReplenishAllEquippedTools(); } } }