Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Y4NGZUI v1.0.0
Y4NGZUI.dll
Decompiled 31 minutes ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using Unity.Collections; using Unity.Netcode; using Unity.Profiling; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Experimental.Rendering; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.Utilities; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.SceneManagement; using UnityEngine.Sprites; using UnityEngine.TextCore; using UnityEngine.TextCore.LowLevel; using UnityEngine.UI; using Y4NGZ.Compatibility; using Y4NGZCompany.Core.Compat; using Y4NGZCompany.Core.Pilot; using Y4NGZCompany.Experience.Fonts; using Y4NGZCompany.Experience.Scan; using Y4NGZCompany.Experience.UITheme; using Y4NGZCompany.Facility.Shared; using Y4NGZCompany.ShipSystems.Rendering; using Y4NGZCore.Lifecycle; using Y4NGZCore.Modules; using Y4NGZCore.Modules.Hud; using Y4NGZCore.Modules.Objectives; using Y4NGZCore.Modules.Security; using Y4NGZUI.Themes.Hairline; using Y4NGZUI.Themes.Immersive; using Y4NGZUI.Themes.Shared; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("ClientNetworkTransform")] [assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")] [assembly: IgnoresAccessChecksTo("DissonanceVoip")] [assembly: IgnoresAccessChecksTo("DunGen")] [assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")] [assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")] [assembly: IgnoresAccessChecksTo("EasyTextEffects")] [assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")] [assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")] [assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")] [assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")] [assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")] [assembly: IgnoresAccessChecksTo("Unity.Burst")] [assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")] [assembly: IgnoresAccessChecksTo("Unity.Collections")] [assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")] [assembly: IgnoresAccessChecksTo("Unity.Jobs")] [assembly: IgnoresAccessChecksTo("Unity.Mathematics")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")] [assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")] [assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")] [assembly: IgnoresAccessChecksTo("Unity.Services.QoS")] [assembly: IgnoresAccessChecksTo("Unity.Services.Relay")] [assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")] [assembly: IgnoresAccessChecksTo("Unity.Timeline")] [assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")] [assembly: IgnoresAccessChecksTo("Unity.XR.Management")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")] [assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")] [assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")] [assembly: IgnoresAccessChecksTo("UnityEngine.UI")] [assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Y4NGZUI")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Centralized Y4NGZ UI: theme publisher, gameplay HUD substrate, and the player HUD")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+cf185c0e51a8a7d6f3cb05e22774d09273ee9fea")] [assembly: AssemblyProduct("Y4NGZUI")] [assembly: AssemblyTitle("Y4NGZUI")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 Y4NGZ.Compatibility { public static class VanillaHudCanvasHost { public const float ReferenceHeight = 1080f; public static Canvas ResolveCanvas() { HUDManager instance = HUDManager.Instance; if ((Object)(object)instance == (Object)null) { return null; } if ((Object)(object)instance.playerScreenTexture != (Object)null && (Object)(object)((Graphic)instance.playerScreenTexture).canvas != (Object)null) { return ((Graphic)instance.playerScreenTexture).canvas; } if ((Object)(object)instance.HUDContainer != (Object)null) { return instance.HUDContainer.GetComponentInParent<Canvas>(); } return null; } public static RectTransform CreateHost(string name, Canvas canvas, ref Transform pauseMenuAnchor) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); AttachHost(component, canvas, ref pauseMenuAnchor); return component; } public static void AttachHost(RectTransform host, Canvas canvas, ref Transform pauseMenuAnchor) { ((Component)host).gameObject.layer = ((Component)canvas).gameObject.layer; ((Transform)host).SetParent(((Component)canvas).transform, false); Stretch(host); pauseMenuAnchor = null; KeepBeneathPauseMenu(host, canvas, ref pauseMenuAnchor); } public static void KeepBeneathPauseMenu(RectTransform host, Canvas canvas, ref Transform pauseMenuAnchor) { if ((Object)(object)host == (Object)null || (Object)(object)canvas == (Object)null) { return; } if ((Object)(object)pauseMenuAnchor == (Object)null) { pauseMenuAnchor = ResolvePauseMenuAnchor(canvas); } if ((Object)(object)pauseMenuAnchor != (Object)null) { int siblingIndex = pauseMenuAnchor.GetSiblingIndex(); if (((Transform)host).GetSiblingIndex() > siblingIndex) { ((Transform)host).SetSiblingIndex(siblingIndex); } return; } GameObject val = (((Object)(object)HUDManager.Instance != (Object)null) ? HUDManager.Instance.HUDContainer : null); Transform val2 = (((Object)(object)val != (Object)null) ? CanvasLevelAncestor(val.transform, ((Component)canvas).transform) : null); if ((Object)(object)val2 != (Object)null && ((Transform)host).GetSiblingIndex() > val2.GetSiblingIndex() + 1) { ((Transform)host).SetSiblingIndex(val2.GetSiblingIndex() + 1); } } public static void PlaceBeneathPauseMenu(RectTransform node, Canvas canvas, ref Transform anchor) { if ((Object)(object)node == (Object)null || (Object)(object)canvas == (Object)null) { return; } if ((Object)(object)anchor == (Object)null) { anchor = ResolvePauseMenuAnchor(canvas); } if ((Object)(object)anchor != (Object)null) { CanvasSiblingOrder.PlaceBelow((Transform)(object)node, anchor); return; } GameObject val = (((Object)(object)HUDManager.Instance != (Object)null) ? HUDManager.Instance.HUDContainer : null); Transform val2 = (((Object)(object)val != (Object)null) ? CanvasLevelAncestor(val.transform, ((Component)canvas).transform) : null); if ((Object)(object)val2 != (Object)null) { CanvasSiblingOrder.PlaceAbove((Transform)(object)node, val2); } } public static float ReferenceScaleRatio(Canvas canvas) { float num = Mathf.Max(0.001f, (float)Screen.height / 1080f); float num2 = (((Object)(object)canvas != (Object)null) ? Mathf.Max(0.001f, canvas.scaleFactor) : 1f); return num / num2; } public static void Stretch(RectTransform rect) { //IL_0001: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.pivot = new Vector2(0.5f, 0.5f); rect.offsetMin = Vector2.zero; rect.offsetMax = Vector2.zero; ((Transform)rect).localRotation = Quaternion.identity; ((Transform)rect).localScale = Vector3.one; } public static void SetLayerRecursively(GameObject go, int layer) { if (!((Object)(object)go == (Object)null)) { Transform[] componentsInChildren = go.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = layer; } } } private static Transform ResolvePauseMenuAnchor(Canvas canvas) { PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val == (Object)null && (Object)(object)StartOfRound.Instance != (Object)null) { val = StartOfRound.Instance.localPlayerController; } QuickMenuManager val2 = (((Object)(object)val != (Object)null) ? val.quickMenuManager : null); GameObject val3 = (((Object)(object)val2 != (Object)null) ? val2.menuContainer : null); if (!((Object)(object)val3 != (Object)null)) { return null; } return CanvasLevelAncestor(val3.transform, ((Component)canvas).transform); } private static Transform CanvasLevelAncestor(Transform node, Transform canvasRoot) { while ((Object)(object)node != (Object)null && (Object)(object)node.parent != (Object)(object)canvasRoot) { node = node.parent; } return node; } } internal static class CanvasSiblingOrder { internal static void PlaceBelow(Transform node, Transform anchor) { int siblingIndex = anchor.GetSiblingIndex(); int siblingIndex2 = node.GetSiblingIndex(); if (siblingIndex2 != siblingIndex - 1) { node.SetSiblingIndex((siblingIndex2 < siblingIndex) ? (siblingIndex - 1) : siblingIndex); } } internal static void PlaceAbove(Transform node, Transform anchor) { int siblingIndex = anchor.GetSiblingIndex(); int siblingIndex2 = node.GetSiblingIndex(); if (siblingIndex2 != siblingIndex + 1) { node.SetSiblingIndex((siblingIndex2 < siblingIndex) ? siblingIndex : (siblingIndex + 1)); } } internal static void PlaceLast(Transform node) { Transform parent = node.parent; if ((Object)(object)parent != (Object)null && node.GetSiblingIndex() != parent.childCount - 1) { node.SetAsLastSibling(); } } } internal sealed class OptionalUnderPauseMenuSignal { private readonly Func<bool> _read; private readonly Action<Action<bool>> _subscribe; private readonly Action<Action<bool>> _unsubscribe; private readonly Action<Func<bool>> _installProbe; private readonly Action<bool> _publish; internal bool IsVisible => _read(); internal OptionalUnderPauseMenuSignal(Type signal, Action<string> warn) { Func<bool> func = Bind<Func<bool>>(signal, "get_IsVisibleUnderPauseMenu"); Action<Action<bool>> action = Bind<Action<Action<bool>>>(signal, "add_UnderPauseMenuChanged"); Action<Action<bool>> action2 = Bind<Action<Action<bool>>>(signal, "remove_UnderPauseMenuChanged"); Action<Func<bool>> action3 = Bind<Action<Func<bool>>>(signal, "InstallUnderPauseMenuLiveProbe"); Action<bool> action4 = Bind<Action<bool>>(signal, "SetUnderPauseMenu"); if (func != null && action != null && action2 != null && action3 != null && action4 != null) { _read = func; _subscribe = action; _unsubscribe = action2; _installProbe = action3; _publish = action4; } else { _read = Bind<Func<bool>>(signal, "get_IsVisible"); _subscribe = Bind<Action<Action<bool>>>(signal, "add_Changed"); _unsubscribe = Bind<Action<Action<bool>>>(signal, "remove_Changed"); warn?.Invoke("[HUD compatibility] Core lacks the pause-independent visibility channel. Using legacy visibility (HUD hides during pause); install the rebuilt Y4NGZCore package."); } } internal void Subscribe(Action<bool> handler) { _subscribe(handler); } internal void Unsubscribe(Action<bool> handler) { _unsubscribe(handler); } internal void InstallLiveProbe(Func<bool> probe) { _installProbe?.Invoke(probe); } internal void Publish(bool visible) { _publish?.Invoke(visible); } private static T Bind<T>(Type signal, string member) where T : Delegate { MethodInfo method = signal.GetMethod(member, BindingFlags.Static | BindingFlags.Public); if (!(method == null)) { return Delegate.CreateDelegate(typeof(T), method, throwOnBindFailure: false) as T; } return null; } } } namespace Y4NGZUI { internal static class DamageSourcePatches { [HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")] private static class LocalHitPatch { [HarmonyPrefix] private static void Prefix(PlayerControllerB __instance, out int __state) { __state = __instance.health; } [HarmonyPostfix] private static void Postfix(PlayerControllerB __instance, int damageNumber, CauseOfDeath causeOfDeath, Vector3 force, int __state) { //IL_0022: 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_002a: 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) if (__instance.health < __state && ((NetworkBehaviour)__instance).IsOwner) { Vector3? source = DamageSourceResolver.Resolve(DamageSourceResolver.ScopedPoint(DamageSourceResolver.Current, OwnerPositionOf), force, causeOfDeath, ((Component)__instance).transform.position); LocalHitFeedback.OnLocalHit(__instance, source, damageNumber, causeOfDeath); } } } [HarmonyPatch(typeof(EnemyAICollisionDetect), "OnTriggerStay")] private static class ContactRecorder { [HarmonyPrefix] private static void Prefix(EnemyAICollisionDetect __instance, out DamageSourceRecord __state) { __state = DamageSourceResolver.Enter(DamageSourceRecord.Deferred(__instance)); } [HarmonyFinalizer] private static void Finalizer(DamageSourceRecord __state) { DamageSourceResolver.Exit(__state); } } [HarmonyPatch(typeof(BlobAI), "OnCollideWithPlayer")] private static class BlobRecorder { [HarmonyPrefix] private static void Prefix(BlobAI __instance, out DamageSourceRecord __state) { __state = DamageSourceResolver.Enter(DamageSourceRecord.Deferred(__instance)); } [HarmonyFinalizer] private static void Finalizer(DamageSourceRecord __state) { DamageSourceResolver.Exit(__state); } } [HarmonyPatch(typeof(Turret), "Update")] private static class TurretRecorder { [HarmonyPrefix] private static void Prefix(Turret __instance, out DamageSourceRecord __state) { __state = DamageSourceResolver.Enter(DamageSourceRecord.Deferred(__instance)); } [HarmonyFinalizer] private static void Finalizer(DamageSourceRecord __state) { DamageSourceResolver.Exit(__state); } } [HarmonyPatch(typeof(Landmine), "SpawnExplosion")] private static class LandmineRecorder { [HarmonyPrefix] private static void Prefix(Vector3 explosionPosition, out DamageSourceRecord __state) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) __state = DamageSourceResolver.Enter(DamageSourceRecord.AtPoint(explosionPosition)); } [HarmonyFinalizer] private static void Finalizer(DamageSourceRecord __state) { DamageSourceResolver.Exit(__state); } } [HarmonyPatch(typeof(StunGrenadeItem), "StunExplosion")] private static class StunGrenadeRecorder { [HarmonyPrefix] private static void Prefix(Vector3 explosionPosition, out DamageSourceRecord __state) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) __state = DamageSourceResolver.Enter(DamageSourceRecord.AtPoint(explosionPosition)); } [HarmonyFinalizer] private static void Finalizer(DamageSourceRecord __state) { DamageSourceResolver.Exit(__state); } } [HarmonyPatch(typeof(PlayerControllerB), "DamagePlayerFromOtherClientClientRpc")] private static class PlayerHitRecorder { [HarmonyPrefix] private static void Prefix(int playerWhoHit, out DamageSourceRecord __state) { __state = DamageSourceResolver.Enter(HitterRecord(playerWhoHit)); } [HarmonyFinalizer] private static void Finalizer(DamageSourceRecord __state) { DamageSourceResolver.Exit(__state); } private static DamageSourceRecord HitterRecord(int playerWhoHit) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) StartOfRound instance = StartOfRound.Instance; PlayerControllerB[] array = (((Object)(object)instance != (Object)null) ? instance.allPlayerScripts : null); if (array == null || playerWhoHit < 0 || playerWhoHit >= array.Length) { return DamageSourceRecord.None; } PlayerControllerB val = array[playerWhoHit]; if (!((Object)(object)val != (Object)null)) { return DamageSourceRecord.None; } return DamageSourceRecord.AtPoint(((Component)val).transform.position); } } private static readonly Type[] Patches = new Type[7] { typeof(LocalHitPatch), typeof(ContactRecorder), typeof(BlobRecorder), typeof(TurretRecorder), typeof(LandmineRecorder), typeof(StunGrenadeRecorder), typeof(PlayerHitRecorder) }; private static readonly Func<object, Vector3?> OwnerPositionOf = OwnerPosition; internal static void Apply(Harmony harmony) { Type[] patches = Patches; foreach (Type type in patches) { try { harmony.PatchAll(type); } catch (Exception ex) { ManualLogSource log = UiPlugin.Log; if (log != null) { log.LogWarning((object)("[Y4NGZUI] " + type.Name + " was not applied (" + ex.GetType().Name + ": " + ex.Message + "); danger feedback runs without it.")); } } } } private static Vector3? OwnerPosition(object owner) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) EnemyAICollisionDetect val = (EnemyAICollisionDetect)((owner is EnemyAICollisionDetect) ? owner : null); if (val == null) { BlobAI val2 = (BlobAI)((owner is BlobAI) ? owner : null); if (val2 == null) { Turret val3 = (Turret)((owner is Turret) ? owner : null); if (val3 != null) { Transform val4 = (((Object)(object)val3 != (Object)null) ? val3.aimPoint : null); if (!((Object)(object)val4 != (Object)null)) { return null; } return val4.position; } return null; } if (!((Object)(object)val2 != (Object)null)) { return null; } return ((Component)val2).transform.position; } EnemyAI val5 = (((Object)(object)val != (Object)null) ? val.mainScript : null); if (!((Object)(object)val5 != (Object)null)) { return null; } return ((Component)val5).transform.position; } } internal readonly struct DamageSourceRecord { internal readonly object Owner; internal readonly Vector3 Point; internal readonly bool IsSet; internal static DamageSourceRecord None => default(DamageSourceRecord); private DamageSourceRecord(object owner, Vector3 point) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) Owner = owner; Point = point; IsSet = true; } internal static DamageSourceRecord AtPoint(Vector3 point) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return new DamageSourceRecord(null, point); } internal static DamageSourceRecord Deferred(object owner) { //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) if (owner == null) { return None; } return new DamageSourceRecord(owner, default(Vector3)); } } internal static class DamageSourceResolver { private const float ForceFallbackDistance = 2f; internal static DamageSourceRecord Current; internal static DamageSourceRecord Enter(DamageSourceRecord record) { DamageSourceRecord current = Current; Current = record; return current; } internal static void Exit(DamageSourceRecord previous) { Current = previous; } internal static Vector3? ScopedPoint(DamageSourceRecord record, Func<object, Vector3?> ownerPosition) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (!record.IsSet) { return null; } if (record.Owner == null) { return record.Point; } return ownerPosition(record.Owner); } internal static Vector3? Resolve(Vector3? scopedPoint, Vector3 force, CauseOfDeath cause, Vector3 playerPosition) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (scopedPoint.HasValue) { return scopedPoint; } if (((Vector3)(ref force)).sqrMagnitude > 0f && !IsDirectionless(cause)) { return playerPosition - ((Vector3)(ref force)).normalized * 2f; } return null; } internal static bool IsDirectionless(CauseOfDeath cause) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 if ((int)cause != 8 && (int)cause != 16) { return (int)cause == 2; } return true; } } internal static class DangerFeedbackDriver { private static bool _installed; private static bool _wasEnabled; internal static void Install(Harmony harmony) { if (!_installed) { _installed = true; _wasEnabled = false; ModuleTickRegistry.RegisterTeardown("com.y4ngz.ui", 450, "DangerFeedbackDriver", (Action)Uninstall); if (harmony != null) { DamageSourcePatches.Apply(harmony); } ModuleTickRegistry.RegisterTick("com.y4ngz.ui", 400, "DangerFeedbackDriver", (Action)Drive); } } private static void Uninstall() { _installed = false; _wasEnabled = false; } private static void Drive() { if (!DangerHudSettings.Enabled) { if (_wasEnabled) { _wasEnabled = false; PlayerDangerHud.DestroyInstance(); DirectionalDamageHud.DestroyInstance(); } return; } _wasEnabled = true; GameNetworkManager instance = GameNetworkManager.Instance; PlayerControllerB val = (((Object)(object)instance != (Object)null) ? instance.localPlayerController : null); if ((Object)(object)val != (Object)null) { PlayerDangerHud.UpdatePlayerState(val); } } } internal static class DangerHudSettings { internal const string ConfigSection = "Damage Feedback"; private static ConfigEntry<bool> _enabled; private static ConfigEntry<bool> _directionalDamageEnabled; private static ConfigEntry<bool> _lowHealthEnabled; private static ConfigEntry<bool> _heartbeatEnabled; private static ConfigEntry<int> _lowHealthThreshold; internal static bool Enabled => _enabled?.Value ?? true; internal static bool DirectionalDamageEnabled => _directionalDamageEnabled?.Value ?? true; internal static bool LowHealthEnabled => _lowHealthEnabled?.Value ?? true; internal static bool HeartbeatEnabled => _heartbeatEnabled?.Value ?? true; internal static int LowHealthThreshold => _lowHealthThreshold?.Value ?? 35; internal static ConfigEntry<bool> EnabledEntry => _enabled; internal static ConfigEntry<bool> DirectionalDamageEntry => _directionalDamageEnabled; internal static ConfigEntry<bool> LowHealthEntry => _lowHealthEnabled; internal static ConfigEntry<bool> HeartbeatEntry => _heartbeatEnabled; internal static ConfigEntry<int> LowHealthThresholdEntry => _lowHealthThreshold; internal static void BindConfig(ConfigFile config) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown _enabled = config.Bind<bool>("Damage Feedback", "Enabled", false, "Master switch for the damage feedback. Off: no low-health vignette, hit flash, hit-direction arc or heartbeat, whatever their own settings say."); _directionalDamageEnabled = config.Bind<bool>("Damage Feedback", "Hit Direction", true, "Show a short screen-space arc pointing toward the most likely damage source. Needs Enabled."); _lowHealthEnabled = config.Bind<bool>("Damage Feedback", "Low Health Vignette", true, "Show a pulsing red vignette while the local player's health is below the threshold. Needs Enabled."); _heartbeatEnabled = config.Bind<bool>("Damage Feedback", "Heartbeat", false, "Play the synthesized heartbeat while your health is far below the threshold, whether or not the low-health vignette is on. Needs Enabled."); _lowHealthThreshold = config.Bind<int>("Damage Feedback", "Low Health Threshold", 35, new ConfigDescription("Health value below which the low-health vignette and the heartbeat begin.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 99), Array.Empty<object>())); } } public sealed class DirectionalDamageHud : MonoBehaviour { private const float Duration = 0.95f; private static DirectionalDamageHud _instance; private static Sprite _arcSprite; private RectTransform _root; private RectTransform _arcTransform; private Image _arcImage; private RectTransform _layer; private PlayerControllerB _player; private float _shownAt = -999f; private float _damageScale = 1f; internal static void ShowFromWorldPosition(PlayerControllerB player, Vector3 sourcePosition, int damageNumber) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (GameplayUiVisibility.IsVisible && DangerHudSettings.Enabled && DangerHudSettings.DirectionalDamageEnabled && !((Object)(object)player == (Object)null) && !((Object)(object)player.gameplayCamera == (Object)null)) { DirectionalDamageHud directionalDamageHud = Ensure(); if (!((Object)(object)directionalDamageHud == (Object)null)) { directionalDamageHud.PositionArrow(player, sourcePosition, damageNumber); directionalDamageHud._player = player; directionalDamageHud._shownAt = Time.unscaledTime; ((Component)directionalDamageHud).gameObject.SetActive(true); directionalDamageHud.UpdateVisual(); } } } public static void DestroyInstance() { DirectionalDamageHud instance = _instance; _instance = null; if ((Object)(object)instance != (Object)null) { Object.Destroy((Object)(object)((Component)instance).gameObject); } } public static void SetPresentationVisible(bool visible) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_instance == (Object)null || visible)) { _instance._shownAt = -999f; if ((Object)(object)_instance._arcImage != (Object)null) { ((Graphic)_instance._arcImage).color = Y4ngzUiStyle.WithAlpha(Y4ngzUiStyle.Danger, 0f); } ((Component)_instance).gameObject.SetActive(false); } } private static DirectionalDamageHud Ensure() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) RectTransform val = CurrentEdgeLayer(); if ((Object)(object)_instance != (Object)null && _instance._layer == val) { return _instance; } DestroyInstance(); if ((Object)(object)HUDManager.Instance == (Object)null || (Object)(object)HUDManager.Instance.playerScreenTexture == (Object)null) { return null; } Canvas canvas = ((Graphic)HUDManager.Instance.playerScreenTexture).canvas; if ((Object)(object)canvas == (Object)null) { return null; } GameObject val2 = new GameObject("Y4NGZ_DirectionalDamageHud"); val2.transform.SetParent((Transform)(((Object)(object)val != (Object)null) ? ((object)val) : ((object)((Component)canvas).transform)), false); DirectionalDamageHud directionalDamageHud = val2.AddComponent<DirectionalDamageHud>(); directionalDamageHud._layer = val; directionalDamageHud.Build(); _instance = directionalDamageHud; return directionalDamageHud; } private static RectTransform CurrentEdgeLayer() { GameplayHudHost instance = GameplayHudHost.Instance; RectTransform val = (((Object)(object)instance != (Object)null) ? instance.EdgeAlertLayer : null); if (!((Object)(object)val != (Object)null)) { return null; } return val; } private void Build() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) _root = ((Component)this).gameObject.AddComponent<RectTransform>(); _root.anchorMin = Vector2.zero; _root.anchorMax = Vector2.one; _root.offsetMin = Vector2.zero; _root.offsetMax = Vector2.zero; GameObject val = new GameObject("DamageDirectionArc"); val.transform.SetParent(((Component)this).transform, false); _arcTransform = val.AddComponent<RectTransform>(); _arcTransform.anchorMin = new Vector2(0.5f, 0.5f); _arcTransform.anchorMax = new Vector2(0.5f, 0.5f); _arcTransform.pivot = new Vector2(0.5f, 0.5f); _arcTransform.sizeDelta = new Vector2(132f, 54f); _arcImage = val.AddComponent<Image>(); _arcImage.sprite = GetArcSprite(); ((Graphic)_arcImage).raycastTarget = false; ((Graphic)_arcImage).color = Y4ngzUiStyle.WithAlpha(Y4ngzUiStyle.Danger, 0f); ((Component)this).gameObject.SetActive(false); } private void PositionArrow(PlayerControllerB player, Vector3 sourcePosition, int damageNumber) { //IL_000b: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //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) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0144: 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) Transform transform = ((Component)player.gameplayCamera).transform; Vector3 val = sourcePosition - ((Component)player).transform.position; val.y = 0f; Vector3 forward = transform.forward; forward.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude < 0.001f) { forward = ((Component)player).transform.forward; } ((Vector3)(ref forward)).Normalize(); Vector3 right = transform.right; right.y = 0f; if (((Vector3)(ref right)).sqrMagnitude < 0.001f) { right = ((Component)player).transform.right; } ((Vector3)(ref right)).Normalize(); Vector2 down = default(Vector2); if (((Vector3)(ref val)).sqrMagnitude < 0.001f) { down = Vector2.down; } else { ((Vector3)(ref val)).Normalize(); ((Vector2)(ref down))..ctor(Vector3.Dot(right, val), Vector3.Dot(forward, val)); if (((Vector2)(ref down)).sqrMagnitude < 0.001f) { down = Vector2.down; } else { ((Vector2)(ref down)).Normalize(); } } float num = 270f; if ((Object)(object)_root != (Object)null) { Rect rect = _root.rect; if (((Rect)(ref rect)).width > 0f) { rect = _root.rect; if (((Rect)(ref rect)).height > 0f) { rect = _root.rect; float width = ((Rect)(ref rect)).width; rect = _root.rect; num = Mathf.Min(width, ((Rect)(ref rect)).height) * 0.36f; } } } _arcTransform.anchoredPosition = down * num; float num2 = Mathf.Atan2(down.y, down.x) * 57.29578f - 90f; ((Transform)_arcTransform).localRotation = Quaternion.Euler(0f, 0f, num2); _damageScale = Mathf.Lerp(0.9f, 1.25f, Mathf.Clamp01((float)damageNumber / 80f)); } private void Update() { UpdateVisual(); } private void UpdateVisual() { //IL_00b2: 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_00c8: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_arcImage == (Object)null) { return; } if (!GameplayUiVisibility.IsVisible || (Object)(object)_player == (Object)null || _player.isPlayerDead || !_player.isPlayerControlled) { SetPresentationVisible(visible: false); return; } ((Component)this).transform.SetAsLastSibling(); float num = Time.unscaledTime - _shownAt; if (num >= 0.95f) { ((Graphic)_arcImage).color = Y4ngzUiStyle.WithAlpha(Y4ngzUiStyle.Danger, 0f); ((Component)this).gameObject.SetActive(false); return; } float num2 = Mathf.Clamp01(num / 0.95f); float alpha = Mathf.Lerp(0.58f, 0f, num2 * num2); ((Graphic)_arcImage).color = Y4ngzUiStyle.WithAlpha(Y4ngzUiStyle.Danger, alpha); ((Transform)_arcTransform).localScale = Vector3.one * Mathf.Lerp(_damageScale * 1.12f, _damageScale, num2); } private static Sprite GetArcSprite() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_arcSprite != (Object)null) { return _arcSprite; } Texture2D val = new Texture2D(192, 96, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1, hideFlags = (HideFlags)61 }; Color val2 = default(Color); ((Color)(ref val2))..ctor(1f, 1f, 1f, 0f); for (int i = 0; i < 96; i++) { for (int j = 0; j < 192; j++) { val.SetPixel(j, i, val2); } } Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(96f, -67.2f); float num = 136.31999f; float num2 = 12f; float num3 = 0.46f; for (int k = 0; k < 96; k++) { for (int l = 0; l < 192; l++) { Vector2 val4 = new Vector2((float)l + 0.5f, (float)k + 0.5f) - val3; float num4 = Mathf.Abs(((Vector2)(ref val4)).magnitude - num); if (!(num4 > num2)) { float num5 = Mathf.Abs(Mathf.DeltaAngle(Mathf.Atan2(val4.y, val4.x) * 57.29578f, 90f)) * (MathF.PI / 180f); if (!(num5 > num3)) { float num6 = 1f - Mathf.Clamp01(num4 / num2); float num7 = 1f - Mathf.Clamp01((num5 - num3 * 0.72f) / (num3 * 0.28f)); float num8 = Mathf.Clamp01(num6 * num7); num8 = num8 * num8 * (3f - 2f * num8); val.SetPixel(l, k, new Color(1f, 1f, 1f, num8)); } } } } val.Apply(false, true); _arcSprite = Sprite.Create(val, new Rect(0f, 0f, 192f, 96f), new Vector2(0.5f, 0.5f)); ((Object)_arcSprite).hideFlags = (HideFlags)61; return _arcSprite; } } internal static class HudDropout { private sealed class Game : IHudDropoutHud { public void TurnHoldOn(HudManualHideHold hold) { if ((Object)(object)HUDManager.Instance != (Object)null) { HudHideHolds.TurnOn(hold, 0f); } } public void ReassertHold(HudManualHideHold hold) { hold.Reassert(HudHideHolds.QuotaGroup(), 0f); } public void SetGate(bool active, bool publish) { GameplayUiVisibility.SetInsanityDropout(active, publish); } public void Silence() { HudDropoutAudioPatch.Silence(HUDManager.Instance); } } private static readonly HudDropoutEffects Effects = new HudDropoutEffects(new HudDropoutModel(HudFlicker.NewSeed()), new Game()); private static bool _skipped; internal static bool LeadInFrame => Effects.Model.LeadInFrame; internal static void Step() { //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) if (!HudDropoutSettings.On && Effects.Model.Phase == HudDropoutPhase.Idle && Effects.Idle) { _skipped = true; if (Effects.Hold.Pending) { Effects.Hold.Pump(); } return; } HUDManager instance = HUDManager.Instance; if (_skipped) { _skipped = false; Effects.Reset(HudFlicker.NewSeed(), instance, publish: true); } PlayerControllerB val = HudManualHideKey.LocalPlayer(); bool flag = (Object)(object)val != (Object)null; StartOfRound instance2 = StartOfRound.Instance; TimeOfDay instance3 = TimeOfDay.Instance; HudDropoutInput hudDropoutInput = new HudDropoutInput { Enabled = HudDropoutSettings.On, HasLocal = (flag && (Object)(object)instance != (Object)null), Alive = (flag && !val.isPlayerDead), Controlled = (flag && val.isPlayerControlled), RoundLive = ((Object)(object)instance2 != (Object)null && (Object)(object)instance3 != (Object)null && HudDropoutModel.RoundLive(instance2.inShipPhase, instance2.shipIsLeaving, instance3.currentDayTimeStarted)), OtherTermHides = GameplayUiVisibility.OtherTermHides, FrameRoute = HudFlicker.Drives }; HudThemePackage active = HudThemePackages.Active; hudDropoutInput.Theme = (HudTheme)((active != null) ? ((int)active.Theme) : 0); hudDropoutInput.Share = (flag ? InsanityMeterReader.Share(val) : 0f); HudDropoutInput input = hudDropoutInput; Effects.Step(Time.unscaledTime, in input, instance); } internal static void End() { Effects.End(HUDManager.Instance, publish: true); } internal static void Reset(bool publish) { Effects.Reset(HudFlicker.NewSeed(), HUDManager.Instance, publish); } internal static void Teardown() { Effects.Teardown(HUDManager.Instance); _skipped = false; } } [HarmonyPatch] internal static class HudDropoutAudioPatch { private static IEnumerable<MethodBase> TargetMethods() { yield return AccessTools.Method(typeof(AudioSource), "PlayOneShot", new Type[1] { typeof(AudioClip) }, (Type[])null); yield return AccessTools.Method(typeof(AudioSource), "PlayOneShot", new Type[2] { typeof(AudioClip), typeof(float) }, (Type[])null); } [HarmonyPrefix] private static bool Prefix(AudioSource __instance, AudioClip clip) { if (HudDropoutCues.Silent) { return HudDropoutCues.Plays(__instance, clip); } return true; } internal static void Silence(HUDManager hud) { if (!((Object)(object)hud == (Object)null)) { HudDropoutCues.Begin(hud.UIAudio, hud.dialogueBoxSFX); HudDropoutCues.Add(hud.scanSFX); HudDropoutCues.Add(hud.addToScrapTotalSFX); HudDropoutCues.Add(hud.finishAddingToTotalSFX); HudDropoutCues.Add(hud.globalNotificationSFX); HudDropoutCues.Add(hud.tipsSFX); HudDropoutCues.Add(hud.warningSFX); HudDropoutCues.Add(hud.displayCollectedScrapSFX); HudDropoutCues.Add(hud.displayCollectedScrapSFXSmall); HudDropoutCues.Add(hud.radiationWarningAudio); HudDropoutCues.Add(hud.meteorShowerWarningAudio); HudDropoutCues.Add(hud.reachedQuotaSFX); HudDropoutCues.Add(hud.newProfitQuotaSFX); HudDropoutCues.Add(hud.OneDayToMeetQuotaSFX); HudDropoutCues.Add(hud.profitQuotaDaysLeftCalmSFX); StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance != (Object)null) { HudDropoutCues.Add(instance.HUDSystemAlertSFX); } SignalTranslator val = Object.FindObjectOfType<SignalTranslator>(); if ((Object)(object)val != (Object)null) { HudDropoutCues.Add(val.startTransmissionSFX); HudDropoutCues.Add(val.typeTextClips); HudDropoutCues.Add(val.finishTypingSFX); } } } } internal static class HudDropoutCues { internal const int MaxClips = 24; internal const int MaxLists = 4; private static readonly AudioClip[] Clips = (AudioClip[])(object)new AudioClip[24]; private static readonly AudioClip[][] Lists = new AudioClip[4][]; private static int _clipCount; private static int _listCount; private static AudioSource _ui; private static AudioSource _dialogue; internal static bool Silent; internal static void Begin(AudioSource ui, AudioSource dialogue) { End(); _ui = ui; _dialogue = dialogue; Silent = true; } internal static void Add(AudioClip clip) { if (clip != null && _clipCount < 24) { Clips[_clipCount++] = clip; } } internal static void Add(AudioClip[] clips) { if (clips != null && _listCount < 4) { Lists[_listCount++] = clips; } } internal static void End() { Silent = false; _ui = null; _dialogue = null; Array.Clear(Clips, 0, _clipCount); Array.Clear(Lists, 0, _listCount); _clipCount = 0; _listCount = 0; } internal static bool Plays(AudioSource source, AudioClip clip) { if (!Silent || source == null) { return true; } if (source == _dialogue) { return (Object)(object)_dialogue == (Object)null; } if (source != _ui || (Object)(object)_ui == (Object)null) { return true; } if (clip == null) { return true; } for (int i = 0; i < _clipCount; i++) { if (Clips[i] == clip) { return (Object)(object)clip == (Object)null; } } for (int j = 0; j < _listCount; j++) { AudioClip[] array = Lists[j]; for (int k = 0; k < array.Length; k++) { if (array[k] == clip) { return (Object)(object)clip == (Object)null; } } } return true; } } internal interface IHudDropoutHud { void TurnHoldOn(HudManualHideHold hold); void ReassertHold(HudManualHideHold hold); void SetGate(bool active, bool publish); void Silence(); } internal sealed class HudDropoutEffects { private readonly IHudDropoutHud _game; private bool _gone; private float _factor = 1f; internal HudDropoutModel Model { get; } internal HudManualHideHold Hold { get; } = new HudManualHideHold("Y4NGZUI.InsanityDropout"); internal bool Idle { get { if (!_gone) { return _factor == 1f; } return false; } } internal HudDropoutEffects(HudDropoutModel model, IHudDropoutHud game) { Model = model; _game = game; } internal void Step(float now, in HudDropoutInput input, HUDManager hud) { if (Hold.Replaced(hud)) { Model.End(); } Model.Step(now, in input); Apply(hud, publish: true); Hold.Pump(); } internal void End(HUDManager hud, bool publish) { Model.End(); Apply(hud, publish); } internal void Reset(uint seed, HUDManager hud, bool publish) { Model.Reset(seed); Apply(hud, publish); } internal void Teardown(HUDManager hud) { End(hud, publish: false); Hold.Teardown(); } private void Apply(HUDManager hud, bool publish) { bool gone = Model.Gone; if (gone != _gone) { _gone = gone; if (gone) { _game.TurnHoldOn(Hold); _game.SetGate(active: true, publish: true); _game.Silence(); } else { Hold.Release(0f); _game.SetGate(active: false, publish); HudDropoutCues.End(); } } else if (gone) { _game.ReassertHold(Hold); } float stockFactor = Model.StockFactor; if (stockFactor != _factor) { _factor = stockFactor; HudOpacity.SetDropout(stockFactor, hud); } } } internal enum HudDropoutPhase { Idle, LeadIn, Gone } internal struct HudDropoutInput { internal bool Enabled; internal bool HasLocal; internal bool Alive; internal bool Controlled; internal bool RoundLive; internal bool OtherTermHides; internal bool FrameRoute; internal HudTheme Theme; internal float Share; } internal sealed class HudDropoutModel { internal const float OnsetInsanity = 0.4f; internal const float OnsetRearm = 0.35f; internal const float MaxInsanity = 0.99f; internal const float MaxRearm = 0.9f; internal const float LeadInSeconds = 1.5f; internal const float GoneMinSeconds = 3f; internal const float GoneMaxSeconds = 4f; internal const float LongerMinSeconds = 7f; internal const float LongerMaxSeconds = 8f; internal const float FaultMinSeconds = 0.03f; internal const float FaultMaxSeconds = 0.15f; internal const float OnLongestSeconds = 0.25f; internal const float OnShortestSeconds = 0.04f; internal const float OnJitterMin = 0.6f; internal const float OnJitterMax = 1.4f; internal const float OnLevelMin = 0.9f; internal const float DipLevelMin = 0.25f; internal const float DipLevelMax = 0.6f; internal const float CutShare = 0.5f; internal const int MaxSegments = 64; private const int SaltGone = 1; private const int SaltLastCut = 2; private const int SaltLength = 3; private const int SaltLevel = 4; private const int SaltKind = 5; private readonly float[] _segmentEnd = new float[64]; private readonly float[] _segmentLevel = new float[64]; private int _segments; private int _segment; private uint _seed; private int _dropouts; private bool _onsetArmed; private bool _maxArmed; private bool _longerNext; private float _start; private float _goneEnd; private bool _route; private HudTheme _theme; internal HudDropoutPhase Phase { get; private set; } internal bool Longer { get; private set; } internal bool Gone => Phase == HudDropoutPhase.Gone; internal bool LeadInFrame { get { if (Phase == HudDropoutPhase.LeadIn) { return _route; } return false; } } internal float StockFactor { get; private set; } = 1f; internal float GoneSeconds { get; private set; } internal int Dropouts => _dropouts; internal int Segments => _segments; internal HudDropoutModel(uint seed) { Reset(seed); } internal float SegmentEnd(int index) { return _segmentEnd[index]; } internal float SegmentLevel(int index) { return _segmentLevel[index]; } internal static bool RoundLive(bool inShipPhase, bool shipIsLeaving, bool dayStarted) { return !inShipPhase && !shipIsLeaving && dayStarted; } internal void Step(float now, in HudDropoutInput input) { //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) if (!input.RoundLive) { if (Phase != HudDropoutPhase.Idle) { End(); } _onsetArmed = false; _maxArmed = false; _longerNext = false; return; } bool flag = input.Enabled && input.HasLocal && input.Alive && input.Controlled && !input.OtherTermHides; if (Phase != HudDropoutPhase.Idle) { if (!flag || input.FrameRoute != _route || input.Theme != _theme) { End(); } else { Advance(now); } } float share = input.Share; if (share < 0.35f) { _onsetArmed = true; } if (share < 0.9f) { _maxArmed = true; } bool flag2 = _onsetArmed && share >= 0.4f; bool flag3 = _maxArmed && share >= 0.99f; if ((flag2 || flag3) && (Phase != HudDropoutPhase.Idle || flag)) { if (flag2) { _onsetArmed = false; } if (flag3) { _maxArmed = false; } if (Phase == HudDropoutPhase.Idle) { Begin(now, in input); } } } internal void End() { StockFactor = 1f; Phase = HudDropoutPhase.Idle; } internal void Reset(uint seed) { End(); _seed = seed; _dropouts = 0; _onsetArmed = false; _maxArmed = false; _longerNext = false; } private void Begin(float now, in HudDropoutInput input) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) uint seed = _seed + (uint)(_dropouts * -1640531527); _dropouts++; Longer = _longerNext; _longerNext = true; GoneSeconds = (Longer ? Lerp(7f, 8f, HudFlickerModel.Draw(seed, 0, 1)) : Lerp(3f, 4f, HudFlickerModel.Draw(seed, 0, 1))); _route = input.FrameRoute; _theme = input.Theme; _start = now; _goneEnd = now + 1.5f + GoneSeconds; FillBulb(seed); Phase = HudDropoutPhase.LeadIn; Advance(now); } private void Advance(float now) { if (Phase == HudDropoutPhase.LeadIn) { float num = now - _start; if (num < 1.5f) { StockFactor = (_route ? 1f : Bulb(num)); return; } StockFactor = 1f; Phase = HudDropoutPhase.Gone; } if (now >= _goneEnd) { End(); } } private float Bulb(float seconds) { while (_segment < _segments - 1 && seconds >= _segmentEnd[_segment]) { _segment++; } return _segmentLevel[_segment]; } private void FillBulb(uint seed) { float num = 1.5f - Lerp(0.03f, 0.15f, HudFlickerModel.Draw(seed, 0, 2)); float num2 = 0f; int num3 = 0; while (num3 < 63) { float num4; float num5; if ((num3 & 1) == 0) { num4 = Lerp(0.25f, 0.04f, num2 / 1.5f) * Lerp(0.6f, 1.4f, HudFlickerModel.Draw(seed, num3, 3)); num5 = Lerp(0.9f, 1f, HudFlickerModel.Draw(seed, num3, 4)); } else { num4 = Lerp(0.03f, 0.15f, HudFlickerModel.Draw(seed, num3, 3)); num5 = ((num3 > 1 && HudFlickerModel.Draw(seed, num3, 5) < 0.5f) ? 0.02f : Lerp(0.25f, 0.6f, HudFlickerModel.Draw(seed, num3, 4))); } num2 += num4; bool flag = num2 >= num; _segmentEnd[num3] = (flag ? num : num2); _segmentLevel[num3] = num5; num3++; if (flag) { break; } } _segmentEnd[num3] = 1.5f; _segmentLevel[num3] = 0.02f; _segments = num3 + 1; _segment = 0; } private static float Lerp(float a, float b, float t) { return a + (b - a) * t; } } internal static class HudDropoutSettings { internal const string Key = "Insanity HUD Dropout"; internal static ConfigEntry<bool> Enabled { get; private set; } internal static bool On { get { if (Enabled != null) { return Enabled.Value; } return false; } } internal static void BindConfig(ConfigFile config) { if (Enabled == null && config != null) { Enabled = config.Bind<bool>("Theme", "Insanity HUD Dropout", true, "In every HUD theme: as insanity sets in, the HUD flickers, then goes dark for a few seconds; longer when insanity comes back or peaks. Off: the HUD never goes dark from insanity."); } } } internal interface IHudFlickerMember { HudFlickerSurface FlickerSurface { get; } bool FlickerShows { get; } void ReapplyFlicker(); } internal static class HudFlicker { private static uint _seeds; private static readonly HudFlickerModel Model = new HudFlickerModel(NewSeed(), HudThemeAudio.Out); private static readonly List<IHudFlickerMember> Members = new List<IHudFlickerMember>(16); private static float _appliedFactor = 1f; private static int _showing; private static bool _showingStale = true; private static bool _faultLogged; internal static bool Drives { get { if (ImmersiveFrame.Draws) { return (Object)(object)ImmersiveFrame.Plane != (Object)null; } return false; } } internal static float Multiplier(HudFlickerSurface surface) { return Model.Multiplier(surface); } internal static void Join(IHudFlickerMember member) { Members.Add(member); _showingStale = true; } internal static void Leave(IHudFlickerMember member) { Members.Remove(member); _showingStale = true; } internal static void PresenceChanged() { _showingStale = true; } internal static void Step() { //IL_0062: 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) long start = VisorFrameCost.Begin(); PlayerControllerB val = HudManualHideKey.LocalPlayer(); StartOfRound instance = StartOfRound.Instance; TimeOfDay instance2 = TimeOfDay.Instance; HudFlickerInput hudFlickerInput = new HudFlickerInput { Alive = ((Object)(object)val != (Object)null && !val.isPlayerDead), HudShown = GameplayUiVisibility.IsVisible, FrameRoute = Drives }; HudThemePackage active = HudThemePackages.Active; hudFlickerInput.Theme = (HudTheme)((active != null) ? ((int)active.Theme) : 0); hudFlickerInput.RoundLive = (Object)(object)instance != (Object)null && (Object)(object)instance2 != (Object)null && HudDropoutModel.RoundLive(instance.inShipPhase, instance.shipIsLeaving, instance2.currentDayTimeStarted); hudFlickerInput.FearWeight = FearWeight(); HudFlickerInput input = hudFlickerInput; if (input.Alive && input.HudShown) { if (input.FrameRoute) { RefreshShowing(); input.Insanity = InsanityMeterReader.Share(val); input.Light = ImmersiveFrameSettings.Light; input.HitBrightness = HudHitFlicker.ModelBrightness; input.Showing = _showing; input.LeadIn = HudDropout.LeadInFrame; } else { input.Immersion = HudFlickerSwitches.StockFear; } } Model.Step(Time.unscaledTime, in input); int changed = Model.Changed; if (changed != 0) { Reapply(changed); } ApplyFactor(Model.StockFactor); VisorFrameCost.End(8, start); } internal static void Clear() { int num = Model.Reset(NewSeed()); if (num != 0) { Reapply(num); } ApplyFactor(Model.StockFactor); } private static void RefreshShowing() { if (!_showingStale) { return; } _showing = 0; for (int i = 0; i < Members.Count; i++) { if (Members[i].FlickerShows) { _showing |= HudFlickerModel.Bit(Members[i].FlickerSurface); } } _showingStale = false; } private static void ApplyFactor(float factor) { if (factor != _appliedFactor) { _appliedFactor = factor; HudOpacity.SetFlicker(factor, HUDManager.Instance); } } private static float FearWeight() { HUDManager instance = HUDManager.Instance; Volume val = (((Object)(object)instance != (Object)null) ? instance.insanityScreenFilter : null); if (!((Object)(object)val != (Object)null)) { return 0f; } return val.weight; } private static void Reapply(int changed) { for (int i = 0; i < Members.Count; i++) { IHudFlickerMember hudFlickerMember = Members[i]; if ((changed & HudFlickerModel.Bit(hudFlickerMember.FlickerSurface)) == 0) { continue; } try { hudFlickerMember.ReapplyFlicker(); } catch (Exception ex) { if (!_faultLogged) { _faultLogged = true; ManualLogSource log = UiPlugin.Log; if (log != null) { log.LogError((object)("[Y4NGZUI] HUD flicker: a surface's alpha write failed, the rest are still written: " + ex)); } } } } } internal static uint NewSeed() { return (uint)(Environment.TickCount + (int)(++_seeds) * -1640531527); } } internal enum HudFlickerSurface { None, Vitals, Perk, Clock, ContractCard, MoonCard, Hotbar, Chat, ControlTips, Notices, Pickup, Radar } internal struct HudFlickerInput { public bool Alive; public bool HudShown; public bool FrameRoute; public HudTheme Theme; public bool RoundLive; public float FearWeight; public bool Immersion; public float Insanity; public float Light; public float HitBrightness; public int Showing; public bool LeadIn; } internal sealed class HudFlickerModel { private sealed class Silent : IHudSoundOut { internal static readonly Silent Instance = new Silent(); public bool Play(HudVoice voice, HudSound sound, bool loop) { return false; } public bool PlayOneShot(HudVoice voice, HudSound sound) { return false; } public void SetGain(HudVoice voice, float gain) { } public void Stop(HudVoice voice) { } public bool TryHeard(HudVoice voice, out int samples, out int length) { samples = 0; length = 0; return false; } } internal const int SurfaceCount = 12; internal const float OnsetInsanity = 0.4f; internal const float GapSlowSeconds = 8f; internal const float GapFastSeconds = 2f; internal const float GapJitterMin = 0.75f; internal const float GapJitterMax = 1.25f; internal const float FearVisibleWeight = 0.2f; internal const float FearFadeSeconds = 0.6f; internal const int MaxDips = 5; internal const float DipsMinAtOnset = 1f; internal const float DipsMinAtFull = 2f; internal const float DipsMaxAtOnset = 1f; internal const float DipsMaxAtFull = 5f; internal const float DipSecondsMinAtOnset = 0.05f; internal const float DipSecondsMinAtFull = 0.04f; internal const float DipSecondsMaxAtOnset = 0.08f; internal const float DipSecondsMaxAtFull = 0.12f; internal const float DipGapMinSeconds = 0.04f; internal const float DipGapMaxSeconds = 0.12f; internal const float DepthMinAtOnset = 0.2f; internal const float DepthMinAtFull = 0.45f; internal const float DepthMaxAtOnset = 0.3f; internal const float DepthMaxAtFull = 0.8f; internal const float SurfaceDelayMax = 0.06f; internal const float ShareMin = 0.7f; internal const float ShareMax = 1f; internal const float FlutterDim = 0.2f; internal const float FlutterGapMin = 10f; internal const float FlutterGapMax = 20f; internal const float FlutterMinSeconds = 0.03f; internal const float FlutterMaxSeconds = 0.07f; private const int SaltGap = 1; private const int SaltCount = 2; private const int SaltPick = 3; private const int SaltDip = 16; private const int SaltDelay = 128; private const int SaltShare = 192; private const int SaltFlutterGap = 256; private const int SaltFlutterSurface = 257; private const int SaltFlutterLength = 258; private const int SaltFearDelay = 320; private const int SaltFearShare = 384; private const int RouteFrame = 1; private const int RouteStock = 2; private readonly IHudSoundOut _sound; private readonly float[] _multiplier = new float[12]; private readonly float[] _delay = new float[12]; private readonly float[] _share = new float[12]; private readonly int[] _fearDelay = new int[12]; private readonly float[] _fearShare = new float[12]; private readonly float[] _dipStart = new float[5]; private readonly float[] _dipEnd = new float[5]; private readonly float[] _dipDepth = new float[5]; private uint _seed; private int _bursts; private float _threshold; private float _phase; private float _lastNow; private bool _on; private bool _burstActive; private float _burstStart; private float _burstEnd; private int _dipCount; private HudSoundDipTable _burstTable; private int _burstAt; private bool _dirty; private int _changed; private float _flutterNext; private int _flutters; private bool _flutterActive; private float _flutterEnd; private int _flutterSurface; private float _flutterDip; private bool _leadIn; private bool _leadInBurst; private bool _afraid; private bool _fearLoop; private float _fearGain; private float _fadeStart; private int _fears; private int _fearAt = -1; private bool _fearWrapped; private int _route; private HudTheme _theme; private bool _roundLive; internal int Bursts => _bursts; internal int Changed => _changed; internal float StockFactor { get; private set; } private bool Quiet { get { if (!_burstActive && !_dirty && !_on && !_afraid && !_fearLoop && !_flutterActive && _flutterNext == float.NegativeInfinity && !_leadIn) { return StockFactor == 1f; } return false; } } internal HudFlickerModel(uint seed) : this(seed, Silent.Instance) { } internal HudFlickerModel(uint seed, IHudSoundOut sound) { _sound = sound; Reset(seed); } internal static int Bit(HudFlickerSurface surface) { return 1 << (int)surface; } internal float Multiplier(HudFlickerSurface surface) { if ((uint)surface >= 12u) { return 1f; } return _multiplier[(int)surface]; } internal float BurstDelay(HudFlickerSurface surface) { return _delay[(int)surface]; } internal float BurstShare(HudFlickerSurface surface) { return _share[(int)surface]; } internal int FearDelay(HudFlickerSurface surface) { return _fearDelay[(int)surface]; } internal float FearShare(HudFlickerSurface surface) { return _fearShare[(int)surface]; } internal static float Rise(float insanity01) { float num = (insanity01 - 0.4f) / 0.6f; if (!(num > 0f)) { return 0f; } if (!(num < 1f)) { return 1f; } return num; } internal static float FearRise(float weight) { float num = (weight - 0.2f) / 0.8f; if (!(num > 0f)) { return 0f; } if (!(num < 1f)) { return 1f; } return num; } internal static int DipCount(uint seed, int burst, float r) { int num = (int)(Lerp(1f, 2f, r) + 0.5f); int num2 = (int)(Lerp(1f, 5f, r) + 0.5f); int num3 = num + (int)(Draw(seed, burst, 2) * (float)(num2 - num + 1)); if (num3 >= num2) { return num2; } return num3; } internal int Reset(uint seed) { _sound.Stop(HudVoice.Fear); _sound.Stop(HudVoice.Burst); int num = 0; for (int i = 0; i < 12; i++) { if (_multiplier[i] != 1f) { num |= 1 << i; } _multiplier[i] = 1f; } _seed = seed; _bursts = 0; _threshold = Jitter(0); _phase = 0f; _on = false; _burstActive = false; _burstTable = null; _dirty = false; _flutterNext = float.NegativeInfinity; _flutters = 0; _flutterActive = false; _leadIn = false; _leadInBurst = false; _afraid = false; _fearLoop = false; _fears = 0; _fearAt = -1; StockFactor = 1f; return _changed = num; } internal void Step(float now, float insanity01, float light, float hitBrightness, int showing, bool leadIn = false, float fear = 0f) { _changed = 0; float num = VisorHudLightModel.ClampStrength(light); if (num > 0f) { if (_flutterActive && now >= _flutterEnd) { _flutterActive = false; } if (now >= _flutterNext) { Flutter(now, num, showing); } } else if (_flutterActive || _flutterNext != float.NegativeInfinity) { _flutterActive = false; _flutterNext = float.NegativeInfinity; } float num2 = ((hitBrightness < 1f) ? (1f - VisorHudLightPlan.SurfaceAlpha(hitBrightness, num)) : 0f); if (_leadIn && !leadIn) { EndLeadIn(); } _leadIn = leadIn; bool flag = num > 0f && insanity01 >= 0.4f; float num3 = (flag ? Rise(insanity01) : 0f); Fear(now, num > 0f && fear >= 0.2f); bool flag2 = leadIn || flag; if (!flag2 && num2 == 0f && !_flutterActive && !_dirty && !_fearLoop) { _on = false; EndBurst(); return; } if (flag2) { Advance(now, leadIn ? 1f : num3, leadIn); } else { _on = false; EndBurst(); _phase = 0f; } float num4 = FearRise(fear); if (num3 > num4) { num4 = num3; } HudSoundDipTable fearLoop = HudSoundDips.FearLoop; bool flag3 = false; for (int i = 1; i < 12; i++) { float num5 = BurstDip(i, now, num3); float num6 = ((num2 > num5) ? num2 : num5); if (_fearAt >= 0) { int num7 = _fearAt - _fearDelay[i]; float num8 = Depth(fearLoop.LevelAt((num7 < 0 && _fearWrapped) ? (num7 + fearLoop.Samples) : num7), num4) * _fearShare[i] * _fearGain; if (num8 > num6) { num6 = num8; } } if (_flutterActive && i == _flutterSurface && _flutterDip > num6) { num6 = _flutterDip; } float num9 = 1f - num6; if (num9 != _multiplier[i]) { _multiplier[i] = num9; _changed |= 1 << i; } flag3 = flag3 || num6 > 0f; } _dirty = flag3; } internal void Step(float now, in HudFlickerInput input) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) int num = (input.FrameRoute ? 1 : 2); bool flag = num != _route || input.Theme != _theme || (_roundLive && !input.RoundLive); _route = num; _theme = input.Theme; _roundLive = input.RoundLive; bool num2 = !input.Alive || !input.HudShown; int num3 = 0; if ((num2 || flag) && !Quiet) { num3 = Reset(Mix(_seed + 2654435769u)); } if (num2) { _changed = num3; return; } float fear = (input.RoundLive ? input.FearWeight : 0f); if (input.FrameRoute) { Step(now, input.Insanity, input.Light, input.HitBrightness, input.Showing, input.LeadIn, fear); } else { StepStock(now, fear, input.Immersion); } _changed |= num3; } private void StepStock(float now, float fear, bool on) { _changed = 0; Fear(now, on && fear >= 0.2f); StockFactor = ((_fearAt >= 0) ? (1f - Depth(HudSoundDips.FearLoop.LevelAt(_fearAt), FearRise(fear)) * _fearGain) : 1f); } private void Fear(float now, bool afraid) { if (afraid && !_afraid) { if (_fearLoop) { _fearGain = 1f; _sound.SetGain(HudVoice.Fear, 1f); } else { StartFear(); } } else if (!afraid && _fearLoop) { if (_afraid) { _fadeStart = now; } float num = 1f - (now - _fadeStart) / 0.6f; if (num <= 0f) { _sound.Stop(HudVoice.Fear); _fearLoop = false; } else if (num != _fearGain) { _fearGain = num; _sound.SetGain(HudVoice.Fear, num); } } _afraid = afraid; int fearAt = _fearAt; _fearAt = ((_fearLoop && _sound.TryHeard(HudVoice.Fear, out var samples, out var _)) ? samples : (-1)); if (_fearAt >= 0 && _fearAt < fearAt) { _fearWrapped = true; } } private void StartFear() { _fearLoop = _sound.Play(HudVoice.Fear, HudSound.FearLoop, loop: true); if (_fearLoop) { _fearGain = 1f; _fearWrapped = false; int index = _fears++; float num = 0.06f * (float)HudSoundDips.FearLoop.Frequency; for (int i = 1; i < 12; i++) { _fearDelay[i] = (int)(num * Unit(index, 320 + i)); _fearShare[i] = Lerp(0.7f, 1f, Unit(index, 384 + i)); } if (_burstTable != null) { EndBurst(); } } } private void Flutter(float now, float strength, int showing) { if (_flutterNext != float.NegativeInfinity) { int index = _flutters++; _flutterSurface = PickSurface(index, showing); _flutterActive = _flutterSurface != 0; if (_flutterActive) { _flutterDip = 1f - VisorHudLightPlan.SurfaceAlpha(1f - 0.2f * strength, strength); _flutterEnd = now + Lerp(0.03f, 0.07f, Unit(index, 258)); } } _flutterNext = now + Lerp(10f, 20f, Unit(_flutters, 256)); } private int PickSurface(int index, int showing) { int num = 0; for (int i = 1; i < 12; i++) { num += (showing >> i) & 1; } if (num == 0) { return 0; } int num2 = (int)(Unit(index, 257) * (float)num); if (num2 >= num) { num2 = num - 1; } for (int j = 1; j < 12; j++) { if (((showing >> j) & 1) != 0 && num2-- == 0) { return j; } } return 0; } private void EndLeadIn() { if (_leadInBurst) { _burstActive = false; } _leadInBurst = false; _on = false; _phase = 0f; _dirty = true; } private void Advance(float now, float r, bool backToBack) { if (!_on) { _on = true; _phase = 0f; _lastNow = now; } float num = now - _lastNow; _lastNow = now; if (num > 0f) { _phase += num / (8f + -6f * r); } if (_burstTable != null) { HearBurst(); } else if (_burstActive && now - _burstStart >= _burstEnd) { _burstActive = false; } if (!_burstActive && (backToBack || !(_phase < _threshold))) { if (backToBack) { StartBurst(now, r); } else { SoundBurst(r); } _leadInBurst = backToBack; } } private void HearBurst() { if (!_sound.TryHeard(HudVoice.Burst, out _burstAt, out var _) || _burstAt >= _burstTable.Samples) { _burstAt = -1; _burstTable = null; _burstActive = false; } } private void EndBurst() { if (_burstTable != null) { _sound.Stop(HudVoice.Burst); _burstTable = null; } _burstActive = false; } private void SoundBurst(float r) { int num = Schedule(); if (!_fearLoop) { int index = HudSoundDips.PickBurst(DipCount(_seed, num, r), Unit(num, 3)); if (_sound.Play(HudVoice.Burst, HudSounds.Burst(index), loop: false)) { DrawSurfaces(num); _burstTable = HudSoundDips.Burst(index); _burstAt = -1; _burstActive = true; } } } private void StartBurst(float now, float r) { int num = Schedule(); _dipCount = DipCount(_seed, num, r); float a = Lerp(0.05f, 0.04f, r); float b = Lerp(0.08f, 0.12f, r); float a2 = Lerp(0.2f, 0.45f, r); float b2 = Lerp(0.3f, 0.8f, r); float num2 = 0f; for (int i = 0; i < _dipCount; i++) { int num3 = 16 + 4 * i; _dipStart[i] = num2; num2 += Lerp(a, b, Unit(num, num3)); _dipEnd[i] = num2; _dipDepth[i] = Lerp(a2, b2, Unit(num, num3 + 2)); num2 += Lerp(0.04f, 0.12f, Unit(num, num3 + 1)); } _burstEnd = _dipEnd[_dipCount - 1] + 0.06f; DrawSurfaces(num); _burstStart = now; _burstActive = true; } private int Schedule() { int result = _bursts++; _threshold = Jitter(_bursts); _phase = 0f; return result; } private void DrawSurfaces(int burst) { for (int i = 1; i < 12; i++) { _delay[i] = 0.06f * Unit(burst, 128 + i); _share[i] = Lerp(0.7f, 1f, Unit(burst, 192 + i)); } } private float BurstDip(int s, float now, float r) { if (!_burstActive) { return 0f; } if (_burstTable == null) { return DipDepth(now - _burstStart - _delay[s]) * _share[s]; } if (_burstAt < 0) { return 0f; } return Depth(_burstTable.LevelAt(_burstAt - (int)(_delay[s] * (float)_burstTable.Frequency)), r) * _share[s]; } private float DipDepth(float t) { for (int i = 0; i < _dipCount; i++) { if (t >= _dipStart[i] && t < _dipEnd[i]) { return _dipDepth[i]; } } return 0f; } private static float Depth(float level, float r) { if (!(level < 0f)) { return Lerp(Lerp(0.2f, 0.45f, r), Lerp(0.3f, 0.8f, r), level); } return 0f; } private float Jitter(int burst) { return Lerp(0.75f, 1.25f, Unit(burst, 1)); } private static float Lerp(float a, float b, float t) { return a + (b - a) * t; } private float Unit(int index, int salt) { return Draw(_seed, index, salt); } internal static float Draw(uint seed, int index, int salt) { return (float)(Mix(Mix((seed ^ 0x9E3779B9u) + (uint)(index * -2048144789)) + (uint)(salt * -1028477387)) >> 8) * 5.9604645E-08f; } private static uint Mix(uint h) { h ^= h >> 16; h *= 2146121005; h ^= h >> 15; h *= 2221713035u; h ^= h >> 16; return h; } } internal static class HudFlickerSwitches { internal static bool StockFear => HelmetSettings.Immersion; } internal static class HudHitFlicker { private static readonly HudHitDip Dip = new HudHitDip(); private static float _appliedDip = 1f; private static float _modelBrightness = 1f; internal const float WakeShare = 0.7f; internal const float MaxWakeSeconds = 0.6f; internal const float LightDepth = 0.4f; internal const float HeavyDepth = 0.85f; internal const float LightStrength = 0.02f; internal const float MidStrength = 0.4f; internal const float HeavyStrength = 1f; internal const float LightLowest = 0.2f; internal const float MidLowest = 0.1f; internal const float HeavyLowest = 0.05f; internal static float ModelBrightness => _modelBrightness; internal static HudSound Sound => Dip.Sound; internal static float Strength => Dip.Strength; internal static HudHitStart Trigger(float strength01, bool accepted) { HUDManager instance = HUDManager.Instance; bool flag = (Object)(object)instance != (Object)null && GameplayUiVisibility.IsVisible; bool drives = HudFlicker.Drives; if (flag && HudHitDip.Takes(accepted, drives)) { HudIdleFade.Ping(instance.Inventory); HudIdleFade.Ping(instance.PlayerInfo); HudIdleFade.Ping(instance.Clock); HudIdleFade.Ping(instance.Compass); HudIdleFade.Ping(instance.Tooltips); } return Dip.Hit(HudThemeAudio.Out, Time.unscaledTime, strength01, accepted, drives, flag, flag && Showing(instance), Random.value); } internal static void Step() { if (!Settled(Dip.Running, _appliedDip, _modelBrightness)) { long start = VisorFrameCost.Begin(); Advance(); VisorFrameCost.End(8, start); } } private static void Advance() { HUDManager instance = HUDManager.Instance; PlayerControllerB val = HudManualHideKey.LocalPlayer(); if ((Object)(object)instance == (Object)null || (Object)(object)val == (Object)null || val.isPlayerDead || !GameplayUiVisibility.IsVisible || !HelmetSettings.Immersion) { Clear(); return; } Dip.Step(HudThemeAudio.Out, Time.unscaledTime, Dip.Waking && Showing(instance)); Route(HudFlicker.Drives, Dip.Factor, Dip.Brightness, out var opacityDip, out _modelBrightness); if (opacityDip != _appliedDip) { _appliedDip = opacityDip; HudOpacity.SetDip(opacityDip, instance); } } private static bool Showing(HUDManager hud) { if (HudIdleFade.Effective(hud.Inventory, 1f) >= 0.7f && HudIdleFade.Effective(hud.PlayerInfo, 1f) >= 0.7f && HudIdleFade.Effective(hud.Clock, 1f) >= 0.7f && HudIdleFade.Effective(hud.Compass, 1f) >= 0.7f) { return HudIdleFade.Effective(hud.Tooltips, 1f) >= 0.7f; } return false; } internal static void Clear() { Dip.Clear(HudThemeAudio.Out); _modelBrightness = 1f; if (_appliedDip != 1f) { _appliedDip = 1f; HudOpacity.SetDip(1f, HUDManager.Instance); } } internal static float Depth(float strength01) { return 0.4f + 0.45000002f * Clamp01(strength01); } internal static float LowestFor(float strength01) { if (!(strength01 > 0.02f)) { return 0.2f; } if (strength01 < 0.4f) { return 0.2f + -0.1f * (strength01 - 0.02f) / 0.38f; } if (strength01 < 1f) { return 0.1f + -0.05f * (strength01 - 0.4f) / 0.6f; } return 0.05f; } internal static float Clamp01(float value) { if (!(value > 0f)) { return 0f; } if (!(value < 1f)) { return 1f; } return value; } internal static void Route(bool frameDrives, float factor, float brightness, out float opacityDip, out float modelBrightness) { opacityDip = (frameDrives ? 1f : factor); modelBrightness = (frameDrives ? brightness : 1f); } internal static bool Settled(bool running, float appliedDip, float modelBrightness) { if (!running && appliedDip == 1f) { return modelBrightness == 1f; } return false; } } internal enum HudHitStart { Refused, Hidden, Waking, Started, Missing } internal sealed class HudHitDip { private enum Phase { Idle, Waking, Playing } private Phase _phase; private float _wokeAt; internal float Strength { get; private set; } internal HudSound Sound { get; private set; } internal bool Running => _phase != Phase.Idle; internal bool Waking => _phase == Phase.Waking; internal bool On { get; private set; } internal float Factor { get { if (!On) { return 1f; } return 1f - HudHitFlicker.Depth(Strength); } } internal float Brightness { get { if (!On) { return 1f; } return HudHitFlicker.LowestFor(Strength); } } internal static bool Jolts(bool hitJolt, bool immersion, int damage) { if (hitJolt && immersion) { return damage > 0; } return false; } internal static bool Takes(bool accepted, bool frameRoute) { return accepted || frameRoute; } internal static int Pick(float draw01) { int num = ((draw01 > 0f) ? ((int)(draw01 * 3f)) : 0); if (num >= 3) { return 2; } return num; } internal HudHitStart Hit(IHudSoundOut output, float now, float strength01, bool accepted, bool frameRoute, bool hudShown, bool showing, float draw01) { if (!Takes(accepted, frameRoute)) { return HudHitStart.Refused; } if (!hudShown) { return HudHitStart.Hidden; } float num = HudHitFlicker.Clamp01(strength01); if (_phase == Phase.Waking) { if (num > Strength) { Strength = num; } return HudHitStart.Waking; } Strength = ((_phase == Phase.Playing && Strength > num) ? Strength : num); Sound = HudSounds.Hit(Pick(draw01)); if (showing) { return Start(output); } output.Stop(HudVoice.Hit); _phase = Phase.Waking; _wokeAt = now; On = false; return HudHitStart.Waking; } internal void Step(IHudSoundOut output, float now, bool showing) { if (_phase == Phase.Waking) { if (now - _wokeAt >= 0.6f || showing) { Start(output); } } else if (_phase == Phase.Playing) { int samples; int length; bool flag = output.TryHeard(HudVoice.Hit, out samples, out length); On = flag && samples >= 0 && samples < length; if (!flag || samples >= length) { _phase = Phase.Idle; } } } internal void Clear(IHudSoundOut output) { output.Stop(HudVoice.Hit); _phase = Phase.Idle; On = false; Strength = 0f; } private HudHitStart Start(IHudSoundOut output) { On = false; if (!output.Play(HudVoice.Hit, Sound, loop: false)) { _phase = Phase.Idle; return HudHitStart.Missing; } _phase = Phase.Playing; return HudHitStart.Started; } } internal struct HelmetHitGap { internal const float Seconds = 0.8f; private bool _any; private float _time; private float _strength; internal bool Accepts(float now, float strength) { if (_any && now - _time < 0.8f && !(strength > _strength)) { return false; } _any = true; _time = now; _strength = strength; return true; } internal float Left(float now) { return 0.8f - (now - _time); } } internal sealed class HudSoundDipTable { private readonly int[] _startCs; private readonly int[] _endCs; private readonly float[] _level; internal int Frequency { get; } internal int Samples { get; } internal bool Loop { get; } internal int Count => _startCs.Length; internal HudSoundDipTable(int frequency, int samples, bool loop, int[] startCs, int[] endCs, float[] level) { Frequency = frequency; Samples = samples; Loop = loop; _startCs = startCs; _endCs = endCs; _level = level; } internal int StartCs(int i) { return _startCs[i]; } internal int EndCs(int i) { return _endCs[i]; } internal float Level(int i) { return _level[i]; } internal float LevelAt(int samples) { if (samples < 0) { return -1f; } if (Loop) { samples %= Samples; } else if (samples >= Samples) { return -1f; } int num = (int)((long)samples * 100L / Frequency); for (int i = 0; i < _startCs.Length; i++) { if (num >= _startCs[i] && num < _endCs[i]) { return _level[i]; } } return -1f; } } internal static class HudSoundDips { internal const int BurstCount = 6; private static readonly HudSoundDipTable FearLoopTable = new HudSoundDipTable(24000, 126240, loop: true, new int[11] { 10, 26, 62, 114, 160, 250, 283, 302, 484, 500, 517 }, new int[11] { 22, 38, 74, 126, 164, 259, 295, 314, 496, 512, 521 }, new float[11] { 1f, 0.829f, 0.623f, 1f, 0.38f, 1f, 0.5f, 0.464f, 0.856f, 0.56f, 0.296f }); private static readonly HudSoundDipTable Burst1aTable = new HudSoundDipTable(24000, 16800, loop: false, new int[4] { 3, 13, 31, 47 }, new int[4] { 7, 17, 43, 58 }, new float[4] { 1f, 0.25f, 1f, 0.829f }); private static readonly HudSoundDipTable Burst1bTable = new HudSoundDipTable(24000, 16800, loop: false, new int[2] { 4, 49 }, new int[2] { 16, 53 }, new float[2] { 1f, 0.374f }); private static readonly HudSoundDipTable Burst1cTable = new HudSoundDipTable(24000, 16800, loop: false, new int[4] { 3, 20, 36, 52 }, new int[4] { 15, 32, 48, 56 }, new float[4] { 0.8f, 0.641f, 1f, 0.423f }); private static readonly HudSoundDipTable Burst2aTable = new HudSoundDipTable(44100, 13671, loop: false, new int[2] { 3, 26 }, new int[2] { 15, 30 }, new float[2] { 0.987f, 0.377f }); private static readonly HudSoundDipTable Burst2bTable = new HudSoundDipTable(44100, 26019, loop: false, new int[3] { 3, 20, 42 }, new int[3] { 15, 32, 47 }, new float[3] { 1f, 0.999f, 0.377f }); private static readonly HudSoundDipTable Burst2cTable = new HudSoundDipTable(44100, 16317, loop: false, new int[3] { 3, 23, 31 }, new int[3] { 15, 27, 35 }, new float[3] { 0.69f, 0.216f, 0.737f }); private static readonly HudSoundDipTable[] Bursts = new HudSoundDipTable[6] { Burst1aTable, Burst1bTable, Burst1cTable, Burst2aTable, Burst2bTable, Burst2cTable }; internal static HudSoundDipTable FearLoop => FearLoopTable; internal static HudSoundDipTable Burst(int index) { return Bursts[index]; } internal static int PickBurst(int dipCount, float draw01) { int num = int.MaxValue; for (int i = 0; i < Bursts.Length; i++) { int num2 = Math.Abs(Bursts[i].Count - dipCount); if (num2 < num) { num = num2; } } int num3 = 0; for (int j = 0; j < Bursts.Length; j++) { if (Math.Abs(Bursts[j].Count - dipCount) == num) { num3++; } } int num4 = (int)(draw01 * (float)num3); if (num4 < 0) { num4 = 0; } else if (num4 >= num3) { num4 = num3 - 1; } for (int k = 0; k < Bursts.Length; k++) { if (Math.Abs(Bursts[k].Count - dipCount) == num) { if (num4 == 0) { return k; } num4--; } } return 0; } } internal enum HudVoice { Hit, Fear, Burst, Tick, Death } internal enum HudSound { HitFlicker1, HitFlicker2, HitFlicker3, FearLoop, InsanityBurst1a, InsanityBurst1b, InsanityBurst1c, InsanityBurst2a, InsanityBurst2b, InsanityBurst2c, ContractTick01, ContractTick02, ContractTick03, ContractTick04, ContractTick05, ContractTick06, ContractTick07, ContractTick08, ContractTick09, ContractTick10, ContractTick11, ContractTick12, ContractTick13, MoonCardType, DeathCue } internal static class HudSounds { internal const int Count = 25; internal const int HitCount = 3; internal const int ContractTickCount = 13; private const float HitVolume = 0.0621f; private const float Burst1Volume = 0.343f; private const float Burst2Volume = 0.33f; private const float TickVolume = 0.17f; private static readonly string[] Files = new string[25] { "hit-flicker-1.wav", "hit-flicker-2.wav", "hit-flicker-3.wav", "fear-flicker-loop-1.wav", "insanity-burst-1a.wav", "insanity-burst-1b.wav", "insanity-burst-1c.wav", "insanity-burst-2a.wav", "insanity-burst-2b.wav", "insanity-burst-2c.wav", "contract-tick-01.wav", "contract-tick-02.wav", "contract-tick-03.wav", "contract-tick-04.wav", "contract-tick-05.wav", "contract-tick-06.wav", "contract-tick-07.wav", "contract-tick-08.wav", "contract-tick-09.wav", "contract-tick-10.wav", "contract-tick-11.wav", "contract-tick-12.wav", "contract-tick-13.wav", "moon-card-type-1.wav", "death-screen-cue-1.ogg" }; private static readonly float[] Volumes = new float[25] { 0.0621f, 0.0621f, 0.0621f, 0.343f, 0.343f, 0.343f, 0.343f, 0.33f, 0.33f, 0.33f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.17f, 0.166f, 0.523f }; internal static string File(HudSound sound) { return Files[(int)sound]; } internal static float Volume(HudSound sound) { return Volumes[(int)sound]; } internal static HudSound Hit(int index) { return (HudSound)(0 + index); } internal static HudSound Burst(int index) { return (HudSound)(4 + index); } internal static HudSound ContractTick(int index) { return (HudSound)(10 + index); } } internal interface IHudSoundOut { bool Play(HudVoice voice, HudSound sound, bool loop); bool PlayOneShot(HudVoice voice, HudSound sound); void SetGain(HudVoice voice, float gain); void Stop(HudVoice voice); bool TryHeard(HudVoice voice, out int samples, out int length); } internal static class HudThemeAudio { private sealed class Voice { internal AudioSource Source; internal HudSound Sound; internal bool Playing; internal bool Loop; internal bool Reached; internal int Latency; } private sealed class Output : IHudSoundOut { bool IHudSoundOut.Play(HudVoice voice, HudSound sound, bool loop) { Voice voice2 = VoiceOf(voice); if (voice2 == null || (Object)(object)voice2.Source == (Object)null) { return false; } AudioClip val = ClipFor(sound); if ((Object)(object)val == (Object)null) { Silence(voice2); return false; } AudioSource source = voice2.Source; source.clip = val; source.loop = loop; source.volume = HudSounds.Volume(sound); source.Play(); voice2.Sound = sound; voice2.Playing = true; voice2.Loop = loop; voice2.Reached = false; voice2.Latency = LatencyFor(val.frequency); return true; } bool IHudSoundOut.PlayOneShot(HudVoice voice, HudSound sound) { Voice voice2 = VoiceOf(voice); if (voice2 == null || (Object)(object)voice2.Source == (Object)null) { return false; } AudioClip val = ClipFor(sound); if ((Object)(object)val == (Object)null) { return false; } AudioSource source = voice2.Source; if (!voice2.Playing) { source.volume = 1f; } float volume = source.volume; source.PlayOneShot(val, (volume > 0f) ? (HudSounds.Volume(sound) / volume) : 0f); return true; } void IHudSoundOut.SetGain(HudVoice voice, float gain) { Voice voice2 = VoiceOf(voice); if (voice2 != null && voice2.Playing && !((Object)(object)voice2.Source == (Object)null)) { float num = ((!(gain > 0f)) ? 0f : ((gain < 1f) ? gain : 1f)); voice2.Source.volume = HudSounds.Volume(voice2.Sound) * num; } } void IHudSoundOut.Stop(HudVoice voice) { Voice voice2 = VoiceOf(voice); if (voice2 != null) { Silence(voice2); } } bool IHudSoundOut.TryHeard(HudVoice voice, out int samples, out int length) { samples = 0; length = 0; Voice voice2 = VoiceOf(voice); if (voice2 == null || !voice2.Playing || (Object)(object)voice2.Source == (Object)null || !voice2.Source.isPlaying) { return false; } length = Lengths[(int)voice2.Sound]; samples = Heard(voice2.Source.timeSamples, voice2.Latency, length, voice2.Loop, ref voice2.Reached); return true; } } private const string TeardownLabel = "HudThemeAudio"; private const string ObjectName = "Y4NGZUI_HudThemeAudio"; private const int VoiceCount = 5; private const int SourcePriority = 0; private static readonly Voice[] Voices = new Voice[5] { new Voice(), new Voice(), new Voice(), new Voice(), new Voice() }; private static readonly AudioClip[] Clips = (AudioClip[])(object)new AudioClip[25]; private static readonly bool[] Copies = new bool[25]; private static readonly int[] Lengths = new int[25]; private static readonly bool[] MissingLogged = new bool[25]; private static bool _installed; private static GameObject _object; internal static readonly IHudSoundOut Out = new Output(); internal const float PadSeconds = 0.25f; internal static void Install() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown if (_installed) { return; } _installed = true; ModuleTickRegistry.RegisterTeardown("com.y4ngz.ui", 450, "HudThemeAudio", (Action)Uninstall); _object = new GameObject("Y4NGZUI_HudThemeAudio") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)(object)_object); for (int i = 0; i < 5; i++) { Voices[i].Source = AddSource(); } for (int j = 0; j < 25; j++) { int index = j; FacilityAudioClipLoader.Request(UiPlugin.CoroutineHost, HudSounds.File((HudSound)j), (Action<AudioClip>)delegate(AudioClip clip) { Loaded(index, clip); }); } } internal static float Seconds(HudSound sound) { AudioClip val = Clips[(int)sound]; if (!((Object)(object)val != (Object)null) || val.frequency <= 0) { return 0f; } return (float)Lengths[(int)sound] / (float)val.frequency; } private static void Uninstall() { if (!_installed) { return; } _installed = false; for (int i = 0; i < 5; i++) { Silence(Voices[i]); Voices[i].Source = null; } if ((Object)(object)_object != (Object)null) { Object.Destroy((Object)(object)_object); } _object = null; for (int j = 0; j < 25; j++) { if (Copies[j] && (Object)(object)Clips[j] != (Object)null) { Object.Destroy((Object)(object)Clips[j]); } Clips[j] = null; Copies[j] = false; Lengths[j] = 0; MissingLogged[j] = false; } } private static AudioSource AddSource() { AudioSource obj = _object.AddComponent<AudioSource>(); obj.playOnAwake = false; obj.spatialBlend = 0f; obj.priority = 0; obj.bypassListenerEffects = true; obj.bypassReverbZones = true; return obj; } private static void Loaded(int index, AudioClip clip) { if (!_installed || (Object)(object)clip == (Object)null || (Object)(object)Clips[index] != (Object)null) { return; } AudioClip val = clip; if (Padded((HudSound)index)) { val = PaddedCopy(clip); if ((Object)(object)val == (Object)null) { MissingLogged[index] = true; ManualLogSource log = UiPlugin.Log; if (log != null) { log.LogWarning((object)("[Y4NGZUI] HUD sound " + HudSounds.File((HudSound)index) + " could not be read for its padded copy; it stays silent and its HUD dip does not show.")); } return; } Copies[index] = true; } Lengths[index] = clip.samples; Clips[index] = val; } private static AudioClip PaddedCopy(AudioClip clip) { int channels = clip.channels; int samples = clip.samples; if (channels <= 0 || samples <= 0) { return null; } float[] array = new float[samples * channels]; if (!clip.GetData(array, 0)) { return null; } int num = samples + PadSamples(clip.frequency); Array.Resize(ref array, num * channels); AudioClip val = AudioClip.Create(((Object)clip).name + "-padded", num, channels, clip.frequency, false); if (val.SetData(array, 0)) { return val; } Object.Destroy((Object)(object)val); return null; } private static AudioClip ClipFor(HudSound sound) { if ((uint)sound >= 25u) { return null; } AudioClip obj = Clips[(int)sound]; if ((Object)(object)obj == (Object)null && !MissingLogged[(int)sound]) { MissingLogged[(int)sound] = true; ManualLogSource log = UiPlugin.Log; if (log == null) { return obj; } log.LogWarning((object)("[Y4NGZUI] HUD sound not loaded: " + HudSounds.File(sound) + " (looked for in Audio\\ beside Y4NGZUI.dll); it stays silent.")); } return obj; } private static Voice VoiceOf(HudVoice voice) { if ((uint)voice >= 5u) { return null; } return Voices[(int)voice]; } private static void Silence(Voice voice) { if ((Object)(object)voice.Source != (Object)null) { voice.Source.Stop(); } voice.Playing = false; } private static int LatencyFor(int clipFrequency) { int bufferLength = default(int); int numBuffers = default(int); AudioSettings.GetDSPBufferSize(ref bufferLength, ref numBuffers); return LatencySamples(bufferLength, numBuffers, clipFrequency, AudioSettings.outputSampleRate); } internal static bool Padded(HudSound sound) { if (sound !=