Decompiled source of NoMoreRoastedGuns v1.1.0

plugins/HowToFish.NoMoreRoastedGuns/HowToFish.NoMoreRoastedGuns.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FishNet.Connection;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("HowToFish.NoMoreRoastedGuns")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("HowToFish.NoMoreRoastedGuns")]
[assembly: AssemblyTitle("HowToFish.NoMoreRoastedGuns")]
[assembly: AssemblyVersion("1.1.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;
		}
	}
}
namespace HowToFish.NoMoreRoastedGuns
{
	internal sealed class MineMarker : MonoBehaviour
	{
	}
	internal sealed class ModConfig
	{
		public readonly ConfigEntry<bool> Enabled;

		public readonly ConfigEntry<bool> LogBlockedCooks;

		public readonly ConfigEntry<bool> ProtectGuns;

		public readonly ConfigEntry<bool> ProtectMelee;

		public readonly ConfigEntry<bool> ProtectFishingRods;

		public readonly ConfigEntry<bool> ProtectTools;

		public readonly ConfigEntry<bool> ProtectExplosives;

		public readonly ConfigEntry<bool> ProtectEverythingButFood;

		public readonly ConfigEntry<string> AlwaysProtectNames;

		public readonly ConfigEntry<string> NeverProtectNames;

		public readonly ConfigEntry<bool> BlockCooking;

		public readonly ConfigEntry<bool> UncookOnLoad;

		public readonly ConfigEntry<bool> OnlyGuardMyOwnItems;

		public readonly ConfigEntry<bool> OwnershipIsSticky;

		public readonly ConfigEntry<bool> BlockLavaRequests;

		public readonly ConfigEntry<bool> HideCookedAppearance;

		public readonly ConfigEntry<bool> GrillIgnoresProtectedItems;

		public ModConfig(ConfigFile f)
		{
			Enabled = f.Bind<bool>("01 - General", "Enabled", true, "Master switch. When off every patch steps aside and the game cooks items exactly as it shipped.");
			LogBlockedCooks = f.Bind<bool>("01 - General", "LogBlockedCooks", false, "Write a line to the BepInEx log every time a cook is refused. Off by default because a gun sitting on the grill would otherwise produce one line per physics tick; turn it on only while checking that a particular item is recognised.");
			ProtectGuns = f.Bind<bool>("02 - Protected Items", "ProtectGuns", true, "Protect firearms - anything with a Weapon component, which is what the game tags as ItemType.Weapon. This is the whole point of the mod.");
			ProtectMelee = f.Bind<bool>("02 - Protected Items", "ProtectMelee", true, "Protect melee weapons (the Melee component: knives, bats and the like). Separate from guns because the game keeps them as a different component, even though both derive from Tool.");
			ProtectFishingRods = f.Bind<bool>("02 - Protected Items", "ProtectFishingRods", true, "Protect fishing rods. Every variant is covered by one rule: the casting rod and the crab rod both derive from the same FishingRod class, so any rod the game ships or adds later is caught without listing it.");
			ProtectTools = f.Bind<bool>("02 - Protected Items", "ProtectTools", false, "Protect the remaining tools - anything that is a Tool but not a gun, a melee weapon or a fishing rod. Off by default; the three switches above already cover what most people mind seeing charred.");
			ProtectExplosives = f.Bind<bool>("02 - Protected Items", "ProtectExplosives", false, "Protect explosives. Cooking does not detonate anything in this game, it only darkens the item and changes its worth, so this is purely a matter of taste.");
			ProtectEverythingButFood = f.Bind<bool>("02 - Protected Items", "ProtectEverythingButFood", false, "Blanket rule: protect everything that is not a creature. Fish, crabs and the rest stay cookable so the grill, the eating bonuses and the cooking achievement keep working. Overrides the four category switches above.");
			AlwaysProtectNames = f.Bind<string>("02 - Protected Items", "AlwaysProtectNames", "", "Comma separated list of extra item names to protect, matched as a case-insensitive substring of the prefab name (the \"(Clone)\" suffix is ignored). Example: Radio,Disc");
			NeverProtectNames = f.Bind<string>("02 - Protected Items", "NeverProtectNames", "", "Comma separated list of item names that stay cookable no matter what the rules above say. Checked last, so it always wins.");
			BlockCooking = f.Bind<bool>("03 - Host", "BlockCooking", true, "Refuse cooking of protected items at the source. Only the server actually changes an item's cookness, so this is the authoritative fix: with it on nobody in the lobby can roast a gun, on the grill or in lava, whether or not they have the mod installed.");
			UncookOnLoad = f.Bind<bool>("03 - Host", "UncookOnLoad", true, "Reset protected items to raw when a save is loaded, so guns that were already roasted before you installed the mod come back clean. Host only, and it is written back to the save the next time the game saves.");
			OnlyGuardMyOwnItems = f.Bind<bool>("04 - Client", "OnlyGuardMyOwnItems", true, "Scope the three client guards below to your own items. Ownership follows the game's own holder chain, so a gun you dropped is still yours. Other players' weapons then cook exactly as the game intends and you see them cooked. Has no effect while you host: there the mod is protecting the whole lobby by design, and nothing is being cooked to hide in the first place.");
			OwnershipIsSticky = f.Bind<bool>("04 - Client", "OwnershipIsSticky", true, "Once an item has been yours it stays yours for as long as it exists - once mine, always mine - so a gun keeps its protection after you put it down and after someone else picks it up. Turn this off to let ownership follow the game's live signals instead, which hands the item over the moment another player takes it. Only matters when OnlyGuardMyOwnItems is on.");
			BlockLavaRequests = f.Bind<bool>("04 - Client", "BlockLavaRequests", true, "When you are a client rather than the host, do not ask the server to grill a protected item that fell in lava. The game only sends that request from whichever client is simulating the item, so this alone prevents lava cooking of your own items even on an unmodded host. The item still gets its bounce out of the lava.");
			HideCookedAppearance = f.Bind<bool>("04 - Client", "HideCookedAppearance", true, "Draw protected items raw on this client even if the server says they are cooked. Purely local, and the only thing that helps against the grill on an unmodded host: the world model, the inventory icon and the inspect panel all stop showing the burn.");
			GrillIgnoresProtectedItems = f.Bind<bool>("04 - Client", "GrillIgnoresProtectedItems", true, "Make the grill not register protected items at all, so it stops sizzling and smoking at a gun laid on it. On the host this also removes the item from the list the grill cooks from, which is a second, earlier guard than BlockCooking.");
		}
	}
	[BepInPlugin("com.zpaulin.howtofish.nomoreroastedguns", "No More Roasted Guns", "1.1.0")]
	[BepInProcess("How to Fish.exe")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		internal static ModConfig Cfg { get; private set; }

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg = new ModConfig(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.zpaulin.howtofish.nomoreroastedguns");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"No More Roasted Guns v1.1.0 loaded");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class PluginInfo
	{
		public const string Guid = "com.zpaulin.howtofish.nomoreroastedguns";

		public const string Name = "No More Roasted Guns";

		public const string Version = "1.1.0";
	}
	internal static class Protection
	{
		private static readonly FieldInfo RenderersField = AccessTools.Field(typeof(Item), "_renderers");

		private static readonly FieldInfo DroppedByField = AccessTools.Field(typeof(Item), "_playerWhoDropped");

		private static string _alwaysRaw = "\0";

		private static string _neverRaw = "\0";

		private static string[] _always = new string[0];

		private static string[] _never = new string[0];

		private static readonly Dictionary<int, float> LastLogged = new Dictionary<int, float>();

		public static bool Active
		{
			get
			{
				if (Plugin.Cfg != null)
				{
					return Plugin.Cfg.Enabled.Value;
				}
				return false;
			}
		}

		public static bool IsHost
		{
			get
			{
				if ((Object)(object)Server.Instance != (Object)null)
				{
					return ((NetworkBehaviour)Server.Instance).IsServerInitialized;
				}
				return false;
			}
		}

		public static bool IsProtected(Item item)
		{
			if (!Active || (Object)(object)item == (Object)null)
			{
				return false;
			}
			string[] array = Parse(ref _neverRaw, ref _never, Plugin.Cfg.NeverProtectNames.Value);
			if (array.Length != 0 && Matches(CleanName(item), array))
			{
				return false;
			}
			if (MatchesCategory(item))
			{
				return true;
			}
			string[] array2 = Parse(ref _alwaysRaw, ref _always, Plugin.Cfg.AlwaysProtectNames.Value);
			if (array2.Length != 0)
			{
				return Matches(CleanName(item), array2);
			}
			return false;
		}

		private static bool MatchesCategory(Item item)
		{
			if (item is Creature)
			{
				return false;
			}
			if (Plugin.Cfg.ProtectEverythingButFood.Value)
			{
				return true;
			}
			if (Plugin.Cfg.ProtectGuns.Value && item is Weapon)
			{
				return true;
			}
			if (Plugin.Cfg.ProtectMelee.Value && item is Melee)
			{
				return true;
			}
			if (Plugin.Cfg.ProtectFishingRods.Value && item is FishingRod)
			{
				return true;
			}
			if (Plugin.Cfg.ProtectTools.Value && item is Tool)
			{
				return true;
			}
			if (Plugin.Cfg.ProtectExplosives.Value && item is Explosive)
			{
				return true;
			}
			return false;
		}

		private static string CleanName(Item item)
		{
			string text = (((Object)(object)((Component)item).gameObject != (Object)null) ? ((Object)((Component)item).gameObject).name : ((Object)item).name);
			if (string.IsNullOrEmpty(text))
			{
				return "";
			}
			int num = text.IndexOf("(Clone)", StringComparison.OrdinalIgnoreCase);
			if (num >= 0)
			{
				text = text.Substring(0, num);
			}
			return text.Trim().ToLowerInvariant();
		}

		private static string[] Parse(ref string cachedRaw, ref string[] cached, string raw)
		{
			if (raw == null)
			{
				raw = "";
			}
			if (string.Equals(cachedRaw, raw, StringComparison.Ordinal))
			{
				return cached;
			}
			cachedRaw = raw;
			string[] array = raw.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
			List<string> list = new List<string>(array.Length);
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string text = array2[i].Trim().ToLowerInvariant();
				if (text.Length > 0)
				{
					list.Add(text);
				}
			}
			cached = list.ToArray();
			return cached;
		}

		private static bool Matches(string name, string[] entries)
		{
			if (string.IsNullOrEmpty(name))
			{
				return false;
			}
			foreach (string value in entries)
			{
				if (name.IndexOf(value, StringComparison.Ordinal) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		public static void Note(Item item, string what)
		{
			if (Plugin.Cfg != null && Plugin.Cfg.LogBlockedCooks.Value && !((Object)(object)item == (Object)null))
			{
				int instanceID = ((Object)item).GetInstanceID();
				float unscaledTime = Time.unscaledTime;
				if (LastLogged.Count > 512)
				{
					LastLogged.Clear();
				}
				if (!LastLogged.TryGetValue(instanceID, out var value) || !(unscaledTime - value < 1f))
				{
					LastLogged[instanceID] = unscaledTime;
					Plugin.Log.LogInfo((object)("refused " + what + " on " + CleanName(item)));
				}
			}
		}

		public static bool ShouldGuardLocally(Item item)
		{
			if (!IsProtected(item))
			{
				return false;
			}
			if (!Plugin.Cfg.OnlyGuardMyOwnItems.Value)
			{
				return true;
			}
			if (IsHost)
			{
				return true;
			}
			return IsMine(item);
		}

		public static bool IsMine(Item item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			bool value = Plugin.Cfg.OwnershipIsSticky.Value;
			MineMarker mineMarker = default(MineMarker);
			if (value && ((Component)item).TryGetComponent<MineMarker>(ref mineMarker))
			{
				return true;
			}
			if (!HoldsLocalPlayer(item))
			{
				return false;
			}
			if (value)
			{
				((Component)item).gameObject.AddComponent<MineMarker>();
			}
			return true;
		}

		private static bool HoldsLocalPlayer(Item item)
		{
			if (IsLocal(item.Holder))
			{
				return true;
			}
			if (IsLocal(item.SyncedHolder))
			{
				return true;
			}
			if (IsLocal(item.LastHolder))
			{
				return true;
			}
			if (DroppedByField != null)
			{
				try
				{
					object? value = DroppedByField.GetValue(item);
					if (IsLocal((Player)((value is Player) ? value : null)))
					{
						return true;
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("reading _playerWhoDropped: " + ex.Message));
				}
			}
			return false;
		}

		private static bool IsLocal(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			NetworkConnection owner = ((NetworkBehaviour)player).Owner;
			if (owner != (NetworkConnection)null && owner.IsLocalClient)
			{
				return true;
			}
			Player localPlayer = Player.LocalPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				return (Object)(object)player == (Object)(object)localPlayer;
			}
			return false;
		}

		public static bool Uncook(Item item)
		{
			if ((Object)(object)item == (Object)null || item._cookness == null)
			{
				return false;
			}
			if (!IsHost)
			{
				return false;
			}
			if (item._cookness.Value <= 0f)
			{
				return false;
			}
			item._cookness.Value = 0f;
			return true;
		}

		public static void ClearAppearance(Item item)
		{
			if ((Object)(object)item == (Object)null || RenderersField == null || !(RenderersField.GetValue(item) is List<Renderer> { Count: not 0 } list))
			{
				return;
			}
			try
			{
				ShaderManager.SetItemCookness(list, 0f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("clearing cooked look: " + ex.Message));
			}
		}
	}
}
namespace HowToFish.NoMoreRoastedGuns.Patches
{
	[HarmonyPatch(typeof(Item), "OnCooknessChange")]
	internal static class ItemOnCooknessChangePatch
	{
		private static void Prefix(Item __instance, ref float __1)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg != null && cfg.Enabled.Value && cfg.HideCookedAppearance.Value && !(__1 <= 0f) && Protection.ShouldGuardLocally(__instance))
			{
				__1 = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(Item), "OnStartClient")]
	internal static class ItemOnStartClientPatch
	{
		private static void Postfix(Item __instance)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg != null && cfg.Enabled.Value && cfg.HideCookedAppearance.Value && Protection.ShouldGuardLocally(__instance))
			{
				Protection.ClearAppearance(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(InventorySlot), "ApplyCookness")]
	internal static class InventorySlotApplyCooknessPatch
	{
		private static readonly FieldInfo RendererField = AccessTools.Field(typeof(InventorySlot), "_renderer");

		private static bool Prefix(InventorySlot __instance, Item __0)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg == null || !cfg.Enabled.Value || !cfg.HideCookedAppearance.Value)
			{
				return true;
			}
			if (RendererField == null)
			{
				return true;
			}
			if (!Protection.ShouldGuardLocally(__0))
			{
				return true;
			}
			object? value = RendererField.GetValue(__instance);
			Renderer val = (Renderer)((value is Renderer) ? value : null);
			if (val != null && (Object)(object)val != (Object)null)
			{
				ShaderManager.SetItemCookness(val, 0f);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(WeaponUI), "UpdateInspectedItemText")]
	internal static class WeaponUiInspectTextPatch
	{
		private static readonly FieldInfo ItemField = AccessTools.Field(typeof(WeaponUI), "_inspectedItem");

		private static readonly FieldInfo TextField = AccessTools.Field(typeof(WeaponUI), "_descriptionText");

		private static void Postfix(WeaponUI __instance)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg == null || !cfg.Enabled.Value || !cfg.HideCookedAppearance.Value || ItemField == null || TextField == null)
			{
				return;
			}
			object? value = ItemField.GetValue(__instance);
			Item val = (Item)((value is Item) ? value : null);
			if (val == null || !Protection.ShouldGuardLocally(val))
			{
				return;
			}
			object? value2 = TextField.GetValue(__instance);
			TextMeshProUGUI val2 = (TextMeshProUGUI)((value2 is TextMeshProUGUI) ? value2 : null);
			if (val2 != null && !((Object)(object)val2 == (Object)null))
			{
				string text = WithoutCookingLine(((TMP_Text)val2).text);
				if (text != null)
				{
					((TMP_Text)val2).text = text;
				}
			}
		}

		private static string WithoutCookingLine(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			string value;
			try
			{
				value = LocalizationManager.CookingLocalized.GetLocalizedString() + ":";
			}
			catch (Exception)
			{
				return null;
			}
			if (string.IsNullOrEmpty(value) || text.IndexOf(value, StringComparison.Ordinal) < 0)
			{
				return null;
			}
			string[] array = text.Split(new char[1] { '\n' });
			List<string> list = new List<string>(array.Length);
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				if (!text2.TrimStart(Array.Empty<char>()).StartsWith(value, StringComparison.Ordinal))
				{
					list.Add(text2);
				}
			}
			return string.Join("\n", list.ToArray());
		}
	}
	[HarmonyPatch(typeof(DazedCommands), "IsServerCommand")]
	internal static class DazedCommandsPatch
	{
		private static bool Prefix(string __0, ref bool __result)
		{
			if (!ModCommands.TryHandle(__0))
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	internal static class ModCommands
	{
		private const string Root = "nrg";

		public static bool TryHandle(string raw)
		{
			if (string.IsNullOrEmpty(raw))
			{
				return false;
			}
			string text = raw.Trim();
			if (text.StartsWith("/"))
			{
				text = text.Substring(1);
			}
			string[] array = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 0)
			{
				return false;
			}
			if (!array[0].Equals("nrg", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			string text2 = ((array.Length > 1) ? array[1].ToLowerInvariant() : "status");
			ModConfig cfg = Plugin.Cfg;
			switch (text2)
			{
			case "status":
				Report();
				return true;
			case "off":
			case "on":
				cfg.Enabled.Value = text2 == "on";
				Say("no more roasted guns " + text2);
				return true;
			case "guns":
				cfg.ProtectGuns.Value = !cfg.ProtectGuns.Value;
				Say($"guns protected={cfg.ProtectGuns.Value}");
				return true;
			case "melee":
				cfg.ProtectMelee.Value = !cfg.ProtectMelee.Value;
				Say($"melee protected={cfg.ProtectMelee.Value}");
				return true;
			case "rods":
				cfg.ProtectFishingRods.Value = !cfg.ProtectFishingRods.Value;
				Say($"fishing rods protected={cfg.ProtectFishingRods.Value}");
				return true;
			case "tools":
				cfg.ProtectTools.Value = !cfg.ProtectTools.Value;
				Say($"tools protected={cfg.ProtectTools.Value}");
				return true;
			case "explosives":
				cfg.ProtectExplosives.Value = !cfg.ProtectExplosives.Value;
				Say($"explosives protected={cfg.ProtectExplosives.Value}");
				return true;
			case "mine":
				cfg.OnlyGuardMyOwnItems.Value = !cfg.OnlyGuardMyOwnItems.Value;
				Say(cfg.OnlyGuardMyOwnItems.Value ? "client guards apply to your own items only" : "client guards apply to every protected item");
				return true;
			case "sticky":
				cfg.OwnershipIsSticky.Value = !cfg.OwnershipIsSticky.Value;
				Say(cfg.OwnershipIsSticky.Value ? "ownership sticky - once mine, always mine" : "ownership follows the game's live holder signals");
				return true;
			case "hide":
				cfg.HideCookedAppearance.Value = !cfg.HideCookedAppearance.Value;
				Say($"hide cooked look={cfg.HideCookedAppearance.Value}");
				return true;
			case "grill":
				cfg.GrillIgnoresProtectedItems.Value = !cfg.GrillIgnoresProtectedItems.Value;
				Say($"grill ignores protected items={cfg.GrillIgnoresProtectedItems.Value}");
				return true;
			case "log":
				cfg.LogBlockedCooks.Value = !cfg.LogBlockedCooks.Value;
				Say($"log blocked cooks={cfg.LogBlockedCooks.Value}");
				return true;
			case "uncook":
				Uncook();
				return true;
			default:
				Say("commands: status, on, off, guns, melee, rods, tools, explosives, mine, sticky, hide, grill, log, uncook");
				return true;
			}
		}

		private static void Uncook()
		{
			if (!Protection.IsHost)
			{
				Say("uncook needs the host - cookness only exists on the server");
				return;
			}
			Item[] array = Object.FindObjectsByType<Item>((FindObjectsInactive)1);
			int num = 0;
			Item[] array2 = array;
			foreach (Item item in array2)
			{
				if (Protection.IsProtected(item) && Protection.Uncook(item))
				{
					num++;
				}
			}
			Say($"uncooked {num} item(s) out of {array.Length} loaded");
		}

		private static void Report()
		{
			ModConfig cfg = Plugin.Cfg;
			string arg = (Protection.IsHost ? "host - cooking blocked at the source" : "client - local guards only");
			Say($"enabled={cfg.Enabled.Value} role={arg}");
			Say($"protecting guns={cfg.ProtectGuns.Value} melee={cfg.ProtectMelee.Value} " + $"rods={cfg.ProtectFishingRods.Value} tools={cfg.ProtectTools.Value} " + $"explosives={cfg.ProtectExplosives.Value} " + $"allButFood={cfg.ProtectEverythingButFood.Value}");
			Say($"host: blockCooking={cfg.BlockCooking.Value} uncookOnLoad={cfg.UncookOnLoad.Value}");
			Say($"client: onlyMine={cfg.OnlyGuardMyOwnItems.Value} sticky={cfg.OwnershipIsSticky.Value} " + $"lavaRequests={cfg.BlockLavaRequests.Value} " + $"hideLook={cfg.HideCookedAppearance.Value} grill={cfg.GrillIgnoresProtectedItems.Value}");
		}

		private static void Say(string message)
		{
			Plugin.Log.LogMessage((object)("[nrg] " + message));
			try
			{
				ChatManager.ChatMessage("[nrg] " + message);
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Item), "CookItem")]
	internal static class ItemCookItemPatch
	{
		private static bool Prefix(Item __instance, float __0)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg == null || !cfg.Enabled.Value || !cfg.BlockCooking.Value)
			{
				return true;
			}
			if (__0 <= 0f)
			{
				return true;
			}
			if (!Protection.IsProtected(__instance))
			{
				return true;
			}
			Protection.Note(__instance, "cook");
			return false;
		}
	}
	[HarmonyPatch(typeof(Item), "CookWithlava")]
	internal static class ItemCookWithLavaPatch
	{
		private static bool Prefix(Item __instance)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg == null || !cfg.Enabled.Value || !cfg.BlockCooking.Value)
			{
				return true;
			}
			if (!Protection.IsProtected(__instance))
			{
				return true;
			}
			Protection.Note(__instance, "lava cook");
			return false;
		}
	}
	[HarmonyPatch(typeof(GrillBox), "OnTriggerStay")]
	internal static class GrillBoxOnTriggerStayPatch
	{
		private static bool Prefix(Collider __0)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg == null || !cfg.Enabled.Value || !cfg.GrillIgnoresProtectedItems.Value)
			{
				return true;
			}
			if ((Object)(object)__0 == (Object)null)
			{
				return true;
			}
			if (!Protection.ShouldGuardLocally(ItemManager.Get(__0)))
			{
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Server), "GrillItemInLava")]
	internal static class ServerGrillItemInLavaPatch
	{
		private static bool Prefix(Item __0)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg == null || !cfg.Enabled.Value || !cfg.BlockLavaRequests.Value)
			{
				return true;
			}
			if (!Protection.ShouldGuardLocally(__0))
			{
				return true;
			}
			Protection.Note(__0, "lava request");
			return false;
		}
	}
	[HarmonyPatch(typeof(Item), "LoadFromSave")]
	internal static class ItemLoadFromSavePatch
	{
		private static void Postfix(Item __instance)
		{
			ModConfig cfg = Plugin.Cfg;
			if (cfg != null && cfg.Enabled.Value && cfg.UncookOnLoad.Value && Protection.IsProtected(__instance) && Protection.Uncook(__instance))
			{
				Protection.Note(__instance, "uncooked on load");
			}
		}
	}
}