using System; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; 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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AllowUtilitySlot")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AllowUtilitySlot")] [assembly: AssemblyTitle("AllowUtilitySlot")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [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("hugeguts.AllowUtilitySlot", "AllowUtilitySlot", "1.1.0")] public class Plugin : BaseUnityPlugin { public const string modGUID = "hugeguts.AllowUtilitySlot"; public const string modName = "AllowUtilitySlot"; public const string modVersion = "1.1.0"; private Harmony harmony = new Harmony("hugeguts.AllowUtilitySlot"); private static Plugin Instance; public static ManualLogSource mls = Logger.CreateLogSource("hugeguts.AllowUtilitySlot"); public static ConfigEntry cfg_allow; public static ConfigEntry cfg_disallow; private void Awake() { Instance = this; BindConfig(); mls.LogInfo((object)("Allow list: " + cfg_allow.Value)); mls.LogInfo((object)("Disallow list: " + cfg_disallow.Value)); harmony.PatchAll(); } private static void BindConfig() { cfg_allow = ((BaseUnityPlugin)Instance).Config.Bind("Utility slot overrides", "Allow", "Shovel", "Comma-separated list of items allowed for utility slot"); cfg_disallow = ((BaseUnityPlugin)Instance).Config.Bind("Utility slot overrides", "Disallow", "", "Comma-separated list of items disallowed for utility slot"); } } [HarmonyPatch] internal class GrabbableObjectPatch { private static string[] allowedItems = Plugin.cfg_allow.Value.Split(',', StringSplitOptions.RemoveEmptyEntries); private static string[] disallowedItems = Plugin.cfg_disallow.Value.Split(',', StringSplitOptions.RemoveEmptyEntries); [HarmonyPostfix] [HarmonyPatch(typeof(GrabbableObject), "Start")] private static void OverrideUtilitySlotFlag(ref Item ___itemProperties) { string itemName = ___itemProperties.itemName; bool flag = false; bool flag2 = false; string[] array = allowedItems; foreach (string text in array) { flag = flag || itemName.Contains(text.Trim(), StringComparison.OrdinalIgnoreCase); } string[] array2 = disallowedItems; foreach (string text2 in array2) { flag2 = flag2 || itemName.Contains(text2.Trim(), StringComparison.OrdinalIgnoreCase); } if (flag != flag2) { if (flag) { ___itemProperties.disallowUtilitySlot = false; } if (flag2) { ___itemProperties.disallowUtilitySlot = true; } } } } [HarmonyPatch(typeof(NetworkManager))] internal static class NetworkPrefabPatch2 { private static readonly string MOD_GUID = "hugeguts.AllowUtilitySlot"; [HarmonyPostfix] [HarmonyPatch("SetSingleton")] private static void RegisterPrefab() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(MOD_GUID + " Prefab"); ((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D); Object.DontDestroyOnLoad((Object)(object)val); NetworkObject obj = val.AddComponent(); FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(obj, GetHash(MOD_GUID)); NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val); static uint GetHash(string value) { return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0; } } }