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 BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ChronoCompassGPS;
[BepInPlugin("cstei.chronocompassgps", "ChronoCompassGPS", "1.0.0")]
public class ChronoCompassGPSPlugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static ConfigEntry<bool> EnableGPS;
internal static ConfigEntry<float> ViewDistance;
internal static ConfigEntry<bool> ShowDecimal;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
EnableGPS = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable GPS", true, "Show lat/lon coordinates above chronocompasses");
ViewDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "View Distance", 3f, "Max distance from player to show text.");
ShowDecimal = ((BaseUnityPlugin)this).Config.Bind<bool>("Format", "Decimal Degrees", true, "Show coordinates as decimal degrees (e.g. 31.5°) instead of deg/min (e.g. 31°30')");
Harmony.CreateAndPatchAll(typeof(ChronoCompassPatches), "cstei.chronocompassgps");
Log.LogInfo((object)string.Format("ChronoCompassGPS v{0} loaded", "1.0.0"));
}
private void Update()
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
KeyValuePair<ShipItemCompass, TextMesh>[] array = ChronoCompassPatches.TextMeshes.ToArray();
for (int i = 0; i < array.Length; i++)
{
KeyValuePair<ShipItemCompass, TextMesh> keyValuePair = array[i];
ShipItemCompass key = keyValuePair.Key;
TextMesh value = keyValuePair.Value;
if ((Object)(object)key == (Object)null || (Object)(object)value == (Object)null || !((Component)value).gameObject.activeInHierarchy || (Object)(object)((PickupableItem)key).held != (Object)null)
{
continue;
}
try
{
float num = Vector3.Distance(((Component)Refs.observerMirror).transform.position, ((Component)key).transform.position);
if (num > ViewDistance.Value)
{
((Component)value).gameObject.SetActive(false);
}
}
catch
{
}
}
}
internal static string FormatDMS(float lat, float lon)
{
string text = ((lat >= 0f) ? "N" : "S");
string text2 = ((lon >= 0f) ? "E" : "W");
lat = Math.Abs(lat);
lon = Math.Abs(lon);
int num = (int)lat;
int num2 = (int)((lat - (float)num) * 60f);
int num3 = (int)lon;
int num4 = (int)((lon - (float)num3) * 60f);
return $"Lat: {num}°{num2}'{text} / Lon: {num3}°{num4}'{text2}";
}
}
internal static class PluginInfo
{
public const string GUID = "cstei.chronocompassgps";
public const string NAME = "ChronoCompassGPS";
public const string VERSION = "1.0.0";
}
internal class ChronoCompassPatches
{
internal static Dictionary<ShipItemCompass, TextMesh> TextMeshes = new Dictionary<ShipItemCompass, TextMesh>();
[HarmonyPatch(typeof(ShipItemCompass), "OnLoad")]
[HarmonyPrefix]
public static void AddTextMesh(ShipItemCompass __instance)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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)
if (!(((ShipItem)__instance).name != "chronocompass"))
{
Transform val = Object.Instantiate<Transform>(((Component)DayLogs.instance).transform.parent.GetChild(0).GetChild(1));
((Object)val).name = "chronogps_text";
val.SetParent(((Component)__instance).transform);
((Component)val).gameObject.layer = 0;
val.localEulerAngles = new Vector3(0f, 0f, 0f);
val.localPosition = new Vector3(0f, 0.03f, 0f);
TextMesh component = ((Component)val).GetComponent<TextMesh>();
component.color = Color32.op_Implicit(new Color32((byte)219, (byte)214, (byte)201, (byte)204));
component.fontSize = 50;
component.fontStyle = (FontStyle)0;
component.anchor = (TextAnchor)7;
component.lineSpacing = 0.7f;
((Component)component).gameObject.SetActive(false);
TextMeshes[__instance] = component;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ShipItemCompass), "ExtraLateUpdate")]
public static void UpdateText(ShipItemCompass __instance)
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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_00cf: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
if (!ChronoCompassGPSPlugin.EnableGPS.Value || !GameState.playing || GameState.currentlyLoading || GameState.loadingBoatLocalItems || ((ShipItem)__instance).name != "chronocompass" || !TextMeshes.TryGetValue(__instance, out var value))
{
return;
}
if (!((ShipItem)__instance).sold || ((Component)__instance).gameObject.layer == 5 || (Object)(object)((ShipItem)__instance).currentActualBoat == (Object)null)
{
((Component)value).gameObject.SetActive(false);
return;
}
Vector3 position = ((Component)Refs.observerMirror).transform.position;
Vector3 position2 = ((Component)__instance).transform.position;
if (Vector3.Distance(position, position2) > ChronoCompassGPSPlugin.ViewDistance.Value)
{
((Component)value).gameObject.SetActive(false);
return;
}
float num = (((Object)(object)((PickupableItem)__instance).held != (Object)null) ? 0f : Vector3.SignedAngle(-((Component)__instance).transform.forward, position - position2, Vector3.up));
((Component)value).transform.localEulerAngles = new Vector3(0f, num, 0f);
value.fontSize = (((Object)(object)((PickupableItem)__instance).held != (Object)null) ? 30 : 50);
Vector3 globeCoords = FloatingOriginManager.instance.GetGlobeCoords(((Component)__instance).transform);
float z = globeCoords.z;
float x = globeCoords.x;
if (ChronoCompassGPSPlugin.ShowDecimal.Value)
{
value.text = $"Lat: {z:F1}° / Lon: {x:F1}°";
}
else
{
value.text = ChronoCompassGPSPlugin.FormatDMS(z, x);
}
((Component)value).gameObject.SetActive(true);
}
}