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 BreathingWalls v1.2.0
BreathingWalls.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using DunGen; using GameNetcodeStuff; using HarmonyLib; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace BreathingWalls; internal static class Breathing { private const float RouteMemorySeconds = 180f; private const float NoticeDistance = 35f; private const float SightDistance = 60f; private const float FacingDot = 0.5f; private static Maze maze; private static bool aliveThisMoon; private static float nextShift; private static float nextSafetyCheck; private static float nextRouteCheck; private static readonly List<PlayerControllerB> inside = new List<PlayerControllerB>(); private static readonly Dictionary<PlayerControllerB, int> lastTile = new Dictionary<PlayerControllerB, int>(); private static readonly Dictionary<int, float> crossedAt = new Dictionary<int, float>(); internal static void HostTick() { StartOfRound instance = StartOfRound.Instance; if (!Plugin.Enabled.Value || (Object)(object)instance == (Object)null || instance.inShipPhase || !instance.shipHasLanded || instance.allPlayerScripts == null) { return; } Maze current = Maze.Current; if (current == null || !current.HasExits) { return; } if (current != maze) { Reset(); maze = current; nextShift = Time.time + Mathf.Max(0f, Plugin.FirstShiftDelay.Value); aliveThisMoon = Random.value < Mathf.Clamp01(Plugin.ChancePerMoon.Value); Plugin.Log.LogInfo((object)(aliveThisMoon ? "The facility is breathing this time." : "The facility is still this time.")); } if (!aliveThisMoon) { return; } inside.Clear(); PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (IsInside(val)) { inside.Add(val); } } float time = Time.time; if (time >= nextRouteCheck) { nextRouteCheck = time + 0.25f; RememberRoutes(); } if (time >= nextSafetyCheck) { nextSafetyCheck = time + 1f; KeepExitsReachable(); } if (time >= nextShift) { nextShift = time + Interval(); if (inside.Count > 0) { Shift(); } } } internal static void Reset() { maze = null; inside.Clear(); lastTile.Clear(); crossedAt.Clear(); } private static void Shift() { //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Max(1, Plugin.WallsPerShift.Value); int num2 = Mathf.FloorToInt((float)maze.UsableCount * Mathf.Clamp01(Plugin.MaxSealedFraction.Value)); if (num2 <= 0) { return; } int num3 = ((maze.SealedCount != 0) ? ((maze.SealedCount >= num2) ? num : Random.Range((num + 1) / 2, num + 1)) : 0); List<int> list = new List<int>(); for (int i = 0; i < maze.ConnectionCount; i++) { if (maze.IsSealed(i)) { list.Add(i); } } Shuffle(list); int num4 = 0; foreach (int item in list) { if (num4 < num3) { maze.Measure(item, out var center, out var size, out var _); if (!AnyoneCanSee(center, size, maze.WallCollider(item))) { Net.BroadcastWall(maze, item, sealedShut: false); num4++; } continue; } break; } int num5 = num; int num6 = 0; foreach (int item2 in SealCandidates()) { if (num6 < num5 && maze.SealedCount < num2) { maze.Measure(item2, out var center2, out var size2, out var rotation2); if (!AnyoneCanSee(center2, size2, null) && !SomethingInDoorway(center2, size2, rotation2) && SafeToSeal(item2)) { Net.BroadcastWall(maze, item2, sealedShut: true); num6++; } continue; } break; } } private static List<int> SealCandidates() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) List<int> list = new List<int>(); Dictionary<int, float> score = new Dictionary<int, float>(); for (int i = 0; i < maze.ConnectionCount; i++) { if (!maze.IsUsable(i) || maze.IsSealed(i)) { continue; } maze.Measure(i, out var center, out var _, out var _); float num = NearestInsideDistance(center); if (!(num < Plugin.HideDistance.Value)) { float num2 = Random.value; if (num < 35f) { num2 += 1f; } if (Plugin.SealRoutesTaken.Value && crossedAt.TryGetValue(i, out var value) && Time.time - value < 180f) { num2 += 2f; } score[i] = num2; list.Add(i); } } list.Sort((int a, int b) => score[b].CompareTo(score[a])); return list; } private static bool SafeToSeal(int c) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) bool[] array = maze.Reach(respectDoors: true); bool[] array2 = maze.Reach(respectDoors: true, c); bool[] array3 = maze.Reach(respectDoors: false); bool[] array4 = maze.Reach(respectDoors: false, c); foreach (PlayerControllerB item in inside) { int num = maze.TileAt(((Component)item).transform.position); if (num < 0 || (array[num] && !array2[num]) || (array3[num] && !array4[num])) { return false; } } return true; } private static void KeepExitsReachable() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) bool[] array = new bool[2] { false, true }; foreach (bool respectDoors in array) { bool[] array2 = maze.Reach(respectDoors); foreach (PlayerControllerB item in inside) { int num = maze.TileAt(((Component)item).transform.position); if (num < 0 || array2[num]) { continue; } List<int> list = maze.WallsBlockingExit(num, respectDoors); if (list == null || list.Count == 0) { continue; } Plugin.Log.LogInfo((object)("Opening " + list.Count + " wall(s) to give " + item.playerUsername + " a way out.")); foreach (int item2 in list) { Net.BroadcastWall(maze, item2, sealedShut: false); } array2 = maze.Reach(respectDoors); } } } private static void RememberRoutes() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) foreach (PlayerControllerB item in inside) { int num = maze.TileAt(((Component)item).transform.position); if (lastTile.TryGetValue(item, out var value) && value != num) { int num2 = maze.ConnectionBetween(value, num); if (num2 >= 0) { crossedAt[num2] = Time.time; } } lastTile[item] = num; } } private static bool AnyoneCanSee(Vector3 center, Vector3 size, Collider ignore) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_007c: 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_005b: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault; Vector3 point = center + Vector3.down * (size.y * 0.35f); foreach (PlayerControllerB item in inside) { Vector3 val = (((Object)(object)item.gameplayCamera != (Object)null) ? ((Component)item.gameplayCamera).transform.position : (((Component)item).transform.position + Vector3.up * 1.6f)); float num = Vector3.Distance(val, center); if (num < Plugin.HideDistance.Value) { return true; } if (!(num > 60f) && Facing(item, center - val) && (Visible(val, center, collidersAndRoomMaskAndDefault, ignore) || Visible(val, point, collidersAndRoomMaskAndDefault, ignore))) { return true; } } return false; } private static bool Facing(PlayerControllerB player, Vector3 toPoint) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_004b: Unknown result type (might be due to invalid IL or missing references) Vector3 forward = ((Component)player).transform.forward; forward.y = 0f; toPoint.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude < 0.001f || ((Vector3)(ref toPoint)).sqrMagnitude < 0.001f) { return true; } return Vector3.Dot(((Vector3)(ref forward)).normalized, ((Vector3)(ref toPoint)).normalized) > 0.5f; } private static bool Visible(Vector3 eye, Vector3 point, int mask, Collider ignore) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) RaycastHit val = default(RaycastHit); if (!Physics.Linecast(eye, point, ref val, mask, (QueryTriggerInteraction)1)) { return true; } if ((Object)(object)ignore != (Object)null) { return (Object)(object)((RaycastHit)(ref val)).collider == (Object)(object)ignore; } return false; } private static bool SomethingInDoorway(Vector3 center, Vector3 size, Quaternion rotation) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) int mask = LayerMask.GetMask(new string[2] { "Enemies", "Player" }); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(size.x * 0.5f, size.y * 0.5f, 1.5f); return Physics.CheckBox(center, val, rotation, mask, (QueryTriggerInteraction)2); } private static float NearestInsideDistance(Vector3 point) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) float num = float.MaxValue; foreach (PlayerControllerB item in inside) { num = Mathf.Min(num, Vector3.Distance(point, ((Component)item).transform.position)); } return num; } private static bool IsInside(PlayerControllerB player) { if ((Object)(object)player != (Object)null && player.isPlayerControlled && !player.isPlayerDead) { return player.isInsideFactory; } return false; } private static float Interval() { float num = Mathf.Max(5f, Plugin.ShiftIntervalMin.Value); return Random.Range(num, Mathf.Max(num, Plugin.ShiftIntervalMax.Value)); } private static void Shuffle(List<int> list) { for (int num = list.Count - 1; num > 0; num--) { int index = Random.Range(0, num + 1); int value = list[num]; list[num] = list[index]; list[index] = value; } } } internal class Maze { private static Maze current; private static readonly FieldInfo BigDoorOpenField = typeof(TerminalAccessibleObject).GetField("isDoorOpen", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); internal readonly Dungeon Dungeon; private readonly List<Tile> tiles = new List<Tile>(); private readonly Dictionary<Tile, int> tileIndex = new Dictionary<Tile, int>(); private readonly Bounds[] tileBounds; private readonly List<int>[] tileConnections; private readonly List<int> exitTiles = new List<int>(); private readonly Doorway[] doorways; private readonly int[] tileA; private readonly int[] tileB; private readonly bool[] sealedShut; private readonly Wall[] walls; private readonly List<DoorLock>[] locks; private readonly List<TerminalAccessibleObject>[] bigDoors; private int usableCount; private int sealedCount; internal static Maze Current { get { RoundManager instance = RoundManager.Instance; Dungeon val = null; if ((Object)(object)instance != (Object)null && instance.dungeonCompletedGenerating && (Object)(object)instance.dungeonGenerator != (Object)null && instance.dungeonGenerator.Generator != null) { val = instance.dungeonGenerator.Generator.CurrentDungeon; } if ((Object)(object)val == (Object)null) { current = null; return null; } if (current == null || (Object)(object)current.Dungeon != (Object)(object)val) { current = new Maze(val); Plugin.Log.LogInfo((object)("Mapped the facility: " + current.tiles.Count + " rooms, " + current.usableCount + " doorways, " + current.exitTiles.Count + " exits.")); } return current; } } internal int ConnectionCount => doorways.Length; internal int UsableCount => usableCount; internal int SealedCount => sealedCount; internal bool HasExits { get { if (exitTiles.Count == 0) { FindExits(); } return exitTiles.Count > 0; } } internal static void Forget() { current = null; } private Maze(Dungeon dungeon) { //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) Dungeon = dungeon; foreach (Tile allTile in dungeon.AllTiles) { if ((Object)(object)allTile != (Object)null && !tileIndex.ContainsKey(allTile)) { tileIndex[allTile] = tiles.Count; tiles.Add(allTile); } } tileBounds = (Bounds[])(object)new Bounds[tiles.Count]; tileConnections = new List<int>[tiles.Count]; for (int i = 0; i < tiles.Count; i++) { ref Bounds reference = ref tileBounds[i]; reference = BoundsOf(tiles[i]); tileConnections[i] = new List<int>(); } List<DoorwayConnection> list = new List<DoorwayConnection>(dungeon.Connections); int count = list.Count; doorways = (Doorway[])(object)new Doorway[count]; tileA = new int[count]; tileB = new int[count]; sealedShut = new bool[count]; walls = new Wall[count]; locks = new List<DoorLock>[count]; bigDoors = new List<TerminalAccessibleObject>[count]; for (int j = 0; j < count; j++) { Doorway val2 = ((list[j] != null) ? list[j].A : null); Doorway val3 = ((list[j] != null) ? list[j].B : null); doorways[j] = (((Object)(object)val2 != (Object)null) ? val2 : val3); tileA[j] = TileOf(val2); tileB[j] = TileOf(val3); locks[j] = new List<DoorLock>(); bigDoors[j] = new List<TerminalAccessibleObject>(); if (IsUsable(j)) { tileConnections[tileA[j]].Add(j); tileConnections[tileB[j]].Add(j); usableCount++; } } DoorLock[] array = Object.FindObjectsOfType<DoorLock>(); foreach (DoorLock val4 in array) { int num = NearestConnection(((Component)val4).transform.position, 3f); if (num >= 0) { locks[num].Add(val4); } } TerminalAccessibleObject[] array2 = Object.FindObjectsOfType<TerminalAccessibleObject>(); foreach (TerminalAccessibleObject val5 in array2) { if (val5.isBigDoor) { int num2 = NearestConnection(((Component)val5).transform.position, 4f); if (num2 >= 0) { bigDoors[num2].Add(val5); } } } FindExits(); } internal bool IsUsable(int c) { if ((Object)(object)doorways[c] != (Object)null && tileA[c] >= 0 && tileB[c] >= 0) { return tileA[c] != tileB[c]; } return false; } internal bool IsSealed(int c) { return sealedShut[c]; } internal Collider WallCollider(int c) { if (!((Object)(object)walls[c] != (Object)null)) { return null; } return walls[c].Collider; } internal void Measure(int c, out Vector3 center, out Vector3 size, out Quaternion rotation) { Wall.Measure(doorways[c], out center, out size, out rotation); } internal void SetSealed(int c, bool shut) { if (c < 0 || c >= sealedShut.Length || !IsUsable(c) || sealedShut[c] == shut) { return; } sealedShut[c] = shut; if (shut) { sealedCount++; walls[c] = Wall.Raise(doorways[c]); return; } sealedCount--; if ((Object)(object)walls[c] != (Object)null) { walls[c].Lower(); walls[c] = null; } } internal int TileAt(Vector3 point) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) int result = -1; float num = float.MaxValue; for (int i = 0; i < tileBounds.Length; i++) { Bounds val = tileBounds[i]; float num2; if (((Bounds)(ref val)).Contains(point)) { Vector3 val2 = ((Bounds)(ref val)).center - point; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; Vector3 extents = ((Bounds)(ref val)).extents; num2 = sqrMagnitude / Mathf.Max(0.01f, ((Vector3)(ref extents)).sqrMagnitude) - 10f; } else { num2 = ((Bounds)(ref val)).SqrDistance(point); } if (num2 < num) { num = num2; result = i; } } return result; } internal int ConnectionBetween(int from, int to) { if (from < 0 || to < 0) { return -1; } foreach (int item in tileConnections[from]) { if (Other(item, from) == to) { return item; } } return -1; } internal bool[] Reach(bool respectDoors, int alsoSealed = -1) { if (exitTiles.Count == 0) { FindExits(); } bool[] array = new bool[tiles.Count]; Queue<int> queue = new Queue<int>(); foreach (int exitTile in exitTiles) { array[exitTile] = true; queue.Enqueue(exitTile); } while (queue.Count > 0) { int num2 = queue.Dequeue(); foreach (int item in tileConnections[num2]) { if (item != alsoSealed && !sealedShut[item] && (!respectDoors || !DoorBlocked(item))) { int num4 = Other(item, num2); if (!array[num4]) { array[num4] = true; queue.Enqueue(num4); } } } } return array; } internal List<int> WallsBlockingExit(int fromTile, bool respectDoors) { if (fromTile < 0 || !HasExits) { return null; } int count = tiles.Count; int[] array = new int[count]; int[] array2 = new int[count]; bool[] array3 = new bool[count]; for (int i = 0; i < count; i++) { array[i] = int.MaxValue; array2[i] = -1; } LinkedList<int> linkedList = new LinkedList<int>(); array[fromTile] = 0; linkedList.AddFirst(fromTile); while (linkedList.Count > 0) { int value = linkedList.First.Value; linkedList.RemoveFirst(); if (array3[value]) { continue; } array3[value] = true; if (exitTiles.Contains(value)) { List<int> list = new List<int>(); for (int num = value; num != fromTile; num = Other(array2[num], num)) { if (sealedShut[array2[num]]) { list.Add(array2[num]); } } return list; } foreach (int item in tileConnections[value]) { if (respectDoors && DoorBlocked(item)) { continue; } int num3 = Other(item, value); int num4 = (sealedShut[item] ? 1 : 0); if (array[value] + num4 < array[num3]) { array[num3] = array[value] + num4; array2[num3] = item; if (num4 == 0) { linkedList.AddFirst(num3); } else { linkedList.AddLast(num3); } } } } return null; } private int Other(int c, int tile) { if (tileA[c] != tile) { return tileA[c]; } return tileB[c]; } private bool DoorBlocked(int c) { foreach (DoorLock item in locks[c]) { if ((Object)(object)item != (Object)null && item.isLocked) { return true; } } if (BigDoorOpenField != null) { foreach (TerminalAccessibleObject item2 in bigDoors[c]) { if ((Object)(object)item2 != (Object)null && !(bool)BigDoorOpenField.GetValue(item2)) { return true; } } } return false; } private int TileOf(Doorway doorway) { if ((Object)(object)doorway == (Object)null) { return -1; } Tile val = (((Object)(object)doorway.Tile != (Object)null) ? doorway.Tile : ((Component)doorway).GetComponentInParent<Tile>()); if (!((Object)(object)val != (Object)null) || !tileIndex.TryGetValue(val, out var value)) { return -1; } return value; } private int NearestConnection(Vector3 point, float within) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) int result = -1; float num = within; for (int i = 0; i < doorways.Length; i++) { if (IsUsable(i)) { float num2 = Vector3.Distance(((Component)doorways[i]).transform.position, point); if (num2 < num) { num = num2; result = i; } } } return result; } private void FindExits() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0054: Unknown result type (might be due to invalid IL or missing references) exitTiles.Clear(); EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>(); foreach (EntranceTeleport val in array) { if (!((Object)(object)val == (Object)null) && !val.isEntranceToBuilding) { Vector3 point = (((Object)(object)val.entrancePoint != (Object)null) ? val.entrancePoint.position : ((Component)val).transform.position); int num = TileAt(point); if (num >= 0 && !exitTiles.Contains(num)) { exitTiles.Add(num); } } } } private static Bounds BoundsOf(Tile tile) { //IL_003e: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) if (tile.Placement != null) { Bounds bounds = tile.Placement.Bounds; Vector3 size = ((Bounds)(ref bounds)).size; if (((Vector3)(ref size)).sqrMagnitude > 0.01f) { return tile.Placement.Bounds; } } Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(((Component)tile).transform.position, Vector3.zero); Renderer[] componentsInChildren = ((Component)tile).GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { ((Bounds)(ref result)).Encapsulate(val.bounds); } return result; } } internal static class Net { private const string WallMessage = "BreathingWalls.Wall"; private const int PayloadSize = 9; private static CustomMessagingManager registeredWith; internal static bool IsHost { get { if ((Object)(object)NetworkManager.Singleton != (Object)null) { return NetworkManager.Singleton.IsServer; } return false; } } internal static void OnLobbyStarted() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null && singleton.CustomMessagingManager != registeredWith) { registeredWith = singleton.CustomMessagingManager; registeredWith.RegisterNamedMessageHandler("BreathingWalls.Wall", new HandleNamedMessageDelegate(OnWallReceived)); } } internal static void OnLobbyEnded() { if (registeredWith != null) { try { registeredWith.UnregisterNamedMessageHandler("BreathingWalls.Wall"); } catch (Exception) { } registeredWith = null; } } internal static void BroadcastWall(Maze maze, int connection, bool sealedShut) { byte[] array = new byte[9]; Buffer.BlockCopy(BitConverter.GetBytes(connection), 0, array, 0, 4); Buffer.BlockCopy(BitConverter.GetBytes(maze.ConnectionCount), 0, array, 4, 4); array[8] = (byte)(sealedShut ? 1 : 0); SendToOthers(array); maze.SetSealed(connection, sealedShut); } private static void OnWallReceived(ulong senderClientId, FastBufferReader reader) { if (senderClientId == 0 && ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position >= 9) { byte[] array = new byte[9]; ((FastBufferReader)(ref reader)).ReadBytesSafe(ref array, 9, 0); int num = BitConverter.ToInt32(array, 0); int num2 = BitConverter.ToInt32(array, 4); Maze current = Maze.Current; if (current == null || current.ConnectionCount != num2 || num < 0 || num >= num2) { Plugin.Log.LogWarning((object)"Ignored a wall change for a facility layout that doesn't match this one."); } else { current.SetSealed(num, array[8] != 0); } } } private static void SendToOthers(byte[] payload) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null) { return; } FastBufferWriter val = default(FastBufferWriter); foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != singleton.LocalClientId) { ((FastBufferWriter)(ref val))..ctor(payload.Length, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteBytesSafe(payload, payload.Length, 0); singleton.CustomMessagingManager.SendNamedMessage("BreathingWalls.Wall", connectedClientsId, val, (NetworkDelivery)3); } finally { ((FastBufferWriter)(ref val)).Dispose(); } } } } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] internal static class PlayerUpdatePatch { private static void Postfix(PlayerControllerB __instance) { if (Net.IsHost && (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController) { Breathing.HostTick(); } } } [HarmonyPatch(typeof(StartOfRound))] internal static class StartOfRoundPatches { [HarmonyPostfix] [HarmonyPatch("Start")] private static void LobbyStarted() { Net.OnLobbyStarted(); } [HarmonyPostfix] [HarmonyPatch("ShipLeave")] private static void ShipLeft() { Breathing.Reset(); } [HarmonyPostfix] [HarmonyPatch("OnDestroy")] private static void LobbyEnded() { Breathing.Reset(); Maze.Forget(); Net.OnLobbyEnded(); } } [BepInPlugin("axelc.breathingwalls", "BreathingWalls", "1.2.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "axelc.breathingwalls"; public const string PluginName = "BreathingWalls"; public const string Version = "1.2.0"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<float> ChancePerMoon; internal static ConfigEntry<float> FirstShiftDelay; internal static ConfigEntry<float> ShiftIntervalMin; internal static ConfigEntry<float> ShiftIntervalMax; internal static ConfigEntry<int> WallsPerShift; internal static ConfigEntry<float> MaxSealedFraction; internal static ConfigEntry<float> HideDistance; internal static ConfigEntry<bool> SealRoutesTaken; internal static ConfigEntry<float> Volume; internal static ConfigEntry<bool> AudibleBreathing; internal static ConfigEntry<bool> CameraShake; private void Awake() { //IL_01ac: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "The facility rearranges itself while you're inside: doorways seal shut and sealed ones open again. There is always an open, unlocked route from every player inside to an exit. Only the host's settings in General and Layout are used; Effects are per player."); ChancePerMoon = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChancePerMoon", 0.3f, "Chance (0 to 1) that the facility is alive on any given landing. Rolled once when you land; nobody is told."); FirstShiftDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "FirstShiftDelay", 60f, "Seconds after landing before the first wall moves."); ShiftIntervalMin = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "MinSecondsBetweenShifts", 25f, "Shortest wait between the facility shifting."); ShiftIntervalMax = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "MaxSecondsBetweenShifts", 60f, "Longest wait between the facility shifting."); WallsPerShift = ((BaseUnityPlugin)this).Config.Bind<int>("Layout", "WallsPerShift", 4, "How many doorways seal each time the facility shifts, all at once. About as many sealed ones open again. Fewer move when there aren't enough out of sight, or when sealing more would cut someone off from the exits."); MaxSealedFraction = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "MaxSealedFraction", 0.35f, "Most of the facility's doorways (0 to 1) that can be sealed at once."); HideDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "HideDistance", 10f, "A wall only moves when no player inside is this close to it (meters) and nobody inside is looking at it."); SealRoutesTaken = ((BaseUnityPlugin)this).Config.Bind<bool>("Layout", "SealRoutesTaken", true, "Prefer sealing doorways the crew walked through recently, so the way you came in is the first thing to go."); Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "Volume", 0.9f, "Loudness of the grinding when a wall moves, on your machine, 0 to 1."); AudibleBreathing = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "AudibleBreathing", true, "Stand close to a sealed doorway and you can hear it breathe."); CameraShake = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "CameraShake", true, "Your view shakes a little when a wall moves nearby."); new Harmony("axelc.breathingwalls").PatchAll(); Log.LogInfo((object)"BreathingWalls 1.2.0 loaded."); } } internal static class Sounds { private const int GrindVariants = 4; private static AudioClip[] grinds; private static AudioClip breath; internal static AudioClip Breath { get { if ((Object)(object)breath == (Object)null) { breath = MakeClip("BreathingWalls Breath", Synth.BreathSamples(2741)); } return breath; } } internal static void PlayGrind(Vector3 position) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) if (grinds == null) { grinds = (AudioClip[])(object)new AudioClip[4]; for (int i = 0; i < 4; i++) { grinds[i] = MakeClip("BreathingWalls Grind " + i, Synth.GrindSamples(6151 * (i + 1))); } } AudioClip val = grinds[Random.Range(0, grinds.Length)]; GameObject val2 = new GameObject("BreathingWalls Grind"); val2.transform.position = position; AudioSource val3 = AddSource(val2, 4f, 45f, Plugin.Volume.Value); val3.pitch = Random.Range(0.85f, 1.1f); val2.AddComponent<AudioReverbFilter>().reverbPreset = (AudioReverbPreset)14; Muffle(val2.AddComponent<AudioLowPassFilter>(), position); val3.PlayOneShot(val); Object.Destroy((Object)(object)val2, val.length / val3.pitch + 4f); } internal static AudioSource AddSource(GameObject go, float minDistance, float maxDistance, float volume) { AudioSource val = go.AddComponent<AudioSource>(); val.playOnAwake = false; val.spatialBlend = 1f; val.rolloffMode = (AudioRolloffMode)0; val.minDistance = minDistance; val.maxDistance = maxDistance; val.dopplerLevel = 0f; val.spread = 60f; val.volume = Mathf.Clamp01(volume); PlayerControllerB val2 = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.movementAudio != (Object)null) { val.outputAudioMixerGroup = val2.movementAudio.outputAudioMixerGroup; } return val; } private static AudioClip MakeClip(string name, float[] samples) { AudioClip val = AudioClip.Create(name, samples.Length, 1, 44100, false); val.SetData(samples, 0); return val; } private static void Muffle(AudioLowPassFilter lowPass, Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_002e: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ListenerPosition(); bool flag = Physics.Linecast(val, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1); float num = Mathf.Lerp(7000f, 2000f, Mathf.InverseLerp(5f, 45f, Vector3.Distance(val, position))); lowPass.cutoffFrequency = (flag ? (num * 0.5f) : num); } private static Vector3 ListenerPosition() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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) StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.audioListener != (Object)null) { return ((Component)instance.audioListener).transform.position; } PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; if (!((Object)(object)localPlayerController != (Object)null)) { return Vector3.zero; } return ((Component)localPlayerController.gameplayCamera).transform.position; } } internal static class Synth { internal const int SampleRate = 44100; private const double TwoPi = Math.PI * 2.0; internal const float BreathPeriod = 5f; private const float InhaleStart = 0.2f; private const float InhaleEnd = 1.9f; private const float ExhaleStart = 2.5f; private const float ExhaleEnd = 4.5f; internal static float BreathFullness(float t) { if (t < 0.2f || t >= 4.5f) { return 0f; } if (t < 1.9f) { return SmoothStep((t - 0.2f) / 1.6999999f); } if (t < 2.5f) { return 1f; } return 1f - SmoothStep((t - 2.5f) / 2f); } internal static float[] GrindSamples(int seed) { Random random = new Random(seed); float num = 3.4f; int num2 = (int)(num * 44100f); float[] array = new float[num2]; float num3 = Range(random, 34f, 52f); float num4 = Range(random, 2.5f, 4.5f); float num5 = Range(random, 6f, 9.5f); double num6 = random.NextDouble() * (Math.PI * 2.0); float num7 = Range(random, 0.00015f, 0.0004f); double num8 = 0.0; float num9 = 0f; float num10 = 0f; float num11 = 0f; float num12 = 0f; float num13 = 0f; for (int i = 0; i < num2; i++) { float num14 = (float)i / 44100f; float num15 = num14 / num; float num16 = (float)(random.NextDouble() * 2.0 - 1.0); num9 = num9 * 0.996f + num16 * 0.04f; num10 += (num9 - num10) * 0.03f; num11 += (num16 - num11) * 0.5f; num12 += (num16 - num12) * 0.1f; float val = (float)(Math.Sin(Math.PI * 2.0 * (double)num4 * (double)num14 + num6) * Math.Sin(Math.PI * 2.0 * (double)num5 * (double)num14)); float num17 = (num11 - num12) * Math.Max(0f, val) * 0.55f; double num18 = (double)num3 * (1.15 - 0.3 * (double)num15) * (1.0 + 0.03 * Math.Sin(4.39822971502571 * (double)num14)); num8 += num18 / 44100.0; float num19 = (float)(Math.Sin(Math.PI * 2.0 * num8) + 0.35 * (double)Saw(num8 * 2.0)) * 0.5f; if (random.NextDouble() < (double)num7) { num13 = Range(random, 0.5f, 1f); } num13 *= 0.9975f; float num20 = (num11 - num12) * num13 * 1.4f; float num21 = Math.Min(1f, num14 / 0.25f); float num22 = ((num15 > 0.8f) ? ((float)Math.Pow(1f - (num15 - 0.8f) / 0.2f, 2.0)) : 1f); float num23 = (num10 * 3f + num17 + num19 * 0.6f + num20) * num21 * num22; array[i] = (float)Math.Tanh(num23 * 1.6f); } Normalize(array, 0.9f); return array; } internal static float[] BreathSamples(int seed) { Random random = new Random(seed); int num = 220500; float[] array = new float[num]; double num2 = 0.0; float num3 = 0f; float num4 = 0f; float num5 = 0f; for (int i = 0; i < num; i++) { float num6 = (float)i / 44100f; float num7 = (float)(random.NextDouble() * 2.0 - 1.0); num3 += (num7 - num3) * 0.35f; num4 += (num7 - num4) * 0.09f; num5 += (num7 - num5) * 0.025f; float num8 = 0f; if (num6 >= 0.2f && num6 < 1.9f) { float num9 = (num6 - 0.2f) / 1.6999999f; float num10 = (float)Math.Sin(Math.PI * (double)num9); num8 += (num3 - num4) * num10 * 0.9f; } if (num6 >= 2.5f && num6 < 4.5f) { float num11 = (num6 - 2.5f) / 2f; float num12 = (float)Math.Sin(Math.PI * Math.Pow(num11, 0.7)); num2 += (double)((55f + 10f * num11) / 44100f); float num13 = 0.6f + 0.4f * (float)Math.Sin(Math.PI * 2.0 * num2); num8 += (num4 - num5) * num12 * num13 * 1.4f + num5 * num12 * 0.8f; } array[i] = num8; } Normalize(array, 0.8f); return array; } private static float Saw(double phase) { return (float)(2.0 * (phase - Math.Floor(phase)) - 1.0); } private static float Range(Random rng, float min, float max) { return min + (float)rng.NextDouble() * (max - min); } private static float SmoothStep(float t) { return t * t * (3f - 2f * t); } private static void Normalize(float[] samples, float peak) { float num = 0f; foreach (float value in samples) { num = Math.Max(num, Math.Abs(value)); } if (!(num <= 0f)) { float num2 = peak / num; for (int j = 0; j < samples.Length; j++) { samples[j] *= num2; } } } } internal class Wall : MonoBehaviour { private const float Thickness = 0.4f; private const float MoveSeconds = 2.6f; private const float ShakeDistance = 14f; private const float StaggerSeconds = 1.5f; private static Material fallbackMaterial; private Transform slab; private BoxCollider box; private AudioSource breath; private Vector3 size; private float progress; private bool rising = true; private float breathOffset; private float startIn; private bool grindPending; internal Collider Collider => (Collider)(object)box; internal static void Measure(Doorway doorway, out Vector3 center, out Vector3 size, out Quaternion rotation) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) Vector2 val = (Vector2)(((Object)(object)doorway.Socket != (Object)null) ? doorway.Socket.Size : new Vector2(3f, 3f)); size = new Vector3(val.x + 0.3f, val.y + 0.2f, 0.4f); center = ((Component)doorway).transform.position + Vector3.up * (size.y * 0.5f); Vector3 forward = ((Component)doorway).transform.forward; forward.y = 0f; rotation = ((((Vector3)(ref forward)).sqrMagnitude > 0.001f) ? Quaternion.LookRotation(((Vector3)(ref forward)).normalized, Vector3.up) : Quaternion.identity); } internal static Wall Raise(Doorway doorway) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_004a: 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_0080: Unknown result type (might be due to invalid IL or missing references) Measure(doorway, out var center, out var wallSize, out var rotation); GameObject val = new GameObject("BreathingWalls Wall"); val.transform.SetParent(((Object)(object)doorway.Tile != (Object)null) ? ((Component)doorway.Tile).transform : ((Component)doorway).transform, true); val.transform.position = center; val.transform.rotation = rotation; int num = LayerMask.NameToLayer("Room"); if (num >= 0) { val.layer = num; } Wall wall = val.AddComponent<Wall>(); wall.Build(doorway, wallSize, num); return wall; } private void Build(Doorway doorway, Vector3 wallSize, int layer) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) size = wallSize; box = ((Component)this).gameObject.AddComponent<BoxCollider>(); box.size = size; NavMeshObstacle val = ((Component)this).gameObject.AddComponent<NavMeshObstacle>(); val.shape = (NavMeshObstacleShape)1; val.size = size; val.carving = true; GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)3); Object.DestroyImmediate((Object)(object)val2.GetComponent<Collider>()); ((Object)val2).name = "Slab"; if (layer >= 0) { val2.layer = layer; } slab = val2.transform; slab.SetParent(((Component)this).transform, false); slab.localScale = size; slab.localPosition = Vector3.down * size.y; Material val3 = WallMaterial(doorway); if ((Object)(object)val3 != (Object)null) { ((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = val3; } breathOffset = Random.Range(0f, 5f); StartMoving(); } internal void Lower() { rising = false; if ((Object)(object)breath != (Object)null) { breath.Stop(); } StartMoving(); } private void StartMoving() { startIn = Random.Range(0f, 1.5f); grindPending = true; } private void Update() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) if (startIn > 0f) { startIn -= Time.deltaTime; return; } if (grindPending) { grindPending = false; Sounds.PlayGrind(((Component)this).transform.position); ShakeIfClose(); } float num = (rising ? 1f : 0f); bool flag = progress != num; if (flag) { progress = Mathf.MoveTowards(progress, num, Time.deltaTime / 2.6f); if (!rising && progress <= 0f) { Object.Destroy((Object)(object)((Component)this).gameObject); return; } if (rising && progress >= 1f) { StartBreathing(); } } float num2 = progress * progress * (3f - 2f * progress); float num3 = (flag ? Random.Range(-0.012f, 0.012f) : 0f); float num4 = Synth.BreathFullness(Mathf.Repeat(Time.time + breathOffset, 5f)) * num2; slab.localPosition = new Vector3(num3, Mathf.Lerp(0f - size.y, 0f, num2), 0f); slab.localScale = new Vector3(size.x * (1f + 0.01f * num4), size.y, size.z * (1f + 0.3f * num4)); } private void StartBreathing() { if (Plugin.AudibleBreathing.Value && !((Object)(object)breath != (Object)null)) { AudioClip val = Sounds.Breath; if (!((Object)(object)val == (Object)null)) { breath = Sounds.AddSource(((Component)this).gameObject, 0.8f, 7f, 0.55f); breath.clip = val; breath.loop = true; breath.Play(); breath.time = Mathf.Repeat(Time.time + breathOffset, 5f) % val.length; } } } private void ShakeIfClose() { //IL_004c: 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) PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if (Plugin.CameraShake.Value && !((Object)(object)val == (Object)null) && !val.isPlayerDead && !((Object)(object)HUDManager.Instance == (Object)null) && Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) < 14f) { HUDManager.Instance.ShakeCamera((ScreenShakeType)0); } } private static Material WallMaterial(Doorway doorway) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) Tile tile = doorway.Tile; Material val = null; float num = 0f; if ((Object)(object)tile != (Object)null) { MeshRenderer[] componentsInChildren = ((Component)tile).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val2 in componentsInChildren) { if (!((Renderer)val2).enabled || (Object)(object)((Renderer)val2).sharedMaterial == (Object)null) { continue; } string text = (((Object)val2).name + " " + ((Object)((Renderer)val2).sharedMaterial).name).ToLowerInvariant(); if (text.Contains("wall")) { Bounds bounds = ((Renderer)val2).bounds; Vector3 val3 = ((Bounds)(ref bounds)).size; float num2 = Mathf.Max(val3.x, val3.z) * val3.y; if (num2 > num) { num = num2; val = ((Renderer)val2).sharedMaterial; } } } } if (!((Object)(object)val != (Object)null)) { return FallbackMaterial(); } return val; } private static Material FallbackMaterial() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)fallbackMaterial == (Object)null) { Shader val = Shader.Find("HDRP/Lit"); if ((Object)(object)val == (Object)null) { return null; } fallbackMaterial = new Material(val); fallbackMaterial.SetColor("_BaseColor", new Color(0.24f, 0.23f, 0.21f)); } return fallbackMaterial; } }