using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using FishNet; 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("UncookableItems")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("UncookableItems")] [assembly: AssemblyTitle("UncookableItems")] [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; } } } namespace UncookableItems { public static class Cookability { private static ConfigEntry _weaponsCookable; private static ConfigEntry _toolsCookable; private static ConfigEntry _resetUncookableItems; private static readonly FieldInfo _cooknessField = AccessTools.Field(typeof(Item), "_cookness"); private static readonly PropertyInfo _cooknessValueProp = _cooknessField.FieldType.GetProperty("Value"); public static bool IsServer => InstanceFinder.IsServerStarted; public static void Init(ConfigFile config) { _weaponsCookable = config.Bind("Cooking", "WeaponsUncookable", true, "If true, weapons can't be cooked (grill, lava, etc)."); _toolsCookable = config.Bind("Cooking", "ToolsUncookable", true, "If true, non-weapon tools can't be cooked."); _resetUncookableItems = config.Bind("Resetting", "ResetUncookableItems", true, "If true, sets Cookness back to 0 on items that shouldn't be cookable (like anything cooked before installing) every few seconds. Set to false to disable this safety without disabling the mod."); } public static bool CanCook(Item item) { if ((Object)(object)item == (Object)null) { return false; } if (item is Weapon) { return !_weaponsCookable.Value; } if (item is Tool) { return !_toolsCookable.Value; } return true; } public static void ResetIfNeeded(Item item) { if (_resetUncookableItems.Value && !CanCook(item)) { object value = _cooknessField.GetValue(item); float num = (float)_cooknessValueProp.GetValue(value); if (num > 0f) { _cooknessValueProp.SetValue(value, 0f); _cooknessField.SetValue(item, value); } } } } [BepInPlugin("mossbug.htf.uncookableitems", "Uncookable Items", "0.4")] public class CookabilityPlugin : BaseUnityPlugin { private Harmony _harmony; private const float SweepIntervalSeconds = 5f; private void Awake() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown Cookability.Init(((BaseUnityPlugin)this).Config); _harmony = new Harmony("mossbug.htf.uncookableitems"); _harmony.PatchAll(); ((MonoBehaviour)this).InvokeRepeating("SweepUncookableItems", 5f, 5f); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Uncookable Items mod loaded and patches applied."); } private void SweepUncookableItems() { if (Cookability.IsServer) { Item[] array = Object.FindObjectsByType(); foreach (Item item in array) { Cookability.ResetIfNeeded(item); } } } } } namespace UncookableItems.Patches { [HarmonyPatch(typeof(Item), "CookItem")] public static class Patch_Item_CookItem { private static bool Prefix(Item __instance) { return Cookability.CanCook(__instance); } } [HarmonyPatch(typeof(Item), "CookWithlava")] public static class Patch_Item_CookWithlava { private static bool Prefix(Item __instance) { return Cookability.CanCook(__instance); } } }