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 No Tool Stamina v0.1.0
FrizzQOL.NoToolStamina.dll
Decompiled 2 days agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("FrizzQOL.NoToolStamina")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+80156216867d82f454e89f4cf1d0ca257ad3bf00")] [assembly: AssemblyProduct("FrizzQOL.NoToolStamina")] [assembly: AssemblyTitle("FrizzQOL.NoToolStamina")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.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; } } } public static class ToolStamina { public static readonly string[] PrefabNames = new string[3] { "Hammer", "Hoe", "Cultivator" }; public static bool AppliesTo(string prefabName) { if (string.IsNullOrEmpty(prefabName)) { return false; } for (int i = 0; i < PrefabNames.Length; i++) { if (string.Equals(prefabName, PrefabNames[i], StringComparison.Ordinal)) { return true; } } return false; } public static float Resolve(string prefabName, float vanilla) { if (!AppliesTo(prefabName)) { return vanilla; } return 0f; } } namespace NoToolStamina { [BepInPlugin("com.frizzqol.notoolstamina", "FrizzQOL No Tool Stamina", "0.1.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "com.frizzqol.notoolstamina"; public const string PluginName = "FrizzQOL No Tool Stamina"; public const string PluginVersion = "0.1.0"; private Harmony _harmony; internal static Plugin Instance { get; private set; } private void Awake() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown Instance = this; _harmony = new Harmony("com.frizzqol.notoolstamina"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"FrizzQOL No Tool Stamina 0.1.0 loaded"); } internal static void LogInfo(string message) { if ((Object)(object)Instance != (Object)null) { ((BaseUnityPlugin)Instance).Logger.LogInfo((object)message); } } internal static void LogWarning(string message) { if ((Object)(object)Instance != (Object)null) { ((BaseUnityPlugin)Instance).Logger.LogWarning((object)message); } } internal static void LogError(string message) { if ((Object)(object)Instance != (Object)null) { ((BaseUnityPlugin)Instance).Logger.LogError((object)message); } } } internal static class UseStaminaGate { private static bool _skipNext; public static void ArmIfTool(Player player) { if (ToolStamina.AppliesTo(CurrentToolName(player))) { _skipNext = true; } } public static bool Consume() { if (!_skipNext) { return false; } _skipNext = false; return true; } public static string CurrentToolName(Player player) { if ((Object)(object)player == (Object)null) { return null; } MethodInfo methodInfo = AccessTools.Method(typeof(Humanoid), "GetRightItem", (Type[])null, (Type[])null); ItemData val = (ItemData)((methodInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); if (val == null) { FieldInfo fieldInfo = AccessTools.Field(typeof(Humanoid), "m_rightItem"); val = (ItemData)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); } if (val == null) { return null; } GameObject dropPrefab = val.m_dropPrefab; if ((Object)(object)dropPrefab == (Object)null) { return null; } string name = ((Object)dropPrefab).name; int num = name.IndexOf("(Clone)"); if (num < 0) { return name; } return name.Substring(0, num).Trim(); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ObjectDBAwakePatch { private static void Postfix(ObjectDB __instance) { if ((Object)(object)__instance == (Object)null) { return; } string[] prefabNames = ToolStamina.PrefabNames; foreach (string text in prefabNames) { GameObject itemPrefab = __instance.GetItemPrefab(text); if ((Object)(object)itemPrefab == (Object)null) { Plugin.LogWarning("Item prefab '" + text + "' missing. Skipped."); continue; } ItemDrop component = itemPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null) { Plugin.LogWarning("'" + text + "' has no ItemDrop. Skipped."); } else { ZeroAttackStamina(component, text); } } } private static void ZeroAttackStamina(ItemDrop drop, string prefabName) { SharedData val = drop.m_itemData?.m_shared; if (val == null) { Plugin.LogWarning("'" + prefabName + "' has no shared item data. Skipped."); } else if (ZeroAttack(val.m_attack, prefabName, "primary") | ZeroAttack(val.m_secondaryAttack, prefabName, "secondary")) { Plugin.LogInfo("Set " + prefabName + " attack stamina to 0."); } } private static bool ZeroAttack(Attack attack, string prefabName, string which) { if (attack == null) { return false; } FieldInfo fieldInfo = AccessTools.Field(typeof(Attack), "m_attackStamina"); if (fieldInfo == null) { Plugin.LogWarning("Attack.m_attackStamina missing on " + prefabName + " " + which + "."); return false; } fieldInfo.SetValue(attack, 0f); return true; } } [HarmonyPatch(typeof(Player), "PlacePiece")] internal static class PlacePiecePatch { private static void Prefix(Player __instance) { UseStaminaGate.ArmIfTool(__instance); } } [HarmonyPatch(typeof(Player), "Repair")] internal static class RepairPatch { private static void Prefix(Player __instance) { UseStaminaGate.ArmIfTool(__instance); } } [HarmonyPatch(typeof(Player), "UseStamina")] internal static class UseStaminaPatch { private static bool Prefix() { return !UseStaminaGate.Consume(); } } }