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 DreadAmbience v1.11.0
DreadAmbience.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using DunGen; using GameNetcodeStuff; using HarmonyLib; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace DreadAmbience; public static class CustomSounds { public class RawClip { public string Name; public float[] Data; public int Rate; public int Channels = 1; } private static readonly Dictionary<string, List<AudioClip>> clips = new Dictionary<string, List<AudioClip>>(StringComparer.OrdinalIgnoreCase); private static readonly Random rng = new Random(); public static string Folder; public static List<RawClip> LoadRaw() { List<RawClip> list = new List<RawClip>(); if (string.IsNullOrEmpty(Folder) || !Directory.Exists(Folder)) { return list; } string[] files = Directory.GetFiles(Folder, "*.wav", SearchOption.AllDirectories); foreach (string path in files) { if (!Path.GetFileNameWithoutExtension(path).Contains("_")) { continue; } try { RawClip rawClip = ReadWav(path); if (rawClip != null) { list.Add(rawClip); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Skipping " + Path.GetFileName(path) + ": " + ex.Message)); } } return list; } public static void CreateClips(List<RawClip> raws) { clips.Clear(); foreach (RawClip raw in raws) { string key = (raw.Name.Contains("_") ? raw.Name.Substring(0, raw.Name.IndexOf('_')) : raw.Name); AudioClip val = AudioClip.Create("DA_" + raw.Name, raw.Data.Length / raw.Channels, raw.Channels, raw.Rate, false); val.SetData(raw.Data, 0); if (!clips.TryGetValue(key, out var value)) { value = (clips[key] = new List<AudioClip>()); } value.Add(val); } List<string> list2 = new List<string>(); foreach (KeyValuePair<string, List<AudioClip>> clip in clips) { list2.Add($"{clip.Key} {clip.Value.Count}"); } Plugin.Log.LogInfo((object)((raws.Count > 0) ? ("Loaded designed sounds: " + string.Join(", ", list2)) : "No designed sounds found, using built-in ones.")); } public static bool Has(string key) { if (clips.TryGetValue(key, out var value)) { return value.Count > 0; } return false; } public static AudioClip Pick(string key) { string theme = Interior.Theme; if (theme != "facility" && clips.TryGetValue(theme + "-" + key, out var value) && value.Count > 0) { return value[rng.Next(value.Count)]; } if (!clips.TryGetValue(key, out var value2) || value2.Count <= 0) { return null; } return value2[rng.Next(value2.Count)]; } private static RawClip ReadWav(string path) { byte[] array = File.ReadAllBytes(path); if (array.Length < 44 || array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70) { throw new Exception("not a RIFF wav"); } int i = 12; int num = 1; int rate = 44100; int num2 = 16; int num3 = 1; int num4 = -1; int num5 = 0; int num6; for (; i + 8 <= array.Length; i += 8 + num6 + (num6 & 1)) { string text = Encoding.ASCII.GetString(array, i, 4); num6 = BitConverter.ToInt32(array, i + 4); if (text == "fmt ") { num3 = BitConverter.ToInt16(array, i + 8); num = BitConverter.ToInt16(array, i + 10); rate = BitConverter.ToInt32(array, i + 12); num2 = BitConverter.ToInt16(array, i + 22); } else if (text == "data") { num4 = i + 8; num5 = Math.Min(num6, array.Length - num4); break; } } if (num4 < 0) { throw new Exception("no data chunk"); } if ((num3 != 1 || (num2 != 16 && num2 != 24)) && (num3 != 3 || num2 != 32)) { throw new Exception($"unsupported format {num3}/{num2}-bit (use 16-bit PCM)"); } int num7 = num2 / 8; int num8 = num5 / (num7 * num); int num9 = ((num != 2) ? 1 : 2); float[] array2 = new float[num8 * num9]; for (int j = 0; j < num8; j++) { float num10 = 0f; for (int k = 0; k < num; k++) { int num11 = num4 + (j * num + k) * num7; float num12 = num2 switch { 16 => (float)BitConverter.ToInt16(array, num11) / 32768f, 24 => (float)(array[num11] | (array[num11 + 1] << 8) | ((sbyte)array[num11 + 2] << 16)) / 8388608f, _ => BitConverter.ToSingle(array, num11), }; if (num9 == 2) { array2[j * 2 + k] = num12; } else { num10 += num12; } } if (num9 == 1) { array2[j] = num10 / (float)num; } } return new RawClip { Name = Path.GetFileNameWithoutExtension(path), Data = array2, Rate = rate, Channels = num9 }; } } public class DreadDirector : MonoBehaviour { private AudioSource drone; private AudioSource tension; private AudioSource heart; private AudioSource sting; private BinauralSource[] bed; private string[] bedKeys; private float[] bedWeight; private BinauralSource tensA; private BinauralSource tensB; private bool spatialLayers; private float bedAngle; private Vector3 lastThreatDir = Vector3.forward; private bool built; private float threat; private float targetThreat; private bool hunted; private bool wasHunted; private float nextScan; private float nextBeat; private float lastSting = -999f; private float nextEvent; private float nextDebug; private float threatOneSecondAgo; private float threatHistoryTimer; private bool insideFactory; private bool active; private HashSet<string> ignored; private readonly Random rng = new Random(); private Task<SoundBank.Raw> synth; private float synthStarted; private string lastSource; private float lastSourceLog; internal Vector3 ThreatPos { get; private set; } internal bool HasThreatPos { get; private set; } internal bool Ready => built; internal bool Active => active; internal float Threat => threat; internal PlayerControllerB Player { get; private set; } internal bool ThreatBehindYou { get; private set; } private void Start() { synthStarted = Time.realtimeSinceStartup; synth = Task.Run(() => SoundBank.GenerateAll()); } private void FinishSetup() { Task<SoundBank.Raw> task = synth; synth = null; if (task.IsFaulted || task.IsCanceled) { Plugin.Log.LogError((object)("Sound synthesis failed, the mod will stay silent: " + task.Exception)); return; } try { SoundBank.CreateClips(task.Result); drone = MakeSource("Drone", SoundBank.Drone, loop: true); tension = MakeSource("Tension", SoundBank.Tension, loop: true); heart = MakeSource("Heart", null, loop: false); sting = MakeSource("Sting", null, loop: false); if (CustomSounds.Has("dronea") && CustomSounds.Has("tensiona")) { List<BinauralSource> list = new List<BinauralSource>(); List<float> list2 = new List<float>(); List<string> list3 = new List<string>(); string[] array = new string[3] { "dronea", "droneb", "dronec" }; foreach (string text in array) { AudioClip val = CustomSounds.Pick(text); if ((Object)(object)val == (Object)null) { continue; } for (int j = 0; j < 2; j++) { BinauralSource binauralSource = Spatial.Loop(val, text + j, ((Component)this).transform, 14f, 90f); if ((Object)(object)binauralSource != (Object)null) { list.Add(binauralSource); list3.Add(text); list2.Add((text == "dronea") ? 0.8f : ((text == "droneb") ? 0.7f : 0.55f)); } } } bed = list.ToArray(); bedWeight = list2.ToArray(); bedKeys = list3.ToArray(); Interior.Changed += RefreshBed; tensA = Spatial.Loop(CustomSounds.Pick("tensiona"), "tensionA", ((Component)this).transform, 3f, 40f); tensB = Spatial.Loop(CustomSounds.Pick("tensionb") ?? CustomSounds.Pick("tensiona"), "tensionB", ((Component)this).transform, 3f, 40f); spatialLayers = bed.Length != 0 && (Object)(object)tensA != (Object)null; Plugin.Log.LogInfo((object)string.Format("Spatial layers: {0} bed emitters, tension {1}", bed.Length, ((Object)(object)tensA != (Object)null) ? "yes" : "no")); } if (!spatialLayers) { drone.Play(); tension.Play(); } ignored = Plugin.ParseIgnored(); ScheduleEvent(); ((Component)this).gameObject.AddComponent<ScareDirector>().Dread = this; built = true; Plugin.Log.LogInfo((object)$"Sounds ready after {Time.realtimeSinceStartup - synthStarted:0.0} s."); } catch (Exception ex) { Plugin.Log.LogError((object)("Failed to set up audio, the mod will stay silent: " + ex)); } } private AudioSource MakeSource(string name, AudioClip clip, bool loop) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("DA_" + name); val.transform.SetParent(((Component)this).transform, false); AudioSource obj = val.AddComponent<AudioSource>(); obj.clip = clip; obj.loop = loop; obj.playOnAwake = false; obj.spatialBlend = 0f; obj.volume = 0f; obj.priority = 40; obj.ignoreListenerPause = false; return obj; } private void Update() { //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_04ec: Unknown result type (might be due to invalid IL or missing references) //IL_04f4: Unknown result type (might be due to invalid IL or missing references) //IL_04fe: Unknown result type (might be due to invalid IL or missing references) //IL_0503: Unknown result type (might be due to invalid IL or missing references) //IL_0516: Unknown result type (might be due to invalid IL or missing references) //IL_051c: Unknown result type (might be due to invalid IL or missing references) if (synth != null && synth.IsCompleted) { FinishSetup(); } if (!built) { return; } float deltaTime = Time.deltaTime; if (Time.time >= nextScan) { nextScan = Time.time + 0.2f; try { Scan(); } catch (Exception ex) { targetThreat = 0f; hunted = false; active = false; nextScan = Time.time + 2f; Plugin.Log.LogDebug((object)("Scan failed: " + ex.Message)); } } float num = ((targetThreat > threat) ? 1.6f : 0.22f); threat = Mathf.MoveTowards(threat, targetThreat, num * deltaTime); float num2 = Plugin.MasterVolume.Value * (active ? 1f : 0f); float num3 = Mathf.Max(insideFactory ? Plugin.FacilityBaseDread.Value : 0f, Smooth(0.2f, 0.8f, threat)); float num4 = (Plugin.DroneEnabled.Value ? (num3 * Plugin.DroneVolume.Value * num2) : 0f); float num5 = Smooth(0.5f, 0.95f, threat); float num6 = (Plugin.TensionEnabled.Value ? (num5 * Plugin.TensionVolume.Value * num2) : 0f); if (spatialLayers) { UpdateSpatialLayers(deltaTime, num4, num6); } else { SetVol(drone, num4, deltaTime, 0.5f); drone.pitch = 1f - 0.1f * threat; SetVol(tension, num6, deltaTime, 0.6f); tension.pitch = 1f - 0.04f * threat; } if (Plugin.HeartbeatEnabled.Value && active && threat > 0.45f && Time.time >= nextBeat) { float num7 = Mathf.InverseLerp(0.45f, 1f, threat); heart.pitch = Mathf.Lerp(0.96f, 1.04f, num7); float num8 = Mathf.Lerp(0.25f, 0.85f, num7) * Plugin.HeartbeatVolume.Value * Plugin.MasterVolume.Value; AudioClip val = CustomSounds.Pick("heartbeat") ?? SoundBank.Heartbeat; Transform val2 = (((Object)(object)Player != (Object)null && (Object)(object)Player.gameplayCamera != (Object)null) ? ((Component)Player.gameplayCamera).transform : null); if ((Object)(object)val2 != (Object)null) { BinauralSource binauralSource = Spatial.Play(val, val2.position - val2.up * 0.35f + val2.forward * 0.05f, num8, 0.8f, 6f); if ((Object)(object)binauralSource != (Object)null) { ((Component)binauralSource).transform.SetParent(val2, true); ((Component)binauralSource).GetComponent<AudioSource>().pitch = heart.pitch; } } else { heart.PlayOneShot(val, num8); } nextBeat = Time.time + Mathf.Lerp(0.95f, 0.46f, num7); } threatHistoryTimer += deltaTime; if (threatHistoryTimer >= 1f) { threatOneSecondAgo = targetThreat; threatHistoryTimer = 0f; } bool flag = targetThreat - threatOneSecondAgo > 0.5f && targetThreat > 0.7f; if (Plugin.StingEnabled.Value && active && ((hunted && !wasHunted) || flag) && Time.time - lastSting > Plugin.StingCooldown.Value) { lastSting = Time.time; AudioClip val3 = CustomSounds.Pick("sting") ?? SoundBank.Stings[rng.Next(SoundBank.Stings.Length)]; float pitch = 0.92f + (float)rng.NextDouble() * 0.16f; float num9 = Plugin.StingVolume.Value * Plugin.MasterVolume.Value; Transform val4 = (((Object)(object)Player != (Object)null && (Object)(object)Player.gameplayCamera != (Object)null) ? ((Component)Player.gameplayCamera).transform : null); if ((Object)(object)val4 != (Object)null) { BinauralSource binauralSource2 = Spatial.Play(val3, val4.position + ThreatDir(val4) * 3.5f, num9, 4f, 40f); if ((Object)(object)binauralSource2 != (Object)null) { ((Component)binauralSource2).GetComponent<AudioSource>().pitch = pitch; } } else { sting.pitch = pitch; sting.PlayOneShot(val3, num9); } threatOneSecondAgo = targetThreat; } wasHunted = hunted; if (Plugin.EventsEnabled.Value && active && insideFactory && threat < 0.2f && Time.time >= nextEvent) { PlayEvent(); ScheduleEvent(); } else if (!insideFactory || threat >= 0.2f) { nextEvent = Mathf.Max(nextEvent, Time.time + 8f); } if (Plugin.DebugLogging.Value && Time.time >= nextDebug) { nextDebug = Time.time + 3f; Plugin.Log.LogInfo((object)$"threat={threat:0.00} target={targetThreat:0.00} hunted={hunted} inside={insideFactory} active={active}"); } } private void Scan() { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) active = false; insideFactory = false; hunted = false; targetThreat = 0f; bool flag = false; Player = null; GameNetworkManager instance = GameNetworkManager.Instance; StartOfRound instance2 = StartOfRound.Instance; RoundManager instance3 = RoundManager.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || (Object)(object)instance3 == (Object)null) { return; } PlayerControllerB localPlayerController = instance.localPlayerController; if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerControlled || localPlayerController.isPlayerDead || instance2.inShipPhase) { return; } active = true; Player = localPlayerController; Spatial.Dread.InsideFactory = localPlayerController.isInsideFactory; Spatial.Dread.OcclusionMask = instance2.collidersAndRoomMaskAndDefault; insideFactory = localPlayerController.isInsideFactory; Transform val = (((Object)(object)localPlayerController.gameplayCamera != (Object)null) ? ((Component)localPlayerController.gameplayCamera).transform : ((Component)localPlayerController).transform); Vector3 position = val.position; float value = Plugin.DetectionRange.Value; int collidersAndRoomMaskAndDefault = instance2.collidersAndRoomMaskAndDefault; float num = 0f; List<EnemyAI> spawnedEnemies = instance3.SpawnedEnemies; if (spawnedEnemies == null) { return; } float value2 = Plugin.MinPowerLevel.Value; string text = null; float num2 = 0f; bool flag2 = false; Vector3 threatPos = Vector3.zero; for (int i = 0; i < spawnedEnemies.Count; i++) { EnemyAI val2 = spawnedEnemies[i]; if ((Object)(object)val2 == (Object)null || val2.isEnemyDead || (Object)(object)val2.enemyType == (Object)null) { continue; } EnemyType enemyType = val2.enemyType; if (ignored.Contains(enemyType.enemyName) || (Plugin.IgnoreDaytimeCreatures.Value && enemyType.isDaytimeEnemy) || val2.isOutside == localPlayerController.isInsideFactory) { continue; } Vector3 val3 = ((Component)val2).transform.position + Vector3.up; float num3 = Vector3.Distance(position, val3); if (num3 > value) { continue; } bool flag3 = (Object)(object)val2.targetPlayer == (Object)(object)localPlayerController; bool flag4 = flag3 && val2.movingTowardsTargetPlayer; float powerLevel = enemyType.PowerLevel; if (powerLevel < value2 && !flag4) { continue; } float num4 = 1f - num3 / value; num4 *= num4; bool flag5 = !Physics.Linecast(position, val3, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1); if (!flag5 && num3 > value * 0.35f && !flag4) { continue; } bool num5 = flag5 && Vector3.Angle(val.forward, val3 - position) < 70f; float num6 = Mathf.Clamp01((powerLevel - 0.4f) / 2.6f); float num7 = num4 * (0.25f + 0.75f * num6) * (flag5 ? 1f : 0.5f); if (num5) { num7 += 0.1f * num4 * num6; } if (flag4) { num7 = Mathf.Max(num7, 0.55f + 0.45f * num4); if (powerLevel >= value2) { hunted = true; } } else if (flag3 && powerLevel >= value2) { num7 = Mathf.Max(num7, 0.3f + 0.3f * num4); } if (num7 > num) { num = num7; text = enemyType.enemyName; num2 = num3; flag2 = flag4; threatPos = val3; } if (powerLevel >= value2 && !flag4 && num3 < 12f && Vector3.Angle(val.forward, val3 - position) > 110f) { flag = true; } } ThreatBehindYou = flag && !localPlayerController.isInHangarShipRoom; if (localPlayerController.isInHangarShipRoom) { num *= 0.3f; } targetThreat = Mathf.Clamp01(num); HasThreatPos = text != null && num > 0.05f; if (HasThreatPos) { ThreatPos = threatPos; } if (targetThreat >= 0.35f && text != null && (text != lastSource || Time.time - lastSourceLog > 15f)) { lastSource = text; lastSourceLog = Time.time; Plugin.Log.LogInfo((object)string.Format("Tension {0:0.00} from {1} ({2:0} m{3})", targetThreat, text, num2, flag2 ? ", chasing you" : "")); } else if (targetThreat < 0.2f) { lastSource = null; } } private Vector3 ThreatDir(Transform cam) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (HasThreatPos) { Vector3 val = ThreatPos - cam.position; val.y *= 0.3f; if (((Vector3)(ref val)).sqrMagnitude > 0.01f) { lastThreatDir = ((Vector3)(ref val)).normalized; } } return lastThreatDir; } private void UpdateSpatialLayers(float dt, float droneTarget, float tenseTarget) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) Transform val = (((Object)(object)Player != (Object)null && (Object)(object)Player.gameplayCamera != (Object)null) ? ((Component)Player.gameplayCamera).transform : null); if ((Object)(object)val == (Object)null) { BinauralSource[] array = bed; foreach (BinauralSource binauralSource in array) { if ((Object)(object)binauralSource != (Object)null) { ((Component)binauralSource).GetComponent<AudioSource>().volume = 0f; } } if ((Object)(object)tensA != (Object)null) { ((Component)tensA).GetComponent<AudioSource>().volume = 0f; } if ((Object)(object)tensB != (Object)null) { ((Component)tensB).GetComponent<AudioSource>().volume = 0f; } return; } Vector3 position = val.position; bedAngle += dt * 1.2f; Vector3 val2 = ThreatDir(val); Vector3 val3 = default(Vector3); for (int j = 0; j < bed.Length; j++) { BinauralSource binauralSource2 = bed[j]; if (!((Object)(object)binauralSource2 == (Object)null)) { float num = (bedAngle + (float)j * (360f / (float)bed.Length)) * ((float)Math.PI / 180f); ((Vector3)(ref val3))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num)); if (j < 2 && HasThreatPos) { val3 = Vector3.Slerp(val3, (j == 0) ? val2 : (-val2), Mathf.Clamp01(threat * 1.2f)); } float num2 = 10f + 2f * (float)(j % 3); ((Component)binauralSource2).transform.position = position + val3 * num2 + Vector3.up * ((j % 2 == 0) ? 1.5f : 3.5f); AudioSource component = ((Component)binauralSource2).GetComponent<AudioSource>(); Spatial.Route(component); component.volume = Mathf.MoveTowards(component.volume, droneTarget * bedWeight[j], 0.5f * dt); component.pitch = 1f - 0.1f * threat; } } if ((Object)(object)tensA != (Object)null) { float num3 = (HasThreatPos ? Mathf.Clamp(Vector3.Distance(position, ThreatPos), 2.5f, 7f) : 4f); ((Component)tensA).transform.position = position + val2 * num3; AudioSource component2 = ((Component)tensA).GetComponent<AudioSource>(); Spatial.Route(component2); component2.volume = Mathf.MoveTowards(component2.volume, tenseTarget, 0.6f * dt); component2.pitch = 1f - 0.04f * threat; } if ((Object)(object)tensB != (Object)null) { Vector3 val4 = Quaternion.Euler(0f, 140f, 0f) * val2; ((Component)tensB).transform.position = position + val4 * 3f + Vector3.down * 0.3f; AudioSource component3 = ((Component)tensB).GetComponent<AudioSource>(); Spatial.Route(component3); component3.volume = Mathf.MoveTowards(component3.volume, tenseTarget * 0.8f, 0.6f * dt); component3.pitch = 1f - 0.04f * threat; } } private void RefreshBed() { if (bed == null || bedKeys == null) { return; } for (int i = 0; i < bed.Length; i++) { if (!((Object)(object)bed[i] == (Object)null)) { AudioSource component = ((Component)bed[i]).GetComponent<AudioSource>(); AudioClip val = CustomSounds.Pick(bedKeys[i]); if (!((Object)(object)val == (Object)null) && !((Object)(object)component.clip == (Object)(object)val)) { component.Stop(); component.clip = val; component.time = Random.Range(0f, Mathf.Max(0f, val.length - 0.5f)); component.Play(); } } } } private void ScheduleEvent() { float num = Mathf.Min(Plugin.EventsMinInterval.Value, Plugin.EventsMaxInterval.Value); float num2 = Mathf.Max(Plugin.EventsMinInterval.Value, Plugin.EventsMaxInterval.Value); nextEvent = Time.time + num + (float)rng.NextDouble() * (num2 - num); } private void PlayEvent() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00dd: 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) PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if (!((Object)(object)val == (Object)null)) { float num = (float)rng.NextDouble() * (float)Math.PI * 2f; float num2 = 12f + (float)rng.NextDouble() * 14f; Vector3 pos = ((Component)val).transform.position + new Vector3(Mathf.Cos(num) * num2, (float)rng.NextDouble() * 4f - 1f, Mathf.Sin(num) * num2); BinauralSource binauralSource = Spatial.Play(CustomSounds.Pick("groan") ?? SoundBank.Events[rng.Next(SoundBank.Events.Length)], pos, Plugin.EventsVolume.Value * Plugin.MasterVolume.Value, 6f, 55f); if ((Object)(object)binauralSource != (Object)null) { ((Component)binauralSource).GetComponent<AudioSource>().pitch = 0.88f + (float)rng.NextDouble() * 0.2f; } } } private static void SetVol(AudioSource s, float target, float dt, float speed) { s.volume = Mathf.MoveTowards(s.volume, target, speed * dt); } private static float Smooth(float a, float b, float x) { float num = Mathf.Clamp01((x - a) / (b - a)); return num * num * (3f - 2f * num); } } public class ScareDirector : MonoBehaviour { private float nextOutside = -1f; private bool outsideBusy; private bool outsideLowVis; private bool wasLowVis; private DoorLock[] doors; private float doorsFoundAt = -999f; private EnemyVent[] vents; private float ventsFoundAt = -999f; private bool hushing; private float hushRestore = 1f; private float hushSafetyAt; private HangarShipDoor shipDoor; private float nextKnock = -1f; internal DreadDirector Dread; private readonly Random rng = new Random(); private float nextUnease; private float nextJumpscare; private float nextBehindCue; private float insideSince = -1f; private bool busy; private bool wasActive; private readonly Dictionary<Light, bool> forcedOff = new Dictionary<Light, bool>(); private readonly List<string> recent = new List<string>(); private float nextSituationTick; private float situationCooldownUntil; private float doorDwell; private float darkDwell; private float steamDwell; private readonly HashSet<long> usedSpots = new HashSet<long>(); private readonly List<string> recentSit = new List<string>(); private string lastSituation = ""; private static readonly FieldRef<DoorLock, bool> doorOpened = Ref<DoorLock>("isDoorOpened"); private static readonly FieldRef<TerminalAccessibleObject, bool> bigDoorOpen = Ref<TerminalAccessibleObject>("isDoorOpen"); private static readonly FieldRef<SteamValveHazard, bool> valveBurst = Ref<SteamValveHazard>("valveHasBurst"); private static readonly FieldRef<SteamValveHazard, bool> valveFixed = Ref<SteamValveHazard>("valveHasBeenRepaired"); private TerminalAccessibleObject[] bigDoors; private SteamValveHazard[] valves; private Light[] sceneLights; private float sceneCachedAt = -999f; private LocalVolumetricFog[] fogVolumes; private float fogCachedAt = -999f; private float visCheckedAt = -999f; private bool lowVisCached; private string lastVisReason = ""; private float nextWeather = -1f; private readonly List<string> recentWeather = new List<string>(); private string lastWeatherLogged = ""; private int WallMask { get { if (!((Object)(object)StartOfRound.Instance != (Object)null)) { return -1; } return StartOfRound.Instance.collidersAndRoomMaskAndDefault; } } private IEnumerator HandleRattle(PlayerControllerB p) { DoorLock val = PickDoor(p, 1.5f, 7f); AudioClip val2 = CustomSounds.Pick("handle"); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { Plugin.Log.LogInfo((object)$"Event: someone tries the handle of a door {Vector3.Distance(((Component)val).transform.position, ((Component)p).transform.position):0}m away"); Spawn(val2, ((Component)val).transform.position + Vector3.up * 1f, Vol(1f), 1f, 1f, 25f, reverb: true); yield return (object)new WaitForSeconds(val2.length); } } private bool FindWallBeside(PlayerControllerB p, out Vector3 point) { //IL_0001: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_005b: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_00b0: 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_00b2: 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_00bb: 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) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) point = Vector3.zero; Transform val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); Vector3 forward = val.forward; forward.y = 0f; ((Vector3)(ref forward)).Normalize(); Vector3 val2 = Vector3.Cross(Vector3.up, forward); Vector3[] obj = new Vector3[7] { val2, -val2, -forward, default(Vector3), default(Vector3), default(Vector3), default(Vector3) }; Vector3 val3 = val2 - forward; obj[3] = ((Vector3)(ref val3)).normalized; val3 = -val2 - forward; obj[4] = ((Vector3)(ref val3)).normalized; val3 = val2 + forward; obj[5] = ((Vector3)(ref val3)).normalized; val3 = -val2 + forward; obj[6] = ((Vector3)(ref val3)).normalized; Vector3 val4 = val.position + Vector3.down * 0.3f; Vector3[] array = (Vector3[])(object)obj; RaycastHit val6 = default(RaycastHit); foreach (Vector3 val5 in array) { if (Physics.Raycast(val4, val5, ref val6, 2.6f, WallMask, (QueryTriggerInteraction)1) && Mathf.Abs(((RaycastHit)(ref val6)).normal.y) < 0.4f) { point = ((RaycastHit)(ref val6)).point + ((RaycastHit)(ref val6)).normal * 0.05f; return true; } } return false; } private IEnumerator WallScratch(PlayerControllerB p) { AudioClip val = CustomSounds.Pick("scratch"); if (!((Object)(object)val == (Object)null) && FindWallBeside(p, out var point)) { Plugin.Log.LogInfo((object)"Event: something scratches the wall beside you"); Spawn(val, point, Vol(0.95f), 1f, 0.8f, 15f, reverb: false); yield return (object)new WaitForSeconds(val.length); } } private IEnumerator Dragging(PlayerControllerB p) { AudioClip val = CustomSounds.Pick("drag"); if ((Object)(object)val == (Object)null) { yield break; } Vector3 position = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform).position; Vector3 val2 = Vector3.zero; bool flag = false; for (int i = 0; i < 8; i++) { if (flag) { break; } float num = R(0f, (float)Math.PI * 2f); float num2 = R(7f, 14f); val2 = ((Component)p).transform.position + new Vector3(Mathf.Cos(num) * num2, 0.2f, Mathf.Sin(num) * num2); flag = Physics.Linecast(position, val2 + Vector3.up * 0.5f, WallMask, (QueryTriggerInteraction)1); } Vector3 up = Vector3.up; Vector3 val3 = val2 - ((Component)p).transform.position; Vector3 drift = Vector3.Cross(up, ((Vector3)(ref val3)).normalized) * ((rng.Next(2) == 0) ? 0.45f : (-0.45f)); Plugin.Log.LogInfo((object)("Event: something heavy dragged " + (flag ? "in the next room" : "nearby"))); Spatial.Play(val, val2, Vol(1f), 2f, 35f, drift); yield return (object)new WaitForSeconds(val.length); } private IEnumerator Runner(PlayerControllerB p) { if ((Object)(object)StepClip(p) == (Object)null) { yield break; } Vector3 val = ((Component)p).transform.position + Vector3.up * 0.5f; Vector3 best = Vector3.zero; float num = 0f; Vector3 val2 = default(Vector3); RaycastHit val3 = default(RaycastHit); for (int i = 0; i < 12; i++) { float num2 = (float)i * (float)Math.PI / 6f; ((Vector3)(ref val2))..ctor(Mathf.Cos(num2), 0f, Mathf.Sin(num2)); float num3 = (Physics.Raycast(val, val2, ref val3, 30f, WallMask, (QueryTriggerInteraction)1) ? ((RaycastHit)(ref val3)).distance : 30f); if (num3 > num) { num = num3; best = val2; } } if (num < 12f) { yield break; } float num4 = Mathf.Min(num - 1f, 26f); float stop = 6f; float d = num4; Plugin.Log.LogInfo((object)$"Event: something sprints toward you from {num4:0}m"); float speed = R(6.5f, 8f); float interval = 0.27f; while (d > stop && (Object)(object)p != (Object)null && !p.isPlayerDead) { Vector3 val4 = ((Component)p).transform.position + best * d; Spawn(StepClip(p), val4 + Vector3.up * 0.1f, Vol(1f), 1f, 1.5f, 40f, reverb: true); yield return (object)new WaitForSeconds(interval * R(0.92f, 1.08f)); d -= speed * interval; } for (int k = 0; k < 2; k++) { if (!((Object)(object)p != (Object)null)) { break; } Spawn(StepClip(p), ((Component)p).transform.position + best * (stop - 0.4f * (float)k) + Vector3.up * 0.1f, Vol(0.8f), 1f, 1.5f, 40f, reverb: true); yield return (object)new WaitForSeconds(0.45f + 0.2f * (float)k); } yield return (object)new WaitForSeconds(4f); } private IEnumerator BulbPop(PlayerControllerB p) { AudioClip val = CustomSounds.Pick("bulb"); RoundManager instance = RoundManager.Instance; if ((Object)(object)val == (Object)null || (Object)(object)instance == (Object)null || instance.allPoweredLights == null) { yield break; } Light val2 = null; float num = 14f; foreach (Light allPoweredLight in instance.allPoweredLights) { if (!((Object)(object)allPoweredLight == (Object)null) && ((Behaviour)allPoweredLight).enabled && ((Component)allPoweredLight).gameObject.activeInHierarchy) { float num2 = Vector3.Distance(((Component)allPoweredLight).transform.position, ((Component)p).transform.position); if (num2 < num && num2 > 2f) { num = num2; val2 = allPoweredLight; } } } if (!((Object)(object)val2 == (Object)null)) { Plugin.Log.LogInfo((object)$"Event: a light {num:0}m away buzzes and pops"); Spawn(val, ((Component)val2).transform.position, Vol(0.9f), 1f, 1.5f, 30f, reverb: true); Light light = val2; float popAt = Time.time + 2.4f; while (Time.time < popAt && (Object)(object)light != (Object)null) { ((Behaviour)light).enabled = rng.Next(3) > 0; yield return (object)new WaitForSeconds(R(0.04f, 0.18f)); } if ((Object)(object)light != (Object)null) { ((Behaviour)light).enabled = false; } yield return (object)new WaitForSeconds(R(10f, 20f)); if ((Object)(object)light != (Object)null) { ((Behaviour)light).enabled = true; } } } private IEnumerator SteamBurst(PlayerControllerB p) { AudioClip val = CustomSounds.Pick("steam"); if (!((Object)(object)val == (Object)null)) { float num = R(0f, (float)Math.PI * 2f); float num2 = R(3f, 6f); float num3 = ((Interior.Theme == "manor") ? 0.4f : ((Interior.Theme == "mineshaft") ? 1.8f : 2.6f)); Vector3 pos = ((Component)p).transform.position + new Vector3(Mathf.Cos(num) * num2, num3, Mathf.Sin(num) * num2); Plugin.Log.LogInfo((object)((Interior.Theme == "manor") ? "Event: something topples over and glass shatters" : ((Interior.Theme == "mineshaft") ? "Event: rocks fall nearby" : "Event: a steam pipe bursts near you"))); Spawn(val, pos, Vol(0.9f), 1f, 1.5f, 35f, reverb: true); yield return (object)new WaitForSeconds(val.length); } } private IEnumerator CallOut(PlayerControllerB p, float minD, float maxD) { AudioClip val = CustomSounds.Pick("callout"); if (!((Object)(object)val == (Object)null)) { float num = R(0f, (float)Math.PI * 2f); float num2 = R(minD, maxD); Vector3 pos = ((Component)p).transform.position + new Vector3(Mathf.Cos(num) * num2, R(0.5f, 1.6f), Mathf.Sin(num) * num2); Plugin.Log.LogInfo((object)$"Event: a voice calls you from {num2:0}m away"); Spawn(val, pos, Vol(1.1f), 1f, 4f, 60f, reverb: false); yield return (object)new WaitForSeconds(val.length); } } private void OutsideHaunts(PlayerControllerB p) { if (!Plugin.OutsideEvents.Value) { return; } TimeOfDay instance = TimeOfDay.Instance; bool flag = Dread.Active && (Object)(object)p != (Object)null && !p.isInsideFactory && !p.isInHangarShipRoom && !p.isPlayerDead; outsideLowVis = flag && LowVisibility(p); float num = (outsideLowVis ? Mathf.Clamp(Plugin.LowVisibilityInterval.Value, 0.1f, 1f) : 1f); if (!flag || (Object)(object)instance == (Object)null || instance.normalizedTimeOfDay < (outsideLowVis ? 0.2f : 0.45f)) { if (!flag) { nextOutside = -1f; } wasLowVis = false; return; } if (nextOutside < 0f) { nextOutside = Time.time + R(40f, 100f) * num; wasLowVis = outsideLowVis; return; } if (outsideLowVis && !wasLowVis) { nextOutside = Mathf.Min(nextOutside, Time.time + R(20f, 50f)); } wasLowVis = outsideLowVis; if (!(Time.time < nextOutside) && !outsideBusy && !(Dread.Threat > 0.2f)) { float value = Plugin.OutsideMinInterval.Value; float b = Mathf.Max(value, Plugin.OutsideMaxInterval.Value); nextOutside = Time.time + R(value, b) * InsanityFactor() * num; ((MonoBehaviour)this).StartCoroutine(OutsideEvent(p)); } } private IEnumerator OutsideEvent(PlayerControllerB p) { outsideBusy = true; if (CustomSounds.Has("brush") && (rng.Next(3) > 0 || !CustomSounds.Has("callout"))) { float num = R(0f, (float)Math.PI * 2f); Vector3 dir = new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)); AudioClip val = CustomSounds.Pick("brush"); Plugin.Log.LogInfo((object)"Event (outside): something moves through the brush near you"); Spawn(val, ((Component)p).transform.position + dir * (outsideLowVis ? R(7f, 11f) : R(11f, 16f)) + Vector3.up * 0.4f, Vol(1f), 1f, 3f, 45f, reverb: false); yield return (object)new WaitForSeconds(val.length + R(6f, 14f)); if ((Object)(object)p != (Object)null && !p.isInsideFactory && !p.isInHangarShipRoom && rng.Next(2) == 0) { Vector3 val2 = Quaternion.Euler(0f, R(-50f, 50f), 0f) * dir; Spawn(CustomSounds.Pick("brush"), ((Component)p).transform.position + val2 * (outsideLowVis ? R(3.5f, 5.5f) : R(5f, 8f)) + Vector3.up * 0.4f, Vol(1f), 1f, 3f, 45f, reverb: false); } } else { yield return outsideLowVis ? CallOut(p, 12f, 20f) : CallOut(p, 20f, 32f); } outsideBusy = false; } private IEnumerator Circling(PlayerControllerB p, Vector3 doorOutside) { //IL_0015: 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) string steps = (CustomSounds.Has("stepg") ? "stepg" : (CustomSounds.Has("steps") ? "steps" : "stepc")); if (!CustomSounds.Has(steps)) { yield break; } Plugin.Log.LogInfo((object)"Something is walking around the outside of the ship"); Vector3 centre = ((Component)p).transform.position; Vector3 val = doorOutside - centre; val.y = 0f; float r = Mathf.Clamp(((Vector3)(ref val)).magnitude + 1.5f, 6f, 10f); float a0 = Mathf.Atan2(val.z, val.x); float dirSign = ((rng.Next(2) == 0) ? 1f : (-1f)); int n = rng.Next(14, 24); Vector3 pos = default(Vector3); for (int i = 0; i < n; i++) { if (!((Object)(object)p != (Object)null)) { break; } if (!p.isInHangarShipRoom) { break; } float num = a0 + dirSign * (float)i * (0.7f / r); ((Vector3)(ref pos))..ctor(centre.x + Mathf.Cos(num) * r, doorOutside.y, centre.z + Mathf.Sin(num) * r); Spawn(CustomSounds.Pick(steps), pos, Vol(0.9f), 1f, 1.5f, 30f, reverb: false); yield return (object)new WaitForSeconds(R(0.55f, 0.75f) * ((i > n - 4) ? 1.6f : 1f)); } } private IEnumerator Follower(PlayerControllerB p) { if ((Object)(object)StepClip(p) == (Object)null) { yield break; } List<KeyValuePair<float, Vector3>> hist = new List<KeyValuePair<float, Vector3>>(); float end = Time.time + R(12f, 18f); float nextStep = 0f; float smooth = 0f; float stoppedAt = -1f; int steps = 0; bool wasMoving = false; Vector3 last = ((Component)p).transform.position; Vector3 moveDir = -((Component)p).transform.forward; while (Time.time < end && (Object)(object)p != (Object)null && !p.isPlayerDead && p.isInsideFactory) { float num = Mathf.Max(Time.deltaTime, 0.0001f); Vector3 position = ((Component)p).transform.position; hist.Add(new KeyValuePair<float, Vector3>(Time.time, position)); while (hist.Count > 0 && Time.time - hist[0].Key > 3f) { hist.RemoveAt(0); } Vector3 val = (position - last) / num; val.y = 0f; last = position; smooth = Mathf.Lerp(smooth, ((Vector3)(ref val)).magnitude, Mathf.Clamp01(8f * num)); if (((Vector3)(ref val)).sqrMagnitude > 0.5f) { moveDir = ((Vector3)(ref val)).normalized; } bool flag = smooth > 1.1f && !p.isClimbingLadder && !p.isFallingFromJump; if (flag) { stoppedAt = -1f; float num2 = (p.isSprinting ? 0.33f : (p.isCrouching ? 0.75f : 0.5f)); if (Time.time >= nextStep) { nextStep = Time.time + num2 * R(0.97f, 1.1f); Vector3 at = PathPoint(hist, 1.1f, position, moveDir); FollowStep(p, at, p.isCrouching ? 0.35f : (p.isSprinting ? 0.75f : 0.55f), 0.12f); steps++; } } else if (wasMoving) { stoppedAt = Time.time; } if (!flag && stoppedAt > 0f && steps >= 4 && Time.time - stoppedAt > 0.5f) { FollowStep(p, position - moveDir * 2.2f, 0.75f, 0f); Plugin.Log.LogInfo((object)("Follower stopped behind you after " + steps + " steps")); break; } wasMoving = flag; yield return null; } } private static Vector3 PathPoint(List<KeyValuePair<float, Vector3>> hist, float lag, Vector3 cur, Vector3 moveDir) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_005b: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_0084: 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_0073: 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) //IL_007e: 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) float num = Time.time - lag; Vector3 val = ((hist.Count > 0) ? hist[0].Value : cur); for (int num2 = hist.Count - 1; num2 >= 0; num2--) { if (hist[num2].Key <= num) { val = hist[num2].Value; break; } } Vector3 val2 = val - cur; if (((Vector3)(ref val2)).sqrMagnitude < 6.25f) { val = cur - moveDir * 2.8f; } return val; } private void FollowStep(PlayerControllerB p, Vector3 at, float vol, float delay) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) AudioClip clip = StepClip(p); if ((Object)(object)clip == (Object)null) { return; } if (delay > 0f) { ((MonoBehaviour)this).StartCoroutine(Delayed(delay, delegate { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) Spawn(clip, at + Vector3.up * 0.1f, Vol(vol), 1f, 1f, 25f, reverb: true); })); } else { Spawn(clip, at + Vector3.up * 0.1f, Vol(vol), 1f, 1f, 25f, reverb: true); } } private AudioClip StepClip(PlayerControllerB p) { StartOfRound instance = StartOfRound.Instance; string text = ""; int num = -1; if ((Object)(object)instance != (Object)null && instance.footstepSurfaces != null && instance.footstepSurfaces.Length != 0) { num = Mathf.Clamp(p.currentFootstepSurfaceIndex, 0, instance.footstepSurfaces.Length - 1); text = (instance.footstepSurfaces[num].surfaceTag ?? "").ToLowerInvariant(); } string text2 = ((text.Contains("metal") || text.Contains("catwalk") || text.Contains("grate")) ? "stepm" : (text.Contains("wood") ? "stepw" : ((text.Contains("carpet") || text.Contains("rug")) ? "steps" : ((text.Contains("grass") || text.Contains("snow") || text.Contains("dirt") || text.Contains("gravel") || text.Contains("rock") || text.Contains("sand") || text.Contains("mud") || text.Contains("puddle")) ? "stepg" : "stepc")))); AudioClip val = CustomSounds.Pick(text2) ?? ((text2 == "stepg") ? CustomSounds.Pick("steps") : null) ?? CustomSounds.Pick("stepc"); if ((Object)(object)val != (Object)null) { return val; } if (num < 0) { return null; } AudioClip[] clips = instance.footstepSurfaces[num].clips; if (clips == null || clips.Length == 0) { return null; } return Pick(clips); } private IEnumerator Delayed(float s, Action a) { yield return (object)new WaitForSeconds(s); try { a(); } catch (Exception ex) { Plugin.Log.LogDebug((object)("Delayed sound failed: " + ex.Message)); } } private DoorLock PickDoor(PlayerControllerB p, float min, float max) { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: 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_00d2: Unknown result type (might be due to invalid IL or missing references) if (doors == null || Time.time - doorsFoundAt > 45f) { doors = Object.FindObjectsOfType<DoorLock>(); doorsFoundAt = Time.time; } Transform val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); List<DoorLock> list = new List<DoorLock>(); List<DoorLock> list2 = new List<DoorLock>(); DoorLock[] array = doors; foreach (DoorLock val2 in array) { if ((Object)(object)val2 == (Object)null || !((Behaviour)val2).isActiveAndEnabled) { continue; } Vector3 val3 = ((Component)val2).transform.position - val.position; if (Mathf.Abs(val3.y) > 5f) { continue; } float magnitude = ((Vector3)(ref val3)).magnitude; if (!(magnitude < min) && !(magnitude > max)) { if (Vector3.Dot(val.forward, val3 / magnitude) < 0.2f) { list.Add(val2); } else { list2.Add(val2); } } } List<DoorLock> list3 = ((list.Count > 0) ? list : list2); if (list3.Count != 0) { return list3[rng.Next(list3.Count)]; } return null; } private static AnimatedObjectTrigger DoorAnim(DoorLock d) { AnimatedObjectTrigger val = ((Component)d).GetComponent<AnimatedObjectTrigger>(); if ((Object)(object)val == (Object)null) { val = ((Component)d).GetComponentInParent<AnimatedObjectTrigger>(); } if ((Object)(object)val == (Object)null) { val = ((Component)d).GetComponentInChildren<AnimatedObjectTrigger>(); } return val; } private IEnumerator DoorHaunt(PlayerControllerB p) { DoorLock val = PickDoor(p, 5f, 24f); if ((Object)(object)val == (Object)null) { yield break; } Vector3 pos = ((Component)val).transform.position + Vector3.up * 1.2f; AnimatedObjectTrigger val2 = DoorAnim(val); AudioClip val3 = (((Object)(object)val2 != (Object)null && val2.boolTrueAudios != null && val2.boolTrueAudios.Length != 0) ? Pick(val2.boolTrueAudios) : null); AudioClip shut = (((Object)(object)val2 != (Object)null && val2.boolFalseAudios != null && val2.boolFalseAudios.Length != 0) ? Pick(val2.boolFalseAudios) : null); StartOfRound instance = StartOfRound.Instance; AudioClip val4 = CustomSounds.Pick("creak"); if ((Object)(object)val4 == (Object)null && (Object)(object)instance != (Object)null && instance.creakOpenDoorMetal != null && instance.creakOpenDoorMetal.Length != 0) { val4 = Pick(instance.creakOpenDoorMetal); } shut = CustomSounds.Pick("slam") ?? shut; if ((Object)(object)shut == (Object)null && (Object)(object)instance != (Object)null && instance.shutDoorMetal != null && instance.shutDoorMetal.Length != 0) { shut = Pick(instance.shutDoorMetal); } val3 = CustomSounds.Pick("creak") ?? val3; AudioClip val5 = CustomSounds.Pick("lockpick"); Plugin.Log.LogInfo((object)$"Door haunt {Vector3.Distance(((Component)p).transform.position, pos):0}m away (real door sounds: {(Object)(object)val3 != (Object)null}/{(Object)(object)shut != (Object)null})"); int num = rng.Next(3); if (num == 2 && (Object)(object)val5 != (Object)null) { Spawn(val5, pos, Vol(1f), 1f, 1.5f, 25f, reverb: true); } else if (num == 2 && (Object)(object)GameSounds.LockPick != (Object)null) { Spawn(GameSounds.LockPick, pos, Vol(0.85f), 1f, 1.5f, 30f, reverb: true); yield return (object)new WaitForSeconds(Mathf.Min(GameSounds.LockPick.length, R(3.5f, 6f))); if ((Object)(object)GameSounds.Unlock != (Object)null && rng.Next(2) == 0) { Spawn(GameSounds.Unlock, pos, Vol(0.9f), 1f, 1.5f, 30f, reverb: true); } } else if (num == 0 && (Object)(object)val4 != (Object)null) { Spawn(val4, pos, Vol(0.9f), 1f, 1.5f, 35f, reverb: true); yield return (object)new WaitForSeconds(val4.length - R(0.6f, 1.2f)); if ((Object)(object)shut != (Object)null && rng.Next(2) == 0) { Spawn(shut, pos, Vol(1f), 1f, 1.5f, 35f, reverb: true); } } else if ((Object)(object)val3 != (Object)null && (Object)(object)shut != (Object)null) { Spawn(val3, pos, Vol(0.9f), 1f, 1.5f, 35f, reverb: true); yield return (object)new WaitForSeconds(R(2.2f, 3.5f)); Spawn(shut, pos, Vol(0.9f), 1f, 1.5f, 35f, reverb: true); } else if ((Object)(object)val4 != (Object)null) { Spawn(val4, pos, Vol(0.9f), 1f, 1.5f, 35f, reverb: true); } else if ((Object)(object)shut != (Object)null) { Spawn(shut, pos, Vol(1f), 1f, 1.5f, 35f, reverb: true); } } private EnemyVent PickVent(PlayerControllerB p, float min, float max) { //IL_007b: 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) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if (vents == null || Time.time - ventsFoundAt > 45f) { vents = Object.FindObjectsOfType<EnemyVent>(); ventsFoundAt = Time.time; } List<EnemyVent> list = new List<EnemyVent>(); EnemyVent[] array = vents; foreach (EnemyVent val in array) { if (!((Object)(object)val == (Object)null) && !val.occupied && (!((Object)(object)val.ventAudio != (Object)null) || !val.ventAudio.isPlaying)) { float num = Vector3.Distance(((Component)val).transform.position, ((Component)p).transform.position); if (num >= min && num <= max && Mathf.Abs(((Component)val).transform.position.y - ((Component)p).transform.position.y) < 6f) { list.Add(val); } } } if (list.Count != 0) { return list[rng.Next(list.Count)]; } return null; } private void CeilingCrawl(PlayerControllerB p) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014c: 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) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) AudioClip obj = CustomSounds.Pick("crawl"); AudioClip val = (((Object)(object)obj == (Object)null) ? GameSounds.VentCrawl : null); if (obj == null) { obj = val; } AudioClip val2 = obj; if (!((Object)(object)val2 == (Object)null)) { EnemyVent val3 = PickVent(p, 4f, 20f); if ((Object)(object)val3 != (Object)null && rng.Next(10) < 4) { Plugin.Log.LogInfo((object)$"Crawling inside a real vent {Vector3.Distance(((Component)val3).transform.position, ((Component)p).transform.position):0}m away"); Spatial.Play(val2, ((Component)val3).transform.position, Vol(1f), 1.5f, 30f, default(Vector3), ((Object)(object)val != (Object)null) ? R(5f, 8f) : 0f, (Object)(object)val != (Object)null); return; } Plugin.Log.LogInfo((object)"Something crawls through the ceiling over you"); Transform obj2 = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); float num = R(0f, (float)Math.PI * 2f); Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num)); Vector3 val5 = Vector3.Cross(Vector3.up, val4) * R(-1.5f, 1.5f); Vector3 val6 = obj2.position + Vector3.up * 2.4f + val4 * 5f + val5; Vector3 val7 = obj2.position + Vector3.up * 2.4f - val4 * 5f - val5; float num2 = (((Object)(object)val != (Object)null) ? Mathf.Min(val2.length, 7f) : val2.length); Spatial.Play(val2, val6, Vol(0.95f), 1f, 25f, (val7 - val6) / num2, ((Object)(object)val != (Object)null) ? num2 : 0f, (Object)(object)val != (Object)null); } } private void MusicBox(PlayerControllerB p) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_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) //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) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) AudioClip val = CustomSounds.Pick("musicbox"); if (!((Object)(object)val == (Object)null)) { DoorLock val2 = PickDoor(p, 10f, 26f); Vector3 pos; if ((Object)(object)val2 != (Object)null) { pos = ((Component)val2).transform.position + Vector3.up * 0.8f; } else { float num = R(0f, (float)Math.PI * 2f); float num2 = R(12f, 20f); pos = ((Component)p).transform.position + new Vector3(Mathf.Cos(num) * num2, R(-0.5f, 1.5f), Mathf.Sin(num) * num2); } Spatial.Play(val, pos, Vol(0.7f), 2f); } } private static WalkieTalkie FindWalkie(PlayerControllerB p) { if ((Object)(object)p == (Object)null || p.ItemSlots == null) { return null; } GrabbableObject[] itemSlots = p.ItemSlots; foreach (GrabbableObject obj in itemSlots) { WalkieTalkie val = (WalkieTalkie)(object)((obj is WalkieTalkie) ? obj : null); if (val != null && ((GrabbableObject)val).isBeingUsed && (((GrabbableObject)val).insertedBattery == null || !((GrabbableObject)val).insertedBattery.empty)) { return val; } } return null; } private IEnumerator RadioCall(PlayerControllerB p) { WalkieTalkie w = FindWalkie(p); float v; if (!((Object)(object)w == (Object)null)) { List<AudioClip> list = new List<AudioClip>(); if ((Object)(object)GameSounds.GirlBreath != (Object)null) { list.Add(GameSounds.GirlBreath); } if ((Object)(object)GameSounds.DogBreath != (Object)null) { list.Add(GameSounds.DogBreath); } list.AddRange(GameSounds.BabyCry); list.AddRange(GameSounds.BugChitter); AudioClip clip = CustomSounds.Pick("radio"); bool live = (Object)(object)clip == (Object)null && list.Count > 0; if (live) { clip = Pick(list.ToArray()); } if (!((Object)(object)clip == (Object)null)) { AudioClip val = ((w.startTransmissionSFX != null && w.startTransmissionSFX.Length != 0) ? Pick(w.startTransmissionSFX) : null); AudioClip stop = ((w.stopTransmissionSFX != null && w.stopTransmissionSFX.Length != 0) ? Pick(w.stopTransmissionSFX) : null); v = Vol(0.7f); Plugin.Log.LogInfo((object)("Walkie call: " + ((Object)clip).name)); Out(val, filter: false, 0f); yield return (object)new WaitForSeconds(((Object)(object)val != (Object)null) ? (val.length * 0.8f) : 0.1f); float num = (live ? Mathf.Min(clip.length, R(2.5f, 4f)) : clip.length); Out(clip, live, live ? num : 0f); yield return (object)new WaitForSeconds(num + (live ? 0.6f : 0f)); Out(stop, filter: false, 0f); } } void Out(AudioClip c, bool filter, float maxDur) { //IL_0016: 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_0033: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)c == (Object)null)) { BinauralSource binauralSource = Spatial.Play(c, ((Component)w).transform.position, v, 0.8f, 12f, default(Vector3), maxDur, maxDur > 0f, null, filter); if ((Object)(object)binauralSource != (Object)null) { ((Component)binauralSource).transform.SetParent(((Component)w).transform, true); } } } } private IEnumerator Hush(PlayerControllerB p) { float prev = (hushRestore = AudioListener.volume); hushing = true; hushSafetyAt = Time.time + 8f; for (float t = 0f; t < 0.4f; t += Time.deltaTime) { AudioListener.volume = Mathf.Lerp(prev, prev * 0.03f, t / 0.4f); yield return null; } AudioListener.volume = prev * 0.03f; yield return (object)new WaitForSeconds(R(2.6f, 3.8f)); AudioListener.volume = prev; hushing = false; AudioClip val = CustomSounds.Pick("whisper") ?? CustomSounds.Pick("breath") ?? Pick(SoundBank.Breaths); WhisperUnlocatable(p, val, 1f); if (rng.Next(2) == 0) { yield return (object)new WaitForSeconds(Mathf.Min(1.4f, val.length * 0.6f)); PlayJumpHit(p); } } private void HushSafety() { if (hushing && Time.time > hushSafetyAt) { AudioListener.volume = hushRestore; hushing = false; } } private void HushRestoreNow() { if (hushing) { AudioListener.volume = hushRestore; hushing = false; } } private void ShipKnocks(PlayerControllerB p) { //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.ShipKnocks.Value || (!CustomSounds.Has("knock") && GameSounds.WallSlams.Count == 0)) { return; } bool flag = Dread.Active && (Object)(object)p != (Object)null && p.isInHangarShipRoom && !p.isInsideFactory; TimeOfDay instance = TimeOfDay.Instance; if (!flag || (Object)(object)instance == (Object)null || instance.normalizedTimeOfDay < 0.5f) { if (!flag) { nextKnock = -1f; } } else if (nextKnock < 0f) { nextKnock = Time.time + R(45f, 150f); } else { if (Time.time < nextKnock || busy) { return; } float value = Plugin.ShipKnockMinInterval.Value; float b = Mathf.Max(value, Plugin.ShipKnockMaxInterval.Value); nextKnock = Time.time + R(value, b); StartOfRound instance2 = StartOfRound.Instance; if ((Object)(object)instance2 == (Object)null || !instance2.shipHasLanded || !instance2.hangarDoorsClosed) { return; } Transform val = instance2.outsideDoorPosition; if ((Object)(object)val == (Object)null) { if ((Object)(object)shipDoor == (Object)null) { shipDoor = Object.FindObjectOfType<HangarShipDoor>(); } val = (((Object)(object)shipDoor != (Object)null) ? shipDoor.outsideDoorPoint : null); } if ((Object)(object)val == (Object)null) { return; } PlayerControllerB[] allPlayerScripts = instance2.allPlayerScripts; foreach (PlayerControllerB val2 in allPlayerScripts) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)p && val2.isPlayerControlled && !val2.isPlayerDead) { Vector3 val3 = ((Component)val2).transform.position - val.position; if (((Vector3)(ref val3)).sqrMagnitude < 36f) { return; } } } Vector3 pos = val.position + Vector3.up * 1.3f; if (Plugin.ShipCircling.Value && (CustomSounds.Has("stepg") || CustomSounds.Has("steps") || CustomSounds.Has("stepc")) && rng.Next(5) < 2) { ((MonoBehaviour)this).StartCoroutine(Circling(p, val.position)); } else { ((MonoBehaviour)this).StartCoroutine(Knocking(pos)); } } } private IEnumerator Knocking(Vector3 pos) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (!CustomSounds.Has("knock") && GameSounds.WallSlams.Count > 0) { Plugin.Log.LogInfo((object)"Something is slamming into the ship door"); int n = rng.Next(2, 5); for (int i = 0; i < n; i++) { Spawn(Pick(GameSounds.WallSlams.ToArray()), pos, Vol(R(0.75f, 1f)), 1f, 2f, 35f, reverb: true); yield return (object)new WaitForSeconds(R(1.1f, 2.2f)); } } else { Plugin.Log.LogInfo((object)"Something is knocking on the ship door"); Spawn(CustomSounds.Pick("knock"), pos, Vol(1f), 1f, 2f, 30f, reverb: true); } } private float InsanityFactor() { PlayerControllerB val = (((Object)(object)Dread != (Object)null) ? Dread.Player : null); if (!Plugin.InsanityScaling.Value || (Object)(object)val == (Object)null) { return 1f; } float num = Mathf.Clamp01(val.insanityLevel / Mathf.Max(1f, val.maxInsanityLevel)); return Mathf.Lerp(1f, 0.5f, num); } private void Start() { ScheduleUnease(first: true); ScheduleJumpscare(first: true); } private float R(float a, float b) { return a + (float)rng.NextDouble() * (b - a); } private void ScheduleUnease(bool first = false) { float value = Plugin.UneaseMinInterval.Value; float num = Mathf.Max(value, Plugin.UneaseMaxInterval.Value); nextUnease = Time.time + (first ? R(value * 0.5f, num * 0.6f) : (R(value, num) * InsanityFactor())); } private void ScheduleJumpscare(bool first = false) { float value = Plugin.JumpscareMinInterval.Value; float num = Mathf.Max(value, Plugin.JumpscareMaxInterval.Value); nextJumpscare = Time.time + (first ? R(value * 0.6f, num * 0.8f) : R(value, num)); } private void Update() { HushSafety(); if ((Object)(object)Dread == (Object)null || !Dread.Ready || !Plugin.ScaresEnabled.Value) { return; } PlayerControllerB player = Dread.Player; try { ShipKnocks(player); } catch (Exception ex) { Plugin.Log.LogDebug((object)("Ship knocks failed: " + ex.Message)); } try { OutsideHaunts(player); } catch (Exception ex2) { Plugin.Log.LogDebug((object)("Outside events failed: " + ex2.Message)); } try { WeatherHaunts(player); } catch (Exception ex3) { Plugin.Log.LogDebug((object)("Weather events failed: " + ex3.Message)); } bool num = Dread.Active && (Object)(object)player != (Object)null && player.isInsideFactory && !player.isInHangarShipRoom; Interior.Poll(); if (Dread.Active && !wasActive) { GameSounds.Build(); Spatial.Refresh(); ClearSituationMemory(); } wasActive = Dread.Active; if (!num) { insideSince = -1f; return; } if (insideSince < 0f) { insideSince = Time.time; } if (Plugin.BehindYouCue.Value && Dread.ThreatBehindYou && Time.time >= nextBehindCue) { nextBehindCue = Time.time + 40f; Play2D(SoundBank.Presence, 0.55f); } bool flag = Dread.Threat < 0.15f && Time.time - insideSince > 40f; if (busy || !flag) { return; } if (Time.time - insideSince > 20f) { try { if (Situations(player)) { return; } } catch (Exception ex4) { Plugin.Log.LogDebug((object)("Situations failed: " + ex4.Message)); } } if (Time.time >= nextJumpscare) { ScheduleJumpscare(); ScheduleUnease(); ((MonoBehaviour)this).StartCoroutine(Jumpscare(player)); } else if (Time.time >= nextUnease) { ScheduleUnease(); ((MonoBehaviour)this).StartCoroutine(Unease(player)); } } private IEnumerator Unease(PlayerControllerB p) { busy = true; List<string> options = new List<string>(); bool built = GameSounds.Built; Opt("steps", available: true, 3); Opt("skitter", built && GameSounds.SpiderSteps.Count > 0); Opt("girl", built && (Object)(object)GameSounds.GirlBreath != (Object)null, 3); Opt("springs", built && GameSounds.Springs.Count > 0, 3); Opt("thumper", built && GameSounds.ThumperRoars.Count > 0); Opt("chitter", built && GameSounds.BugChitter.Count > 0); Opt("baby", built && GameSounds.BabyCry.Count > 0); Opt("nutcracker", built && GameSounds.NutcrackerTurn.Count > 0); Opt("dog", built && (Object)(object)GameSounds.DogBreath != (Object)null, 1); Opt("flea", built && GameSounds.FleaShriek.Count > 0); Opt("jester", built && (Object)(object)GameSounds.JesterTheme != (Object)null); Opt("neck", built && (Object)(object)GameSounds.NeckCrack != (Object)null, 1); Opt("turret", built && (Object)(object)GameSounds.TurretDetect != (Object)null, 1); Opt("mine", built && (Object)(object)GameSounds.MinePress != (Object)null, 1); Opt("insanity", built && GameSounds.InsanityMusic.Count > 0, 1); Opt("whisper", CustomSounds.Has("whisper"), 4); Opt("distant", CustomSounds.Has("distant"), 3); Opt("breath", available: true, (!CustomSounds.Has("breath")) ? 1 : 2); StartOfRound instance = StartOfRound.Instance; Opt("follower", Plugin.Follower.Value && (CustomSounds.Has("stepc") || ((Object)(object)instance != (Object)null && instance.footstepSurfaces != null && instance.footstepSurfaces.Length != 0)), 3); Opt("door", Plugin.Doors.Value && (Object)(object)PickDoor(p, 5f, 24f) != (Object)null, 3); Opt("crawl", Plugin.CeilingCrawl.Value && ((Object)(object)GameSounds.VentCrawl != (Object)null || CustomSounds.Has("crawl"))); Opt("musicbox", Plugin.MusicBox.Value && CustomSounds.Has("musicbox"), 1); Opt("radio", Plugin.Radio.Value && (Object)(object)FindWalkie(p) != (Object)null, 3); Opt("handle", Plugin.HandleRattle.Value && CustomSounds.Has("handle") && (Object)(object)PickDoor(p, 1.5f, 7f) != (Object)null, 3); Opt("scratch", Plugin.WallScratch.Value && CustomSounds.Has("scratch") && FindWallBeside(p, out var _), 3); Opt("drag", Plugin.Dragging.Value && CustomSounds.Has("drag")); Opt("runner", Plugin.Runner.Value && (Object)(object)StepClip(p) != (Object)null); Opt("bulb", Plugin.LightBulb.Value && CustomSounds.Has("bulb")); Opt("steam", Plugin.SteamPipe.Value && CustomSounds.Has("steam"), 1); Opt("callout", Plugin.CallOut.Value && CustomSounds.Has("callout"), 3); if (options.Count == 0) { options.Add("steps"); } string text = options[rng.Next(options.Count)]; recent.Add(text); if (recent.Count > 4) { recent.RemoveAt(0); } Plugin.Log.LogInfo((object)("Fake-out: " + text)); switch (text) { case "steps": if (GameSounds.ButlerSteps.Count > 0) { yield return StepSequence(p, GameSounds.ButlerSteps, 6, 0.55f, 11f, 4f, 0.8f, overhead: false); } else { PlayBehind(p, Pick(SoundBank.StepsSlow), 0.85f, 5f, 0.6f); } break; case "skitter": yield return StepSequence(p, GameSounds.SpiderSteps, 10, 0.13f, 8f, 4f, 0.7f, overhead: true); break; case "girl": PlayBehind(p, GameSounds.GirlBreath, 0.8f, 1.6f, 0.4f, 6f); break; case "springs": PlayBehind(p, PickL(GameSounds.Springs), 0.9f, 6f, 0.5f); break; case "thumper": PlayAround(p, PickL(GameSounds.ThumperRoars), 0.8f, 22f); break; case "chitter": PlaySide(p, PickL(GameSounds.BugChitter), 0.8f, 7f); break; case "baby": PlayAround(p, PickL(GameSounds.BabyCry), 0.75f, 18f); break; case "nutcracker": PlayBehind(p, PickL(GameSounds.NutcrackerTurn), 0.9f, 7f, 0.5f); break; case "dog": PlayBehind(p, GameSounds.DogBreath, 0.7f, 4f, 0.5f, 5f); break; case "flea": PlayAbove(p, PickL(GameSounds.FleaShriek), 0.85f); break; case "jester": PlayAround(p, GameSounds.JesterTheme, 0.7f, 16f, R(2.5f, 4.5f), randomStart: true); break; case "neck": PlayAround(p, GameSounds.NeckCrack, 0.9f, 14f); break; case "turret": PlaySide(p, GameSounds.TurretDetect, 0.9f, 9f); break; case "mine": Spawn(GameSounds.MinePress, ((Component)p).transform.position + Vector3.down * 0.2f, Vol(1f), 0.6f, 1f, 8f, reverb: false); break; case "insanity": Play2D(PickL(GameSounds.InsanityMusic), 0.5f, 7f); break; case "handle": yield return HandleRattle(p); break; case "scratch": yield return WallScratch(p); break; case "drag": yield return Dragging(p); break; case "runner": yield return Runner(p); break; case "bulb": ((MonoBehaviour)this).StartCoroutine(BulbPop(p)); yield return (object)new WaitForSeconds(4f); break; case "steam": yield return SteamBurst(p); break; case "callout": yield return CallOut(p, 16f, 26f); break; case "follower": yield return Follower(p); break; case "door": yield return DoorHaunt(p); break; case "crawl": CeilingCrawl(p); yield return (object)new WaitForSeconds(6f); break; case "musicbox": MusicBox(p); yield return (object)new WaitForSeconds(10f); break; case "radio": yield return RadioCall(p); break; case "whisper": WhisperUnlocatable(p, CustomSounds.Pick("whisper"), 0.85f); break; case "distant": PlayAround(p, CustomSounds.Pick("distant"), 1f, 16f); break; default: PlayBehind(p, CustomSounds.Pick("breath") ?? Pick(SoundBank.Breaths), 0.8f, 1.3f, 0.4f); break; } yield return (object)new WaitForSeconds(5f); busy = false; void Opt(string name, bool available, int weight = 2) { if (available && !recent.Contains(name)) { for (int i = 0; i < weight; i++) { options.Add(name); } } } } private IEnumerator StepSequence(PlayerControllerB p, List<AudioClip> clips, int count, float interval, float startDist, float endDist, float vol, bool overhead) { Transform val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); Vector3 val2 = -val.forward; val2.y = 0f; ((Vector3)(ref val2)).Normalize(); Vector3 val3 = Vector3.Cross(Vector3.up, val2) * R(-0.4f, 0.4f); Vector3 drift = val2 + val3; Vector3 dir = ((Vector3)(ref drift)).normalized; Vector3 origin = val.position; for (int i = 0; i < count; i++) { float num = ((count <= 1) ? 1f : ((float)i / (float)(count - 1))); float num2 = Mathf.Lerp(startDist, endDist, num); Vector3 pos = origin + dir * num2 + (overhead ? (Vector3.up * 2.2f) : (Vector3.down * 1.4f)); ScareDirector scareDirector = this; AudioClip clip = PickL(clips); float vol2 = Vol(vol * Mathf.Lerp(0.6f, 1f, num)); drift = default(Vector3); scareDirector.Spawn(clip, pos, vol2, 1f, 1.5f, 30f, reverb: true, 0f, randomStart: false, drift); yield return (object)new WaitForSeconds(interval * R(0.85f, 1.15f)); } } private IEnumerator Jumpscare(PlayerControllerB p) { busy = true; int num = rng.Next(Plugin.Hush.Value ? 4 : 3); bool lights = Plugin.FlickerLights.Value; Plugin.Log.LogInfo((object)("Jumpscare #" + num)); switch (num) { case 0: if (lights) { yield return Flicker(p, 0.5f); } if (CustomSounds.Has("powerdown")) { PlayAbove(p, CustomSounds.Pick("powerdown"), 1f); } else if ((Object)(object)GameSounds.PowerOff != (Object)null) { Play2D(GameSounds.PowerOff, 0.9f); } if (lights) { BlackoutStart(p); } yield return (object)new WaitForSeconds(R(1f, 2.2f)); PlayJumpHit(p); yield return (object)new WaitForSeconds(1.6f); if (lights) { BlackoutEnd(); yield return Flicker(p, 0.35f); } break; case 1: if ((Object)(object)GameSounds.PowerOff != (Object)null) { Play2D(GameSounds.PowerOff, 0.8f); } if (lights) { BlackoutStart(p); yield return (object)new WaitForSeconds(R(1.8f, 2.6f)); BlackoutEnd(); } yield return (object)new WaitForSeconds(R(0.5f, 1f)); if ((Object)(object)GameSounds.GirlBreath != (Object)null && (rng.Next(2) == 0 || !CustomSounds.Has("breath"))) { PlayBehind(p, GameSounds.GirlBreath, 1f, 0.9f, 0.2f, 4f); } else { PlayBehind(p, CustomSounds.Pick("breath") ?? Pick(SoundBank.Breaths), 1f, 0.9f, 0.25f); } yield return (object)new WaitForSeconds(2.2f); if (GameSounds.Springs.Count > 0) { PlayBehind(p, PickL(GameSounds.Springs), 1f, 2f, 0.3f); } break; case 3: yield return Hush(p); break; default: if (GameSounds.ButlerSteps.Count > 0) { yield return StepSequence(p, GameSounds.ButlerSteps, 10, 0.2f, 14f, 1.2f, 1f, overhead: false); } else { AudioClip val = Pick(SoundBank.StepsRush); PlayBehind(p, val, 1f, 6f, 0.7f); yield return (object)new WaitForSeconds(Mathf.Max(0.5f, val.length - 0.95f)); } if (lights) { BlackoutStart(p); } PlayJumpHit(p); yield return (object)new WaitForSeconds(1.2f); if (lights) { BlackoutEnd(); yield return Flicker(p, 0.3f); } break; } yield return (object)new WaitForSeconds(4f); busy = false; } private void PlayJumpHit(PlayerControllerB p) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0070: 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_0081: 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_0092: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) if (CustomSounds.Has("jump") && (GameSounds.JumpHits.Count == 0 || rng.Next(3) > 0)) { Transform val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); Vector3 val2 = ((rng.Next(2) == 0) ? val.right : (-val.right)); Spatial.Play(CustomSounds.Pick("jump"), val.position + val2 * 0.55f - val.forward * 0.35f, Vol(1f), 0.8f, 15f); PlayBehind(p, CustomSounds.Pick("bang") ?? Pick(SoundBank.Bangs), 0.6f, 2f, 0.6f); } else if (GameSounds.JumpHits.Count > 0) { PlayBehind(p, PickL(GameSounds.JumpHits), 1f, 1.2f, 0.6f, 2.2f); Play2D(CustomSounds.Pick("bang") ?? Pick(SoundBank.Bangs), 0.55f); } else { Play2D(Pick(SoundBank.JumpHits), 1f); } } private IEnumerator Flicker(PlayerControllerB p, float duration) { float end = Time.time + duration; while (Time.time < end) { BlackoutStart(p); yield return (object)new WaitForSeconds(R(0.04f, 0.12f)); BlackoutEnd(); yield return (object)new WaitForSeconds(R(0.03f, 0.1f)); } } private void BlackoutStart(PlayerControllerB p) { //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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0064: Unknown result type (might be due to invalid IL or missing references) try { Vector3 position = ((Component)p).transform.position; RoundManager instance = RoundManager.Instance; if ((Object)(object)instance != (Object)null && instance.allPoweredLights != null) { foreach (Light allPoweredLight in instance.allPoweredLights) { if ((Object)(object)allPoweredLight != (Object)null && !forcedOff.ContainsKey(allPoweredLight)) { Vector3 val = ((Component)allPoweredLight).transform.position - position; if (((Vector3)(ref val)).sqrMagnitude < 900f) { forcedOff[allPoweredLight] = ((Behaviour)allPoweredLight).enabled; } } } } AddLight(p.helmetLight); GrabbableObject[] itemSlots = p.ItemSlots; foreach (GrabbableObject obj in itemSlots) { FlashlightItem val2 = (FlashlightItem)(object)((obj is FlashlightItem) ? obj : null); if (val2 != null) { AddLight(val2.flashlightBulb); AddLight(val2.flashlightBulbGlow); } } } catch (Exception ex) { Plugin.Log.LogDebug((object)("Blackout failed: " + ex.Message)); } } private void AddLight(Light l) { if ((Object)(object)l != (Object)null && !forcedOff.ContainsKey(l)) { forcedOff[l] = ((Behaviour)l).enabled; } } private void BlackoutEnd() { foreach (KeyValuePair<Light, bool> item in forcedOff) { if ((Object)(object)item.Key != (Object)null) { ((Behaviour)item.Key).enabled = item.Value; } } forcedOff.Clear(); } private void LateUpdate() { if (forcedOff.Count == 0) { return; } foreach (KeyValuePair<Light, bool> item in forcedOff) { if ((Object)(object)item.Key != (Object)null) { ((Behaviour)item.Key).enabled = false; } } } private void OnDisable() { BlackoutEnd(); HushRestoreNow(); } private AudioClip Pick(AudioClip[] arr) { return arr[rng.Next(arr.Length)]; } private AudioClip PickL(List<AudioClip> l) { if (l.Count != 0) { return l[rng.Next(l.Count)]; } return null; } private float Vol(float v) { return v * Plugin.ScareVolume.Value * Plugin.MasterVolume.Value; } private void Play2D(AudioClip clip, float vol, float maxDuration = 0f) { //IL_002c: 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_004c: 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) Spawn(clip, ((Object)(object)Dread.Player != (Object)null) ? ((Component)Dread.Player).transform.position : Vector3.zero, Vol(vol), 0f, 1f, 10f, reverb: false, maxDuration); } private void PlayBehind(PlayerControllerB p, AudioClip clip, float vol, float dist, float sideJitter, float maxDuration = 0f) { //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) //IL_0040: 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) //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_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_0062: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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) Transform obj = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); Vector3 val = -obj.forward; val.y = 0f; ((Vector3)(ref val)).Normalize(); Vector3 val2 = Vector3.Cross(Vector3.up, val) * R(0f - sideJitter, sideJitter); Vector3 position = obj.position; Vector3 drift = val + val2; Vector3 pos = position + ((Vector3)(ref drift)).normalized * dist + Vector3.down * 0.4f; float vol2 = Vol(vol); drift = default(Vector3); Spawn(clip, pos, vol2, 1f, 1f, 30f, reverb: true, maxDuration, randomStart: false, drift); } private void PlaySide(PlayerControllerB p, AudioClip clip, float vol, float dist) { //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_0052: 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) //IL_004b: 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) //IL_005e: 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_0068: 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) //IL_0073: 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) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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) Transform val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); Vector3 right = val.right; right.y = 0f; ((Vector3)(ref right)).Normalize(); Vector3 val2 = ((rng.Next(2) == 0) ? right : (-right)) - val.forward * 0.4f; Spawn(clip, val.position + ((Vector3)(ref val2)).normalized * dist, Vol(vol), 1f, 1.5f, 30f, reverb: true); } private void PlayAbove(PlayerControllerB p, AudioClip clip, float vol) { //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_002d: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_0068: 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_0092: Unknown result type (might be due to invalid IL or missing references) Transform val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform : ((Component)p).transform); Vector3 val2 = -val.forward; val2.y = 0f; ((Vector3)(ref val2)).Normalize(); Spawn(clip, val.position + Vector3.up * 2.5f + val2 * 1.5f, Vol(vol), 1f, 1f, 20f, reverb: true); } private void PlayAround(PlayerControllerB p, AudioClip clip, float vol, float dist, float maxDuration = 0f, bool randomStart = false) { //IL_0017: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) float num = R(0f, (float)Math.PI * 2f); Vector3 pos = ((Component)p).transform.position + new Vector3(Mathf.Cos(num) * dist, R(-1f, 3f), Mathf.Sin(num) * dist); Vector3 drift = new Vector3(0f - Mathf.Sin(num), 0f, Mathf.Cos(num)) * ((rng.Next(2) == 0) ? 1f : (-1f)) * R(0.8f, 1.8f); Spawn(clip, pos, Vol(vol), 1f, 5f, 60f, reverb: true, maxDuration, randomStart, drift); } private void Spawn(AudioClip clip, Vector3 pos, float vol, float spatial, float minD, float maxD, bool reverb, float maxDuration = 0f, bool randomStart = false, Vector3 drift = default(Vector3)) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)clip == (Object)null) { return; } if (spatial > 0.5f) { Spatial.Play(clip, pos, vol, Mathf.Max(0.8f, minD), maxD, drift, maxDuration, randomStart); return; } GameObject val = new GameObject("DA_Scare"); val.transform.position = pos; AudioSource val2 = val.AddComponent<AudioSource>(); val2.clip = clip; val2.spatialBlend = spatial; val2.rolloffMode = (AudioRolloffMode)1; val2.minDistance = minD; val2.maxDistance = maxD; val2.dopplerLevel = 0f; val2.volume = Mathf.Clamp01(vol); val2.priority = 30; if (reverb && (Object)(object)Dread.Player != (Object)null && Dread.Player.isInsideFactory) { val.AddComponent<AudioReverbFilter>().reverbPreset = (AudioReverbPreset)14; } float length = clip.length; if (randomStart && maxDuration > 0f && clip.length > maxDuration + 1f) { val2.time = R(0f, clip.length - maxDuration - 0.5f); } val2.Play(); if (maxDuration > 0f && maxDuration < length) { ((MonoBehaviour)this).StartCoroutine(FadeOutAfter(val2, maxDuration)); Object.Destroy((Object)(object)val, maxDuration + 1.5f); } else { Object.Destroy((Object)(object)val, length + 1.5f); } } private IEnumerator FadeOutAfter(AudioSource src, float after) { yield return (object)new WaitForSeconds(after); float v0 = (((Object)(object)src != (Object)null) ? src.volume : 0f); for (float t = 0f; t < 0.8f; t += Time.deltaTime) { if (!((Object)(object)src != (Object)null)) { break; } src.volume = Mathf.Lerp(v0, 0f, t / 0.8f); yield return null; } if ((Object)(object)src != (Object)null) { src.Stop(); } } private static Fiel