Decompiled source of REPO Advanced Performance Optimizer v1.2.3

RepoOptimizer.dll

Decompiled 25 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
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: AssemblyCompany("RepoOptimizer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoOptimizer")]
[assembly: AssemblyTitle("RepoOptimizer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RepoOptimizer;

[BepInPlugin("com.optimizer.repo.repoconfig", "REPO Advanced Performance Optimizer", "1.2.3")]
public class RepoMenuOptimizer : BaseUnityPlugin
{
	private ConfigEntry<string> presetSetting;

	private ConfigEntry<string> resolutionSetting;

	private ConfigEntry<int> textureQuality;

	private ConfigEntry<int> fpsCap;

	private ConfigEntry<bool> lowRamMode;

	private ConfigEntry<bool> reduceCpuLoad;

	private ConfigEntry<bool> disableFog;

	private ConfigEntry<bool> emergencyPotatoHotkey;

	private ConfigEntry<bool> backgroundThrottling;

	private bool isEmergencyActive = false;

	private int originalFpsCap = 90;

	private void Awake()
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Expected O, but got Unknown
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Expected O, but got Unknown
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Expected O, but got Unknown
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Expected O, but got Unknown
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"REPO Performance Optimizer: Registering advanced features...");
		presetSetting = ((BaseUnityPlugin)this).Config.Bind<string>("1. Presets", "Quick Preset", "Custom", new ConfigDescription("Select a preset profile", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "Potato Mode", "Mid Mode", "High Mode", "Custom" }), Array.Empty<object>()));
		resolutionSetting = ((BaseUnityPlugin)this).Config.Bind<string>("2. Graphics", "Resolution", "1080p", new ConfigDescription("Screen Resolution", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "720p", "900p", "1080p", "Native" }), Array.Empty<object>()));
		textureQuality = ((BaseUnityPlugin)this).Config.Bind<int>("2. Graphics", "Texture Quality", 0, new ConfigDescription("0 = High Quality, 3 = Minimal VRAM/RAM", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), Array.Empty<object>()));
		fpsCap = ((BaseUnityPlugin)this).Config.Bind<int>("3. Performance", "Target FPS Cap", 90, new ConfigDescription("Limits GPU/CPU frame rendering", (AcceptableValueBase)(object)new AcceptableValueRange<int>(30, 240), Array.Empty<object>()));
		lowRamMode = ((BaseUnityPlugin)this).Config.Bind<bool>("4. RAM & CPU", "Aggressive RAM Cleaner", true, new ConfigDescription("Forces Unity to unload unused assets and drop unused textures.", (AcceptableValueBase)null, Array.Empty<object>()));
		reduceCpuLoad = ((BaseUnityPlugin)this).Config.Bind<bool>("4. RAM & CPU", "Reduce CPU Overhead", true, new ConfigDescription("Disables VSync wait states and optimizes physics step intervals.", (AcceptableValueBase)null, Array.Empty<object>()));
		disableFog = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Unique Features", "Disable Volumetric Fog", false, new ConfigDescription("Toggles rendering of atmospheric fog to boost GPU fill rate and FPS.", (AcceptableValueBase)null, Array.Empty<object>()));
		emergencyPotatoHotkey = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Unique Features", "Emergency Potato Hotkey (Insert)", true, new ConfigDescription("Press Insert anytime in-game to instantly drop resolution to 480p and disable shadows during extreme lag.", (AcceptableValueBase)null, Array.Empty<object>()));
		backgroundThrottling = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Unique Features", "Background Process Throttling", true, new ConfigDescription("Drops game FPS to 15 when Alt-Tabbed or unfocused to free up CPU/GPU resources.", (AcceptableValueBase)null, Array.Empty<object>()));
		presetSetting.SettingChanged += delegate
		{
			ApplyPreset();
		};
		resolutionSetting.SettingChanged += delegate
		{
			ApplyGraphics();
		};
		textureQuality.SettingChanged += delegate
		{
			ApplyGraphics();
		};
		fpsCap.SettingChanged += delegate
		{
			ApplyGraphics();
		};
		lowRamMode.SettingChanged += delegate
		{
			ApplyMemoryCpuTweaks();
		};
		reduceCpuLoad.SettingChanged += delegate
		{
			ApplyMemoryCpuTweaks();
		};
		disableFog.SettingChanged += delegate
		{
			ApplyFogTweak();
		};
	}

	private void Start()
	{
		ApplyGraphics();
		ApplyMemoryCpuTweaks();
		ApplyFogTweak();
	}

	private void Update()
	{
		if (emergencyPotatoHotkey.Value && UnityInput.Current.GetKeyDown((KeyCode)277))
		{
			ToggleEmergencyPotatoMode();
		}
	}

	private void OnApplicationFocus(bool hasFocus)
	{
		if (backgroundThrottling.Value)
		{
			if (!hasFocus)
			{
				originalFpsCap = fpsCap.Value;
				Application.targetFrameRate = 15;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[Optimizer] Game unfocused: Throttled FPS to 15.");
			}
			else
			{
				Application.targetFrameRate = (isEmergencyActive ? 30 : originalFpsCap);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[Optimizer] Game focused: Restored target FPS.");
			}
		}
	}

	private void ApplyFogTweak()
	{
		RenderSettings.fog = !disableFog.Value;
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"[Optimizer] Render Fog set to: {!disableFog.Value}");
	}

	private void ToggleEmergencyPotatoMode()
	{
		isEmergencyActive = !isEmergencyActive;
		if (isEmergencyActive)
		{
			Screen.SetResolution(854, 480, Screen.fullScreen);
			QualitySettings.shadows = (ShadowQuality)0;
			QualitySettings.globalTextureMipmapLimit = 3;
			Application.targetFrameRate = 30;
			((BaseUnityPlugin)this).Logger.LogWarning((object)"[Optimizer] \ud83d\udea8 EMERGENCY POTATO MODE ACTIVATED! (480p + Low)");
		}
		else
		{
			ApplyGraphics();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[Optimizer] \ud83d\udfe2 Emergency Mode Deactivated. Restored settings.");
		}
	}

	private void ApplyPreset()
	{
		switch (presetSetting.Value)
		{
		case "Potato Mode":
			resolutionSetting.Value = "720p";
			QualitySettings.shadows = (ShadowQuality)0;
			textureQuality.Value = 2;
			fpsCap.Value = 60;
			break;
		case "Mid Mode":
			resolutionSetting.Value = "900p";
			QualitySettings.shadows = (ShadowQuality)1;
			textureQuality.Value = 1;
			fpsCap.Value = 90;
			break;
		case "High Mode":
			resolutionSetting.Value = "Native";
			QualitySettings.shadows = (ShadowQuality)2;
			textureQuality.Value = 0;
			fpsCap.Value = 240;
			break;
		}
		ApplyGraphics();
	}

	private void ApplyGraphics()
	{
		//IL_0099: 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)
		if (!isEmergencyActive)
		{
			switch (resolutionSetting.Value)
			{
			case "720p":
				Screen.SetResolution(1280, 720, Screen.fullScreen);
				break;
			case "900p":
				Screen.SetResolution(1600, 900, Screen.fullScreen);
				break;
			case "1080p":
				Screen.SetResolution(1920, 1080, Screen.fullScreen);
				break;
			case "Native":
			{
				Resolution currentResolution = Screen.currentResolution;
				Screen.SetResolution(((Resolution)(ref currentResolution)).width, ((Resolution)(ref currentResolution)).height, Screen.fullScreen);
				break;
			}
			}
			QualitySettings.globalTextureMipmapLimit = textureQuality.Value;
			Application.targetFrameRate = fpsCap.Value;
		}
	}

	private void ApplyMemoryCpuTweaks()
	{
		if (lowRamMode.Value)
		{
			GC.Collect();
			Resources.UnloadUnusedAssets();
			QualitySettings.streamingMipmapsActive = true;
			QualitySettings.streamingMipmapsMemoryBudget = 512f;
		}
		if (reduceCpuLoad.Value)
		{
			QualitySettings.vSyncCount = 0;
			Time.fixedDeltaTime = 0.0333f;
		}
		else
		{
			Time.fixedDeltaTime = 0.02f;
		}
	}
}