using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Photon.Pun; using Photon.Realtime; using TMPro; using UnityEngine; using UnityEngine.Localization; using UnityEngine.SceneManagement; using UnityEngine.TextCore.LowLevel; 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: AssemblyCompany("PingDisplay")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("2.0.2.0")] [assembly: AssemblyInformationalVersion("2.0.2+98350628c98f7c56623531e84e4cd0adbd48f1d9")] [assembly: AssemblyProduct("PingDisplay")] [assembly: AssemblyTitle("PingDisplay")] [assembly: AssemblyVersion("2.0.2.0")] namespace PingDisplay; [BepInPlugin("com.peachh.pingdisplay", "PingDisplay", "2.0.2")] public class Plugin : BaseUnityPlugin { private enum UILanguage { Auto, Chinese, English } private static class Loc { public const string LabelCN = "Ping: "; public const string LabelEN = "Ping: "; public const string MaxCN = "最大: "; public const string MaxEN = "Max: "; public const string AvgCN = "均: "; public const string AvgEN = "Avg: "; public const string JitCN = "抖: "; public const string JitEN = "Jit: "; public const string LossCN = "丢: "; public const string LossEN = "Loss: "; public const string MsCN = "ms"; public const string MsEN = "ms"; public const string HostCN = "房主: "; public const string HostEN = "Host: "; public const string HostWarnCN = "!"; public const string HostWarnEN = "!"; public const string DisconnectedCN = "未连接"; public const string DisconnectedEN = "Not Connected"; public const string ConnectingCN = "连接中"; public const string ConnectingEN = "Connecting..."; public const string InLobbyCN = "大厅中"; public const string InLobbyEN = "In Lobby"; } private enum PingCorner { TopLeft, TopRight, BottomLeft, BottomRight } internal static class PluginInfo { public const string PLUGIN_GUID = "com.peachh.pingdisplay"; public const string PLUGIN_NAME = "PingDisplay"; public const string PLUGIN_VERSION = "2.0.2"; public const string PLUGIN_AUTHOR = "peachh"; } private ConfigEntry _language; private ConfigEntry _corner; private ConfigEntry _paddingLeft; private ConfigEntry _paddingRight; private ConfigEntry _paddingTop; private ConfigEntry _paddingBottom; private ConfigEntry _fontName; private ConfigEntry _fontSize; private ConfigEntry _fontColor; private ConfigEntry _showMsSuffix; private ConfigEntry _showLabel; private ConfigEntry _showInMenu; private ConfigEntry _greenThreshold; private ConfigEntry _yellowThreshold; private ConfigEntry _orangeThreshold; private ConfigEntry _outlineColor; private ConfigEntry _outlineWidth; private ConfigEntry _showMaxPing; private ConfigEntry _maxPingFontSize; private ConfigEntry _maxPingColor; private ConfigEntry _maxPingResetInterval; private ConfigEntry _regionNotifyDuration; private ConfigEntry _showAvgPing; private ConfigEntry _showJitter; private ConfigEntry _showPacketLoss; private ConfigEntry _showHostPing; private ConfigEntry _showHostPingWarning; private ConfigEntry _hostPingWarningThreshold; private Harmony _harmony; private static Plugin _instance; private static GameObject _container; private static TextMeshProUGUI _pingText; private static TextMeshProUGUI _maxPingText; private static TextMeshProUGUI _statsText; private const string BUILTIN_FONT_FILE = "PingDisplayFont.ttf"; private static int _currentPing; private static float _lastPingCheck; private static float _periodStartTime; private static int _periodMaxPing; private static int[] _pingHistory; private static int _pingHistoryIdx; private static int _pingHistoryCount; private static int _pingSum; private const float PING_CHECK_INTERVAL = 1f; private const int PING_HISTORY_SIZE = 10; private static bool _wasConnected; private static float _regionNotifyTime; private static string _regionStr = ""; private static float _disconnectedSince = -1f; private const float DISCONNECT_GRACE = 2f; private static int _cachedPing = -1; private static int _cachedMaxPing = -1; private static string _cachedPingStr = ""; private static string _cachedMaxStr = ""; private static string _cachedStatsStr = ""; private Color _cachedFontColor; private Color _cachedMaxPingColor; private int _cachedFontSize; private int _cachedMaxFontSize; private int _cachedGreen; private int _cachedYellow; private int _cachedOrange; private static Color _cachedOutlineColor = Color.black; private static float _cachedOutlineWidth = 1.5f; private bool _cachedShowLabel; private bool _cachedShowMs; private bool _cachedShowMax; private bool _cachedShowInMenu; private bool _cachedShowAvg; private bool _cachedShowJitter; private bool _cachedShowLoss; private bool _cachedShowHost; private bool _cachedShowHostWarning; private int _cachedHostWarningThreshold; private static readonly Dictionary _actorPings = new Dictionary(); private static int[] _hostPingHistory; private static int _hostPingHistoryIdx; private static int _hostPingHistoryCount; private static int _hostPingSum; private static int _lastMasterActor; private const int HOST_PING_HISTORY_SIZE = 8; private static bool _forceRefresh; private static bool _cachedInMenu = true; private static float _lastMenuCheck; private static bool _isCN; private static string _gameLocaleCode = "?"; private static string _lastLoggedLocale; private static TMP_FontAsset _tmpFont; private static bool _tmpFontFinal; private static readonly FieldInfo _playerPingField = typeof(PlayerAvatar).GetField("playerPing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly Dictionary _peerPropCache = new Dictionary(); private void Awake() { _instance = this; _pingHistory = new int[10]; _hostPingHistory = new int[8]; BindConfig(); CacheConfig(); InitHarmony(); CreateCanvasUI(); SceneManager.sceneLoaded += OnSceneLoaded; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PingDisplay v2.0.2 loaded."); } private void BindConfig() { _language = ((BaseUnityPlugin)this).Config.Bind("语言 / Language", "语言 / Language", UILanguage.Auto, "界面语言。Auto = 跟随游戏本体语言(默认);也可强制中文/英文。切换到游戏内其他语言时自动回落到英文文案。 UI language. Auto = follow the game language (default); Chinese/English forces it. Other game languages fall back to English."); _isCN = ResolveIsChinese(_language.Value); _corner = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("显示位置", "Corner"), PingCorner.TopLeft, L("显示在屏幕的哪个角", "Display corner")); _paddingLeft = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("左边距", "PaddingLeft"), 80f, L("距屏幕左边距离 (1920x1080 参考)", "Padding from left (1920x1080 ref)")); _paddingRight = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("右边距", "PaddingRight"), 50f, L("距屏幕右边距离", "Padding from right")); _paddingTop = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("上边距", "PaddingTop"), 5f, L("距屏幕顶部距离", "Padding from top")); _paddingBottom = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("下边距", "PaddingBottom"), 50f, L("距屏幕底部距离", "Padding from bottom")); _fontName = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("自定义字体文件", "CustomFontFile"), "", L("把 .ttf 放到 plugins\\PingDisplay\\ 下并填文件名即可替换内置字体;留空=用内置字体", "Put a .ttf in plugins\\PingDisplay\\ and enter its file name; empty = bundled font")); _fontSize = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("字体大小", "FontSize"), 26, L("Ping 文字字体大小", "Ping text font size")); _fontColor = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("字体颜色", "FontColor"), "", L("自定义 HEX 颜色,留空=自动着色", "Custom HEX color, empty=auto-color")); _showMsSuffix = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("显示ms后缀", "ShowMsSuffix"), true, L("数值后显示 'ms'", "Show 'ms' suffix after value")); _showLabel = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("显示标签", "ShowLabel"), true, L("显示 'Ping:' 标签前缀", "Show 'Ping:' label prefix")); _showInMenu = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("菜单中显示", "ShowInMenu"), true, L("在菜单/大厅界面也显示", "Show in menu and lobby")); _greenThreshold = ((BaseUnityPlugin)this).Config.Bind(L("颜色", "Colors"), L("绿色阈值", "GreenThreshold"), 50, L("低于此值为最亮的明黄 (ms)", "Below this → brightest yellow (ms)")); _yellowThreshold = ((BaseUnityPlugin)this).Config.Bind(L("颜色", "Colors"), L("黄色阈值", "YellowThreshold"), 100, L("低于此值为金黄,超过开始转琥珀 (ms)", "Below this → gold, above fades to amber (ms)")); _orangeThreshold = ((BaseUnityPlugin)this).Config.Bind(L("颜色", "Colors"), L("橙色阈值", "OrangeThreshold"), 200, L("超过此值转为橙红 (ms)", "Above this → orange-red (ms)")); _outlineColor = ((BaseUnityPlugin)this).Config.Bind(L("颜色", "Colors"), L("边缘颜色", "OutlineColor"), "000000", L("文字描边颜色 HEX,默认纯黑(黄字黑边效果)", "Text outline color HEX, default black")); _outlineWidth = ((BaseUnityPlugin)this).Config.Bind(L("颜色", "Colors"), L("边缘厚度", "OutlineWidth"), 3f, L("描边粗细(像素),0 = 关闭描边", "Outline thickness in px, 0 = off")); _showMaxPing = ((BaseUnityPlugin)this).Config.Bind(L("最大延迟", "MaxPing"), L("显示最大延迟", "ShowMaxPing"), true, L("显示周期内最大 Ping 值", "Show max ping value in period")); _maxPingFontSize = ((BaseUnityPlugin)this).Config.Bind(L("最大延迟", "MaxPing"), L("最大延迟字体大小", "MaxPingFontSize"), 14, L("最大 Ping 文字字体大小", "Max ping text font size")); _maxPingColor = ((BaseUnityPlugin)this).Config.Bind(L("最大延迟", "MaxPing"), L("最大延迟颜色", "MaxPingColor"), "", L("最大 Ping HEX 颜色,留空=跟随主文字", "Max ping HEX color, empty=follow main")); _maxPingResetInterval = ((BaseUnityPlugin)this).Config.Bind(L("最大延迟", "MaxPing"), L("重置间隔", "ResetInterval"), 60, L("最大 Ping 重置间隔(秒),0=不重置", "Max ping reset interval in seconds, 0=never")); _regionNotifyDuration = ((BaseUnityPlugin)this).Config.Bind(L("显示", "Display"), L("地区显示时长", "RegionNotifyDuration"), 5f, L("连接后显示服务器地区的时间(秒),0=不显示", "Show region for N seconds after connect, 0=off")); _showAvgPing = ((BaseUnityPlugin)this).Config.Bind(L("统计", "Stats"), L("显示平均延迟", "ShowAvgPing"), false, L("显示平均延迟 (10秒滑动窗口)", "Show average ping (10s sliding window)")); _showJitter = ((BaseUnityPlugin)this).Config.Bind(L("统计", "Stats"), L("显示抖动", "ShowJitter"), false, L("显示网络抖动 (RTT 方差)", "Show jitter (RTT variance)")); _showPacketLoss = ((BaseUnityPlugin)this).Config.Bind(L("统计", "Stats"), L("显示丢包率", "ShowPacketLoss"), false, L("显示丢包率百分比", "Show packet loss %")); _showHostPing = ((BaseUnityPlugin)this).Config.Bind(L("统计", "Stats"), L("显示主机延迟", "ShowHostPing"), false, L("显示房主(主机)的网络延迟", "Show host (master client) ping")); _showHostPingWarning = ((BaseUnityPlugin)this).Config.Bind(L("统计", "Stats"), L("主机延迟波动警告", "ShowHostPingWarning"), true, L("主机延迟波动较大时在末尾显示 ! 警告", "Append '!' when host ping fluctuates")); _hostPingWarningThreshold = ((BaseUnityPlugin)this).Config.Bind(L("统计", "Stats"), L("波动警告阈值", "HostWarningThreshold"), 80, L("主机延迟标准差超过此值(ms)时显示警告", "Show warning when host ping stddev exceeds this (ms)")); _fontColor.SettingChanged += delegate { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) _cachedFontColor = ParseHexColor(_fontColor.Value, Color.white); _forceRefresh = true; }; _maxPingColor.SettingChanged += delegate { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) _cachedMaxPingColor = ParseHexColor(_maxPingColor.Value, Color.white); _forceRefresh = true; }; _fontSize.SettingChanged += delegate { CacheConfig(); _forceRefresh = true; }; _maxPingFontSize.SettingChanged += delegate { CacheConfig(); _forceRefresh = true; }; _greenThreshold.SettingChanged += delegate { _cachedGreen = _greenThreshold.Value; _forceRefresh = true; }; _yellowThreshold.SettingChanged += delegate { _cachedYellow = _yellowThreshold.Value; _forceRefresh = true; }; _orangeThreshold.SettingChanged += delegate { _cachedOrange = _orangeThreshold.Value; _forceRefresh = true; }; _outlineColor.SettingChanged += delegate { CacheConfig(); ApplyOutline(); _forceRefresh = true; }; _outlineWidth.SettingChanged += delegate { CacheConfig(); ApplyOutline(); _forceRefresh = true; }; _fontName.SettingChanged += delegate { RebuildUI(); }; _showLabel.SettingChanged += delegate { _cachedShowLabel = _showLabel.Value; _forceRefresh = true; }; _showMsSuffix.SettingChanged += delegate { _cachedShowMs = _showMsSuffix.Value; _forceRefresh = true; }; _showMaxPing.SettingChanged += delegate { _cachedShowMax = _showMaxPing.Value; _forceRefresh = true; }; _showInMenu.SettingChanged += delegate { _cachedShowInMenu = _showInMenu.Value; _forceRefresh = true; }; _showAvgPing.SettingChanged += delegate { _cachedShowAvg = _showAvgPing.Value; _forceRefresh = true; }; _showJitter.SettingChanged += delegate { _cachedShowJitter = _showJitter.Value; _forceRefresh = true; }; _showPacketLoss.SettingChanged += delegate { _cachedShowLoss = _showPacketLoss.Value; _forceRefresh = true; }; _showHostPing.SettingChanged += delegate { _cachedShowHost = _showHostPing.Value; _forceRefresh = true; }; _showHostPingWarning.SettingChanged += delegate { _cachedShowHostWarning = _showHostPingWarning.Value; _forceRefresh = true; }; _hostPingWarningThreshold.SettingChanged += delegate { _cachedHostWarningThreshold = _hostPingWarningThreshold.Value; _forceRefresh = true; }; _language.SettingChanged += delegate { _isCN = ResolveIsChinese(_language.Value); _forceRefresh = true; }; _corner.SettingChanged += delegate { RepositionContainer(); }; _paddingLeft.SettingChanged += delegate { RepositionContainer(); }; _paddingRight.SettingChanged += delegate { RepositionContainer(); }; _paddingTop.SettingChanged += delegate { RepositionContainer(); }; _paddingBottom.SettingChanged += delegate { RepositionContainer(); }; } private static string L(string cn, string en) { if (!_isCN) { return en; } return cn; } private unsafe static bool IsGameLocaleChinese() { //IL_00b0: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Invalid comparison between Unknown and I4 //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Invalid comparison between Unknown and I4 try { LocalizationManager instance = LocalizationManager.instance; if ((Object)(object)instance != (Object)null) { LocaleAsset activeLocale = instance.ActiveLocale; if ((Object)(object)activeLocale != (Object)null && (Object)(object)activeLocale.LocaleReference != (Object)null) { LocaleIdentifier identifier = activeLocale.LocaleReference.Identifier; string code = ((LocaleIdentifier)(ref identifier)).Code; if (!string.IsNullOrEmpty(code)) { _gameLocaleCode = code; if (_gameLocaleCode != _lastLoggedLocale) { _lastLoggedLocale = _gameLocaleCode; Plugin instance2 = _instance; if (instance2 != null) { ManualLogSource logger = ((BaseUnityPlugin)instance2).Logger; if (logger != null) { logger.LogInfo((object)("[语言] 游戏本体语言 = " + _gameLocaleCode)); } } } return code.StartsWith("zh", StringComparison.OrdinalIgnoreCase); } } } } catch { } SystemLanguage systemLanguage = Application.systemLanguage; _gameLocaleCode = "system:" + ((object)(*(SystemLanguage*)(&systemLanguage))/*cast due to .constrained prefix*/).ToString(); if ((int)systemLanguage != 40 && (int)systemLanguage != 41) { return (int)systemLanguage == 6; } return true; } private static bool ResolveIsChinese(UILanguage mode) { return mode switch { UILanguage.Chinese => true, UILanguage.English => false, _ => IsGameLocaleChinese(), }; } private void CacheConfig() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) _cachedFontColor = ParseHexColor(_fontColor.Value, Color.white); _cachedMaxPingColor = ParseHexColor(_maxPingColor.Value, Color.white); _cachedFontSize = _fontSize.Value; _cachedMaxFontSize = _maxPingFontSize.Value; _cachedGreen = _greenThreshold.Value; _cachedYellow = _yellowThreshold.Value; _cachedOrange = _orangeThreshold.Value; _cachedOutlineColor = ParseHexColor(_outlineColor.Value, Color.black); _cachedOutlineWidth = _outlineWidth.Value; _cachedShowLabel = _showLabel.Value; _cachedShowMs = _showMsSuffix.Value; _cachedShowMax = _showMaxPing.Value; _cachedShowInMenu = _showInMenu.Value; _cachedShowAvg = _showAvgPing.Value; _cachedShowJitter = _showJitter.Value; _cachedShowLoss = _showPacketLoss.Value; _cachedShowHost = _showHostPing.Value; _cachedShowHostWarning = _showHostPingWarning.Value; _cachedHostWarningThreshold = _hostPingWarningThreshold.Value; } private void InitHarmony() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown _harmony = new Harmony("com.peachh.pingdisplay"); try { MethodInfo method = typeof(PlayerAvatar).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { _harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "OnPlayerUpdatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"PlayerAvatar.Update not found."); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Harmony patch failed: " + ex.Message)); } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if ((Object)(object)_pingText == (Object)null || (Object)(object)((Component)_pingText).gameObject == (Object)null) { CreateCanvasUI(); } else { RefreshFont(); } } private void RepositionContainer() { if (!((Object)(object)_container == (Object)null)) { RectTransform component = _container.GetComponent(); if (!((Object)(object)component == (Object)null)) { SetupCornerPosition(component); ApplyAlignment(); } } } private bool CornerIsLeft() { PingCorner value = _corner.Value; if (value != PingCorner.TopLeft) { return value == PingCorner.BottomLeft; } return true; } private void ApplyAlignment() { //IL_0045: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_container == (Object)null)) { bool flag = CornerIsLeft(); VerticalLayoutGroup component = _container.GetComponent(); if ((Object)(object)component != (Object)null) { ((LayoutGroup)component).childAlignment = (TextAnchor)((!flag) ? 2 : 0); } TextAlignmentOptions alignment = (TextAlignmentOptions)(flag ? 257 : 260); if ((Object)(object)_pingText != (Object)null) { ((TMP_Text)_pingText).alignment = alignment; } if ((Object)(object)_maxPingText != (Object)null) { ((TMP_Text)_maxPingText).alignment = alignment; } if ((Object)(object)_statsText != (Object)null) { ((TMP_Text)_statsText).alignment = alignment; } } } private void OnDestroy() { SceneManager.sceneLoaded -= OnSceneLoaded; } private void CreateCanvasUI() { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown try { if (!UIReady()) { if ((Object)(object)_container != (Object)null) { Transform parent = _container.transform.parent; Object.Destroy((Object)(object)(((Object)(object)parent != (Object)null) ? ((Component)parent).gameObject : _container)); _container = null; _pingText = null; _maxPingText = null; _statsText = null; } GameObject val = new GameObject("PingDisplay_Canvas"); Object.DontDestroyOnLoad((Object)(object)val); val.layer = 5; Canvas obj = val.AddComponent(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 32767; CanvasScaler obj2 = val.AddComponent(); obj2.uiScaleMode = (ScaleMode)1; obj2.referenceResolution = new Vector2(1920f, 1080f); val.AddComponent(); _container = new GameObject("PingContainer"); _container.transform.SetParent(val.transform, false); _container.layer = 5; RectTransform rt = _container.AddComponent(); SetupCornerPosition(rt); VerticalLayoutGroup obj3 = _container.AddComponent(); ((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false; ((HorizontalOrVerticalLayoutGroup)obj3).spacing = 3f; ContentSizeFitter obj4 = _container.AddComponent(); obj4.horizontalFit = (FitMode)2; obj4.verticalFit = (FitMode)2; _pingText = CreateText("PingText", _cachedFontSize, 300f); _maxPingText = CreateText("MaxPingText", _cachedMaxFontSize, 260f); _statsText = CreateText("StatsText", 12, 260f); ApplyAlignment(); _periodStartTime = Time.time; _periodMaxPing = 0; } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[CreateCanvasUI] Failed: " + ex.Message)); } } private void SetupCornerPosition(RectTransform rt) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0116: 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_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) float num; float num2; switch (_corner.Value) { case PingCorner.TopLeft: num = _paddingLeft.Value; num2 = 0f - _paddingTop.Value; rt.anchorMin = new Vector2(0f, 1f); rt.anchorMax = new Vector2(0f, 1f); rt.pivot = new Vector2(0f, 1f); break; case PingCorner.TopRight: num = 0f - _paddingRight.Value; num2 = 0f - _paddingTop.Value; rt.anchorMin = new Vector2(1f, 1f); rt.anchorMax = new Vector2(1f, 1f); rt.pivot = new Vector2(1f, 1f); break; case PingCorner.BottomLeft: num = _paddingLeft.Value; num2 = _paddingBottom.Value; rt.anchorMin = new Vector2(0f, 0f); rt.anchorMax = new Vector2(0f, 0f); rt.pivot = new Vector2(0f, 0f); break; default: num = 0f - _paddingRight.Value; num2 = _paddingBottom.Value; rt.anchorMin = new Vector2(1f, 0f); rt.anchorMax = new Vector2(1f, 0f); rt.pivot = new Vector2(1f, 0f); break; } rt.anchoredPosition = new Vector2(num, num2); rt.sizeDelta = new Vector2(300f, 80f); } private static TMP_FontAsset GetTmpFontAsset() { if (_tmpFontFinal) { return _tmpFont; } ManualLogSource val = (((Object)(object)_instance != (Object)null) ? ((BaseUnityPlugin)_instance).Logger : null); try { string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location); string text = (((Object)(object)_instance != (Object)null) ? _instance._fontName.Value : null); string text2 = ((!string.IsNullOrEmpty(text) && File.Exists(Path.Combine(directoryName ?? "", text))) ? Path.Combine(directoryName ?? "", text) : Path.Combine(directoryName ?? "", "PingDisplayFont.ttf")); if (File.Exists(text2)) { TMP_FontAsset val2 = TMP_FontAsset.CreateFontAsset(text2, 0, 64, 9, (GlyphRenderMode)4165, 1024, 1024); if ((Object)(object)val2 != (Object)null) { ((Object)val2).name = "PingDisplay_TMP"; _tmpFont = val2; _tmpFontFinal = true; if (val != null) { val.LogInfo((object)("[字体] 已从 " + Path.GetFileName(text2) + " 创建 TMP 字体资产")); } return val2; } if (val != null) { val.LogWarning((object)("[字体] 从 " + Path.GetFileName(text2) + " 创建 TMP 资产返回 null,尝试游戏内置字体")); } } if (TryUseGameFont(val)) { _tmpFontFinal = true; return _tmpFont; } } catch (Exception ex) { if (val != null) { val.LogWarning((object)("[字体] 创建动态 TMP 字体失败: " + ex.GetType().Name + ": " + ex.Message)); } } return _tmpFont; } private static bool TryUseGameFont(ManualLogSource log) { TMP_FontAsset val = null; TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll(); foreach (TMP_FontAsset val2 in array) { if ((Object)(object)val2 != (Object)null && ((Object)val2).name.Contains("NotoSansSC")) { val = val2; break; } } if ((Object)(object)val != (Object)null && (Object)(object)val.sourceFontFile != (Object)null) { _tmpFont = TMP_FontAsset.CreateFontAsset(val.sourceFontFile, 90, 9, (GlyphRenderMode)4165, 1024, 1024, (AtlasPopulationMode)1, true); if ((Object)(object)_tmpFont != (Object)null) { ((Object)_tmpFont).name = "PingDisplay_TMP"; if (log != null) { log.LogInfo((object)"[字体] 使用游戏自带 NotoSansSC 字体"); } return true; } } array = Resources.FindObjectsOfTypeAll(); foreach (TMP_FontAsset val3 in array) { if ((Object)(object)val3 != (Object)null && ((Object)val3).name == "LiberationSans SDF") { _tmpFont = val3; if (log != null) { log.LogInfo((object)"[字体] 使用游戏自带 LiberationSans SDF"); } return true; } } return false; } private static void RefreshFont() { TMP_FontAsset tmpFontAsset = GetTmpFontAsset(); if ((Object)(object)tmpFontAsset == (Object)null) { return; } try { bool flag = false; if ((Object)(object)_pingText != (Object)null && (Object)(object)((TMP_Text)_pingText).font != (Object)(object)tmpFontAsset) { ((TMP_Text)_pingText).font = tmpFontAsset; ApplyOutlineTo(_pingText); flag = true; } if ((Object)(object)_maxPingText != (Object)null && (Object)(object)((TMP_Text)_maxPingText).font != (Object)(object)tmpFontAsset) { ((TMP_Text)_maxPingText).font = tmpFontAsset; ApplyOutlineTo(_maxPingText); flag = true; } if ((Object)(object)_statsText != (Object)null && (Object)(object)((TMP_Text)_statsText).font != (Object)(object)tmpFontAsset) { ((TMP_Text)_statsText).font = tmpFontAsset; ApplyOutlineTo(_statsText); flag = true; } if (!flag) { return; } Plugin instance = _instance; if (instance != null) { ManualLogSource logger = ((BaseUnityPlugin)instance).Logger; if (logger != null) { logger.LogInfo((object)("[字体] 已切换为 TMP 字体: " + ((Object)tmpFontAsset).name)); } } } catch { } } private TextMeshProUGUI CreateText(string name, int size, float width) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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) GameObject val = new GameObject(name); val.transform.SetParent(_container.transform, false); val.layer = 5; val.AddComponent().sizeDelta = new Vector2(width, (float)(size + 10)); TextMeshProUGUI obj = val.AddComponent(); ((TMP_Text)obj).font = GetTmpFontAsset(); ((TMP_Text)obj).fontSize = size; ((TMP_Text)obj).alignment = (TextAlignmentOptions)(CornerIsLeft() ? 257 : 260); ((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)obj).overflowMode = (TextOverflowModes)0; ((TMP_Text)obj).text = ""; ApplyOutlineTo(obj); return obj; } private static void ApplyOutlineTo(TextMeshProUGUI t) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)t == (Object)null) { return; } float num = Mathf.Clamp(_cachedOutlineWidth / 60f, 0f, 1f); try { Material fontMaterial = ((TMP_Text)t).fontMaterial; if ((Object)(object)fontMaterial != (Object)null) { fontMaterial.EnableKeyword("OUTLINE_ON"); fontMaterial.SetFloat(ShaderUtilities.ID_OutlineWidth, num); fontMaterial.SetColor(ShaderUtilities.ID_OutlineColor, _cachedOutlineColor); fontMaterial.SetFloat(ShaderUtilities.ID_OutlineSoftness, 0f); Shader shader = fontMaterial.shader; Plugin instance = _instance; if (instance != null) { ManualLogSource logger = ((BaseUnityPlugin)instance).Logger; if (logger != null) { logger.LogDebug((object)$"[描边] shader={((Object)shader).name} w={num}"); } } } else { Plugin instance2 = _instance; if (instance2 != null) { ManualLogSource logger2 = ((BaseUnityPlugin)instance2).Logger; if (logger2 != null) { logger2.LogWarning((object)"[描边] fontMaterial 为 null"); } } } } catch (Exception ex) { Plugin instance3 = _instance; if (instance3 != null) { ManualLogSource logger3 = ((BaseUnityPlugin)instance3).Logger; if (logger3 != null) { logger3.LogWarning((object)("[描边] 设置失败: " + ex.Message)); } } } ((TMP_Text)t).outlineWidth = num; ((TMP_Text)t).outlineColor = Color32.op_Implicit(_cachedOutlineColor); ((TMP_Text)t).fontStyle = (FontStyles)1; } private static void ApplyOutline() { ApplyOutlineTo(_pingText); ApplyOutlineTo(_maxPingText); ApplyOutlineTo(_statsText); } private static void RebuildUI() { try { if ((Object)(object)_container != (Object)null) { Transform parent = _container.transform.parent; Object.Destroy((Object)(object)(((Object)(object)parent != (Object)null) ? ((Component)parent).gameObject : _container)); } } catch { } _container = null; _pingText = null; _maxPingText = null; _statsText = null; _cachedPingStr = ""; _cachedMaxStr = ""; _cachedStatsStr = ""; _cachedPing = -1; _cachedMaxPing = -1; _tmpFont = null; _tmpFontFinal = false; _instance?.CreateCanvasUI(); } private static void OnPlayerUpdatePostfix(PlayerAvatar __instance) { try { if ((Object)(object)__instance?.photonView != (Object)null && _playerPingField != null) { _actorPings[__instance.photonView.OwnerActorNr] = (int)_playerPingField.GetValue(__instance); } } catch { } _instance?.UpdatePingDisplay(); } private static bool UIReady() { if ((Object)(object)_pingText != (Object)null && (Object)(object)((Component)_pingText).gameObject != (Object)null && (Object)(object)_maxPingText != (Object)null && (Object)(object)((Component)_maxPingText).gameObject != (Object)null && (Object)(object)_statsText != (Object)null) { return (Object)(object)((Component)_statsText).gameObject != (Object)null; } return false; } private void UpdatePingDisplay() { //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Invalid comparison between Unknown and I4 //IL_0946: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_048e: Unknown result type (might be due to invalid IL or missing references) //IL_0481: Unknown result type (might be due to invalid IL or missing references) //IL_0561: Unknown result type (might be due to invalid IL or missing references) //IL_0605: Unknown result type (might be due to invalid IL or missing references) //IL_05f9: Unknown result type (might be due to invalid IL or missing references) if (!UIReady()) { CreateCanvasUI(); if (!UIReady()) { return; } } if (Time.time - _lastMenuCheck >= 0.5f) { _lastMenuCheck = Time.time; try { _cachedInMenu = SemiFunc.MenuLevel(); } catch { _cachedInMenu = false; } } if (_cachedInMenu && !_cachedShowInMenu) { _cachedPingStr = ""; _cachedMaxStr = ""; _cachedStatsStr = ""; ((TMP_Text)_pingText).text = ""; ((TMP_Text)_maxPingText).text = ""; ((TMP_Text)_statsText).text = ""; return; } bool flag = false; if (Time.time - _lastPingCheck >= 1f) { _lastPingCheck = Time.time; if (_language.Value == UILanguage.Auto) { bool flag2 = IsGameLocaleChinese(); if (flag2 != _isCN) { _isCN = flag2; _forceRefresh = true; } } int currentPing = GetCurrentPing(); if (currentPing != _currentPing) { _currentPing = currentPing; flag = true; } if (_pingHistoryCount == 10) { _pingSum -= _pingHistory[_pingHistoryIdx]; } _pingHistory[_pingHistoryIdx] = _currentPing; _pingSum += _currentPing; _pingHistoryIdx = (_pingHistoryIdx + 1) % 10; if (_pingHistoryCount < 10) { _pingHistoryCount++; } int value = _maxPingResetInterval.Value; if (value > 0 && Time.time - _periodStartTime >= (float)value) { _periodMaxPing = 0; _periodStartTime = Time.time; } if (_currentPing > _periodMaxPing) { _periodMaxPing = _currentPing; } flag = true; } ClientState networkClientState = PhotonNetwork.NetworkClientState; if (!PhotonNetwork.IsConnectedAndReady) { _wasConnected = false; bool isCN = _isCN; if (_disconnectedSince < 0f) { _disconnectedSince = Time.time; } bool flag3 = Time.time - _disconnectedSince < 2f; string text = (((int)networkClientState == 4) ? (isCN ? "大厅中" : "In Lobby") : ((!flag3) ? (isCN ? "未连接" : "Not Connected") : (isCN ? "连接中" : "Connecting..."))); if (_cachedPingStr != text) { _cachedPingStr = text; ((TMP_Text)_pingText).text = text; ((Graphic)_pingText).color = new Color(0.7f, 0.7f, 0.7f); ((TMP_Text)_pingText).fontSize = _cachedFontSize; ((TMP_Text)_maxPingText).text = ""; ((TMP_Text)_statsText).text = ""; _cachedMaxStr = ""; _cachedStatsStr = ""; } return; } if (!_wasConnected) { _wasConnected = true; _disconnectedSince = -1f; _cachedPing = -1; _cachedMaxPing = -1; _cachedPingStr = ""; _cachedMaxStr = ""; _cachedStatsStr = ""; if (_regionNotifyDuration.Value > 0f) { try { _regionStr = PhotonNetwork.CloudRegion ?? ""; } catch { _regionStr = ""; } if (!string.IsNullOrEmpty(_regionStr)) { _regionNotifyTime = Time.time; } } } if (_forceRefresh) { _forceRefresh = false; _cachedPingStr = ""; _cachedMaxStr = ""; _cachedStatsStr = ""; _cachedPing = -1; _cachedMaxPing = -1; } if (!flag && _currentPing == _cachedPing && _periodMaxPing == _cachedMaxPing) { return; } _cachedPing = _currentPing; _cachedMaxPing = _periodMaxPing; bool isCN2 = _isCN; string text2 = (isCN2 ? "ms" : "ms"); string text3 = (_cachedShowMs ? $"{_currentPing}{text2}" : $"{_currentPing}"); string text4 = (isCN2 ? "Ping: " : "Ping: "); string text5 = (_cachedShowLabel ? (text4 + text3) : text3); if (_cachedPingStr != text5 || _cachedPingStr == "") { _cachedPingStr = text5; ((TMP_Text)_pingText).text = text5; ((TMP_Text)_pingText).fontSize = _cachedFontSize; ((Graphic)_pingText).color = (string.IsNullOrEmpty(_fontColor.Value) ? GetAutoPingColor(_currentPing) : _cachedFontColor); } if (_regionNotifyDuration.Value > 0f && _regionNotifyTime > 0f && Time.time - _regionNotifyTime < _regionNotifyDuration.Value && !string.IsNullOrEmpty(_regionStr)) { ((Component)_maxPingText).gameObject.SetActive(true); string text6 = (isCN2 ? ("地区: " + _regionStr) : ("Region: " + _regionStr)); if (_cachedMaxStr != text6) { _cachedMaxStr = text6; ((TMP_Text)_maxPingText).text = text6; ((TMP_Text)_maxPingText).fontSize = _cachedMaxFontSize; ((Graphic)_maxPingText).color = new Color(0.4f, 0.8f, 1f); } } else if (_cachedShowMax) { ((Component)_maxPingText).gameObject.SetActive(true); string text7 = (isCN2 ? "最大: " : "Max: ") + _periodMaxPing + text2; if (_cachedMaxStr != text7) { _cachedMaxStr = text7; ((TMP_Text)_maxPingText).text = text7; ((TMP_Text)_maxPingText).fontSize = _cachedMaxFontSize; ((Graphic)_maxPingText).color = (string.IsNullOrEmpty(_maxPingColor.Value) ? ((Graphic)_pingText).color : _cachedMaxPingColor); } } else { ((Component)_maxPingText).gameObject.SetActive(false); if (_cachedMaxStr != "") { _cachedMaxStr = ""; ((TMP_Text)_maxPingText).text = ""; } } if (_cachedShowAvg || _cachedShowJitter || _cachedShowLoss || _cachedShowHost) { ((Component)_statsText).gameObject.SetActive(true); List list = new List(4); if (_cachedShowAvg) { int num = ((_pingHistoryCount > 0) ? (_pingSum / _pingHistoryCount) : _currentPing); string arg = (isCN2 ? "均: " : "Avg: "); list.Add($"{arg}{num}{text2}"); } if (_cachedShowJitter) { int num2 = 0; try { num2 = GetPeerStat("RoundTripTimeVariance"); } catch { } string arg2 = (isCN2 ? "抖: " : "Jit: "); list.Add($"{arg2}{num2}{text2}"); } if (_cachedShowLoss) { int num3 = 0; try { num3 = GetPeerStat("PacketLossByCrc"); } catch { } string arg3 = (isCN2 ? "丢: " : "Loss: "); list.Add($"{arg3}{num3}%"); } if (_cachedShowHost) { int value2 = 0; bool flag4 = false; if (PhotonNetwork.InRoom && PhotonNetwork.MasterClient != null) { int actorNumber = PhotonNetwork.MasterClient.ActorNumber; if (actorNumber != _lastMasterActor) { _lastMasterActor = actorNumber; _hostPingHistoryCount = 0; _hostPingSum = 0; } flag4 = _actorPings.TryGetValue(actorNumber, out value2); if (flag4) { if (_hostPingHistoryCount == 8) { _hostPingSum -= _hostPingHistory[_hostPingHistoryIdx]; } _hostPingHistory[_hostPingHistoryIdx] = value2; _hostPingSum += value2; _hostPingHistoryIdx = (_hostPingHistoryIdx + 1) % 8; if (_hostPingHistoryCount < 8) { _hostPingHistoryCount++; } } } string text8 = (isCN2 ? "房主: " : "Host: "); if (flag4) { string text9 = $"{text8}{value2}{text2}"; if (_cachedShowHostWarning && _hostPingHistoryCount >= 4) { double num4 = (double)_hostPingSum / (double)_hostPingHistoryCount; double num5 = 0.0; for (int i = 0; i < _hostPingHistoryCount; i++) { double num6 = (double)_hostPingHistory[i] - num4; num5 += num6 * num6; } if (Math.Sqrt(num5 / (double)_hostPingHistoryCount) >= (double)_cachedHostWarningThreshold) { text9 += (isCN2 ? "!" : "!"); } } list.Add(text9); } else { list.Add(text8 + "N/A"); } } string text10 = string.Join(" ", list); if (_cachedStatsStr != text10) { _cachedStatsStr = text10; ((TMP_Text)_statsText).text = text10; ((TMP_Text)_statsText).fontSize = 12f; ((Graphic)_statsText).color = new Color(0.55f, 0.55f, 0.55f); } } else { ((Component)_statsText).gameObject.SetActive(false); if (_cachedStatsStr != "") { _cachedStatsStr = ""; ((TMP_Text)_statsText).text = ""; } } } private static int GetCurrentPing() { try { return PhotonNetwork.GetPing(); } catch { return 0; } } private static T GetPeerStat(string propertyName) { try { LoadBalancingClient networkingClient = PhotonNetwork.NetworkingClient; LoadBalancingPeer val = ((networkingClient != null) ? networkingClient.LoadBalancingPeer : null); if (val == null) { return default(T); } if (!_peerPropCache.TryGetValue(propertyName, out var value)) { Type type = ((object)val).GetType(); while (type != null && value == null) { value = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public); type = type.BaseType; } _peerPropCache[propertyName] = value; } if (value == null) { return default(T); } object value2 = value.GetValue(val); if (value2 == null) { return default(T); } if (value2 is T result) { return result; } return (T)Convert.ChangeType(value2, typeof(T)); } catch { return default(T); } } private Color GetAutoPingColor(int ping) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) if (ping <= 0) { return new Color(0.5f, 0.5f, 0.5f); } Color val = default(Color); ((Color)(ref val))..ctor(1f, 0.95f, 0f); Color val2 = default(Color); ((Color)(ref val2))..ctor(1f, 0.78f, 0.06f); Color val3 = default(Color); ((Color)(ref val3))..ctor(1f, 0.56f, 0.05f); Color val4 = default(Color); ((Color)(ref val4))..ctor(1f, 0.32f, 0.12f); int cachedGreen = _cachedGreen; int cachedYellow = _cachedYellow; int cachedOrange = _cachedOrange; if (ping < cachedGreen) { return val; } if (ping < cachedYellow) { return Color.Lerp(val, val2, Norm01(ping, cachedGreen, cachedYellow)); } if (ping < cachedOrange) { return Color.Lerp(val2, val3, Norm01(ping, cachedYellow, cachedOrange)); } return Color.Lerp(val3, val4, Mathf.Clamp01((float)(ping - cachedOrange) / (float)Mathf.Max(1, cachedOrange))); } private static float Norm01(int value, int from, int to) { int num = to - from; if (num <= 0) { return 1f; } return Mathf.Clamp01((float)(value - from) / (float)num); } private static Color ParseHexColor(string hex, Color fallback) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(hex)) { return fallback; } hex = hex.TrimStart('#'); if (hex.Length != 6 && hex.Length != 8) { return fallback; } try { return new Color((float)Convert.ToInt32(hex.Substring(0, 2), 16) / 255f, (float)Convert.ToInt32(hex.Substring(2, 2), 16) / 255f, (float)Convert.ToInt32(hex.Substring(4, 2), 16) / 255f, (hex.Length >= 8) ? ((float)Convert.ToInt32(hex.Substring(6, 2), 16) / 255f) : 1f); } catch { return fallback; } } }