Decompiled source of TootTallyFrameRateSettings v1.0.0

plugins/TootTallyFrameRateSettings.dll

Decompiled 5 months ago
using System;
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 BaboonAPI.Hooks.Initializer;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TootTallyCore;
using TootTallyCore.Utils.TootTallyModules;
using TootTallySettings;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TootTallyFrameRateSettings")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Frame Rate Settings Plugin TootTallyModule")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
[assembly: AssemblyProduct("TootTallyFrameRateSettings")]
[assembly: AssemblyTitle("TootTallyFrameRateSettings")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.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 TootTallyFrameRateSettings
{
	[BepInPlugin("TootTallyFrameRateSettings", "TootTallyFrameRateSettings", "2.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin, ITootTallyModule
	{
		public static class FrameRateSettingsPatch
		{
			[HarmonyPatch(typeof(SaveSlotController), "Start")]
			[HarmonyPostfix]
			public static void PatchFPSOnSaveSlotController()
			{
				ResolveFPSCap();
			}

			[HarmonyPatch(typeof(HomeController), "Start")]
			[HarmonyPostfix]
			public static void PatchFPSOnHomeController()
			{
				ResolveFPSCap();
			}

			[HarmonyPatch(typeof(HomeController), "tryToSaveSettings")]
			[HarmonyPostfix]
			public static void PatchFPSOnSettingsSave()
			{
				ResolveFPSCap();
			}

			[HarmonyPatch(typeof(LevelSelectController), "Start")]
			[HarmonyPostfix]
			public static void PatchFPSOnLevelSelectController()
			{
				ResolveFPSCap();
			}

			[HarmonyPatch(typeof(PointSceneController), "Start")]
			[HarmonyPostfix]
			public static void PatchFPSOnPointSceneController()
			{
				ResolveFPSCap();
			}

			[HarmonyPatch(typeof(GameController), "Start")]
			[HarmonyPostfix]
			public static void PatchFPSOnGameController()
			{
				int num = (int)Instance.option.Max_FPS.Value;
				Application.targetFrameRate = (Instance.option.Unlimited.Value ? (-1) : num);
			}

			private static void ResolveFPSCap()
			{
				int targetFrameRate = (int)(Instance.option.Unlimited.Value ? (-1f) : Instance.option.Max_FPS.Value);
				if (Instance.option.Cap_FPS_In_Menus.Value)
				{
					Application.targetFrameRate = (int)Instance.option.Max_FPS_In_Menus.Value;
				}
				else
				{
					Application.targetFrameRate = targetFrameRate;
				}
			}
		}

		public class Options
		{
			public ConfigEntry<bool> Cap_FPS_In_Menus { get; set; }

			public ConfigEntry<bool> Unlimited { get; set; }

			public ConfigEntry<float> Max_FPS { get; set; }

			public ConfigEntry<float> Max_FPS_In_Menus { get; set; }
		}

		public static Plugin Instance;

		private const string CONFIG_NAME = "FrameRateSettings.cfg";

		private const string CONFIG_FIELD = "FrameRate";

		private const bool DEFAULT_CAPSETTING = true;

		private const bool DEFAULT_UNLISETTING = false;

		private const float DEFAULT_FPSSETTING = 144f;

		public Options option;

		public static TootTallySettingPage settingPage;

		public ConfigEntry<bool> ModuleConfigEnabled { get; set; }

		public bool IsConfigInitialized { get; set; }

		public string Name
		{
			get
			{
				return "TootTallyFrameRateSettings";
			}
			set
			{
				Name = value;
			}
		}

		public static void LogInfo(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogError(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
		}

		private void Awake()
		{
			if (!((Object)(object)Instance != (Object)null))
			{
				Instance = this;
				GameInitializationEvent.Register(((BaseUnityPlugin)this).Info, (Action)TryInitialize);
			}
		}

		private void TryInitialize()
		{
			ModuleConfigEnabled = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Modules", "Frame Rate Settings", true, "Enable Frame Rate Settings Module");
			TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
		}

		public void LoadModule()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Paths.BepInExRootPath, "config/");
			ConfigFile val = new ConfigFile(text + "FrameRateSettings.cfg", true);
			option = new Options
			{
				Cap_FPS_In_Menus = val.Bind<bool>("FrameRate", "Cap FPS In Menus", true, (ConfigDescription)null),
				Max_FPS_In_Menus = val.Bind<float>("FrameRate", "Maximum FPS In Menus", 144f, (ConfigDescription)null),
				Max_FPS = val.Bind<float>("FrameRate", "Maximum FPS", 144f, (ConfigDescription)null),
				Unlimited = val.Bind<bool>("FrameRate", "Unlimited", false, (ConfigDescription)null)
			};
			settingPage = TootTallySettingsManager.AddNewPage("Frame Rates", "Frame Rate Settings", 40f, new Color(0.1f, 0.1f, 0.1f, 0.1f));
			if (settingPage != null)
			{
				settingPage.AddToggle("CapFPSMenuToggle", option.Cap_FPS_In_Menus, (UnityAction<bool>)delegate(bool value)
				{
					ResolveSlider(settingPage, "CapFPSMenu", "Max FPS In Menu", value, option.Max_FPS_In_Menus);
				});
				ResolveSlider(settingPage, "CapFPSMenu", "Max FPS In Menu", option.Cap_FPS_In_Menus.Value, option.Max_FPS_In_Menus);
				settingPage.AddToggle("UnlimitedFPSToggle", option.Unlimited, (UnityAction<bool>)delegate(bool value)
				{
					ResolveSlider(settingPage, "MaxFPS", "Max FPS In Game", !value, option.Max_FPS);
				});
				ResolveSlider(settingPage, "MaxFPS", "Max FPS In Game", !option.Unlimited.Value, option.Max_FPS);
			}
			Plugin.TryAddThunderstoreIconToPageButton(((BaseUnityPlugin)Instance).Info.Location, Name, settingPage);
			Harmony.CreateAndPatchAll(typeof(FrameRateSettingsPatch), "TootTallyFrameRateSettings");
			LogInfo("Module loaded!");
		}

		public void ResolveSlider(TootTallySettingPage page, string sliderName, string text, bool value, ConfigEntry<float> configEntry)
		{
			if (value)
			{
				page.AddSlider(sliderName + "Slider", 30f, 1000f, 350f, text, configEntry, true);
			}
			else
			{
				page.RemoveSettingObjectFromList(sliderName + "Slider");
			}
		}

		public void UnloadModule()
		{
			Harmony.UnpatchID("TootTallyFrameRateSettings");
			settingPage.Remove();
			LogInfo("Module unloaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TootTallyFrameRateSettings";

		public const string PLUGIN_NAME = "TootTallyFrameRateSettings";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}