using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using ExitGames.Client.Photon;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CheekyEntity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A location pinging mod for Cave Crawlers")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a065ddfc40f8d9b4d230d3268999a5b590612869")]
[assembly: AssemblyProduct("LocationPing")]
[assembly: AssemblyTitle("LocationPing")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 LocationPing
{
public class PingManager : MonoBehaviour
{
private const byte PING_EVENT_CODE = 220;
private const float PING_COOLDOWN = 2f;
private float _lastPingTime = -999f;
private Sprite _pingSprite;
private Action<EventData> _eventHandler;
private bool _subscribed = false;
private readonly Queue<(Vector3 pos, string name)> _pendingPings = new Queue<(Vector3, string)>();
public PingManager(IntPtr ptr)
: base(ptr)
{
}
private void OnDisable()
{
Unsubscribe();
}
private void OnDestroy()
{
Unsubscribe();
}
private void TrySubscribe()
{
if (!_subscribed && PhotonNetwork.NetworkingClient != null)
{
_eventHandler = DelegateSupport.ConvertDelegate<Action<EventData>>((Delegate)new Action<EventData>(OnPhotonEvent));
LoadBalancingClient networkingClient = PhotonNetwork.NetworkingClient;
networkingClient.EventReceived += _eventHandler;
_subscribed = true;
Plugin.Log.LogInfo((object)"[LocationPing] Subscribed to Photon events.");
}
}
private void Unsubscribe()
{
if (_subscribed)
{
if (PhotonNetwork.NetworkingClient != null && (Delegate)(object)_eventHandler != (Delegate)null)
{
LoadBalancingClient networkingClient = PhotonNetwork.NetworkingClient;
networkingClient.EventReceived -= _eventHandler;
}
_subscribed = false;
}
}
private void Update()
{
//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_0037: Unknown result type (might be due to invalid IL or missing references)
TrySubscribe();
lock (_pendingPings)
{
while (_pendingPings.Count > 0)
{
var (worldPos, senderName) = _pendingPings.Dequeue();
SpawnMarker(worldPos, senderName);
}
}
if (Input.GetMouseButtonDown(2) && PhotonNetwork.InRoom && !(Time.time - _lastPingTime < 2f))
{
TryPing();
}
}
private void TryPing()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Expected O, but got Unknown
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Expected O, but got Unknown
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
Camera val = Camera.main ?? Object.FindObjectOfType<Camera>();
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)"[LocationPing] No camera found.");
return;
}
Ray val2 = val.ScreenPointToRay(new Vector3((float)Screen.width * 0.5f, (float)Screen.height * 0.5f, 0f));
RaycastHit val3 = default(RaycastHit);
Vector3 val4 = (Physics.Raycast(val2, ref val3, 200f) ? ((RaycastHit)(ref val3)).point : ((Ray)(ref val2)).GetPoint(10f));
_lastPingTime = Time.time;
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
string text = $"{val4.x.ToString(invariantCulture)},{val4.y.ToString(invariantCulture)},{val4.z.ToString(invariantCulture)},{PhotonNetwork.LocalPlayer.ActorNumber}";
RaiseEventOptions val5 = new RaiseEventOptions
{
Receivers = (ReceiverGroup)1
};
PhotonNetwork.RaiseEvent((byte)220, Object.op_Implicit(text), val5, SendOptions.SendReliable);
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val6 = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("[LocationPing] Ping sent at ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<Vector3>(val4);
}
log.LogInfo(val6);
}
private void OnPhotonEvent(EventData photonEvent)
{
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
if (photonEvent.Code != 220)
{
return;
}
Object customData = photonEvent.CustomData;
string text = ((customData != null) ? customData.ToString() : null);
if (string.IsNullOrEmpty(text))
{
return;
}
string[] array = text.Split(',');
if (array.Length < 4)
{
return;
}
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
if (!float.TryParse(array[0], NumberStyles.Float, invariantCulture, out var result) || !float.TryParse(array[1], NumberStyles.Float, invariantCulture, out var result2) || !float.TryParse(array[2], NumberStyles.Float, invariantCulture, out var result3) || !int.TryParse(array[3], out var result4))
{
return;
}
string item = "Player";
if (PhotonNetwork.CurrentRoom != null)
{
Enumerator<int, Player> enumerator = PhotonNetwork.CurrentRoom.Players.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<int, Player> current = enumerator.Current;
if (current.Value.ActorNumber == result4)
{
item = (string.IsNullOrEmpty(current.Value.NickName) ? "Player" : current.Value.NickName);
break;
}
}
}
lock (_pendingPings)
{
_pendingPings.Enqueue((new Vector3(result, result2, result3), item));
}
}
private void SpawnMarker(Vector3 worldPos, string senderName)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//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_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0028: 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_006f: 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)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: 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_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Expected O, but got Unknown
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Expected O, but got Unknown
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = worldPos + Vector3.up * 0.4f;
GameObject val = new GameObject("PingMarker");
val.transform.position = position;
Canvas val2 = ((Il2CppObjectBase)val.AddComponent(Il2CppType.Of<Canvas>())).Cast<Canvas>();
val2.renderMode = (RenderMode)2;
val2.sortingOrder = 100;
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = new Vector2(200f, 200f);
((Transform)component).localScale = Vector3.one * 0.005f;
val.AddComponent(Il2CppType.Of<CanvasScaler>());
val.AddComponent(Il2CppType.Of<GraphicRaycaster>());
GameObject val3 = new GameObject("Icon");
val3.transform.SetParent(val.transform, false);
RectTransform val4 = ((Il2CppObjectBase)val3.AddComponent(Il2CppType.Of<RectTransform>())).Cast<RectTransform>();
val4.anchoredPosition = new Vector2(0f, 20f);
val4.sizeDelta = new Vector2(80f, 80f);
Image val5 = ((Il2CppObjectBase)val3.AddComponent(Il2CppType.Of<Image>())).Cast<Image>();
((Graphic)val5).color = new Color(0.2f, 0.85f, 1f, 1f);
if ((Object)(object)_pingSprite == (Object)null)
{
_pingSprite = FindSprite("UIFoldoutOpened");
}
if ((Object)(object)_pingSprite != (Object)null)
{
val5.sprite = _pingSprite;
}
GameObject val6 = new GameObject("Label");
val6.transform.SetParent(val.transform, false);
RectTransform val7 = ((Il2CppObjectBase)val6.AddComponent(Il2CppType.Of<RectTransform>())).Cast<RectTransform>();
val7.anchoredPosition = new Vector2(0f, -55f);
val7.sizeDelta = new Vector2(200f, 50f);
TextMeshProUGUI val8 = ((Il2CppObjectBase)val6.AddComponent(Il2CppType.Of<TextMeshProUGUI>())).Cast<TextMeshProUGUI>();
((TMP_Text)val8).text = senderName;
((TMP_Text)val8).fontSize = 24f;
((TMP_Text)val8).alignment = (TextAlignmentOptions)514;
((Graphic)val8).color = Color.white;
val.AddComponent(Il2CppType.Of<PingMarker>());
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val9 = new BepInExInfoLogInterpolatedStringHandler(40, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("[LocationPing] Marker spawned for '");
((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(senderName);
((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("' at ");
((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<Vector3>(worldPos);
}
log.LogInfo(val9);
}
private static Sprite FindSprite(string spriteName)
{
foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
{
if (((Object)item).name == spriteName)
{
return item;
}
}
return null;
}
}
public class PingMarker : MonoBehaviour
{
private const float LIFETIME = 8f;
private const float FADE_START = 6f;
private const float PULSE_END = 1f;
private float _elapsed = 0f;
private Vector3 _baseScale;
private Image _image;
private Text _label;
public PingMarker(IntPtr ptr)
: base(ptr)
{
}
private void Start()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
_baseScale = ((Component)this).transform.localScale;
_image = ((Component)this).GetComponentInChildren<Image>();
_label = ((Component)this).GetComponentInChildren<Text>();
}
private void Update()
{
//IL_0030: 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_0045: 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_0090: 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)
_elapsed += Time.deltaTime;
Camera main = Camera.main;
if ((Object)(object)main != (Object)null)
{
((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)main).transform.position);
}
if (_elapsed < 1f)
{
float num = _elapsed / 1f;
float num2 = 1f + 0.3f * Mathf.Sin(num * (float)Math.PI);
((Component)this).transform.localScale = _baseScale * num2;
}
else
{
((Component)this).transform.localScale = _baseScale;
}
if (_elapsed >= 6f)
{
float alpha = 1f - Mathf.Clamp01((_elapsed - 6f) / 2f);
SetAlpha(alpha);
}
if (_elapsed >= 8f)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
}
}
private void SetAlpha(float alpha)
{
//IL_0018: 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_002c: 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_005f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_image != (Object)null)
{
Color color = ((Graphic)_image).color;
color.a = alpha;
((Graphic)_image).color = color;
}
if ((Object)(object)_label != (Object)null)
{
Color color2 = ((Graphic)_label).color;
color2.a = alpha;
((Graphic)_label).color = color2;
}
}
}
[BepInPlugin("LocationPing", "LocationPing", "1.0.0")]
public class Plugin : BasePlugin
{
internal static ManualLogSource Log;
public override void Load()
{
Log = ((BasePlugin)this).Log;
Log.LogInfo((object)"LocationPing loaded. Middle-click to ping your location.");
ClassInjector.RegisterTypeInIl2Cpp<PingMarker>();
((BasePlugin)this).AddComponent<PingManager>();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "LocationPing";
public const string PLUGIN_NAME = "LocationPing";
public const string PLUGIN_VERSION = "1.0.0";
}
}