using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsDebugTools;
using EquinoxsModUtils;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoNorth")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoNorth")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cd726907-a77f-40f4-9ce0-2003ddeb347f")]
[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 AutoNorth;
public class AutoNorthConfig
{
internal static ConfigEntry<KeyboardShortcut> toggleShortcut;
public static void CreateConfigEntries(BaseUnityPlugin plugin)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
toggleShortcut = plugin.Config.Bind<KeyboardShortcut>("General", "Toggle Shortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "The shortcut to press to toggle auto-rotation");
}
}
[BepInPlugin("com.equinox.AutoNorth", "AutoNorth", "1.0.0")]
public class AutoNorthPlugin : BaseUnityPlugin
{
internal const string MyGUID = "com.equinox.AutoNorth";
private const string PluginName = "AutoNorth";
private const string VersionString = "1.0.0";
private static readonly Harmony Harmony = new Harmony("com.equinox.AutoNorth");
internal static ManualLogSource Log = new ManualLogSource("AutoNorth");
private HUDCameraManager camera;
private bool buildingLastFrame;
private bool enabled = true;
private void Awake()
{
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: AutoNorth, VersionString: 1.0.0 is loading...");
AutoNorthConfig.CreateConfigEntries((BaseUnityPlugin)(object)this);
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: AutoNorth, VersionString: 1.0.0 has loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void Update()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)camera == (Object)null)
{
TryCacheCamera();
}
bool flag = IsPlayerBuilding();
if (flag && !buildingLastFrame)
{
SetToNorth();
}
buildingLastFrame = flag;
KeyboardShortcut value = AutoNorthConfig.toggleShortcut.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
enabled = !enabled;
Logging.Log("Updates", $"Toggled auto-rotation to '{enabled}'");
}
}
private void TryCacheCamera()
{
HUDCameraManager[] array = Object.FindObjectsOfType<HUDCameraManager>();
if (array.Length != 0)
{
camera = array[0];
Logging.Log("Updates", "Cached Camera");
}
}
private bool IsPlayerBuilding()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)camera == (Object)null)
{
return false;
}
return ((Player)Reflection.GetPrivateProperty<HUDCameraManager>(new FieldSearchInfo<HUDCameraManager>("Player", camera, false, false))).InteractionState.PlacingAnything;
}
private void SetToNorth()
{
if ((Object)(object)camera == (Object)null)
{
Logging.Log("Updates", "Didn't rotate as camera is null");
return;
}
if (!enabled)
{
Logging.Log("Updates", "Didn't rotate as auto-rotation is disabled");
return;
}
Reflection.SetPrivateField<HUDCameraManager>(new FieldSearchInfo<HUDCameraManager>("TargetRotationDegrees", camera, false, false), (object)0);
Logging.Log("Updates", "Set camera to north");
}
}