Decompiled source of Smaller HUD v1.0.0

UMM/Mods/SmallerHUD/SmallerHUD.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using HarmonyLib;
using UnityEngine;
using UnityModManagerNet;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SmallerHUD")]
[assembly: AssemblyCompany("Gorzontrok")]
[assembly: AssemblyProduct("SmallerHUD")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: ComVisible(false)]
[assembly: Guid("c438c1d9-1e69-4bf2-839c-56812ff470c9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SmallerHUD
{
	internal static class Main
	{
		public static ModEntry mod;

		public static bool enabled;

		public static Settings settings;

		private static bool Load(ModEntry modEntry)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			modEntry.OnGUI = OnGUI;
			modEntry.OnSaveGUI = OnSaveGUI;
			modEntry.OnToggle = OnToggle;
			modEntry.OnUpdate = OnUpdate;
			mod = modEntry;
			settings = ModSettings.Load<Settings>(modEntry);
			try
			{
				Harmony val = new Harmony(modEntry.Info.Id);
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				val.PatchAll(executingAssembly);
			}
			catch (Exception ex)
			{
				mod.Logger.Log("Failed to Patch Harmony\n" + ex.ToString());
			}
			return true;
		}

		private static void OnGUI(ModEntry modEntry)
		{
			ModUI.OnGUI();
		}

		private static void OnUpdate(ModEntry modEntry, float dt)
		{
		}

		private static void OnSaveGUI(ModEntry modEntry)
		{
			((ModSettings)settings).Save(modEntry);
		}

		private static bool OnToggle(ModEntry modEntry, bool value)
		{
			enabled = value;
			return true;
		}

		public static void Log(object str)
		{
			mod.Logger.Log(str.ToString());
		}
	}
	public class Settings : ModSettings
	{
		public int scaleLevel = 5;

		public override void Save(ModEntry modEntry)
		{
			ModSettings.Save<Settings>(this, modEntry);
		}
	}
	public static class Mod
	{
		public static bool CanUsePatch => Main.enabled;

		private static Settings Sett => Main.settings;

		public static string LevelName()
		{
			switch (Sett.scaleLevel)
			{
			case 9:
			case 10:
				return "No Change";
			case 7:
			case 8:
				return "A little smaller";
			case 5:
			case 6:
				return "Smaller";
			case 3:
			case 4:
				return "That's Small";
			case 1:
			case 2:
				return "Too small";
			case 0:
				return "I'm sure i can see it";
			default:
				return "You broke the scale";
			}
		}

		public static Vector3 LevelVector()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3((float)Sett.scaleLevel / 10f, (float)Sett.scaleLevel / 10f, 1f);
		}

		public static void ResetScale()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Player[] players = HeroController.players;
			foreach (Player val in players)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val.hud != (Object)null)
				{
					((Component)val.hud).transform.localScale = LevelVector();
				}
			}
		}
	}
	public static class ModUI
	{
		private static Settings Sett => Main.settings;

		public static void OnGUI()
		{
			GUILayout.Label("Small level: " + Mod.LevelName(), (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (Sett.scaleLevel != (Sett.scaleLevel = (int)GUILayout.HorizontalSlider((float)Sett.scaleLevel, 10f, 0f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) })))
			{
				Mod.ResetScale();
			}
		}
	}
}
namespace SmallerHUD.Patches
{
	[HarmonyPatch(typeof(PlayerHUD), "Start")]
	internal static class PlayerHUD_Start_Patch
	{
		private static void Postfix(PlayerHUD __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Mod.CanUsePatch)
				{
					((Component)__instance).gameObject.transform.localScale = Mod.LevelVector();
				}
			}
			catch (Exception str)
			{
				Main.Log(str);
			}
		}
	}
}