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 ImmersivePlanetIntroForVanillaHud v1.0.0
ImmersivePlanetIntroForVanillaHud.dll
Decompiled 2 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ImmersivePlanetIntroForVanillaHud")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ImmersivePlanetIntroForVanillaHud")] [assembly: AssemblyTitle("ImmersivePlanetIntroForVanillaHud")] [assembly: AssemblyVersion("1.0.0.0")] namespace ImmersivePlanetIntro; internal sealed class PlanetIntroOverlay : MonoBehaviour { private static readonly int IntroState = Animator.StringToHash("PlanetIntro"); private static readonly int IntroReplayState = Animator.StringToHash("PlanetIntro 0"); private static Type _canvasGroupType; private static PropertyInfo _canvasGroupAlpha; private HUDManager _hud; private GameObject _overlay; private RectTransform _plane; private PlanetCardBinding _card; private Transform _stockCard; private Component _stockGroup; private float _stockAlpha = 1f; private bool _stockHadGroup; private bool _stockHidden; private bool _showing; private float _hiddenAt = -1f; private float _nextBuildAt; private bool _warned; private bool _warnedRuntime; private void LateUpdate() { if (!Plugin.Enabled.Value) { if (_card != null) { Release(); } return; } if (!Y4ngzUiBridge.Available) { Y4ngzUiBridge.Probe(); if (!Y4ngzUiBridge.Available) { return; } } HUDManager instance = HUDManager.Instance; if (instance == null) { if (_card != null) { Release(); } return; } if (_card != null && instance != _hud) { Release(); } if (!Y4ngzUiBridge.IsVanillaTheme()) { if (_card != null) { Release(); } return; } if (IsPlanetIntroPlaying(instance)) { if (_card == null) { if (Time.time < _nextBuildAt) { return; } Build(instance); if (_card == null) { _nextBuildAt = Time.time + 2f; return; } } try { ApplyTexts(instance); if (!_showing) { _showing = true; _hiddenAt = -1f; _card.Play(0); HideStockCard(); if (Plugin.LogActivity.Value) { Plugin.Log.LogInfo((object)"[ImmersivePlanetIntro] Showing the Immersive planet card on the base game HUD."); } } _card.SetLayerAlpha(1f); return; } catch (Exception ex) { WarnRuntime(ex); return; } } if (_showing) { _showing = false; _hiddenAt = Time.time; try { _card.Play(1); _card.SetLayerAlpha(1f); return; } catch (Exception ex2) { WarnRuntime(ex2); return; } } if (_card == null || !(_hiddenAt >= 0f)) { return; } try { _card.SetLayerAlpha(1f); if (Time.time - _hiddenAt >= 0.35f) { Release(); } } catch (Exception ex3) { WarnRuntime(ex3); } } private void Build(HUDManager hud) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_012f: 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_0137: 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_0183: Unknown result type (might be due to invalid IL or missing references) Transform val = ResolveCanvasRoot(hud); Transform val2 = FindStockCard(hud); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { if (!_warned) { _warned = true; Plugin.Log.LogWarning((object)"[ImmersivePlanetIntro] Could not find the HUD canvas or the stock planet card; the base game intro is left untouched."); } return; } _hud = hud; _overlay = new GameObject("ImmersivePlanetIntro_Overlay", new Type[1] { typeof(RectTransform) }); RectTransform val3 = (RectTransform)_overlay.transform; ((Transform)val3).SetParent(val, false); val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.pivot = new Vector2(0.5f, 0.5f); val3.offsetMin = Vector2.zero; val3.offsetMax = Vector2.zero; ((Transform)val3).SetAsLastSibling(); _plane = (RectTransform)new GameObject("Plane", new Type[1] { typeof(RectTransform) }).transform; ((Transform)_plane).SetParent((Transform)(object)val3, false); RectTransform plane = _plane; RectTransform plane2 = _plane; RectTransform plane3 = _plane; Vector2 val4 = default(Vector2); ((Vector2)(ref val4))..ctor(0.5f, 0.5f); plane3.pivot = val4; Vector2 anchorMin = (plane2.anchorMax = val4); plane.anchorMin = anchorMin; _plane.sizeDelta = Vector2.zero; float num = ResolveCanvasHeight(val) / 1440f * 0.93f * Mathf.Max(0.25f, Plugin.CardScale.Value); ((Transform)_plane).localScale = new Vector3(num, num, 1f); _stockCard = val2; _card = Y4ngzUiBridge.Open(val2, _plane); if (_card == null) { _stockCard = null; Y4ngzUiBridge.RestorePlane(_plane); Object.Destroy((Object)(object)((Component)_plane).gameObject); Object.Destroy((Object)(object)_overlay); _plane = null; _overlay = null; _hud = null; if (!_warned) { _warned = true; Plugin.Log.LogWarning((object)"[ImmersivePlanetIntro] Y4NGZUI could not build the Immersive planet card (theme bundle not installed?); the base game intro is left untouched."); } } } private void WarnRuntime(Exception ex) { if (!_warnedRuntime) { _warnedRuntime = true; Plugin.Log.LogWarning((object)("[ImmersivePlanetIntro] The Immersive card stopped and the stock intro was restored: " + ex.Message)); } _nextBuildAt = Time.time + 2f; Release(); } private void ApplyTexts(HUDManager hud) { string text = TextOf(hud, "planetInfoHeaderText"); string summary = TextOf(hud, "planetInfoSummaryText"); string value = TextOf(hud, "planetRiskLevelText"); int num = text.IndexOf(':'); if (num >= 0) { _card.SetHeader(text.Substring(0, num + 1), text.Substring(num + 1).Trim()); } else { _card.SetHeader(string.Empty, text.Trim()); } _card.SetSummary(summary); _card.SetRisk(string.Empty, value); } private void HideStockCard() { if ((Object)(object)_stockCard == (Object)null || _stockHidden) { return; } if (_canvasGroupType == null) { _canvasGroupType = Type.GetType("UnityEngine.CanvasGroup, UnityEngine.UIModule"); if (_canvasGroupType != null) { _canvasGroupAlpha = _canvasGroupType.GetProperty("alpha", BindingFlags.Instance | BindingFlags.Public); } } if (_canvasGroupType == null || _canvasGroupAlpha == null) { return; } Component component = ((Component)_stockCard).GetComponent(_canvasGroupType); _stockHadGroup = (Object)(object)component != (Object)null; _stockGroup = (((Object)(object)component != (Object)null) ? component : ((Component)_stockCard).gameObject.AddComponent(_canvasGroupType)); if ((Object)(object)_stockGroup == (Object)null) { return; } try { _stockAlpha = (float)_canvasGroupAlpha.GetValue(_stockGroup, null); _canvasGroupAlpha.SetValue(_stockGroup, 0f, null); _stockHidden = true; } catch (Exception ex) { Plugin.Log.LogWarning((object)("[ImmersivePlanetIntro] Hiding the stock planet card failed: " + ex.Message)); } } private void RestoreStockCard() { if (!_stockHidden || (Object)(object)_stockGroup == (Object)null) { _stockHidden = false; _stockGroup = null; return; } try { _canvasGroupAlpha.SetValue(_stockGroup, _stockAlpha, null); if (!_stockHadGroup && (Object)(object)_stockGroup != (Object)null) { Object.Destroy((Object)(object)_stockGroup); } } catch { } _stockHidden = false; _stockGroup = null; } private void Release() { if (_card != null) { try { _card.Play(1); } catch { } _card.Dispose(); _card = null; } RestoreStockCard(); Y4ngzUiBridge.RestorePlane(_plane); if ((Object)(object)_plane != (Object)null) { Object.Destroy((Object)(object)((Component)_plane).gameObject); } if ((Object)(object)_overlay != (Object)null) { Object.Destroy((Object)(object)_overlay); } _plane = null; _overlay = null; _stockCard = null; _hud = null; _showing = false; _hiddenAt = -1f; } private static bool IsPlanetIntroPlaying(HUDManager hud) { //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) Animator planetIntroAnimator = hud.planetIntroAnimator; if ((Object)(object)planetIntroAnimator == (Object)null || !((Behaviour)planetIntroAnimator).isActiveAndEnabled) { return false; } AnimatorStateInfo currentAnimatorStateInfo = planetIntroAnimator.GetCurrentAnimatorStateInfo(0); if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash == IntroState || ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).shortNameHash == IntroReplayState) { return ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime < 1f; } return false; } private static string TextOf(object owner, string member) { object obj = Member(owner, member); object obj2; if (obj != null) { obj2 = Member(obj, "text") as string; if (obj2 == null) { return string.Empty; } } else { obj2 = string.Empty; } return (string)obj2; } private static Transform ResolveCanvasRoot(HUDManager hud) { object obj = Member(hud, "playerScreenTexture"); object obj2 = ((obj != null) ? Member(obj, "canvas") : null); object obj3 = ((obj2 != null) ? Member(obj2, "rootCanvas") : null); Component val = (Component)((obj3 is Component) ? obj3 : null); if (val != null) { return val.transform; } if ((Object)(object)hud.HUDContainer != (Object)null) { Transform parent = hud.HUDContainer.transform.parent; if (!((Object)(object)parent != (Object)null)) { return hud.HUDContainer.transform; } return parent; } return null; } private static float ResolveCanvasHeight(Transform parent) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); if (val != null) { Rect rect = val.rect; if (((Rect)(ref rect)).height > 1f) { rect = val.rect; return ((Rect)(ref rect)).height; } } return Screen.height; } private static Transform FindStockCard(HUDManager hud) { object obj = Member(hud, "PlayerInfo"); object obj2 = ((obj != null) ? Member(obj, "canvasGroup") : null); Component val = (Component)((obj2 is Component) ? obj2 : null); if (val != null) { Transform val2 = FindDescendant(val.transform, "CinematicGraphics"); if ((Object)(object)val2 != (Object)null) { return val2; } } Transform a = TransformOf(hud, "planetInfoHeaderText"); Transform b = TransformOf(hud, "planetInfoSummaryText"); Transform c = TransformOf(hud, "planetRiskLevelText"); Transform val3 = CommonAncestor(a, b, c); if ((Object)(object)val3 != (Object)null && (Object)(object)hud.HUDContainer != (Object)null) { Transform transform = hud.HUDContainer.transform; if ((Object)(object)val3 == (Object)(object)transform || transform.IsChildOf(val3)) { val3 = null; } } if ((Object)(object)val3 != (Object)null) { return val3; } object obj3 = Member(hud, "planetIntroAnimator"); Component val4 = (Component)((obj3 is Component) ? obj3 : null); if (val4 != null && ((Object)(object)hud.HUDContainer == (Object)null || (Object)(object)val4.transform != (Object)(object)hud.HUDContainer.transform)) { return val4.transform; } return null; } private static Transform TransformOf(object owner, string member) { object obj = Member(owner, member); Component val = (Component)((obj is Component) ? obj : null); if (val == null) { return null; } return val.transform; } private static Transform FindDescendant(Transform root, string name) { if ((Object)(object)root == (Object)null) { return null; } for (int i = 0; i < root.childCount; i++) { Transform child = root.GetChild(i); if (string.Equals(((Object)child).name, name, StringComparison.Ordinal)) { return child; } Transform val = FindDescendant(child, name); if ((Object)(object)val != (Object)null) { return val; } } return null; } private static Transform CommonAncestor(Transform a, Transform b, Transform c) { if ((Object)(object)a == (Object)null || (Object)(object)b == (Object)null || (Object)(object)c == (Object)null) { return null; } HashSet<Transform> hashSet = new HashSet<Transform>(); Transform val = a; while ((Object)(object)val != (Object)null) { hashSet.Add(val); val = val.parent; } Transform val2 = null; Transform val3 = b; while ((Object)(object)val3 != (Object)null) { if (hashSet.Contains(val3)) { val2 = val3; break; } val3 = val3.parent; } if ((Object)(object)val2 == (Object)null) { return null; } Transform val4 = c; while ((Object)(object)val4 != (Object)null) { if ((Object)(object)val4 == (Object)(object)val2) { return val2; } val4 = val4.parent; } return null; } private static object Member(object owner, string name) { if (owner == null) { return null; } Type type = owner.GetType(); while (type != null) { FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { try { return field.GetValue(owner); } catch { return null; } } PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { try { return property.GetValue(owner, null); } catch { return null; } } type = type.BaseType; } return null; } } [BepInPlugin("com.immersiveplanetintro.lethalcompany", "Immersive Planet Intro for the Vanilla HUD", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string PluginGuid = "com.immersiveplanetintro.lethalcompany"; public const string PluginName = "Immersive Planet Intro for the Vanilla HUD"; public const string PluginVersion = "1.0.0"; private const string Y4ngzUiGuid = "com.y4ngz.ui"; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<float> CardScale; internal static ConfigEntry<bool> LogActivity; internal static Plugin Instance { get; private set; } internal static ManualLogSource Log { get; private set; } private void Awake() { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the Immersive planet introduction from Y4NGZUI while the base game (Vanilla) HUD theme is selected. Hairline and Immersive already draw their own card, so this addon stays out of their way. On by default."); CardScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Card Scale", 1f, "Size of the planet card. 1 is its normal size on the visor, about 45% of the screen width at 1080p. 0.5 to 2."); LogActivity = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Log Activity", true, "Write one line to the BepInEx log when the card is shown or released. On by default."); GameObject val = new GameObject("ImmersivePlanetIntro_Host") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val); val.AddComponent<PlanetIntroOverlay>(); Y4ngzUiBridge.Probe(force: true); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Immersive Planet Intro for the Vanilla HUD 1.0.0 loaded. Y4NGZUI " + (Y4ngzUiBridge.Available ? "detected." : "not detected yet; waiting for it."))); } } internal sealed class PlanetCardBinding { private readonly object _card; private readonly MethodInfo _setHeader; private readonly MethodInfo _setSummary; private readonly MethodInfo _setRisk; private readonly MethodInfo _play; private readonly MethodInfo _setLayerAlpha; private readonly MethodInfo _dispose; private readonly Type _cueType; internal bool IsUsable { get { if (_card != null && _setHeader != null && _setSummary != null && _setRisk != null && _play != null && _setLayerAlpha != null) { return _cueType != null; } return false; } } internal PlanetCardBinding(object card, Type cardType) { _card = card; _setHeader = cardType.GetMethod("SetHeader", BindingFlags.Instance | BindingFlags.Public); _setSummary = cardType.GetMethod("SetSummary", BindingFlags.Instance | BindingFlags.Public); _setRisk = cardType.GetMethod("SetRisk", BindingFlags.Instance | BindingFlags.Public); _play = cardType.GetMethod("Play", BindingFlags.Instance | BindingFlags.Public); _setLayerAlpha = cardType.GetMethod("SetLayerAlpha", BindingFlags.Instance | BindingFlags.Public); _dispose = cardType.GetMethod("Dispose", BindingFlags.Instance | BindingFlags.Public); _cueType = ((_play != null) ? _play.GetParameters()[0].ParameterType : null); } internal void SetHeader(string label, string name) { _setHeader.Invoke(_card, new object[2] { label, name }); } internal void SetSummary(string text) { _setSummary.Invoke(_card, new object[1] { text }); } internal void SetRisk(string label, string value) { _setRisk.Invoke(_card, new object[2] { label, value }); } internal void Play(int cue) { _play.Invoke(_card, new object[1] { Enum.ToObject(_cueType, cue) }); } internal void SetLayerAlpha(float alpha) { _setLayerAlpha.Invoke(_card, new object[1] { alpha }); } internal void Dispose() { try { _dispose?.Invoke(_card, null); } catch (Exception ex) { Plugin.Log.LogWarning((object)("[ImmersivePlanetIntro] Releasing the planet card failed: " + ex.Message)); } } } internal static class Y4ngzUiBridge { private static bool _probeLogged; private static float _nextProbe; private static bool _missingLogged; private static Type _attachmentType; private static Type _attachmentBaseType; private static Type _frameType; private static Type _themePackagesType; private static ConstructorInfo _attachmentCtor; private static MethodInfo _open; private static FieldInfo _planeField; private static PropertyInfo _activeTheme; internal static bool Available { get { if (_attachmentType != null && _attachmentCtor != null && _open != null && _planeField != null) { return _activeTheme != null; } return false; } } internal static void Probe(bool force = false) { if (_attachmentType != null) { return; } float realtimeSinceStartup = Time.realtimeSinceStartup; if (!force && realtimeSinceStartup < _nextProbe) { return; } _nextProbe = realtimeSinceStartup + 1f; try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type type; try { type = assembly.GetType("Y4NGZUI.Themes.Immersive.VisorFramePlanetCardAttachment", throwOnError: false); } catch { continue; } if (type != null) { _attachmentType = type; _attachmentBaseType = type.BaseType; break; } } if (_attachmentType == null) { LogMissing(); return; } assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly2 in assemblies) { if (_frameType == null) { try { _frameType = assembly2.GetType("Y4NGZUI.Themes.Immersive.ImmersiveFrame", throwOnError: false); } catch { _frameType = null; } } if (_themePackagesType == null) { try { _themePackagesType = assembly2.GetType("Y4NGZCompany.Experience.UITheme.HudThemePackages", throwOnError: false); } catch { _themePackagesType = null; } } } if (_frameType == null || _themePackagesType == null) { _attachmentType = null; LogMissing(); return; } _attachmentCtor = _attachmentType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); _open = _attachmentBaseType.GetMethod("Open", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); _planeField = _frameType.GetField("_plane", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); _activeTheme = _themePackagesType.GetProperty("Active", BindingFlags.Static | BindingFlags.Public); if (_attachmentCtor == null || _open == null || _planeField == null || _activeTheme == null) { _attachmentType = null; LogMissing(); } else if (!_probeLogged) { _probeLogged = true; Plugin.Log.LogInfo((object)"[ImmersivePlanetIntro] Y4NGZUI's Immersive planet card was found. It will be reused while the base game HUD theme is selected."); } } catch (Exception ex) { _attachmentType = null; Plugin.Log.LogWarning((object)("[ImmersivePlanetIntro] Looking for Y4NGZUI failed: " + ex.Message)); } } internal static bool IsVanillaTheme() { if (_activeTheme == null) { return true; } try { return _activeTheme.GetValue(null, null) == null; } catch { return true; } } internal static PlanetCardBinding Open(Transform stockCard, RectTransform plane) { if (!Available || (Object)(object)stockCard == (Object)null || (Object)(object)plane == (Object)null) { return null; } try { object value = _planeField.GetValue(null); if (value != null && value != plane) { Plugin.Log.LogWarning((object)"[ImmersivePlanetIntro] Y4NGZUI already owns an Immersive frame plane; leaving the stock planet card alone for this landing."); return null; } _planeField.SetValue(null, plane); object obj = _attachmentCtor.Invoke(null); IList list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(_attachmentBaseType)); _open.Invoke(null, new object[3] { obj, stockCard, list }); PlanetCardBinding planetCardBinding = new PlanetCardBinding(obj, _attachmentType); if (!planetCardBinding.IsUsable) { planetCardBinding.Dispose(); Plugin.Log.LogWarning((object)"[ImmersivePlanetIntro] Y4NGZUI's planet card is missing a member this addon drives; leaving the stock planet card alone."); return null; } return planetCardBinding; } catch (Exception ex) { Plugin.Log.LogWarning((object)("[ImmersivePlanetIntro] Could not build the Immersive planet card: " + ex)); return null; } } internal static void RestorePlane(RectTransform plane) { if (_planeField == null || (Object)(object)plane == (Object)null) { return; } try { if (_planeField.GetValue(null) == plane) { _planeField.SetValue(null, null); } } catch { } } private static void LogMissing() { if (!_missingLogged) { _missingLogged = true; Plugin.Log.LogInfo((object)"[ImmersivePlanetIntro] Y4NGZUI (com.y4ngz.ui) is not loaded or its Immersive theme is missing. The addon idles until it is."); } } }