using System;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using Sparroh.UI;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Altimeter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Altimeter")]
[assembly: AssemblyTitle("Altimeter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
public class AltimeterMod
{
private ConfigEntry<bool> enableAltimeterHUD;
private ConfigEntry<float> altimeterAnchorX;
private ConfigEntry<float> altimeterAnchorY;
private ConfigColor valueColor;
private HudHandle hud;
private const float RaycastMaxDistance = 1000f;
private readonly ConfigFile configFile;
private readonly Harmony harmony;
public static AltimeterMod Instance { get; private set; }
public bool IsActive
{
get
{
if (hud != null)
{
return hud.IsActive;
}
return false;
}
}
public Vector2 GetSize
{
get
{
//IL_0010: 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)
HudHandle obj = hud;
if (obj == null)
{
return Vector2.zero;
}
return obj.Size;
}
}
public AltimeterMod(ConfigFile configFile, Harmony harmony)
{
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
this.configFile = configFile;
this.harmony = harmony;
Instance = this;
enableAltimeterHUD = configFile.Bind<bool>("General", "EnableAltimeterHUD", true, "Enables the Altimeter HUD display showing player altitude above ground.");
enableAltimeterHUD.SettingChanged += OnEnableAltimeterHUDChanged;
altimeterAnchorX = configFile.Bind<float>("HUD Positioning", "AltimeterAnchorX", 0.06355292f, "X anchor position for Altimeter (0-1).");
altimeterAnchorY = configFile.Bind<float>("HUD Positioning", "AltimeterAnchorY", 0.2589327f, "Y anchor position for Altimeter (0-1).");
altimeterAnchorX.SettingChanged += OnAnchorChanged;
altimeterAnchorY.SettingChanged += OnAnchorChanged;
valueColor = ConfigColor.Bind(configFile, "Colors", "ValueColor", UIColors.Shamrock, "Rich-text value color for altitude (hex RRGGBB or #RRGGBB).");
}
public void UpdateHudVisibility()
{
if (hud != null)
{
hud.SetActive(enableAltimeterHUD.Value);
}
}
private void OnEnableAltimeterHUDChanged(object sender, EventArgs e)
{
if (!enableAltimeterHUD.Value && hud != null)
{
DestroyHud();
}
UpdateHudVisibility();
}
private void OnAnchorChanged(object sender, EventArgs e)
{
UpdateAnchors();
}
private void UpdateAnchors()
{
if (hud != null)
{
hud.SetAnchor(altimeterAnchorX.Value, altimeterAnchorY.Value);
}
}
private void CreateAltimeterHUD()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (hud == null)
{
hud = HudBuilder.Create("AltimeterHUD").ParentToReticle(true).Anchor(altimeterAnchorX.Value, altimeterAnchorY.Value)
.Pivot(new Vector2(0f, 0.5f))
.Size(300f, 25f, true)
.AddText("AltitudeText", -1f, (TextAlignmentOptions)513)
.Build();
if (hud != null)
{
HudRepositionClient.Register("sparroh.altimeter", "Altimeter", hud.Rect, altimeterAnchorX, altimeterAnchorY);
UpdateHudVisibility();
}
}
}
private void DestroyHud()
{
HudRepositionClient.Unregister("sparroh.altimeter");
if (hud != null)
{
hud.Destroy();
hud = null;
}
}
public void Update()
{
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
if (!enableAltimeterHUD.Value)
{
return;
}
if (hud == null)
{
CreateAltimeterHUD();
}
else if (hud.Primary != null && !((Object)(object)Player.LocalPlayer == (Object)null))
{
float num = CalculateAltitude();
if (num < 1.3f)
{
hud.Primary.Text = "On Ground";
}
else if (num >= 1000f)
{
hud.Primary.Text = "Too High";
}
else
{
hud.Primary.SetRich("Altitude", num, valueColor.Value, "m", "F1");
}
}
}
private float CalculateAltitude()
{
//IL_001d: 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_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_003c: 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_0059: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Player.LocalPlayer == (Object)null)
{
return 0f;
}
Vector3 val = ((Component)Player.LocalPlayer).transform.position + Vector3.up * 0.1f;
Vector3 down = Vector3.down;
RaycastHit[] array = Physics.RaycastAll(val, down, 1000f);
float num = float.MaxValue;
RaycastHit[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
RaycastHit val2 = array2[i];
if ((Object)(object)((Component)((RaycastHit)(ref val2)).collider).gameObject != (Object)(object)((Component)Player.LocalPlayer).gameObject && !((RaycastHit)(ref val2)).collider.isTrigger)
{
num = Mathf.Min(num, ((RaycastHit)(ref val2)).distance);
}
}
if (!(num < float.MaxValue))
{
return 1000f;
}
return num;
}
public void OnDestroy()
{
DestroyHud();
}
}
public static class HudRepositionClient
{
private const string ApiTypeName = "HudRepositionAPI";
private static Type _apiType;
private static MethodInfo _register;
private static MethodInfo _unregister;
private static bool _available;
public static bool IsAvailable
{
get
{
EnsureResolved();
return _available;
}
}
public static void Register(string id, string displayName, RectTransform rect, ConfigEntry<float> anchorX, ConfigEntry<float> anchorY)
{
if (!_available)
{
EnsureResolved(force: true);
}
if (!_available || (Object)(object)rect == (Object)null || anchorX == null || anchorY == null)
{
return;
}
try
{
_register.Invoke(null, new object[5] { id, displayName, rect, anchorX, anchorY });
}
catch (Exception ex)
{
Debug.LogWarning((object)("[HudRepositionClient] Register failed: " + (ex.InnerException?.Message ?? ex.Message)));
}
}
public static void Unregister(string id)
{
if (!_available)
{
EnsureResolved(force: true);
}
if (!_available || string.IsNullOrEmpty(id))
{
return;
}
try
{
_unregister.Invoke(null, new object[1] { id });
}
catch (Exception)
{
}
}
private static void EnsureResolved(bool force = false)
{
if (_available && !force)
{
return;
}
_apiType = null;
_register = null;
_unregister = null;
_available = false;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
Type type = assembly.GetType("HudRepositionAPI", throwOnError: false);
if (type != null)
{
_apiType = type;
break;
}
}
catch
{
}
}
if (_apiType == null)
{
return;
}
MethodInfo[] methods = _apiType.GetMethods(BindingFlags.Static | BindingFlags.Public);
foreach (MethodInfo methodInfo in methods)
{
ParameterInfo[] parameters = methodInfo.GetParameters();
if (methodInfo.Name == "Register" && parameters.Length == 5 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(string) && typeof(RectTransform).IsAssignableFrom(parameters[2].ParameterType))
{
_register = methodInfo;
}
else if (methodInfo.Name == "Unregister" && parameters.Length == 1 && parameters[0].ParameterType == typeof(string))
{
_unregister = methodInfo;
}
}
_available = _register != null && _unregister != null;
}
}
[BepInPlugin("sparroh.altimeter", "Altimeter", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class SparrohPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.altimeter";
public const string PluginName = "Altimeter";
public const string PluginVersion = "1.0.0";
internal static ManualLogSource Logger;
private Harmony harmony;
private AltimeterMod altimeter;
private void Awake()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
try
{
harmony = new Harmony("sparroh.altimeter");
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to create Harmony instance: " + ex.Message));
return;
}
ConfigFile configFile = ((BaseUnityPlugin)this).Config;
try
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.altimeter.cfg");
fileSystemWatcher.Changed += delegate
{
configFile.Reload();
};
fileSystemWatcher.EnableRaisingEvents = true;
}
catch (Exception ex2)
{
Logger.LogWarning((object)("Failed to set up config watcher: " + ex2.Message));
}
try
{
altimeter = new AltimeterMod(configFile, harmony);
}
catch (Exception ex3)
{
Logger.LogError((object)("Failed to initialize Altimeter: " + ex3.Message));
}
try
{
harmony.PatchAll();
}
catch (Exception ex4)
{
Logger.LogError((object)("Failed to apply Harmony patches: " + ex4.Message));
}
Logger.LogInfo((object)"Altimeter loaded successfully.");
}
private void Update()
{
try
{
if (altimeter != null)
{
altimeter.UpdateHudVisibility();
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error in Altimeter.UpdateHudVisibility(): " + ex.Message));
}
try
{
if (altimeter != null)
{
altimeter.Update();
}
}
catch (Exception ex2)
{
Logger.LogError((object)("Error in Altimeter.Update(): " + ex2.Message));
}
}
private void OnDestroy()
{
try
{
if (altimeter != null)
{
altimeter.OnDestroy();
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error in Altimeter.OnDestroy(): " + ex.Message));
}
try
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch (Exception ex2)
{
Logger.LogError((object)("Error unpatching Harmony: " + ex2.Message));
}
}
}
namespace Altimeter
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Altimeter";
public const string PLUGIN_NAME = "Altimeter";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}