using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using MonoMod.Utils; using Photon.Pun; using Photon.Realtime; using SpongePEAK.Core.Config; using SpongePEAK.Core.Game; using SpongePEAK.Core.Logging; using SpongePEAK.Core.Patching; using SpongePEAK.Lib.Items; using SpongePEAK.Lib.Mods; using SpongePEAK.Lib.UI; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.Localization; using UnityEngine.SceneManagement; using UnityEngine.UI; using Zorro.Core; using Zorro.Settings; using Zorro.UI; [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("sponge")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) sponge")] [assembly: AssemblyDescription("Modding API tier: plugin base, game event bus and networking helpers.")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+ddcbf023fcb4c2065ad9b038910633cd4a3a93b0")] [assembly: AssemblyProduct("SpongePEAKLib")] [assembly: AssemblyTitle("com.sponge.peaklib")] [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 SpongePEAK.Lib.UI { public sealed class HudBar { private readonly RectTransform _root; private readonly RectTransform _fill; private readonly Image _fillImage; private float _value = 1f; public bool IsValid { get { if ((Object)(object)_root != (Object)null) { return (Object)(object)_fill != (Object)null; } return false; } } public RectTransform Transform => _root; public float Value { get { return _value; } set { //IL_002b: Unknown result type (might be due to invalid IL or missing references) _value = Mathf.Clamp01(value); if ((Object)(object)_fill != (Object)null) { _fill.anchorMax = new Vector2(_value, 1f); } } } public Color Color { get { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_fillImage != (Object)null)) { return Color.white; } return ((Graphic)_fillImage).color; } set { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_fillImage != (Object)null) { ((Graphic)_fillImage).color = value; } } } public static HudBar Create(string name, float width = 120f, float height = 10f) { Transform root = HudRoot.Root; if ((Object)(object)root == (Object)null) { return null; } return new HudBar(name, root, width, height); } private HudBar(string name, Transform parent, float width, float height) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); _root = (RectTransform)val.transform; ((Transform)_root).SetParent(parent, false); _root.sizeDelta = new Vector2(width, height); Image obj = val.AddComponent(); ((Graphic)obj).color = new Color(0f, 0f, 0f, 0.55f); ((Graphic)obj).raycastTarget = false; GameObject val2 = new GameObject("Fill", new Type[1] { typeof(RectTransform) }); _fill = (RectTransform)val2.transform; ((Transform)_fill).SetParent((Transform)(object)_root, false); _fill.anchorMin = new Vector2(0f, 0f); _fill.anchorMax = new Vector2(1f, 1f); _fill.offsetMin = new Vector2(1f, 1f); _fill.offsetMax = new Vector2(-1f, -1f); _fillImage = val2.AddComponent(); ((Graphic)_fillImage).color = Color.white; ((Graphic)_fillImage).raycastTarget = false; } public void SetVisible(bool visible) { if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf != visible) { ((Component)_root).gameObject.SetActive(visible); } } public void Destroy() { if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)((Component)_root).gameObject); } } } public static class HudRoot { private static Transform _root; private static ModLog _log; private const string RootName = "SpongePEAK_HUD"; public static bool IsReady => (Object)(object)_root != (Object)null; public static Transform Root { get { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown if ((Object)(object)_root != (Object)null) { return _root; } GUIManager instance = GUIManager.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.hudCanvas == (Object)null) { return null; } RectTransform val = (RectTransform)new GameObject("SpongePEAK_HUD", new Type[1] { typeof(RectTransform) }).transform; ((Transform)val).SetParent(((Component)instance.hudCanvas).transform, false); val.anchorMin = Vector2.zero; val.anchorMax = Vector2.one; val.offsetMin = Vector2.zero; val.offsetMax = Vector2.zero; ((Component)val).gameObject.AddComponent().blocksRaycasts = false; _root = (Transform)val; ModLog log = _log; if (log != null) { log.Debug((object)"HUD root attached to the game's hudCanvas."); } return _root; } } public static void SetLogger(ModLog log) { _log = log; } public static TextMeshProUGUI CreateLabel(string name, UiAnchor anchor = UiAnchor.TopLeft, float fontSize = 18f) { //IL_0025: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_004c: 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) Transform root = Root; if ((Object)(object)root == (Object)null) { return null; } GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(root, false); TextMeshProUGUI val3 = val.AddComponent(); ((TMP_Text)val3).fontSize = fontSize; ((Graphic)val3).color = Color.white; ((Graphic)val3).raycastTarget = false; ((TMP_Text)val3).outlineWidth = 0.2f; ((TMP_Text)val3).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue); ApplyAnchor(val2, val3, anchor); return val3; } private static void ApplyAnchor(RectTransform rect, TextMeshProUGUI text, UiAnchor anchor) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: 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) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) rect.sizeDelta = new Vector2(600f, 40f); switch (anchor) { case UiAnchor.TopLeft: SetAnchor(rect, new Vector2(0f, 1f)); rect.anchoredPosition = new Vector2(20f, -20f); ((TMP_Text)text).alignment = (TextAlignmentOptions)257; break; case UiAnchor.TopRight: SetAnchor(rect, new Vector2(1f, 1f)); rect.anchoredPosition = new Vector2(-20f, -20f); ((TMP_Text)text).alignment = (TextAlignmentOptions)260; break; case UiAnchor.BottomLeft: SetAnchor(rect, new Vector2(0f, 0f)); rect.anchoredPosition = new Vector2(20f, 20f); ((TMP_Text)text).alignment = (TextAlignmentOptions)1025; break; case UiAnchor.BottomRight: SetAnchor(rect, new Vector2(1f, 0f)); rect.anchoredPosition = new Vector2(-20f, 20f); ((TMP_Text)text).alignment = (TextAlignmentOptions)1028; break; case UiAnchor.Center: SetAnchor(rect, new Vector2(0.5f, 0.5f)); rect.anchoredPosition = Vector2.zero; ((TMP_Text)text).alignment = (TextAlignmentOptions)514; break; case UiAnchor.World: SetAnchor(rect, new Vector2(0.5f, 0.5f)); ((TMP_Text)text).alignment = (TextAlignmentOptions)514; break; } } private static void SetAnchor(RectTransform rect, Vector2 anchor) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) rect.anchorMin = anchor; rect.anchorMax = anchor; rect.pivot = anchor; } public static bool PositionAtWorldPoint(RectTransform rect, Vector3 worldPoint, Camera camera = null) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)rect == (Object)null) { return false; } if (camera == null) { camera = Camera.main; } if ((Object)(object)camera == (Object)null) { return false; } Vector3 val = camera.WorldToViewportPoint(worldPoint); if (val.z <= 0f) { return false; } Transform parent = ((Transform)rect).parent; RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null); if ((Object)(object)val2 == (Object)null) { return false; } Rect rect2 = val2.rect; Vector2 size = ((Rect)(ref rect2)).size; Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0.5f, 0.5f); rect.pivot = val3; Vector2 anchorMin = (rect.anchorMax = val3); rect.anchorMin = anchorMin; rect.anchoredPosition = new Vector2((val.x - 0.5f) * size.x, (val.y - 0.5f) * size.y); return true; } public static void Reset() { _root = null; } } public enum UiAnchor { TopLeft, TopRight, BottomLeft, BottomRight, Center, World } public static class MenuIntegration { private sealed class MenuButtonRequest { public string Label; public Action OnClick; } private static readonly List PauseButtons = new List(); private static readonly List MainMenuButtons = new List(); private static ModLog _log; private static bool _patched; public static void SetLogger(ModLog log) { _log = log; PeakStyle.SetLogger(log); } public static void AddPauseMenuButton(string label, Action onClick) { if (!string.IsNullOrEmpty(label) && onClick != null) { PauseButtons.Add(new MenuButtonRequest { Label = label, OnClick = onClick }); ModLog log = _log; if (log != null) { log.Debug((object)("Registered pause menu button '" + label + "'.")); } } } public static void AddMainMenuButton(string label, Action onClick) { if (!string.IsNullOrEmpty(label) && onClick != null) { MainMenuButtons.Add(new MenuButtonRequest { Label = label, OnClick = onClick }); ModLog log = _log; if (log != null) { log.Debug((object)("Registered main menu button '" + label + "'.")); } } } public static void Install(Harmony harmony) { if (_patched || harmony == null) { return; } try { harmony.PatchAll(typeof(MenuIntegrationPatches)); _patched = true; ModLog log = _log; if (log != null) { log.Debug((object)"Menu integration hooks installed."); } } catch (Exception ex) { ModLog log2 = _log; if (log2 != null) { log2.Exception("Failed to install menu integration hooks", ex); } } } internal static void PopulatePauseMenu(PauseMenuMainPage page) { if ((Object)(object)page == (Object)null || PauseButtons.Count == 0) { return; } try { Button resumeButton = page.resumeButton; if ((Object)(object)resumeButton == (Object)null) { return; } Transform parent = ((Component)resumeButton).transform.parent; if ((Object)(object)parent == (Object)null) { return; } foreach (MenuButtonRequest pauseButton in PauseButtons) { CreateOnce(parent, pauseButton); } } catch (Exception ex) { ModLog log = _log; if (log != null) { log.Exception("Failed to populate the pause menu", ex); } } } internal static void PopulateMainMenu(MainMenuMainPage page) { if ((Object)(object)page == (Object)null || MainMenuButtons.Count == 0) { return; } try { Button value = Traverse.Create((object)page).Field("m_settingsButton").GetValue