Decompiled source of PeachSell v0.2.0

PeachSell.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using Platforms;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PeachSell;

internal class AuthorTag : MonoBehaviour
{
	private const string Gold = "#FFD700";

	private const string GoldOpen = "<color=#FFD700>";

	private static string _authorName;

	private static Harmony _harmony;

	private static float _nextScan;

	internal static void Init(GameObject root)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		try
		{
			_harmony = new Harmony("com.peachh.peachsell.tag");
			PropertyInfo property = typeof(TMP_Text).GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
			if (property != null)
			{
				MethodInfo setMethod = property.GetSetMethod();
				HarmonyMethod val = new HarmonyMethod(typeof(AuthorTag).GetMethod("TextSetterPrefix", BindingFlags.Static | BindingFlags.NonPublic));
				_harmony.Patch((MethodBase)setMethod, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo methodInfo = AccessTools.Method(typeof(TMP_Text), "SetText", new Type[1] { typeof(string) }, (Type[])null);
			if (methodInfo != null)
			{
				HarmonyMethod val2 = new HarmonyMethod(typeof(AuthorTag).GetMethod("SetTextPrefix", BindingFlags.Static | BindingFlags.NonPublic));
				_harmony.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			root.AddComponent<AuthorTag>();
		}
		catch (Exception ex)
		{
			Plugin.Warn("名字高亮补丁挂载失败: " + ex);
		}
	}

	private void Update()
	{
		if (!(Time.unscaledTime < _nextScan))
		{
			_nextScan = Time.unscaledTime + 5f;
			ScanAuthorName();
		}
	}

	private static void ScanAuthorName()
	{
		foreach (PlayerAvatar item in GameRefs.Players())
		{
			if (Permissions.IsAuthorSteam(GameRefs.SteamId(item)))
			{
				string text = GameRefs.PlayerName(item);
				if (!string.IsNullOrEmpty(text))
				{
					_authorName = text;
					return;
				}
			}
		}
		_authorName = null;
	}

	private static void TextSetterPrefix(TMP_Text __instance, ref string value)
	{
		if (ShouldDecorate(__instance, value))
		{
			value = Decorate(value);
		}
	}

	private static void SetTextPrefix(TMP_Text __instance, ref string __0)
	{
		if (ShouldDecorate(__instance, __0))
		{
			__0 = Decorate(__0);
		}
	}

	private static bool ShouldDecorate(TMP_Text target, string text)
	{
		if ((Object)(object)target == (Object)null || string.IsNullOrEmpty(text))
		{
			return false;
		}
		string authorName = _authorName;
		if (string.IsNullOrEmpty(authorName))
		{
			return false;
		}
		if (text.IndexOf(authorName, StringComparison.Ordinal) < 0)
		{
			return false;
		}
		if (!target.richText)
		{
			return false;
		}
		if (IsInputFieldText(target))
		{
			return false;
		}
		try
		{
			return SemiFunc.RunIsLevel();
		}
		catch
		{
			return false;
		}
	}

	private static bool IsInputFieldText(TMP_Text target)
	{
		try
		{
			return (Object)(object)((Component)target).GetComponentInParent<TMP_InputField>() != (Object)null;
		}
		catch
		{
			return false;
		}
	}

	private static string Decorate(string source)
	{
		if (string.IsNullOrEmpty(source))
		{
			return source;
		}
		string authorName = _authorName;
		if (string.IsNullOrEmpty(authorName))
		{
			return source;
		}
		if (source.IndexOf("<color=#FFD700>", StringComparison.Ordinal) >= 0)
		{
			return source;
		}
		StringBuilder stringBuilder = null;
		int num = 0;
		while (true)
		{
			int num2 = source.IndexOf(authorName, num, StringComparison.Ordinal);
			if (num2 < 0)
			{
				break;
			}
			int num3 = num2 + authorName.Length;
			bool num4 = num2 == 0 || !IsNameChar(source[num2 - 1]);
			bool flag = num3 >= source.Length || !IsNameChar(source[num3]);
			if (num4 && flag)
			{
				if (stringBuilder == null)
				{
					stringBuilder = new StringBuilder(source.Length + 32);
				}
				stringBuilder.Append(source, num, num2 - num);
				stringBuilder.Append("<color=#FFD700>").Append(authorName).Append("</color>");
				num = num3;
			}
			else
			{
				num = num2 + 1;
			}
		}
		if (stringBuilder == null)
		{
			return source;
		}
		stringBuilder.Append(source, num, source.Length - num);
		return stringBuilder.ToString();
	}

	private static bool IsNameChar(char c)
	{
		if (!char.IsLetterOrDigit(c))
		{
			return c == '_';
		}
		return true;
	}
}
internal static class ConfigLabels
{
	private sealed class TrackedLabel
	{
		internal WeakReference Target;

		internal string English;
	}

	private static readonly Dictionary<string, string> EnToCn;

	private static readonly Dictionary<string, string> CnToEn;

	private static readonly List<TrackedLabel> Tracked;

	private const int MaxTracked = 512;

	private static readonly Dictionary<Type, PropertyInfo> TextSetters;

	static ConfigLabels()
	{
		EnToCn = new Dictionary<string, string>(StringComparer.Ordinal);
		CnToEn = new Dictionary<string, string>(StringComparer.Ordinal);
		Tracked = new List<TrackedLabel>();
		TextSetters = new Dictionary<Type, PropertyInfo>();
		Add("General", "通用");
		Add("Sell", "出售");
		Add("Input", "按键");
		Add("Permissions", "权限");
		Add("UI", "界面");
		Add("Language", "语言");
		Add("RefundPercent", "回收比例");
		Add("Refund Percent", "回收比例");
		Add("PanelKey", "面板按键");
		Add("Panel Key", "面板按键");
		Add("SellKey", "手持出售键");
		Add("Sell Key", "手持出售键");
		Add("AllowLobbySell", "允许大厅出售");
		Add("Allow Lobby Sell", "允许大厅出售");
		Add("WhitelistSteamIds", "白名单");
		Add("Whitelist Steam Ids", "白名单");
		Add("BlacklistSteamIds", "黑名单");
		Add("Blacklist Steam Ids", "黑名单");
		Add("ShowStatusHud", "显示状态提示");
		Add("Show Status Hud", "显示状态提示");
		Add("Debug", "调试日志");
		Add("Auto", "自动");
		Add("Chinese", "中文");
		Add("English", "英文");
	}

	private static void Add(string english, string chinese)
	{
		EnToCn[english] = chinese;
	}

	internal static void AddPair(string english, string chinese, bool bothWays)
	{
		if (!string.IsNullOrEmpty(english) && !string.IsNullOrEmpty(chinese) && !string.Equals(english, chinese, StringComparison.Ordinal))
		{
			EnToCn[english] = chinese;
			if (bothWays)
			{
				CnToEn[chinese] = english;
			}
		}
	}

	private static void Translate(ref string __0, object __instance)
	{
		if (string.IsNullOrEmpty(__0))
		{
			return;
		}
		string text = __0;
		string value2;
		if (EnToCn.TryGetValue(text, out var value))
		{
			value2 = text;
		}
		else
		{
			if (!CnToEn.TryGetValue(text, out value2))
			{
				return;
			}
			value = text;
		}
		Track(__instance, value2);
		__0 = (Plugin.Chinese ? value : value2);
	}

	private static void TranslateOnly(ref string __0)
	{
		if (!string.IsNullOrEmpty(__0) && EnToCn.TryGetValue(__0, out var value) && Plugin.Chinese)
		{
			__0 = value;
		}
	}

	internal static void Install(Harmony harmony)
	{
		int num = PatchEverything(harmony, "Translate");
		if (num == 0)
		{
			num = PatchEverything(harmony, "TranslateOnly");
		}
		if (num == 0)
		{
			Plugin.Warn("配置菜单文本补丁没有找到可挂的 setter,标题保持英文。");
		}
		else
		{
			Plugin.Dbg("配置菜单文本补丁:" + num + " 个 setter");
		}
	}

	private static int PatchEverything(Harmony harmony, string prefixName)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		MethodInfo method = typeof(ConfigLabels).GetMethod(prefixName, BindingFlags.Static | BindingFlags.NonPublic);
		if (method == null)
		{
			return 0;
		}
		HarmonyMethod prefix = new HarmonyMethod(method);
		HashSet<MethodInfo> seen = new HashSet<MethodInfo>();
		return 0 + PatchSetter(harmony, prefix, seen, "TMPro.TMP_Text", "Unity.TextMeshPro") + PatchSetter(harmony, prefix, seen, "TMPro.TextMeshProUGUI", "Unity.TextMeshPro") + PatchSetter(harmony, prefix, seen, "TMPro.TextMeshPro", "Unity.TextMeshPro") + PatchSetter(harmony, prefix, seen, "UnityEngine.UI.Text", "UnityEngine.UI");
	}

	private static int PatchSetter(Harmony harmony, HarmonyMethod prefix, HashSet<MethodInfo> seen, string typeName, string assemblyName)
	{
		int num = 0;
		try
		{
			Type type = FindType(typeName, assemblyName);
			if (type == null)
			{
				return 0;
			}
			PropertyInfo property = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
			MethodInfo methodInfo = Declared((property == null) ? null : property.GetSetMethod());
			if (methodInfo != null && methodInfo.GetParameters().Length == 1 && seen.Add(methodInfo))
			{
				harmony.Patch((MethodBase)methodInfo, prefix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				num++;
			}
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public);
			foreach (MethodInfo methodInfo2 in methods)
			{
				if (methodInfo2.Name != "SetText")
				{
					continue;
				}
				ParameterInfo[] parameters = methodInfo2.GetParameters();
				if (parameters.Length == 1 && !(parameters[0].ParameterType != typeof(string)))
				{
					MethodInfo methodInfo3 = Declared(methodInfo2);
					if (!(methodInfo3 == null) && seen.Add(methodInfo3))
					{
						harmony.Patch((MethodBase)methodInfo3, prefix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("配置标签补丁跳过 " + typeName + ":" + ex.Message);
		}
		return num;
	}

	private static MethodInfo Declared(MethodInfo m)
	{
		if (m == null || m.DeclaringType == null || m.DeclaringType == m.ReflectedType)
		{
			return m;
		}
		ParameterInfo[] parameters = m.GetParameters();
		Type[] array = new Type[parameters.Length];
		for (int i = 0; i < parameters.Length; i++)
		{
			array[i] = parameters[i].ParameterType;
		}
		return m.DeclaringType.GetMethod(m.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, array, null) ?? m;
	}

	private static Type FindType(string typeName, string assemblyName)
	{
		Type type = Type.GetType(typeName + ", " + assemblyName, throwOnError: false);
		if (type != null)
		{
			return type;
		}
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			if (!(assembly.GetName().Name != assemblyName))
			{
				type = assembly.GetType(typeName, throwOnError: false);
				if (type != null)
				{
					return type;
				}
			}
		}
		return null;
	}

	private static void Track(object instance, string english)
	{
		if (instance == null)
		{
			return;
		}
		for (int i = 0; i < Tracked.Count; i++)
		{
			object target = Tracked[i].Target.Target;
			if (target != null && target == instance)
			{
				Tracked[i].English = english;
				return;
			}
		}
		if (Tracked.Count >= 512)
		{
			for (int num = Tracked.Count - 1; num >= 0; num--)
			{
				if (!Tracked[num].Target.IsAlive)
				{
					Tracked.RemoveAt(num);
				}
			}
			if (Tracked.Count >= 512)
			{
				Tracked.RemoveAt(0);
			}
		}
		Tracked.Add(new TrackedLabel
		{
			Target = new WeakReference(instance),
			English = english
		});
	}

	internal static void RefreshAll()
	{
		for (int num = Tracked.Count - 1; num >= 0; num--)
		{
			TrackedLabel trackedLabel = Tracked[num];
			object target = trackedLabel.Target.Target;
			if (target == null)
			{
				Tracked.RemoveAt(num);
			}
			else
			{
				try
				{
					SetText(target, trackedLabel.English);
				}
				catch
				{
					Tracked.RemoveAt(num);
				}
			}
		}
	}

	private static bool SetText(object target, string english)
	{
		Type type = target.GetType();
		if (!TextSetters.TryGetValue(type, out var value))
		{
			value = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
			TextSetters[type] = value;
		}
		if (value == null || !value.CanWrite)
		{
			return false;
		}
		value.SetValue(target, english, null);
		return true;
	}

	internal static bool GameIsChinese()
	{
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Invalid comparison between Unknown and I4
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Invalid comparison between Unknown and I4
		try
		{
			Type type = FindGameType("LocalizationManager");
			if (type != null)
			{
				object obj = type.GetField("instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null) ?? type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null, null);
				if (obj != null)
				{
					object obj2 = type.GetProperty("ActiveLocale")?.GetValue(obj, null);
					object obj3 = obj2?.GetType().GetProperty("LocaleReference")?.GetValue(obj2, null);
					object obj4 = obj3?.GetType().GetProperty("Identifier")?.GetValue(obj3, null);
					string text = obj4?.GetType().GetProperty("Code")?.GetValue(obj4, null) as string;
					if (!string.IsNullOrEmpty(text))
					{
						return text.StartsWith("zh", StringComparison.OrdinalIgnoreCase);
					}
				}
			}
		}
		catch
		{
		}
		SystemLanguage systemLanguage = Application.systemLanguage;
		if ((int)systemLanguage == 6 || systemLanguage - 40 <= 1)
		{
			return true;
		}
		return false;
	}

	private static Type FindGameType(string name)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			if (!(assembly.GetName().Name != "Assembly-CSharp"))
			{
				Type type = assembly.GetType(name, throwOnError: false);
				if (type != null)
				{
					return type;
				}
			}
		}
		return Type.GetType(name + ", Assembly-CSharp", throwOnError: false);
	}
}
internal static class GameRefs
{
	private static FieldInfo _attrValue;

	private static FieldInfo _attrShopItem;

	private static FieldInfo _attrInstanceName;

	private static FieldInfo _attrCachedName;

	private static FieldInfo _valuableOverride;

	private static FieldInfo _playerSteamId;

	private static FieldInfo _playerName;

	internal static FieldInfo MenuPage;

	internal static PlayerAvatar LocalAvatar => PlayerAvatar.instance;

	internal static void Init()
	{
		try
		{
			Type? typeFromHandle = typeof(ItemAttributes);
			_attrValue = AccessTools.Field(typeFromHandle, "value");
			_attrShopItem = AccessTools.Field(typeFromHandle, "shopItem");
			_attrInstanceName = AccessTools.Field(typeFromHandle, "instanceName");
			_attrCachedName = AccessTools.Field(typeFromHandle, "cachedItemName");
			_valuableOverride = AccessTools.Field(typeof(ValuableObject), "dollarValueOverride");
			Type? typeFromHandle2 = typeof(PlayerAvatar);
			_playerSteamId = AccessTools.Field(typeFromHandle2, "steamID");
			_playerName = AccessTools.Field(typeFromHandle2, "playerName");
			MenuPage = AccessTools.Field(typeof(MenuManager), "currentMenuPage");
		}
		catch (Exception ex)
		{
			Plugin.Warn("反射初始化失败(部分功能会降级): " + ex);
		}
		if (_attrValue == null)
		{
			Plugin.Warn("ItemAttributes.value 未找到,回收金额会退化为最低值");
		}
		if (_attrValue == null || _attrShopItem == null || _attrInstanceName == null)
		{
			Plugin.Warn("ItemAttributes 关键字段缺失,出售校验可能失效");
		}
		if (_valuableOverride == null)
		{
			Plugin.Warn("ValuableObject.dollarValueOverride 未找到,钱袋金额会随机");
		}
		if (_playerSteamId == null)
		{
			Plugin.Warn("PlayerAvatar.steamID 未找到,权限系统将失效");
		}
	}

	internal static int GetValue(ItemAttributes attr)
	{
		if ((Object)(object)attr == (Object)null || _attrValue == null)
		{
			return 1;
		}
		try
		{
			object value = _attrValue.GetValue(attr);
			if (value is int)
			{
				return (int)value;
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("GetValue: " + ex.Message);
		}
		return 1;
	}

	internal static bool IsShopItem(ItemAttributes attr)
	{
		if ((Object)(object)attr == (Object)null || _attrShopItem == null)
		{
			return false;
		}
		try
		{
			return (bool)_attrShopItem.GetValue(attr);
		}
		catch
		{
			return false;
		}
	}

	internal static string InstanceName(ItemAttributes attr)
	{
		if ((Object)(object)attr == (Object)null || _attrInstanceName == null)
		{
			return null;
		}
		try
		{
			return _attrInstanceName.GetValue(attr) as string;
		}
		catch
		{
			return null;
		}
	}

	internal static string DisplayName(ItemAttributes attr)
	{
		if ((Object)(object)attr == (Object)null)
		{
			return "?";
		}
		try
		{
			string text = ((_attrCachedName != null) ? (_attrCachedName.GetValue(attr) as string) : null);
			if (!string.IsNullOrEmpty(text))
			{
				return text;
			}
		}
		catch
		{
		}
		if (Object.op_Implicit((Object)(object)attr.item))
		{
			try
			{
				if (!string.IsNullOrEmpty(attr.item.itemName))
				{
					return attr.item.itemName;
				}
			}
			catch
			{
			}
		}
		if (!Object.op_Implicit((Object)(object)((Component)attr).gameObject))
		{
			return "?";
		}
		return ((Object)((Component)attr).gameObject).name;
	}

	internal static bool SetBagValue(ValuableObject valuable, int dollars)
	{
		if ((Object)(object)valuable == (Object)null)
		{
			return false;
		}
		if (_valuableOverride == null)
		{
			Plugin.Warn("无法设置钱袋金额(dollarValueOverride 缺失)");
			return false;
		}
		try
		{
			_valuableOverride.SetValue(valuable, dollars);
			return true;
		}
		catch (Exception ex)
		{
			Plugin.Warn("设置钱袋金额失败: " + ex.Message);
			return false;
		}
	}

	internal static string SteamId(PlayerAvatar avatar)
	{
		if ((Object)(object)avatar == (Object)null || _playerSteamId == null)
		{
			return null;
		}
		try
		{
			return _playerSteamId.GetValue(avatar) as string;
		}
		catch
		{
			return null;
		}
	}

	internal static string PlayerName(PlayerAvatar avatar)
	{
		if ((Object)(object)avatar == (Object)null)
		{
			return null;
		}
		if (_playerName != null)
		{
			try
			{
				string text = _playerName.GetValue(avatar) as string;
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
			}
			catch
			{
			}
		}
		try
		{
			return ((Object)(object)avatar.photonView != (Object)null) ? avatar.photonView.Owner.NickName : null;
		}
		catch
		{
			return null;
		}
	}

	internal static string LocalSteamId()
	{
		try
		{
			PlatformManager instance = PlatformManager.instance;
			if ((Object)(object)instance != (Object)null)
			{
				string platformUserId = instance.GetPlatformUserId();
				if (!string.IsNullOrEmpty(platformUserId))
				{
					return platformUserId;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("GetPlatformUserId: " + ex.Message);
		}
		return SteamId(LocalAvatar);
	}

	internal static PlayerAvatar AvatarByActor(int actorNumber)
	{
		try
		{
			GameDirector instance = GameDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.PlayerList == null)
			{
				return null;
			}
			foreach (PlayerAvatar player in instance.PlayerList)
			{
				if (!((Object)(object)player == (Object)null) && !((Object)(object)player.photonView == (Object)null) && player.photonView.OwnerActorNr == actorNumber)
				{
					return player;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("AvatarByActor: " + ex.Message);
		}
		return null;
	}

	internal static List<PlayerAvatar> Players()
	{
		List<PlayerAvatar> list = new List<PlayerAvatar>();
		try
		{
			GameDirector instance = GameDirector.instance;
			if ((Object)(object)instance != (Object)null && instance.PlayerList != null)
			{
				foreach (PlayerAvatar player in instance.PlayerList)
				{
					if ((Object)(object)player != (Object)null)
					{
						list.Add(player);
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("Players: " + ex.Message);
		}
		return list;
	}

	internal static bool InGameLevel()
	{
		try
		{
			return SemiFunc.RunIsLevel() || SemiFunc.RunIsLobby() || SemiFunc.RunIsShop();
		}
		catch (Exception ex)
		{
			Plugin.Dbg("InGameLevel: " + ex.Message);
			return false;
		}
	}

	internal static bool InTruck(PlayerAvatar avatar)
	{
		if ((Object)(object)avatar == (Object)null)
		{
			return false;
		}
		try
		{
			RoomVolumeCheck roomVolumeCheck = avatar.RoomVolumeCheck;
			if ((Object)(object)roomVolumeCheck == (Object)null || roomVolumeCheck.CurrentRooms == null)
			{
				return false;
			}
			foreach (RoomVolume currentRoom in roomVolumeCheck.CurrentRooms)
			{
				if ((Object)(object)currentRoom != (Object)null && currentRoom.Truck)
				{
					return true;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("InTruck(player): " + ex.Message);
		}
		return false;
	}

	internal static bool ItemInTruck(ItemAttributes attr, PlayerAvatar seller)
	{
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)attr == (Object)null || !Object.op_Implicit((Object)(object)((Component)attr).gameObject))
		{
			return false;
		}
		try
		{
			RoomVolumeCheck val = ((Component)attr).GetComponent<RoomVolumeCheck>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)attr).GetComponentInParent<RoomVolumeCheck>();
			}
			if ((Object)(object)val != (Object)null && val.CurrentRooms != null && val.CurrentRooms.Count > 0)
			{
				foreach (RoomVolume currentRoom in val.CurrentRooms)
				{
					if ((Object)(object)currentRoom != (Object)null && currentRoom.Truck)
					{
						return true;
					}
				}
				return false;
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("ItemInTruck: " + ex.Message);
		}
		if ((Object)(object)seller == (Object)null || !InTruck(seller))
		{
			return false;
		}
		return Vector3.Distance(((Component)attr).transform.position, ((Component)seller).transform.position) <= 4f;
	}
}
internal static class Permissions
{
	private static string[] Split(string raw)
	{
		if (string.IsNullOrEmpty(raw))
		{
			return Array.Empty<string>();
		}
		return raw.Split(new char[6] { ',', ';', ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
	}

	internal static bool IsAuthorSteam(string steamId)
	{
		if (string.IsNullOrEmpty(steamId))
		{
			return false;
		}
		return steamId == "76561199082855746";
	}

	internal static bool IsLocalAuthor()
	{
		return IsAuthorSteam(GameRefs.LocalSteamId());
	}

	internal static bool IsWhitelisted(string steamId)
	{
		if (string.IsNullOrEmpty(steamId) || Plugin.WhitelistSteamIds == null)
		{
			return false;
		}
		string[] array = Split(Plugin.WhitelistSteamIds.Value);
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] == steamId)
			{
				return true;
			}
		}
		return false;
	}

	internal static bool IsBlacklisted(string steamId)
	{
		if (string.IsNullOrEmpty(steamId) || Plugin.BlacklistSteamIds == null)
		{
			return false;
		}
		string[] array = Split(Plugin.BlacklistSteamIds.Value);
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] == steamId)
			{
				return true;
			}
		}
		return false;
	}

	internal static bool CanSell(string steamId)
	{
		if (string.IsNullOrEmpty(steamId))
		{
			return false;
		}
		if (IsBlacklisted(steamId))
		{
			return false;
		}
		if (IsAuthorSteam(steamId))
		{
			return true;
		}
		return IsWhitelisted(steamId);
	}

	internal static List<string> WhitelistIds()
	{
		return new List<string>(Split((Plugin.WhitelistSteamIds != null) ? Plugin.WhitelistSteamIds.Value : null));
	}

	internal static List<string> BlacklistIds()
	{
		return new List<string>(Split((Plugin.BlacklistSteamIds != null) ? Plugin.BlacklistSteamIds.Value : null));
	}

	internal static void SetWhitelisted(string steamId, bool allowed)
	{
		if (!string.IsNullOrEmpty(steamId) && Plugin.WhitelistSteamIds != null && !IsAuthorSteam(steamId))
		{
			List<string> list = new List<string>(Split(Plugin.WhitelistSteamIds.Value));
			list.RemoveAll((string id) => id == steamId);
			if (allowed)
			{
				list.Add(steamId);
			}
			Plugin.WhitelistSteamIds.Value = string.Join(",", list);
			if (allowed)
			{
				SetBlacklisted(steamId, blocked: false);
			}
		}
	}

	internal static void SetBlacklisted(string steamId, bool blocked)
	{
		if (!string.IsNullOrEmpty(steamId) && Plugin.BlacklistSteamIds != null && !IsAuthorSteam(steamId))
		{
			List<string> list = new List<string>(Split(Plugin.BlacklistSteamIds.Value));
			list.RemoveAll((string id) => id == steamId);
			if (blocked)
			{
				list.Add(steamId);
			}
			Plugin.BlacklistSteamIds.Value = string.Join(",", list);
		}
	}

	internal static string ItemKey(Item item)
	{
		if ((Object)(object)item == (Object)null)
		{
			return string.Empty;
		}
		string text = null;
		try
		{
			text = ((Object)item).name;
		}
		catch
		{
		}
		if (string.IsNullOrEmpty(text))
		{
			try
			{
				text = item.itemName;
			}
			catch
			{
			}
		}
		if (string.IsNullOrEmpty(text))
		{
			return string.Empty;
		}
		StringBuilder stringBuilder = new StringBuilder(text.Length);
		string text2 = text;
		foreach (char c in text2)
		{
			if (char.IsLetterOrDigit(c))
			{
				stringBuilder.Append(char.ToLowerInvariant(c));
			}
		}
		return stringBuilder.ToString();
	}

	private static string[] SplitItems(string raw)
	{
		if (string.IsNullOrEmpty(raw))
		{
			return Array.Empty<string>();
		}
		return raw.Split(new char[3] { ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
	}

	internal static bool IsItemBlacklisted(Item item)
	{
		if ((Object)(object)item == (Object)null || Plugin.BlacklistItems == null)
		{
			return false;
		}
		string text = ItemKey(item);
		if (text.Length == 0)
		{
			return false;
		}
		string[] array = SplitItems(Plugin.BlacklistItems.Value);
		for (int i = 0; i < array.Length; i++)
		{
			if (string.Equals(array[i].Trim(), text, StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
		}
		return false;
	}

	internal static List<string> ItemBlacklistIds()
	{
		return new List<string>(SplitItems((Plugin.BlacklistItems != null) ? Plugin.BlacklistItems.Value : null));
	}

	internal static void SetItemBlacklisted(Item item, bool blocked)
	{
		if ((Object)(object)item == (Object)null || Plugin.BlacklistItems == null)
		{
			return;
		}
		string key = ItemKey(item);
		if (key.Length != 0)
		{
			List<string> list = new List<string>(SplitItems(Plugin.BlacklistItems.Value));
			list.RemoveAll((string name) => string.Equals(name.Trim(), key, StringComparison.OrdinalIgnoreCase));
			if (blocked)
			{
				list.Add(key);
			}
			Plugin.BlacklistItems.Value = string.Join(";", list);
		}
	}
}
[BepInPlugin("com.peachh.peachsell", "PeachSell", "0.2.0")]
public sealed class Plugin : BaseUnityPlugin
{
	public enum UiLanguage
	{
		Auto,
		Chinese,
		English
	}

	public const string Guid = "com.peachh.peachsell";

	public const string ModName = "PeachSell";

	public const string Version = "0.2.0";

	public const string AuthorSteamId = "76561199082855746";

	internal static ConfigEntry<UiLanguage> Language;

	internal static ConfigEntry<float> RefundPercent;

	internal static ConfigEntry<string> PanelKey;

	internal static ConfigEntry<string> SellKey;

	internal static ConfigEntry<bool> AllowLobbySell;

	internal static ConfigEntry<string> WhitelistSteamIds;

	internal static ConfigEntry<string> BlacklistSteamIds;

	internal static ConfigEntry<string> BlacklistItems;

	internal static ConfigEntry<bool> ShowStatusHud;

	internal static ConfigEntry<bool> DebugLog;

	internal static SellNet Net;

	internal static SellPanel Panel;

	private const string LanguageCn = "Auto 跟随游戏语言;Chinese / English 强制指定。";

	private const string LanguageEn = "Auto follows the game language; Chinese / English force it.";

	private const string RefundCn = "卖出已购物品时按原价返还的比例(0~1),默认 0.8。";

	private const string RefundEn = "Refund ratio applied to the purchase price when an item is sold back (0..1), default 0.8.";

	private const string PanelKeyCn = "卡车里打开回收面板的按键,支持 BackQuote(` / ~)或任意 KeyCode 名称,默认 `。旧版的 H / F8 会自动迁移。";

	private const string PanelKeyEn = "Key that opens the recycle panel inside the truck. Accepts BackQuote (` / ~) or any KeyCode name, default `. Old H / F8 values are migrated automatically.";

	private const string SellKeyCn = "在卡车里拿着物品时按此键回收,默认 X。";

	private const string SellKeyEn = "Key that sells the item you are holding inside the truck, default X.";

	private const string LobbyCn = "允许在大厅出售。大厅没有提取点,钱袋无法兑现,默认关闭。";

	private const string LobbyEn = "Allow selling in the lobby. The lobby has no extraction point, so money bags cannot be cashed there. Off by default.";

	private const string WhiteCn = "允许出售的 SteamID64,逗号分隔。房主可在回收面板里直接授权,省去手改。";

	private const string WhiteEn = "Comma separated SteamID64 list allowed to sell. The host can also grant access from the panel.";

	private const string BlackCn = "禁止出售的 SteamID64,逗号分隔,优先于白名单。";

	private const string BlackEn = "Comma separated SteamID64 list blocked from selling; takes priority over the whitelist.";

	private const string ItemBlackCn = "禁止出售的物品名,逗号分隔(按物品资产名匹配)。黑名单物品在面板里对普通玩家不可回收,房主仍可回收。";

	private const string ItemBlackEn = "Comma separated item names blocked from selling (matched against the item asset name). Regular players cannot sell them back; the host still can.";

	private const string HudCn = "在卡车里显示当前是主机、客机还是未装模组。";

	private const string HudEn = "Show whether the host runs PeachSell while standing inside the truck.";

	private const string DebugCn = "输出详细调试日志。";

	private const string DebugEn = "Verbose debug logging.";

	internal static Plugin Instance { get; private set; }

	internal static bool Chinese { get; private set; }

	private static string T(string cn, string en)
	{
		if (!Chinese)
		{
			return en;
		}
		return cn;
	}

	private void Awake()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Expected O, but got Unknown
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Expected O, but got Unknown
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Expected O, but got Unknown
		Instance = this;
		Language = ((BaseUnityPlugin)this).Config.Bind<UiLanguage>("General", "Language", UiLanguage.Auto, "Auto 跟随游戏语言;Chinese / English 强制指定。\nAuto follows the game language; Chinese / English force it.");
		Chinese = ResolveChinese(Language.Value);
		RefundPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Sell", "RefundPercent", 0.8f, new ConfigDescription(T("卖出已购物品时按原价返还的比例(0~1),默认 0.8。", "Refund ratio applied to the purchase price when an item is sold back (0..1), default 0.8."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		AllowLobbySell = ((BaseUnityPlugin)this).Config.Bind<bool>("Sell", "AllowLobbySell", false, T("允许在大厅出售。大厅没有提取点,钱袋无法兑现,默认关闭。", "Allow selling in the lobby. The lobby has no extraction point, so money bags cannot be cashed there. Off by default."));
		PanelKey = ((BaseUnityPlugin)this).Config.Bind<string>("Input", "PanelKey", "`", T("卡车里打开回收面板的按键,支持 BackQuote(` / ~)或任意 KeyCode 名称,默认 `。旧版的 H / F8 会自动迁移。", "Key that opens the recycle panel inside the truck. Accepts BackQuote (` / ~) or any KeyCode name, default `. Old H / F8 values are migrated automatically."));
		SellKey = ((BaseUnityPlugin)this).Config.Bind<string>("Input", "SellKey", "X", T("在卡车里拿着物品时按此键回收,默认 X。", "Key that sells the item you are holding inside the truck, default X."));
		WhitelistSteamIds = ((BaseUnityPlugin)this).Config.Bind<string>("Permissions", "WhitelistSteamIds", "", T("允许出售的 SteamID64,逗号分隔。房主可在回收面板里直接授权,省去手改。", "Comma separated SteamID64 list allowed to sell. The host can also grant access from the panel."));
		BlacklistSteamIds = ((BaseUnityPlugin)this).Config.Bind<string>("Permissions", "BlacklistSteamIds", "", T("禁止出售的 SteamID64,逗号分隔,优先于白名单。", "Comma separated SteamID64 list blocked from selling; takes priority over the whitelist."));
		BlacklistItems = ((BaseUnityPlugin)this).Config.Bind<string>("Permissions", "BlacklistItems", "", T("禁止出售的物品名,逗号分隔(按物品资产名匹配)。黑名单物品在面板里对普通玩家不可回收,房主仍可回收。", "Comma separated item names blocked from selling (matched against the item asset name). Regular players cannot sell them back; the host still can."));
		ShowStatusHud = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowStatusHud", true, T("在卡车里显示当前是主机、客机还是未装模组。", "Show whether the host runs PeachSell while standing inside the truck."));
		DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug", false, T("输出详细调试日志。", "Verbose debug logging."));
		ConfigLabels.AddPair("Refund ratio applied to the purchase price when an item is sold back (0..1), default 0.8.", "卖出已购物品时按原价返还的比例(0~1),默认 0.8。", bothWays: true);
		ConfigLabels.AddPair("Key that opens the recycle panel inside the truck. Accepts BackQuote (` / ~) or any KeyCode name, default `. Old H / F8 values are migrated automatically.", "卡车里打开回收面板的按键,支持 BackQuote(` / ~)或任意 KeyCode 名称,默认 `。旧版的 H / F8 会自动迁移。", bothWays: true);
		ConfigLabels.AddPair("Key that sells the item you are holding inside the truck, default X.", "在卡车里拿着物品时按此键回收,默认 X。", bothWays: true);
		ConfigLabels.AddPair("Allow selling in the lobby. The lobby has no extraction point, so money bags cannot be cashed there. Off by default.", "允许在大厅出售。大厅没有提取点,钱袋无法兑现,默认关闭。", bothWays: true);
		ConfigLabels.AddPair("Comma separated SteamID64 list allowed to sell. The host can also grant access from the panel.", "允许出售的 SteamID64,逗号分隔。房主可在回收面板里直接授权,省去手改。", bothWays: true);
		ConfigLabels.AddPair("Comma separated SteamID64 list blocked from selling; takes priority over the whitelist.", "禁止出售的 SteamID64,逗号分隔,优先于白名单。", bothWays: true);
		ConfigLabels.AddPair("Comma separated item names blocked from selling (matched against the item asset name). Regular players cannot sell them back; the host still can.", "禁止出售的物品名,逗号分隔(按物品资产名匹配)。黑名单物品在面板里对普通玩家不可回收,房主仍可回收。", bothWays: true);
		ConfigLabels.AddPair("Show whether the host runs PeachSell while standing inside the truck.", "在卡车里显示当前是主机、客机还是未装模组。", bothWays: true);
		ConfigLabels.AddPair("Verbose debug logging.", "输出详细调试日志。", bothWays: true);
		ConfigLabels.AddPair("Auto follows the game language; Chinese / English force it.", "Auto 跟随游戏语言;Chinese / English 强制指定。", bothWays: true);
		Language.SettingChanged += delegate
		{
			Chinese = ResolveChinese(Language.Value);
			ApplyDescriptions();
			ConfigLabels.RefreshAll();
			Dbg("语言切换 -> " + (Chinese ? "中文" : "English"));
		};
		try
		{
			ConfigLabels.Install(new Harmony("com.peachh.peachsell.labels"));
		}
		catch (Exception ex)
		{
			Warn("配置菜单文本补丁挂载失败: " + ex.Message);
		}
		GameRefs.Init();
		try
		{
			string text = ((PanelKey != null) ? PanelKey.Value : null);
			if (text == "H" || text == "F8")
			{
				PanelKey.Value = "`";
			}
		}
		catch
		{
		}
		try
		{
			if (BlacklistItems != null && !string.IsNullOrEmpty(BlacklistItems.Value))
			{
				List<string> list = new List<string>();
				string[] array = BlacklistItems.Value.Split(new char[3] { ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
				for (int num = 0; num < array.Length; num++)
				{
					string text2 = array[num].Trim().ToLowerInvariant();
					if (text2.Length == 0)
					{
						continue;
					}
					bool flag = true;
					string text3 = text2;
					for (int num2 = 0; num2 < text3.Length; num2++)
					{
						if (!char.IsLetterOrDigit(text3[num2]))
						{
							flag = false;
							break;
						}
					}
					if (flag)
					{
						list.Add(text2);
					}
				}
				string text4 = string.Join(";", list);
				if (text4 != BlacklistItems.Value)
				{
					BlacklistItems.Value = text4;
				}
			}
		}
		catch
		{
		}
		GameObject val = new GameObject("PeachSellRuntime");
		Object.DontDestroyOnLoad((Object)val);
		Net = val.AddComponent<SellNet>();
		Panel = val.AddComponent<SellPanel>();
		AuthorTag.Init(val);
		Notice("PeachSell v0.2.0 loaded");
	}

	private static void ApplyDescriptions()
	{
		ForceDescription((ConfigEntryBase)(object)RefundPercent, T("卖出已购物品时按原价返还的比例(0~1),默认 0.8。", "Refund ratio applied to the purchase price when an item is sold back (0..1), default 0.8."));
		ForceDescription((ConfigEntryBase)(object)PanelKey, T("卡车里打开回收面板的按键,支持 BackQuote(` / ~)或任意 KeyCode 名称,默认 `。旧版的 H / F8 会自动迁移。", "Key that opens the recycle panel inside the truck. Accepts BackQuote (` / ~) or any KeyCode name, default `. Old H / F8 values are migrated automatically."));
		ForceDescription((ConfigEntryBase)(object)SellKey, T("在卡车里拿着物品时按此键回收,默认 X。", "Key that sells the item you are holding inside the truck, default X."));
		ForceDescription((ConfigEntryBase)(object)AllowLobbySell, T("允许在大厅出售。大厅没有提取点,钱袋无法兑现,默认关闭。", "Allow selling in the lobby. The lobby has no extraction point, so money bags cannot be cashed there. Off by default."));
		ForceDescription((ConfigEntryBase)(object)WhitelistSteamIds, T("允许出售的 SteamID64,逗号分隔。房主可在回收面板里直接授权,省去手改。", "Comma separated SteamID64 list allowed to sell. The host can also grant access from the panel."));
		ForceDescription((ConfigEntryBase)(object)BlacklistSteamIds, T("禁止出售的 SteamID64,逗号分隔,优先于白名单。", "Comma separated SteamID64 list blocked from selling; takes priority over the whitelist."));
		ForceDescription((ConfigEntryBase)(object)BlacklistItems, T("禁止出售的物品名,逗号分隔(按物品资产名匹配)。黑名单物品在面板里对普通玩家不可回收,房主仍可回收。", "Comma separated item names blocked from selling (matched against the item asset name). Regular players cannot sell them back; the host still can."));
		ForceDescription((ConfigEntryBase)(object)ShowStatusHud, T("在卡车里显示当前是主机、客机还是未装模组。", "Show whether the host runs PeachSell while standing inside the truck."));
		ForceDescription((ConfigEntryBase)(object)DebugLog, T("输出详细调试日志。", "Verbose debug logging."));
	}

	private static void ForceDescription(ConfigEntryBase entry, string text)
	{
		if (entry == null)
		{
			return;
		}
		try
		{
			FieldInfo field = typeof(ConfigEntryBase).GetField("<Description>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return;
			}
			object value = field.GetValue(entry);
			if (value != null)
			{
				FieldInfo field2 = value.GetType().GetField("<Description>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
				if (!(field2 == null))
				{
					field2.SetValue(value, text);
					field.SetValue(entry, value);
				}
			}
		}
		catch
		{
		}
	}

	private static bool ResolveChinese(UiLanguage mode)
	{
		return mode switch
		{
			UiLanguage.Chinese => true, 
			UiLanguage.English => false, 
			_ => ConfigLabels.GameIsChinese(), 
		};
	}

	internal static void Notice(string message)
	{
		if ((Object)(object)Instance != (Object)null && ((BaseUnityPlugin)Instance).Logger != null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
		}
	}

	internal static void Warn(string message)
	{
		if ((Object)(object)Instance != (Object)null && ((BaseUnityPlugin)Instance).Logger != null)
		{
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)message);
		}
	}

	internal static void Dbg(string message)
	{
		if (DebugLog != null && DebugLog.Value && (Object)(object)Instance != (Object)null && ((BaseUnityPlugin)Instance).Logger != null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[dbg] " + message));
		}
	}
}
internal static class PoolPrefabs
{
	private static bool _keysLogged;

	private static Dictionary<string, GameObject> Cache()
	{
		try
		{
			IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
			return ((MultiplayerPool)(((prefabPool is MultiplayerPool) ? prefabPool : null)?)).ResourceCache;
		}
		catch (Exception ex)
		{
			Plugin.Dbg("读取 Photon 预制体池失败: " + ex.Message);
			return null;
		}
	}

	internal static string KeyFor(GameObject prefab)
	{
		if ((Object)(object)prefab == (Object)null)
		{
			return null;
		}
		Dictionary<string, GameObject> dictionary = Cache();
		if (dictionary == null)
		{
			return null;
		}
		try
		{
			foreach (KeyValuePair<string, GameObject> item in dictionary)
			{
				if ((Object)(object)item.Value == (Object)(object)prefab)
				{
					return item.Key;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("反查预制体 key 失败: " + ex.Message);
		}
		return null;
	}

	internal static string Pick(params string[] preferred)
	{
		Dictionary<string, GameObject> dictionary = Cache();
		if (dictionary == null || dictionary.Count == 0)
		{
			return null;
		}
		try
		{
			foreach (string text in preferred)
			{
				if (string.IsNullOrEmpty(text))
				{
					continue;
				}
				foreach (KeyValuePair<string, GameObject> item in dictionary)
				{
					if (!((Object)(object)item.Value == (Object)null) && item.Key.ToLowerInvariant().Contains(text.ToLowerInvariant()))
					{
						return item.Key;
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("挑选预制体 key 失败: " + ex.Message);
		}
		return null;
	}

	internal static bool KeyExists(string key)
	{
		if (string.IsNullOrEmpty(key))
		{
			return false;
		}
		Dictionary<string, GameObject> dictionary = Cache();
		if (dictionary == null)
		{
			return false;
		}
		try
		{
			return dictionary.ContainsKey(key);
		}
		catch
		{
			return false;
		}
	}

	internal static GameObject Resolve(string key)
	{
		if (string.IsNullOrEmpty(key))
		{
			return null;
		}
		Dictionary<string, GameObject> dictionary = Cache();
		if (dictionary != null)
		{
			try
			{
				if (dictionary.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
				{
					return value;
				}
			}
			catch (Exception ex)
			{
				Plugin.Dbg("池内查找失败: " + ex.Message);
			}
		}
		try
		{
			return Resources.Load<GameObject>(key);
		}
		catch (Exception ex2)
		{
			Plugin.Dbg("Resources.Load 失败: " + ex2.Message);
		}
		return null;
	}

	internal static void LogKeysOnce()
	{
		if (_keysLogged)
		{
			return;
		}
		_keysLogged = true;
		Dictionary<string, GameObject> dictionary = Cache();
		if (dictionary == null)
		{
			Plugin.Warn("Photon 预制体池不可用(PrefabPool 不是 MultiplayerPool),钱袋只能退回直接到账");
			return;
		}
		if (dictionary.Count == 0)
		{
			Plugin.Warn("Photon 预制体池为空,钱袋暂时只能退回直接到账");
			return;
		}
		StringBuilder stringBuilder = new StringBuilder();
		int num = 0;
		try
		{
			foreach (KeyValuePair<string, GameObject> item in dictionary)
			{
				if (num >= 40)
				{
					stringBuilder.Append(" …");
					break;
				}
				if (num > 0)
				{
					stringBuilder.Append(" | ");
				}
				stringBuilder.Append(item.Key);
				num++;
			}
		}
		catch (Exception ex)
		{
			Plugin.Dbg("列举预制体 key 失败: " + ex.Message);
		}
		Plugin.Notice("Photon 预制体池共 " + dictionary.Count + " 项,示例: " + stringBuilder);
	}
}
internal enum NetMode
{
	Unavailable,
	Single,
	Host,
	ClientModded,
	ClientVanilla
}
internal struct PlayerEntry
{
	internal string Name;

	internal string SteamId;

	internal bool Authorized;

	internal bool IsAuthor;

	internal bool Online;

	internal bool Blocked;
}
internal class SellNet : MonoBehaviourPunCallbacks, IOnEventCallback
{
	internal const byte ProtocolVersion = 1;

	private const byte EvHello = 190;

	private const byte EvState = 191;

	private const byte EvSell = 192;

	private const byte EvResult = 193;

	private const byte EvAuth = 194;

	internal NetMode Mode;

	internal bool Authorized;

	internal bool HostHasMod;

	internal string HostVersion = string.Empty;

	internal string LastResult = string.Empty;

	internal float LastResultAt;

	private readonly Dictionary<int, string> _actorSteam = new Dictionary<int, string>();

	private float _nextHello;

	private float _inRoomSince;

	private float _lastStateAt = -999f;

	internal bool IsLocalHostLike
	{
		get
		{
			if (Mode != NetMode.Single)
			{
				return Mode == NetMode.Host;
			}
			return true;
		}
	}

	internal bool Active => Mode != NetMode.ClientVanilla;

	private void Update()
	{
		bool flag = PhotonNetwork.InRoom && !PhotonNetwork.OfflineMode;
		bool flag2 = false;
		try
		{
			flag2 = (Object)(object)GameManager.instance != (Object)null && SemiFunc.IsMultiplayer();
		}
		catch
		{
		}
		if (!flag && !flag2)
		{
			Mode = NetMode.Single;
			HostHasMod = true;
			Authorized = true;
			return;
		}
		if (PhotonNetwork.IsMasterClient)
		{
			Mode = NetMode.Host;
			HostHasMod = true;
			Authorized = true;
			return;
		}
		if (!PhotonNetwork.InRoom)
		{
			Mode = NetMode.Unavailable;
			Authorized = false;
			_inRoomSince = 0f;
			return;
		}
		if (_inRoomSince <= 0f)
		{
			_inRoomSince = Time.unscaledTime;
		}
		if (Time.unscaledTime >= _nextHello)
		{
			_nextHello = Time.unscaledTime + 2f;
			SendHello();
		}
		if (Mode == NetMode.ClientModded && Time.unscaledTime - _lastStateAt > 6.5f)
		{
			Mode = NetMode.ClientVanilla;
			Authorized = false;
			HostHasMod = false;
			Plugin.Dbg("主机状态超时,判定为主机未装模组");
		}
		if (Mode == NetMode.Unavailable && Time.unscaledTime - _inRoomSince > 3.5f)
		{
			Mode = NetMode.ClientVanilla;
			HostHasMod = false;
			Plugin.Dbg("未收到主机 STATE,判定为主机未装模组");
		}
	}

	public override void OnJoinedRoom()
	{
		_inRoomSince = Time.unscaledTime;
		_nextHello = 0f;
		_actorSteam.Clear();
		Mode = (PhotonNetwork.IsMasterClient ? NetMode.Host : NetMode.Unavailable);
		Authorized = PhotonNetwork.IsMasterClient;
		Plugin.Dbg("进入房间,master=" + (object)PhotonNetwork.MasterClient);
	}

	public override void OnLeftRoom()
	{
		Mode = NetMode.Unavailable;
		Authorized = false;
		HostHasMod = false;
		_inRoomSince = 0f;
		_actorSteam.Clear();
	}

	public override void OnMasterClientSwitched(Player newMasterClient)
	{
		_actorSteam.Clear();
		_lastStateAt = -999f;
		if (PhotonNetwork.IsMasterClient)
		{
			Mode = NetMode.Host;
			HostHasMod = true;
			Authorized = true;
		}
		else
		{
			Mode = NetMode.Unavailable;
			Authorized = false;
			_inRoomSince = Time.unscaledTime;
			_nextHello = 0f;
		}
	}

	public void OnEvent(EventData photonEvent)
	{
		if (!(photonEvent.CustomData is object[] payload))
		{
			return;
		}
		switch (photonEvent.Code)
		{
		case 190:
			if (PhotonNetwork.IsMasterClient)
			{
				HandleHello(photonEvent.Sender, payload);
			}
			break;
		case 192:
			if (PhotonNetwork.IsMasterClient)
			{
				HandleSellRequest(photonEvent.Sender, payload);
			}
			break;
		case 191:
		case 193:
		case 194:
			if (!FromMaster(photonEvent.Sender))
			{
				break;
			}
			try
			{
				if (photonEvent.Code == 191)
				{
					HandleState(payload);
				}
				else if (photonEvent.Code == 193)
				{
					HandleResult(payload);
				}
				else
				{
					HandleAuth(payload);
				}
				break;
			}
			catch (Exception ex)
			{
				Plugin.Warn("处理事件 " + photonEvent.Code + " 失败: " + ex.Message);
				break;
			}
		}
	}

	private static bool FromMaster(int sender)
	{
		Player masterClient = PhotonNetwork.MasterClient;
		if (masterClient != null)
		{
			return sender == masterClient.ActorNumber;
		}
		return true;
	}

	private static int SafeInt(object value)
	{
		try
		{
			return Convert.ToInt32(value);
		}
		catch
		{
			return 0;
		}
	}

	internal void SendSell(string instanceName, int requestId)
	{
		if (!string.IsNullOrEmpty(instanceName))
		{
			RaiseToMaster(192, instanceName, requestId);
		}
	}

	private void SendHello()
	{
		RaiseToMaster(190, (byte)1, "0.2.0");
	}

	private void HandleState(object[] payload)
	{
		byte b = (byte)((payload.Length != 0 && payload[0] is byte b2) ? b2 : 0);
		if (b != 1)
		{
			if (Mode != NetMode.ClientVanilla)
			{
				Mode = NetMode.ClientVanilla;
				HostHasMod = false;
				Authorized = false;
				Plugin.Warn("主机 PeachSell 协议版本 v" + b + " 与本机 v" + (byte)1 + " 不一致,按未装处理");
			}
			return;
		}
		_lastStateAt = Time.unscaledTime;
		Mode = NetMode.ClientModded;
		HostHasMod = true;
		bool flag = default(bool);
		int num;
		if (payload.Length > 1)
		{
			object obj = payload[1];
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
		}
		else
		{
			num = 0;
		}
		Authorized = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		HostVersion = ((payload.Length > 3) ? ((payload[3] as string) ?? string.Empty) : string.Empty);
		Plugin.Dbg("主机已装模组 v" + HostVersion + ",授权=" + Authorized);
	}

	private void HandleAuth(object[] payload)
	{
		_lastStateAt = Time.unscaledTime;
		bool flag = default(bool);
		int num;
		if (payload.Length != 0)
		{
			object obj = payload[0];
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
		}
		else
		{
			num = 0;
		}
		Authorized = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
	}

	private void HandleResult(object[] payload)
	{
		int requestId = ((payload.Length != 0) ? SafeInt(payload[0]) : 0);
		int dollars = ((payload.Length > 1) ? SafeInt(payload[1]) : 0);
		string text = ((payload.Length > 2) ? (payload[2] as string) : null);
		LastResult = ((text == null) ? ("OK:" + dollars) : ("ERR:" + text));
		LastResultAt = Time.unscaledTime;
		if ((Object)(object)Plugin.Panel != (Object)null)
		{
			Plugin.Panel.OnSellResult(requestId, dollars, text);
		}
		Plugin.Dbg("出售结果 request=" + requestId + " dollars=" + dollars + " err=" + text);
	}

	private void HandleHello(int actor, object[] payload)
	{
		string text = GameRefs.SteamId(GameRefs.AvatarByActor(actor));
		if (!string.IsNullOrEmpty(text))
		{
			_actorSteam[actor] = text;
		}
		bool flag = Permissions.CanSell(text);
		bool flag2 = Permissions.IsAuthorSteam(text);
		SendTo(actor, 191, (byte)1, flag, flag2, "0.2.0");
		Plugin.Dbg("HELLO from actor " + actor + " steam=" + (text ?? "?") + " authorized=" + flag);
	}

	private void HandleSellRequest(int actor, object[] payload)
	{
		string instance = ((payload.Length != 0) ? (payload[0] as string) : null);
		int num = ((payload.Length > 1) ? Convert.ToInt32(payload[1]) : 0);
		PlayerAvatar val = GameRefs.AvatarByActor(actor);
		string text = GameRefs.SteamId(val);
		if ((Object)(object)val == (Object)null || string.IsNullOrEmpty(text))
		{
			SendTo(actor, 193, num, 0, "no_seller");
			return;
		}
		if (!Permissions.CanSell(text))
		{
			SendTo(actor, 193, num, 0, "not_authorized");
			return;
		}
		try
		{
			ItemAttributes val2 = SellService.FindByInstance(instance);
			int bagDollars;
			string error;
			if ((Object)(object)val2 == (Object)null)
			{
				SendTo(actor, 193, num, 0, "not_found");
			}
			else if (SellService.TrySell(val2, val, out bagDollars, out error))
			{
				SendTo(actor, 193, num, bagDollars, null);
			}
			else
			{
				SendTo(actor, 193, num, 0, error ?? "failed");
			}
		}
		catch (Exception ex)
		{
			Plugin.Warn("处理回收请求失败: " + ex.Message);
			SendTo(actor, 193, num, 0, "sell_failed");
		}
	}

	internal void ToggleWhitelist(string steamId)
	{
		if (!string.IsNullOrEmpty(steamId) && !Permissions.IsAuthorSteam(steamId))
		{
			bool allowed = !Permissions.CanSell(steamId);
			Permissions.SetWhitelisted(steamId, allowed);
			NotifyAuth(steamId, allowed);
		}
	}

	internal void ToggleBlacklist(string steamId)
	{
		if (!string.IsNullOrEmpty(steamId) && !Permissions.IsAuthorSteam(steamId))
		{
			bool flag = !Permissions.IsBlacklisted(steamId);
			Permissions.SetBlacklisted(steamId, flag);
			if (flag)
			{
				Permissions.SetWhitelisted(steamId, allowed: false);
			}
			NotifyAuth(steamId, Permissions.CanSell(steamId));
		}
	}

	private void NotifyAuth(string steamId, bool allowed)
	{
		foreach (KeyValuePair<int, string> item in _actorSteam)
		{
			if (!(item.Value != steamId))
			{
				SendTo(item.Key, 194, allowed);
			}
		}
	}

	internal List<PlayerEntry> HostPlayerEntries()
	{
		List<PlayerEntry> list = new List<PlayerEntry>();
		foreach (PlayerAvatar item in GameRefs.Players())
		{
			string steamId = GameRefs.SteamId(item);
			bool flag = Permissions.IsAuthorSteam(steamId);
			list.Add(new PlayerEntry
			{
				Name = (GameRefs.PlayerName(item) ?? "?"),
				SteamId = steamId,
				Authorized = (flag || Permissions.CanSell(steamId)),
				IsAuthor = flag,
				Online = true,
				Blocked = (!flag && Permissions.IsBlacklisted(steamId))
			});
		}
		return list;
	}

	internal List<PlayerEntry> HostPermissionEntries()
	{
		List<PlayerEntry> list = HostPlayerEntries();
		HashSet<string> hashSet = new HashSet<string>();
		foreach (PlayerEntry item in list)
		{
			hashSet.Add(item.SteamId);
		}
		foreach (string item2 in Permissions.BlacklistIds())
		{
			if (hashSet.Add(item2) && !Permissions.IsAuthorSteam(item2))
			{
				list.Add(new PlayerEntry
				{
					Name = Loc.T("离线 ", "offline ") + Tail(item2),
					SteamId = item2,
					Authorized = false,
					IsAuthor = false,
					Online = false,
					Blocked = true
				});
			}
		}
		foreach (string item3 in Permissions.WhitelistIds())
		{
			if (hashSet.Add(item3) && !Permissions.IsAuthorSteam(item3))
			{
				list.Add(new PlayerEntry
				{
					Name = Loc.T("离线 ", "offline ") + Tail(item3),
					SteamId = item3,
					Authorized = true,
					IsAuthor = false,
					Online = false,
					Blocked = false
				});
			}
		}
		return list;
	}

	internal void AddPermission(string steamId, bool whitelist)
	{
		if (!string.IsNullOrEmpty(steamId) && !Permissions.IsAuthorSteam(steamId))
		{
			if (whitelist)
			{
				Permissions.SetWhitelisted(steamId, allowed: true);
				Permissions.SetBlacklisted(steamId, blocked: false);
			}
			else
			{
				Permissions.SetBlacklisted(steamId, blocked: true);
				Permissions.SetWhitelisted(steamId, allowed: false);
			}
			NotifyAuth(steamId, Permissions.CanSell(steamId));
		}
	}

	private static string Tail(string steamId)
	{
		if (string.IsNullOrEmpty(steamId))
		{
			return "?";
		}
		if (steamId.Length > 6)
		{
			return "…" + steamId.Substring(steamId.Length - 6);
		}
		return steamId;
	}

	private void SendTo(int actor, byte code, params object[] content)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			RaiseEventOptions val = new RaiseEventOptions();
			val.TargetActors = new int[1] { actor };
			RaiseEventOptions val2 = val;
			PhotonNetwork.RaiseEvent(code, (object)content, val2, SendOptions.SendReliable);
		}
		catch (Exception ex)
		{
			Plugin.Warn("RaiseEvent 失败: " + ex.Message);
		}
	}

	private void RaiseToMaster(byte code, params object[] content)
	{
		//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_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)2
			};
			PhotonNetwork.RaiseEvent(code, (object)content, val, SendOptions.SendReliable);
		}
		catch (Exception ex)
		{
			Plugin.Warn("RaiseEvent(master) 失败: " + ex.Message);
		}
	}
}
internal class SellPanel : MonoBehaviour
{
	private sealed class UiButton
	{
		internal GameObject Go;

		internal Image Bg;

		internal Text Label;

		internal Color Base;

		internal Action OnClick;

		internal bool Enabled = true;

		internal void SetColor(Color color)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Bg != (Object)null)
			{
				((Graphic)Bg).color = color;
			}
		}
	}

	private const int PageSize = 7;

	private const float RowHeight = 44f;

	private const float RowGap = 4f;

	private static readonly Color BgDeep = new Color(0.055f, 0.055f, 0.06f, 0.98f);

	private static readonly Color BgPanel = new Color(0.09f, 0.09f, 0.1f, 0.98f);

	private static readonly Color BgCard = new Color(0.13f, 0.13f, 0.145f, 0.98f);

	private static readonly Color BgCardHover = new Color(0.17f, 0.17f, 0.185f, 0.98f);

	private static readonly Color BgInput = new Color(0.11f, 0.11f, 0.12f, 0.98f);

	private static readonly Color Border = new Color(1f, 1f, 1f, 0.06f);

	private static readonly Color BorderLight = new Color(1f, 1f, 1f, 0.1f);

	private static readonly Color TextPrimary = new Color(0.95f, 0.95f, 0.96f);

	private static readonly Color TextSecondary = new Color(0.62f, 0.62f, 0.65f);

	private static readonly Color TextMuted = new Color(0.4f, 0.4f, 0.44f);

	private static readonly Color Accent = new Color(0.3f, 0.72f, 0.62f);

	private static readonly Color AccentDim = new Color(0.2f, 0.48f, 0.42f);

	private static readonly Color Danger = new Color(0.82f, 0.36f, 0.34f);

	private static readonly Color DangerDim = new Color(0.55f, 0.24f, 0.23f);

	private static readonly Color Warning = new Color(0.85f, 0.65f, 0.3f);

	private KeyCode _panelKey = (KeyCode)96;

	private KeyCode _sellKey = (KeyCode)120;

	private bool _uiReady;

	private bool _open;

	private GameObject _panelRoot;

	private Text _title;

	private Text _subtitle;

	private Text _status;

	private Text _status2;

	private Text _footer;

	private Text _pageLabel;

	private Text _summary;

	private Text _empty;

	private Text _notice;

	private UiButton _close;

	private Text _toast;

	private Text _hud;

	private Text _hint;

	private float _nextHintAt;

	private string _hintText = string.Empty;

	private RectTransform _listRoot;

	private readonly List<GameObject> _inputRow = new List<GameObject>();

	private Image _inputBox;

	private Text _inputText;

	private bool _inputActive;

	private string _input = string.Empty;

	private float _toastUntil;

	private float _nextRefresh;

	private int _tab;

	private int _page;

	private int _pendingId;

	private NetMode _lastMode;

	private readonly List<UiButton> _buttons = new List<UiButton>();

	private readonly List<ItemAttributes> _items = new List<ItemAttributes>();

	private readonly List<PlayerEntry> _players = new List<PlayerEntry>();

	private static readonly List<InputKey> BlockedWhileOpen = new List<InputKey>
	{
		(InputKey)16,
		(InputKey)3,
		(InputKey)17
	};

	private void Awake()
	{
		RebindKeys();
		try
		{
			Plugin.PanelKey.SettingChanged += delegate
			{
				RebindKeys();
			};
		}
		catch
		{
		}
		try
		{
			Plugin.SellKey.SettingChanged += delegate
			{
				RebindKeys();
			};
		}
		catch
		{
		}
	}

	private void RebindKeys()
	{
		//IL_000f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		_panelKey = Keys.Parse(Plugin.PanelKey.Value, (KeyCode)96, out var ok);
		if (!ok)
		{
			Plugin.Warn("PanelKey 无法解析:" + Plugin.PanelKey.Value + ",回退到 `");
		}
		_sellKey = Keys.Parse(Plugin.SellKey.Value, (KeyCode)120, out ok);
		if (!ok)
		{
			Plugin.Warn("SellKey 无法解析:" + Plugin.SellKey.Value + ",回退到 X");
		}
	}

	private void Update()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Plugin.Net == (Object)null)
		{
			return;
		}
		TrackModeSwitch();
		if (_open && !Plugin.Net.Active)
		{
			TogglePanel();
		}
		bool flag = _open && _inputActive;
		if (flag)
		{
			HandleTyping();
		}
		if (InputAllowed())
		{
			bool flag2 = Input.GetKeyDown(_panelKey);
			if (!flag2 && !_open && !_inputActive)
			{
				flag2 = TypedPanelChar();
			}
			if (flag2)
			{
				TogglePanel();
			}
			else if (_open && !flag && Input.GetKeyDown((KeyCode)27))
			{
				TogglePanel();
			}
			if (!_open && Input.GetKeyDown(_sellKey))
			{
				QuickSell();
			}
		}
		if (_open && !CanStayOpen())
		{
			TogglePanel();
		}
		if (_open)
		{
			UnlockCursor(0.2f);
			ShowCursor();
			BlockGameplayMouse();
			HandleButtons();
			if (Input.GetMouseButtonDown(1))
			{
				TogglePanel();
			}
			if (Time.unscaledTime >= _nextRefresh)
			{
				_nextRefresh = Time.unscaledTime + 0.35f;
				Refresh();
			}
		}
		UpdateHud();
		UpdateToast();
	}

	private static bool InputAllowed()
	{
		try
		{
			return SemiFunc.NoTextInputsActive();
		}
		catch
		{
			return true;
		}
	}

	private static bool TypedPanelChar()
	{
		string inputString;
		try
		{
			inputString = Input.inputString;
		}
		catch
		{
			return false;
		}
		if (string.IsNullOrEmpty(inputString))
		{
			return false;
		}
		foreach (char c in inputString)
		{
			if (c == '·' || c == '~' || c == '`')
			{
				return true;
			}
		}
		return false;
	}

	private void TrackModeSwitch()
	{
		NetMode mode = Plugin.Net.Mode;
		if (mode != _lastMode)
		{
			NetMode lastMode = _lastMode;
			_lastMode = mode;
			if (mode == NetMode.ClientVanilla && lastMode != NetMode.ClientVanilla)
			{
				Toast(Loc.T("房主没有安装 PeachSell,已自动禁用", "Host has no PeachSell — disabled"));
			}
			else if (lastMode == NetMode.ClientVanilla && mode == NetMode.ClientModded)
			{
				Toast(Loc.T("已连接房主的 PeachSell,已自动启用", "Host PeachSell found — enabled"));
			}
		}
	}

	private void TogglePanel()
	{
		if (_open)
		{
			_open = false;
			if ((Object)(object)_panelRoot != (Object)null)
			{
				_panelRoot.SetActive(false);
			}
			UnlockCursor(0f);
			return;
		}
		if (!Plugin.Net.Active)
		{
			Toast(Loc.T("房主没有安装 PeachSell,本模组已自动禁用", "Host has no PeachSell — the mod is disabled"));
			return;
		}
		PlayerAvatar localAvatar = GameRefs.LocalAvatar;
		if ((Object)(object)localAvatar == (Object)null || !GameRefs.InTruck(localAvatar))
		{
			Toast(Loc.T("只能在卡车里打开回收面板", "The recycle panel only opens inside the truck"));
			return;
		}
		EnsureUi();
		_open = true;
		_tab = 0;
		_page = 0;
		_panelRoot.SetActive(true);
		Refresh();
	}

	private void QuickSell()
	{
		PlayerAvatar localAvatar = GameRefs.LocalAvatar;
		if ((Object)(object)localAvatar == (Object)null)
		{
			return;
		}
		if (!GameRefs.InTruck(localAvatar))
		{
			Toast(Loc.T("只能在卡车里出售", "You can only sell inside the truck"));
			return;
		}
		if (!CanLocalSell())
		{
			Toast(SellBlockedText());
			return;
		}
		ItemAttributes val = SellService.HeldItem(localAvatar);
		if ((Object)(object)val == (Object)null)
		{
			Toast(Loc.T("手里没有拿着物品", "You are not holding an item"));
		}
		else
		{
			RequestSell(val);
		}
	}

	private void UnlockCursor(float seconds)
	{
		try
		{
			if ((Object)(object)CursorManager.instance != (Object)null)
			{
				CursorManager.instance.Unlock(seconds);
			}
		}
		catch
		{
		}
	}

	private static bool CanStayOpen()
	{
		if (!GameRefs.InGameLevel())
		{
			return false;
		}
		PlayerAvatar localAvatar = GameRefs.LocalAvatar;
		if ((Object)(object)localAvatar != (Object)null)
		{
			return GameRefs.InTruck(localAvatar);
		}
		return false;
	}

	private static void ShowCursor()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Cursor.visible = true;
			if ((int)Cursor.lockState != 0)
			{
				Cursor.lockState = (CursorLockMode)0;
			}
		}
		catch
		{
		}
	}

	private void BlockGameplayMouse()
	{
		try
		{
			if ((Object)(object)InputManager.instance != (Object)null)
			{
				InputManager.instance.DisableControlsSpecific(0.2f, BlockedWhileOpen);
			}
		}
		catch
		{
		}
	}

	private void HandleButtons()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//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_00f4: 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)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		if (_buttons.Count == 0)
		{
			return;
		}
		Vector2 screen = Vector2.op_Implicit(Input.mousePosition);
		bool mouseButtonDown = Input.GetMouseButtonDown(0);
		foreach (UiButton button in _buttons)
		{
			if (button != null && !((Object)(object)button.Go == (Object)null) && button.Go.activeInHierarchy)
			{
				bool flag = button.Enabled && Contains(button, screen);
				button.SetColor(flag ? Lighten(button.Base, 0.08f) : button.Base);
				if (flag && mouseButtonDown && button.OnClick != null)
				{
					button.OnClick();
					return;
				}
			}
		}
		if (_close != null && !((Object)(object)_close.Go == (Object)null))
		{
			bool flag2 = Contains(_close, screen);
			_close.SetColor(flag2 ? Lighten(_close.Base, 0.08f) : _close.Base);
			if (flag2 && mouseButtonDown)
			{
				_close.OnClick();
			}
		}
	}

	private static bool Contains(UiButton button, Vector2 screen)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = button.Go.transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		return RectTransformUtility.RectangleContainsScreenPoint(val, screen, (Camera)null);
	}

	private static Color Lighten(Color color, float amount)
	{
		//IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		return new Color(Mathf.Clamp01(color.r + amount), Mathf.Clamp01(color.g + amount), Mathf.Clamp01(color.b + amount), color.a);
	}

	private static Color Darken(Color color, float amount)
	{
		//IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		return new Color(Mathf.Clamp01(color.r - amount), Mathf.Clamp01(color.g - amount), Mathf.Clamp01(color.b - amount), color.a);
	}

	private void RequestSell(ItemAttributes attr)
	{
		if ((Object)(object)attr == (Object)null)
		{
			return;
		}
		string text = GameRefs.InstanceName(attr);
		if (string.IsNullOrEmpty(text))
		{
			Toast(Loc.T("这不是已购物品", "This is not a purchased item"));
		}
		else if (!CanLocalSell())
		{
			Toast(SellBlockedText());
		}
		else if (Plugin.Net.IsLocalHostLike)
		{
			if (SellService.TrySell(attr, GameRefs.LocalAvatar, out var bagDollars, out var error))
			{
				Toast(Loc.T("已回收:$", "Sold for $") + bagDollars);
			}
			else
			{
				Toast(ErrorText(error));
			}
			Refresh();
		}
		else
		{
			_pendingId++;
			Plugin.Net.SendSell(text, _pendingId);
			Toast(Loc.T("已向房主发送回收请求…", "Sell request sent to the host..."));
		}
	}

	internal void OnSellResult(int requestId, int dollars, string error)
	{
		if (error == null)
		{
			Toast(Loc.T("房主已回收:$", "Host sold it for $") + dollars);
		}
		else
		{
			Toast(ErrorText(error));
		}
		Refresh();
	}

	private void ToggleWhitelist(PlayerEntry entry)
	{
		if (!Plugin.Net.IsLocalHostLike)
		{
			Toast(Loc.T("只有房主可以管理权限", "Only the host manages permissions"));
			return;
		}
		if (string.IsNullOrEmpty(entry.SteamId))
		{
			Toast(Loc.T("无法读取该玩家的 SteamID", "Cannot read that player's SteamID"));
			return;
		}
		Plugin.Net.ToggleWhitelist(entry.SteamId);
		Toast(entry.Authorized ? Loc.T("已收回 " + entry.Name + " 的出售权限", "Revoked permission from " + entry.Name) : Loc.T("已授权 " + entry.Name + " 出售(即时生效)", "Authorized " + entry.Name + " (instant)"));
		Refresh();
	}

	private void ToggleBlacklist(PlayerEntry entry)
	{
		if (!Plugin.Net.IsLocalHostLike)
		{
			Toast(Loc.T("只有房主可以管理权限", "Only the host manages permissions"));
			return;
		}
		if (string.IsNullOrEmpty(entry.SteamId))
		{
			Toast(Loc.T("无法读取该玩家的 SteamID", "Cannot read that player's SteamID"));
			return;
		}
		if (entry.SteamId == GameRefs.LocalSteamId())
		{
			Toast(Loc.T("不能拉黑自己", "You cannot ban yourself"));
			return;
		}
		bool flag = Permissions.IsBlacklisted(entry.SteamId);
		Plugin.Net.ToggleBlacklist(entry.SteamId);
		Toast(flag ? Loc.T("已解除拉黑 " + entry.Name, "Unblocked " + entry.Name) : Loc.T("已拉黑 " + entry.Name + "(即时生效)", "Blocked " + entry.Name + " (instant)"));
		Refresh();
	}

	private void HandleTyping()
	{
		string inputString = Input.inputString;
		if (!string.IsNullOrEmpty(inputString))
		{
			string text = inputString;
			for (int i = 0; i < text.Length; i++)
			{
				char c = text[i];
				switch (c)
				{
				case '\b':
					if (_input.Length > 0)
					{
						_input = _input.Substring(0, _input.Length - 1);
					}
					break;
				case '\n':
				case '\r':
					CommitPermission(whitelist: true);
					return;
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					if (_input.Length < 17)
					{
						_input += c;
					}
					break;
				}
			}
			UpdateInputText();
		}
		if (Input.GetKeyDown((KeyCode)27))
		{
			_inputActive = false;
		}
	}

	private void CommitPermission(bool whitelist)
	{
		if (!Plugin.Net.IsLocalHostLike)
		{
			Toast(Loc.T("只有房主可以管理权限", "Only the host manages permissions"));
			return;
		}
		string text = (_input ?? string.Empty).Trim();
		if (text.Length < 6)
		{
			Toast(Loc.T("先输入完整的 SteamID64", "Enter a full SteamID64 first"));
			return;
		}
		if (!whitelist && text == GameRefs.LocalSteamId())
		{
			Toast(Loc.T("不能把自己加进黑名单", "You cannot blacklist your own SteamID"));
			return;
		}
		Plugin.Net.AddPermission(text, whitelist);
		Toast(whitelist ? Loc.T("已加入白名单:" + text, "Added to whitelist: " + text) : Loc.T("已加入黑名单:" + text, "Added to blacklist: " + text));
		_input = string.Empty;
		_inputActive = false;
		Refresh();
	}

	private void FocusInput()
	{
		if (Plugin.Net.IsLocalHostLike)
		{
			_inputActive = true;
			UpdateInputText();
		}
	}

	private void UpdateInputText()
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_inputText == (Object)null))
		{
			string text = (_inputActive ? "|" : string.Empty);
			_inputText.text = (string.IsNullOrEmpty(_input) ? (Loc.T("输入 SteamID64", "Enter SteamID64") + text) : (_input + text));
			if ((Object)(object)_inputBox != (Object)null)
			{
				((Graphic)_inputBox).color = (_inputActive ? Lighten(BgInput, 0.06f) : BgInput);
			}
		}
	}

	private bool CanLocalSell()
	{
		if ((Object)(object)Plugin.Net == (Object)null)
		{
			return false;
		}
		if (Plugin.Net.IsLocalHostLike)
		{
			return true;
		}
		if (Plugin.Net.Mode != NetMode.ClientModded)
		{
			return false;
		}
		if (!Permissions.IsLocalAuthor())
		{
			return Plugin.Net.Authorized;
		}
		return true;
	}

	private string SellBlockedText()
	{
		return (((Object)(object)Plugin.Net != (Object)null) ? Plugin.Net.Mode : NetMode.Unavailable) switch
		{
			NetMode.ClientVanilla => Loc.T("房主没有安装 PeachSell,无法出售", "The host does not run PeachSell; selling is unavailable"), 
			NetMode.Unavailable => Loc.T("正在等待房主响应,请稍后再试", "Waiting for the host to respond; try again shortly"), 
			_ => Loc.T("你没有出售权限,请联系房主授权", "Not authorized. Ask the host for permission."), 
		};
	}

	private string ModeText()
	{
		switch (Plugin.Net.Mode)
		{
		case NetMode.Single:
			return Loc.T("主机模式 · 单人", "HOST · SINGLEPLAYER");
		case NetMode.Host:
			return Loc.T("主机模式", "HOST MODE");
		case NetMode.ClientModded:
			if (!Plugin.Net.Authorized)
			{
				return Loc.T("客机模式 · 待授权", "CLIENT MODE · NOT AUTHORIZED");
			}
			return Loc.T("客机模式 · 已授权", "CLIENT MODE · AUTHORIZED");
		case NetMode.ClientVanilla:
			return Loc.T("客机模式 · 主机未装模组", "CLIENT MODE · HOST HAS NO MOD");
		default:
			return Loc.T("客机模式 · 连接中", "CLIENT MODE · CONNECTING");
		}
	}

	private void Refresh()
	{
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		if (!_open || (Object)(object)_panelRoot == (Object)null)
		{
			return;
		}
		int num = Mathf.RoundToInt(((Plugin.RefundPercent != null) ? Mathf.Clamp01(Plugin.RefundPercent.Value) : 0.8f) * 100f);
		_title.text = "PeachSell";
		if ((Object)(object)_subtitle != (Object)null)
		{
			_subtitle.text = "v0.2.0";
		}
		_status.text = ModeText();
		if ((Object)(object)_status2 != (Object)null)
		{
			_status2.text = Loc.T("退款 ", "Refund ") + num + "%  ·  " + (Plugin.Net.IsLocalHostLike ? Loc.T("本机结算", "Local") : Loc.T("房主结算", "Host"));
		}
		_footer.text = Loc.T("点击操作    右键关闭    面板键 ", "Click to act    right-click to close    panel key ") + KeyName(_panelKey);
		if (_tab == 0)
		{
			CollectItems();
		}
		else
		{
			CollectPlayers();
		}
		bool flag = _tab == 1 && Plugin.Net.IsLocalHostLike;
		foreach (GameObject item in _inputRow)
		{
			if ((Object)(object)item != (Object)null)
			{
				item.SetActive(flag);
			}
		}
		if (!flag && _inputActive)
		{
			_inputActive = false;
		}
		UpdateInputText();
		RebuildButtons();
	}

	private void CollectItems()
	{
		_items.Clear();
		ItemAttributes[] array = Object.FindObjectsByType<ItemAttributes>((FindObjectsSortMode)0);
		foreach (ItemAttributes val in array)
		{
			if (!((Object)(object)val == (Object)null) && Object.op_Implicit((Object)(object)((Component)val).gameObject) && !GameRefs.IsShopItem(val))
			{
				string text = GameRefs.InstanceName(val);
				if (!string.IsNullOrEmpty(text) && text.IndexOf('/') >= 0 && !((Object)(object)val.item == (Object)null) && GameRefs.ItemInTruck(val, GameRefs.LocalAvatar))
				{
					_items.Add(val);
				}
			}
		}
		bool allowed = CanLocalSell();
		bool privileged = ((Object)(object)Plugin.Net != (Object)null && Plugin.Net.IsLocalHostLike) || Permissions.IsLocalAuthor();
		_items.Sort(delegate(ItemAttributes a, ItemAttributes b)
		{
			int num = ItemRank(a, allowed, privileged);
			int num2 = ItemRank(b, allowed, privileged);
			return (num != num2) ? num.CompareTo(num2) : SellService.RefundDollars(GameRefs.GetValue(b)).CompareTo(SellService.RefundDollars(GameRefs.GetValue(a)));
		});
	}

	private static int ItemRank(ItemAttributes attr, bool allowed, bool privileged)
	{
		if (!allowed)
		{
			return 1;
		}
		if (!Permissions.IsItemBlacklisted(attr.item) || privileged)
		{
			return 0;
		}
		return 1;
	}

	private void CollectPlayers()
	{
		_players.Clear();
		if (Plugin.Net.IsLocalHostLike)
		{
			_players.AddRange(Plugin.Net.HostPermissionEntries());
		}
	}

	private void RebuildButtons()
	{
		ClearButtons();
		BuildTabs();
		int num = ((_tab == 0) ? _items.Count : _players.Count);
		int num2 = Mathf.Max(1, Mathf.CeilToInt((float)num / 7f));
		_page = Mathf.Clamp(_page, 0, num2 - 1);
		int num3 = _page * 7;
		int shown = Mathf.Min(7, Mathf.Max(0, num - num3));
		if (_tab == 0)
		{
			BuildItemRows(num3, shown);
		}
		else
		{
			BuildPlayerRows(num3, shown);
		}
		if (_tab == 1 && Plugin.Net.IsLocalHostLike)
		{
			BuildPermissionInput();
		}
		BuildPager(num2, num);
		BuildFeedback(num);
	}

	private void BuildTabs()
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: 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_0122: Unknown result type (might be due to invalid IL or missing references)
		string[] array = new string[2]
		{
			Loc.T("物品", "Items") + " " + _items.Count,
			Loc.T("玩家", "Players") + " " + _players.Count
		};
		for (int i = 0; i < array.Length; i++)
		{
			int index = i;
			bool flag = _tab == i;
			UiButton uiButton = AddButton(((Transform)_listRoot).parent, array[i], new Vector2(120f, 34f), new Vector2(28f + (float)i * 128f, -112f), flag ? BgCard : Color.clear, flag ? TextPrimary : TextMuted, delegate
			{
				_tab = index;
				_page = 0;
				_inputActive = false;
				Refresh();
			});
			if (flag)
			{
				((Graphic)CreateFrame(uiButton.Go.transform, new Vector2(0f, -32f), new Vector2(120f, 2f), Accent)).raycastTarget = false;
			}
		}
	}

	private void BuildItemRows(int start, int shown)
	{
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: 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_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		bool flag = CanLocalSell();
		bool flag2 = (Object)(object)Plugin.Net != (Object)null && Plugin.Net.IsLocalHostLike;
		bool flag3 = flag2 || Permissions.IsLocalAuthor();
		int num = 0;
		foreach (ItemAttributes item in _items)
		{
			if ((Object)(object)item != (Object)null && Object.op_Implicit((Object)(object)((Component)item).gameObject))
			{
				num += SellService.RefundDollars(GameRefs.GetValue(item));
			}
		}
		if ((Object)(object)_summary != (Object)null)
		{
			_summary.text = Loc.T("可回收 ", "") + _items.Count + Loc.T(" 件   合计 $", " sellable   total $") + num;
		}
		for (int i = 0; i < shown; i++)
		{
			ItemAttributes val = _items[start + i];
			string text = Fit(GameRefs.DisplayName(val), 26);
			string text2 = "$" + SellService.RefundDollars(GameRefs.GetValue(val));
			ItemAttributes captured = val;
			bool flag4 = Permissions.IsItemBlacklisted(val.item);
			bool flag5 = flag && (!flag4 || flag3);
			UiButton uiButton = AddButton((Transform)(object)_listRoot, string.Empty, new Vector2(880f, 44f), new Vector2(0f, 0f - (float)i * 48f), flag5 ? BgCard : BgPanel, TextPrimary, null);
			uiButton.Enabled = false;
			Text val2 = CreateText(uiButton.Go.transform, 19, (TextAnchor)3, new Vector2(14f, 0f), new Vector2(380f, 44f), flag5 ? TextPrimary : TextMuted);
			val2.text = text;
			if (flag4)
			{
				val2.text = val2.text + "  " + Loc.T("(黑名单)", " (blocked)");
			}
			CreateText(uiButton.Go.transform, 19, (TextAnchor)5, new Vector2(396f, 0f), new Vector2(140f, 44f), flag5 ? TextSecondary : TextMuted).text = text2;
			UiButton uiButton2 = AddButton(uiButton.Go.transform, Loc.T("回收 ", "Sell ") + text2, new Vector2(150f, 32f), new Vector2(548f, -6f), flag5 ? Accent : BgCardHover, flag5 ? BgDeep : TextMuted, delegate
			{
				RequestSell(captured);
			});
			uiButton2.Enabled = flag5;
			uiButton2.Label.fontSize = 17;
			if (flag2)
			{
				AddButton(uiButton.Go.transform, flag4 ? Loc.T("解除", "Unblock") : Loc.T("拉黑", "Block"), new Vector2(80f, 32f), new Vector2(710f, -6f), flag4 ? Warning : BgCardHover, flag4 ? BgDeep : TextSecondary, delegate
				{
					Permissions.SetItemBlacklisted(captured.item, !Permissions.IsItemBlacklisted(captured.item));
					Refresh();
				}).Label.fontSize = 16;
			}
		}
		if (shown == 0)
		{
			ShowEmpty(flag ? Loc.T("卡车里没有可回收的已购物品", "No sellable purchased items in the truck") : SellBlockedText());
		}
		else if (!flag)
		{
			ShowNotice(Loc.T("面板只读 · ", "Read-only · ") + SellBlockedText());
		}
	}

	private void BuildPlayerRows(int start, int shown)
	{
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: 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)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_summary != (Object)null)
		{
			_summary.text = Loc.T("白名单 ", "Whitelist ") + Permissions.WhitelistIds().Count + Loc.T(" 人   黑名单 ", "   Blacklist ") + Permissions.BlacklistIds().Count + Loc.T(" 人", "");
		}
		if (!Plugin.Net.IsLocalHostLike)
		{
			ShowEmpty(Loc.T("只有房主可以管理出售权限", "Only the host manages sell permissions"));
			return;
		}
		if (shown == 0)
		{
			ShowEmpty(Loc.T("还没有权限记录。点下方输入框加 SteamID,或等玩家进房后直接点行操作。", "No permissions yet. Add a SteamID below, or wait for players to join."));
			return;
		}
		for (int i = 0; i < shown; i++)
		{
			PlayerEntry captured;
			PlayerEntry playerEntry = (captured = _players[start + i]);
			bool flag = Permissions.IsBlacklisted(playerEntry.SteamId);
			bool flag2 = playerEntry.Authorized && !flag;
			bool flag3 = Permissions.IsAuthorSteam(playerEntry.SteamId);
			bool flag4 = !string.IsNullOrEmpty(playerEntry.SteamId) && playerEntry.SteamId == GameRefs.LocalSteamId();
			string text = (flag4 ? Loc.T("房主", "Host") : (flag3 ? Loc.T("作者 · 允许出售", "Author · Allowed") : (flag ? Loc.T("黑名单", "Blocked") : (flag2 ? Loc.T("允许出售", "Allowed") : Loc.T("禁止出售", "Denied")))));
			string text2 = Fit(playerEntry.Name, 16);
			if (flag3)
			{
				text2 = "<color=#FFD700>" + text2 + "</color>";
			}
			string text3 = text2 + (flag3 ? Loc.T(" [作者]", " [author]") : string.Empty) + "  " + (playerEntry.Online ? string.Empty : Loc.T("[离线] ", "[offline] ")) + text;
			float num = 0f - (float)i * 48f;
			UiButton uiButton = AddButton((Transform)(object)_listRoot, string.Empty, new Vector2(880f, 44f), new Vector2(0f, num), BgCard, TextPrimary, null);
			uiButton.Enabled = false;
			CreateText(uiButton.Go.transform, 19, (TextAnchor)3, new Vector2(14f, 0f), new Vector2(480f, 44f), flag ? TextMuted : TextPrimary).text = text3;
			((Graphic)CreateFrame(uiButton.Go.transform, new Vector2(470f, -18f), new Vector2(8f, 8f), (flag4 || flag3) ? Accent : (flag ? Danger : (flag2 ? Accent : TextMuted)))).raycastTarget = false;
			if (!(flag4 || flag3))
			{
				AddButton(uiButton.Go.transform, flag2 ? Loc.T("收回", "Revoke") : Loc.T("允许", "Allow"), new Vector2(88f, 32f), new Vector2(560f, -6f), flag2 ? DangerDim : AccentDim, TextPrimary, delegate
				{
					ToggleWhitelist(captured);
				}).Label.fontSize = 16;
				AddButton(uiButton.Go.transform, flag ? Loc.T("解黑", "Unban") : Loc.T("拉黑", "Ban"), new Vector2(88f, 32f), new Vector2(656f, -6f), flag ? Danger : DangerDim, TextPrimary, delegate
				{
					ToggleBlacklist(captured);
				}).Label.fontSize = 16;
			}
		}
	}

	private void BuildPermissionInput()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		UiButton uiButton = AddButton(((Transform)_listRoot).parent, string.Empty, new Vector2(300f, 34f), new Vector2(28f, -492f), BgInput, TextPrimary, delegate
		{
			FocusInput();
		});
		((Graphic)uiButton.Bg).raycastTarget = false;
		_inputBox = uiButton.Bg;
		_inputText = uiButton.Label;
		_inputText.fontSize = 17;
		((Graphic)_inputText).color = TextMuted;
		UpdateInputText();
		UiButton uiButton2 = AddButton(((Transform)_listRoot).parent, Loc.T("加白名单", "Whitelist"), new Vector2(110f, 34f), new Vector2(336f, -492f), AccentDim, TextPrimary, delegate
		{
			CommitPermission(whitelist: true);
		});
		uiButton2.Label.fontSize = 16;
		UiButton uiButton3 = AddButton(((Transform)_listRoot).parent, Loc.T("加黑名单", "Blacklist"), new Vector2(110f, 34f), new Vector2(454f, -492f), DangerDim, TextPrimary, delegate
		{
			CommitPermission(whitelist: false);
		});
		uiButton3.Label.fontSize = 16;
		_inputRow.Clear();
		_inputRow.Add(uiButton.Go);
		_inputRow.Add(uiButton2.Go);
		_inputRow.Add(uiButton3.Go);
	}

	private void BuildPager(int pages, int count)
	{
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: 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)
		_pageLabel.text = ((pages <= 1) ? (Loc.T("共 ", "") + count + Loc.T(" 条", " total")) : (_page + 1 + " / " + pages));
		if (pages <= 1)
		{
			return;
		}
		UiButton uiButton = AddButton(((Transform)_listRoot).parent, Loc.T("上一页", "Prev"), new Vector2(88f, 32f), new Vector2(28f, -534f), BgCard, TextSecondary, delegate
		{
			if (_page > 0)
			{
				_page--;
				Refresh();
			}
		});
		uiButton.Enabled = _page > 0;
		uiButton.Label.fontSize = 16;
		UiButton uiButton2 = AddButton(((Transform)_listRoot).parent, Loc.T("下一页", "Next"), new Vector2(88f, 32f), new Vector2(124f, -534f), BgCard, TextSecondary, delegate
		{
			if (_page < pages - 1)
			{
				_page++;
				Refresh();
			}
		});
		uiButton2.Enabled = _page < pages - 1;
		uiButton2.Label.fontSize = 16;
	}

	private void BuildFeedback(int count)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		if (_tab == 1 || !CanLocalSell() || count == 0)
		{
			return;
		}
		AddButton(((Transform)_listRoot).parent, Loc.T("全部回收", "Sell All"), new Vector2(140f, 34f), new Vector2(768f, -492f), Accent, BgDeep, delegate
		{
			if (CanLocalSell())
			{
				List<ItemAttributes> list = new List<ItemAttributes>(_items);
				bool flag = Plugin.Net.IsLocalHostLike || Permissions.IsLocalAuthor();
				int num = 0;
				foreach (ItemAttributes item in list)
				{
					if (!((Object)(object)item == (Object)null) && Object.op_Implicit((Object)(object)((Component)item).gameObject) && (!Permissions.IsItemBlacklisted(item.item) || flag))
					{
						if (Plugin.Net.IsLocalHostLike)
						{
							if (SellService.TrySell(item, GameRefs.LocalAvatar, out var _, out var _))
							{
								num++;
							}
						}
						else
						{
							_pendingId++;
							Plugin.Net.SendSell(GameRefs.InstanceName(item), _pendingId);
							num++;
						}
					}
				}
				if (num > 0)
				{
					Toast(Loc.T("已提交回收:", "Submitted: ") + num + Loc.T(" 件", " item(s)"));
				}
				Refresh();
			}
		}).Label.fontSize = 17;
	}

	private void ShowEmpty(string message)
	{
		if (!((Object)(object)_empty == (Object)null))
		{
			_empty.text = message;
			((Component)_empty).gameObject.SetActive(true);
		}
	}

	private void ShowNotice(string message)
	{
		if (!((Object)(object)_notice == (Object)null))
		{
			_notice.text = message;
			((Component)_notice).gameObject.SetActive(true);
		}
	}

	private void ClearButtons()
	{
		foreach (UiButton button in _buttons)
		{
			if (button != null && (Object)(object)button.Go != (Object)null)
			{
				Object.Destroy((Object)(object)button.Go);
			}
		}
		_buttons.Clear();
		if ((Object)(object)_empty != (Object)null)
		{
			((Component)_empty).gameObject.SetActive(false);
		}
		if ((Object)(object)_notice != (Object)null)
		{
			((Component)_notice).gameObject.SetActive(false);
		}
	}

	private UiButton AddButton(Transform parent, string label, Vector2 size, Vector2 position, Color baseColor, Color textColor, Action onClick)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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_0098: 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_00b4: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Btn", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val.transform.SetParent(parent, false);
		RectTransform val2 = (RectTransform)val.transform;
		val2.anchorMin = new Vector2(0f, 1f);
		val2.anchorMax = new Vector2(0f, 1f);
		val2.pivot = new Vector2(0f, 1f);
		val2.anchoredPosition = position;
		val2.sizeDelta = size;
		Image component = val.GetComponent<Image>();
		((Graphic)component).color = baseColor;
		((Graphic)component).raycastTarget = false;
		Text val3 = CreateText(val.transform, 18, (TextAnchor)4, Vector2.zero, size, textColor);
		val3.text = label;
		val3.fontStyle = (FontStyle)0;
		UiButton uiButton = new UiButton
		{
			Go = val,
			Bg = component,
			Label = val3,
			Base = baseColor,
			OnClick = onClick
		};
		_buttons.Add(uiButton);
		return uiButton;
	}

	private void UpdateHud()
	{
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		bool flag = GameRefs.InGameLevel() && (Object)(object)GameRefs.LocalAvatar != (Object)null && GameRefs.InTruck(GameRefs.LocalAvatar);
		bool flag2 = Plugin.ShowStatusHud.Value && flag && (Object)(object)Plugin.Net != (Object)null && (Plugin.Net.IsLocalHostLike || Plugin.Net.HostHasMod || Plugin.Net.Mode == NetMode.ClientVanilla || Plugin.Net.Mode == NetMode.Unavailable);
		bool flag3 = flag2 || (flag && (Object)(object)Plugin.Net != (Object)null);
		if (!_uiReady)
		{
			if (!flag3)
			{
				return;
			}
			EnsureUi();
		}
		if (!((Object)(object)_hud == (Object)null))
		{
			((Component)_hud).gameObject.SetActive(flag2);
			if (flag2)
			{
				string text = (_open ? string.Empty : ("  [" + KeyName(_panelKey) + "] " + Loc.T("面板", "panel")));
				_hud.text = "PeachSell  " + ModeText() + text;
			}
			UpdateSellHint(flag);
		}
	}

	private void UpdateSellHint(bool inTruck)
	{
		//IL_0077: 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)
		if ((Object)(object)_hint == (Object)null)
		{
			return;
		}
		if (!Plugin.Net.Active)
		{
			_hintText = string.Empty;
			((Component)_hint).gameObject.SetActive(false);
			return;
		}
		if (inTruck && Time.unscaledTime >= _nextHintAt)
		{
			_nextHintAt = Time.unscaledTime + 0.2f;
			_hintText = BuildSellHint(out var sellable);
			((Graphic)_hint).color = (sellable ? Accent : Warning);
		}
		if (!inTruck)
		{
			_hintText = string.Empty;
		}
		bool flag = !_open && !string.IsNullOrEmpty(_hintText);
		((Component)_hint).gameObject.SetActive(flag);
		if (flag)
		{
			_hint.text = _hintText;
		}
	}

	private string BuildSellHint(out bool sellable)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		sellable = false;
		PlayerAvatar localAvatar = GameRefs.LocalAvatar;
		if ((Object)(object)localAvatar == (Object)null)
		{
			return string.Empty;
		}
		ItemAttributes val;
		try
		{
			val = SellService.HeldItem(localAvatar);
		}
		catch (Exception ex)
		{
			Plugin.Dbg("取手持物品失败: " + ex.Message);
			return string.Empty;
		}
		if ((Object)(object)val == (Object)null)
		{
			return string.Empty;
		}
		string text = KeyName(_sellKey);
		if (!CanLocalSell())
		{
			return Loc.T("手持物品 · 按 " + text + " 无效:", "Holding an item · " + text + " does nothing: ") + SellBlockedText();
		}
		string text2 = SellService.Validate(val, localAvatar);
		if (text2 != null)
		{
			return Loc.T("手持物品 · 不能回收:", "Holding an item · cannot sell: ") + ErrorText(text2);
		}
		int value = GameRefs.GetValue(val);
		int num = SellService.RefundDollars(value);
		int num2 = Mathf.Max(0, value) * 1000;
		int num3 = Mathf.RoundToInt(Mathf.Clamp01(Plugin.RefundPercent.Value) * 100f);
		sellable = true;
		return Loc.T("按 " + text + " 回收 · $" + num + "  (原价 $" + num2 + " × " + num3 + "%,取整到百位)", "Press " + text + " to sell · $" + num + "  ($" + num2 + " × " + num3 + "%,