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 ToolLockWhenSeen v1.1.0
plugins/ToolLockWhenSeen.dll
Decompiled 6 days agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; 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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("ToolLockWhenSeen")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ToolLockWhenSeen")] [assembly: AssemblyTitle("ToolLockWhenSeen")] [assembly: AssemblyVersion("1.0.0.0")] [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; } } } [BepInPlugin("ToolLockWhenSeen", "ToolLockWhenSeen", "1.1.0")] public class ToolLockWhenSeen : BaseUnityPlugin { public const string PluginGuid = "ToolLockWhenSeen"; public const string PluginName = "ToolLockWhenSeen"; public const string PluginVersion = "1.1.0"; private const string DetectionSection = "0 - Detection"; private const string HammerSection = "1 - Hammer"; private const string HoeSection = "2 - Hoe"; private const string CultivatorSection = "3 - Cultivator"; internal static ConfigEntry<bool> RestrictWhenSeen; internal static ConfigEntry<bool> RestrictWhenHeard; internal static ConfigEntry<bool> HammerEnabled; internal static ConfigEntry<string> HammerSeenBlockedMessage; internal static ConfigEntry<string> HammerHeardBlockedMessage; internal static ConfigEntry<bool> HoeEnabled; internal static ConfigEntry<string> HoeSeenBlockedMessage; internal static ConfigEntry<string> HoeHeardBlockedMessage; internal static ConfigEntry<bool> CultivatorEnabled; internal static ConfigEntry<string> CultivatorSeenBlockedMessage; internal static ConfigEntry<string> CultivatorHeardBlockedMessage; private void Awake() { //IL_017e: Unknown result type (might be due to invalid IL or missing references) RestrictWhenSeen = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Detection", "RestrictWhenSeen", true, "If enabled, restricted tools cannot be used while the player is seen by an enemy."); RestrictWhenHeard = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Detection", "RestrictWhenHeard", false, "If enabled, restricted tools cannot be used while the player is heard by an enemy."); HammerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Hammer", "Enabled", true, "If enabled, the hammer cannot be used while the player is seen or heard."); HammerSeenBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Hammer", "SeenBlockedMessage", "Hammer cannot be used while seen.", "Message shown when hammer use is blocked because the player is seen."); HammerHeardBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Hammer", "HeardBlockedMessage", "Hammer cannot be used while heard.", "Message shown when hammer use is blocked because the player is heard."); HoeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Hoe", "Enabled", false, "If enabled, the hoe cannot be used while the player is seen or heard."); HoeSeenBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Hoe", "SeenBlockedMessage", "Hoe cannot be used while seen.", "Message shown when hoe use is blocked because the player is seen."); HoeHeardBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Hoe", "HeardBlockedMessage", "Hoe cannot be used while heard.", "Message shown when hoe use is blocked because the player is heard."); CultivatorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Cultivator", "Enabled", false, "If enabled, the cultivator cannot be used while the player is seen or heard."); CultivatorSeenBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Cultivator", "SeenBlockedMessage", "Cultivator cannot be used while seen.", "Message shown when cultivator use is blocked because the player is seen."); CultivatorHeardBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Cultivator", "HeardBlockedMessage", "Cultivator cannot be used while heard.", "Message shown when cultivator use is blocked because the player is heard."); new Harmony("ToolLockWhenSeen").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ToolLockWhenSeen loaded (1.1.0)"); } internal static bool IsToolRestricted(string itemName) { return itemName == "$item_hammer" || itemName == "$item_hoe" || itemName == "$item_cultivator"; } internal static bool IsRestrictionEnabled(string itemName) { if (1 == 0) { } bool result = itemName switch { "$item_hammer" => HammerEnabled.Value, "$item_hoe" => HoeEnabled.Value, "$item_cultivator" => CultivatorEnabled.Value, _ => false, }; if (1 == 0) { } return result; } internal static string GetBlockedMessage(string itemName, bool seen) { if (1 == 0) { } string result = itemName switch { "$item_hammer" => (!seen) ? (string.IsNullOrWhiteSpace(HammerHeardBlockedMessage.Value) ? "Hammer cannot be used while heard." : HammerHeardBlockedMessage.Value) : (string.IsNullOrWhiteSpace(HammerSeenBlockedMessage.Value) ? "Hammer cannot be used while seen." : HammerSeenBlockedMessage.Value), "$item_hoe" => (!seen) ? (string.IsNullOrWhiteSpace(HoeHeardBlockedMessage.Value) ? "Hoe cannot be used while heard." : HoeHeardBlockedMessage.Value) : (string.IsNullOrWhiteSpace(HoeSeenBlockedMessage.Value) ? "Hoe cannot be used while seen." : HoeSeenBlockedMessage.Value), "$item_cultivator" => (!seen) ? (string.IsNullOrWhiteSpace(CultivatorHeardBlockedMessage.Value) ? "Cultivator cannot be used while heard." : CultivatorHeardBlockedMessage.Value) : (string.IsNullOrWhiteSpace(CultivatorSeenBlockedMessage.Value) ? "Cultivator cannot be used while seen." : CultivatorSeenBlockedMessage.Value), _ => "This tool cannot be used.", }; if (1 == 0) { } return result; } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] public static class Patch_Player_UpdatePlacement_ToolLockWhenSeen { private static readonly FieldRef<Humanoid, ItemData> RightItemRef = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_rightItem"); private static float _nextMsgTime; private static bool Prefix(Player __instance) { if (!((Character)__instance).InPlaceMode()) { return true; } ItemData val = RightItemRef.Invoke((Humanoid)(object)__instance); if (val?.m_shared == null) { return true; } string name = val.m_shared.m_name; if (!ToolLockWhenSeen.IsToolRestricted(name)) { return true; } if (!ToolLockWhenSeen.IsRestrictionEnabled(name)) { return true; } bool flag = ToolLockWhenSeen.RestrictWhenSeen.Value && __instance.IsSensed(); bool flag2 = ToolLockWhenSeen.RestrictWhenHeard.Value && __instance.IsTargeted(); if (!flag && !flag2) { return true; } if (Time.time >= _nextMsgTime) { _nextMsgTime = Time.time + 1f; ((Character)__instance).Message((MessageType)2, ToolLockWhenSeen.GetBlockedMessage(name, flag), 0, (Sprite)null, false); } return false; } }