// Consolidated decompiled source — Azumatt-SunkenCompass v1.0.2 // Generated by Hexium's decompiled-source browser. Best-effort concatenation of every type in this // version's manifest — decompiler output isn't guaranteed to compile as-is. using System; using System.Runtime.CompilerServices; using System.IO; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using UnityEngine; using UnityEngine.UI; using System.Reflection; // ---- SunkenCompass.dll :: Microsoft.CodeAnalysis.EmbeddedAttribute ---- namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } // ---- SunkenCompass.dll :: SunkenCompass.SunkenCompassPlugin ---- namespace SunkenCompass { [BepInPlugin("Azumatt.SunkenCompass", "SunkenCompass", "1.0.2")] public class SunkenCompassPlugin : BaseUnityPlugin { public enum Toggle { Off, On } private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [UsedImplicitly] public string? Category; [UsedImplicitly] public Action? CustomDrawer; } internal const string ModName = "SunkenCompass"; internal const string ModVersion = "1.0.2"; internal const string Author = "Azumatt"; private const string ModGuid = "Azumatt.SunkenCompass"; private static string ConfigFileName = "Azumatt.SunkenCompass.cfg"; private static string ConfigFileFullPath; private readonly Harmony _harmony = new Harmony("Azumatt.SunkenCompass"); public static readonly ManualLogSource SunkenCompassLogger; internal static Sprite CompassSprite; internal static Sprite CompassCenter; internal static Sprite CompassMask; internal static GameObject ObjectCompass; internal static GameObject ObjectParent; internal static GameObject ObjectCenterMark; internal static bool GotCompassImage; internal static bool GotCompassMask; internal static bool GotCompassCenter; internal static ConfigEntry ConfigEnabled; internal static ConfigEntry ColorCompass; internal static ConfigEntry ColorCenterMark; internal static ConfigEntry CompassUsePlayerDirection; internal static ConfigEntry CompassYOffset; internal static ConfigEntry CompassScale; internal static ConfigEntry CompassShowCenterMark; private void Awake() { ConfigEnabled = base.Config.Bind("1 - Sunken Compass", "Enabled", Toggle.On, "Enable or disable the Sunken Compass."); CompassUsePlayerDirection = base.Config.Bind("2 - Compass Display", "Use Player Direction", Toggle.Off, "Orient the compass based on the direction the player is facing, rather than the middle of the screen."); CompassScale = base.Config.Bind("2 - Compass Display", "Scale (Compass)", 0.75f, "Enlarge or shrink the scale of the compass."); CompassYOffset = base.Config.Bind("2 - Compass Display", "Offset (Y)", 0, "Offset from the top of the screen in pixels."); CompassShowCenterMark = base.Config.Bind("2 - Compass Display", "Show Center Mark", Toggle.Off, "Show center mark graphic."); ColorCompass = base.Config.Bind("3 - Color Adjustment", "Color (Compass)", Color.white, "Adjust the color of the compass."); ColorCenterMark = base.Config.Bind("3 - Color Adjustment", "Color (Center Mark)", Color.yellow, "Adjust the color of the center mark graphic."); if (ConfigEnabled.Value == Toggle.On) { CompassSprite = Utilities.LoadSprite("compass.png"); CompassCenter = Utilities.LoadSprite("center.png"); CompassMask = Utilities.LoadSprite("mask.png"); GotCompassImage = CompassSprite != null; GotCompassMask = CompassMask != null; GotCompassCenter = CompassCenter != null; _harmony.PatchAll(); SetupWatcher(); } else { SunkenCompassLogger.LogInfo("SunkenCompass v[1.0.2] not enabled in configuration."); } } private void OnDestroy() { base.Config.Save(); } private void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { SunkenCompassLogger.LogDebug("ReadConfigValues called"); base.Config.Reload(); } catch { SunkenCompassLogger.LogError("There was an issue loading your " + ConfigFileName); SunkenCompassLogger.LogError("Please check your config entries for spelling and format!"); } } static SunkenCompassPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; SunkenCompassLogger = BepInEx.Logging.Logger.CreateLogSource("SunkenCompass"); CompassSprite = null; CompassCenter = null; CompassMask = null; ObjectCompass = null; ObjectParent = null; ObjectCenterMark = null; ConfigEnabled = null; ColorCompass = null; ColorCenterMark = null; CompassUsePlayerDirection = null; CompassYOffset = null; CompassScale = null; CompassShowCenterMark = null; } } } // ---- SunkenCompass.dll :: SunkenCompass.UICombatStartPatch ---- namespace SunkenCompass { [HarmonyPatch(typeof(UICombat), "Start")] internal static class UICombatStartPatch { private static void Prefix(UICombat __instance) { if (SunkenCompassPlugin.CompassSprite.texture.width < 1) { SunkenCompassPlugin.SunkenCompassLogger.LogDebug("Image for compass was invalid or zero pixels in width."); return; } float num = (float)SunkenCompassPlugin.CompassSprite.texture.width / 2f; Sprite sprite = Sprite.Create(SunkenCompassPlugin.CompassSprite.texture, new Rect(0f, 0f, SunkenCompassPlugin.CompassSprite.texture.width, SunkenCompassPlugin.CompassSprite.texture.height), Vector2.zero); Sprite sprite2 = null; if (SunkenCompassPlugin.GotCompassMask && SunkenCompassPlugin.CompassMask.texture.width > 0) { sprite2 = Sprite.Create(SunkenCompassPlugin.CompassMask.texture, new Rect(0f, 0f, num, SunkenCompassPlugin.CompassMask.texture.height), Vector2.zero); } Sprite sprite3 = null; if (SunkenCompassPlugin.CompassShowCenterMark.Value == SunkenCompassPlugin.Toggle.On && SunkenCompassPlugin.GotCompassImage && SunkenCompassPlugin.GotCompassMask && SunkenCompassPlugin.GotCompassCenter && SunkenCompassPlugin.CompassCenter.texture.width > 0) { sprite3 = Sprite.Create(SunkenCompassPlugin.CompassCenter.texture, new Rect(0f, 0f, SunkenCompassPlugin.CompassCenter.texture.width, SunkenCompassPlugin.CompassCenter.texture.height), Vector2.zero); } SunkenCompassPlugin.ObjectParent = new GameObject(); SunkenCompassPlugin.ObjectParent.name = "Compass"; SunkenCompassPlugin.ObjectParent.AddComponent().SetParent(__instance.CombatRoot.transform); GameObject gameObject = new GameObject(); if (SunkenCompassPlugin.CompassMask.texture != null && SunkenCompassPlugin.CompassMask.texture.width > 0) { gameObject.name = "Mask"; RectTransform rectTransform = gameObject.AddComponent(); rectTransform.SetParent(SunkenCompassPlugin.ObjectParent.transform); rectTransform.sizeDelta = new Vector2(num, SunkenCompassPlugin.CompassSprite.texture.height); rectTransform.localScale = Vector3.one * SunkenCompassPlugin.CompassScale.Value; rectTransform.anchoredPosition = Vector2.zero; Image image = gameObject.AddComponent(); image.sprite = sprite2; image.preserveAspect = true; gameObject.AddComponent().showMaskGraphic = false; } SunkenCompassPlugin.ObjectCompass = new GameObject(); SunkenCompassPlugin.ObjectCompass.name = "Image"; RectTransform rectTransform2 = SunkenCompassPlugin.ObjectCompass.AddComponent(); rectTransform2.SetParent(gameObject.transform); rectTransform2.localScale = Vector3.one; rectTransform2.anchoredPosition = Vector2.zero; rectTransform2.sizeDelta = new Vector2(SunkenCompassPlugin.CompassSprite.texture.width, SunkenCompassPlugin.CompassSprite.texture.height); Image image2 = SunkenCompassPlugin.ObjectCompass.AddComponent(); image2.sprite = sprite; image2.preserveAspect = true; if (SunkenCompassPlugin.CompassShowCenterMark.Value == SunkenCompassPlugin.Toggle.On && SunkenCompassPlugin.CompassCenter.texture.width > 0) { SunkenCompassPlugin.ObjectCenterMark = new GameObject(); SunkenCompassPlugin.ObjectCenterMark.name = "CenterMark"; RectTransform rectTransform3 = SunkenCompassPlugin.ObjectCenterMark.AddComponent(); rectTransform3.SetParent(gameObject.transform); rectTransform3.localScale = Vector3.one; rectTransform3.anchoredPosition = Vector2.zero; rectTransform3.sizeDelta = new Vector2(SunkenCompassPlugin.CompassCenter.texture.width, SunkenCompassPlugin.CompassCenter.texture.height); Image image3 = SunkenCompassPlugin.ObjectCenterMark.AddComponent(); image3.sprite = sprite3; image3.preserveAspect = true; } SunkenCompassPlugin.SunkenCompassLogger.LogDebug("Finished attempting to add compass to game hud."); } } } // ---- SunkenCompass.dll :: SunkenCompass.UICombatUpdatePatch ---- namespace SunkenCompass { [HarmonyPatch(typeof(UICombat), "Update")] internal static class UICombatUpdatePatch { private static void Prefix(UICombat __instance) { if ((bool)(UnityEngine.Object)(object)WorldScene.code && (bool)(UnityEngine.Object)(object)Global.code.Player && SunkenCompassPlugin.ConfigEnabled.Value != SunkenCompassPlugin.Toggle.Off && (bool)(UnityEngine.Object)(object)Global.code.Player && SunkenCompassPlugin.GotCompassImage && SunkenCompassPlugin.GotCompassMask) { SunkenCompassPlugin.ObjectParent.SetActive(!Global.code.OnGUI); float num = ((SunkenCompassPlugin.CompassUsePlayerDirection.Value == SunkenCompassPlugin.Toggle.Off) ? ((Component)(object)FPSPlayer.code.CameraControlComponent).transform.eulerAngles.y : ((Component)(object)Global.code.Player).transform.eulerAngles.y); if ((double)num > 180.0) { num -= 360f; } float num2 = num * (-MathF.PI / 180f); Rect rect = SunkenCompassPlugin.ObjectCompass.GetComponent().sprite.rect; SunkenCompassPlugin.ObjectCompass.GetComponent().localPosition = Vector3.right * (rect.width / 2f) * num2 / 6.283185f - new Vector3(rect.width * 0.125f, 0f, 0f); SunkenCompassPlugin.ObjectCompass.GetComponent().color = SunkenCompassPlugin.ColorCompass.Value; SunkenCompassPlugin.ObjectParent.GetComponent().localScale = Vector3.one * SunkenCompassPlugin.CompassScale.Value; SunkenCompassPlugin.ObjectParent.GetComponent().anchoredPosition = new Vector2(0f, (float)(((double)Screen.height / 1.0 - (double)SunkenCompassPlugin.ObjectCompass.GetComponent().sprite.texture.height * (double)SunkenCompassPlugin.CompassScale.Value) / 2.0)) - Vector2.up * SunkenCompassPlugin.CompassYOffset.Value; if (SunkenCompassPlugin.CompassShowCenterMark.Value == SunkenCompassPlugin.Toggle.On && !(SunkenCompassPlugin.ObjectCenterMark == null)) { SunkenCompassPlugin.ObjectCenterMark.GetComponent().color = SunkenCompassPlugin.ColorCenterMark.Value; SunkenCompassPlugin.ObjectCenterMark.SetActive(value: true); } } } } } // ---- SunkenCompass.dll :: SunkenCompass.Utilities ---- namespace SunkenCompass { public class Utilities { private static byte[] ReadEmbeddedFileBytes(string name) { using MemoryStream memoryStream = new MemoryStream(); Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + "." + name).CopyTo(memoryStream); return memoryStream.ToArray(); } internal static Texture2D LoadTexture(string name) { Texture2D texture2D = null; texture2D = ((!(name == "mask.png") && !(name == "compass.png")) ? new Texture2D(0, 0, TextureFormat.RGBA32, mipChain: true, linear: true) : new Texture2D(2, 2, TextureFormat.RGBA32, mipChain: true, linear: true)); texture2D.LoadImage(ReadEmbeddedFileBytes("images." + name)); return texture2D; } internal static Sprite LoadSprite(string name) { Texture2D texture2D = LoadTexture(name); if (texture2D != null) { return Sprite.Create(texture2D, new Rect(0f, 0f, texture2D.width, texture2D.height), Vector2.zero); } return null; } } }