using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("PEAKCoordinates")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAKCoordinates")]
[assembly: AssemblyTitle("PEAKCoordinates")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("PEAKCoordinates", "PEAK Coordinates", "1.0.0")]
public class UnityCoordinatesPlugin : BaseUnityPlugin
{
private ConfigEntry<KeyCode> toggleKey;
private ConfigEntry<float> updateRate;
private ConfigEntry<int> fontSize;
private ConfigEntry<bool> showRotation;
private ConfigEntry<bool> showVelocity;
private ConfigEntry<bool> showSpeed;
private ConfigEntry<bool> showMaxSpeed;
private ConfigEntry<float> positionToMetersMultiplier;
private ConfigEntry<string> targetGameObjectName;
private ConfigEntry<bool> enableMod;
private void Awake()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
InitializeConfig();
if (enableMod.Value)
{
GameObject val = new GameObject("UnityCoordinatesManager");
Object.DontDestroyOnLoad((Object)(object)val);
CoordinatesComponent coordinatesComponent = val.AddComponent<CoordinatesComponent>();
coordinatesComponent.Initialize(toggleKey.Value, updateRate.Value, fontSize.Value, showRotation.Value, showVelocity.Value, showSpeed.Value, showMaxSpeed.Value, positionToMetersMultiplier.Value, targetGameObjectName.Value);
}
}
private void InitializeConfig()
{
enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, (ConfigDescription)null);
toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybindings", "ToggleKey", (KeyCode)106, (ConfigDescription)null);
updateRate = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "UpdateRate", 10f, (ConfigDescription)null);
fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "FontSize", 18, (ConfigDescription)null);
targetGameObjectName = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "TargetGameObjectName", "MainCamera", (ConfigDescription)null);
showRotation = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "ShowRotation", true, (ConfigDescription)null);
showVelocity = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "ShowVelocity", true, (ConfigDescription)null);
showSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "ShowSpeed", true, (ConfigDescription)null);
showMaxSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "ShowMaxSpeed", true, (ConfigDescription)null);
positionToMetersMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Conversion", "PositionToMetersMultiplier", 1.59f, (ConfigDescription)null);
}
}
public class CoordinatesComponent : MonoBehaviour
{
private KeyCode toggleKey;
private float updateRate;
private int fontSize;
private bool showRotation;
private bool showVelocity;
private bool showSpeed;
private bool showMaxSpeed;
private float positionToMetersMultiplier;
private string targetGameObjectName;
private bool _showCoordinates = false;
private GameObject _canvasGO;
private TextMeshProUGUI _coordinateText;
private Image _backgroundPanel;
private float _lastUpdateTime = 0f;
private bool _uiCreated = false;
private Transform _targetTransform;
private Character _targetCharacter;
private Vector3 _lastPosition;
private bool _hasLastPosition = false;
private Vector3 _currentVelocity;
private bool _useCharacterVelocity = true;
private float _maxSpeed = 0f;
public void Initialize(KeyCode tk, float ur, int fs, bool rot, bool vel, bool spd, bool maxSpd, float posMultiplier, string targetName)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
toggleKey = tk;
updateRate = ur;
fontSize = fs;
showRotation = rot;
showVelocity = vel;
showSpeed = spd;
showMaxSpeed = maxSpd;
positionToMetersMultiplier = posMultiplier;
targetGameObjectName = targetName;
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: 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)
_targetTransform = null;
_targetCharacter = null;
_lastPosition = Vector3.zero;
_hasLastPosition = false;
_currentVelocity = Vector3.zero;
_maxSpeed = 0f;
if ((Object)(object)_canvasGO != (Object)null)
{
_canvasGO.SetActive(_showCoordinates);
}
if (_showCoordinates)
{
TryInitializeTarget();
}
}
private void Update()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(toggleKey))
{
if (!_uiCreated)
{
CreateCoordinateUI();
}
_showCoordinates = !_showCoordinates;
if ((Object)(object)_canvasGO != (Object)null)
{
_canvasGO.SetActive(_showCoordinates);
}
if (_showCoordinates)
{
TryInitializeTarget();
}
}
if (_showCoordinates && _uiCreated && Time.time - _lastUpdateTime >= 1f / updateRate)
{
UpdateCoordinateText();
_lastUpdateTime = Time.time;
}
}
private void TryInitializeTarget()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_0061: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_targetTransform != (Object)null))
{
GameObject val = GameObject.Find(targetGameObjectName);
if ((Object)(object)val != (Object)null)
{
_targetTransform = val.transform;
_targetCharacter = FindTargetCharacter();
_lastPosition = _targetTransform.position;
_hasLastPosition = true;
_currentVelocity = Vector3.zero;
_maxSpeed = 0f;
}
}
}
private Character FindTargetCharacter()
{
Character[] array = Object.FindObjectsOfType<Character>();
Character[] array2 = array;
foreach (Character val in array2)
{
if (val.IsLocal)
{
return val;
}
}
return (array.Length != 0) ? array[0] : null;
}
private void CreateCoordinateUI()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_006d: 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_008f: Expected O, but got Unknown
//IL_00cd: 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)
//IL_0100: 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_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Expected O, but got Unknown
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
if (_uiCreated)
{
return;
}
_canvasGO = new GameObject("UnityCoordinatesCanvas");
Object.DontDestroyOnLoad((Object)(object)_canvasGO);
Canvas val = _canvasGO.AddComponent<Canvas>();
val.renderMode = (RenderMode)0;
val.sortingOrder = 1000;
CanvasScaler val2 = _canvasGO.AddComponent<CanvasScaler>();
val2.uiScaleMode = (ScaleMode)1;
val2.referenceResolution = new Vector2(1920f, 1080f);
_canvasGO.AddComponent<GraphicRaycaster>();
GameObject val3 = new GameObject("CoordinatePanel");
val3.transform.SetParent(_canvasGO.transform, false);
_backgroundPanel = val3.AddComponent<Image>();
((Graphic)_backgroundPanel).color = new Color(0f, 0f, 0f, 0.75f);
RectTransform component = val3.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0f);
component.anchorMax = new Vector2(0.5f, 0f);
component.anchoredPosition = new Vector2(0f, 40f);
component.sizeDelta = new Vector2(400f, 80f);
GameObject val4 = new GameObject("CoordinateText");
val4.transform.SetParent(val3.transform, false);
_coordinateText = val4.AddComponent<TextMeshProUGUI>();
TMP_FontAsset val5 = null;
try
{
val5 = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "DarumaDropOne-Regular SDF"));
}
catch
{
}
if ((Object)(object)val5 == (Object)null)
{
try
{
val5 = Resources.GetBuiltinResource<TMP_FontAsset>("LiberationSans SDF.asset");
}
catch
{
}
}
if ((Object)(object)val5 == (Object)null)
{
val5 = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().FirstOrDefault();
}
((TMP_Text)_coordinateText).font = val5;
((TMP_Text)_coordinateText).fontSize = fontSize;
((Graphic)_coordinateText).color = Color.white;
((TMP_Text)_coordinateText).alignment = (TextAlignmentOptions)514;
((TMP_Text)_coordinateText).text = "X: 0.00 Y: 0.00 Z: 0.00";
((TMP_Text)_coordinateText).enableAutoSizing = true;
((TMP_Text)_coordinateText).fontSizeMin = 10f;
((TMP_Text)_coordinateText).fontSizeMax = fontSize + 4;
RectTransform component2 = val4.GetComponent<RectTransform>();
component2.anchorMin = Vector2.zero;
component2.anchorMax = Vector2.one;
component2.offsetMin = new Vector2(10f, 5f);
component2.offsetMax = new Vector2(-10f, -5f);
_canvasGO.SetActive(false);
_uiCreated = true;
}
private void UpdateVelocity()
{
//IL_006d: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: 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_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_targetTransform == (Object)null)
{
return;
}
if ((Object)(object)_targetCharacter != (Object)null && _useCharacterVelocity)
{
try
{
_currentVelocity = _targetCharacter.data.avarageVelocity;
}
catch
{
_useCharacterVelocity = false;
}
}
if (!_useCharacterVelocity)
{
Vector3 position = _targetTransform.position;
if (!_hasLastPosition)
{
_lastPosition = position;
_hasLastPosition = true;
_currentVelocity = Vector3.zero;
}
else
{
float num = Mathf.Max(Time.deltaTime, 1f / 60f);
_currentVelocity = (position - _lastPosition) / num;
_lastPosition = position;
}
}
float magnitude = ((Vector3)(ref _currentVelocity)).magnitude;
if (magnitude > _maxSpeed)
{
_maxSpeed = magnitude;
}
}
private void UpdateCoordinateText()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_coordinateText == (Object)null || (Object)(object)_targetTransform == (Object)null)
{
((TMP_Text)_coordinateText).text = "GameObject '" + targetGameObjectName + "' unavailable";
return;
}
Vector3 position = _targetTransform.position;
string text = $"X: {position.x:F2} Y: {position.y:F2} Z: {position.z:F2}";
UpdateVelocity();
if (showVelocity)
{
text += $"\nVel X: {_currentVelocity.x:F2} Y: {_currentVelocity.y:F2} Z: {_currentVelocity.z:F2}";
}
if (showSpeed)
{
float num = ((Vector3)(ref _currentVelocity)).magnitude * positionToMetersMultiplier;
text += $"\nSpeed: {num:F2} m/s ({num * 3.6f:F1} km/h)";
}
if (showMaxSpeed)
{
float num2 = _maxSpeed * positionToMetersMultiplier;
text += $"\nMax Speed: {num2:F2} m/s ({num2 * 3.6f:F1} km/h)";
}
if (showRotation)
{
Vector3 eulerAngles = _targetTransform.eulerAngles;
text += $"\nPitch: {eulerAngles.x:F1} Yaw: {eulerAngles.y:F1} Roll: {eulerAngles.z:F1}";
}
((TMP_Text)_coordinateText).text = text;
}
}