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 MoreToggleableItems v1.0.1
MoreToggleableItems.dll
Decompiled a month agousing System; using System.Collections.Generic; 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("MoreToggleableItems")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1")] [assembly: AssemblyProduct("More Toggleable Items")] [assembly: AssemblyTitle("MoreToggleableItems")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.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; } } } namespace MoreToggleableItems { public class ClockNoiseBlocker : MonoBehaviour { public bool blockClockTicking; public float timeUntilNextSecond; public void Initialize(GrabbableObject obj, int offChance) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) Random random = new Random(StartOfRound.Instance.randomMapSeed + StartOfRound.Instance.currentLevelID + obj.itemProperties.itemId + (int)(((Component)this).transform.position.x + ((Component)this).transform.position.z) + obj.scrapValue); blockClockTicking = random.Next(0, 100) < offChance; timeUntilNextSecond = 1f; } } [HarmonyPatch(typeof(NetworkManager))] internal static class NetworkPrefabPatch { private static readonly string MOD_GUID = "MoreToggleableItems"; [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<NetworkObject>(); 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; } } } [BepInPlugin("MoreToggleableItems", "More Toggleable Items", "1.0.1")] [Harmony] public class Plugin : BaseUnityPlugin { public const string TOGGLE_TOOLTIP = "Toggle : [RMB]"; internal static ManualLogSource Logger; internal static ConfigEntry<int> ClockOffChance; internal static ConfigEntry<bool> CanToggleClock; internal static ConfigEntry<bool> CanToggleRobot; internal static ConfigEntry<bool> CanToggleTeeth; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; Harmony val = new Harmony("MoreToggleableItems"); val.PatchAll(); ClockOffChance = ((BaseUnityPlugin)this).Config.Bind<int>("Clock", "turnedOffChance", 5, "The chance for a given Clock to be turned off by default"); CanToggleClock = ((BaseUnityPlugin)this).Config.Bind<bool>("Clock", "canToggleClock", true, "Whether you can toggle on/off Clocks with Item Primary Use"); CanToggleRobot = ((BaseUnityPlugin)this).Config.Bind<bool>("ToyRobot", "canToggleToyRobot", true, "Whether you can toggle on/off Toy Robots with Item Primary Use"); CanToggleTeeth = ((BaseUnityPlugin)this).Config.Bind<bool>("Teeth", "canToggleTeeth", true, "Whether you can toggle on/off Teeth with Item Primary Use"); Logger.LogInfo((object)"Plugin MoreToggleableItems is loaded!"); } [HarmonyPatch(typeof(AnimatedItem), "Start")] [HarmonyPrefix] private static void SyncAnimatedItemUse(AnimatedItem __instance) { if (((Object)((GrabbableObject)__instance).itemProperties).name == "RobotToy" || ((Object)((GrabbableObject)__instance).itemProperties).name == "Dentures") { ((GrabbableObject)__instance).itemProperties.syncUseFunction = true; ((GrabbableObject)__instance).itemProperties.syncInteractLRFunction = true; if (!((GrabbableObject)__instance).itemProperties.toolTips.Contains("Toggle : [RMB]")) { List<string> list = ((GrabbableObject)__instance).itemProperties.toolTips.ToList(); list.Add("Toggle : [RMB]"); ((GrabbableObject)__instance).itemProperties.toolTips = list.ToArray(); } } } [HarmonyPatch(typeof(GrabbableObject), "ItemActivate")] [HarmonyPrefix] private static void OnActivateItem(GrabbableObject __instance, bool used, bool buttonDown = true) { if ((((Object)__instance.itemProperties).name == "RobotToy" && CanToggleRobot.Value) || (((Object)__instance.itemProperties).name == "Dentures" && CanToggleTeeth.Value)) { AnimatedItem val = (AnimatedItem)(object)((__instance is AnimatedItem) ? __instance : null); if (!Object.op_Implicit((Object)(object)val)) { return; } if (val.chanceToTriggerAlternateMesh > 0) { ((Component)val).gameObject.GetComponent<MeshFilter>().mesh = val.normalMesh; } if ((Object)(object)val.itemAudio != (Object)null) { if ((Object)(object)val.itemAnimator != (Object)null) { val.itemAnimator.SetBool(val.grabItemBoolString, !val.itemAudio.isPlaying); } if (val.itemAudio.isPlaying) { val.itemAudio.Stop(); return; } val.itemAudio.Play(); val.itemAudio.clip = val.grabAudio; val.itemAudio.loop = val.loopGrabAudio; } } else { ClockNoiseBlocker clockNoiseBlocker = default(ClockNoiseBlocker); if (!(((Object)__instance.itemProperties).name == "Clock") || !CanToggleClock.Value || !((Component)__instance).TryGetComponent<ClockNoiseBlocker>(ref clockNoiseBlocker)) { return; } ClockProp val2 = (ClockProp)(object)((__instance is ClockProp) ? __instance : null); if (Object.op_Implicit((Object)(object)val2)) { if (clockNoiseBlocker.blockClockTicking) { val2.timeOfLastSecond = Time.realtimeSinceStartup - clockNoiseBlocker.timeUntilNextSecond; clockNoiseBlocker.blockClockTicking = false; } else { clockNoiseBlocker.timeUntilNextSecond = Time.realtimeSinceStartup - val2.timeOfLastSecond; clockNoiseBlocker.blockClockTicking = true; } } } } [HarmonyPatch(typeof(GrabbableObject), "Start")] [HarmonyPrefix] private static void SyncClockPropUse(GrabbableObject __instance) { if (((Object)__instance.itemProperties).name == "Clock" && Object.op_Implicit((Object)(object)((__instance is ClockProp) ? __instance : null))) { __instance.itemProperties.syncUseFunction = true; __instance.itemProperties.syncInteractLRFunction = true; __instance.itemProperties.saveItemVariable = true; if (!__instance.itemProperties.toolTips.Contains("Toggle : [RMB]")) { List<string> list = __instance.itemProperties.toolTips.ToList(); list.Add("Toggle : [RMB]"); __instance.itemProperties.toolTips = list.ToArray(); } if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<ClockNoiseBlocker>())) { ClockNoiseBlocker clockNoiseBlocker = ((Component)__instance).gameObject.AddComponent<ClockNoiseBlocker>(); clockNoiseBlocker.Initialize(__instance, ClockOffChance.Value); } } } [HarmonyPatch(typeof(ClockProp), "Update")] [HarmonyPrefix] private static void TurnOffClock(ClockProp __instance) { ClockNoiseBlocker clockNoiseBlocker = default(ClockNoiseBlocker); if (((Object)((GrabbableObject)__instance).itemProperties).name == "Clock" && ((Component)__instance).TryGetComponent<ClockNoiseBlocker>(ref clockNoiseBlocker) && clockNoiseBlocker.blockClockTicking) { __instance.timeOfLastSecond = Time.realtimeSinceStartup; } } [HarmonyPatch(typeof(GrabbableObject), "GetItemDataToSave")] [HarmonyPostfix] private static void ClockSoundSaveData(GrabbableObject __instance, ref int __result) { ClockNoiseBlocker clockNoiseBlocker = default(ClockNoiseBlocker); if (((Object)__instance.itemProperties).name == "Clock" && Object.op_Implicit((Object)(object)((__instance is ClockProp) ? __instance : null)) && ((Component)__instance).TryGetComponent<ClockNoiseBlocker>(ref clockNoiseBlocker)) { __result = (clockNoiseBlocker.blockClockTicking ? ((int)(clockNoiseBlocker.timeUntilNextSecond * 100f)) : (-1)); } } [HarmonyPatch(typeof(GrabbableObject), "LoadItemSaveData")] [HarmonyPostfix] private static void ClockSoundLoadData(GrabbableObject __instance, int saveData) { if (((Object)__instance.itemProperties).name == "Clock" && Object.op_Implicit((Object)(object)((__instance is ClockProp) ? __instance : null))) { ClockNoiseBlocker clockNoiseBlocker = ((Component)__instance).GetComponent<ClockNoiseBlocker>(); if ((Object)(object)clockNoiseBlocker == (Object)null) { clockNoiseBlocker = ((Component)__instance).gameObject.AddComponent<ClockNoiseBlocker>(); clockNoiseBlocker.Initialize(__instance, ClockOffChance.Value); } clockNoiseBlocker.blockClockTicking = saveData != -1; clockNoiseBlocker.timeUntilNextSecond = (float)saveData / 100f; } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "MoreToggleableItems"; public const string PLUGIN_NAME = "More Toggleable Items"; public const string PLUGIN_VERSION = "1.0.1"; } }