Decompiled source of Performance Squeezer v1.1.0

PerformanceSqueezer.dll

Decompiled 2 years 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 Colossal.Logging;
using Game;
using Game.Common;
using Game.Modding;
using Game.Rendering;
using Game.Rendering.Utilities;
using Game.UI.InGame;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PerformanceSqueezer.Systems;
using Unity.Entities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PerformanceSqueezer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Dynamic Resolution Extended")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1")]
[assembly: AssemblyProduct("PerformanceSqueezer")]
[assembly: AssemblyTitle("PerformanceSqueezer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 PerformanceSqueezer
{
	[BepInPlugin("com.nyoko.PerformanceSqueezer", "Performance Squeezer", "1.0")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.nyoko.PerformanceSqueezer";

		private Mod _mod;

		private PhotoModeUISystem m_PhotoModeUISystem;

		private static CameraUpdateSystem m_CameraUpdateSystem;

		public static bool orbitMode { get; set; }

		public void Awake()
		{
			_mod = new Mod();
			_mod.OnLoad();
			_mod.Log.Info((object)"=======Performance Squeezer=======");
			_mod.Log.Info((object)"=======     Initialized   =======");
			_mod.Log.Info((object)"=======                   =======");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nyoko.PerformanceSqueezer");
		}

		[HarmonyPatch(typeof(SystemOrder), "Initialize")]
		[HarmonyPostfix]
		private static void InjectSystems(UpdateSystem updateSystem)
		{
			Mod.Instance.OnCreateWorld(updateSystem);
		}
	}
	internal static class Initializer
	{
		public static void OnLoad()
		{
		}

		public static void OnInitialized()
		{
		}
	}
	public sealed class Mod : IMod
	{
		public const string ModName = "Performance Squeezer";

		public static Mod Instance { get; private set; }

		internal ILog Log { get; private set; }

		public void OnLoad()
		{
			Instance = this;
			Log = LogManager.GetLogger("Performance Squeezer", true);
			Log.Info((object)"setting logging level to Debug");
			Log.effectivenessLevel = Level.Debug;
			Log.Info((object)"loading");
		}

		public void OnCreateWorld(UpdateSystem updateSystem)
		{
			updateSystem.UpdateAt<MainMenuRelieve>((SystemUpdatePhase)10);
			updateSystem.UpdateAt<ModeSystem>((SystemUpdatePhase)12);
		}

		public void OnDispose()
		{
			Log.Info((object)"disposing");
			Instance = null;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PerformanceSqueezer";

		public const string PLUGIN_NAME = "PerformanceSqueezer";

		public const string PLUGIN_VERSION = "1.1";
	}
}
namespace PerformanceSqueezer.Systems
{
	public class MainMenuRelieve : SystemBase
	{
		private bool hasTriggered;

		private bool ctrlPressed;

		private bool altPressed;

		private RenderingSystem RenderingSystem;

		private bool graphicsSettingsApplied;

		public bool PotatoMode { get; set; }

		protected override void OnUpdate()
		{
			bool num = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
			bool flag = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
			if (num && flag && !ctrlPressed && !altPressed)
			{
				PotatoMode = !PotatoMode;
				ctrlPressed = true;
				altPressed = true;
			}
			if ((!num || !flag) && (ctrlPressed || altPressed))
			{
				ctrlPressed = false;
				altPressed = false;
			}
			if (PotatoMode && !graphicsSettingsApplied)
			{
				ApplyLowestGraphicsSettings();
				graphicsSettingsApplied = true;
			}
		}

		private void ApplyLowestGraphicsSettings()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			new RenderingSystem().levelOfDetail = 0f;
			QualitySettings.SetQualityLevel(0, true);
			QualitySettings.masterTextureLimit = 3;
			QualitySettings.shadows = (ShadowQuality)0;
			QualitySettings.shadowResolution = (ShadowResolution)0;
			QualitySettings.shadowDistance = 0f;
			QualitySettings.shadowCascades = 0;
			QualitySettings.shadowProjection = (ShadowProjection)0;
			QualitySettings.shadowNearPlaneOffset = 0.2f;
			QualitySettings.realtimeReflectionProbes = false;
			QualitySettings.billboardsFaceCameraPosition = false;
			QualitySettings.antiAliasing = 0;
			QualitySettings.asyncUploadTimeSlice = 2;
			QualitySettings.asyncUploadBufferSize = 2;
			SetPrivateFieldValue();
		}

		public void SetPrivateFieldValue()
		{
			FieldInfo field = typeof(AdaptiveDynamicResolutionScale).GetField("s_CurrentScaleFraction", BindingFlags.Static | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(null, 1E-05f);
			}
			else
			{
				Console.WriteLine("[Critical] CurrentScaleFraction not found.");
			}
		}
	}
	public class ModeSystem : SystemBase
	{
		private bool hasTriggered;

		private bool ctrlPressed;

		private bool altPressed;

		private RenderingSystem RenderingSystem;

		private bool graphicsSettingsApplied;

		public bool PotatoMode { get; set; }

		protected override void OnUpdate()
		{
			bool num = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
			bool flag = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
			if (num && flag && !ctrlPressed && !altPressed)
			{
				PotatoMode = !PotatoMode;
				ctrlPressed = true;
				altPressed = true;
			}
			if ((!num || !flag) && (ctrlPressed || altPressed))
			{
				ctrlPressed = false;
				altPressed = false;
				graphicsSettingsApplied = false;
			}
			if (PotatoMode)
			{
				ApplyLowestGraphicsSettings();
				graphicsSettingsApplied = true;
			}
		}

		private void ApplyLowestGraphicsSettings()
		{
			QualitySettings.SetQualityLevel(0, true);
			QualitySettings.masterTextureLimit = 3;
			QualitySettings.shadows = (ShadowQuality)0;
			QualitySettings.shadowResolution = (ShadowResolution)0;
			QualitySettings.shadowDistance = 0f;
			QualitySettings.shadowCascades = 0;
			QualitySettings.shadowProjection = (ShadowProjection)0;
			QualitySettings.shadowNearPlaneOffset = 0.2f;
			QualitySettings.realtimeReflectionProbes = false;
			QualitySettings.billboardsFaceCameraPosition = false;
			QualitySettings.antiAliasing = 0;
			QualitySettings.asyncUploadTimeSlice = 2;
			QualitySettings.asyncUploadBufferSize = 2;
			SetPrivateFieldValue();
		}

		public void SetPrivateFieldValue()
		{
			FieldInfo field = typeof(AdaptiveDynamicResolutionScale).GetField("s_CurrentScaleFraction", BindingFlags.Static | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(null, 0.001f);
			}
			else
			{
				Console.WriteLine("[Critical] CurrentScaleFraction not found.");
			}
		}
	}
}