Decompiled source of ShopUI Client v0.1.8
BepInEx/plugins/ShopUI/ShopUI.Client.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; 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.Text.Json; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using BepInEx.Unity.IL2CPP.Utils.Collections; using HarmonyLib; using Il2CppInterop.Runtime; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem.Collections.Generic; using Microsoft.CodeAnalysis; using ProjectM; using ProjectM.Network; using ProjectM.Physics; using ProjectM.UI; using ShopUI.Client.Net; using ShopUI.Client.Patches; using ShopUI.Client.Services; using ShopUI.Client.UI; using ShopUI.Shared; using Stunlock.Core; using Stunlock.Localization; using TMPro; using Unity.Collections; using Unity.Entities; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.LowLevel; using UnityEngine.InputSystem.Utilities; 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("ShopUI.Client")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.8.0")] [assembly: AssemblyInformationalVersion("0.1.8+193d54d01ebba69389dcc92e74f9e830334dfaae")] [assembly: AssemblyProduct("ShopUI.Client")] [assembly: AssemblyTitle("ShopUI.Client")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.8.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 ShopUI.Client { public static class Core { private static Entity _localCharacter = Entity.Null; private static Entity _localUser = Entity.Null; private static IgnorePhysicsDebugSystem _runner; public static World Client { get; private set; } public static EntityManager EntityManager => Client.EntityManager; public static bool Initialized { get; private set; } public static PrefabCollectionSystem PrefabCollectionSystem { get; private set; } public static Entity LocalCharacter { get { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (_localCharacter != Entity.Null && Client != null && Client.IsCreated) { EntityManager entityManager = EntityManager; if (((EntityManager)(ref entityManager)).Exists(_localCharacter)) { return _localCharacter; } } _localCharacter = Entity.Null; if (Client == null || !Client.IsCreated) { return Entity.Null; } if (!ConsoleShared.TryGetLocalCharacterInCurrentWorld(ref _localCharacter, Client)) { return Entity.Null; } return _localCharacter; } } public static Entity LocalUser { get { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (_localUser != Entity.Null && Client != null && Client.IsCreated) { EntityManager entityManager = EntityManager; if (((EntityManager)(ref entityManager)).Exists(_localUser)) { return _localUser; } } _localUser = Entity.Null; if (Client == null || !Client.IsCreated) { return Entity.Null; } if (!ConsoleShared.TryGetLocalUserInCurrentWorld(ref _localUser, Client)) { return Entity.Null; } return _localUser; } } public static void Initialize(World world) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown if (world == null || !world.IsCreated || (Initialized && Client == world)) { return; } if (Initialized) { Plugin.LogInstance.LogInfo((object)"[ShopUI] client world changed - rebinding to the new world"); Reset(); } try { Client = world; PrefabCollectionSystem = world.GetExistingSystemManaged<PrefabCollectionSystem>(); Initialized = true; Plugin.LogInstance.LogInfo((object)"[ShopUI] client Core initialized"); } catch (Exception ex) { ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(40, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] client Core.Initialize failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } logInstance.LogError(val); } } public static void Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) _localCharacter = Entity.Null; _localUser = Entity.Null; Initialized = false; Client = null; PrefabCollectionSystem = null; Try(delegate { BridgeClient.Reset(); }); Try(delegate { AdminAuth.Reset(); }); Try(delegate { PublicState.Reset(); }); Try(delegate { ShopUiState.Reset(); }); Try(delegate { NamePlates.Clear(); }); } private static void Try(Action action) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown try { action(); } catch (Exception ex) { ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(23, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] reset failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } logInstance.LogWarning(val); } } public static void StartCoroutine(IEnumerator routine) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if (routine != null) { if ((Object)(object)_runner == (Object)null) { GameObject val = new GameObject("ShopUI.Client.Coroutines"); Object.DontDestroyOnLoad((Object)val); _runner = val.AddComponent<IgnorePhysicsDebugSystem>(); } ((MonoBehaviour)_runner).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine)); } } } internal static class EntityExtensions { private static EntityManager EntityManager => Core.EntityManager; public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) TypeIndex typeIndex = new ComponentType(Il2CppType.Of<T>(), (AccessMode)0).TypeIndex; int num = Marshal.SizeOf<T>(); byte[] array = new byte[num]; IntPtr intPtr = Marshal.AllocHGlobal(num); Marshal.StructureToPtr(componentData, intPtr, fDeleteOld: true); Marshal.Copy(intPtr, array, 0, num); Marshal.FreeHGlobal(intPtr); fixed (byte* ptr = array) { EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, typeIndex, (void*)ptr, num); } } public unsafe static T Read<T>(this Entity entity) where T : struct { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) TypeIndex typeIndex = new ComponentType(Il2CppType.Of<T>(), (AccessMode)0).TypeIndex; EntityManager entityManager = EntityManager; return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, typeIndex))); } public static bool Exists(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) if (entity != Entity.Null && Core.Client != null && Core.Client.IsCreated) { EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).Exists(entity); } return false; } public static bool Has<T>(this Entity entity) where T : struct { //IL_0000: 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_000d: 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) if (entity.Exists()) { EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).HasComponent<T>(entity); } return false; } public static NetworkId GetNetworkId(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_001f: 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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; if (((EntityManager)(ref entityManager)).HasComponent<NetworkId>(entity)) { entityManager = EntityManager; return ((EntityManager)(ref entityManager)).GetComponentData<NetworkId>(entity); } return NetworkId.Empty; } } [BepInPlugin("fainel.shopui.client", "ShopUI.Client", "0.1.8")] [BepInProcess("VRising.exe")] public class Plugin : BasePlugin { internal static Plugin Instance; internal static Harmony Harmony; private ConfigEntry<string> _colorScheme; public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log; public static bool VerboseDiagnostics { get; private set; } public static bool IgnoreVanillaMenuState { get; private set; } public static string Version { get { try { Version version = typeof(Plugin).Assembly.GetName().Version; return (version == null) ? "?" : $"{version.Major}.{version.Minor}.{version.Build}"; } catch { return "?"; } } } internal static string KeyTogglePanel { get; private set; } = "x"; internal static string KeyAdminAuth { get; private set; } = "numpad5"; internal static string KeyAdminRemove { get; private set; } = "numpad9"; internal static string ColorScheme { get { return Instance?._colorScheme?.Value ?? "violet"; } set { if (Instance?._colorScheme != null) { Instance._colorScheme.Value = value; } } } public override void Load() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Expected O, but got Unknown Instance = this; Harmony = new Harmony("fainel.shopui.client"); _colorScheme = ((BasePlugin)this).Config.Bind<string>("UIOptions", "ColorScheme", "violet", "Interface colour scheme: violet, ice, acid, ember, graphite, darkred or vanilla."); Theme.SelectById(_colorScheme.Value); VerboseDiagnostics = ((BasePlugin)this).Config.Bind<bool>("Diagnostics", "Verbose", false, "Verbose diagnostics in BepInEx log (input counters, key traces, chat samples).").Value; IgnoreVanillaMenuState = ((BasePlugin)this).Config.Bind<bool>("UIOptions", "IgnoreVanillaMenuState", false, "Open the panel with the hotkey even if another mod keeps a fullscreen menu open.").Value; KeyTogglePanel = ((BasePlugin)this).Config.Bind<string>("Keybinds", "TogglePanel", "x", "Key that opens the ShopUI panel (x, f5, numpad5, digit5...).").Value; KeyAdminAuth = ((BasePlugin)this).Config.Bind<string>("Keybinds", "AdminAuth", "numpad5", "Key that requests admin rights, like the console command adminauth.").Value; KeyAdminRemove = ((BasePlugin)this).Config.Bind<string>("Keybinds", "AdminRemove", "numpad9", "Key that removes admin rights.").Value; Type[] types = Assembly.GetExecutingAssembly().GetTypes(); bool flag = default(bool); foreach (Type type in types) { if (type == null || type == typeof(Plugin) || !type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Any()) { continue; } try { Harmony.PatchAll(type); } catch (Exception ex) { ManualLogSource log = ((BasePlugin)this).Log; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] patch "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(type.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogError(val); } } CheckHalvesMatch(); ShopUIWindow.Initialize(); LogPatchOwners(); ((BasePlugin)this).Log.LogInfo((object)"ShopUI.Client loaded"); } public override bool Unload() { Harmony harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } return true; } private static void LogPatchOwners() { //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown bool flag = default(bool); try { Patches patchInfo = Harmony.GetPatchInfo((MethodBase)AccessTools.Method(typeof(ClientChatSystem), "OnUpdate", (Type[])null, (Type[])null)); if (patchInfo == null) { return; } foreach (Patch prefix in patchInfo.Prefixes) { ManualLogSource log = ((BasePlugin)Instance).Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(41, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] chat prefix: owner='"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(prefix.owner); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("', priority="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(prefix.priority); } log.LogInfo(val); } foreach (Patch postfix in patchInfo.Postfixes) { ManualLogSource log2 = ((BasePlugin)Instance).Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] chat postfix: owner='"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(postfix.owner); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("', priority="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(postfix.priority); } log2.LogInfo(val); } } catch (Exception ex) { ManualLogSource log3 = ((BasePlugin)Instance).Log; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ShopUI] patch owner dump failed: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } log3.LogWarning(val2); } } private static void CheckHalvesMatch() { //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown bool flag = default(bool); try { Version version = typeof(Plugin).Assembly.GetName().Version; Version version2 = typeof(Payload).Assembly.GetName().Version; if (version == null || version2 == null) { return; } if (version.Major == version2.Major && version.Minor == version2.Minor && version.Build == version2.Build) { ManualLogSource logInstance = LogInstance; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] halves match: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(version.Major); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(version.Minor); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(version.Build); } logInstance.LogInfo(val); } else { LogInstance.LogError((object)($"[ShopUI] ВЕРСИИ НЕ СОВПАДАЮТ: ShopUI.Client.dll {version.Major}.{version.Minor}.{version.Build}, ShopUI.Shared.dll {version2.Major}.{version2.Minor}.{version2.Build}. " + "Перезапишите ОБЕ DLL (ShopUI.Client.dll и ShopUI.Shared.dll).")); } } catch (Exception ex) { ManualLogSource logInstance2 = LogInstance; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(31, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ShopUI] version check failed: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } logInstance2.LogWarning(val2); } } } } namespace ShopUI.Client.UI { internal static class ClickService { private class Target { public RectTransform Rect; public Graphic Visual; public string Name; public Action Handler; public Color BaseColor; public bool BaseValid; public bool Hovered; public bool Pressed; } private static readonly List<Target> _targets = new List<Target>(); private static Target _pressed; private static Target _hover; private static float _nextHoverCheck; public static void Register(RectTransform rect, Graphic visual, string name, Action handler) { if (!((Object)(object)rect == (Object)null)) { Unregister(rect); _targets.Add(new Target { Rect = rect, Visual = visual, Name = name, Handler = handler }); Button component = ((Component)rect).GetComponent<Button>(); if ((Object)(object)component != (Object)null) { ((Selectable)component).transition = (Transition)0; } } } public static void Unregister(RectTransform rect) { for (int num = _targets.Count - 1; num >= 0; num--) { if ((Object)(object)_targets[num].Rect == (Object)(object)rect) { _targets.RemoveAt(num); } } } public static void Clear() { _targets.Clear(); _pressed = null; _hover = null; } public static void ResetBaseColors() { for (int i = 0; i < _targets.Count; i++) { _targets[i].BaseValid = false; } } public static void Tick() { //IL_0010: 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_0036: 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_0059: Unknown result type (might be due to invalid IL or missing references) Mouse current = Mouse.current; if (current == null) { return; } Vector2 position = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue(); if (_pressed != null && current.leftButton.wasReleasedThisFrame) { Target pressed = _pressed; _pressed = null; if (HitTest(position) == pressed) { Invoke(pressed); } } if (_pressed == null && current.leftButton.wasPressedThisFrame) { _pressed = HitTest(position); } float realtimeSinceStartup = Time.realtimeSinceStartup; if (!(realtimeSinceStartup < _nextHoverCheck)) { _nextHoverCheck = realtimeSinceStartup + 0.08f; _hover = HitTest(position); } } private static Target HitTest(Vector2 position) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) EventSystem current = EventSystem.current; if ((Object)(object)current == (Object)null) { return null; } PointerEventData val = new PointerEventData(current); val.position = position; List<RaycastResult> val2 = new List<RaycastResult>(); current.RaycastAll(val, val2); if (val2.Count == 0) { return null; } GameObject gameObject = val2[0].gameObject; if ((Object)(object)gameObject == (Object)null) { return null; } Transform val3 = gameObject.transform; while ((Object)(object)val3 != (Object)null) { RectTransform component = ((Component)val3).GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { Target target = Find(component); if (target != null) { Button component2 = ((Component)target.Rect).GetComponent<Button>(); if ((Object)(object)component2 != (Object)null && !((Selectable)component2).interactable) { return null; } return target; } } val3 = val3.parent; } return null; } private static Target Find(RectTransform rect) { for (int i = 0; i < _targets.Count; i++) { if ((Object)(object)_targets[i].Rect == (Object)(object)rect) { return _targets[i]; } } return null; } private static void Invoke(Target target) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown try { target.Handler?.Invoke(); } catch (Exception ex) { ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(35, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] button '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(target.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' handler failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } logInstance.LogError(val); } } private static void Paint() { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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_00b3: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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_01ad: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013c: 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) //IL_014a: 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_019b: Unknown result type (might be due to invalid IL or missing references) for (int num = _targets.Count - 1; num >= 0; num--) { Target target = _targets[num]; if ((Object)(object)target.Rect == (Object)null) { _targets.RemoveAt(num); } else if (!((Object)(object)target.Visual == (Object)null)) { bool flag = _pressed == target; bool flag2 = _hover == target; if (flag != target.Pressed || flag2 != target.Hovered) { target.Pressed = flag; target.Hovered = flag2; if (!target.BaseValid) { target.BaseColor = target.Visual.color; target.BaseValid = true; } Color baseColor = target.BaseColor; if (flag) { target.Visual.color = new Color(baseColor.r * 0.65f, baseColor.g * 0.65f, baseColor.b * 0.65f, baseColor.a); } else if (flag2) { float num2 = 0.22f; Color neon = UiSkin.Neon; float num3 = baseColor.r + (neon.r - baseColor.r) * num2; float num4 = baseColor.g + (neon.g - baseColor.g) * num2; float num5 = baseColor.b + (neon.b - baseColor.b) * num2; target.Visual.color = new Color(Math.Min(1f, num3 * 1.05f), Math.Min(1f, num4 * 1.05f), Math.Min(1f, num5 * 1.05f), baseColor.a); } else { target.Visual.color = baseColor; } } } } } } internal static class DragService { private static RectTransform _window; private static RectTransform _fallbackSpace; private static Func<Vector2, Vector2> _clamp; private static Action _ended; private static Vector2 _grabOffset; public static bool Dragging { get; private set; } public static void Tick(RectTransform window, Transform handle, Func<Vector2, Vector2> clamp, Action ended, RectTransform fallbackSpace) { //IL_00fd: 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_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00bf: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)window == (Object)null || (Object)(object)handle == (Object)null || (Dragging && (Object)(object)_window != (Object)(object)window)) { return; } EventSystem current = EventSystem.current; if ((Object)(object)current == (Object)null) { return; } Mouse current2 = Mouse.current; if (current2 == null) { return; } if (!Dragging) { if (!current2.leftButton.wasPressedThisFrame || !PointerOver(current, handle)) { return; } RectTransform val = DragSpace(window, fallbackSpace); if (!((Object)(object)val == (Object)null)) { _window = window; _fallbackSpace = fallbackSpace; _clamp = clamp; _ended = ended; Dragging = true; Vector2 val2 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(val, ((InputControl<Vector2>)(object)((Pointer)current2).position).ReadValue(), CanvasCamera(val), ref val2)) { _grabOffset = val2 - window.anchoredPosition; } } return; } RectTransform val3 = DragSpace(_window, _fallbackSpace); if ((Object)(object)val3 == (Object)null) { Cancel(_window); return; } Vector2 val4 = default(Vector2); if (current2.leftButton.isPressed && RectTransformUtility.ScreenPointToLocalPointInRectangle(val3, ((InputControl<Vector2>)(object)((Pointer)current2).position).ReadValue(), CanvasCamera(val3), ref val4)) { _window.anchoredPosition = ((_clamp != null) ? _clamp(val4 - _grabOffset) : (val4 - _grabOffset)); } if (current2.leftButton.wasReleasedThisFrame) { Action ended2 = _ended; Cancel(_window); ended2?.Invoke(); } } public static void Cancel(RectTransform window) { if (Dragging && !((Object)(object)_window != (Object)(object)window)) { Dragging = false; _window = null; _fallbackSpace = null; _clamp = null; _ended = null; } } private static RectTransform DragSpace(RectTransform window, RectTransform fallbackSpace) { Transform parent = ((Transform)window).parent; RectTransform val = (((Object)(object)parent != (Object)null) ? ((Component)parent).GetComponent<RectTransform>() : null); if (!((Object)(object)val != (Object)null)) { return fallbackSpace; } return val; } private static Camera CanvasCamera(RectTransform space) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) Canvas componentInParent = ((Component)space).GetComponentInParent<Canvas>(); if ((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) { return componentInParent.worldCamera; } return null; } private static bool PointerOver(EventSystem es, Transform root) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0012: Unknown result type (might be due to invalid IL or missing references) PointerEventData val = new PointerEventData(es); val.position = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue(); List<RaycastResult> val2 = new List<RaycastResult>(); es.RaycastAll(val, val2); for (int i = 0; i < val2.Count; i++) { GameObject gameObject = val2[i].gameObject; if ((Object)(object)gameObject != (Object)null && gameObject.transform.IsChildOf(root)) { return true; } } return false; } } internal static class InputGate { private static uint _lastUpdateCountA; private static uint _lastUpdateCountB; private static float _lastTimeA; private static float _lastTimeB; private static int _diagTicks; private static readonly HashSet<string> _seen = new HashSet<string>(); public static bool ShouldProcessA() { return ShouldProcess(slotB: false); } public static bool ShouldProcessB() { return ShouldProcess(slotB: true); } private static bool ShouldProcess(bool slotB) { uint num = Count(); if (num != 0) { ref uint reference = ref slotB ? ref _lastUpdateCountB : ref _lastUpdateCountA; if (num == reference) { return false; } reference = num; return true; } float unscaledTime = Time.unscaledTime; ref float reference2 = ref slotB ? ref _lastTimeB : ref _lastTimeA; if (reference2 > 0f && unscaledTime - reference2 < 0.008f) { return false; } reference2 = unscaledTime; return true; } private static uint Count() { try { return InputState.updateCount; } catch { return 0u; } } public static void Diagnose() { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown _diagTicks++; if (_diagTicks % 120 != 0) { return; } uint num = 0u; try { num = InputState.updateCount; } catch { } int num2 = 0; float num3 = 0f; try { num2 = Time.frameCount; num3 = Time.unscaledTime; } catch { } string item = $"{num}/{num2}"; if (_seen.Add(item)) { if (_seen.Count > 20) { _seen.Clear(); } ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(60, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] diag: inputUpdateCount="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(num); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", frameCount="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", unscaledTime="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num3, "F3"); } logInstance.LogInfo(val); } } } internal static class ItemPicker { private const int MaxRows = 80; private static GameObject _ui; private static GameObject _panel; private static GameObject _listContent; private static LabelRef _title; private static LabelRef _hint; private static InputFieldRef _search; private static Action<int> _callback; private static GameObject _dragHandle; private static readonly List<GameObject> _optionRows = new List<GameObject>(); public static bool IsOpen { get { if ((Object)(object)_panel != (Object)null) { return _panel.activeSelf; } return false; } } public static void TickDrag() { if (IsOpen) { DragService.Tick(_panel.GetComponent<RectTransform>(), fallbackSpace: (RectTransform)/*isinst with value type is only supported in some contexts*/, handle: ((Object)(object)_dragHandle != (Object)null) ? _dragHandle.transform : null, clamp: ClampPosition, ended: null); } } private static Vector2 ClampPosition(Vector2 position) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_0061: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_009c: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)(((Object)(object)_panel != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); RectTransform val2 = (((Object)(object)_panel != (Object)null) ? _panel.GetComponent<RectTransform>() : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return position; } Rect rect = val.rect; Rect rect2 = val2.rect; Vector2 val3 = ((Rect)(ref rect2)).size * 0.5f; float num = ((Rect)(ref rect)).xMin + val3.x; float num2 = ((Rect)(ref rect)).xMax - val3.x; float num3 = ((Rect)(ref rect)).yMin + val3.y; float num4 = ((Rect)(ref rect)).yMax - val3.y; position.x = ((num > num2) ? ((Rect)(ref rect)).center.x : Mathf.Clamp(position.x, num, num2)); position.y = ((num3 > num4) ? ((Rect)(ref rect)).center.y : Mathf.Clamp(position.y, num3, num4)); return position; } public static void Open(string title, int currentGuid, Action<int> onPick) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown _callback = onPick; EnsureCreated(); UiHelpers.ClearFocus(); _title.TextMesh.text = title; _panel.SetActive(true); _panel.transform.SetAsLastSibling(); if ((Object)(object)_ui != (Object)null) { _ui.SetActive(true); } _search.Component.SetTextWithoutNotify(string.Empty); Rebuild(string.Empty, currentGuid); ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] picker opened: '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(title); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("', options="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_optionRows.Count); } logInstance.LogInfo(val); } public static void Close() { if ((Object)(object)_panel != (Object)null) { _panel.SetActive(false); } UiHelpers.ClearFocus(); InputSuppressionPatch.SuppressFor(0.35f); Plugin.LogInstance.LogInfo((object)"[ShopUI] picker closed"); } private static void EnsureCreated() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_010c: 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) //IL_0293: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_panel != (Object)null)) { GameObject val = ShopUIWindow.Root; if ((Object)(object)val == (Object)null) { _ui = Widgets.CreateCanvas("ShopUI.ItemPickerCanvas"); val = _ui; } _panel = Widgets.CreatePanel(val, "ShopUI.ItemPicker.Panel", out GameObject content, (Color?)new Color(0.07f, 0.07f, 0.09f, 0.99f), 1f); UiHelpers.ThemedWindow(_panel.GetComponent<Image>()); _panel.transform.SetAsLastSibling(); RectTransform component = _panel.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0.5f, 0.5f); component.anchorMax = new Vector2(0.5f, 0.5f); component.pivot = new Vector2(0.5f, 0.5f); component.sizeDelta = new Vector2(760f, 640f); component.anchoredPosition = Vector2.zero; GameObject obj = Widgets.CreateVerticalGroup(content, "PickerBody", forceWidth: true, forceHeight: true, childControlWidth: true, childControlHeight: true, 8, new Vector4(14f, 12f, 14f, 12f), (Color?)new Color(0f, 0f, 0f, 0f)); float? minWidth = 720f; float? minHeight = 600f; float? flexibleWidth = 1f; float? flexibleHeight = 1f; Widgets.SetLayoutElement(obj, minWidth, null, flexibleWidth, minHeight, null, flexibleHeight); GameObject obj2 = UiHelpers.Row(obj, "PickerHeader", 36); UiHelpers.ThemedHeader(obj2); _title = UiHelpers.Label(obj2, "PickerTitle", "Выберите товар", 260, 1, 18, (TextAlignmentOptions)513); _title.TextMesh.fontStyle = (FontStyles)1; UiHelpers.MakeDragHandle(_title, out _dragHandle); UiHelpers.Button(obj2, "PickerClose", "X", 40, 30).OnClick = Close; _search = UiHelpers.Input(obj, "PickerSearch", "поиск: название или GUID", 0, 32); GameObject gameObject = _search.GameObject; flexibleHeight = 32f; flexibleWidth = 32f; minHeight = 1f; Widgets.SetLayoutElement(gameObject, null, null, minHeight, flexibleHeight, flexibleWidth); _hint = Widgets.CreateLabel(obj, "PickerHint", "", (TextAlignmentOptions)513, (Color?)new Color(0.63f, 0.68f, 0.76f), 13f, 28); GameObject gameObject2 = _hint.GameObject; minHeight = 20f; flexibleWidth = 20f; flexibleHeight = 1f; Widgets.SetLayoutElement(gameObject2, null, null, flexibleHeight, minHeight, flexibleWidth); Scrollbar scrollbar; GameObject go = Widgets.CreateScrollView(obj, "PickerScroll", out _listContent, out scrollbar); flexibleHeight = 460f; flexibleWidth = 1f; minHeight = 1f; Widgets.SetLayoutElement(go, null, null, flexibleWidth, flexibleHeight, null, minHeight); ((UnityEvent<string>)(object)_search.Component.onValueChanged).AddListener(UnityAction<string>.op_Implicit((Action<string>)OnSearchChanged)); UiHelpers.BindEdit(_search, () => _search.Component.text, delegate { }, Close); } } private static void OnSearchChanged(string term) { Rebuild(term, 0); } private static void Rebuild(string term, int highlightGuid) { if ((Object)(object)_listContent == (Object)null) { return; } foreach (GameObject optionRow in _optionRows) { if ((Object)(object)optionRow != (Object)null) { Object.DestroyImmediate((Object)(object)optionRow); } } _optionRows.Clear(); List<ItemOption> items = CatalogService.Items; string text = (term ?? string.Empty).Trim(); int num = 0; int num2 = 0; AddOption("(нет предмета)", 0, highlightGuid); for (int i = 0; i < items.Count; i++) { ItemOption itemOption = items[i]; if (itemOption != null && (text.Length <= 0 || itemOption.Display.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 || itemOption.Guid.ToString().IndexOf(text, StringComparison.Ordinal) >= 0)) { num2++; if (num < 80) { AddOption(itemOption.Display, itemOption.Guid, highlightGuid); num++; } } } _hint.TextMesh.text = ((text.Length == 0) ? $"Всего предметов: {items.Count}. Начните вводить название." : $"Найдено: {num2}, показано: {Math.Min(num2, 80)}"); } private static void AddOption(string text, int guid, int highlightGuid) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) GameObject val = UiHelpers.Row(_listContent, "PickerRow", 32, 4); ButtonRef buttonRef = Widgets.CreateButton(val, "PickerOption", text, (guid == highlightGuid) ? new Color?(new Color(0.18f, 0.32f, 0.2f, 1f)) : ((Color?)null)); GameObject gameObject = buttonRef.GameObject; float? minWidth = 620f; float? flexibleWidth = 1f; float? minHeight = 30f; float? preferredHeight = 30f; Widgets.SetLayoutElement(gameObject, minWidth, null, flexibleWidth, minHeight, preferredHeight); if (guid == highlightGuid) { UiHelpers.ThemedSelected(buttonRef); } else { UiHelpers.ThemedButton(buttonRef); } buttonRef.OnClick = delegate { Action<int> callback = _callback; Close(); callback?.Invoke(guid); }; _optionRows.Add(val); } } internal static class NamePlates { private sealed class Plate { public GameObject Root; public TextMeshProUGUI Label; public string Text; public float X; public float Y; public float Z; } private const float Height = 2.1f; private const float Scale = 0.01f; private static readonly Dictionary<string, Plate> _plates = new Dictionary<string, Plate>(); private static GameObject _root; private const float SyncInterval = 10f; private static float _nextSync; public static void Tick() { //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown try { List<MerchantDto> merchants = PublicState.Merchants; if (merchants == null) { return; } foreach (string item in new List<string>(_plates.Keys)) { MerchantDto val = Find(merchants, item); if (val == null || !val.Placed) { Remove(item); } } for (int i = 0; i < merchants.Count; i++) { MerchantDto val2 = merchants[i]; if (val2 == null || !val2.Placed || string.IsNullOrEmpty(val2.Id)) { continue; } string text = (val2.Name ?? string.Empty).Trim(); if (text.Length == 0) { text = "Торговец"; } if (!_plates.TryGetValue(val2.Id, out var value)) { value = Create(val2.Id); _plates[val2.Id] = value; } if (value.Text != text) { value.Text = text; if ((Object)(object)value.Label != (Object)null) { ((TMP_Text)value.Label).text = text; } } if (value.X != val2.X || value.Y != val2.Y || value.Z != val2.Z) { value.X = val2.X; value.Y = val2.Y; value.Z = val2.Z; } Place(value); } } catch (Exception ex) { ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[ShopUI] name plates failed: "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message); } logInstance.LogError(val3); } } public static void Clear() { foreach (string item in new List<string>(_plates.Keys)) { Remove(item); } } public static void RequestStatePeriodically() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0034: 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_0049: Expected O, but got Unknown try { if (Core.Initialized && PublicState.Merchants.Count <= 0) { float unscaledTime = Time.unscaledTime; if (!(unscaledTime < _nextSync)) { _nextSync = unscaledTime + 10f; BridgeClient.Send(new Payload { Type = "publicstate" }); } } } catch (Exception ex) { ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] state sync failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } logInstance.LogError(val); } } private static Plate Create(string id) { //IL_0010: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_0114: 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_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown EnsureRoot(); GameObject val = new GameObject("ShopUI.NamePlate." + id) { layer = 5, hideFlags = (HideFlags)61 }; val.transform.SetParent(_root.transform, false); val.AddComponent<Canvas>().renderMode = (RenderMode)2; RectTransform component = val.GetComponent<RectTransform>(); component.sizeDelta = new Vector2(360f, 60f); ((Transform)component).localScale = Vector3.one * 0.01f; GameObject val2 = new GameObject("Text") { layer = 5, hideFlags = (HideFlags)61 }; val2.transform.SetParent(val.transform, false); RectTransform obj = val2.AddComponent<RectTransform>(); obj.anchorMin = Vector2.zero; obj.anchorMax = Vector2.one; obj.offsetMin = Vector2.zero; obj.offsetMax = Vector2.zero; TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val3).text = ""; ((TMP_Text)val3).font = Widgets.Font; ((TMP_Text)val3).fontSize = 34f; ((TMP_Text)val3).alignment = (TextAlignmentOptions)514; ((Graphic)val3).color = new Color(1f, 0.93f, 0.72f); ((Graphic)val3).raycastTarget = false; ((TMP_Text)val3).enableWordWrapping = false; try { ((TMP_Text)val3).SetOutlineColor(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue)); ((TMP_Text)val3).SetOutlineThickness(0.22f); } catch { } ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[ShopUI] name plate created for '"); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(id); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("'"); } logInstance.LogInfo(val4); return new Plate { Root = val, Label = val3 }; } private static void Place(Plate plate) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)plate?.Root == (Object)null) { return; } RectTransform component = plate.Root.GetComponent<RectTransform>(); if (!((Object)(object)component == (Object)null)) { ((Transform)component).position = new Vector3(plate.X, plate.Y + 2.1f, plate.Z); Camera val = MainCamera(); if (!((Object)(object)val == (Object)null)) { Transform transform = plate.Root.transform; transform.LookAt(((Component)val).transform.position, Vector3.up); transform.Rotate(0f, 180f, 0f); } } } private static void Remove(string id) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown if (!_plates.TryGetValue(id, out var value)) { return; } try { if ((Object)(object)value.Root != (Object)null) { Object.Destroy((Object)(object)value.Root); } } catch { } _plates.Remove(id); ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] name plate removed for '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(id); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); } logInstance.LogInfo(val); } private static void EnsureRoot() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (!((Object)(object)_root != (Object)null)) { _root = new GameObject("ShopUI.NamePlates") { layer = 5, hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)(object)_root); } } private static Camera MainCamera() { try { Camera main = Camera.main; if ((Object)(object)main != (Object)null) { return main; } } catch { } try { return CameraManager.GetCamera(); } catch { return null; } } private static MerchantDto Find(List<MerchantDto> merchants, string id) { for (int i = 0; i < merchants.Count; i++) { MerchantDto val = merchants[i]; if (val != null && val.Id == id) { return val; } } return null; } } internal class LabelRef { public GameObject GameObject; public TMP_Text TextMesh; } internal class ButtonRef { public GameObject GameObject; public GameObject LayoutGameObject; public Button Button; public TMP_Text Label; private Action _onClick; public Action OnClick { get { return _onClick; } set { _onClick = value; Register(); } } private void Register() { if (!((Object)(object)GameObject == (Object)null)) { ClickService.Register(GameObject.GetComponent<RectTransform>(), GameObject.GetComponent<Graphic>(), ((Object)GameObject).name, delegate { _onClick?.Invoke(); }); } } } internal class InputFieldRef { public GameObject GameObject; public GameObject Visual; public TMP_InputField Component; public string Text { get { if (!((Object)(object)Component != (Object)null)) { return string.Empty; } return Component.text; } set { if ((Object)(object)Component != (Object)null) { Component.text = value; } } } } internal class ToggleRef { public GameObject GameObject; public Toggle Toggle; public TMP_Text Text; public Image Checkmark; public bool IsOn { get; private set; } public Action<bool> OnValueChanged { get; set; } public void SetToggleValueWithoutEvent(bool value) { IsOn = value; if ((Object)(object)Toggle != (Object)null) { Toggle.SetIsOnWithoutNotify(value); } if ((Object)(object)Checkmark != (Object)null) { ((Behaviour)Checkmark).enabled = value; } } public void ToggleValue(bool value) { SetToggleValueWithoutEvent(value); OnValueChanged?.Invoke(value); } } internal static class SelectList { private static GameObject _panel; private static GameObject _list; private static GameObject _dragHandle; private static Action<int> _callback; public static bool IsOpen { get { if ((Object)(object)_panel != (Object)null) { return _panel.activeSelf; } return false; } } public static void TickDrag() { if (IsOpen) { DragService.Tick(_panel.GetComponent<RectTransform>(), fallbackSpace: (RectTransform)/*isinst with value type is only supported in some contexts*/, handle: ((Object)(object)_dragHandle != (Object)null) ? _dragHandle.transform : null, clamp: null, ended: null); } } public static void Open(GameObject host, string title, List<string> items, int selectedIndex, Action<int> onPick) { EnsureCreated(host); _callback = onPick; Rebuild(title, items, selectedIndex); _panel.SetActive(true); } public static void Close() { if ((Object)(object)_panel != (Object)null) { _panel.SetActive(false); } InputSuppressionPatch.SuppressFor(0.35f); } private static void EnsureCreated(GameObject host) { //IL_0044: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_panel != (Object)null) { return; } if ((Object)(object)host == (Object)null) { host = ShopUIWindow.Root; if ((Object)(object)host == (Object)null) { return; } } _panel = Widgets.CreatePanel(host, "ShopUI.SelectList.Panel", out GameObject content, (Color?)new Color(0.07f, 0.07f, 0.09f, 0.98f), 1f); UiHelpers.ThemedWindow(_panel.GetComponent<Image>()); RectTransform component = _panel.GetComponent<RectTransform>(); component.sizeDelta = new Vector2(520f, 420f); UiHelpers.PlaceOverWindow(component); GameObject obj = Widgets.CreateVerticalGroup(content, "SelectListBody", forceWidth: true, forceHeight: true, childControlWidth: true, childControlHeight: true, 6, new Vector4(10f, 10f, 10f, 10f), (Color?)new Color(0.09f, 0.05f, 0.16f, 0.94f)); float? minWidth = 500f; float? minHeight = 400f; float? flexibleWidth = 1f; float? flexibleHeight = 1f; Widgets.SetLayoutElement(obj, minWidth, null, flexibleWidth, minHeight, null, flexibleHeight); UiHelpers.ThemedCard(obj); GameObject obj2 = UiHelpers.Row(obj, "SelectListHeader", 30); UiHelpers.ThemedHeader(obj2); UiHelpers.MakeDragHandle(UiHelpers.Label(obj2, "SelectListTitle", "Выберите", 0, 1, 15, (TextAlignmentOptions)513), out _dragHandle); Scrollbar scrollbar; GameObject obj3 = Widgets.CreateScrollView(obj, "SelectListScroll", out _list, out scrollbar); flexibleHeight = 320f; flexibleWidth = 1f; minHeight = 1f; Widgets.SetLayoutElement(obj3, null, null, flexibleWidth, flexibleHeight, null, minHeight); UiHelpers.ThemedScrollView(obj3); } private static void Rebuild(string title, List<string> items, int selectedIndex) { if ((Object)(object)_list == (Object)null) { return; } for (int num = _list.transform.childCount - 1; num >= 0; num--) { GameObject gameObject = ((Component)_list.transform.GetChild(num)).gameObject; if ((Object)(object)gameObject != (Object)null) { Object.DestroyImmediate((Object)(object)gameObject); } } object obj; if (!((Object)(object)_list.transform.parent != (Object)null)) { obj = null; } else { Transform obj2 = _list.transform.parent.Find("SelectListHeader"); obj = ((obj2 != null) ? ((Component)obj2).gameObject : null); } GameObject val = (GameObject)obj; if ((Object)(object)val != (Object)null) { TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>(); if ((Object)(object)componentInChildren != (Object)null) { ((TMP_Text)componentInChildren).text = title; } } if (items == null) { return; } for (int i = 0; i < items.Count; i++) { int index = i; ButtonRef buttonRef = UiHelpers.Button(_list, "SelectItem_" + i, items[i], 480); if (index == selectedIndex) { UiHelpers.ThemedSelected(buttonRef); } else { UiHelpers.ThemedButton(buttonRef); } buttonRef.OnClick = delegate { Action<int> callback = _callback; Close(); callback?.Invoke(index); }; } } } public static class ShopUIWindow { private class OfferRow { public OfferDto Offer; public GameObject Root; public ButtonRef OutputButton; public InputFieldRef OutputAmount; public ButtonRef InputButton; public InputFieldRef InputAmount; public InputFieldRef Stock; public ButtonRef Remove; } private static GameObject _ui; private static GameObject _panel; private static GameObject _content; private static GameObject _blocker; private static LabelRef _status; private static bool _suppressEvents; private static float _blockerUntil; private static bool _closedByUser; private static bool _openRequested; private static GameObject _overlay; private static GameObject _merchantDock; private static GameObject _merchantDockList; private static GameObject _skinDock; private static GameObject _skinDockList; private static InputFieldRef _nameInput; private static ButtonRef _traderButton; private static InputFieldRef _restockInput; private static ToggleRef _roamToggle; private static LabelRef _stateLabel; private static int _lastRevision; private static bool _removeAllArmed; private static TextMeshProUGUI _skinLabel; private static GameObject _dragHandle; private static ButtonRef _merchantButton; private static GameObject _offersContent; private static readonly List<OfferRow> _rows = new List<OfferRow>(); public static bool IsOpen { get { if ((Object)(object)_panel != (Object)null) { return _panel.activeSelf; } return false; } } internal static GameObject Root => _ui; internal static GameObject Panel => _panel; public static MerchantDto Selected { get { if (!string.IsNullOrEmpty(ShopUiState.SelectedId)) { return ((IEnumerable<MerchantDto>)ShopUiState.Merchants).FirstOrDefault((Func<MerchantDto, bool>)((MerchantDto m) => m.Id == ShopUiState.SelectedId)); } return null; } } public static void Initialize() { ShopUiState.Changed -= OnStateChanged; ShopUiState.Changed += OnStateChanged; Plugin.LogInstance.LogInfo((object)"[ShopUI] window handler subscribed"); } public static void Toggle() { if (IsOpen) { Close(); } else { Open(); } } public static void Open() { _closedByUser = false; _openRequested = true; SetStatus("Загрузка..."); AdminAuth.RequestOpen(); } public static void ShowFromServer() { _closedByUser = false; bool isOpen = IsOpen; if (!isOpen) { ShowPanel(); } if (!isOpen) { KeybindPatch.DumpKeyLayout(Keyboard.current); Plugin.LogInstance.LogInfo((object)"[ShopUI] window shown"); RefreshMerchants(); } } public static void Close() { _closedByUser = true; if ((Object)(object)_panel != (Object)null) { _panel.SetActive(false); } CloseDocks(); GameInputState.Flush(); GameInputSuppressor.SetBlocked(blocked: false); InputActionObserver.Tick(); InputActionObserver.ListMenuActions(); InputSuppressionPatch.SuppressFor(0.35f); _blockerUntil = Time.unscaledTime + 0.35f; } internal static void TickDrag() { if (!((Object)(object)_panel == (Object)null) && _panel.activeSelf) { DragService.Tick(_panel.GetComponent<RectTransform>(), fallbackSpace: (RectTransform)/*isinst with value type is only supported in some contexts*/, handle: ((Object)(object)_dragHandle != (Object)null) ? _dragHandle.transform : null, clamp: ClampPosition, ended: null); } } private static Vector2 ClampPosition(Vector2 position) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_0061: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)(((Object)(object)_panel != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); RectTransform val2 = (((Object)(object)_panel != (Object)null) ? _panel.GetComponent<RectTransform>() : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return position; } Rect rect = val.rect; Rect rect2 = val2.rect; Vector2 val3 = ((Rect)(ref rect2)).size * 0.5f; float num = ((Rect)(ref rect)).xMin + val3.x + 240f; float num2 = ((Rect)(ref rect)).xMax - val3.x - 240f; float num3 = ((Rect)(ref rect)).yMin + val3.y; float num4 = ((Rect)(ref rect)).yMax - val3.y; position.x = ((num > num2) ? ((Rect)(ref rect)).center.x : Mathf.Clamp(position.x, num, num2)); position.y = ((num3 > num4) ? ((Rect)(ref rect)).center.y : Mathf.Clamp(position.y, num3, num4)); return position; } private static void ShowPanel() { EnsureCreated(); CatalogService.Rebuild(); _panel.SetActive(true); if ((Object)(object)_ui != (Object)null) { _ui.SetActive(true); } CloseDocks(); if ((Object)(object)_blocker != (Object)null) { _blocker.SetActive(true); } GameInputSuppressor.SetBlocked(blocked: true); } internal static void TickBlocker() { if (!((Object)(object)_blocker == (Object)null)) { bool flag = IsOpen || Time.unscaledTime < _blockerUntil; if (_blocker.activeSelf != flag) { _blocker.SetActive(flag); } } } private static void EnsureCreated() { //IL_0029: 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_0059: 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_007f: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_010d: 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_0137: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0156: 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_019d: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_panel != (Object)null)) { _ui = Widgets.CreateCanvas("ShopUI.Canvas"); _blocker = Widgets.CreateUIObject("ShopUI.Blocker", _ui); Image obj = _blocker.AddComponent<Image>(); ((Graphic)obj).color = new Color(0f, 0f, 0f, 0.01f); ((Graphic)obj).raycastTarget = true; RectTransform component = _blocker.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; _blocker.transform.SetAsFirstSibling(); _panel = Widgets.CreatePanel(_ui, "ShopUI.Panel", out _content, (Color?)new Color(0.07f, 0.07f, 0.09f, 0.98f), 1f); UiHelpers.ThemedWindow(_panel.GetComponent<Image>()); RectTransform component2 = _panel.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0.5f, 0.5f); component2.anchorMax = new Vector2(0.5f, 0.5f); component2.pivot = new Vector2(0.5f, 0.5f); component2.sizeDelta = new Vector2(1040f, 760f); component2.anchoredPosition = Vector2.zero; GameObject obj2 = Widgets.CreateVerticalGroup(_content, "Body", forceWidth: true, forceHeight: false, childControlWidth: true, childControlHeight: true, 10, new Vector4(16f, 16f, 16f, 16f), (Color?)new Color(0f, 0f, 0f, 0f)); float? minWidth = 1000f; float? minHeight = 720f; float? flexibleWidth = 1f; float? flexibleHeight = 1f; Widgets.SetLayoutElement(obj2, minWidth, null, flexibleWidth, minHeight, null, flexibleHeight); BuildHeader(obj2); BuildToolbar(obj2); BuildEditorCard(obj2); BuildOffersSection(obj2); _status = Widgets.CreateLabel(obj2, "Status", "", (TextAlignmentOptions)513, (Color?)new Color(0.8f, 0.85f, 0.9f), 14f, 28); GameObject gameObject = _status.GameObject; flexibleHeight = 22f; flexibleWidth = 22f; minHeight = 1f; Widgets.SetLayoutElement(gameObject, null, null, minHeight, flexibleHeight, flexibleWidth); EnsureDocks(); } } private static void EnsureDocks() { //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_0046: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_merchantDock != (Object)null)) { _overlay = Widgets.CreateUIObject("ShopUI.Overlay", _panel); _overlay.AddComponent<LayoutElement>().ignoreLayout = true; RectTransform component = _overlay.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; _merchantDock = BuildDock("ShopUI.Dock.Merchants", "Торговцы", right: false, out _merchantDockList); _skinDock = BuildDock("ShopUI.Dock.Skins", "Скины", right: true, out _skinDockList); _merchantDock.SetActive(false); _skinDock.SetActive(false); RefreshMerchantDock(); RefreshSkinDock(); } } private static GameObject BuildDock(string name, string title, bool right, out GameObject list) { //IL_0008: 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) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_0069: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) GameObject val = Widgets.CreateUIObject(name, _overlay); Image obj = val.AddComponent<Image>(); ((Graphic)obj).color = new Color(0.07f, 0.07f, 0.09f, 0.98f); UiHelpers.ThemedWindow(obj); RectTransform component = val.GetComponent<RectTransform>(); if (right) { component.anchorMin = new Vector2(1f, 0.5f); component.anchorMax = new Vector2(1f, 0.5f); component.pivot = new Vector2(0f, 0.5f); component.anchoredPosition = Vector2.zero; } else { component.anchorMin = new Vector2(0f, 0.5f); component.anchorMax = new Vector2(0f, 0.5f); component.pivot = new Vector2(1f, 0.5f); component.anchoredPosition = Vector2.zero; } component.sizeDelta = new Vector2(240f, 700f); GameObject obj2 = Widgets.CreateUIObject(name + ".Header", val); RectTransform component2 = obj2.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0f, 1f); component2.anchorMax = new Vector2(1f, 1f); component2.pivot = new Vector2(0.5f, 1f); component2.offsetMin = new Vector2(0f, -34f); component2.offsetMax = Vector2.zero; ((Graphic)obj2.AddComponent<Image>()).color = Color.clear; UiHelpers.ThemedHeader(obj2); GameObject obj3 = Widgets.CreateHorizontalGroup(obj2, "HeaderRow", forceWidth: false, forceHeight: false, childControlWidth: true, childControlHeight: true, 6, new Vector4(8f, 8f, 0f, 0f), Color.clear); RectTransform component3 = obj3.GetComponent<RectTransform>(); component3.anchorMin = Vector2.zero; component3.anchorMax = Vector2.one; component3.offsetMin = Vector2.zero; component3.offsetMax = Vector2.zero; UiHelpers.Label(obj3, "DockTitle", title, 0, 1, 15, (TextAlignmentOptions)513).TextMesh.enableWordWrapping = false; UiHelpers.Button(obj3, "DockClose", "X", 34, 24).OnClick = CloseDocks; Scrollbar scrollbar; GameObject obj4 = Widgets.CreateScrollView(val, name + ".Scroll", out list, out scrollbar); RectTransform component4 = obj4.GetComponent<RectTransform>(); component4.anchorMin = Vector2.zero; component4.anchorMax = Vector2.one; component4.offsetMin = new Vector2(8f, 8f); component4.offsetMax = new Vector2(-8f, -42f); UiHelpers.ThemedScrollView(obj4); return val; } internal static void ToggleMerchantDock() { EnsureDocks(); if (!((Object)(object)_merchantDock == (Object)null)) { bool active = !_merchantDock.activeSelf; _skinDock.SetActive(false); _merchantDock.SetActive(active); } } internal static void ToggleSkinDock() { EnsureDocks(); if (!((Object)(object)_skinDock == (Object)null)) { bool active = !_skinDock.activeSelf; _merchantDock.SetActive(false); _skinDock.SetActive(active); } } internal static void CloseDocks() { if ((Object)(object)_merchantDock != (Object)null) { _merchantDock.SetActive(false); } if ((Object)(object)_skinDock != (Object)null) { _skinDock.SetActive(false); } } private static void RefreshMerchantDock() { if ((Object)(object)_merchantDockList == (Object)null) { return; } ClearList(_merchantDockList); List<MerchantDto> merchants = ShopUiState.Merchants; if (merchants.Count == 0) { UiHelpers.ThemedButton(UiHelpers.Button(_merchantDockList, "DockEmpty", "торговцев нет", 196, 26)); return; } for (int i = 0; i < merchants.Count; i++) { MerchantDto val = merchants[i]; int index = i; string text = (val.Placed ? "● " : "○ "); string text2 = (string.IsNullOrEmpty(val.Name) ? "Trader" : val.Name); ButtonRef buttonRef = UiHelpers.Button(_merchantDockList, "DockMerchant_" + i, text + text2, 196, 26); if (val.Id == ShopUiState.SelectedId) { UiHelpers.ThemedSelected(buttonRef); } else { UiHelpers.ThemedButton(buttonRef); } buttonRef.OnClick = delegate { if (!_suppressEvents) { OnMerchantSelected(index); } }; } } private static void RefreshSkinDock() { if ((Object)(object)_skinDockList == (Object)null) { return; } ClearList(_skinDockList); Theme[] all = Theme.All; foreach (Theme theme in all) { bool current = theme.Id == Theme.Current.Id; ButtonRef buttonRef = ThemeButtons.Build(_skinDockList, theme, current, 196); string id = theme.Id; buttonRef.OnClick = delegate { Theme.SelectById(id); ThemeBinder.Apply(); Plugin.ColorScheme = id; RefreshSkinDock(); OnSkinChanged(); CloseDocks(); }; } } private static void ClearList(GameObject list) { if ((Object)(object)list == (Object)null) { return; } for (int num = list.transform.childCount - 1; num >= 0; num--) { GameObject gameObject = ((Component)list.transform.GetChild(num)).gameObject; if (!((Object)(object)gameObject == (Object)null)) { RectTransform component = gameObject.GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { ClickService.Unregister(component); } Object.DestroyImmediate((Object)(object)gameObject); } } } private static void BuildEditorCard(GameObject parent) { //IL_001f: 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_0307: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Widgets.CreateVerticalGroup(parent, "EditorCard", forceWidth: true, forceHeight: false, childControlWidth: true, childControlHeight: true, 8, new Vector4(12f, 10f, 12f, 10f), (Color?)new Color(0.11f, 0.11f, 0.14f, 0.95f)); float? minHeight = 200f; float? preferredHeight = 200f; float? flexibleWidth = 1f; float? flexibleHeight = 0f; Widgets.SetLayoutElement(obj, null, null, flexibleWidth, minHeight, preferredHeight, flexibleHeight); UiHelpers.ThemedCard(obj); UiHelpers.Label(obj, "EditorCaption", "Торговец", 0, 1, 16, (TextAlignmentOptions)513).TextMesh.fontStyle = (FontStyles)1; GameObject parent2 = UiHelpers.Row(obj, "NameRow", 32); UiHelpers.Label(parent2, "NameLabel", "Имя:", 200, 0, 15, (TextAlignmentOptions)516); _nameInput = UiHelpers.Input(parent2, "NameInput", "название торговца", 300, 30); GameObject gameObject = _nameInput.GameObject; float? minWidth = 300f; flexibleHeight = 0f; flexibleWidth = 30f; preferredHeight = 30f; Widgets.SetLayoutElement(gameObject, minWidth, null, flexibleHeight, flexibleWidth, preferredHeight); _nameInput.Component.textComponent.alignment = (TextAlignmentOptions)513; UiHelpers.BindEdit(_nameInput, delegate { MerchantDto selected = Selected; return ((selected != null) ? selected.Name : null) ?? string.Empty; }, ApplyName); GameObject parent3 = UiHelpers.Row(obj, "PrefabRow", 32); UiHelpers.Label(parent3, "TraderLabel", "Префаб:", 200, 0, 15, (TextAlignmentOptions)516); _traderButton = UiHelpers.Button(parent3, "TraderButton", "нет префабов", 300, 30); GameObject gameObject2 = _traderButton.GameObject; float? minWidth2 = 300f; preferredHeight = 0f; flexibleWidth = 30f; flexibleHeight = 30f; Widgets.SetLayoutElement(gameObject2, minWidth2, null, preferredHeight, flexibleWidth, flexibleHeight); _traderButton.OnClick = OpenTraderList; GameObject parent4 = UiHelpers.Row(obj, "RestockRow", 32); UiHelpers.Label(parent4, "RestockLabel", "Пополнение запасов, мин:", 200, 0, 15, (TextAlignmentOptions)516); _restockInput = UiHelpers.Input(parent4, "RestockInput", "0", 90, 30); UiHelpers.BindEdit(_restockInput, delegate { MerchantDto selected = Selected; return ((selected != null) ? selected.RestockMinutes.ToString() : null) ?? "0"; }, OnRestockEndEdit); _roamToggle = Widgets.CreateToggle(parent4, "RoamToggle", Color.clear, 20, 20, "перемещается"); GameObject gameObject3 = _roamToggle.GameObject; float? minWidth3 = 180f; float? preferredWidth = 180f; flexibleHeight = 30f; Widgets.SetLayoutElement(gameObject3, minWidth3, preferredWidth, null, flexibleHeight); _roamToggle.OnValueChanged = OnRoamChanged; UiHelpers.ThemedToggle(_roamToggle); UiHelpers.Spacer(parent4, "RestockSpacer"); UiHelpers.Button(parent4, "Place", "Разместить здесь", 170, 30).OnClick = OnPlaceClicked; ButtonRef buttonRef = UiHelpers.Button(parent4, "Despawn", "Убрать из мира", 160, 30); UiHelpers.ThemedButton(buttonRef, () => UiHelpers.AccentDark); buttonRef.OnClick = OnDespawnClicked; _stateLabel = UiHelpers.Label(UiHelpers.Row(obj, "StateRow", 22), "StateLabel", "", 0, 1, 14, (TextAlignmentOptions)513); _stateLabel.TextMesh.enableWordWrapping = false; } private static void OnDespawnClicked() { MerchantDto selected = Selected; if (selected == null) { SetStatus("Торговец не выбран."); return; } ShopUiState.Despawn(selected); SetStatus("Торговец снимается с мира. Запись в конфиге сохраняется, но сам он не вернётся после перезапуска сервера — поставить заново можно кнопкой «Разместить здесь»."); } private static void OnPlaceClicked() { MerchantDto selected = Selected; if (selected == null) { SetStatus("Торговец не выбран."); return; } ShopUiState.Place(selected); SetStatus("Позиция взята из точки прицела. Нажмите «Применить»."); } private static void RefreshEditor() { MerchantDto selected = Selected; _suppressEvents = true; try { if (selected == null) { _nameInput.Text = string.Empty; _restockInput.Text = "0"; _roamToggle.SetToggleValueWithoutEvent(value: false); RefreshTraderOptions(null); SetStateLabel(null); } else { if ((Object)(object)_nameInput.Component == (Object)null || !_nameInput.Component.isFocused) { _nameInput.Text = selected.Name ?? string.Empty; } if ((Object)(object)_restockInput.Component == (Object)null || !_restockInput.Component.isFocused) { _restockInput.Text = selected.RestockMinutes.ToString(); } _roamToggle.SetToggleValueWithoutEvent(selected.Roam); RefreshTraderOptions(selected); SetStateLabel(selected); } } finally { _suppressEvents = false; } RefreshOffers(); } private static void SetStateLabel(MerchantDto merchant) { if (_stateLabel != null) { string text = ((merchant == null) ? "" : ((!merchant.Placed) ? "○ Снят с мира: сам не вернётся после перезапуска сервера — «Разместить здесь», потом «Применить»." : "● В мире: виден игрокам, над ним висит подпись с названием.")); _stateLabel.TextMesh.text = text; } } private static void RefreshTraderOptions(MerchantDto merchant) { if (_traderButton != null) { List<ItemOption> traders = CatalogService.Traders; int num = ((merchant != null) ? traders.FindIndex((ItemOption t) => t.Guid == merchant.TraderPrefab) : 0); if (num < 0) { num = 0; } string text = ((traders.Count == 0) ? "нет префабов" : traders[num].Display); if ((Object)(object)_traderButton.Label != (Object)null) { _traderButton.Label.text = text; } } } private static void OpenTraderList() { List<ItemOption> traders = CatalogService.Traders; List<string> list = new List<string>(); foreach (ItemOption item in traders) { list.Add(item.Display); } if (list.Count == 0) { list.Add("нет префабов"); } int selectedIndex = 0; MerchantDto merchant = Selected; if (merchant != null) { int num = traders.FindIndex((ItemOption t) => t.Guid == merchant.TraderPrefab); if (num >= 0) { selectedIndex = num; } } SelectList.Open(Panel, "Префаб торговца", list, selectedIndex, OnTraderSelected); } private static void OnTraderSelected(int index) { if (!_suppressEvents) { MerchantDto selected = Selected; if (selected != null && index >= 0 && index < CatalogService.Traders.Count) { selected.TraderPrefab = CatalogService.Traders[index].Guid; ShopUiState.MarkDirty(selected); SaveSelected(selected); } } } private static void ApplyName(string text) { if (_suppressEvents) { return; } MerchantDto selected = Selected; if (selected == null) { SetStatus("Сначала выберите торговца."); return; } string text2 = (string.IsNullOrWhiteSpace(text) ? "Trader" : text.Trim()); if (!(text2 == selected.Name)) { selected.Name = text2; ShopUiState.MarkDirty(selected); SaveSelected(selected); RefreshMerchants(); SetStatus("Торговец переименован: " + text2); } } private static void OnRestockEndEdit(string text) { if (_suppressEvents) { return; } MerchantDto selected = Selected; if (selected != null) { if (!int.TryParse((text ?? string.Empty).Trim(), out var result) || result < 0) { SetStatus("Пополнение: нужно целое число минут (0 — отключить)."); } else if (result != selected.RestockMinutes) { selected.RestockMinutes = result; ShopUiState.MarkDirty(selected); SaveSelected(selected); SetStatus((result > 0) ? $"Запасы пополняются каждые {result} мин." : "Пополнение отключено (0 мин)."); } } } private static void OnRoamChanged(bool value) { if (!_suppressEvents) { MerchantDto selected = Selected; if (selected != null) { selected.Roam = value; ShopUiState.MarkDirty(selected); SaveSelected(selected); } } } private static void SaveSelected(MerchantDto merchant) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown if (merchant != null) { BridgeClient.Send(new Payload { Type = "upsert", Merchant = merchant }); } } private static void BuildHeader(GameObject parent) { GameObject obj = UiHelpers.Row(parent, "Header", 40); UiHelpers.ThemedHeader(obj); LabelRef labelRef = UiHelpers.Label(obj, "Title", "ShopUI — управление торговцами", 320, 1, 20, (TextAlignmentOptions)513); labelRef.TextMesh.fontStyle = (FontStyles)1; labelRef.TextMesh.enableWordWrapping = false; ((Graphic)labelRef.TextMesh).raycastTarget = true; _dragHandle = labelRef.GameObject; ButtonRef buttonRef = UiHelpers.Button(obj, "Skin", "Скин: " + Theme.Current.Label, 180, 30); buttonRef.OnClick = ToggleSkinDock; _skinLabel = buttonRef.GameObject.GetComponentInChildren<TextMeshProUGUI>(); UiHelpers.Button(obj, "Close", "X", 42, 30).OnClick = Close; } public static void OnSkinChanged() { if ((Object)(object)_skinLabel != (Object)null) { ((TMP_Text)_skinLabel).text = "Скин: " + Theme.Current.Label; } RefreshSkinDock(); SetStatus("Скин: " + Theme.Current.Label); ClickService.ResetBaseColors(); } private static void BuildToolbar(GameObject parent) { GameObject parent2 = UiHelpers.Row(parent, "Toolbar", 34); UiHelpers.Label(parent2, "MerchantLabel", "Торговец:", 100, 0, 15, (TextAlignmentOptions)513); _merchantButton = UiHelpers.Button(parent2, "MerchantButton", "нет торговцев", 300, 30); GameObject gameObject = _merchantButton.GameObject; float? minWidth = 300f; float? flexibleWidth = 0f; float? minHeight = 30f; float? preferredHeight = 30f; Widgets.SetLayoutElement(gameObject, minWidth, null, flexibleWidth, minHeight, preferredHeight); _merchantButton.OnClick = ToggleMerchantDock; UiHelpers.Spacer(parent2, "ToolbarSpacer"); UiHelpers.Button(parent2, "Add", "Новый", 100, 30).OnClick = OnAddClicked; UiHelpers.Button(parent2, "Delete", "Удалить", 100, 30).OnClick = OnDeleteClicked; ButtonRef buttonRef = UiHelpers.Button(parent2, "Apply", "Применить", 130, 30); UiHelpers.ThemedButton(buttonRef, () => UiHelpers.AccentBright); buttonRef.OnClick = OnApplyClicked; ButtonRef buttonRef2 = UiHelpers.Button(parent2, "RemoveAll", "Убрать всех из мира", 190, 30); UiHelpers.ThemedButton(buttonRef2, () => UiHelpers.AccentDark); buttonRef2.OnClick = OnRemoveAllClicked; } private static void OnRemoveAllClicked() { if (!_removeAllArmed) { _removeAllArmed = true; SetStatus("Точно? Нажмите ещё раз, чтобы убрать всех торговцев из мира."); } else { _removeAllArmed = false; ShopUiState.RemoveAllFromWorld(); SetStatus("Запрос на снятие всех торговцев с мира отправлен."); } } private static void OnStateChanged(Payload payload) { //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Expected O, but got Unknown if (payload == null) { return; } if (payload.Type == "state") { if (_openRequested || payload.OpenPanel == true) { _openRequested = false; ShowFromServer(); } _lastRevision = ShopUiState.Revision; RefreshMerchants(); if (ShopUiState.VersionMismatch) { SetStatus($"Внимание: версия сервера {ShopUiState.ServerVersion}, клиента {Plugin.Version}. Обе части должны быть одной версии."); } } else { if (!(payload.Type == "toast") && !(payload.Type == "denied")) { return; } string text = payload.Message ?? string.Empty; if (payload.AdminGranted.HasValue) { AdminAuth.OnAdminAuthResult(payload.AdminGranted.Value); } if (payload.Type == "denied" && !IsOpen) { if (_openRequested) { _closedByUser = true; _openRequested = false; Toast.Show(text); ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] open denied: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); } logInstance.LogInfo(val); } } else { SetStatus(text); } } } private static void RefreshMerchants() { if (_merchantButton == null) { return; } _suppressEvents = true; try { int num = ShopUiState.Merchants.FindIndex((MerchantDto m) => m.Id == ShopUiState.SelectedId); if (num < 0 && ShopUiState.Merchants.Count > 0) { num = 0; ShopUiState.SelectedId = ShopUiState.Merchants[0].Id; } string text = "нет торговцев"; if (num >= 0 && num < ShopUiState.Merchants.Count) { MerchantDto val = ShopUiState.Merchants[num]; text = (val.Placed ? "● " : "○ ") + (string.IsNullOrEmpty(val.Name) ? "Trader" : val.Name); } if ((Object)(object)_merchantButton.Label != (Object)null) { _merchantButton.Label.text = text; } RefreshMerchantDock(); } finally { _suppressEvents = false; } RefreshEditor(); } private static void OpenMerchantList() { List<string> list = new List<string>(); foreach (MerchantDto merchant in ShopUiState.Merchants) { string text = (merchant.Placed ? "● " : "○ "); list.Add(text + (string.IsNullOrEmpty(merchant.Name) ? "Trader" : merchant.Name)); } if (list.Count == 0) { list.Add("торговцев нет — нажмите «Новый»"); } int selectedIndex = ShopUiState.Merchants.FindIndex((MerchantDto m) => m.Id == ShopUiState.SelectedId); SelectList.Open(Panel, "Торговец", list, selectedIndex, OnMerchantSelected); } private static void OnMerchantSelected(int index) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown if (!_suppressEvents && index >= 0 && index < ShopUiState.Merchants.Count) { ShopUiState.SelectedId = ShopUiState.Merchants[index].Id; ManualLogSource logInstance = Plugin.LogInstance; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ShopUI] merchant selected: '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ShopUiState.Merchants[index].Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(index); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")"); } logInstance.LogInfo(val); RefreshMerchants(); RefreshEditor(); } } private static void OnAddClicked() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown MerchantDto val = new MerchantDto { Id = Guid.NewGuid().ToString("N"), Name = "Новый торговец", TraderPrefab = 1631713257, Placed = false, Roam = false, RestockMinutes = 0, Offers = new List<OfferDto>() }; ShopUiState.SelectedId = val.Id; ShopUiState.UpsertLocal(val); RefreshMerchants(); SetStatus("Торговец создан: выберите префаб, задайте имя, затем «Разместить здесь» и «Применить»."); } private static void OnDeleteClicked() { if (string.IsNullOrEmpty(ShopUiState.SelectedId)) { SetStatus("Торговец не выбран."); return; } ShopUiState.DeleteLocal(ShopUiState.SelectedId); RefreshMerchants(); SetStatus("Торговец удалён. Нажмите «Применить», чтобы убрать его из мира."); } private static void OnApplyClicked() { ShopUiState.ApplyAll(); SetSta
BepInEx/plugins/ShopUI/ShopUI.Shared.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.Json; using System.Text.Json.Serialization; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("ShopUI.Shared")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.8.0")] [assembly: AssemblyInformationalVersion("0.1.8+193d54d01ebba69389dcc92e74f9e830334dfaae")] [assembly: AssemblyProduct("ShopUI.Shared")] [assembly: AssemblyTitle("ShopUI.Shared")] [assembly: AssemblyVersion("0.1.8.0")] [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 ShopUI.Shared { public static class Chunking { private class Envelope { public string Id { get; set; } public int I { get; set; } public int N { get; set; } public string D { get; set; } } private class Buffer { public string[] Parts; public int Have; } private static readonly Dictionary<string, Buffer> Buffers = new Dictionary<string, Buffer>(); private static readonly object Sync = new object(); public static List<string> Split(string payloadJson) { List<string> list = new List<string>(); if (payloadJson == null) { return list; } string id = Guid.NewGuid().ToString("N"); int num = 300; List<string> list2 = new List<string>(); while (true) { list2 = Cut(payloadJson, num); bool flag = true; for (int i = 0; i < list2.Count; i++) { string text = JsonSerializer.Serialize(new Envelope { Id = id, I = i, N = list2.Count, D = list2[i] }, Protocol.Json); if ("[[SHOPUI]]".Length + text.Length > 460) { flag = false; break; } } if (flag || num <= 1) { break; } num = Math.Max(1, num * 9 / 10); } if (list2.Count == 0) { list2.Add(string.Empty); } for (int j = 0; j < list2.Count; j++) { Envelope value = new Envelope { Id = id, I = j, N = list2.Count, D = list2[j] }; list.Add(JsonSerializer.Serialize(value, Protocol.Json)); } return list; } private static List<string> Cut(string payloadJson, int take) { List<string> list = new List<string>(); int num; for (int i = 0; i < payloadJson.Length; i += num) { num = Math.Min(take, payloadJson.Length - i); list.Add(payloadJson.Substring(i, num)); } return list; } public static bool TryAccept(string message, out string payloadJson) { payloadJson = null; if (string.IsNullOrEmpty(message) || !message.StartsWith("[[SHOPUI]]")) { return false; } try { Envelope envelope = JsonSerializer.Deserialize<Envelope>(message.Substring("[[SHOPUI]]".Length), Protocol.Json); if (envelope == null || string.IsNullOrEmpty(envelope.Id) || envelope.N <= 0 || envelope.I < 0 || envelope.I >= envelope.N) { return false; } lock (Sync) { if (!Buffers.TryGetValue(envelope.Id, out var value)) { value = new Buffer { Parts = new string[envelope.N], Have = 0 }; Buffers[envelope.Id] = value; } if (value.Parts.Length != envelope.N) { Buffers.Remove(envelope.Id); return false; } if (value.Parts[envelope.I] == null) { value.Parts[envelope.I] = envelope.D ?? string.Empty; value.Have++; } if (value.Have < value.Parts.Length) { return false; } payloadJson = string.Concat(value.Parts); Buffers.Remove(envelope.Id); return true; } } catch { return false; } } } public static class Protocol { public const string Prefix = "[[SHOPUI]]"; public const int DefaultTraderPrefab = 1631713257; public const int MaxChunkChars = 300; public const int MaxMessageChars = 460; public static readonly JsonSerializerOptions Json = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNameCaseInsensitive = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; } public class Payload { public string Type { get; set; } public string Message { get; set; } public MerchantDto Merchant { get; set; } public List<MerchantDto> Merchants { get; set; } public string MerchantId { get; set; } public int Revision { get; set; } public string Session { get; set; } public bool? AdminGranted { get; set; } public bool? OpenPanel { get; set; } public string ClientVersion { get; set; } public string ServerVersion { get; set; } } public class MerchantDto { public string Id { get; set; } public string Name { get; set; } public int TraderPrefab { get; set; } public float X { get; set; } public float Y { get; set; } public float Z { get; set; } public bool Placed { get; set; } public bool Roam { get; set; } public int RestockMinutes { get; set; } public List<OfferDto> Offers { get; set; } = new List<OfferDto>(); public bool ClearOffers { get; set; } public bool Unplaced { get; set; } } public class OfferDto { public int Output { get; set; } public int OutputAmount { get; set; } public int Input { get; set; } public int InputAmount { get; set; } public int Stock { get; set; } } public static class StateMerge { public static void Merge(List<MerchantDto> target, List<MerchantDto> incoming) { Merge(target, incoming, null); } public static void Merge(List<MerchantDto> target, List<MerchantDto> incoming, Func<string, bool> isDirty) { if (target == null) { return; } if (incoming == null) { incoming = new List<MerchantDto>(); } foreach (MerchantDto item in incoming) { if (item != null && !string.IsNullOrEmpty(item.Id)) { MerchantDto merchantDto = Find(target, item.Id); if (merchantDto == null) { target.Add(item); } else if (isDirty != null && isDirty(item.Id)) { merchantDto.X = item.X; merchantDto.Y = item.Y; merchantDto.Z = item.Z; merchantDto.Placed = item.Placed; } else { Copy(item, merchantDto); } } } for (int num = target.Count - 1; num >= 0; num--) { if ((isDirty == null || !isDirty(target[num].Id)) && !Contains(incoming, target[num].Id)) { target.RemoveAt(num); } } } public static void Copy(MerchantDto src, MerchantDto dst) { if (src != null && dst != null) { dst.Name = src.Name; dst.TraderPrefab = src.TraderPrefab; dst.X = src.X; dst.Y = src.Y; dst.Z = src.Z; dst.Placed = src.Placed; dst.Roam = src.Roam; dst.RestockMinutes = src.RestockMinutes; dst.ClearOffers = src.ClearOffers; SyncOffers(dst, src.Offers); } } public static void SyncOffers(MerchantDto dst, List<OfferDto> incoming) { if (dst == null) { return; } if (dst.Offers == null) { List<OfferDto> list = (dst.Offers = new List<OfferDto>()); } if (incoming == null) { incoming = new List<OfferDto>(); } while (dst.Offers.Count > incoming.Count) { dst.Offers.RemoveAt(dst.Offers.Count - 1); } for (int i = 0; i < incoming.Count; i++) { OfferDto offerDto = incoming[i]; if (offerDto != null) { if (i < dst.Offers.Count) { OfferDto offerDto2 = dst.Offers[i]; offerDto2.Output = offerDto.Output; offerDto2.OutputAmount = offerDto.OutputAmount; offerDto2.Input = offerDto.Input; offerDto2.InputAmount = offerDto.InputAmount; offerDto2.Stock = offerDto.Stock; } else { dst.Offers.Add(new OfferDto { Output = offerDto.Output, OutputAmount = offerDto.OutputAmount, Input = offerDto.Input, InputAmount = offerDto.InputAmount, Stock = offerDto.Stock }); } } } } private static MerchantDto Find(List<MerchantDto> list, string id) { for (int i = 0; i < list.Count; i++) { if (list[i] != null && list[i].Id == id) { return list[i]; } } return null; } private static bool Contains(List<MerchantDto> list, string id) { for (int i = 0; i < list.Count; i++) { if (list[i] != null && list[i].Id == id) { return true; } } return false; } } }