Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BetterMonitor v0.1.3
BetterMonitor.dll
Decompiled 2 years agousing System; using System.Collections.Generic; 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 BetterMonitor.Models; using BetterMonitor.Patches.ManualCameraRendererPatch; using BetterMonitor.Patches.ScrapShapePatch; using BetterMonitor.Resources; using BetterMonitor.Utilities; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("Unity.Collections")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: IgnoresAccessChecksTo("UnityEngine.CoreModule")] [assembly: IgnoresAccessChecksTo("UnityEngine")] [assembly: AssemblyCompany("BetterMonitor")] [assembly: AssemblyDescription("Enhances the on-board monitor. Makes identifying objects and telling the way home easier.")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BetterMonitor")] [assembly: AssemblyTitle("BetterMonitor")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 BetterMonitor { public class Config { public ConfigEntry<bool> VerboseLogging { get; private set; } public ConfigEntry<bool> DisplayScrapByValue { get; private set; } public ConfigEntry<bool> AlignMonitorToPlayer { get; private set; } public ConfigEntry<CompassLocationType> CompassLocation { get; private set; } public Config(ConfigFile config) { VerboseLogging = config.Bind<bool>("Logging", "Verbose logging", true, "Log all events to the console (Useful for identifying issues during customization)"); DisplayScrapByValue = config.Bind<bool>("Scraps", "Show value", true, "Scrap icon changes shape by their value (Customize the icons in the 'ScrapIcons' folder)"); AlignMonitorToPlayer = config.Bind<bool>("Monitor", "Align view to player", true, "Rotate the camera view so that the player is always facing up"); CompassLocation = config.Bind<CompassLocationType>("Monitor", "Compass location", CompassLocationType.AroundPlayerWithProximity, "Where the compass should be placed on the monitor"); } } [BepInPlugin("BetterMonitor", "BetterMonitor", "1.0.0")] public class Plugin : BaseUnityPlugin { public static Plugin Instance { get; private set; } public static Config Configuration { get; private set; } private void Awake() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown Instance = this; Configuration = new Config(((BaseUnityPlugin)this).Config); Harmony val = new Harmony("com.fumiko.bettermonitor"); if (Configuration.DisplayScrapByValue.Value) { val.PatchAll(typeof(ScrapObjectPatch)); ScrapObjectPatch.Initialize(); } if (Configuration.CompassLocation.Value != 0) { val.PatchAll(typeof(MonitorPatch)); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BetterMonitor is loaded!"); } public static void LogError(string s) { if (Configuration.VerboseLogging.Value) { ((BaseUnityPlugin)Instance).Logger.LogError((object)s); } } public static void LogInfo(string s) { if (Configuration.VerboseLogging.Value) { ((BaseUnityPlugin)Instance).Logger.LogInfo((object)s); } } } public static class PluginInfo { public const string PLUGIN_GUID = "BetterMonitor"; public const string PLUGIN_NAME = "BetterMonitor"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace BetterMonitor.Utilities { public static class BytesExtensions { public static Sprite ToSprite(this byte[] bytes, int width = 256, int height = 256, float pixelsPerUnit = 100f, SpriteMeshType meshType = 1) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Texture2D texture = bytes.ToTexture2D(width, height); return texture.ToSprite(pixelsPerUnit, meshType); } public static Texture2D ToTexture2D(this byte[] bytes, int width = 256, int height = 256) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Expected O, but got Unknown Texture2D val = new Texture2D(width, height); return ImageConversion.LoadImage(val, bytes) ? val : null; } } public static class Texture2DExtensions { public static Sprite ToSprite(this Texture2D texture, float pixelsPerUnit = 100f, SpriteMeshType meshType = 1) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.one * 0.5f, pixelsPerUnit, 0u, meshType); } } } namespace BetterMonitor.Resources { public static class ModResources { private static readonly Assembly Assembly = typeof(ModResources).GetTypeInfo().Assembly; public static Stream Get(string path) { return Assembly.GetManifestResourceStream("BetterMonitor.Resources." + path); } } } namespace BetterMonitor.Patches.ScrapShapePatch { [HarmonyPatch(typeof(GrabbableObject))] public static class ScrapObjectPatch { private static readonly string ScrapIconsPath = Path.Combine(Paths.PluginPath, "ScrapIcons"); private static readonly int MainTexture = Shader.PropertyToID("_UnlitColorMap"); private static readonly SortedList<int, Texture> ScrapIcons = new SortedList<int, Texture>(); private static readonly Dictionary<string, Texture> NamedScrapReplacements = new Dictionary<string, Texture>(); public static void Initialize() { if (!Directory.Exists(ScrapIconsPath)) { InitializeDirectory(); } LoadScrapIcons(); } private static void LoadScrapIcons() { Plugin.LogInfo("Loading scrap icons from " + ScrapIconsPath); foreach (string item in Directory.EnumerateFiles(ScrapIconsPath)) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item); string extension = Path.GetExtension(item); if (!(extension.ToLowerInvariant() != ".png")) { Texture2D value = File.ReadAllBytes(item).ToTexture2D(); if (int.TryParse(fileNameWithoutExtension, out var result)) { ScrapIcons.Add(result, (Texture)(object)value); Plugin.LogInfo("Added icon for scrap value " + fileNameWithoutExtension); } else { NamedScrapReplacements.Add(fileNameWithoutExtension, (Texture)(object)value); Plugin.LogInfo("Added icon for scrap " + fileNameWithoutExtension); } } } if (ScrapIcons.Count > 0) { return; } using Stream stream = ModResources.Get("ScrapIcons.0.png"); byte[] array = new byte[stream.Length]; if (stream.Read(array, 0, array.Length) == 0) { ScrapIcons.Add(0, (Texture)(object)array.ToTexture2D()); } } private static void InitializeDirectory() { Directory.CreateDirectory(ScrapIconsPath); string[] array = new string[3] { "0.png", "59.png", "89.png" }; string[] array2 = array; foreach (string text in array2) { string path = Path.Combine(ScrapIconsPath, text); using FileStream destination = File.Create(path); ModResources.Get("ScrapIcons." + text).CopyTo(destination); } } [HarmonyPostfix] [HarmonyPatch("Start")] public static void StartPostfix(GrabbableObject __instance) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown MeshRenderer val = default(MeshRenderer); if (__instance.itemProperties.isScrap && ((Component)__instance.radarIcon).TryGetComponent<MeshRenderer>(ref val)) { MaterialPropertyBlock val2 = new MaterialPropertyBlock(); ((Renderer)val).GetPropertyBlock(val2); val2.SetTexture(MainTexture, FindScrapIcon(__instance)); ((Renderer)val).SetPropertyBlock(val2); } } private static Texture FindScrapIcon(GrabbableObject item) { if (NamedScrapReplacements.TryGetValue(item.itemProperties.itemName, out var value)) { return value; } for (int i = 0; i < ScrapIcons.Count; i++) { int num = ScrapIcons.Keys[i]; if (num >= item.scrapValue) { return ScrapIcons.Values[Mathf.Max(0, i - 1)]; } } IList<Texture> values = ScrapIcons.Values; return values[values.Count - 1]; } } } namespace BetterMonitor.Patches.ManualCameraRendererPatch { [HarmonyPatch(typeof(ManualCameraRenderer))] public static class MonitorPatch { [HarmonyPostfix] [HarmonyPatch("Update")] public static void UpdatePostfix(ManualCameraRenderer __instance) { TransformAndName val = __instance.radarTargets[__instance.targetTransformIndex]; if (!((Object)(object)__instance.cam != (Object)(object)__instance.mapCamera) && !((Object)(object)val.transform == (Object)null)) { AlignCameraToPlayer(((Component)__instance.cam).transform, val.transform); UpdateCompass(__instance, val.transform); } } private static void UpdateCompass(ManualCameraRenderer __instance, Transform radarTarget) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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) if (__instance.shipArrowUI.activeSelf) { Vector3 val = StartOfRound.Instance.elevatorTransform.position - radarTarget.position; val.y = 0f; if (Plugin.Configuration.AlignMonitorToPlayer.Value) { Quaternion rotation = radarTarget.rotation; val = Quaternion.AngleAxis(0f - rotation.y, Vector3.up) * val; } if (Plugin.Configuration.CompassLocation.Value == CompassLocationType.AroundPlayer) { __instance.shipArrowPointer.localPosition = ((Vector3)(ref val)).normalized * 50f; } else { float num = Mathf.Lerp(40f, 90f, ((Vector3)(ref val)).sqrMagnitude / 196f); __instance.shipArrowPointer.localPosition = ((Vector3)(ref val)).normalized * num; } __instance.shipArrowPointer.forward = val; } } private static void AlignCameraToPlayer(Transform camera, Transform player) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Configuration.AlignMonitorToPlayer.Value) { Quaternion rotation = player.rotation; camera.rotation = Quaternion.Euler(90f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f); } } } } namespace BetterMonitor.Models { public enum CompassLocationType { BottomRight, AroundPlayer, AroundPlayerWithProximity } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }