Please disclose if your mod was created primarily 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 DarkMist v1.3.0
DarkMist.dll
Decompiled 2 years agousing 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 DarkMist.MonoBehaviors; using DarkMist.Patches; using GameNetcodeStuff; using HarmonyLib; using UnityEngine; using UnityEngine.AI; [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 = "")] [assembly: AssemblyCompany("DarkMist")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("DarkMist")] [assembly: AssemblyTitle("DarkMist")] [assembly: AssemblyVersion("1.0.0.0")] namespace DarkMist { [BepInPlugin("Frack.DarkMist", "Dark Mist", "1.3.0")] public class DarkMistBase : BaseUnityPlugin { public static ConfigEntry<float> ConfigMinDoorDistanceFromPlayers; public static ConfigEntry<int> ConfigMinOpenDoorCountToEntrance; public static ConfigEntry<float> ConfigMinDistanceFromEntrance; public static ConfigEntry<float> ConfigMinDistanceFromOtherPlayers; public static ConfigEntry<float> ConfigMinTime; public static ConfigEntry<int> ConfigMaxDoorsClosed; private static ConfigEntry<bool> DebugMode; private const string ModGuid = "Frack.DarkMist"; private const string ModName = "Dark Mist"; private const string ModVersion = "1.3.0"; private readonly Harmony HarmonyPatch = new Harmony("Frack.DarkMist"); private static DarkMistBase Instance; private ManualLogSource LogSource; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } LogSource = Logger.CreateLogSource("Frack.DarkMist"); LogSource.LogInfo((object)"Dark Mist is awake"); ConfigMinDoorDistanceFromPlayers = ((BaseUnityPlugin)this).Config.Bind<float>("DoorSelection", "MinDoorDistanceFromPlayers", 17f, "Minimum distance from players that a door should be before it closes"); ConfigMaxDoorsClosed = ((BaseUnityPlugin)this).Config.Bind<int>("DoorSelection", "MaxDoorsClosed", 5, "Maximum number of doors that can get closed. (use -1 for infinity)"); ConfigMinOpenDoorCountToEntrance = ((BaseUnityPlugin)this).Config.Bind<int>("TargetingRequirements", "MinOpenDoorCountToEntrance", 2, "Player's won't be targeted until they're at least this many open doors away from the enterance"); ConfigMinDistanceFromEntrance = ((BaseUnityPlugin)this).Config.Bind<float>("TargetingRequirements", "MinDistanceFromEntrance", 50f, "Player's won't be targeted until they're at least this far from the enterance"); ConfigMinDistanceFromOtherPlayers = ((BaseUnityPlugin)this).Config.Bind<float>("TargetingRequirements", "MinDistanceFromOtherPlayers", 0f, "Player's won't be targeted until they're at least this far from other players"); ConfigMinTime = ((BaseUnityPlugin)this).Config.Bind<float>("TargetingRequirements", "MinTime", 30f, "Player's won't be targeted until they've met the above requirements for this many seconds. each player's timer resets after they're targeted"); DebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugMode", false, "Just a debug/cheat mode to help with development"); HarmonyPatch.PatchAll(typeof(DarkMistBase)); HarmonyPatch.PatchAll(typeof(PlayerControllerBPatch)); HarmonyPatch.PatchAll(typeof(DoorLockPatch)); } public static void LogInfo(object data) { Instance.LogSource.LogInfo(data); } public static bool IsDebugMode() { return DebugMode.Value; } } } namespace DarkMist.Patches { [HarmonyPatch(typeof(DoorLock))] internal class DoorLockPatch { [HarmonyPatch("Awake")] [HarmonyPostfix] private static void PatchAwake(DoorLock __instance) { DoorFrameCollider.Spawn(__instance); } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch { [HarmonyPatch("ConnectClientToPlayerObject")] [HarmonyPostfix] private static void PatchConnectClientToPlayerObject(PlayerControllerB __instance) { ((Component)__instance).gameObject.AddComponent<PlayerPathHomeMonitor>(); } [HarmonyPatch("Update")] [HarmonyPostfix] private static void PatchUpdate(ref float ___sprintMeter) { if (DarkMistBase.IsDebugMode()) { ___sprintMeter = 1f; } } } } namespace DarkMist.MonoBehaviors { public class DoorFrameCollider : MonoBehaviour { private DoorLock _Door; public DoorLock Door { get { return _Door; } set { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) _Door = value; Transform transform = ((Component)_Door).transform; ((Component)this).transform.position = transform.position; ((Component)this).transform.localScale = transform.lossyScale * 1.2f; ((Component)this).transform.rotation = transform.rotation; } } private void OnDestroy() { DarkMistBase.LogInfo("Doorframe Destroyed"); } public static DoorFrameCollider Spawn(DoorLock Door) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)3); val.GetComponent<Collider>().isTrigger = true; MeshRenderer component = val.GetComponent<MeshRenderer>(); if (DarkMistBase.IsDebugMode()) { ((Renderer)component).material = new Material(Shader.Find("HDRP/Unlit")); ((Renderer)component).material.color = new Color(0.48f, 1f, 0.87f); ((Renderer)component).material.SetFloat("Alpha", 0.3f); } else { Object.Destroy((Object)(object)component); } DoorFrameCollider doorFrameCollider = val.AddComponent<DoorFrameCollider>(); doorFrameCollider.Door = Door; val.transform.SetParent(((Component)Door).transform.parent.parent); return doorFrameCollider; } } public class PlayerPathHomeMonitor : MonoBehaviour { private PlayerControllerB MyPlayerControllerB; private Transform MyTransform; private Vector3 MainEnteranceNavMeshPos; private LineRenderer PathRenderer; private NavMeshPath PathToEntrance = new NavMeshPath(); private List<DoorLock> OpenDoorsInPath = new List<DoorLock>(); private float TimeWithConditionsMet = 0f; private const float SlowUpdatePathInterval = 0.5f; private static int NumDoorsClosed; private int lastLogTimeWithConditionsMet; private int LastTickDoorCount = 0; private Vector3 PrevMainEnterancePos; private void Awake() { NumDoorsClosed = 0; DarkMistBase.LogInfo("PlayerPathHomeMonitor Awake"); MyTransform = ((Component)this).GetComponent<Transform>(); MyPlayerControllerB = ((Component)this).GetComponent<PlayerControllerB>(); if (DarkMistBase.IsDebugMode()) { PathRenderer = ((Component)this).GetComponent<LineRenderer>(); if ((Object)(object)PathRenderer == (Object)null) { PathRenderer = ((Component)this).gameObject.AddComponent<LineRenderer>(); LineRenderer pathRenderer = PathRenderer; pathRenderer.startWidth *= 0.2f; LineRenderer pathRenderer2 = PathRenderer; pathRenderer2.endWidth *= 0.2f; } } } private void Start() { ((MonoBehaviour)this).Invoke("SlowUpdatePath", 0.5f); } private void Update() { UpdateTimeWithConditionsMet(); } private void UpdateTimeWithConditionsMet() { //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) if (MyPlayerControllerB.isPlayerDead || !MyPlayerControllerB.isInsideFactory) { PathToEntrance.ClearCorners(); if (Object.op_Implicit((Object)(object)PathRenderer)) { PathRenderer.positionCount = 0; } TimeWithConditionsMet = 0f; lastLogTimeWithConditionsMet = 0; } else if (NumDoorsClosed >= DarkMistBase.ConfigMaxDoorsClosed.Value && DarkMistBase.ConfigMaxDoorsClosed.Value != -1) { TimeWithConditionsMet = 0f; lastLogTimeWithConditionsMet = 0; } else { if (OpenDoorsInPath.Count < DarkMistBase.ConfigMinOpenDoorCountToEntrance.Value) { return; } float num = PathLength(PathToEntrance); if (num < DarkMistBase.ConfigMinDistanceFromEntrance.Value) { return; } PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>(false); foreach (PlayerControllerB val in array) { if (!val.isPlayerDead && val.isInsideFactory && (Object)(object)((Component)val).gameObject != (Object)(object)((Component)this).gameObject) { Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position; float magnitude = ((Vector3)(ref val2)).magnitude; if (magnitude < DarkMistBase.ConfigMinDistanceFromOtherPlayers.Value) { return; } } } TimeWithConditionsMet += Time.deltaTime; if ((int)TimeWithConditionsMet >= lastLogTimeWithConditionsMet + 1) { DarkMistBase.LogInfo("Conditions have been met for " + TimeWithConditionsMet + " Seconds"); lastLogTimeWithConditionsMet = (int)TimeWithConditionsMet; } if (TimeWithConditionsMet > DarkMistBase.ConfigMinTime.Value) { DoorLock val3 = SelectDoorToClose(); if (Object.op_Implicit((Object)(object)val3)) { DarkMistBase.LogInfo("Door Closed!"); val3.OpenOrCloseDoor(MyPlayerControllerB); TimeWithConditionsMet = 0f; lastLogTimeWithConditionsMet = 0; } } } } private DoorLock SelectDoorToClose() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) List<DoorLock> list = new List<DoorLock>(); foreach (DoorLock item in OpenDoorsInPath) { bool flag = true; Vector3 position = ((Component)item).transform.position; PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>(false); foreach (PlayerControllerB val in array) { if (!val.isPlayerDead && val.isInsideFactory) { Vector3 val2 = ((Component)val).transform.position - position; float magnitude = ((Vector3)(ref val2)).magnitude; if (magnitude < DarkMistBase.ConfigMinDoorDistanceFromPlayers.Value) { flag = false; break; } } } if (flag) { list.Add(item); } } if (list.Count > 0) { return list[Random.Range(0, list.Count)]; } return null; } private float PathLength(NavMeshPath Path) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) float num = 0f; for (int i = 0; i < Path.corners.Length - 1; i++) { float num2 = num; Vector3 val = Path.corners[i] - Path.corners[i + 1]; num = num2 + ((Vector3)(ref val)).magnitude; } return num; } private void SlowUpdatePath() { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)MyPlayerControllerB)) { return; } if (!MyPlayerControllerB.isPlayerDead && MyPlayerControllerB.isInsideFactory) { if (OpenDoorsInPath == null) { DarkMistBase.LogInfo("OpenDoorsInPath was null unexpectedly... fixing it."); OpenDoorsInPath = new List<DoorLock>(); } if (PathToEntrance == null) { DarkMistBase.LogInfo("PathToEntrance was null unexpectedly... fixing it."); PathToEntrance = new NavMeshPath(); } OpenDoorsInPath.Clear(); if (GetPathFromEnterance(PathToEntrance)) { Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(0f, ((Component)this).transform.lossyScale.y * 0.5f, 0f); if (Object.op_Implicit((Object)(object)PathRenderer)) { ((Renderer)PathRenderer).enabled = true; PathRenderer.positionCount = PathToEntrance.corners.Length; for (int i = 0; i < PathRenderer.positionCount; i++) { PathRenderer.SetPosition(i, PathToEntrance.corners[i] + val); } DarkMistBase.LogInfo("The player is " + PathLength(PathToEntrance) + " Units from the entrance"); } List<DoorFrameCollider> doorFramesInPath = GetDoorFramesInPath(PathToEntrance, val); if (doorFramesInPath.Count != LastTickDoorCount) { DarkMistBase.LogInfo(doorFramesInPath.Count + " Doorframes Found!"); LastTickDoorCount = doorFramesInPath.Count; } foreach (DoorFrameCollider item in doorFramesInPath) { AnimatedObjectTrigger component = ((Component)item.Door).gameObject.GetComponent<AnimatedObjectTrigger>(); if (component.boolValue) { OpenDoorsInPath.Add(item.Door); } } } else if (Object.op_Implicit((Object)(object)PathRenderer)) { ((Renderer)PathRenderer).enabled = false; } } ((MonoBehaviour)this).Invoke("SlowUpdatePath", 0.5f); } private List<DoorFrameCollider> GetDoorFramesInPath(NavMeshPath Path, Vector3 Offset) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) List<DoorFrameCollider> list = new List<DoorFrameCollider>(); Ray val4 = default(Ray); for (int i = 0; i < Path.corners.Length - 1; i++) { Vector3 val = Path.corners[i] + Offset; Vector3 val2 = Path.corners[i + 1] + Offset; Vector3 val3 = val2 - val; float magnitude = ((Vector3)(ref val3)).magnitude; val3 /= magnitude; ((Ray)(ref val4))..ctor(val, val3); RaycastHit[] array = Physics.RaycastAll(val4, magnitude, -1, (QueryTriggerInteraction)2); for (int j = 0; j < array.Length; j++) { RaycastHit val5 = array[j]; DoorFrameCollider component = ((Component)((RaycastHit)(ref val5)).collider).GetComponent<DoorFrameCollider>(); if (Object.op_Implicit((Object)(object)component)) { list.Add(component); } } } return list; } private bool GetPathFromEnterance(NavMeshPath Path) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) bool result = false; if (FindMainEntrancePosition(out var Result)) { if (PrevMainEnterancePos != Result) { MainEnteranceNavMeshPos = RoundManager.Instance.GetRandomNavMeshPositionInRadius(Result, 6f, default(NavMeshHit)); PrevMainEnterancePos = Result; } NavMeshHit val = default(NavMeshHit); if (NavMesh.FindClosestEdge(MyTransform.position, ref val, -1) && NavMesh.CalculatePath(MainEnteranceNavMeshPos, ((NavMeshHit)(ref val)).position, -1, Path)) { result = true; } } return result; } public static bool FindMainEntrancePosition(out Vector3 Result) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>(false); for (int i = 0; i < array.Length; i++) { if (array[i].entranceId == 0 && !array[i].isEntranceToBuilding) { Result = ((Component)array[i]).transform.position; return true; } } Result = default(Vector3); return false; } } }