Decompiled source of ToolLockWhenSeen v1.0.0

plugins/ToolLockWhenSeen.dll

Decompiled a month ago
using 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]
	[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;
		}
	}
}
[BepInPlugin("toollockwhenseen", "ToolLockWhenSeen", "1.0.0")]
public class ToolLockWhenSeen : BaseUnityPlugin
{
	public const string PluginGuid = "toollockwhenseen";

	public const string PluginName = "ToolLockWhenSeen";

	public const string PluginVersion = "1.0.0";

	private const string HammerSection = "1 - Hammer";

	private const string HoeSection = "2 - Hoe";

	private const string CultivatorSection = "3 - Cultivator";

	internal static ConfigEntry<bool> HammerEnabled;

	internal static ConfigEntry<string> HammerBlockedMessage;

	internal static ConfigEntry<bool> HoeEnabled;

	internal static ConfigEntry<string> HoeBlockedMessage;

	internal static ConfigEntry<bool> CultivatorEnabled;

	internal static ConfigEntry<string> CultivatorBlockedMessage;

	private void Awake()
	{
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		HammerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Hammer", "Enabled", true, "If enabled, the hammer cannot be used while the player is fully seen (big eye / IsSensed).");
		HammerBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Hammer", "BlockedMessage", "Hammer cannot be used while seen.", "Message shown when hammer use is blocked.");
		HoeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Hoe", "Enabled", false, "If enabled, the hoe cannot be used while the player is fully seen (big eye / IsSensed).");
		HoeBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Hoe", "BlockedMessage", "Hoe cannot be used while seen.", "Message shown when hoe use is blocked.");
		CultivatorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Cultivator", "Enabled", false, "If enabled, the cultivator cannot be used while the player is fully seen (big eye / IsSensed).");
		CultivatorBlockedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Cultivator", "BlockedMessage", "Cultivator cannot be used while seen.", "Message shown when cultivator use is blocked.");
		new Harmony("toollockwhenseen").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ToolLockWhenSeen loaded (1.0.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)
	{
		if (1 == 0)
		{
		}
		string result = itemName switch
		{
			"$item_hammer" => string.IsNullOrWhiteSpace(HammerBlockedMessage.Value) ? "Hammer cannot be used while seen." : HammerBlockedMessage.Value, 
			"$item_hoe" => string.IsNullOrWhiteSpace(HoeBlockedMessage.Value) ? "Hoe cannot be used while seen." : HoeBlockedMessage.Value, 
			"$item_cultivator" => string.IsNullOrWhiteSpace(CultivatorBlockedMessage.Value) ? "Cultivator cannot be used while seen." : CultivatorBlockedMessage.Value, 
			_ => "This tool cannot be used while seen.", 
		};
		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;
		}
		if (!__instance.IsSensed())
		{
			return true;
		}
		if (Time.time >= _nextMsgTime)
		{
			_nextMsgTime = Time.time + 1f;
			((Character)__instance).Message((MessageType)2, ToolLockWhenSeen.GetBlockedMessage(name), 0, (Sprite)null);
		}
		return false;
	}
}