using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using CG; using CG.Game.Player; using CG.Input; using MelonLoader; using MelonLoader.Preferences; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using VoidCrewCompass; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(Mod), "Void Crew Compass", "1.0.0", "Mainsys", null)] [assembly: MelonGame(null, "Void Crew")] [assembly: AssemblyVersion("0.0.0.0")] [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; } } } namespace VoidCrewCompass { public static class CompassMath { public static double Wrap(double degrees) { return (degrees % 360.0 + 360.0) % 360.0; } public static double Delta(double from, double to) { return Wrap(to - from + 180.0) - 180.0; } public static bool Read(double x, double y, double z, out double heading, out double elevation) { heading = (elevation = 0.0); double num = Math.Sqrt(x * x + y * y + z * z); if (double.IsNaN(num) || double.IsInfinity(num) || num < 1E-09) { return false; } double num2 = Math.Sqrt(x * x + z * z); elevation = Math.Atan2(y, num2) * 180.0 / Math.PI; if (num2 / num < 0.01) { return false; } heading = Wrap(Math.Atan2(x, z) * 180.0 / Math.PI); return true; } public static string Cardinal(double heading) { return (new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" })[(int)Math.Floor((Wrap(heading) + 22.5) / 45.0) % 8]; } public static int DisplayDegrees(double heading) { return (int)Math.Floor(Wrap(heading) + 0.5) % 360; } public static float Clamp(float value, float min, float max, float fallback) { if (!float.IsNaN(value) && !float.IsInfinity(value)) { return Math.Max(min, Math.Min(max, value)); } return fallback; } } public sealed class Mod : MelonMod, IInputActionMapRequest, IShowCursorSource { private MelonPreferences_Category settings; private MelonPreferences_Entry enabled; private MelonPreferences_Entry showDegrees; private MelonPreferences_Entry showElevation; private MelonPreferences_Entry hideInMenus; private MelonPreferences_Entry size; private MelonPreferences_Entry positionX; private MelonPreferences_Entry positionY; private MelonPreferences_Entry opacity; private MelonPreferences_Entry span; private bool menuOpen; private bool inputRequested; private bool cursorRequested; private Rect menu = new Rect(40f, 130f, 460f, 490f); private GUIStyle small; private GUIStyle major; private GUIStyle center; private GUIStyle title; private GUIStyle body; private GUIStyle toggle; private GUIStyle button; private GUIStyle panel; private Texture2D panelTexture; private static readonly Color Accent = new Color(0.27f, 0.9f, 0.81f); private float lastError = -100f; public override void OnInitializeMelon() { settings = MelonPreferences.CreateCategory("VoidCrewCompass"); enabled = settings.CreateEntry("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); showDegrees = settings.CreateEntry("ShowDegrees", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); showElevation = settings.CreateEntry("ShowElevation", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); hideInMenus = settings.CreateEntry("HideInGameMenus", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); size = settings.CreateEntry("Scale", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); positionX = settings.CreateEntry("HorizontalPosition", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); positionY = settings.CreateEntry("VerticalPosition", 0.025f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); opacity = settings.CreateEntry("Opacity", 0.9f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); span = settings.CreateEntry("VisibleDegrees", 150f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); Sanitize(); ((MelonBase)this).LoggerInstance.Msg("Compass ready. F8: Settings. F9: HUD."); } private void Sanitize() { size.Value = CompassMath.Clamp(size.Value, 0.6f, 1.8f, 1f); positionX.Value = CompassMath.Clamp(positionX.Value, 0f, 1f, 0.5f); positionY.Value = CompassMath.Clamp(positionY.Value, 0f, 1f, 0.025f); opacity.Value = CompassMath.Clamp(opacity.Value, 0.2f, 1f, 0.9f); span.Value = CompassMath.Clamp(span.Value, 90f, 240f, 150f); } public override void OnUpdate() { Keyboard current = Keyboard.current; if (current != null) { if (((ButtonControl)current.f8Key).wasPressedThisFrame) { SetMenu(!menuOpen); } if (((ButtonControl)current.f9Key).wasPressedThisFrame) { enabled.Value = !enabled.Value; settings.SaveToFile(false); } if (menuOpen && ((ButtonControl)current.escapeKey).wasPressedThisFrame) { SetMenu(open: false); } } } private void SetMenu(bool open) { if (open == menuOpen) { return; } if (!open) { menuOpen = false; ReleaseInput(); settings.SaveToFile(false); return; } try { if (InputActionMapRequests.Instance != null && ServiceBase.Instance != null) { inputRequested = true; InputActionMapRequests.AddOrChangeRequest((IInputActionMapRequest)(object)this, (InputStateRequestType)2); cursorRequested = true; CursorUtility.ShowCursor((IShowCursorSource)(object)this, true); menuOpen = true; } } catch (Exception error) { ReleaseInput(); Report(error); } } private void ReleaseInput() { try { if (cursorRequested && ServiceBase.Instance != null) { CursorUtility.ShowCursor((IShowCursorSource)(object)this, false); } } catch (Exception error) { Report(error); } finally { cursorRequested = false; } try { if (inputRequested) { InputActionMapRequests.RemoveRequest((IInputActionMapRequest)(object)this); } } catch (Exception error2) { Report(error2); } finally { inputRequested = false; } } public override void OnSceneWasUnloaded(int buildIndex, string sceneName) { SetMenu(open: false); } public override void OnDeinitializeMelon() { menuOpen = false; ReleaseInput(); settings.SaveToFile(false); if (Object.op_Implicit((Object)(object)panelTexture)) { Object.Destroy((Object)(object)panelTexture); } } private void Report(Exception error) { if (!(Time.realtimeSinceStartup - lastError < 10f)) { lastError = Time.realtimeSinceStartup; ((MelonBase)this).LoggerInstance.Warning("Compass: " + error.Message); } } public override void OnGUI() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_0180: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Expected O, but got Unknown //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: 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) Matrix4x4 matrix = GUI.matrix; Color color = GUI.color; int depth = GUI.depth; try { InitStyles(); GUI.depth = -50; Camera main = Camera.main; bool flag = Object.op_Implicit((Object)(object)LocalPlayer.Instance) && Object.op_Implicit((Object)(object)main) && ((Behaviour)main).isActiveAndEnabled && (Object)(object)main.targetTexture == (Object)null; if (enabled.Value && flag && (menuOpen || !hideInMenus.Value || !MenuScreenController.IsOpen())) { DrawCompass(((Component)main).transform.forward); } if (menuOpen) { GUI.color = Color.white; float num = Mathf.Min(new float[3] { 1f, (float)Screen.width / 500f, (float)Screen.height / 620f }); GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f)); ((Rect)(ref menu)).x = Mathf.Clamp(((Rect)(ref menu)).x, 0f, Mathf.Max(0f, (float)Screen.width / num - ((Rect)(ref menu)).width)); ((Rect)(ref menu)).y = Mathf.Clamp(((Rect)(ref menu)).y, 0f, Mathf.Max(0f, (float)Screen.height / num - ((Rect)(ref menu)).height)); menu = GUILayout.Window(736202, menu, new WindowFunction(DrawSettings), "", panel, Array.Empty()); } } catch (Exception error) { Report(error); } finally { GUI.matrix = matrix; GUI.color = color; GUI.depth = depth; } } private void DrawCompass(Vector3 forward) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_0452: Unknown result type (might be due to invalid IL or missing references) //IL_0459: Unknown result type (might be due to invalid IL or missing references) //IL_000e: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_015f: 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_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_042a: Unknown result type (might be due to invalid IL or missing references) //IL_0446: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) if ((int)Event.current.type != 7) { return; } double heading; double elevation; bool flag = CompassMath.Read(forward.x, forward.y, forward.z, out heading, out elevation); float num = Mathf.Min(size.Value * Mathf.Clamp((float)Screen.height / 1080f, 0.65f, 1.5f), (float)(Screen.width - 16) / 620f); if (num <= 0f) { return; } float num2 = (showElevation.Value ? 102 : 82); float num3 = 8f + Mathf.Max(0f, (float)Screen.width - 620f * num - 16f) * positionX.Value; float num4 = 8f + Mathf.Max(0f, (float)Screen.height - num2 * num - 16f) * positionY.Value; Matrix4x4 matrix = GUI.matrix; GUI.matrix = Matrix4x4.TRS(new Vector3(num3, num4, 0f), Quaternion.identity, new Vector3(num, num, 1f)); try { Fill(new Rect(0f, 0f, 620f, num2), new Color(0.025f, 0.045f, 0.075f, 0.8f)); Fill(new Rect(0f, 0f, 620f, 2f), new Color(0.27f, 0.9f, 0.81f, 0.65f)); string text = (flag ? CompassMath.Cardinal(heading) : "VERTICAL"); if (flag && showDegrees.Value) { text = text + " " + CompassMath.DisplayDegrees(heading).ToString("000") + "°"; } Text(new Rect(0f, 5f, 620f, 25f), text, center, Accent); if (flag) { float num5 = 28f; float num6 = 592f; for (int i = 0; i < 360; i += 5) { float num7 = (float)CompassMath.Delta(heading, i); if (!(Mathf.Abs(num7) > span.Value * 0.5f)) { float num8 = 310f + num7 / span.Value * (num6 - num5); float num9 = Mathf.Clamp01((span.Value * 0.5f - Mathf.Abs(num7)) / 12f); bool flag2 = i % 45 == 0; Fill(new Rect(num8, 34f, 1f, (float)(flag2 ? 12 : 5)), new Color(0.8f, 0.87f, 0.94f, num9 * 0.7f)); if (flag2 || i % 15 == 0) { string text2 = (flag2 ? CompassMath.Cardinal(i) : i.ToString("000")); Color color = (Color)(flag2 ? Accent : new Color(0.72f, 0.8f, 0.88f)); color.a = num9; Text(new Rect(num8 - 23f, 48f, 46f, 22f), text2, flag2 ? major : small, color); } } } Fill(new Rect(309f, 32f, 2f, 16f), Accent); } else { Text(new Rect(0f, 39f, 620f, 25f), "Heading is undefined when looking straight up or down", small, Color.white); } if (showElevation.Value) { string text3 = ((Math.Abs(elevation) < 0.5) ? "0° · HORIZONTAL" : (Math.Abs(elevation).ToString("0") + "° " + ((elevation > 0.0) ? "UP" : "DOWN"))); Text(new Rect(0f, 78f, 620f, 20f), text3, small, new Color(0.72f, 0.8f, 0.88f)); } } finally { GUI.matrix = matrix; GUI.color = Color.white; } } private void Fill(Rect rect, Color color) { //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) color.a *= opacity.Value; GUI.color = color; GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture); } private void Text(Rect rect, string text, GUIStyle style, Color color) { //IL_0016: 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) color.a *= opacity.Value; GUI.color = color; GUI.Label(rect, text, style); } private void InitStyles() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0062: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_0086: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00b9: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Expected O, but got Unknown //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_01e3: Expected O, but got Unknown if (small == null) { small = new GUIStyle(GUI.skin.label) { fontSize = 12, alignment = (TextAnchor)4 }; small.normal.textColor = Color.white; major = new GUIStyle(small) { fontSize = 17, fontStyle = (FontStyle)1 }; center = new GUIStyle(major) { fontSize = 20 }; body = new GUIStyle(GUI.skin.label) { fontSize = 14, wordWrap = true }; body.normal.textColor = new Color(0.85f, 0.9f, 0.96f); title = new GUIStyle(body) { fontSize = 25, fontStyle = (FontStyle)1 }; title.normal.textColor = Accent; toggle = new GUIStyle(GUI.skin.toggle) { fontSize = 14, fixedHeight = 26f }; toggle.normal.textColor = body.normal.textColor; toggle.onNormal.textColor = Accent; button = new GUIStyle(GUI.skin.button) { fontSize = 14, fixedHeight = 32f }; panelTexture = new Texture2D(1, 1); panelTexture.SetPixel(0, 0, new Color(0.025f, 0.045f, 0.075f, 0.98f)); panelTexture.Apply(); panel = new GUIStyle(GUI.skin.window) { padding = new RectOffset(22, 22, 20, 20) }; panel.normal.background = panelTexture; panel.onNormal.background = panelTexture; } } private void DrawSettings(int id) { //IL_02e0: Unknown result type (might be due to invalid IL or missing references) GUILayout.Label("CREW / Compass", title, Array.Empty()); GUILayout.Label("F8 Settings · F9 Toggle HUD", body, Array.Empty()); GUILayout.Space(8f); enabled.Value = GUILayout.Toggle(enabled.Value, " Show compass", toggle, Array.Empty()); showDegrees.Value = GUILayout.Toggle(showDegrees.Value, " Show degrees", toggle, Array.Empty()); showElevation.Value = GUILayout.Toggle(showElevation.Value, " Show elevation", toggle, Array.Empty()); hideInMenus.Value = GUILayout.Toggle(hideInMenus.Value, " Hide in game menus", toggle, Array.Empty()); size.Value = Slider("Scale", size.Value, 0.6f, 1.8f, "0.00"); positionX.Value = Slider("Horizontal position", positionX.Value, 0f, 1f, "0.00"); positionY.Value = Slider("Vertical position", positionY.Value, 0f, 1f, "0.00"); opacity.Value = Slider("Opacity", opacity.Value, 0.2f, 1f, "0.00"); span.Value = Slider("Visible angle", span.Value, 90f, 240f, "0"); GUILayout.Space(8f); GUILayout.Label("Fixed world directions: N = +Z, E = +X.\nAll crew members share the same north.", body, Array.Empty()); GUILayout.Space(8f); GUILayout.BeginHorizontal(Array.Empty()); if (GUILayout.Button("Reset", button, Array.Empty())) { MelonPreferences_Entry obj = enabled; MelonPreferences_Entry obj2 = showDegrees; MelonPreferences_Entry obj3 = showElevation; bool flag = (hideInMenus.Value = true); bool flag3 = (obj3.Value = flag); bool value = (obj2.Value = flag3); obj.Value = value; size.Value = 1f; positionX.Value = 0.5f; positionY.Value = 0.025f; opacity.Value = 0.9f; span.Value = 150f; } if (GUILayout.Button("Save & close", button, Array.Empty())) { SetMenu(open: false); } GUILayout.EndHorizontal(); GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref menu)).width, 65f)); } private float Slider(string caption, float value, float min, float max, string format) { GUILayout.Label(caption + " " + value.ToString(format), body, Array.Empty()); return GUILayout.HorizontalSlider(value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(19f) }); } } }