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 Lock Doors Mod v1.1.0
BepInEx/plugins/LockDoorsMod.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; 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(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")] [assembly: AssemblyCompany("LockDoorsMod")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("My first plugin")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("LockDoorsMod")] [assembly: AssemblyTitle("LockDoorsMod")] [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; } } } namespace LockDoorsMod { [HarmonyPatch(typeof(HUDManager))] public class Broadcaster { public static Action<string, string> GetString = delegate { }; public static void BroadcastString(string data, string signature) { HUDManager.Instance.AddTextToChatOnServer("<size=0>ENZDATA/" + data + "/" + signature + "/" + GameNetworkManager.Instance.localPlayerController.playerClientId + "/</size>", -1); } [HarmonyPatch(typeof(HUDManager), "AddChatMessage")] [HarmonyPostfix] internal static void AddChatMessagePatch(string chatMessage, string nameOfUserWhoTyped = "") { string[] array = chatMessage.Split(new char[1] { '/' }); if (chatMessage.StartsWith("<size=0>ENZDATA") && !(GameNetworkManager.Instance.localPlayerController.playerClientId.ToString() == array[3])) { GetString(array[1], array[2]); } } } public static class LDMPluginInfo { public const string PLUGIN_GUID = "ENZDS.LockDoorsMod"; public const string PLUGIN_NAME = "Lock Doors Mod"; public const string PLUGIN_VERSION = "1.1.0"; } public static class LDMLogger { public static readonly ManualLogSource logger = Logger.CreateLogSource("LockDoorsMod"); } [JsonObject] internal class LockDoorData { [JsonProperty] public ulong networkObjectId { get; set; } [JsonProperty] public ulong clientId { get; set; } } [HarmonyPatch(typeof(DoorLock))] public class DoorLockPatch { [HarmonyPatch("Awake")] [HarmonyPrefix] private static void Awake() { Broadcaster.GetString = (Action<string, string>)Delegate.Combine(Broadcaster.GetString, new Action<string, string>(CloseDoorReceived)); } private static void CloseDoorReceived(string data, string signature) { LockDoorData lockDoorData = JsonConvert.DeserializeObject<LockDoorData>(data); LDMLogger.logger.LogInfo((object)("[BROADCAST_RECEIVE] Got message \n data: " + data + " \n signature: " + signature)); if (signature == "lock_door") { GameObject val = FindObjectById(Convert.ToUInt64(lockDoorData.networkObjectId)); DoorLock componentInChildren = val.GetComponentInChildren<DoorLock>(); LDMLogger.logger.LogInfo((object)$"[BROADCAST_RECEIVE] found object with id {lockDoorData.networkObjectId}: {val} \n {componentInChildren} \n doorLockNID: {((NetworkBehaviour)componentInChildren).NetworkObjectId}"); componentInChildren.LockDoor(30f); } } [HarmonyPatch("LockDoor")] [HarmonyPrefix] private static bool LockDoorPatch(ref DoorLock __instance, ref bool ___isDoorOpened, ref bool ___isLocked, ref AudioSource ___doorLockSFX, ref AudioClip ___unlockSFX) { if (___isDoorOpened | ___isLocked) { LDMLogger.logger.LogInfo((object)"The door is opened or locked. Can't lock it"); return false; } AudioSource val = ___doorLockSFX; val.PlayOneShot(___unlockSFX); return true; } public static void LockDoorPatchSyncWithServer(ulong networkObjectId) { LockDoorData lockDoorData = new LockDoorData { networkObjectId = networkObjectId, clientId = GameNetworkManager.Instance.localPlayerController.playerClientId }; LDMLogger.logger.LogInfo((object)"[BROADCAST] Locking the door"); Broadcaster.BroadcastString(JsonConvert.SerializeObject((object)lockDoorData, (Formatting)0), "lock_door"); } private static GameObject FindObjectById(ulong networkId) { return (networkId == 0L) ? null : ((Component)NetworkManager.Singleton.SpawnManager.SpawnedObjects[networkId]).gameObject; } } [HarmonyPatch(typeof(KeyItem))] internal class KeyItemPatch { [HarmonyPatch("ItemActivate")] [HarmonyPrefix] private static bool ItemActivatePatch(ref KeyItem __instance, bool used, bool buttonDown = true) { //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) //IL_003d: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB playerHeldBy = ((GrabbableObject)__instance).playerHeldBy; bool isOwner = ((NetworkBehaviour)__instance).IsOwner; RaycastHit val = default(RaycastHit); if ((Object)(object)playerHeldBy == (Object)null || !isOwner || !Physics.Raycast(new Ray(((Component)playerHeldBy.gameplayCamera).transform.position, ((Component)playerHeldBy.gameplayCamera).transform.forward), ref val, 3f, 2816)) { return false; } DoorLock component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<DoorLock>(); if ((Object)(object)component == (Object)null || component.isPickingLock) { return false; } if ((bool)typeof(DoorLock).GetField("isDoorOpened", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(component)) { LDMLogger.logger.LogInfo((object)"The door is opened"); return false; } if (!component.isLocked) { component.LockDoor(30f); DoorLockPatch.LockDoorPatchSyncWithServer(((NetworkBehaviour)component).NetworkObjectId); } else { component.UnlockDoorSyncWithServer(); } ((GrabbableObject)__instance).playerHeldBy.DespawnHeldObject(); return false; } } [BepInPlugin("ENZDS.LockDoorsMod", "Lock Doors Mod", "1.1.0")] public class LockingKeyModBase : BaseUnityPlugin { private readonly Harmony harmony = new Harmony("ENZDS.LockDoorsMod"); private static LockingKeyModBase instance; private void Awake() { if (instance == null) { instance = this; } LDMLogger.logger.LogInfo((object)"Lock Doors 1.1.0 :)"); harmony.PatchAll(); } } public static class PluginInfo { public const string PLUGIN_GUID = "LockDoorsMod"; public const string PLUGIN_NAME = "LockDoorsMod"; public const string PLUGIN_VERSION = "1.0.0"; } }