using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Dissonance; using Dissonance.Audio.Playback; using GameNetcodeStuff; using HarmonyLib; using InsanityMod.Managers; using InsanityMod.Network; using InsanityMod.Patches; using InsanityMod.Voice; using Microsoft.CodeAnalysis; using MrovLib.Events; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.SceneManagement; using UnityEngine.UI; using WeatherRegistry; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace InsanityMod { internal static class ModConfig { public static ConfigEntry Language { get; private set; } public static ConfigEntry InsanityRateInFacility { get; private set; } public static ConfigEntry InsanityDecayOutdoor { get; private set; } public static ConfigEntry NightOutdoorRate { get; private set; } public static ConfigEntry NightStartHour { get; private set; } public static ConfigEntry EclipseOutdoorRate { get; private set; } public static ConfigEntry ParanoiaOutdoorRate { get; private set; } public static ConfigEntry BloodNightMultiplier { get; private set; } public static ConfigEntry BloodNightSpawnWeight { get; private set; } public static ConfigEntry TunnelVisionThreshold { get; private set; } public static ConfigEntry TunnelVisionColor { get; private set; } public static ConfigEntry HideHudAtZero { get; private set; } public static ConfigEntry EnableHud { get; private set; } public static ConfigEntry MobVisibilityScale { get; private set; } public static ConfigEntry MobVisibilityRange { get; private set; } public static ConfigEntry TeammateBuffRate { get; private set; } public static ConfigEntry TeammateBuffRange { get; private set; } public static ConfigEntry LightBuffRate { get; private set; } public static ConfigEntry DeathWitnessSpike { get; private set; } public static ConfigEntry DeathWitnessRange { get; private set; } public static ConfigEntry GhostGirlBoostThreshold { get; private set; } public static ConfigEntry VoiceHauntThreshold { get; private set; } public static ConfigEntry LightProximityRange { get; private set; } public static ConfigEntry ApparatusSpike { get; private set; } public static ConfigEntry EnableMaskedTransform { get; private set; } public static ConfigEntry MaskedTransformOnlyDuringParanoia { get; private set; } public static ConfigEntry UnderwaterRate { get; private set; } public static ConfigEntry CompanyMoonDecayRate { get; private set; } public static ConfigEntry TZPInsanityDrainRate { get; private set; } public static ConfigEntry RateOnShipLightsOn { get; private set; } public static ConfigEntry RateOnShipLightsOff { get; private set; } public static void Initialize(ConfigFile cfg) { Language = cfg.Bind("General", "Language", "AUTO", "Display language. AUTO detects from system locale. Options: AUTO, EN, KO."); InsanityRateInFacility = cfg.Bind("Insanity", "InsanityRateInFacility", 0.167f, "Insanity gained per second inside the facility (baseline, ~10 min solo to 100%)."); InsanityDecayOutdoor = cfg.Bind("Insanity", "InsanityDecayOutdoor", 0.8f, "Insanity lost per second outdoors (daytime)."); NightOutdoorRate = cfg.Bind("Insanity", "NightOutdoorRate", 0.05f, "Insanity gained per second outdoors at night. Set to 0 to disable."); NightStartHour = cfg.Bind("Insanity", "NightStartHour", 19, "Game hour (0-23) at which night begins outdoors."); EclipseOutdoorRate = cfg.Bind("Insanity", "EclipseOutdoorRate", 0.1f, "Insanity gained per second outdoors during Eclipse weather."); ParanoiaOutdoorRate = cfg.Bind("Insanity", "ParanoiaOutdoorRate", 0.1f, "Insanity gained per second outdoors during Paranoia weather."); BloodNightMultiplier = cfg.Bind("Paranoia", "ParanoiaMultiplier", 1.2f, "Insanity rate multiplier when Paranoia weather is active."); BloodNightSpawnWeight = cfg.Bind("Paranoia", "ParanoiaSpawnWeight", 20, "Spawn weight for Paranoia weather (other weathers are 100, so ~3% per night at 20)."); TunnelVisionThreshold = cfg.Bind("VFX", "TunnelVisionThreshold", 80f, "Insanity % at which the tunnel-vision overlay starts."); TunnelVisionColor = cfg.Bind("VFX", "TunnelVisionColor", "#180202", "Tunnel vision overlay color (hex). Default is very dark red. Use #000000 for pure black."); HideHudAtZero = cfg.Bind("VFX", "HideHudAtZero", false, "If true, the insanity HUD ring is hidden while insanity is 0%."); EnableHud = cfg.Bind("VFX", "EnableHud", true, "Master switch for the insanity HUD ring. Set to false to disable it entirely (no canvas/sprite created)."); MobVisibilityScale = cfg.Bind("Reactions", "MobVisibilityScale", 1f, "Multiplier for insanity gained per second per visible enemy (per-type rates are scaled by this)."); MobVisibilityRange = cfg.Bind("Reactions", "MobVisibilityRange", 30f, "Max distance (m) at which a visible enemy contributes to insanity."); TeammateBuffRate = cfg.Bind("Reactions", "TeammateBuffRate", 0.15f, "Insanity-rate reduction per second when at least one living teammate is nearby."); TeammateBuffRange = cfg.Bind("Reactions", "TeammateBuffRange", 6f, "Max distance (m) for the teammate proximity buff."); LightBuffRate = cfg.Bind("Reactions", "LightBuffRate", 0.1f, "Insanity-rate reduction per second when player is illuminated (own flashlight on, or in ship)."); DeathWitnessSpike = cfg.Bind("Reactions", "DeathWitnessSpike", 25f, "Instant insanity gain when a teammate dies in your line of sight."); DeathWitnessRange = cfg.Bind("Reactions", "DeathWitnessRange", 40f, "Max distance (m) for the death witness check."); GhostGirlBoostThreshold = cfg.Bind("Reactions", "GhostGirlBoostThreshold", 80f, "Insanity % above which the host slightly raises Ghost Girl haunt chance (set high to disable)."); VoiceHauntThreshold = cfg.Bind("Reactions", "VoiceHauntThreshold", 70f, "Insanity % at which voice distortion + recorded teammate voice playback start."); LightProximityRange = cfg.Bind("Reactions", "LightProximityRange", 8f, "Max distance (m) to a facility light for the light proximity buff."); ApparatusSpike = cfg.Bind("Reactions", "ApparatusSpike", 15f, "Instant insanity gain when the apparatus is removed. Also disables insanity-reduction buffs inside the facility for the rest of the round."); EnableMaskedTransform = cfg.Bind("Reactions", "EnableMaskedTransform", true, "If true, reaching 100% insanity transforms the player into a Masked enemy."); MaskedTransformOnlyDuringParanoia = cfg.Bind("Reactions", "MaskedTransformOnlyDuringParanoia", true, "If true, the 100% Masked transformation only triggers when Paranoia weather is active."); UnderwaterRate = cfg.Bind("Reactions", "UnderwaterRate", 0.4f, "Insanity gained per second while the local player is underwater."); CompanyMoonDecayRate = cfg.Bind("Insanity", "CompanyMoonDecayRate", 0.5f, "Insanity reduced per second while on the Company building moon (71 Gordion)."); TZPInsanityDrainRate = cfg.Bind("Reactions", "TZPInsanityDrainRate", 1f, "Insanity reduced per second while the local player has an active TZP-Inhalant effect."); RateOnShipLightsOn = cfg.Bind("Insanity", "RateOnShipLightsOn", -0.3f, "Insanity per second on the ship while ship lights are ON. Negative reduces, positive increases."); RateOnShipLightsOff = cfg.Bind("Insanity", "RateOnShipLightsOff", 0.15f, "Insanity per second on the ship while ship lights are OFF. Negative reduces, positive increases."); } } internal static class InsanityCalculator { public static float TickDelta(bool isInFacility, bool isInShip, float rateInFacility, float rateOnShip, float outdoorRate, float multiplier, float deltaTime) { return (isInFacility ? (rateInFacility * multiplier) : (isInShip ? rateOnShip : outdoorRate)) * deltaTime; } public static float Clamp(float value) { return Math.Clamp(value, 0f, 100f); } public static float TunnelVisionAlpha(float insanity, float threshold) { if (!(insanity >= threshold)) { return 0f; } return (insanity - threshold) / (100f - threshold); } } [BepInPlugin("com.insanitymod.lethalcompany", "InsanityMod", "1.0.7")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string GUID = "com.insanitymod.lethalcompany"; public const string NAME = "InsanityMod"; public const string VERSION = "1.0.7"; internal static ManualLogSource Log; internal static Plugin Instance; private readonly Harmony _harmony = new Harmony("com.insanitymod.lethalcompany"); private void Awake() { Instance = this; Log = ((BaseUnityPlugin)this).Logger; ModConfig.Initialize(((BaseUnityPlugin)this).Config); LocalizationManager.Initialize(); BloodNightManager.Initialize(); VFXManager.Initialize(); InsanityHud.Initialize(); _harmony.PatchAll(); Log.LogInfo((object)"InsanityMod v1.0.7 by Cpt.Dristyler loaded."); } private void LateUpdate() { SafePatch.Run("LateUpdate", delegate { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown if (BloodNightManager.IsActive) { BloodNightManager.EnforceVisuals(); } else { BloodNightManager.TickFade(); } if (InsanityManager.IsRoundActive) { PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController; if (!((Object)val == (Object)null)) { if (val.isPlayerDead) { MaskedTransformManager.Reset(); VFXManager.ClearEffect(); InsanityManager.ResetOnDeath(); } else { CameraShakeManager.ApplyShake(val, InsanityManager.Insanity); } } } }); } private void OnDestroy() { BloodNightManager.OnPluginDestroy(); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "InsanityMod"; public const string PLUGIN_NAME = "InsanityMod"; public const string PLUGIN_VERSION = "1.0.7"; } } namespace InsanityMod.Managers { internal static class BloodNightManager { private static Weather? _bloodNightWeather; private static GameObject? _rainEffectRef; private static Light? _cachedSun; private static float _lastSunSearch = -100f; private const float SunSearchCooldown = 5f; private static readonly HashSet _paranoiaLevels = new HashSet(); private static readonly HashSet _preserveExistingFogMoons = new HashSet { "85 Rend", "7 Dine", "8 Titan" }; private static AmbientMode _savedAmbientMode; private static Color _savedAmbientLight; private static Color _savedSunColor; private static float _savedSunIntensity; private static bool _pendingSave; private static bool _fadingOut; private static GameObject? _skyVolumeObj; private static Volume? _skyVolume; private static VolumeProfile? _skyProfile; private static GameObject? _fogVolumeObj; private static Volume? _fogVolume; private static VolumeProfile? _fogProfile; private static readonly Color _ambientFlat = new Color(0.07f, 0.01f, 0.01f); private static readonly Color _sunColor = new Color(0.7f, 0.1f, 0.1f); private static readonly Quaternion _sunRot = Quaternion.Euler(8f, 330f, 0f); public static bool IsActive { get; private set; } public static void Initialize() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_005a: 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_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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) ImprovedWeatherEffect val = ScriptableObject.CreateInstance(); _bloodNightWeather = new Weather(LocalizationManager.Get("weather.blood_night"), val); _bloodNightWeather.Config.DefaultWeight = new IntegerConfigHandler(ModConfig.BloodNightSpawnWeight.Value, false); TMP_ColorGradient val2 = ScriptableObject.CreateInstance(); Color bottomRight = default(Color); ((Color)(ref bottomRight))..ctor(0.55f, 0.04f, 0.04f); val2.topLeft = (val2.topRight = (val2.bottomLeft = (val2.bottomRight = bottomRight))); _bloodNightWeather.ColorGradient = val2; WeatherManager.RegisterWeather(_bloodNightWeather); ((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.WeatherChanged).AddListener((ParameterEvent<(SelectableLevel, Weather)>)OnWeatherChanged); SceneManager.sceneLoaded += OnSceneLoaded; } public static void OnPluginDestroy() { _paranoiaLevels.Clear(); SceneManager.sceneLoaded -= OnSceneLoaded; if (_bloodNightWeather != null) { ((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.WeatherChanged).RemoveListener((ParameterEvent<(SelectableLevel, Weather)>)OnWeatherChanged); } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) SafePatch.Run("OnSceneLoaded", delegate { if (!(((Scene)(ref scene)).name != "MainMenu")) { IsActive = false; _fadingOut = false; _pendingSave = false; _cachedSun = null; _paranoiaLevels.Clear(); DisableHDRPVolume(); DisableRain(); } }); } private static void OnWeatherChanged((SelectableLevel level, Weather weather) args) { SafePatch.Run("OnWeatherChanged", delegate { if (_bloodNightWeather != null) { if (args.weather == _bloodNightWeather) { _paranoiaLevels.Add(args.level); } else { _paranoiaLevels.Remove(args.level); } } }); } public static void OnRoundStart() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown SelectableLevel val = StartOfRound.Instance?.currentLevel; int num; if ((Object)val != (Object)null) { num = (_paranoiaLevels.Contains(val) ? 1 : 0); if (num != 0) { goto IL_0042; } } else { num = 0; } if (IsActive) { RestoreVisuals(); } goto IL_0042; IL_0042: IsActive = (byte)num != 0; _pendingSave = false; } public static void OnLevelLoaded() { if (IsActive) { EnableRain(); EnableHDRPVolume(); _pendingSave = true; } } public static void OnRoundEnd() { if (IsActive) { IsActive = false; _pendingSave = false; _fadingOut = true; DisableRain(); } } public static void TickFade() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00de: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) if (!_fadingOut) { return; } if ((Object)_skyVolume == (Object)null && (Object)_fogVolume == (Object)null) { _fadingOut = false; return; } float num = Time.deltaTime / 2f; if ((Object)_skyVolume != (Object)null) { _skyVolume.weight = Mathf.MoveTowards(_skyVolume.weight, 0f, num); } if ((Object)_fogVolume != (Object)null) { _fogVolume.weight = Mathf.MoveTowards(_fogVolume.weight, 0f, num); } float num2 = _fogVolume?.weight ?? 0f; RenderSettings.ambientLight = Color.Lerp(_savedAmbientLight, _ambientFlat, num2); Light sun = GetSun(); if ((Object)sun != (Object)null) { sun.color = Color.Lerp(_savedSunColor, _sunColor, num2); sun.intensity = Mathf.Lerp(_savedSunIntensity, 0.12f, num2); } if ((_skyVolume?.weight ?? 0f) <= 0f && num2 <= 0f) { RestoreVisuals(); _fadingOut = false; } } private static Light? GetSun() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Invalid comparison between Unknown and I4 if ((Object)_cachedSun != (Object)null) { return _cachedSun; } if ((Object)RenderSettings.sun != (Object)null) { return _cachedSun = RenderSettings.sun; } if (Time.time - _lastSunSearch < 5f) { return null; } _lastSunSearch = Time.time; Light[] array = Object.FindObjectsOfType(); foreach (Light val in array) { if ((int)val.type == 1) { return _cachedSun = val; } } return null; } public static void EnforceVisuals() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Expected O, but got Unknown //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Expected O, but got Unknown //IL_0149: 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_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) if (_pendingSave) { _savedAmbientMode = RenderSettings.ambientMode; _savedAmbientLight = RenderSettings.ambientLight; Light sun = GetSun(); if ((Object)sun != (Object)null) { _savedSunColor = sun.color; _savedSunIntensity = sun.intensity; } _pendingSave = false; } PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController; bool flag = (Object)val != (Object)null && !val.isInsideFactory && !InsanityManager.IsInShip(val); float num = (flag ? 1f : 0f); float num2 = Time.deltaTime * 2f; if ((Object)_skyVolume != (Object)null) { _skyVolume.weight = Mathf.MoveTowards(_skyVolume.weight, num, num2); } if ((Object)_fogVolume != (Object)null) { _fogVolume.weight = Mathf.MoveTowards(_fogVolume.weight, num, num2); } float num3 = _fogVolume?.weight ?? 0f; RenderSettings.ambientMode = _savedAmbientMode; RenderSettings.ambientLight = Color.Lerp(_savedAmbientLight, _ambientFlat, num3); Light sun2 = GetSun(); if ((Object)sun2 != (Object)null) { sun2.color = Color.Lerp(_savedSunColor, _sunColor, num3); sun2.intensity = Mathf.Lerp(_savedSunIntensity, 0.12f, num3); if (flag) { ((Component)sun2).transform.rotation = _sunRot; } } if ((Object)_rainEffectRef != (Object)null && !_rainEffectRef.activeSelf) { _rainEffectRef.SetActive(true); } } private static void EnableHDRPVolume() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_00ae: 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_00c7: Expected O, but got Unknown //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) if (!((Object)_skyVolumeObj != (Object)null)) { _skyVolumeObj = new GameObject("InsanityMod_ParanoiaSky"); _skyVolume = _skyVolumeObj.AddComponent(); _skyVolume.isGlobal = true; _skyVolume.priority = 9999f; _skyVolume.weight = 0f; _skyProfile = ScriptableObject.CreateInstance(); _skyVolume.profile = _skyProfile; ColorAdjustments obj = _skyProfile.Add(true); ((VolumeParameter)(object)obj.postExposure).Override(-0.4f); ((VolumeParameter)(object)obj.colorFilter).Override(new Color(0.95f, 0.82f, 0.82f)); _fogVolumeObj = new GameObject("InsanityMod_ParanoiaFog"); _fogVolume = _fogVolumeObj.AddComponent(); _fogVolume.isGlobal = true; _fogVolume.priority = 10000f; _fogVolume.weight = 0f; _fogProfile = ScriptableObject.CreateInstance(); _fogVolume.profile = _fogProfile; string text = StartOfRound.Instance?.currentLevel?.PlanetName; if (text == null || !_preserveExistingFogMoons.Contains(text)) { Fog obj2 = _fogProfile.Add(true); ((VolumeParameter)(object)obj2.enabled).Override(true); ((VolumeParameter)(object)obj2.albedo).Override(new Color(0.18f, 0.02f, 0.02f)); ((VolumeParameter)(object)obj2.meanFreePath).Override(120f); ((VolumeParameter)(object)obj2.baseHeight).Override(0f); ((VolumeParameter)(object)obj2.maximumHeight).Override(150f); ((VolumeParameter)(object)obj2.tint).Override(new Color(0.5f, 0.1f, 0.1f)); } ColorAdjustments obj3 = _fogProfile.Add(true); ((VolumeParameter)(object)obj3.postExposure).Override(-1.3f); ((VolumeParameter)(object)obj3.colorFilter).Override(new Color(0.88f, 0.58f, 0.58f)); ((VolumeParameter)(object)obj3.saturation).Override(-22f); } } private static void DisableHDRPVolume() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown if ((Object)_skyVolumeObj != (Object)null) { Object.Destroy((Object)_skyVolumeObj); } if ((Object)_skyProfile != (Object)null) { Object.Destroy((Object)_skyProfile); } if ((Object)_fogVolumeObj != (Object)null) { Object.Destroy((Object)_fogVolumeObj); } if ((Object)_fogProfile != (Object)null) { Object.Destroy((Object)_fogProfile); } _skyVolumeObj = null; _skyVolume = null; _skyProfile = null; _fogVolumeObj = null; _fogVolume = null; _fogProfile = null; } private static void RestoreVisuals() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) RenderSettings.ambientMode = _savedAmbientMode; RenderSettings.ambientLight = _savedAmbientLight; Light sun = GetSun(); if ((Object)sun != (Object)null) { sun.color = _savedSunColor; sun.intensity = _savedSunIntensity; } _cachedSun = null; DisableHDRPVolume(); DisableRain(); } private static void EnableRain() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown TimeOfDay instance = TimeOfDay.Instance; if ((Object)instance == (Object)null || instance.effects == null) { return; } int num = 1; if (num >= 0 && num < instance.effects.Length) { GameObject effectObject = instance.effects[num].effectObject; if (!((Object)effectObject == (Object)null)) { _rainEffectRef = effectObject; ClearStopActions(_rainEffectRef); _rainEffectRef.SetActive(true); } } } private static void DisableRain() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if (!((Object)_rainEffectRef == (Object)null)) { _rainEffectRef.SetActive(false); _rainEffectRef = null; } } private static void ClearStopActions(GameObject root) { //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_0017: Unknown result type (might be due to invalid IL or missing references) ParticleSystem[] componentsInChildren = root.GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { MainModule main = componentsInChildren[i].main; if ((int)((MainModule)(ref main)).stopAction != 0) { ((MainModule)(ref main)).stopAction = (ParticleSystemStopAction)0; } } } } internal static class CameraShakeManager { private const float ShakeThreshold = 90f; private const float NoiseFrequency = 8f; private const float MaxPositionAmplitude = 0.02f; private const float MaxRotationAmplitude = 0.8f; private static Vector3 _prevPosShake = Vector3.zero; private static Quaternion _prevRotShake = Quaternion.identity; public static void ApplyShake(PlayerControllerB local, float insanity) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_001f: 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) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_004e: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Camera gameplayCamera = local.gameplayCamera; if (!((Object)gameplayCamera == (Object)null)) { Transform transform = ((Component)gameplayCamera).transform; transform.localPosition -= _prevPosShake; ((Component)gameplayCamera).transform.localRotation = ((Component)gameplayCamera).transform.localRotation * Quaternion.Inverse(_prevRotShake); if (insanity < 90f) { _prevPosShake = Vector3.zero; _prevRotShake = Quaternion.identity; return; } float num = Mathf.Clamp01((insanity - 90f) / 10f); float num2 = Time.time * 8f; float num3 = (Mathf.PerlinNoise(num2, 0f) - 0.5f) * 2f; float num4 = (Mathf.PerlinNoise(0f, num2) - 0.5f) * 2f; float num5 = (Mathf.PerlinNoise(num2 + 7f, num2) - 0.5f) * 2f; _prevPosShake = new Vector3(num3, num4, num5) * 0.02f * num; _prevRotShake = Quaternion.Euler(num4 * 0.8f * num, num3 * 0.8f * num, num5 * 0.8f * 0.6f * num); Transform transform2 = ((Component)gameplayCamera).transform; transform2.localPosition += _prevPosShake; Transform transform3 = ((Component)gameplayCamera).transform; transform3.localRotation *= _prevRotShake; } } } internal static class InsanityHud { private const int RingSize = 110; private const int RingThickness = 7; private const float ScreenMarginX = 35f; private const float ScreenMarginY = 130f; private static GameObject? _canvasGO; private static CanvasGroup? _canvasGroup; private static Image? _ringFill; private static Image? _ringBg; private static TextMeshProUGUI? _label; private static Sprite? _ringSprite; public static void Initialize() { SceneManager.sceneLoaded += OnSceneLoaded; } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) SafePatch.Run("OnSceneLoaded", delegate { if (!(((Scene)(ref scene)).name != "SampleSceneRelay") && ModConfig.EnableHud.Value) { CreateOverlay(); SetVisible(visible: false); } }); } public static void SetVisible(bool visible) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if (!((Object)_canvasGroup == (Object)null)) { _canvasGroup.alpha = (visible ? 1f : 0f); } } public static void UpdateValue(float insanity) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown //IL_00b8: 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) if ((Object)_canvasGroup != (Object)null) { float num = ((!ModConfig.EnableHud.Value || (ModConfig.HideHudAtZero.Value && insanity <= 0.5f)) ? 0f : 1f); _canvasGroup.alpha = Mathf.MoveTowards(_canvasGroup.alpha, num, Time.deltaTime * 2f); } if (!((Object)_ringFill == (Object)null) && !((Object)_ringBg == (Object)null) && !((Object)_label == (Object)null)) { float num2 = Mathf.Clamp01(insanity / 100f); _ringFill.fillAmount = num2; ((Graphic)_ringFill).color = ColorForInsanity(num2); ((TMP_Text)_label).text = $"{Mathf.FloorToInt(insanity)}%"; ((Graphic)_label).color = ColorForInsanity(num2); } } private static void CreateOverlay() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_00a0: 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_00dc: 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_0106: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown //IL_0143: 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_0158: 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_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Expected O, but got Unknown //IL_01c3: 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_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025b: 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_026e: Expected O, but got Unknown //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) if (!((Object)_canvasGO != (Object)null)) { _canvasGO = new GameObject("InsanityHud_Canvas"); Object.DontDestroyOnLoad((Object)_canvasGO); Canvas obj = _canvasGO.AddComponent(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 50; _canvasGO.AddComponent(); _canvasGO.AddComponent(); _canvasGroup = _canvasGO.AddComponent(); _canvasGroup.alpha = 1f; _canvasGroup.interactable = false; _canvasGroup.blocksRaycasts = false; Sprite ringSprite = GetRingSprite(); RectTransform val = new GameObject("InsanityHud_Root").AddComponent(); ((Transform)val).SetParent(_canvasGO.transform, false); val.anchorMin = new Vector2(1f, 0f); val.anchorMax = new Vector2(1f, 0f); val.pivot = new Vector2(1f, 0f); val.anchoredPosition = new Vector2(-35f, 130f); val.sizeDelta = new Vector2(110f, 110f); GameObject val2 = new GameObject("InsanityHud_RingBg"); RectTransform obj2 = val2.AddComponent(); ((Transform)obj2).SetParent((Transform)val, false); obj2.anchorMin = Vector2.zero; obj2.anchorMax = Vector2.one; obj2.sizeDelta = Vector2.zero; _ringBg = val2.AddComponent(); _ringBg.sprite = ringSprite; ((Graphic)_ringBg).color = new Color(0.1f, 0.1f, 0.1f, 0.75f); ((Graphic)_ringBg).raycastTarget = false; GameObject val3 = new GameObject("InsanityHud_RingFill"); RectTransform obj3 = val3.AddComponent(); ((Transform)obj3).SetParent((Transform)val, false); obj3.anchorMin = Vector2.zero; obj3.anchorMax = Vector2.one; obj3.sizeDelta = Vector2.zero; _ringFill = val3.AddComponent(); _ringFill.sprite = ringSprite; _ringFill.type = (Type)3; _ringFill.fillMethod = (FillMethod)4; _ringFill.fillOrigin = 2; _ringFill.fillClockwise = true; _ringFill.fillAmount = 0f; ((Graphic)_ringFill).color = ColorForInsanity(0f); ((Graphic)_ringFill).raycastTarget = false; GameObject val4 = new GameObject("InsanityHud_Label"); RectTransform obj4 = val4.AddComponent(); ((Transform)obj4).SetParent((Transform)val, false); obj4.anchorMin = Vector2.zero; obj4.anchorMax = Vector2.one; obj4.sizeDelta = Vector2.zero; _label = val4.AddComponent(); ((TMP_Text)_label).alignment = (TextAlignmentOptions)514; ((TMP_Text)_label).fontSize = 22f; ((TMP_Text)_label).fontStyle = (FontStyles)1; ((TMP_Text)_label).text = "0%"; ((Graphic)_label).color = ColorForInsanity(0f); ((Graphic)_label).raycastTarget = false; } } private static Color ColorForInsanity(float t) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (t < 0.5f) { return Color.Lerp(new Color(0.85f, 0.85f, 0.85f), new Color(1f, 0.85f, 0.2f), t / 0.5f); } return Color.Lerp(new Color(1f, 0.85f, 0.2f), new Color(1f, 0.15f, 0.15f), (t - 0.5f) / 0.5f); } private static Sprite GetRingSprite() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_001f: 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) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_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_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) if ((Object)_ringSprite != (Object)null) { return _ringSprite; } int num = 110; Texture2D val = new Texture2D(num, num, (TextureFormat)1, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor((float)num / 2f, (float)num / 2f); float num2 = (float)num / 2f - 1.5f; float num3 = num2 - 7f; Color32[] array = (Color32[])(object)new Color32[num * num]; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { float num4 = Vector2.Distance(new Vector2((float)j, (float)i), val2); float num5 = 0f; if (num4 >= num3 && num4 <= num2) { num5 = 1f; } else if (num4 > num2 && num4 < num2 + 1f) { num5 = 1f - (num4 - num2); } else if (num4 < num3 && num4 > num3 - 1f) { num5 = 1f - (num3 - num4); } array[i * num + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num5 * 255f)); } } val.SetPixels32(array); val.Apply(); _ringSprite = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f)); return _ringSprite; } } internal static class InsanityManager { private static float _insanity; private static float _maxInsanityThisRound; private static bool _roundActive; private static bool _apparatusRemoved; private static bool _hasTransformedThisRound; private static ShipLights? _cachedShipLights; public static float Insanity => _insanity; public static float MaxInsanityThisRound => _maxInsanityThisRound; public static bool IsRoundActive => _roundActive; public static void OnApparatusRemoved() { if (_roundActive) { _apparatusRemoved = true; AddInsanity(ModConfig.ApparatusSpike.Value); } } public static void StartRound() { _insanity = 0f; _maxInsanityThisRound = 0f; _roundActive = true; _apparatusRemoved = false; _hasTransformedThisRound = false; MaskedTransformManager.Reset(); InsanityHud.SetVisible(visible: true); } public static void EndRound() { _roundActive = false; VFXManager.ClearEffect(); InsanityHud.SetVisible(visible: false); } public static void ResetForRound() { StartRound(); } public static bool IsInShip(PlayerControllerB player) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) if ((Object)player == (Object)null) { return false; } Collider val = StartOfRound.Instance?.shipInnerRoomBounds; if ((Object)val != (Object)null) { Bounds bounds = val.bounds; return ((Bounds)(ref bounds)).Contains(((Component)player).transform.position); } return player.isInHangarShipRoom; } public static void Tick(PlayerControllerB player, float deltaTime) { //IL_0064: 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_0078: Invalid comparison between Unknown and I4 if (!_roundActive) { return; } bool flag = IsInShip(player); bool flag2 = !player.isInsideFactory && !flag; float num; if (flag2 && BloodNightManager.IsActive) { num = ModConfig.ParanoiaOutdoorRate.Value; } else { if (flag2) { StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance != (Object)null && (int)(instance.currentLevel?.currentWeather).GetValueOrDefault() == 5) { num = ModConfig.EclipseOutdoorRate.Value; goto IL_00d5; } } num = ((!flag2 || !(ModConfig.NightOutdoorRate.Value > 0f) || (TimeOfDay.Instance?.hour ?? 0) < ModConfig.NightStartHour.Value) ? (0f - ModConfig.InsanityDecayOutdoor.Value) : ModConfig.NightOutdoorRate.Value); } goto IL_00d5; IL_00d5: if (flag2 && player.isUnderwater && num < 0f) { num = 0f; } float num2 = InsanityCalculator.TickDelta(player.isInsideFactory, flag, ModConfig.InsanityRateInFacility.Value, GetShipRate(), num, BloodNightManager.IsActive ? ModConfig.BloodNightMultiplier.Value : 1f, deltaTime); float num3 = InsanityModifiers.ComputeBonusRate(player) * deltaTime; if (_apparatusRemoved && player.isInsideFactory) { num3 = Math.Max(num3, 0f); } _insanity = InsanityCalculator.Clamp(_insanity + num2 + num3); if (_insanity > _maxInsanityThisRound) { _maxInsanityThisRound = _insanity; } VFXManager.UpdateTunnelVision(_insanity); InsanityHud.UpdateValue(_insanity); VoiceHaunt.Tick(_insanity, deltaTime); if (_insanity >= 100f && !_hasTransformedThisRound && !MaskedTransformManager.IsActive && ModConfig.EnableMaskedTransform.Value && (!ModConfig.MaskedTransformOnlyDuringParanoia.Value || BloodNightManager.IsActive)) { _hasTransformedThisRound = true; MaskedTransformManager.TriggerTransform(player); } if (MaskedTransformManager.IsActive) { MaskedTransformManager.Tick(player, deltaTime); } } public static void ResetOnDeath() { _insanity = 0f; InsanityHud.UpdateValue(0f); } private static float GetShipRate() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if ((Object)_cachedShipLights == (Object)null) { _cachedShipLights = Object.FindObjectOfType(); } if (!((Object)_cachedShipLights != (Object)null) || !_cachedShipLights.areLightsOn) { return ModConfig.RateOnShipLightsOff.Value; } return ModConfig.RateOnShipLightsOn.Value; } public static void AddInsanity(float amount) { if (_roundActive) { _insanity = InsanityCalculator.Clamp(_insanity + amount); if (_insanity > _maxInsanityThisRound) { _maxInsanityThisRound = _insanity; } } } } internal static class InsanityModifiers { private static Light[] _cachedLights = Array.Empty(); private static float _lastLightCacheTime = -100f; private const float LightCacheRefreshSec = 5f; private static readonly Dictionary EnemyRates = new Dictionary { { "Flowerman", 2f }, { "Crawler", 0.8f }, { "Spring", 1.5f }, { "Hoarding bug", 0.1f }, { "Centipede", 0.6f }, { "SandSpider", 0.9f }, { "BushWolf", 1.2f }, { "ForestGiant", 1.4f }, { "DressGirl", 2f }, { "Jester", 1.5f }, { "Blob", 0.3f }, { "Puffer", 0.4f }, { "MaskedPlayerEnemy", 1.6f }, { "Maneater", 1.4f }, { "BaboonHawk", 0.5f }, { "RedLocustBees", 0.2f }, { "DocileLocustBees", 0f }, { "DoublewingBird", 0f }, { "SandWorm", 1.8f }, { "Tulip Snake", 0.3f }, { "Butler", 1.4f }, { "Butler Bees", 0.2f }, { "ClaySurgeon", 1.3f } }; private const float DefaultEnemyRate = 0.3f; public static float ComputeBonusRate(PlayerControllerB local) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if ((Object)local == (Object)null) { return 0f; } return 0f + MobVisibilityBonus(local) + UnderwaterBonus(local) - ProximityBuff(local) - LightBuff(local) - CompanyMoonBonus(local) - TZPBuff(local); } public static float UnderwaterBonus(PlayerControllerB local) { if (!local.isUnderwater) { return 0f; } return ModConfig.UnderwaterRate.Value; } public static float CompanyMoonBonus(PlayerControllerB local) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown SelectableLevel val = StartOfRound.Instance?.currentLevel; if ((Object)val == (Object)null) { return 0f; } if (val.PlanetName == "71 Gordion") { return ModConfig.CompanyMoonDecayRate.Value; } return 0f; } public static float TZPBuff(PlayerControllerB local) { if (!(local.drunkness > 0.05f)) { return 0f; } return ModConfig.TZPInsanityDrainRate.Value; } public static float MobVisibilityBonus(PlayerControllerB local) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_006d: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) Camera gameplayCamera = local.gameplayCamera; if ((Object)gameplayCamera == (Object)null) { return 0f; } RoundManager instance = RoundManager.Instance; if ((Object)instance == (Object)null || instance.SpawnedEnemies == null) { return 0f; } float value = ModConfig.MobVisibilityScale.Value; float value2 = ModConfig.MobVisibilityRange.Value; float num = value2 * value2; Vector3 position = ((Component)gameplayCamera).transform.position; Vector3 forward = ((Component)gameplayCamera).transform.forward; float num2 = gameplayCamera.fieldOfView * 0.5f + 5f; float num3 = 0f; RaycastHit val = default(RaycastHit); for (int i = 0; i < instance.SpawnedEnemies.Count; i++) { EnemyAI val2 = instance.SpawnedEnemies[i]; if ((Object)val2 == (Object)null || val2.isEnemyDead || (Object)val2.enemyType == (Object)null) { continue; } Vector3 val3 = ((Component)val2).transform.position - position; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; if (!(sqrMagnitude > num) && !(sqrMagnitude < 0.01f)) { float num4 = Mathf.Sqrt(sqrMagnitude); Vector3 val4 = val3 / num4; if (!(Vector3.Angle(forward, val4) > num2) && (!Physics.Linecast(position, ((Component)val2).transform.position, ref val, -1, (QueryTriggerInteraction)1) || ((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)val2).transform))) { float rateForEnemy = GetRateForEnemy(val2); num3 += rateForEnemy; } } } return num3 * value; } public static float ProximityBuff(PlayerControllerB local) { //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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_0052: 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_0062: Expected O, but got Unknown //IL_0062: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB[] array = StartOfRound.Instance?.allPlayerScripts; if (array == null) { return 0f; } float value = ModConfig.TeammateBuffRange.Value; float num = value * value; Vector3 position = ((Component)local).transform.position; PlayerControllerB[] array2 = array; foreach (PlayerControllerB val in array2) { if (!((Object)val == (Object)null) && !((Object)val == (Object)local) && !val.isPlayerDead && val.isPlayerControlled) { Vector3 val2 = ((Component)val).transform.position - position; if (((Vector3)(ref val2)).sqrMagnitude <= num) { return ModConfig.TeammateBuffRate.Value; } } } return 0f; } public static float LightBuff(PlayerControllerB local) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0093: 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_0067: Expected O, but got Unknown if (InsanityManager.IsInShip(local)) { return ModConfig.LightBuffRate.Value; } if ((Object)local.helmetLight != (Object)null && ((Behaviour)local.helmetLight).enabled) { return ModConfig.LightBuffRate.Value; } if (local.ItemSlots != null) { GrabbableObject[] itemSlots = local.ItemSlots; foreach (GrabbableObject val in itemSlots) { FlashlightItem val2 = (FlashlightItem)((val is FlashlightItem) ? val : null); if ((Object)(object)val2 != (Object)null && ((GrabbableObject)val2).isBeingUsed) { return ModConfig.LightBuffRate.Value; } } } if (IsNearActiveLight(((Component)local).transform.position)) { return ModConfig.LightBuffRate.Value; } return 0f; } private static bool IsNearActiveLight(Vector3 pos) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Invalid comparison between Unknown and I4 //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) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (Time.time - _lastLightCacheTime > 5f) { _cachedLights = Object.FindObjectsOfType(); _lastLightCacheTime = Time.time; } float value = ModConfig.LightProximityRange.Value; float num = value * value; for (int i = 0; i < _cachedLights.Length; i++) { Light val = _cachedLights[i]; if (!((Object)val == (Object)null) && ((Behaviour)val).enabled && ((Component)val).gameObject.activeInHierarchy && (int)val.type != 1 && !(val.intensity < 0.3f)) { Vector3 val2 = ((Component)val).transform.position - pos; if (((Vector3)(ref val2)).sqrMagnitude <= num) { return true; } } } return false; } public static void InvalidateLightCache() { _cachedLights = Array.Empty(); _lastLightCacheTime = -100f; } public static bool IsPositionVisible(PlayerControllerB local, Vector3 worldPos, float maxRange) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_0057: 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_007b: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00a5: Unknown result type (might be due to invalid IL or missing references) Camera gameplayCamera = local.gameplayCamera; if ((Object)gameplayCamera == (Object)null) { return false; } Vector3 val = worldPos - ((Component)gameplayCamera).transform.position; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude > maxRange * maxRange || sqrMagnitude < 0.01f) { return false; } float num = Mathf.Sqrt(sqrMagnitude); Vector3 val2 = val / num; if (Vector3.Angle(((Component)gameplayCamera).transform.forward, val2) > gameplayCamera.fieldOfView * 0.5f + 5f) { return false; } RaycastHit val3 = default(RaycastHit); if (Physics.Linecast(((Component)gameplayCamera).transform.position, worldPos, ref val3, -1, (QueryTriggerInteraction)1)) { Vector3 val4 = ((RaycastHit)(ref val3)).point - worldPos; if (((Vector3)(ref val4)).sqrMagnitude > 1f) { return false; } } return true; } private static float GetRateForEnemy(EnemyAI enemy) { string key = enemy.enemyType?.enemyName ?? ""; if (EnemyRates.TryGetValue(key, out var value)) { return value; } return 0.3f; } } internal static class LocalizationManager { private static Dictionary _strings = new Dictionary(); public static void Initialize() { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Langs.json"); if (!File.Exists(text)) { Plugin.Log.LogWarning((object)("Langs.json not found at " + text + ", falling back to EN defaults.")); LoadDefaults(); return; } string text2 = DetectLanguage(); Dictionary> dictionary = ParseLangSections(File.ReadAllText(text)); if (!dictionary.TryGetValue(text2, out var value)) { dictionary.TryGetValue("EN", out value); } if (value != null) { foreach (KeyValuePair item in value) { _strings[item.Key] = item.Value; } } else { LoadDefaults(); } Plugin.Log.LogInfo((object)$"Localization loaded: {text2} ({_strings.Count} strings)"); } public static string Get(string key) { if (!_strings.TryGetValue(key, out string value)) { return key; } return value; } private static string DetectLanguage() { string text = ModConfig.Language.Value?.Trim().ToUpper(); if (!string.IsNullOrEmpty(text) && text != "AUTO") { return text; } if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToUpper() == "KO") { return "KO"; } return "EN"; } private static void LoadDefaults() { _strings["item.bread.name"] = "Cheap Bread"; _strings["item.bread.choke"] = "Choking on Bread!"; _strings["item.potion.name"] = "Lucid Doom"; _strings["item.potion.use"] = "Vision cleared, but..."; _strings["hud.max_insanity"] = "Peak Insanity"; _strings["weather.blood_night"] = "Paranoia"; } private static Dictionary> ParseLangSections(string json) { Dictionary> dictionary = new Dictionary>(); int i = 0; SkipWhitespace(json, ref i); if (i >= json.Length || json[i] != '{') { return dictionary; } i++; while (i < json.Length) { SkipWhitespace(json, ref i); if (i < json.Length && json[i] == '}') { break; } string key = ReadString(json, ref i); SkipWhitespace(json, ref i); if (i >= json.Length || json[i] != ':') { break; } i++; SkipWhitespace(json, ref i); if (i >= json.Length || json[i] != '{') { break; } i++; Dictionary dictionary2 = new Dictionary(); while (i < json.Length) { SkipWhitespace(json, ref i); if (i < json.Length && json[i] == '}') { i++; break; } string key2 = ReadString(json, ref i); SkipWhitespace(json, ref i); if (i >= json.Length || json[i] != ':') { break; } i++; SkipWhitespace(json, ref i); string value = ReadString(json, ref i); dictionary2[key2] = value; SkipWhitespace(json, ref i); if (i < json.Length && json[i] == ',') { i++; } } dictionary[key] = dictionary2; SkipWhitespace(json, ref i); if (i < json.Length && json[i] == ',') { i++; } } return dictionary; } private static void SkipWhitespace(string s, ref int i) { while (i < s.Length && char.IsWhiteSpace(s[i])) { i++; } } private static string ReadString(string s, ref int i) { if (i >= s.Length || s[i] != '"') { return ""; } i++; StringBuilder stringBuilder = new StringBuilder(); while (i < s.Length && s[i] != '"') { if (s[i] == '\\' && i + 1 < s.Length) { char c = s[i + 1]; switch (c) { case 'n': stringBuilder.Append('\n'); break; case 't': stringBuilder.Append('\t'); break; case 'r': stringBuilder.Append('\r'); break; default: stringBuilder.Append(c); break; } i += 2; } else { stringBuilder.Append(s[i]); i++; } } if (i < s.Length) { i++; } return stringBuilder.ToString(); } } internal static class MaskedTransformManager { private enum Phase { Idle, Slowing, Cutscene, Done } private static Phase _phase; private static float _timer; private static float _savedSpeed; private static PlayerControllerB? _local; private const float SlowDuration = 6f; private const float CutsceneDuration = 2.5f; public static bool IsActive { get { if (_phase != 0) { return _phase != Phase.Done; } return false; } } public static void TriggerTransform(PlayerControllerB local) { if (_phase == Phase.Idle) { _local = local; _savedSpeed = local.movementSpeed; _phase = Phase.Slowing; _timer = 0f; } } public static void Tick(PlayerControllerB local, float deltaTime) { //IL_00d2: 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) if (_phase == Phase.Idle || _phase == Phase.Done) { return; } _timer += deltaTime; if (_phase == Phase.Slowing) { float num = Mathf.Clamp01(_timer / 6f); local.movementSpeed = Mathf.Lerp(_savedSpeed, 0f, num * num); VFXManager.SetBlackout(Mathf.Clamp01((_timer - 4f) / 2f)); if (num >= 1f) { local.movementSpeed = 0f; local.disableMoveInput = true; local.disableLookInput = true; VFXManager.SetBlackout(1f); InsanityNetworkHandler.SendSpawnMasked(local); _phase = Phase.Cutscene; _timer = 0f; } } else if (_phase == Phase.Cutscene && _timer >= 2.5f) { _phase = Phase.Done; VFXManager.SetBlackout(0f); local.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, default(Vector3), false); } } public static void Reset() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if ((Object)_local != (Object)null && _phase != 0) { _local.movementSpeed = ((_savedSpeed > 0f) ? _savedSpeed : 4.6f); _local.disableMoveInput = false; _local.disableLookInput = false; } VFXManager.SetBlackout(0f); _phase = Phase.Idle; _timer = 0f; _local = null; } } internal static class VFXManager { private static Image? _overlay; private static Image? _blackOverlay; private static Sprite? _vignetteSprite; private static Color _tunnelColor = new Color(0.12f, 0.02f, 0.02f); public static void Initialize() { //IL_0022: 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_003c: Unknown result type (might be due to invalid IL or missing references) SceneManager.sceneLoaded += OnSceneLoaded; Color tunnelColor = default(Color); if (ColorUtility.TryParseHtmlString(ModConfig.TunnelVisionColor.Value, ref tunnelColor)) { _tunnelColor = tunnelColor; } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) SafePatch.Run("OnSceneLoaded", delegate { if (!(((Scene)(ref scene)).name != "SampleSceneRelay")) { CreateOverlay(); } }); } private static void CreateOverlay() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_007e: 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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) if (!((Object)_overlay != (Object)null)) { GameObject val = new GameObject("InsanityVFX_Canvas"); Object.DontDestroyOnLoad((Object)val); Canvas obj = val.AddComponent(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 999; val.AddComponent(); val.AddComponent(); GameObject val2 = new GameObject("InsanityVFX_Overlay"); val2.transform.SetParent(val.transform, false); RectTransform obj2 = val2.AddComponent(); obj2.anchorMin = Vector2.zero; obj2.anchorMax = Vector2.one; obj2.sizeDelta = Vector2.zero; _overlay = val2.AddComponent(); ((Graphic)_overlay).raycastTarget = false; _overlay.sprite = GetVignetteSprite(); ((Graphic)_overlay).color = new Color(1f, 0f, 0f, 0f); GameObject val3 = new GameObject("InsanityVFX_Black"); val3.transform.SetParent(val.transform, false); RectTransform obj3 = val3.AddComponent(); obj3.anchorMin = Vector2.zero; obj3.anchorMax = Vector2.one; obj3.sizeDelta = Vector2.zero; _blackOverlay = val3.AddComponent(); ((Graphic)_blackOverlay).raycastTarget = false; ((Graphic)_blackOverlay).color = new Color(0f, 0f, 0f, 0f); } } private static Sprite GetVignetteSprite() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0100: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) if ((Object)_vignetteSprite != (Object)null) { return _vignetteSprite; } Texture2D val = new Texture2D(256, 256, (TextureFormat)1, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(128f, 128f); float num = 128f; Color32[] array = (Color32[])(object)new Color32[65536]; for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { float num2 = Mathf.Clamp01(Mathf.Pow(Mathf.Clamp01(Vector2.Distance(new Vector2((float)j, (float)i), val2) / num), 2.5f)); array[i * 256 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num2 * 255f)); } } val.SetPixels32(array); val.Apply(); _vignetteSprite = Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f)); return _vignetteSprite; } public static void UpdateTunnelVision(float insanity) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_002d: 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) if (!((Object)_overlay == (Object)null)) { float value = ModConfig.TunnelVisionThreshold.Value; float num = InsanityCalculator.TunnelVisionAlpha(insanity, value); float num2 = Mathf.Lerp(((Graphic)_overlay).color.a, num, Time.deltaTime * 2f); float num3 = 0.94f + 0.06f * Mathf.Sin(Time.time * 1.2f); ((Graphic)_overlay).color = new Color(_tunnelColor.r * num3, _tunnelColor.g * num3, _tunnelColor.b * num3, num2); } } public static void SetBlackout(float alpha) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (!((Object)_blackOverlay == (Object)null)) { ((Graphic)_blackOverlay).color = new Color(0f, 0f, 0f, alpha); } } public static void ClearEffect() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) if ((Object)_overlay != (Object)null) { ((Graphic)_overlay).color = new Color(1f, 0f, 0f, 0f); } if ((Object)_blackOverlay != (Object)null) { ((Graphic)_blackOverlay).color = new Color(0f, 0f, 0f, 0f); } } } } namespace InsanityMod.Network { internal static class InsanityNetworkHandler { private const string MSG_SUBMIT = "InsanityMod.SubmitMaxInsanity"; private const string MSG_RESULTS = "InsanityMod.BroadcastResults"; private const string MSG_SPAWN_MASKED = "InsanityMod.SpawnMasked"; private static EnemyType? _maskedEnemyType; public static readonly Dictionary PlayerMaxInsanity = new Dictionary(); public static void RegisterHandlers() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown UnregisterHandlers(); if (!((Object)NetworkManager.Singleton == (Object)null)) { CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager; if (NetworkManager.Singleton.IsServer) { customMessagingManager.RegisterNamedMessageHandler("InsanityMod.SubmitMaxInsanity", new HandleNamedMessageDelegate(ReceiveMaxInsanity)); customMessagingManager.RegisterNamedMessageHandler("InsanityMod.SpawnMasked", new HandleNamedMessageDelegate(ReceiveSpawnMasked)); } customMessagingManager.RegisterNamedMessageHandler("InsanityMod.BroadcastResults", new HandleNamedMessageDelegate(ReceiveBroadcastResults)); } } public static void UnregisterHandlers() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if (!((Object)NetworkManager.Singleton == (Object)null)) { CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager; customMessagingManager.UnregisterNamedMessageHandler("InsanityMod.SubmitMaxInsanity"); customMessagingManager.UnregisterNamedMessageHandler("InsanityMod.BroadcastResults"); customMessagingManager.UnregisterNamedMessageHandler("InsanityMod.SpawnMasked"); } } public static void SendMaxInsanity(float maxInsanity) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0022: 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_003f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)NetworkManager.Singleton == (Object)null)) { FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1); ((FastBufferWriter)(ref val)).WriteValueSafe(ref maxInsanity, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("InsanityMod.SubmitMaxInsanity", 0uL, val, (NetworkDelivery)3); ((FastBufferWriter)(ref val)).Dispose(); } } private static void ReceiveMaxInsanity(ulong senderId, FastBufferReader reader) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) SafePatch.Run("ReceiveMaxInsanity", delegate { //IL_0010: 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) float value = 0f; ((FastBufferReader)(ref reader)).ReadValueSafe(ref value, default(ForPrimitives)); PlayerMaxInsanity[senderId] = value; }); } public static void BroadcastResults() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0041: 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_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_008e: 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_00c2: Unknown result type (might be due to invalid IL or missing references) if ((Object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsServer) { return; } int count = PlayerMaxInsanity.Count; int num = 4 + count * 12; FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1); ((FastBufferWriter)(ref val)).WriteValueSafe(ref count, default(ForPrimitives)); foreach (KeyValuePair item in PlayerMaxInsanity) { ulong key = item.Key; ((FastBufferWriter)(ref val)).WriteValueSafe(ref key, default(ForPrimitives)); float value = item.Value; ((FastBufferWriter)(ref val)).WriteValueSafe(ref value, default(ForPrimitives)); } NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("InsanityMod.BroadcastResults", val, (NetworkDelivery)3); ((FastBufferWriter)(ref val)).Dispose(); } private static void ReceiveBroadcastResults(ulong _, FastBufferReader reader) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) SafePatch.Run("ReceiveBroadcastResults", delegate { //IL_000c: 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_003a: 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_0050: 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) int num = 0; ((FastBufferReader)(ref reader)).ReadValueSafe(ref num, default(ForPrimitives)); PlayerMaxInsanity.Clear(); ulong key = 0uL; float value = 0f; for (int i = 0; i < num; i++) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref key, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe(ref value, default(ForPrimitives)); PlayerMaxInsanity[key] = value; } }); } public static void SendSpawnMasked(PlayerControllerB local) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00a3: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (!((Object)singleton == (Object)null)) { FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(20, (Allocator)2, -1); Vector3 position = ((Component)local).transform.position; ((FastBufferWriter)(ref val)).WriteValueSafe(ref position.x, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref position.y, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref position.z, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref local.playerClientId, default(ForPrimitives)); if (singleton.IsServer) { FastBufferReader reader = default(FastBufferReader); ((FastBufferReader)(ref reader))..ctor(val, (Allocator)2, -1, 0, (Allocator)2); ReceiveSpawnMasked(singleton.LocalClientId, reader); ((FastBufferReader)(ref reader)).Dispose(); } else { singleton.CustomMessagingManager.SendNamedMessage("InsanityMod.SpawnMasked", 0uL, val, (NetworkDelivery)3); } ((FastBufferWriter)(ref val)).Dispose(); } } private static void ReceiveSpawnMasked(ulong _, FastBufferReader reader) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) SafePatch.Run("ReceiveSpawnMasked", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_004a: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown float num = 0f; ((FastBufferReader)(ref reader)).ReadValueSafe(ref num, default(ForPrimitives)); float num2 = 0f; ((FastBufferReader)(ref reader)).ReadValueSafe(ref num2, default(ForPrimitives)); float num3 = 0f; ((FastBufferReader)(ref reader)).ReadValueSafe(ref num3, default(ForPrimitives)); ulong num4 = 0uL; ((FastBufferReader)(ref reader)).ReadValueSafe(ref num4, default(ForPrimitives)); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(num, num2, num3); EnemyType maskedEnemyType = GetMaskedEnemyType(); if (!((Object)maskedEnemyType == (Object)null) && !((Object)RoundManager.Instance == (Object)null)) { NetworkObjectReference val2 = RoundManager.Instance.SpawnEnemyGameObject(val, 0f, -1, maskedEnemyType); NetworkObject val3 = null; if (((NetworkObjectReference)(ref val2)).TryGet(ref val3, (NetworkManager)null)) { MaskedPlayerEnemy val4 = ((Component)val3).GetComponent() ?? ((Component)val3).GetComponentInChildren(); if (!((Object)val4 == (Object)null)) { PlayerControllerB[] array = StartOfRound.Instance?.allPlayerScripts; if (array != null) { PlayerControllerB[] array2 = array; foreach (PlayerControllerB val5 in array2) { if (val5.playerClientId == num4) { val4.mimickingPlayer = val5; val4.SetSuit(val5.currentSuitID); break; } } } } } } }); } private static EnemyType? GetMaskedEnemyType() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if ((Object)_maskedEnemyType != (Object)null) { return _maskedEnemyType; } EnemyType[] array = Resources.FindObjectsOfTypeAll(); foreach (EnemyType val in array) { if (val.enemyName == "Masked") { _maskedEnemyType = val; return val; } } return null; } } } namespace InsanityMod.Patches { [HarmonyPatch(typeof(PlayerControllerB))] internal static class DeathWitnessPatcher { [HarmonyPatch("KillPlayer")] [HarmonyPostfix] private static void KillPlayerPostfix(PlayerControllerB __instance) { PlayerControllerB __instance2 = __instance; SafePatch.Run("KillPlayerPostfix", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0053: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) if (InsanityManager.IsRoundActive && !((Object)__instance2 == (Object)null)) { PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController; if (!((Object)val == (Object)null) && !((Object)val == (Object)__instance2) && !val.isPlayerDead) { float value = ModConfig.DeathWitnessRange.Value; if (InsanityModifiers.IsPositionVisible(val, ((Component)__instance2).transform.position, value)) { InsanityManager.AddInsanity(ModConfig.DeathWitnessSpike.Value); } } } }); } } [HarmonyPatch(typeof(DressGirlAI))] internal static class GhostGirlBoostPatcher { [HarmonyPatch("Update")] [HarmonyPostfix] private static void UpdatePostfix(DressGirlAI __instance) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown DressGirlAI __instance2 = __instance; if (!InsanityManager.IsRoundActive || !__instance2.hauntingLocalPlayer || (Object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsServer) { return; } float threshold = ModConfig.GhostGirlBoostThreshold.Value; float current = InsanityManager.Insanity; if (!(current < threshold)) { SafePatch.Run("UpdatePostfix", delegate { float num = (current - threshold) / Mathf.Max(0.01f, 100f - threshold); DressGirlAI obj = __instance2; obj.timer += Time.deltaTime * num * 0.5f; }); } } } [HarmonyPatch(typeof(LungProp))] internal static class LungPropPatcher { [HarmonyPatch("EquipItem")] [HarmonyPrefix] private static void EquipItemPrefix(LungProp __instance) { LungProp __instance2 = __instance; SafePatch.Run("EquipItemPrefix", delegate { if (__instance2.isLungDocked) { InsanityManager.OnApparatusRemoved(); } }); } } [HarmonyPatch(typeof(PlayerControllerB))] internal static class PlayerPatcher { [HarmonyPatch("Update")] [HarmonyPostfix] private static void UpdatePostfix(PlayerControllerB __instance) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_003c: Expected O, but got Unknown PlayerControllerB __instance2 = __instance; GameNetworkManager instance = GameNetworkManager.Instance; if (!((Object)instance == (Object)null) && !((Object)__instance2 != (Object)instance.localPlayerController) && !__instance2.isPlayerDead) { SafePatch.Run("UpdatePostfix", delegate { InsanityManager.Tick(__instance2, Time.deltaTime); }); } } } [HarmonyPatch(typeof(RoundManager))] internal static class LevelGenerationPatcher { [HarmonyPatch("FinishGeneratingNewLevelClientRpc")] [HarmonyPostfix] private static void FinishGeneratingPostfix() { SafePatch.Run("FinishGeneratingPostfix", delegate { if (!InsanityManager.IsRoundActive) { InsanityManager.StartRound(); InsanityNetworkHandler.PlayerMaxInsanity.Clear(); InsanityNetworkHandler.RegisterHandlers(); VoiceHaunt.ResetForRound(); InsanityModifiers.InvalidateLightCache(); BloodNightManager.OnRoundStart(); RoundResultsPatcher.Reset(); } BloodNightManager.OnLevelLoaded(); }); } } [HarmonyPatch(typeof(StartOfRound))] internal static class RoundPatcher { [HarmonyPatch("StartGame")] [HarmonyPostfix] private static void StartGamePostfix() { SafePatch.Run("StartGamePostfix", delegate { InsanityManager.StartRound(); InsanityNetworkHandler.PlayerMaxInsanity.Clear(); InsanityNetworkHandler.RegisterHandlers(); VoiceHaunt.ResetForRound(); InsanityModifiers.InvalidateLightCache(); BloodNightManager.OnRoundStart(); RoundResultsPatcher.Reset(); }); } [HarmonyPatch("ShipLeave")] [HarmonyPostfix] private static void ShipLeavePostfix() { SafePatch.Run("ShipLeavePostfix", delegate { InsanityNetworkHandler.SendMaxInsanity(InsanityManager.MaxInsanityThisRound); BloodNightManager.OnRoundEnd(); VoiceHaunt.ResetForRound(); }); } [HarmonyPatch("EndGameClientRpc")] [HarmonyPostfix] private static void EndGamePostfix() { SafePatch.Run("EndGamePostfix", delegate { InsanityNetworkHandler.BroadcastResults(); InsanityNetworkHandler.UnregisterHandlers(); InsanityManager.EndRound(); BloodNightManager.OnRoundEnd(); }); } [HarmonyPatch("OnDestroy")] [HarmonyPostfix] private static void OnDestroyPostfix() { SafePatch.Run("OnDestroyPostfix", delegate { InsanityManager.EndRound(); BloodNightManager.OnRoundEnd(); VFXManager.ClearEffect(); }); } } [HarmonyPatch(typeof(HUDManager))] internal static class RoundResultsPatcher { private static bool _appendedThisRound; public static void Reset() { _appendedThisRound = false; } [HarmonyPatch("ApplyPenalty")] [HarmonyPostfix] private static void ShowInsanityStats(HUDManager __instance) { HUDManager __instance2 = __instance; SafePatch.Run("ShowInsanityStats", delegate { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown if (!_appendedThisRound && InsanityNetworkHandler.PlayerMaxInsanity.Count != 0) { TextMeshProUGUI val = __instance2.statsUIElements?.penaltyAddition; if (!((Object)val == (Object)null)) { string text = LocalizationManager.Get("hud.max_insanity"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(); stringBuilder.Append("— " + text + " —"); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val2 in allPlayerScripts) { ulong actualClientId = val2.actualClientId; if (InsanityNetworkHandler.PlayerMaxInsanity.TryGetValue(actualClientId, out var value)) { string arg = ((value >= 100f) ? "" : ((value >= 80f) ? "" : "")); stringBuilder.AppendLine(); stringBuilder.Append($"{arg}{val2.playerUsername}: {value:F0}%"); } } ((TMP_Text)val).text = ((TMP_Text)val).text + stringBuilder.ToString(); _appendedThisRound = true; } } }); } } internal static class SafePatch { private static readonly HashSet _loggedKeys = new HashSet(); private static readonly object _lock = new object(); public static void Run(string label, Action body) { try { body(); } catch (Exception ex) { string item = label + ":" + ex.GetType().FullName + ":" + ex.Message; lock (_lock) { if (_loggedKeys.Add(item)) { Plugin.Log.LogError((object)$"[{label}] {ex}"); } } } } } } namespace InsanityMod.Voice { internal sealed class CircularSampleBuffer { private readonly float[] _data; private readonly object _lock = new object(); private int _writeIdx; private int _filled; public int Capacity => _data.Length; public int FilledSamples { get { lock (_lock) { return _filled; } } } public CircularSampleBuffer(int capacity) { _data = new float[capacity]; } public void Write(float[] samples, int offset, int count) { if (count <= 0) { return; } lock (_lock) { int num = _data.Length; for (int i = 0; i < count; i++) { _data[_writeIdx] = samples[offset + i]; _writeIdx = (_writeIdx + 1) % num; } _filled = Math.Min(_filled + count, num); } } public float[]? ExtractSnippet(int sampleCount, Random rng) { lock (_lock) { if (_filled < sampleCount) { return null; } int num = _data.Length; int filled = _filled; int num2 = (_writeIdx - filled + num) % num; int num3 = filled - sampleCount; int num4 = ((num3 > 0) ? rng.Next(0, num3 + 1) : 0); int num5 = (num2 + num4) % num; float[] array = new float[sampleCount]; for (int i = 0; i < sampleCount; i++) { array[i] = _data[num5]; num5 = (num5 + 1) % num; } return array; } } public void Clear() { lock (_lock) { Array.Clear(_data, 0, _data.Length); _writeIdx = 0; _filled = 0; } } } [HarmonyPatch(typeof(SamplePlaybackComponent))] internal static class VoiceCapturePatcher { [HarmonyPatch("OnAudioFilterRead")] [HarmonyPostfix] private static void CaptureSamples(SamplePlaybackComponent __instance, float[] data, int channels) { float[] data2 = data; VoiceTrack track = VoiceHaunt.GetTrackFor(__instance); if (track == null || channels <= 0 || data2.Length == 0) { return; } SafePatch.Run("CaptureSamples", delegate { int num = data2.Length / channels; float[] array = new float[num]; for (int i = 0; i < num; i++) { float num2 = 0f; for (int j = 0; j < channels; j++) { num2 += data2[i * channels + j]; } array[i] = num2 / (float)channels; } track.Buffer.Write(array, 0, num); }); } } internal static class VoiceHaunt { private const int SampleRate = 48000; private const int BufferSeconds = 30; private const int SnippetMinMs = 600; private const int SnippetMaxMs = 2000; private static DissonanceComms? _comms; private static readonly Dictionary _tracks = new Dictionary(); private static readonly Dictionary _tracksByPlayback = new Dictionary(); private static readonly Random _rng = new Random(); private static float _hauntCooldown = 5f; private static bool _subscribed; private static readonly List _activeClips = new List(); public static void Tick(float localInsanity, float deltaTime) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown EnsureComms(); if ((Object)_comms == (Object)null) { return; } RefreshTracks(); float value = ModConfig.VoiceHauntThreshold.Value; float num = Mathf.Clamp01((localInsanity - value) / Mathf.Max(0.01f, 100f - value)); foreach (VoiceTrack value2 in _tracks.Values) { value2.ApplyLiveDistortion(num); } if (localInsanity < value) { _hauntCooldown = NextInterval(localInsanity); return; } _hauntCooldown -= deltaTime; if (!(_hauntCooldown > 0f)) { _hauntCooldown = NextInterval(localInsanity); TryHauntPlayback(num); } } public static void ResetForRound() { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown foreach (VoiceTrack value in _tracks.Values) { value.ClearBuffer(); value.ResetFilters(); } _hauntCooldown = 5f; for (int num = _activeClips.Count - 1; num >= 0; num--) { if ((Object)_activeClips[num] != (Object)null) { Object.Destroy((Object)_activeClips[num]); } } _activeClips.Clear(); } public static VoiceTrack? GetTrackFor(SamplePlaybackComponent component) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if ((Object)component == (Object)null) { return null; } int instanceID = ((Object)((Component)component).gameObject).GetInstanceID(); _tracksByPlayback.TryGetValue(instanceID, out VoiceTrack value); return value; } private static void EnsureComms() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (!((Object)_comms != (Object)null)) { _comms = Object.FindObjectOfType(); if (!((Object)_comms == (Object)null) && !_subscribed) { _comms.OnPlayerLeftSession += OnPlayerLeft; _subscribed = true; } } } private static void OnPlayerLeft(VoicePlayerState state) { VoicePlayerState state2 = state; SafePatch.Run("OnPlayerLeft", delegate { if (state2 != null && _tracks.TryGetValue(state2.Name, out VoiceTrack value)) { _tracks.Remove(state2.Name); _tracksByPlayback.Remove(((Object)((Component)value.Playback).gameObject).GetInstanceID()); } }); } private static void RefreshTracks() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown if ((Object)_comms == (Object)null) { return; } foreach (VoicePlayerState player in _comms.Players) { if (!player.IsLocalPlayer) { IVoicePlayback playback = player.Playback; VoicePlayback val = (VoicePlayback)((playback is VoicePlayback) ? playback : null); if ((Object)(object)val != (Object)null && !_tracks.ContainsKey(player.Name)) { int bufferSamples = 1440000; VoiceTrack value = new VoiceTrack(val, bufferSamples); _tracks[player.Name] = value; _tracksByPlayback[((Object)((Component)val).gameObject).GetInstanceID()] = value; } } } } private static float NextInterval(float insanity) { if (insanity >= 90f) { return Random.Range(3f, 8f); } return Random.Range(12f, 25f); } private static void TryHauntPlayback(float intensity) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) List list = new List(); foreach (VoiceTrack value in _tracks.Values) { if (value.Buffer.FilledSamples > 24000) { list.Add(value); } } if (list.Count != 0) { VoiceTrack voiceTrack = list[_rng.Next(list.Count)]; int num = _rng.Next(600, 2001); int sampleCount = 48000 * num / 1000; float[] array = voiceTrack.Buffer.ExtractSnippet(sampleCount, _rng); if (array != null) { PlayHauntClip(array, ((Component)voiceTrack.Playback).transform.position, intensity); } } } private static void PlayHauntClip(float[] samples, Vector3 position, float intensity) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_002f: 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_0040: Expected O, but got Unknown //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Expected O, but got Unknown AudioClip val = AudioClip.Create("InsanityHaunt", samples.Length, 1, 48000, false); val.SetData(samples, 0); GameObject val2 = new GameObject("InsanityHauntPlayer"); val2.transform.position = position; Object.DontDestroyOnLoad((Object)val2); _activeClips.Add(val2); AudioSource obj = val2.AddComponent(); obj.clip = val; obj.spatialBlend = 1f; obj.minDistance = 1f; obj.maxDistance = 25f; obj.rolloffMode = (AudioRolloffMode)0; obj.volume = Mathf.Lerp(0.4f, 0.85f, intensity); obj.pitch = Mathf.Lerp(0.95f, 0.55f, intensity); val2.AddComponent().cutoffFrequency = Mathf.Lerp(6000f, 1200f, intensity); val2.AddComponent().distortionLevel = Mathf.Lerp(0.15f, 0.65f, intensity); val2.AddComponent().reverbPreset = (AudioReverbPreset)2; if (intensity > 0.6f) { AudioEchoFilter obj2 = val2.AddComponent(); obj2.delay = Mathf.Lerp(120f, 280f, intensity); obj2.wetMix = 0.5f; obj2.dryMix = 1f; obj2.decayRatio = Mathf.Lerp(0.4f, 0.7f, intensity); } obj.Play(); Object.Destroy((Object)val2, (float)samples.Length / 48000f + 1f); } } internal sealed class VoiceTrack { public string PlayerName { get; } public VoicePlayback Playback { get; } public AudioSource Source { get; } public CircularSampleBuffer Buffer { get; } public AudioLowPassFilter LowPass { get; } public AudioDistortionFilter Distortion { get; } public AudioReverbFilter Reverb { get; } public AudioEchoFilter Echo { get; } public VoiceTrack(VoicePlayback playback, int bufferSamples) { PlayerName = playback.PlayerName; Playback = playback; Source = playback.AudioSource; Buffer = new CircularSampleBuffer(bufferSamples); GameObject gameObject = ((Component)playback).gameObject; LowPass = GetOrAdd(gameObject); Distortion = GetOrAdd(gameObject); Reverb = GetOrAdd(gameObject); Echo = GetOrAdd(gameObject); ResetFilters(); } public void ApplyLiveDistortion(float insanityNorm) { float num = Mathf.Clamp01(insanityNorm); LowPass.cutoffFrequency = Mathf.Lerp(22000f, 1500f, num); Distortion.distortionLevel = Mathf.Lerp(0f, 0.55f, num); Reverb.reverbLevel = Mathf.Lerp(-10000f, 800f, num); Reverb.decayTime = Mathf.Lerp(0.1f, 3.5f, num); Echo.delay = Mathf.Lerp(0f, 180f, num); Echo.wetMix = Mathf.Lerp(0f, 0.45f, num); Echo.dryMix = 1f; Echo.decayRatio = Mathf.Lerp(0f, 0.55f, num); ((Behaviour)LowPass).enabled = num > 0.01f; ((Behaviour)Distortion).enabled = num > 0.2f; ((Behaviour)Reverb).enabled = num > 0.01f; ((Behaviour)Echo).enabled = num > 0.4f; } public void ResetFilters() { LowPass.cutoffFrequency = 22000f; ((Behaviour)LowPass).enabled = false; Distortion.distortionLevel = 0f; ((Behaviour)Distortion).enabled = false; Reverb.reverbLevel = -10000f; Reverb.decayTime = 0.1f; ((Behaviour)Reverb).enabled = false; Echo.delay = 0f; Echo.wetMix = 0f; Echo.dryMix = 1f; Echo.decayRatio = 0f; ((Behaviour)Echo).enabled = false; } public void ClearBuffer() { Buffer.Clear(); } private static T GetOrAdd(GameObject go) where T : Component { return go.GetComponent() ?? go.AddComponent(); } } }