Decompiled source of BetterUI v1.1.0

BetterUI.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BetterUI.Patches;
using GameNetcodeStuff;
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: AssemblyTitle("BetterUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterUI")]
[assembly: AssemblyCopyright("Copyright © LessonLethal 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("de27b4d1-820d-4505-a953-6001420281e4")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[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 BetterUI
{
	[BepInPlugin("LessonLethal.BetterUI", "BetterUI", "1.1.0")]
	public class BetterUIBase : BaseUnityPlugin
	{
		internal const string Name = "BetterUI";

		internal const string GUID = "LessonLethal.BetterUI";

		internal const string Version = "1.1.0";

		private readonly Harmony harmony = new Harmony("LessonLethal.BetterUI");

		private static BetterUIBase Instance;

		private static ManualLogSource mls;

		public void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			ConfigCtrl.InitConfig(((BaseUnityPlugin)this).Config);
			CreateCustomLogger();
			Log("BetterUI: v1.1.0 HAS AWAKENED FROM A DEEP SLEEP RAWR!");
			if (ConfigCtrl.fpsEnabled.Value)
			{
				harmony.PatchAll(typeof(FpsCtrl));
			}
			if (ConfigCtrl.hudEnabled.Value)
			{
				harmony.PatchAll(typeof(HudCtrl));
			}
			if (ConfigCtrl.clockEnabled.Value)
			{
				harmony.PatchAll(typeof(ClockCtrl));
			}
			if (ConfigCtrl.autoFadeChat.Value)
			{
				harmony.PatchAll(typeof(ChatCtrl));
			}
			if (ConfigCtrl.realTimeClock.Value)
			{
				harmony.PatchAll(typeof(TimeCtrl));
			}
		}

		private void OnGUI()
		{
			if (ConfigCtrl.fpsEnabled.Value)
			{
				FpsCtrl.FpsProcessor();
			}
		}

		private void Update()
		{
			//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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigCtrl.fpsEnabled.Value)
			{
				FpsCtrl.FpsProcessorRelay();
			}
			if (ConfigCtrl.frameRateOverride.Value)
			{
				if (Application.targetFrameRate != 500)
				{
					Application.targetFrameRate = 500;
				}
				if (QualitySettings.vSyncCount != 0)
				{
					QualitySettings.vSyncCount = 0;
				}
			}
			if (ConfigCtrl.fpsEnabled.Value)
			{
				KeyboardShortcut value = ConfigCtrl.fpsHotkey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					FpsCtrl.state = !FpsCtrl.state;
				}
			}
			if (ConfigCtrl.hudEnabled.Value)
			{
				KeyboardShortcut value2 = ConfigCtrl.hudHotkey.Value;
				if (((KeyboardShortcut)(ref value2)).IsDown())
				{
					HudCtrl.HudToggle();
				}
			}
		}

		private void Start()
		{
			if (ConfigCtrl.frameRateOverride.Value)
			{
				Application.targetFrameRate = 500;
				QualitySettings.vSyncCount = 0;
			}
		}

		private void CreateCustomLogger()
		{
			try
			{
				mls = Logger.CreateLogSource("LessonLethal.BetterUI");
			}
			catch
			{
				mls = ((BaseUnityPlugin)this).Logger;
			}
		}

		public static void Log(string message)
		{
			mls.LogMessage((object)message);
		}
	}
	internal static class ConfigCtrl
	{
		internal static ConfigEntry<bool> hudEnabled;

		internal static ConfigEntry<KeyboardShortcut> hudHotkey;

		internal static ConfigEntry<bool> fpsEnabled;

		internal static ConfigEntry<KeyboardShortcut> fpsHotkey;

		internal static ConfigEntry<int> fpsSize;

		internal static ConfigEntry<string> fpsColorStr;

		internal static Color fpsColor;

		internal static ConfigEntry<bool> clockEnabled;

		internal static ConfigEntry<KeyboardShortcut> clockHotkey;

		internal static ConfigEntry<float> clockInsideVis;

		internal static ConfigEntry<bool> realTimeClock;

		internal static ConfigEntry<bool> autoFadeChat;

		internal static ConfigEntry<bool> frameRateOverride;

		public static void InitConfig(ConfigFile config)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			hudEnabled = config.Bind<bool>("1_HUD", "Enable_HUD", true, "Enable the HUD Hotkey");
			hudHotkey = config.Bind<KeyboardShortcut>("1_HUD", "HUD_Hotkey", new KeyboardShortcut((KeyCode)263, Array.Empty<KeyCode>()), "Hotkey to toggle the visibility of the HUD");
			fpsEnabled = config.Bind<bool>("2_FPS", "Enable_FPS", true, "Enable the FPS Hotkey");
			fpsHotkey = config.Bind<KeyboardShortcut>("2_FPS", "FPS_Hotkey", new KeyboardShortcut((KeyCode)264, Array.Empty<KeyCode>()), "Hotkey to toggle the visibility of the FPS counter (hidden by default)");
			fpsSize = config.Bind<int>("2_FPS", "FPS_Font_Size", 13, "Change the FPS font size");
			fpsColorStr = config.Bind<string>("2_FPS", "FPS_Font_Color", "#FFFFFF", "Change the FPS font color (HEX Code)");
			ColorUtility.TryParseHtmlString(fpsColorStr.Value, ref fpsColor);
			clockEnabled = config.Bind<bool>("3_Clock", "Enable_Clock", true, "Enable the Clock Hotkey");
			clockHotkey = config.Bind<KeyboardShortcut>("3_Clock", "Clock_Hotkey", new KeyboardShortcut((KeyCode)265, Array.Empty<KeyCode>()), "Hotkey to toggle the visibility of the clock when you're inside the ship or a building (hidden by default)");
			clockInsideVis = config.Bind<float>("3_Clock", "Clock_Inside_Visibility", 0.3f, "Visibility of the clock when inside the ship or a building");
			realTimeClock = config.Bind<bool>("3_Clock", "Real_Time_Clock", false, "Smooth the speed of time on the clock (appearance only)");
			autoFadeChat = config.Bind<bool>("4_CHAT", "Auto_Fade_Chat", true, "Hides the chat box when not being used");
			frameRateOverride = config.Bind<bool>("5_EXPERIMENTAL", "Frame_Rate_Override", false, "Set target frame rate to 500 and turn off vSync");
		}
	}
	public static class PluginInfo
	{
		public const string GUID = "LessonLethal.BetterUI";

		public const string AUTHOR = "LessonLethal";

		public const string NAME = "BetterUI";

		public const string VERSION = "1.1.0";
	}
}
namespace BetterUI.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class ChatCtrl
	{
		[HarmonyPatch("AddChatMessage")]
		[HarmonyPatch("OpenMenu_performed")]
		[HarmonyPatch("SubmitChat_performed")]
		[HarmonyPostfix]
		public static void FadeToNothing(ref HUDManager __instance)
		{
			__instance.PingHUDElement(__instance.Chat, 5f, 1f, 0f);
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal static class ClockCtrl
	{
		private static bool state;

		[HarmonyPrefix]
		[HarmonyPatch("SetClockVisible")]
		public static bool PrefixVisible(ref HUDManager __instance)
		{
			//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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			KeyboardShortcut value = ConfigCtrl.clockHotkey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				state = !state;
			}
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = null;
			if ((Object)(object)instance != (Object)null)
			{
				val = instance.localPlayerController;
			}
			if ((Object)val != (Object)null && (val.isInHangarShipRoom || val.isInsideFactory))
			{
				__instance.Clock.targetAlpha = (state ? ConfigCtrl.clockInsideVis.Value : 0f);
				return false;
			}
			return true;
		}
	}
	internal static class FpsCtrl
	{
		public static bool state;

		public static float dTime;

		public static void FpsProcessor()
		{
			Mathf.RoundToInt(1f / dTime);
			int num = Mathf.RoundToInt(1f / Time.deltaTime);
			if (state)
			{
				DrawFPS("{0}", num);
			}
		}

		public static void FpsProcessorRelay()
		{
			dTime += (Time.unscaledDeltaTime - dTime) * 0.1f;
		}

		public static void DrawFPS(string format, params object[] args)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			string text = string.Format(format, args);
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = ConfigCtrl.fpsSize.Value;
			val.normal.textColor = ConfigCtrl.fpsColor;
			val.fontStyle = (FontStyle)0;
			GUI.Label(new Rect((float)Screen.width - 30f, 5f, 30f, 30f), new GUIContent(text), val);
		}
	}
	internal class HudCtrl
	{
		private static bool state;

		public static void HudToggle()
		{
			state = !state;
			HUDManager.Instance.HideHUD(state);
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal static class TimeCtrl
	{
		private static int lTime = -1;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay))]
		[HarmonyPatch("MoveTimeOfDay")]
		public static void PostfixMoveTimeOfDay(ref TimeOfDay __instance, ref float ___changeHUDTimeInterval)
		{
			int num = (int)(__instance.normalizedTimeOfDay * (60f * (float)__instance.numberOfHours));
			if (num != lTime)
			{
				lTime = num;
				HUDManager.Instance.SetClock(__instance.normalizedTimeOfDay, (float)__instance.numberOfHours, true);
				___changeHUDTimeInterval = 0f;
			}
		}
	}
}