using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("楠橘MOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dd1a6393-cd15-48a8-9b55-974feb1cf717")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PingMarkerMod;
[BepInPlugin("com.pingmarkermod.simple", "Ping Marker Mod (简易版)", "1.0.0")]
public class PingMarkerMod : BaseUnityPlugin
{
public class PingMarkerInfo
{
public int playerViewId;
public GameObject markerObject;
public LineRenderer rayLine;
public Vector3 markerPosition;
public Vector3 playerPosition;
public float timeCreated;
public string playerName;
}
private float rayWidth = 0.03f;
private float markerSize = 0.2f;
private float markerDuration = 3f;
private Dictionary<int, PingMarkerInfo> activeMarkers = new Dictionary<int, PingMarkerInfo>();
private PointPing[] cachedPingMarkers = (PointPing[])(object)new PointPing[0];
private float lastCacheUpdateTime = 0f;
private const float CACHE_UPDATE_INTERVAL = 1f;
private Harmony harmony;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
harmony = new Harmony("com.pingmarkermod.simple");
harmony.PatchAll();
Debug.Log((object)"PingMarkerMod: 简易版模组加载成功!");
}
private void OnDestroy()
{
CleanupAllMarkers();
if (harmony != null)
{
harmony.UnpatchAll((string)null);
}
}
private void CleanupAllMarkers()
{
foreach (KeyValuePair<int, PingMarkerInfo> activeMarker in activeMarkers)
{
PingMarkerInfo value = activeMarker.Value;
if ((Object)(object)value.markerObject != (Object)null)
{
Object.Destroy((Object)(object)value.markerObject);
}
if ((Object)(object)value.rayLine != (Object)null)
{
Object.Destroy((Object)(object)((Component)value.rayLine).gameObject);
}
}
activeMarkers.Clear();
}
private void Update()
{
try
{
int frameCount = Time.frameCount;
UpdateAllRayDisplays();
if (frameCount % 2 == 0)
{
UpdateCachedObjects();
DetectAndCreatePingMarkers();
}
if (frameCount % 60 == 0)
{
CleanupExpiredMarkers();
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: Update方法执行时出错: " + ex.Message));
}
}
private void UpdateCachedObjects()
{
try
{
if (Time.time - lastCacheUpdateTime > 1f)
{
float num = ((activeMarkers.Count > 0) ? 1f : 2f);
if (Time.time - lastCacheUpdateTime > num)
{
cachedPingMarkers = Object.FindObjectsByType<PointPing>((FindObjectsInactive)0, (FindObjectsSortMode)0);
lastCacheUpdateTime = Time.time;
Debug.Log((object)$"PingMarkerMod: 更新缓存,找到 {cachedPingMarkers.Length} 个Ping标记");
}
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 更新缓存时出错: " + ex.Message));
}
}
private void DetectAndCreatePingMarkers()
{
//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_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_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
try
{
if (cachedPingMarkers == null || cachedPingMarkers.Length == 0)
{
return;
}
int num = Math.Min(cachedPingMarkers.Length, 10);
int num2 = 0;
PointPing[] array = cachedPingMarkers;
foreach (PointPing val in array)
{
if (num2 >= num)
{
break;
}
if ((Object)(object)val == (Object)null || (Object)(object)val.pointPinger == (Object)null || (Object)(object)val.pointPinger.character == (Object)null || (Object)(object)((MonoBehaviourPun)val.pointPinger.character).photonView == (Object)null)
{
continue;
}
Character character = val.pointPinger.character;
PhotonView photonView = ((MonoBehaviourPun)character).photonView;
if (!((Object)(object)character == (Object)null) && !((Object)(object)photonView == (Object)null))
{
int viewID = photonView.ViewID;
Vector3 position = ((Component)val).transform.position;
Vector3 center = character.Center;
string playerName = character.characterName ?? "未知玩家";
if (activeMarkers.ContainsKey(viewID))
{
UpdateExistingMarker(activeMarkers[viewID], position, center);
}
else
{
CreateNewPingMarker(viewID, position, center, playerName);
}
num2++;
}
}
if (num2 > 0)
{
Debug.Log((object)$"PingMarkerMod: 处理了 {num2} 个Ping标记");
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 检测游戏Ping标记时出错: " + ex.Message));
}
}
private void CreateNewPingMarker(int playerViewId, Vector3 markerPosition, Vector3 playerPosition, string playerName)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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_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_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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)
try
{
PingMarkerInfo pingMarkerInfo = new PingMarkerInfo();
pingMarkerInfo.playerViewId = playerViewId;
pingMarkerInfo.markerPosition = markerPosition;
pingMarkerInfo.playerPosition = playerPosition;
pingMarkerInfo.playerName = playerName;
pingMarkerInfo.timeCreated = Time.time;
pingMarkerInfo.markerObject = GameObject.CreatePrimitive((PrimitiveType)0);
if ((Object)(object)pingMarkerInfo.markerObject != (Object)null)
{
((Object)pingMarkerInfo.markerObject).name = $"PingMarker_{playerViewId}";
pingMarkerInfo.markerObject.transform.position = markerPosition;
pingMarkerInfo.markerObject.transform.localScale = Vector3.one * markerSize;
SetupMarkerRenderer(pingMarkerInfo.markerObject);
}
pingMarkerInfo.rayLine = CreateRayLine(playerPosition, markerPosition);
activeMarkers[playerViewId] = pingMarkerInfo;
Debug.Log((object)("PingMarkerMod: 为玩家 " + playerName + " 创建Ping标记"));
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 创建Ping标记时出错: " + ex.Message));
}
}
private void UpdateExistingMarker(PingMarkerInfo markerInfo, Vector3 markerPosition, Vector3 playerPosition)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: 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_0065: Unknown result type (might be due to invalid IL or missing references)
try
{
markerInfo.markerPosition = markerPosition;
markerInfo.playerPosition = playerPosition;
markerInfo.timeCreated = Time.time;
if ((Object)(object)markerInfo.markerObject != (Object)null)
{
markerInfo.markerObject.transform.position = markerPosition;
}
if ((Object)(object)markerInfo.rayLine != (Object)null)
{
markerInfo.rayLine.SetPosition(0, playerPosition);
markerInfo.rayLine.SetPosition(1, markerPosition);
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 更新标记时出错: " + ex.Message));
}
}
private LineRenderer CreateRayLine(Vector3 startPos, Vector3 endPos)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
try
{
GameObject val = new GameObject("PingRayLine");
if ((Object)(object)val == (Object)null)
{
return null;
}
LineRenderer val2 = val.AddComponent<LineRenderer>();
if ((Object)(object)val2 == (Object)null)
{
return null;
}
val2.startWidth = rayWidth;
val2.endWidth = rayWidth * 0.3f;
val2.positionCount = 2;
val2.SetPosition(0, startPos);
val2.SetPosition(1, endPos);
val2.useWorldSpace = true;
Shader val3 = Shader.Find("Sprites/Default");
if ((Object)(object)val3 != (Object)null)
{
((Renderer)val2).material = new Material(val3);
}
val2.startColor = Color.yellow;
val2.endColor = Color.yellow;
((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val2).receiveShadows = false;
return val2;
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 创建射线时出错: " + ex.Message));
return null;
}
}
private void SetupMarkerRenderer(GameObject markerObject)
{
//IL_0055: 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_004d: Expected O, but got Unknown
try
{
if ((Object)(object)markerObject == (Object)null)
{
return;
}
Renderer component = markerObject.GetComponent<Renderer>();
if ((Object)(object)component != (Object)null)
{
Shader val = Shader.Find("Sprites/Default");
if ((Object)(object)val != (Object)null)
{
component.material = new Material(val);
}
component.material.color = Color.yellow;
component.shadowCastingMode = (ShadowCastingMode)0;
component.receiveShadows = false;
}
Collider component2 = markerObject.GetComponent<Collider>();
if ((Object)(object)component2 != (Object)null)
{
Object.Destroy((Object)(object)component2);
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 设置标记渲染器时出错: " + ex.Message));
}
}
private void UpdateAllRayDisplays()
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
try
{
int frameCount = Time.frameCount;
foreach (KeyValuePair<int, PingMarkerInfo> activeMarker in activeMarkers)
{
PingMarkerInfo value = activeMarker.Value;
if ((Object)(object)value.rayLine != (Object)null)
{
value.rayLine.SetPosition(0, value.playerPosition);
value.rayLine.SetPosition(1, value.markerPosition);
}
if (frameCount % 10 == 0 && (Object)(object)value.markerObject != (Object)null)
{
value.markerObject.transform.position = value.markerPosition;
}
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 更新射线显示时出错: " + ex.Message));
}
}
private void CleanupExpiredMarkers()
{
try
{
List<int> list = new List<int>();
float time = Time.time;
foreach (KeyValuePair<int, PingMarkerInfo> activeMarker in activeMarkers)
{
PingMarkerInfo value = activeMarker.Value;
if (time - value.timeCreated > markerDuration)
{
list.Add(activeMarker.Key);
}
}
foreach (int item in list)
{
if (activeMarkers.ContainsKey(item))
{
PingMarkerInfo pingMarkerInfo = activeMarkers[item];
if ((Object)(object)pingMarkerInfo.markerObject != (Object)null)
{
Object.Destroy((Object)(object)pingMarkerInfo.markerObject);
}
if ((Object)(object)pingMarkerInfo.rayLine != (Object)null)
{
Object.Destroy((Object)(object)((Component)pingMarkerInfo.rayLine).gameObject);
}
activeMarkers.Remove(item);
Debug.Log((object)$"PingMarkerMod: 清理过期标记 (玩家ID: {item})");
}
}
}
catch (Exception ex)
{
Debug.LogError((object)("PingMarkerMod: 清理过期标记时出错: " + ex.Message));
}
}
}