using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BetterPingDistance.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("youxia173")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("BetterPingDistance")]
[assembly: AssemblyTitle("youxia173.BetterPingDistance")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BetterPingDistance
{
[BepInPlugin("youxia173.BetterPingDistance", "BetterPingDistance", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("youxia173.BetterPingDistance");
internal static ConfigEntry<float> DisplayDuration;
internal static ConfigEntry<bool> ShowPlayerNameShort;
internal static Plugin instance { get; private set; }
internal static ManualLogSource Log => instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal static PingDistanceManager PDM { get; private set; }
private void Awake()
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
DisplayDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DisplayDuration", 3f, new ConfigDescription("标记距离文字在屏幕上停留的秒数。范围 0.1–30。 / How long the ping distance text stays on screen, in seconds. Range 0.1–30.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 30f), Array.Empty<object>()));
ShowPlayerNameShort = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowPlayerNameShort", false, "在距离后显示玩家名缩写。优先:中文首字 → 拉丁首字母 → 名字首字符。默认关。 / Show a short player name after the distance. Priority: first Chinese char, else first Latin letter, else first character. Default off.");
PDM = new PingDistanceManager();
harmony.PatchAll(typeof(GUIManagerPatch));
harmony.PatchAll(typeof(PointPingerPatch));
Log.LogInfo((object)"BetterPingDistance v1.2.0 by youxia173 initialized!");
}
private void OnDestroy()
{
harmony.UnpatchSelf();
PDM.OnDestroy();
}
}
public class PingDistance : MonoBehaviour
{
public Vector3 position;
public Color color = Color.white;
public string nameShort = "";
private TextMeshProUGUI? TMP;
private void Awake()
{
EnsureTMP();
}
private void OnEnable()
{
EnsureTMP();
}
private void EnsureTMP()
{
if ((Object)(object)TMP == (Object)null)
{
TMP = ((Component)this).GetComponentInChildren<TextMeshProUGUI>(true);
}
}
private void LateUpdate()
{
//IL_0029: 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_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_007d: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
EnsureTMP();
if (!((Object)(object)Camera.main == (Object)null) && !((Object)(object)TMP == (Object)null))
{
Camera main = Camera.main;
Vector3 val = position - ((Component)main).transform.position;
float num = Mathf.Round(((Vector3)(ref val)).magnitude);
if (num < 1f)
{
num = 1f;
}
float num2 = Mathf.Clamp(2f / (num / 10f), 0.5f, 1.5f);
float num3 = Vector3.Angle(((Component)main).transform.forward, val);
Vector3 val2 = main.WorldToScreenPoint(position);
bool active = val2.z > 0.1f && num3 < 90f;
((Component)this).transform.position = val2;
((Component)this).transform.localScale = new Vector3(num2, num2, num2);
((Graphic)TMP).color = MakeOpaque(color);
if (Plugin.ShowPlayerNameShort.Value && !string.IsNullOrEmpty(nameShort))
{
((TMP_Text)TMP).text = $"{num}m {nameShort}";
}
else
{
((TMP_Text)TMP).text = $"{num}m";
}
((Component)TMP).gameObject.SetActive(active);
}
}
private static Color MakeOpaque(Color c)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0039: Unknown result type (might be due to invalid IL or missing references)
c.a = 1f;
if (float.IsNaN(c.r) || float.IsNaN(c.g) || float.IsNaN(c.b))
{
return Color.white;
}
return c;
}
}
public class PingDistanceManager
{
private TMP_FontAsset? font;
private Material? fontMaterial;
private Canvas? pingDistanceCanvas;
private GameObject? template;
private readonly Dictionary<int, GameObject> pingDistanceInstances = new Dictionary<int, GameObject>();
public bool isInitialized
{
get
{
if ((Object)(object)Plugin.instance != (Object)null && (Object)(object)pingDistanceCanvas != (Object)null)
{
return (Object)(object)template != (Object)null;
}
return false;
}
}
public PingDistanceManager()
{
Plugin.Log.LogInfo((object)"PingDistanceManager has started");
}
public void Initialize()
{
if (isInitialized)
{
return;
}
try
{
CreateCanvas();
CreateTemplate();
if (isInitialized)
{
Plugin.Log.LogInfo((object)"PingDistanceManager UI initialized");
}
else
{
Plugin.Log.LogWarning((object)"PingDistanceManager UI not ready yet (GUIManager/font missing)");
}
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"PingDistanceManager.Initialize failed: {arg}");
}
}
public void OnDestroy()
{
CleanupUI();
Plugin.Log.LogInfo((object)"PingDistanceManager UI cleaned up");
}
private void CleanupUI()
{
if ((Object)(object)pingDistanceCanvas != (Object)null)
{
Object.Destroy((Object)(object)((Component)pingDistanceCanvas).gameObject);
pingDistanceCanvas = null;
}
template = null;
pingDistanceInstances.Clear();
}
private void FindFont()
{
TextMeshProUGUI[] array = Resources.FindObjectsOfTypeAll<TextMeshProUGUI>();
TextMeshProUGUI[] array2 = array;
foreach (TextMeshProUGUI val in array2)
{
if (!((Object)(object)val == (Object)null))
{
Material materialForRendering = ((Graphic)val).materialForRendering;
if (((Object)val).name == "Text" && (Object)(object)materialForRendering != (Object)null && ((Object)materialForRendering).name.Contains("DarumaDropOne-Regular SDF"))
{
font = ((TMP_Text)val).font;
fontMaterial = materialForRendering;
return;
}
}
}
TextMeshProUGUI[] array3 = array;
foreach (TextMeshProUGUI val2 in array3)
{
if (!((Object)(object)((val2 != null) ? ((TMP_Text)val2).font : null) == (Object)null) && (((Object)((TMP_Text)val2).font).name.Contains("Daruma") || ((Object)(object)((Graphic)val2).materialForRendering != (Object)null && ((Object)((Graphic)val2).materialForRendering).name.Contains("Daruma"))))
{
font = ((TMP_Text)val2).font;
fontMaterial = ((Graphic)val2).materialForRendering;
return;
}
}
if ((Object)(object)font == (Object)null)
{
Plugin.Log.LogError((object)"Error finding game font");
}
}
private void CreateCanvas()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)pingDistanceCanvas != (Object)null))
{
pingDistanceInstances.Clear();
GameObject val = GameObject.Find("GAME/GUIManager");
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)"GUIManager not found, delay BetterPingDistance canvas");
return;
}
GameObject val2 = new GameObject("Canvas_BetterPingDistance", new Type[3]
{
typeof(Canvas),
typeof(CanvasScaler),
typeof(GraphicRaycaster)
});
val2.transform.SetParent(val.transform, false);
pingDistanceCanvas = val2.GetComponent<Canvas>();
pingDistanceCanvas.renderMode = (RenderMode)0;
pingDistanceCanvas.sortingOrder = 100;
CanvasScaler component = val2.GetComponent<CanvasScaler>();
component.uiScaleMode = (ScaleMode)1;
component.referenceResolution = new Vector2(1920f, 1080f);
component.screenMatchMode = (ScreenMatchMode)1;
val2.layer = LayerMask.NameToLayer("UI");
Plugin.Log.LogInfo((object)"Canvas_BetterPingDistance created");
}
}
private void CreateTemplate()
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)template != (Object)null) && !((Object)(object)pingDistanceCanvas == (Object)null))
{
template = new GameObject("PingDistanceIndicator", new Type[3]
{
typeof(RectTransform),
typeof(CanvasRenderer),
typeof(PingDistance)
});
template.transform.SetParent(((Component)pingDistanceCanvas).transform, false);
AddTMPChildren("DistanceText", template.transform, new Vector2(200f, 50f));
template.SetActive(false);
Plugin.Log.LogInfo((object)"PingDistanceIndicator template created");
}
}
private GameObject AddTMPChildren(string name, Transform parent, Vector2 size)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: 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)
if ((Object)(object)font == (Object)null)
{
FindFont();
}
GameObject val = new GameObject(name, new Type[4]
{
typeof(RectTransform),
typeof(CanvasRenderer),
typeof(TextMeshProUGUI),
typeof(Shadow)
});
val.transform.SetParent(parent, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0.5f);
component.anchorMax = new Vector2(0.5f, 0.5f);
component.pivot = new Vector2(0.5f, 0.5f);
component.sizeDelta = size;
TextMeshProUGUI component2 = val.GetComponent<TextMeshProUGUI>();
if ((Object)(object)font != (Object)null)
{
((TMP_Text)component2).font = font;
}
if ((Object)(object)fontMaterial != (Object)null)
{
((TMP_Text)component2).fontMaterial = fontMaterial;
}
((TMP_Text)component2).fontSize = 30f;
((Graphic)component2).color = Color.white;
((TMP_Text)component2).outlineWidth = 0.1f;
((TMP_Text)component2).outlineColor = Color32.op_Implicit(Color.black);
((TMP_Text)component2).enableAutoSizing = false;
((TMP_Text)component2).alignment = (TextAlignmentOptions)514;
((TMP_Text)component2).horizontalAlignment = (HorizontalAlignmentOptions)2;
((TMP_Text)component2).verticalAlignment = (VerticalAlignmentOptions)512;
Shadow component3 = val.GetComponent<Shadow>();
component3.effectColor = new Color(0f, 0f, 0f, 0.95f);
component3.effectDistance = new Vector2(2f, -2f);
return val;
}
public void CreateInstance(PointPinger pinger, Vector3 position)
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)pingDistanceCanvas == (Object)null || (Object)(object)template == (Object)null)
{
Initialize();
if ((Object)(object)pingDistanceCanvas == (Object)null || (Object)(object)template == (Object)null)
{
return;
}
}
int num = 0;
try
{
if ((Object)(object)pinger != (Object)null && (Object)(object)pinger.photonView != (Object)null)
{
num = pinger.photonView.ViewID;
}
}
catch
{
num = 0;
}
if (num != 0 && pingDistanceInstances.TryGetValue(num, out GameObject value) && (Object)(object)value != (Object)null)
{
Object.Destroy((Object)(object)value);
pingDistanceInstances.Remove(num);
}
GameObject val = Object.Instantiate<GameObject>(template, ((Component)pingDistanceCanvas).transform);
((Object)val).name = ((num != 0) ? $"PingDistance_{num}" : "PingDistance");
PingDistance component = val.GetComponent<PingDistance>();
component.position = position;
component.color = ResolveVisiblePingColor(pinger);
component.nameShort = ResolvePlayerNameShort(pinger);
val.SetActive(true);
if (num != 0)
{
pingDistanceInstances[num] = val;
}
Object.Destroy((Object)(object)val, Mathf.Max(0.1f, Plugin.DisplayDuration.Value));
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"CreateInstance failed: {arg}");
}
}
private static string ResolvePlayerNameShort(PointPinger? pinger)
{
if (!Plugin.ShowPlayerNameShort.Value)
{
return "";
}
string fullName = null;
try
{
Character val = (((Object)(object)pinger != (Object)null) ? pinger.character : null);
if ((Object)(object)val != (Object)null)
{
fullName = val.characterName;
}
}
catch
{
fullName = null;
}
return FormatNameShort(fullName);
}
internal static string FormatNameShort(string? fullName)
{
if (string.IsNullOrWhiteSpace(fullName))
{
return "";
}
string text = fullName.Trim();
if (text.Length == 0)
{
return "";
}
string text2 = text;
foreach (char c in text2)
{
if (IsCjk(c))
{
return char.ToString(c);
}
}
string text3 = text;
foreach (char c2 in text3)
{
if ((c2 >= 'A' && c2 <= 'Z') || (c2 >= 'a' && c2 <= 'z'))
{
return char.ToString(c2);
}
}
return char.ToString(text[0]);
}
private static bool IsCjk(char c)
{
if ((c < '一' || c > '鿿') && (c < '㐀' || c > '䶿'))
{
if (c >= '豈')
{
return c <= '\ufaff';
}
return false;
}
return true;
}
private static Color ResolveVisiblePingColor(PointPinger? pinger)
{
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: 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_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
try
{
Character character = (((Object)(object)pinger != (Object)null) ? pinger.character : null);
if (TryGetPlayerSkinColor(character, out var color))
{
return MakeReadable(color);
}
}
catch
{
}
try
{
GameObject val = (((Object)(object)pinger != (Object)null) ? pinger.pingInstance : null);
if ((Object)(object)val != (Object)null)
{
Material val2 = null;
PointPing component = val.GetComponent<PointPing>();
if ((Object)(object)component != (Object)null)
{
val2 = component.material;
}
if ((Object)(object)val2 == (Object)null)
{
MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>();
if ((Object)(object)componentInChildren != (Object)null)
{
val2 = ((Renderer)componentInChildren).sharedMaterial ?? ((Renderer)componentInChildren).material;
}
}
if ((Object)(object)val2 != (Object)null)
{
Color c = SampleMaterialColor(val2);
if (HasValidRgb(c) && !IsNearWhite(c))
{
return MakeReadable(c);
}
}
}
}
catch
{
}
try
{
SkinnedMeshRenderer val3 = (((Object)(object)pinger != (Object)null) ? pinger.character : null)?.refs?.mainRenderer;
if ((Object)(object)val3 != (Object)null)
{
Material val4 = ((Renderer)val3).sharedMaterial ?? ((Renderer)val3).material;
if ((Object)(object)val4 != (Object)null)
{
Color c2 = SampleMaterialColor(val4);
if (HasValidRgb(c2) && !IsNearWhite(c2))
{
return MakeReadable(c2);
}
}
}
}
catch
{
}
return Color.white;
}
private static bool TryGetPlayerSkinColor(Character? character, out Color color)
{
//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_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: 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_011d: Unknown result type (might be due to invalid IL or missing references)
color = Color.white;
if ((Object)(object)character?.refs?.customization == (Object)null)
{
return false;
}
CharacterCustomization customization = character.refs.customization;
try
{
color = customization.PlayerColor;
if (HasValidRgb(color))
{
return true;
}
}
catch
{
}
try
{
CustomizationOption[] array = (((Object)(object)Singleton<Customization>.Instance != (Object)null) ? Singleton<Customization>.Instance.skins : null);
if (array == null || array.Length == 0)
{
return false;
}
Player val = null;
try
{
if ((Object)(object)customization.view != (Object)null)
{
val = customization.view.Owner;
}
}
catch
{
}
if (val == null)
{
try
{
if ((Object)(object)character.view != (Object)null)
{
val = character.view.Owner;
}
}
catch
{
}
}
if (val == null)
{
return false;
}
CharacterCustomizationData customizationData = CharacterCustomization.GetCustomizationData(val);
if (customizationData == null)
{
return false;
}
int currentSkin = customizationData.currentSkin;
if (currentSkin < 0 || currentSkin >= array.Length)
{
return false;
}
CustomizationOption val2 = array[currentSkin];
if ((Object)(object)val2 == (Object)null)
{
return false;
}
color = val2.color;
return HasValidRgb(color);
}
catch
{
return false;
}
}
private static Color SampleMaterialColor(Material mat)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
if (mat.HasProperty("_Color"))
{
return mat.GetColor("_Color");
}
if (mat.HasProperty("_BaseColor"))
{
return mat.GetColor("_BaseColor");
}
return mat.color;
}
private static bool HasValidRgb(Color c)
{
//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)
if (!float.IsNaN(c.r) && !float.IsNaN(c.g))
{
return !float.IsNaN(c.b);
}
return false;
}
private static bool IsNearWhite(Color c)
{
//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)
if (c.r > 0.92f && c.g > 0.92f)
{
return c.b > 0.92f;
}
return false;
}
private static Color MakeReadable(Color c)
{
//IL_000c: 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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_0085: Unknown result type (might be due to invalid IL or missing references)
c.a = 1f;
float num = c.r * 0.299f + c.g * 0.587f + c.b * 0.114f;
if (float.IsNaN(num))
{
return Color.white;
}
if (num < 0.12f)
{
float num2 = 0.12f / Mathf.Max(num, 0.001f);
c.r = Mathf.Clamp01(c.r * num2);
c.g = Mathf.Clamp01(c.g * num2);
c.b = Mathf.Clamp01(c.b * num2);
}
return c;
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "youxia173.BetterPingDistance";
public const string PLUGIN_NAME = "BetterPingDistance";
public const string PLUGIN_VERSION = "1.2.0";
public const string PLUGIN_AUTHOR = "youxia173";
}
}
namespace BetterPingDistance.Patches
{
[HarmonyPatch(typeof(GUIManager))]
internal static class GUIManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void Start_Postfix(GUIManager __instance)
{
Plugin.PDM.Initialize();
}
[HarmonyPatch("LateUpdate")]
[HarmonyPostfix]
private static void LateUpdate_Postfix(GUIManager __instance)
{
if (!Plugin.PDM.isInitialized)
{
Plugin.PDM.Initialize();
}
}
[HarmonyPatch("OnDestroy")]
[HarmonyPostfix]
private static void OnDestroy_Postfix(GUIManager __instance)
{
Plugin.PDM.OnDestroy();
}
}
[HarmonyPatch(typeof(PointPinger))]
internal static class PointPingerPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void Awake_Postfix(PointPinger __instance)
{
if (!Plugin.PDM.isInitialized)
{
Plugin.PDM.Initialize();
}
}
[HarmonyPatch("ReceivePoint_Rpc")]
[HarmonyPostfix]
private static void ReceivePoint_Rpc_Postfix(PointPinger __instance, Vector3 point, Vector3 hitNormal)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!Plugin.PDM.isInitialized)
{
Plugin.PDM.Initialize();
}
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.pingInstance == (Object)null))
{
Vector3 val = hitNormal;
if (((Vector3)(ref val)).sqrMagnitude > 1E-08f)
{
val = ((Vector3)(ref val)).normalized;
}
Vector3 position = __instance.pingInstance.transform.position + val * 0.15f;
Plugin.PDM.CreateInstance(__instance, position);
}
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"BetterPingDistance Postfix failed: {arg}");
}
}
}
}