Decompiled source of SoulstoneArchipelago v1.3.0
BepInEx/plugins/SoulstoneAP.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Net; using System.Net.Sockets; using System.Net.WebSockets; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Threading; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using ECM2.Characters; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("SoulstoneAP")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+2c263f53ee530bbf37d2bbcb82afcfeaa6e8f653")] [assembly: AssemblyProduct("SoulstoneAP")] [assembly: AssemblyTitle("SoulstoneAP")] [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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 SoulstoneAP { public sealed class ApPanel : MonoBehaviour { private sealed class Field { public Image Background; public TextMeshProUGUI Text; public string Value = ""; public string Placeholder = ""; public bool IsPassword; private bool _active; public bool Active { get { return _active; } set { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) _active = value; if ((Object)(object)Background != (Object)null) { ((Graphic)Background).color = (value ? FieldActiveColor : FieldColor); } } } } private const float PanelWidth = 560f; private const float PanelHeight = 660f; private const float LogHeight = 132f; private const int MaxFieldLength = 120; private static readonly Color PanelColor = new Color(0.09f, 0.09f, 0.12f, 0.97f); private static readonly Color FieldColor = new Color(0.16f, 0.16f, 0.21f, 1f); private static readonly Color FieldActiveColor = new Color(0.21f, 0.26f, 0.34f, 1f); private static readonly Color AccentColor = new Color(0.29f, 0.52f, 0.78f, 1f); private static readonly Color MutedColor = new Color(0.62f, 0.64f, 0.7f, 1f); private static readonly Color ChatColor = new Color(0.22f, 0.25f, 0.33f, 1f); private Canvas _canvas; private GameObject _panel; private readonly List<Field> _fields = new List<Field>(); private Field _server; private Field _slot; private Field _password; private TextMeshProUGUI _statusText; private TextMeshProUGUI _errorText; private TextMeshProUGUI _connectLabel; private TextMeshProUGUI _logText; private RectTransform _logContent; private ScrollRect _logScroll; private int _logVersion = int.MinValue; private bool _showConsole; private Texture2D _logo; private float _bootTime; private bool _toggled; private bool _dismissed; private bool _autoOpened; private bool _built; private float _nextStatusRefresh; private string _error = ""; private static readonly Key[] PrintableKeys = BuildPrintableKeys(); private Field _activeField; private const int CapsLockVirtualKey = 20; private static ManualLogSource Log => Plugin.Logger; private void Awake() { _bootTime = Time.unscaledTime; LoadLogo(); } private void Update() { if (Keyboard.current != null && ((ButtonControl)Keyboard.current.f8Key).wasPressedThisFrame) { _toggled = !_toggled; _dismissed = false; } if (!_built) { if ((Object)(object)EventSystem.current == (Object)null && Time.unscaledTime - _bootTime < 10f) { return; } Build(); if (!_built) { return; } } if ((Object)(object)_canvas == (Object)null) { _built = false; return; } bool flag = !ProfileMissing(); if (!flag) { _autoOpened = false; } else if (!_autoOpened) { _autoOpened = true; if (Plugin.OpenPanelAfterSaveLoad.Value) { _toggled = true; _dismissed = false; } } bool flag2 = _toggled || (!_dismissed && Plugin.ShowPanelOnSlotScreen.Value && !flag); if (_panel.activeSelf != flag2) { _panel.SetActive(flag2); if (!flag2) { SetActiveField(null); } } if (flag2) { HandleLogScroll(); HandleClickOutside(); HandleTyping(); if (Time.unscaledTime >= _nextStatusRefresh) { _nextStatusRefresh = Time.unscaledTime + 0.25f; RefreshStatus(); RefreshFieldTexts(); } } } private static bool ProfileMissing() { try { return Global.PlayerProfile == null; } catch { return true; } } private static Key[] BuildPrintableKeys() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_0021: 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_0029: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Invalid comparison between Unknown and I4 //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_00b8: 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) List<Key> list = new List<Key>(); for (Key val = (Key)15; (int)val <= 40; val = (Key)(val + 1)) { list.Add(val); } for (Key val2 = (Key)41; (int)val2 <= 49; val2 = (Key)(val2 + 1)) { list.Add(val2); } list.Add((Key)50); list.Add((Key)1); list.Add((Key)8); list.Add((Key)7); list.Add((Key)9); list.Add((Key)6); list.Add((Key)13); list.Add((Key)14); list.Add((Key)5); list.Add((Key)11); list.Add((Key)12); list.Add((Key)10); list.Add((Key)4); list.Add((Key)82); list.Add((Key)78); list.Add((Key)81); for (Key val3 = (Key)84; (int)val3 <= 93; val3 = (Key)(val3 + 1)) { list.Add(val3); } return list.ToArray(); } private void HandleClickOutside() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) Mouse current = Mouse.current; if (current != null && current.leftButton.wasPressedThisFrame && _activeField != null && !((Object)(object)_panel == (Object)null)) { RectTransform component = _panel.GetComponent<RectTransform>(); if (!((Object)(object)component == (Object)null) && !RectTransformUtility.RectangleContainsScreenPoint(component, ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue(), (Camera)null)) { SetActiveField(null); } } } private void SetActiveField(Field field) { foreach (Field field2 in _fields) { field2.Active = field2 == field; } _activeField = field; if (field != null) { RefreshFieldText(field); } } [DllImport("user32.dll")] private static extern short GetKeyState(int virtualKey); private static bool CapsLockOn() { try { return (GetKeyState(20) & 1) != 0; } catch { return false; } } private void HandleTyping() { //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) Keyboard current = Keyboard.current; if (current == null || _activeField == null) { return; } bool flag = false; if (((ButtonControl)current.backspaceKey).wasPressedThisFrame && _activeField.Value.Length > 0) { _activeField.Value = _activeField.Value.Substring(0, _activeField.Value.Length - 1); flag = true; } bool flag2 = current.ctrlKey.isPressed || (current.leftCommandKey != null && ((ButtonControl)current.leftCommandKey).isPressed) || (current.rightCommandKey != null && ((ButtonControl)current.rightCommandKey).isPressed); if (flag2 && ((ButtonControl)current.vKey).wasPressedThisFrame) { PasteIntoActiveField(); } else if (flag2 && ((ButtonControl)current.cKey).wasPressedThisFrame) { CopyActiveField(); } if (!flag2) { bool isPressed = current.shiftKey.isPressed; bool caps = CapsLockOn(); Key[] printableKeys = PrintableKeys; foreach (Key val in printableKeys) { if (_activeField.Value.Length >= 120) { break; } KeyControl val2 = current[val]; if (val2 != null && ((ButtonControl)val2).wasPressedThisFrame) { char? c = KeyToChar(val, isPressed, caps); if (c.HasValue) { _activeField.Value += c.Value; flag = true; } } } } if (((ButtonControl)current.enterKey).wasPressedThisFrame || ((ButtonControl)current.numpadEnterKey).wasPressedThisFrame || ((ButtonControl)current.tabKey).wasPressedThisFrame) { SetActiveField(null); } if (flag && _activeField != null) { RefreshFieldText(_activeField); } } private void CopyActiveField() { try { GUIUtility.systemCopyBuffer = _activeField.Value ?? ""; _error = ""; } catch (Exception ex) { _error = "Clipboard unavailable on this build (" + ex.GetType().Name + ")."; } } private void PasteIntoActiveField() { Field activeField = _activeField; if (activeField == null) { return; } string systemCopyBuffer; try { systemCopyBuffer = GUIUtility.systemCopyBuffer; } catch (Exception ex) { _error = "Clipboard unavailable on this build (" + ex.GetType().Name + ")."; return; } if (string.IsNullOrEmpty(systemCopyBuffer)) { return; } char[] array = new char[systemCopyBuffer.Length]; int num = 0; string text = systemCopyBuffer; foreach (char c in text) { if (c >= ' ' && c != '\u007f') { array[num++] = c; } } if (num == 0) { return; } int num2 = 120 - activeField.Value.Length; if (num2 > 0) { if (num > num2) { num = num2; } activeField.Value += new string(array, 0, num); _error = ""; RefreshFieldText(activeField); } } private static char? KeyToChar(Key key, bool shift, bool caps) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected I4, but got Unknown //IL_007d: 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_00bd: Expected I4, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Invalid comparison between Unknown and I4 //IL_00bd: 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_00da: Expected I4, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) if ((int)key >= 15 && (int)key <= 40) { char c = (char)(97 + (key - 15)); return (shift ^ caps) ? char.ToUpperInvariant(c) : c; } if ((int)key >= 41 && (int)key <= 49) { int num = key - 41; return shift ? "!@#$%^&*("[num] : ((char)(49 + num)); } if ((int)key == 50) { return shift ? ')' : '0'; } if ((int)key >= 84 && (int)key <= 93) { return (char)(48 + (key - 84)); } switch (key - 1) { default: switch (key - 78) { case 4: return '.'; case 0: return '/'; case 3: return '-'; } break; case 0: return ' '; case 7: return shift ? '>' : '.'; case 6: return shift ? '<' : ','; case 8: return shift ? '?' : '/'; case 5: return shift ? ':' : ';'; case 12: return shift ? '_' : '-'; case 13: return shift ? '+' : '='; case 4: return shift ? '"' : '\''; case 10: return shift ? '{' : '['; case 11: return shift ? '}' : ']'; case 9: return shift ? '|' : '\\'; case 3: return shift ? '~' : '`'; case 1: case 2: break; } return null; } private void RefreshFieldTexts() { foreach (Field field in _fields) { RefreshFieldText(field); } } private void RefreshFieldText(Field field) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)field?.Text == (Object)null)) { string text = ((field.Active && (int)(Time.unscaledTime * 2f) % 2 == 0) ? "|" : ""); if (string.IsNullOrEmpty(field.Value)) { ((TMP_Text)field.Text).text = (field.Active ? text : field.Placeholder); ((Graphic)field.Text).color = new Color(0.5f, 0.52f, 0.58f, 1f); } else { ((Graphic)field.Text).color = Color.white; ((TMP_Text)field.Text).text = (field.IsPassword ? (new string('*', field.Value.Length) + text) : (field.Value + text)); } } } private void Build() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) try { GameObject val = new GameObject("SoulstoneAP_Canvas"); Object.DontDestroyOnLoad((Object)(object)val); _canvas = val.AddComponent<Canvas>(); _canvas.renderMode = (RenderMode)0; _canvas.sortingOrder = 25000; CanvasScaler obj = val.AddComponent<CanvasScaler>(); obj.uiScaleMode = (ScaleMode)1; obj.referenceResolution = new Vector2(1920f, 1080f); obj.matchWidthOrHeight = 0.5f; val.AddComponent<GraphicRaycaster>(); _panel = BuildPanel(val.transform); _built = true; ManualLogSource log = Log; if (log != null) { log.LogInfo((object)"AP: in-game panel built"); } } catch (Exception ex) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogError((object)("AP: panel build failed: " + ex)); } _built = false; } } private GameObject BuildPanel(Transform parent) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: 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_0135: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03dd: Unknown result type (might be due to invalid IL or missing references) //IL_03ec: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_044e: Unknown result type (might be due to invalid IL or missing references) //IL_0492: Unknown result type (might be due to invalid IL or missing references) //IL_04a1: Unknown result type (might be due to invalid IL or missing references) //IL_04b0: Unknown result type (might be due to invalid IL or missing references) //IL_04f3: Unknown result type (might be due to invalid IL or missing references) //IL_0502: Unknown result type (might be due to invalid IL or missing references) //IL_0511: Unknown result type (might be due to invalid IL or missing references) //IL_0542: Unknown result type (might be due to invalid IL or missing references) //IL_0551: Unknown result type (might be due to invalid IL or missing references) //IL_0560: Unknown result type (might be due to invalid IL or missing references) //IL_0591: Unknown result type (might be due to invalid IL or missing references) //IL_05a0: Unknown result type (might be due to invalid IL or missing references) //IL_05af: Unknown result type (might be due to invalid IL or missing references) //IL_05e0: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) //IL_05fe: Unknown result type (might be due to invalid IL or missing references) //IL_062f: Unknown result type (might be due to invalid IL or missing references) //IL_063e: Unknown result type (might be due to invalid IL or missing references) //IL_064d: Unknown result type (might be due to invalid IL or missing references) //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_069b: Unknown result type (might be due to invalid IL or missing references) //IL_06ae: Unknown result type (might be due to invalid IL or missing references) //IL_06c4: Unknown result type (might be due to invalid IL or missing references) //IL_06da: Unknown result type (might be due to invalid IL or missing references) //IL_0704: Unknown result type (might be due to invalid IL or missing references) //IL_0735: Unknown result type (might be due to invalid IL or missing references) //IL_074b: Unknown result type (might be due to invalid IL or missing references) //IL_0761: Unknown result type (might be due to invalid IL or missing references) //IL_076d: Unknown result type (might be due to invalid IL or missing references) //IL_0783: Unknown result type (might be due to invalid IL or missing references) //IL_079d: Unknown result type (might be due to invalid IL or missing references) //IL_07a9: Unknown result type (might be due to invalid IL or missing references) //IL_07bf: Unknown result type (might be due to invalid IL or missing references) //IL_07d5: Unknown result type (might be due to invalid IL or missing references) //IL_083b: Unknown result type (might be due to invalid IL or missing references) RectTransform val = MakeRect("SoulstoneAP_Panel", parent); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0.5f, 0.5f); val.anchoredPosition = Vector2.zero; val.sizeDelta = new Vector2(560f, 660f); ((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = PanelColor; if ((Object)(object)_logo != (Object)null) { RectTransform obj = MakeRect("Logo", (Transform)(object)val); ((Vector2)(ref val2))..ctor(0.5f, 1f); obj.anchorMax = val2; obj.anchorMin = val2; obj.pivot = new Vector2(0.5f, 1f); obj.anchoredPosition = new Vector2(0f, -14f); obj.sizeDelta = new Vector2(92f, 92f); Image obj2 = ((Component)obj).gameObject.AddComponent<Image>(); obj2.sprite = Sprite.Create(_logo, new Rect(0f, 0f, (float)((Texture)_logo).width, (float)((Texture)_logo).height), new Vector2(0.5f, 0.5f)); obj2.preserveAspect = true; ((Graphic)obj2).raycastTarget = false; } MakeText(val, "Title", "Archipelago", 26f, (TextAlignmentOptions)514, Color.white, new Vector2(0f, -108f), new Vector2(400f, 34f)); MakeText(val, "Subtitle", "Soulstone Survivors", 14f, (TextAlignmentOptions)514, MutedColor, new Vector2(0f, -136f), new Vector2(400f, 22f)); _server = MakeField(val, "Server", "localhost:38281", password: false, -172f); _slot = MakeField(val, "Slot", "slot name", password: false, -220f); _password = MakeField(val, "Password", "password (optional)", password: true, -268f); _server.Value = Plugin.Server.Value ?? ""; _slot.Value = Plugin.Slot.Value ?? ""; _password.Value = Plugin.Password.Value ?? ""; MakeButton(val, "ConnectButton", "Connect", AccentColor, new Vector2(-92f, -330f), new Vector2(160f, 40f), OnConnectPressed, out _connectLabel); MakeButton(val, "CloseButton", "Close", new Color(0.28f, 0.29f, 0.34f, 1f), new Vector2(96f, -330f), new Vector2(120f, 40f), OnClosePressed, out var _); _errorText = MakeText(val, "Error", "", 13f, (TextAlignmentOptions)514, new Color(0.95f, 0.55f, 0.55f, 1f), new Vector2(0f, -374f), new Vector2(520f, 20f)); _statusText = MakeText(val, "Status", "", 13f, (TextAlignmentOptions)514, MutedColor, new Vector2(0f, -398f), new Vector2(520f, 34f)); ((TMP_Text)_statusText).enableWordWrapping = true; MakeButton(val, "ChecksTab", "Checks", AccentColor, new Vector2(-96f, -436f), new Vector2(150f, 26f), delegate { SetView(0); }, out var labelText2); ((TMP_Text)labelText2).fontSize = 14f; MakeButton(val, "ConsoleTab", "Console", new Color(0.28f, 0.29f, 0.34f, 1f), new Vector2(64f, -436f), new Vector2(150f, 26f), delegate { SetView(1); }, out var labelText3); ((TMP_Text)labelText3).fontSize = 14f; MakeButton(val, "GlobalButton", "Global", new Color(0.25f, 0.37f, 0.52f, 1f), new Vector2(204f, -436f), new Vector2(104f, 26f), delegate { CheckListPanel.ShowGlobal(); }, out var labelText4); ((TMP_Text)labelText4).fontSize = 13f; MakeButton(val, "ChatHint", "Hint", ChatColor, new Vector2(-200f, -612f), new Vector2(92f, 24f), delegate { SendChat("!hint"); }, out var labelText5); ((TMP_Text)labelText5).fontSize = 11.5f; MakeButton(val, "ChatMissing", "Missing", ChatColor, new Vector2(-100f, -612f), new Vector2(92f, 24f), delegate { SendChat("!missing"); }, out var labelText6); ((TMP_Text)labelText6).fontSize = 11.5f; MakeButton(val, "ChatGoal", "Goal", ChatColor, new Vector2(0f, -612f), new Vector2(92f, 24f), delegate { SendChat("!goal"); }, out var labelText7); ((TMP_Text)labelText7).fontSize = 11.5f; MakeButton(val, "ChatRelease", "Release", ChatColor, new Vector2(100f, -612f), new Vector2(92f, 24f), delegate { SendChat("!release"); }, out var labelText8); ((TMP_Text)labelText8).fontSize = 11.5f; MakeButton(val, "ChatCollect", "Collect", ChatColor, new Vector2(200f, -612f), new Vector2(92f, 24f), delegate { SendChat("!collect"); }, out var labelText9); ((TMP_Text)labelText9).fontSize = 11.5f; RectTransform val3 = MakeRect("LogViewport", (Transform)(object)val); ((Vector2)(ref val2))..ctor(0.5f, 1f); val3.anchorMax = val2; val3.anchorMin = val2; val3.pivot = new Vector2(0.5f, 1f); val3.anchoredPosition = new Vector2(0f, -470f); val3.sizeDelta = new Vector2(500f, 132f); ((Graphic)((Component)val3).gameObject.AddComponent<Image>()).color = new Color(0.05f, 0.05f, 0.08f, 1f); ((Component)val3).gameObject.AddComponent<RectMask2D>(); RectTransform val4 = MakeRect("LogContent", (Transform)(object)val3); val4.anchorMin = new Vector2(0f, 1f); val4.anchorMax = new Vector2(1f, 1f); val4.pivot = new Vector2(0.5f, 1f); val4.anchoredPosition = Vector2.zero; val4.sizeDelta = new Vector2(0f, 132f); RectTransform val5 = MakeRect("LogText", (Transform)(object)val4); val5.anchorMin = Vector2.zero; val5.anchorMax = Vector2.one; val5.offsetMin = new Vector2(10f, 6f); val5.offsetMax = new Vector2(-10f, -6f); _logText = ((Component)val5).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)_logText).text = "nothing yet"; ((TMP_Text)_logText).fontSize = 13f; ((TMP_Text)_logText).alignment = (TextAlignmentOptions)257; ((Graphic)_logText).color = new Color(0.82f, 0.85f, 0.9f, 1f); ((TMP_Text)_logText).enableWordWrapping = true; ((TMP_Text)_logText).richText = true; ((Graphic)_logText).raycastTarget = false; _logContent = val4; _logScroll = ((Component)val3).gameObject.AddComponent<ScrollRect>(); _logScroll.content = val4; _logScroll.viewport = val3; _logScroll.horizontal = false; _logScroll.vertical = true; _logScroll.movementType = (MovementType)2; _logScroll.inertia = true; _logScroll.decelerationRate = 0.12f; _logScroll.scrollSensitivity = 0f; RefreshFieldTexts(); return ((Component)val).gameObject; } private Field MakeField(RectTransform parent, string name, string placeholder, bool password, float y) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0150: 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_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) RectTransform val = MakeRect(name + "Row", (Transform)(object)parent); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 1f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0.5f, 1f); val.anchoredPosition = new Vector2(0f, y); val.sizeDelta = new Vector2(500f, 40f); TextMeshProUGUI val3 = MakeText(val, name + "Label", name, 14f, (TextAlignmentOptions)4097, MutedColor, Vector2.zero, new Vector2(150f, 40f)); RectTransform rectTransform = ((TMP_Text)val3).rectTransform; RectTransform rectTransform2 = ((TMP_Text)val3).rectTransform; ((Vector2)(ref val2))..ctor(0f, 0.5f); rectTransform2.anchorMax = val2; rectTransform.anchorMin = val2; ((TMP_Text)val3).rectTransform.pivot = new Vector2(0f, 0.5f); ((TMP_Text)val3).rectTransform.anchoredPosition = Vector2.zero; RectTransform val4 = MakeRect(name + "Field", (Transform)(object)val); ((Vector2)(ref val2))..ctor(1f, 0.5f); val4.anchorMax = val2; val4.anchorMin = val2; val4.pivot = new Vector2(1f, 0.5f); val4.anchoredPosition = Vector2.zero; val4.sizeDelta = new Vector2(340f, 38f); Image val5 = ((Component)val4).gameObject.AddComponent<Image>(); ((Graphic)val5).color = FieldColor; RectTransform obj = MakeRect("Text", (Transform)(object)val4); obj.anchorMin = Vector2.zero; obj.anchorMax = Vector2.one; obj.offsetMin = new Vector2(10f, 4f); obj.offsetMax = new Vector2(-10f, -4f); ((Component)obj).gameObject.AddComponent<RectMask2D>(); TextMeshProUGUI val6 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val6).fontSize = 17f; ((Graphic)val6).color = Color.white; ((TMP_Text)val6).alignment = (TextAlignmentOptions)4097; ((TMP_Text)val6).enableWordWrapping = false; ((Graphic)val6).raycastTarget = false; Field field = new Field { Background = val5, Text = val6, Placeholder = placeholder, IsPassword = password }; _fields.Add(field); Button obj2 = ((Component)val4).gameObject.AddComponent<Button>(); ((Selectable)obj2).targetGraphic = (Graphic)(object)val5; ((Selectable)obj2).transition = (Transition)0; ((UnityEvent)obj2.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { SetActiveField(field); })); return field; } private Button MakeButton(RectTransform parent, string name, string label, Color color, Vector2 position, Vector2 size, Action onClick, out TextMeshProUGUI labelText) { //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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00fc: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = MakeRect(name, (Transform)(object)parent); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0.5f, 1f); obj.anchorMax = val; obj.anchorMin = val; obj.pivot = new Vector2(0.5f, 1f); obj.anchoredPosition = position; obj.sizeDelta = size; Image val2 = ((Component)obj).gameObject.AddComponent<Image>(); ((Graphic)val2).color = color; Button val3 = ((Component)obj).gameObject.AddComponent<Button>(); ((Selectable)val3).targetGraphic = (Graphic)(object)val2; ((UnityEvent)val3.onClick).AddListener(UnityAction.op_Implicit((Action)delegate { onClick(); })); TextMeshProUGUI val4 = MakeText(obj, name + "Label", label, 17f, (TextAlignmentOptions)514, Color.white, Vector2.zero, size); ((TMP_Text)val4).rectTransform.anchorMin = Vector2.zero; ((TMP_Text)val4).rectTransform.anchorMax = Vector2.one; ((TMP_Text)val4).rectTransform.offsetMin = Vector2.zero; ((TMP_Text)val4).rectTransform.offsetMax = Vector2.zero; ((Graphic)val4).raycastTarget = false; labelText = val4; return val3; } private static TextMeshProUGUI MakeText(RectTransform parent, string name, string content, float size, TextAlignmentOptions alignment, Color color, Vector2 position, Vector2 dimensions) { //IL_001a: 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_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = MakeRect(name, (Transform)(object)parent); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0.5f, 1f); obj.anchorMax = val; obj.anchorMin = val; obj.pivot = new Vector2(0.5f, 1f); obj.anchoredPosition = position; obj.sizeDelta = dimensions; TextMeshProUGUI obj2 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)obj2).text = content; ((TMP_Text)obj2).fontSize = size; ((TMP_Text)obj2).alignment = alignment; ((Graphic)obj2).color = color; ((TMP_Text)obj2).enableWordWrapping = false; ((Graphic)obj2).raycastTarget = false; return obj2; } private static RectTransform MakeRect(string name, Transform parent) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = new GameObject(name).AddComponent<RectTransform>(); ((Transform)obj).SetParent(parent, false); ((Transform)obj).localScale = Vector3.one; return obj; } private void SendChat(string command) { ApRuntime instance = ApRuntime.Instance; if ((Object)(object)instance == (Object)null) { _error = "Mod not ready yet."; } else { instance.SendChat(command); } } private void OnClosePressed() { _dismissed = true; _toggled = false; SetActiveField(null); } private void OnConnectPressed() { ApRuntime instance = ApRuntime.Instance; if ((Object)(object)instance == (Object)null) { _error = "Mod not ready yet."; return; } SetActiveField(null); string host; int port; if (instance.IsRunning) { instance.Disconnect(); _error = ""; } else if (!TryParseAddress(_server.Value, out host, out port)) { _error = "Server must look like host:port (e.g. localhost:38281)."; } else if (string.IsNullOrWhiteSpace(_slot.Value)) { _error = "Enter your slot name."; } else { _error = ""; SaveSettings(); instance.Connect(host, port, _slot.Value.Trim(), _password.Value ?? ""); } } private static bool TryParseAddress(string address, out string host, out int port) { host = null; port = 38281; if (string.IsNullOrWhiteSpace(address)) { return false; } string[] array = address.Trim().Split(':'); host = array[0]; if (array.Length > 1 && !int.TryParse(array[1], out port)) { return false; } return !string.IsNullOrEmpty(host); } private void SaveSettings() { Plugin.Server.Value = _server.Value ?? ""; Plugin.Slot.Value = _slot.Value ?? ""; Plugin.Password.Value = _password.Value ?? ""; Plugin instance = Plugin.Instance; if (instance != null) { ((BasePlugin)instance).Config.Save(); } } private void RefreshStatus() { //IL_019e: Unknown result type (might be due to invalid IL or missing references) ApRuntime instance = ApRuntime.Instance; bool flag = (Object)(object)instance != (Object)null && instance.IsRunning; if ((Object)(object)_statusText != (Object)null) { string text = (((Object)(object)instance == (Object)null) ? "mod not initialised" : instance.Status); if (ProfileMissing() && flag) { text = text + "\nWaiting for you to pick save slot " + Plugin.AllowedProfile.Value; } ((TMP_Text)_statusText).text = text; } if ((Object)(object)_errorText != (Object)null) { ((TMP_Text)_errorText).text = _error; } if ((Object)(object)_connectLabel != (Object)null) { ((TMP_Text)_connectLabel).text = (flag ? "Disconnect" : "Connect"); } if (!((Object)(object)_logText != (Object)null)) { return; } int num = (_showConsole ? ConsoleLog.Version : (((Object)(object)instance == (Object)null) ? (-1) : instance.EventLogVersion)); if (num != _logVersion) { _logVersion = num; bool flag2 = (Object)(object)_logScroll == (Object)null || _logScroll.verticalNormalizedPosition <= 0.02f; string text2 = (_showConsole ? ConsoleLog.Text : (((Object)(object)instance == (Object)null) ? "" : instance.EventLog)); ((TMP_Text)_logText).text = ((!string.IsNullOrEmpty(text2)) ? text2 : (_showConsole ? "no console output yet" : "nothing yet")); ResizeLog(); if ((Object)(object)_logScroll != (Object)null && flag2) { Canvas.ForceUpdateCanvases(); _logScroll.velocity = Vector2.zero; _logScroll.verticalNormalizedPosition = 0f; } } } private void SetView(int view) { bool flag = view == 1; if (_showConsole != flag) { _showConsole = flag; _logVersion = int.MinValue; RefreshStatus(); } } private void HandleLogScroll() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_logScroll == (Object)null || (Object)(object)_logScroll.viewport == (Object)null) { return; } Mouse current = Mouse.current; if (current != null && RectTransformUtility.RectangleContainsScreenPoint(_logScroll.viewport, ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue(), (Camera)null)) { float num = ((InputControl<Vector2>)(object)current.scroll).ReadValue().y / 120f; if (!(Mathf.Abs(num) < 0.01f)) { Vector2 velocity = _logScroll.velocity; velocity.y = Mathf.Clamp(velocity.y - num * 90f, -900f, 900f); _logScroll.velocity = velocity; } } } private void ResizeLog() { //IL_0045: 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) if (!((Object)(object)_logContent == (Object)null) && !((Object)(object)_logText == (Object)null)) { float num = Mathf.Max(132f, ((TMP_Text)_logText).preferredHeight + 14f); _logContent.sizeDelta = new Vector2(_logContent.sizeDelta.x, num); } } private void LoadLogo() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string[] manifestResourceNames = executingAssembly.GetManifestResourceNames(); foreach (string text in manifestResourceNames) { if (!text.EndsWith("ap-logo.png", StringComparison.OrdinalIgnoreCase)) { continue; } using Stream stream = executingAssembly.GetManifestResourceStream(text); using MemoryStream memoryStream = new MemoryStream(); stream?.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2); ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(memoryStream.ToArray())); _logo = val; break; } } catch (Exception ex) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)("AP: could not load logo: " + ex.Message)); } } } } public sealed class ApRuntime : MonoBehaviour { private sealed class PendingGrant { public int Index; public string Command; } private sealed class EventLine { public string Text; public string Class; } public sealed class FeedEntry { public string Text; public string Kind; public string Key; public string Class; public float Time; } private static ApRuntime _instance; private readonly ApSession _session = new ApSession(); private readonly HashSet<int> _sentChecks = new HashSet<int>(); private readonly HashSet<int> _checkedLocations = new HashSet<int>(); private readonly HashSet<string> _receivedItems = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private readonly Dictionary<string, int> _mapLocations = new Dictionary<string, int>(); private readonly Dictionary<string, int> _achievementLocations = new Dictionary<string, int>(); private readonly List<string> _goalMaps = new List<string>(); private readonly List<int> _goalLocations = new List<int>(); private string _goalLabel = "maps"; private string _serverLabel = ""; private readonly Dictionary<int, string> _itemCommands = new Dictionary<int, string>(); private readonly HashSet<string> _grantedMaps = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private bool _mapsAreDefault; private readonly List<PendingGrant> _pendingGrants = new List<PendingGrant>(); private const int MaxLogLines = 200; private readonly List<EventLine> _events = new List<EventLine>(); private readonly Dictionary<int, string> _playerNames = new Dictionary<int, string>(); private int _ourSlot = -1; private readonly List<FeedEntry> _feed = new List<FeedEntry>(); private bool _joined; private bool _autoConnectTried; private float _saveAt = -1f; private float _nextPoll; private string _joinStatus = ""; private bool _deathLinkEnabled; private bool _knockbackLinkEnabled; private string _slotName = ""; private bool _wasDead; private float _lastHealth = -1f; private float _nextKnockbackSend; private float _nextLinkPoll; private string _effectNotice = ""; private float _effectNoticeUntil; private AudioSource _audio; private AudioClip _goodTone; private AudioClip _badTone; private bool _soundWarned; private float _nextChime; public List<FeedEntry> Feed => _feed; public string EventLog { get { if (_events.Count == 0) { return ""; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < _events.Count; i++) { if (i > 0) { stringBuilder.Append('\n'); } stringBuilder.Append("<color=#").Append(ColorOf(_events[i].Class)).Append('>') .Append(_events[i].Text) .Append("</color>"); } return stringBuilder.ToString(); } } public int EventLogVersion { get; private set; } public static ApRuntime Instance => _instance; public string Status { get { if (_session.RetrySeconds <= 0) { if (!_joined) { return _session.Status; } return "In game (v1.3.0): " + _joinStatus + ((Time.unscaledTime < _effectNoticeUntil) ? (" | " + _effectNotice) : ""); } return _session.Status; } } public bool IsRunning => _session.IsRunning; public bool IsJoined => _joined; public string ServerLabel => _serverLabel; public int RetrySeconds => _session.RetrySeconds; public string Phase { get { if (!_session.IsRunning) { return "off"; } if (_session.RetrySeconds > 0) { return "retrying"; } if (!_session.Connected) { return "connecting"; } if (!_joined) { return "joining"; } return "joined"; } } public int GoalTotal => _goalLocations.Count; public string GoalLabel => _goalLabel; public int GoalCleared { get { int num = 0; foreach (int goalLocation in _goalLocations) { if (IsChecked(goalLocation)) { num++; } } return num; } } private static ManualLogSource Log => Plugin.Logger; public int ProgressVersion { get; private set; } public ApRuntime(IntPtr ptr) : base(ptr) { } private void Awake() { _instance = this; } public void Connect(string host, int port, string slot, string password) { _sentChecks.Clear(); _slotName = slot; _serverLabel = host + ":" + port; _goalMaps.Clear(); _goalLocations.Clear(); _goalLabel = "maps"; _wasDead = false; _lastHealth = -1f; _joined = false; _itemCommands.Clear(); _mapLocations.Clear(); _achievementLocations.Clear(); _joinStatus = ""; _session.Start(host, port, slot, password); } public void SendChat(string command) { command = (command ?? "").Trim(); if (command.Length != 0) { if (!_joined || !_session.IsRunning || !_session.Connected) { NoteEvent("Not connected - chat command not sent.", "chat"); return; } string text = new Json().StartObject().Name("cmd").Value("Say") .Name("text") .Value(command) .EndObject() .ToString(); _session.Send("[" + text + "]"); NoteEvent("> " + command, "chat"); } } public void Disconnect() { _session.Stop(); _joined = false; _joinStatus = ""; _goalMaps.Clear(); _goalLocations.Clear(); _goalLabel = "maps"; } private void Update() { if (!_autoConnectTried) { _autoConnectTried = true; TryAutoConnect(); } DrainIncoming(); if (Time.unscaledTime >= _nextPoll) { _nextPoll = Time.unscaledTime + 1f; if (_joined) { RetryPendingGrants(); ReportChecks(); } MaybeSave(); } PollLinks(); } private void MaybeSave() { if (_saveAt < 0f || Time.unscaledTime < _saveAt) { return; } SaveFileKind[] array = new SaveFileKind[4]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); string text = GameState.Save((SaveFileKind[])(object)array); if (text.StartsWith("OK", StringComparison.Ordinal)) { _saveAt = -1f; ManualLogSource log = Log; if (log != null) { log.LogInfo((object)"AP: profile saved after item grants"); } } else if (text.Contains("BUSY")) { _saveAt = Time.unscaledTime + 1f; } else { _saveAt = Time.unscaledTime + 5f; } } private void TryAutoConnect() { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown if (!Plugin.AutoConnect.Value || string.IsNullOrWhiteSpace(Plugin.Slot.Value)) { return; } string[] array = (Plugin.Server.Value ?? "localhost:38281").Trim().Split(':'); string text = array[0]; int result = 38281; if (array.Length > 1 && !int.TryParse(array[1], out result)) { result = 38281; } ManualLogSource log = Log; if (log != null) { bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(30, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: auto-connecting to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(result); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" as '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Plugin.Slot.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); } log.LogInfo(val); } Connect(text, result, Plugin.Slot.Value, Plugin.Password.Value ?? ""); } private void RetryPendingGrants() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown if (_pendingGrants.Count == 0) { return; } bool flag = false; bool flag2 = default(bool); for (int i = 0; i < _pendingGrants.Count; i++) { PendingGrant pendingGrant = _pendingGrants[i]; string text = GameState.Grant(pendingGrant.Command); if (!text.StartsWith("OK", StringComparison.Ordinal)) { continue; } ManualLogSource log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 2, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: (retried) "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(pendingGrant.Command); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); } log.LogInfo(val); } _pendingGrants.RemoveAt(i); AdvanceApplied(pendingGrant.Index + 1); _saveAt = Time.unscaledTime + 1f; flag = true; i--; } if (flag) { Plugin instance = Plugin.Instance; if (instance != null) { ((BasePlugin)instance).Config.Save(); } } } private void AdvanceApplied(int count) { if (count > Plugin.AppliedItems.Value) { Plugin.AppliedItems.Value = count; } } private void DrainIncoming() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown string result; bool flag = default(bool); while (_session.Incoming.TryDequeue(out result)) { List<object> list; try { object obj = JsonParser.Parse(result); list = (obj as List<object>) ?? new List<object> { obj }; } catch (Exception ex) { ManualLogSource log = Log; if (log != null) { BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: could not parse message: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogWarning(val); } continue; } foreach (object item in list) { Dictionary<string, object> dictionary = JsonParser.AsObject(item); if (dictionary == null) { continue; } try { HandleMessage(dictionary); } catch (Exception ex2) { ManualLogSource log = Log; if (log != null) { BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(24, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("AP: handling '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(JsonParser.GetString(dictionary, "cmd")); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' failed: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex2); } log.LogError(val2); } } } } } private void HandleMessage(Dictionary<string, object> message) { string text = JsonParser.GetString(message, "cmd", ""); if (text == null) { return; } switch (text.Length) { case 9: switch (text[1]) { default: return; case 'o': if (text == "Connected") { OnConnected(message); } return; case 'r': if (text == "PrintJSON") { OnPrintJson(message); } return; case 'h': break; } if (!(text == "ChatPrint")) { break; } goto IL_0118; case 8: if (text == "RoomInfo") { SendConnect(); } break; case 13: if (text == "ReceivedItems") { OnReceivedItems(message); } break; case 6: if (!(text == "Bounce")) { break; } goto IL_0108; case 7: if (!(text == "Bounced")) { break; } goto IL_0108; case 5: if (!(text == "Print")) { break; } goto IL_0118; case 17: if (text == "ConnectionRefused") { _session.Status = "Refused: " + FirstError(message); ManualLogSource log = Log; if (log != null) { log.LogWarning((object)("AP: connection refused - " + FirstError(message))); } _session.Stop(); } break; case 10: case 11: case 12: case 14: case 15: case 16: break; IL_0118: NoteChat(JsonParser.GetString(message, "text", "")); break; IL_0108: OnBounce(message); break; } } private static string FirstError(Dictionary<string, object> message) { if (message.TryGetValue("errors", out var value)) { List<object> list = JsonParser.AsArray(value); if (list != null && list.Count > 0) { return JsonParser.AsString(list[0]) ?? "unknown"; } } return "unknown"; } private void OnPrintJson(Dictionary<string, object> message) { switch (JsonParser.GetString(message, "type", "")) { case "Chat": { string text2 = JoinData(message); if (!string.IsNullOrEmpty(text2)) { NoteChat(text2); } break; } case "Hint": { string text3 = HintText(message); if (!string.IsNullOrEmpty(text3)) { NoteChat(text3); } break; } case "ItemSend": { object value; Dictionary<string, object> dictionary = (message.TryGetValue("item", out value) ? JsonParser.AsObject(value) : null); if (dictionary != null) { int num2 = JsonParser.GetInt(dictionary, "player", -1); int num3 = JsonParser.GetInt(message, "receiving", -1); if (num2 != _ourSlot && num3 != _ourSlot) { string text4 = PlayerName(num2) + " found " + JsonParser.GetString(dictionary, "name", "an item") + " for " + PlayerName(num3); string cls = ClassOfFlags(dictionary); NoteEvent(text4, cls); NoteFeed(text4, "Other", "", cls, silent: true); } } break; } case "Goal": { int num = JsonParser.GetInt(message, "slot", -1); if (num >= 0 && num != _ourSlot) { string text = PlayerName(num) + " completed their goal"; NoteEvent(text, "goal"); NoteFeed(text, "Goal", "", "goal"); } break; } } } private void SendConnect() { string text = new Json().StartObject().Name("cmd").Value("Connect") .Name("game") .Value("Soulstone Survivors") .Name("name") .Value(Plugin.Slot.Value) .Name("uuid") .Value(Guid.NewGuid().ToString()) .Name("version") .StartObject() .Name("major") .Value(0) .Name("minor") .Value(6) .Name("build") .Value(8) .Name("class") .Value("Version") .EndObject() .Name("items_handling") .Value(7) .Name("tags") .StartArray() .Value("DeathLink") .Value("KnockbackLink") .EndArray() .Name("password") .Value(Plugin.Password.Value ?? "") .EndObject() .ToString(); _session.Send("[" + text + "]"); _session.Status = "Joining slot '" + Plugin.Slot.Value + "'..."; } private void OnConnected(Dictionary<string, object> message) { //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown _joined = true; _sentChecks.Clear(); _checkedLocations.Clear(); _receivedItems.Clear(); if (message.TryGetValue("checked_locations", out var value)) { List<object> list = JsonParser.AsArray(value); if (list != null) { foreach (object item in list) { int num = JsonParser.AsInt(item, -1); if (num >= 0) { _checkedLocations.Add(num); } } } } int num2 = (_ourSlot = JsonParser.GetInt(message, "slot", -1)); _events.Clear(); EventLogVersion++; ReadPlayerNames(message); object value2; int num3 = (message.TryGetValue("slot_info", out value2) ? (JsonParser.AsObject(value2)?.Count ?? 0) : 0); string summary = ""; if (message.TryGetValue("slot_data", out var value3)) { Dictionary<string, object> dictionary = JsonParser.AsObject(value3); if (dictionary != null) { ParseSlotData(dictionary, out summary); } } SyncAppliedSeed(JsonParser.GetString(message, "seed_name", ""), num2); _joinStatus = $"slot {num2}, {summary}"; ManualLogSource log = Log; if (log != null) { bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(72, 6, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: joined slot "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num3); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" slots), "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_itemCommands.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" items, "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_mapLocations.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" maps, "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_achievementLocations.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" achievements, "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(EndgameChecks.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" endgame checks"); } log.LogInfo(val); } } private void ReadPlayerNames(Dictionary<string, object> message) { _playerNames.Clear(); if (!message.TryGetValue("players", out var value)) { return; } List<object> list = JsonParser.AsArray(value); if (list == null) { return; } foreach (object item in list) { Dictionary<string, object> dictionary = JsonParser.AsObject(item); if (dictionary == null) { continue; } int num = JsonParser.GetInt(dictionary, "slot", -1); if (num >= 0) { string value2 = JsonParser.GetString(dictionary, "alias", ""); if (string.IsNullOrEmpty(value2)) { value2 = JsonParser.GetString(dictionary, "name", ""); } _playerNames[num] = value2; } } } private void NoteEvent(string line, string cls = "") { if (!string.IsNullOrEmpty(line)) { _events.Add(new EventLine { Text = line, Class = (cls ?? "") }); while (_events.Count > 200) { _events.RemoveAt(0); } EventLogVersion++; } } private void NoteFeed(string text, string kind, string key, string cls = "", bool silent = false) { if (!string.IsNullOrEmpty(text)) { string text2 = (string.IsNullOrEmpty(cls) ? ClassOf(kind) : cls); _feed.Add(new FeedEntry { Text = text, Kind = (kind ?? ""), Key = (key ?? ""), Class = text2, Time = Time.unscaledTime }); while (_feed.Count > 24) { _feed.RemoveAt(0); } if (!silent && (text2 == "progression" || text2 == "trap")) { Chime(text2 == "trap"); } } } private void NoteChat(string text) { if (string.IsNullOrEmpty(text)) { return; } string[] array = text.Split('\n'); for (int i = 0; i < array.Length; i++) { string text2 = array[i].TrimEnd(); if (text2.Length != 0) { NoteEvent(text2, "chat"); ManualLogSource logger = Plugin.Logger; if (logger != null) { logger.LogInfo((object)("AP chat: " + text2)); } } } } private static string JoinData(Dictionary<string, object> message) { string text = JsonParser.GetString(message, "text", ""); if (!string.IsNullOrEmpty(text)) { return text; } if (message.TryGetValue("data", out var value)) { List<object> list = JsonParser.AsArray(value); if (list != null) { StringBuilder stringBuilder = new StringBuilder(); foreach (object item in list) { Dictionary<string, object> dictionary = JsonParser.AsObject(item); string value2 = ((dictionary != null) ? JsonParser.GetString(dictionary, "text", "") : (JsonParser.AsString(item) ?? "")); if (!string.IsNullOrEmpty(value2)) { if (stringBuilder.Length > 0) { stringBuilder.Append('\n'); } stringBuilder.Append(value2); } } return stringBuilder.ToString(); } } return ""; } private string HintText(Dictionary<string, object> message) { object value; Dictionary<string, object> dictionary = (message.TryGetValue("item", out value) ? JsonParser.AsObject(value) : null); if (dictionary == null) { return JoinData(message); } object value2; Dictionary<string, object> dictionary2 = (message.TryGetValue("location", out value2) ? JsonParser.AsObject(value2) : null); string text = JsonParser.GetString(dictionary, "name", "an item"); int num = JsonParser.GetInt(dictionary, "player", -1); string text2 = ((dictionary2 != null) ? JsonParser.GetString(dictionary2, "name", "a location") : "a location"); int num2 = ((dictionary2 != null) ? JsonParser.GetInt(dictionary2, "player", -1) : (-1)); string text3 = "Hint: " + text + " for " + PlayerName(num) + " at " + text2; if (num2 >= 0 && num2 != num) { text3 = text3 + " (" + PlayerName(num2) + "'s world)"; } return text3 + (JsonParser.GetBool(message, "found") ? " - already found" : ""); } private static string ClassOfFlags(Dictionary<string, object> item) { if (item == null) { return ""; } int num = JsonParser.GetInt(item, "flags"); if ((num & 4) != 0) { return "trap"; } if ((num & 1) != 0) { return "progression"; } if ((num & 2) != 0) { return "useful"; } if (num == 0) { return ""; } return "filler"; } private static string ClassOf(string kind) { switch ((kind ?? "").ToLowerInvariant()) { case "mode": case "char": case "craft": case "curse": case "cursetier": case "weaponcap": case "map": return "progression"; case "rune": case "weapon": case "resource": return "useful"; case "souls": return "filler"; case "trap": return "trap"; case "check": return "check"; case "goal": return "goal"; default: return ""; } } private static string ColorOf(string category) { return (category ?? "") switch { "progression" => "FFC857", "useful" => "6FB3FF", "filler" => "9AA3B2", "trap" => "FF6B6B", "check" => "7BE0A3", "goal" => "FFD166", "chat" => "C9B6FF", _ => "E8EDF5", }; } private void Chime(bool trap) { if (Plugin.FeedSounds == null || !Plugin.FeedSounds.Value || Time.unscaledTime < _nextChime) { return; } _nextChime = Time.unscaledTime + 0.4f; try { if ((Object)(object)_audio == (Object)null) { _audio = ((Component)this).gameObject.AddComponent<AudioSource>(); _audio.playOnAwake = false; _audio.spatialBlend = 0f; _audio.volume = 0.35f; } if (trap) { if ((Object)(object)_badTone == (Object)null) { _badTone = Tone(196f, 0.22f); } _audio.PlayOneShot(_badTone, 0.7f); } else { if ((Object)(object)_goodTone == (Object)null) { _goodTone = Tone(659f, 0.14f); } _audio.PlayOneShot(_goodTone, 0.55f); } } catch (Exception ex) { if (!_soundWarned) { _soundWarned = true; ManualLogSource log = Log; if (log != null) { log.LogWarning((object)("AP: feed sound unavailable: " + ex.Message)); } } } } private static AudioClip Tone(float hz, float seconds) { int num = Mathf.Max(1, Mathf.CeilToInt(44100f * seconds)); float[] array = new float[num]; for (int i = 0; i < num; i++) { float num2 = (float)i / 44100f; float num3 = Mathf.Min(1f, num2 * 60f) * Mathf.Min(1f, (seconds - num2) * 30f); array[i] = Mathf.Sin((float)Math.PI * 2f * hz * num2) * 0.5f * num3; } AudioClip obj = AudioClip.Create("ap_tone", num, 1, 44100, false); obj.SetData(Il2CppStructArray<float>.op_Implicit(array), 0); return obj; } public bool IsChecked(int id) { if (!_sentChecks.Contains(id)) { return _checkedLocations.Contains(id); } return true; } public bool HasReceivedItem(string name) { if (!string.IsNullOrEmpty(name)) { return _receivedItems.Contains(name); } return false; } private string PlayerName(int slot) { if (slot < 0) { return "another world"; } if (slot == _ourSlot) { return "you"; } if (!_playerNames.TryGetValue(slot, out var value) || string.IsNullOrEmpty(value)) { return "player " + slot; } return value; } private void NoteReceived(string command, Dictionary<string, object> item, bool silent = false) { string text = JsonParser.GetString(item, "name", ""); if (!string.IsNullOrEmpty(text)) { _receivedItems.Add(text); } ProgressVersion++; string text2 = PlayerName(JsonParser.GetInt(item, "player", -1)); string text3 = "You received " + Describe(command) + ((text2 == "you") ? "" : (" (from " + text2 + ")")); int num = command.IndexOf(':'); string kind = ((num > 0) ? command.Substring(0, num) : command); string text4 = ClassOfFlags(item); if (string.IsNullOrEmpty(text4)) { text4 = ClassOf(kind); } NoteEvent(text3, text4); NoteFeed(text3, kind, (num > 0) ? command.Substring(num + 1) : "", text4, silent); } private static string Describe(string command) { int num = command.IndexOf(':'); string text = ((num > 0) ? command.Substring(0, num) : command); string text2 = ((num > 0) ? command.Substring(num + 1) : ""); switch (text) { case "Char": return Spaced(text2) + " (character)"; case "Weapon": return Spaced(Strip(text2, "Weapon")) + " (weapon)"; case "Rune": return Spaced(Strip(text2, "Rune")) + " (rune)"; case "Map": return Spaced(Strip(text2, "Survivors")) + " (map)"; case "Mode": if (text2 == "Mastery") { return "Unholy Cathedral (mode)"; } if (text2 == "Crusade") { return "Titan Hunt (mode)"; } return text2 + " (mode)"; case "Curse": return "Curse tier " + text2; case "WeaponCap": if (!(text2 == "-1")) { return "Weapon upgrades +" + text2; } return "Weapon upgrades: unlimited"; case "Souls": { string[] array = text2.Split(':'); string obj = array[^1]; string text3 = ((array.Length > 1) ? array[0] : "minor"); return obj + " " + Spaced(text3) + " soulstones"; } case "Resource": return "Resource Cache"; case "Craft": return "Crafting licence: " + Spaced(text2); case "Trap": return "Trap: " + text2; default: return command; } } private static string Strip(string value, string prefix) { if (value == null || !value.StartsWith(prefix, StringComparison.Ordinal)) { return value; } return value.Substring(prefix.Length); } internal static string Spaced(string text) { if (string.IsNullOrEmpty(text)) { return text ?? ""; } StringBuilder stringBuilder = new StringBuilder(text.Length + 8); for (int i = 0; i < text.Length; i++) { char c = text[i]; if (i > 0) { char c2 = text[i - 1]; if (char.IsUpper(c) && !char.IsUpper(c2) && c2 != ' ' && !char.IsDigit(c2)) { stringBuilder.Append(' '); } else if (char.IsDigit(c) && !char.IsDigit(c2) && c2 != ' ') { stringBuilder.Append(' '); } } stringBuilder.Append(c); } return stringBuilder.ToString(); } private void SyncAppliedSeed(string seedName, int slot) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown string text = (string.IsNullOrEmpty(seedName) ? "?" : seedName) + "|" + Plugin.Slot.Value + "|" + slot; if (string.Equals(Plugin.AppliedSeed.Value, text, StringComparison.Ordinal)) { return; } int value = Plugin.AppliedItems.Value; Plugin.AppliedSeed.Value = text; Plugin.AppliedItems.Value = 0; GameState.ResetLicences(); Plugin instance = Plugin.Instance; if (instance != null) { ((BasePlugin)instance).Config.Save(); } ManualLogSource log = Log; if (log != null) { bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(59, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: new seed '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' - replaying all "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" previously counted item(s)"); } log.LogInfo(val); } } private void ParseSlotData(Dictionary<string, object> slotData, out string summary) { _itemCommands.Clear(); _mapLocations.Clear(); _achievementLocations.Clear(); _grantedMaps.Clear(); GameState.GrantedMaps.Clear(); _mapsAreDefault = false; _goalMaps.Clear(); _goalLocations.Clear(); _goalLabel = "maps"; _deathLinkEnabled = false; GameState.CraftLicences = false; _knockbackLinkEnabled = false; bool flag = false; bool flag2 = false; if (slotData.TryGetValue("items", out var value)) { Dictionary<string, object> dictionary = JsonParser.AsObject(value); if (dictionary != null) { foreach (KeyValuePair<string, object> item in dictionary) { if (!int.TryParse(item.Key, out var result)) { continue; } Dictionary<string, object> dictionary2 = JsonParser.AsObject(item.Value); if (dictionary2 != null) { string text = JsonParser.GetString(dictionary2, "kind", ""); string text2 = JsonParser.GetString(dictionary2, "value", ""); switch (text) { case "char": _itemCommands[result] = "Char:" + text2; break; case "weapon": _itemCommands[result] = "Weapon:" + text2; flag = true; break; case "rune": _itemCommands[result] = "Rune:" + text2; break; case "map": _itemCommands[result] = "Map:" + text2; flag2 = true; break; case "souls": _itemCommands[result] = "Souls:" + text2; break; case "craft": _itemCommands[result] = "Craft:" + text2; break; case "trap": _itemCommands[result] = "Trap:" + text2; break; case "resource": _itemCommands[result] = "Resource:" + text2; break; } } } } } List<string> list; if (slotData.TryGetValue("maps", out var value2)) { Dictionary<string, object> dictionary3 = JsonParser.AsObject(value2); if (dictionary3 != null) { list = new List<string>(); foreach (KeyValuePair<string, object> item2 in dictionary3) { _mapLocations[item2.Key] = JsonParser.AsInt(item2.Value); list.Add(item2.Key); } _mapsAreDefault = JsonParser.GetBool(slotData, "maps_default"); if (slotData.TryGetValue("goal_maps", out var value3)) { List<object> list2 = JsonParser.AsArray(value3); if (list2 != null) { foreach (object item3 in list2) { string text3 = JsonParser.AsString(item3); if (!string.IsNullOrEmpty(text3)) { if (text3.StartsWith("Clear ", StringComparison.Ordinal)) { text3 = text3.Substring(6); } _goalMaps.Add(text3); } } } } if (slotData.TryGetValue("goal_locations", out var value4)) { List<object> list3 = JsonParser.AsArray(value4); if (list3 != null) { foreach (object item4 in list3) { int num = JsonParser.AsInt(item4); if (num != 0) { _goalLocations.Add(num); } } goto IL_04db; } } foreach (string goalMap in _goalMaps) { if (_mapLocations.TryGetValue(goalMap, out var value5)) { _goalLocations.Add(value5); } } goto IL_04db; } } goto IL_051e; IL_051e: GameState.EnsureStartingMap(); if (slotData.TryGetValue("achievements", out var value6)) { Dictionary<string, object> dictionary4 = JsonParser.AsObject(value6); if (dictionary4 != null) { foreach (KeyValuePair<string, object> item5 in dictionary4) { _achievementLocations[item5.Key] = JsonParser.AsInt(item5.Value); } } } EndgameChecks.Load(slotData); if (slotData.ContainsKey("weapons_default")) { if (JsonParser.GetBool(slotData, "weapons_default")) { GameState.WeaponsFromItems = false; } } else if (!flag) { GameState.WeaponsFromItems = false; } if (slotData.ContainsKey("maps_default")) { if (JsonParser.GetBool(slotData, "maps_default")) { GameState.MapsFromItems = false; } } else if (!flag2) { GameState.MapsFromItems = false; } GameState.CraftLicences = JsonParser.GetBool(slotData, "craft_licences"); LocationBook.Load(slotData); _deathLinkEnabled = JsonParser.GetBool(slotData, "death_link"); _knockbackLinkEnabled = JsonParser.GetBool(slotData, "knockback_link"); summary = _itemCommands.Count + " items, " + EndgameChecks.Count + " endgame runs" + (_deathLinkEnabled ? ", death link on" : "") + (_knockbackLinkEnabled ? ", knockback link on" : ""); return; IL_04db: _goalLabel = JsonParser.GetString(slotData, "goal_label", "maps"); if (_mapsAreDefault) { string text4 = GameState.UnlockMaps(list); ManualLogSource logger = Plugin.Logger; if (logger != null) { logger.LogInfo((object)("maps unlocked by default: " + text4)); } } goto IL_051e; } private void OnReceivedItems(Dictionary<string, object> message) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Expected O, but got Unknown //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Expected O, but got Unknown //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Expected O, but got Unknown //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Expected O, but got Unknown //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown int num = JsonParser.GetInt(message, "index"); if (!message.TryGetValue("items", out var value)) { return; } List<object> list = JsonParser.AsArray(value); if (list == null) { return; } int value2 = Plugin.AppliedItems.Value; bool flag = default(bool); if (num == 0 && _pendingGrants.Count == 0) { ManualLogSource log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" item(s) replayed, "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value2); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" already applied"); } log.LogInfo(val); } } for (int i = 0; i < list.Count; i++) { int globalIndex = num + i; if (globalIndex < value2) { Dictionary<string, object> dictionary = JsonParser.AsObject(list[i]); if (dictionary != null && _itemCommands.TryGetValue(JsonParser.GetInt(dictionary, "item", -1), out var value3)) { RememberItem(value3); NoteReceived(value3, dictionary, silent: true); } continue; } Dictionary<string, object> dictionary2 = JsonParser.AsObject(list[i]); if (dictionary2 == null) { continue; } int num2 = JsonParser.GetInt(dictionary2, "item", -1); ManualLogSource log; if (!_itemCommands.TryGetValue(num2, out var value4)) { log = Log; if (log != null) { BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("AP: no mapping for item id "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num2); } log.LogWarning(val2); } AdvanceApplied(globalIndex + 1); continue; } NoteReceived(value4, dictionary2); if (value4.StartsWith("Trap:", StringComparison.Ordinal)) { string text = value4.Substring("Trap:".Length); if (PlayerRefs.TryGet(out var entity)) { string text2 = Traps.Apply(text, entity); log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: trap "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(globalIndex); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2); } log.LogInfo(val); } if (text2.StartsWith("OK", StringComparison.Ordinal)) { Notice("Trap: " + text); } } else { log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: trap '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' arrived with no run active - ignored"); } log.LogInfo(val); } } AdvanceApplied(globalIndex + 1); continue; } string text3 = GameState.Grant(value4); if (text3.StartsWith("OK", StringComparison.Ordinal)) { RememberItem(value4); log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: item "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(globalIndex); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value4); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")"); } log.LogInfo(val); } AdvanceApplied(globalIndex + 1); _saveAt = Time.unscaledTime + 2f; continue; } log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: holding "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value4); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")"); } log.LogInfo(val); } if (!_pendingGrants.Exists((PendingGrant p) => p.Index == globalIndex)) { _pendingGrants.Add(new PendingGrant { Index = globalIndex, Command = value4 }); } } Plugin instance = Plugin.Instance; if (instance != null) { ((BasePlugin)instance).Config.Save(); } } private void Notice(string text) { ShowNotice(text); } public static void ShowNotice(string text) { if (!((Object)(object)_instance == (Object)null)) { _instance._effectNotice = text; _instance._effectNoticeUntil = Time.unscaledTime + 6f; } } private void PollLinks() { if (!_joined || (!_deathLinkEnabled && !_knockbackLinkEnabled) || Time.unscaledTime < _nextLinkPoll) { return; } _nextLinkPoll = Time.unscaledTime + 0.25f; if (!PlayerRefs.TryGet(out var entity)) { _lastHealth = -1f; _wasDead = false; return; } HealthComponent health = entity._health; if ((Object)(object)health == (Object)null) { return; } float currentHealth = health.CurrentHealth; if (health.HasBeenKilled || currentHealth <= 0f) { if (!_wasDead) { _wasDead = true; if (_deathLinkEnabled) { SendBounce("DeathLink", "fell in Soulstone Survivors"); } } } else { _wasDead = false; if (_knockbackLinkEnabled && _lastHealth >= 0f && currentHealth < _lastHealth - 0.01f && Time.unscaledTime >= _nextKnockbackSend) { _nextKnockbackSend = Time.unscaledTime + 5f; SendBounce("KnockbackLink", "took a hit"); } } _lastHealth = currentHealth; } private void OnBounce(Dictionary<string, object> message) { if (!message.TryGetValue("tags", out var value)) { return; } List<object> list = JsonParser.AsArray(value); if (list == null) { return; } bool flag = false; bool flag2 = false; foreach (object item in list) { string text = JsonParser.AsString(item); if (text == "DeathLink") { flag = true; } else if (text == "KnockbackLink") { flag2 = true; } } string text2 = ""; if (message.TryGetValue("data", out var value2)) { Dictionary<string, object> dictionary = JsonParser.AsObject(value2); if (dictionary != null) { text2 = JsonParser.GetString(dictionary, "source", ""); } } if (string.IsNullOrEmpty(text2) || !(text2 == _slotName)) { if (flag && _deathLinkEnabled) { ApplyLink("death"); } if (flag2 && _knockbackLinkEnabled) { ApplyLink("knockback"); } } } private void ApplyLink(string kind) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown bool flag = default(bool); ManualLogSource log; if (!PlayerRefs.TryGet(out var entity)) { log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(47, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(kind); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" link received with no run active - ignored"); } log.LogInfo(val); } return; } string text; if (kind == "death") { CursedChoice.Show(entity); text = "OK awaiting the player's choice"; } else { text = Knockback.Push(entity, 22f); } log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(13, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(kind); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" link -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); } log.LogInfo(val); } if (text.StartsWith("OK", StringComparison.Ordinal)) { Notice((kind == "death") ? ("Death link: " + text.Substring(3)) : "Knockback link"); } } private void SendBounce(string tag, string cause) { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown string text = new Json().StartObject().Name("cmd").Value("Bounce") .Name("tags") .StartArray() .Value(tag) .EndArray() .Name("data") .StartObject() .Name("time") .Value((int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()) .Name("source") .Value(_slotName) .Name("cause") .Value(cause) .EndObject() .EndObject() .ToString(); _session.Send("[" + text + "]"); ManualLogSource log = Log; if (log != null) { bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: sent "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(tag); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" bounce"); } log.LogInfo(val); } } private void RememberItem(string command) { if (command != null && command.StartsWith("Map:", StringComparison.Ordinal)) { string item = command.Substring("Map:".Length); _grantedMaps.Add(item); GameState.GrantedMaps.Add(item); } } private void ReportChecks() { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Expected O, but got Unknown GameSnapshot gameSnapshot = GameState.Snapshot(); if (gameSnapshot == null) { return; } List<int> list = new List<int>(); List<string> list2 = new List<string>(); bool flag = default(bool); ManualLogSource log; foreach (MapState map in gameSnapshot.Maps) { if (map.Completeness < 0.999f) { continue; } int value2; if (!_mapsAreDefault && !_grantedMaps.Contains(map.Id)) { if (!_mapLocations.TryGetValue(map.Id, out var value)) { continue; } log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(51, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: cleared "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(map.Id); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" without its map item - check "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" not sent"); } log.LogInfo(val); } } else if (_mapLocations.TryGetValue(map.Id, out value2) && _sentChecks.Add(value2)) { list.Add(value2); list2.Add("You cleared " + Spaced(map.Id)); } } foreach (AchievementState achievement in gameSnapshot.Achievements) { if (achievement.Done && _achievementLocations.TryGetValue(achievement.Id, out var value3) && _sentChecks.Add(value3)) { list.Add(value3); list2.Add("You completed " + (LocationBook.NameForId(value3) ?? Spaced(achievement.Id))); } } int num = 0; foreach (int item in EndgameChecks.Evaluate(gameSnapshot)) { if (_sentChecks.Add(item)) { list.Add(item); num++; } } if (num > 0) { list2.Add("You completed " + num + " endgame check(s)"); } if (list.Count == 0) { return; } StringBuilder stringBuilder = new StringBuilder("[{\"cmd\":\"LocationChecks\",\"locations\":["); for (int i = 0; i < list.Count; i++) { if (i > 0) { stringBuilder.Append(','); } stringBuilder.Append(list[i]); } stringBuilder.Append("]}]"); _session.Send(stringBuilder.ToString()); foreach (string item2 in list2) { NoteEvent(item2, "check"); NoteFeed(item2, "Check", "", "check"); } ProgressVersion++; log = Log; if (log != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AP: sent "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" check(s)"); } log.LogInfo(val); } } } internal static class SoulstoneConfig { public const string GameName = "Soulstone Survivors"; } internal sealed class ApSession { private readonly ConcurrentQueue<string> _incoming = new ConcurrentQueue<string>(); private readonly ConcurrentQueue<string> _outgoing = new ConcurrentQueue<string>(); private CancellationTokenSource _cts; public volatile string Status = "Not connected"; public volatile bool Connected; public volatile string Address = ""; private long _retryAtTicks; public int RetrySeconds { get { long num = Interlocked.Read(in _retryAtTicks); if (num <= 0) { return 0; } double totalSeconds = new TimeSpan(num - DateTime.UtcNow.Ticks).TotalSeconds; if (!(totalSeconds <= 0.0)) { return (int)Math.Ceiling(totalSeconds); } return 0; } } public ConcurrentQueue<string> Incoming => _incoming; public ConcurrentQueue<string> Outgoing => _outgoing; public bool IsRunning { get { if (_cts != null) { return !_cts.IsCancellationRequested; } return false; } } public void Start(string host, int port, string slot, string password) { Stop(); CancellationTokenSource cts = new CancellationTokenSource(); _cts = cts; Connected = false; Address = host + ":" + port; Interlocked.Exchange(ref _retryAtTicks, 0L); Status = $"Connecting to {host}:{port}..."; Task.Run(() => RunAsync(host, port, slot, password, cts.Token)); } public void Stop() { CancellationTokenSource cts = _cts; _cts = null; Connected = false; Interlocked.Exchange(ref _retryAtTicks, 0L); try { cts?.Cancel(); } catch { } Status = "Not connected"; } public void Send(string json) { if (json != null) { _outgoing.Enqueue(json); } } private static string[] SchemesFor(string host) { switch (host) { default: if (!host.StartsWith("192.168.", StringComparison.Ordinal) && !host.StartsWith("10.", StringComparison.Ordinal) && !host.StartsWith("172.", StringComparison.Ordinal)) { return new string[2] { "wss", "ws" }; } break; case "localhost": case "127.0.0.1": case "::1": case "[::1]": break; } return new string[2] { "ws", "wss" }; } private async Task RunAsync(string host, int port, string slot, string password, CancellationToken token) { while (!token.IsCancellationRequested) { string[] array = SchemesFor(host); foreach (string scheme in array) { bool reached = false; bool[] array2 = new bool[2] { true, false }; foreach (bool compress in array2) { ClientWebSocket socket = new ClientWebSocket(); try { _ = 2; try { socket.Options.KeepAliveInterval = TimeSpan.FromSeconds(20.0); if (compress) { socket.Options.DangerousDeflateOptions = new WebSocketDeflateOptions { ClientMaxWindowBits = 11, ServerMaxWindowBits = 11 }; } Status = $"Connecting to {scheme}://{host}:{port}..."; await socket.ConnectAsync(new Uri($"{scheme}://{host}:{port}"), token).ConfigureAwait(continueOnCapturedContext: false); reached = true; Connected = true; Status = "Connected, joining slot..."; Task sender = Task.Run(() => SendLoopAsync(socket, token), token); await ReceiveLoopAsync(socket, token).ConfigureAwait(continueOnCapturedContext: false); await sender.ConfigureAwait(continueOnCapturedContext: false); } catch (OperationCanceledException) { token.ThrowIfCancellationRequested(); return; } catch (Exception ex2) { Status = "Error (" + scheme + (compress ? " + compression" : "") + "): " + ex2.Message; if (compress) { continue; } } finally { Connected = false; } } finally { if (socket != null) { ((IDisposable)socket).Dispose(); } } break; } if (reached || token.IsCancellationRequested) { break; } } if (token.IsCancellationRequested) { break; } Status = "Disconnected - retrying in 5s"; Interlocked.Exchange(ref _retryAtTicks, DateTime.UtcNow.AddSeconds(5.0).Ticks); try { await Task.Delay(5000, token).ConfigureAwait(continueOnCapturedContext: false); } catch (OperationCanceledException) { break; } Interlocked.Exchange(ref _retryAtTicks, 0L); } Interlocked.Exchange(ref _retryAtTicks, 0L); Status = "Not connected"; } private async Task SendLoopAsync(ClientWebSocket socket, CancellationToken token) { _ = 1; try { while (!token.IsCancellationRequested && socket.State == WebSocketState.Open) { string result; while (_outgoing.TryDequeue(out result)) { byte[] bytes = Encoding.UTF8.GetBytes(result); await socket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, endOfMessage: true, token).ConfigureAwait(continueOnCapturedContext: false); } await Task.Delay(40, token).ConfigureAwait(continueOnCapturedContext: false); } } catch (OperationCanceledException) { } catch (Exception ex2) { Status = "Send error: " + ex2.Message; } } private async Task ReceiveLoopAsync(ClientWebSocket socket, CancellationToken token) { byte[] buffer = new byte[65536]; StringBuilder builder = new StringBuilder(); while (!token.IsCancellationRequested && socket.State == WebSocketState.Open) { WebSocketReceiveResult webSocketReceiveResult = await socket.ReceiveAsync(new ArraySegment<byte>(buffer), token).ConfigureAwait(continueOnCapturedContext: false); if (webSocketReceiveResult.MessageType != WebSocketMessageType.Close) { builder.Append(Encoding.UTF8.GetString(buffer, 0, webSocketReceiveResult.Count)); if (webSocketReceiveResult.EndOfMessage) { _incoming.Enqueue(builder.ToString()); builder.Clear(); } continue; } break; } } } internal sealed class ConsoleLog : ILogListener, IDisposable { private const int MaxLines = 500; private static readonly List<string> Lines = new List<string>(); public LogLevel LogLevelFilter { get; set; } = (LogLevel)63; public static int Version { get; private set; } public static string Text { get { lock (Lines) { return (Lines.Count == 0) ? "" : string.Join("\n", Lines); } } } public static void Install() { Logger.Listeners.Add((ILogListener)(object)new ConsoleLog()); } public void Dispose() { } public void LogEvent(object sender, LogEventArgs eventArgs) { string text = ((eventArgs == null) ? null : eventArgs.Data?.ToString()); if (string.IsNullOrEmpty(text)) { return; } ILogSource source = eventArgs.Sou