Decompiled source of CustomGraphicsSettings v1.0.0

CustomGraphicsSettings.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bbc458827b0aa992d3c9a9749506f3403f21c5f4")]
[assembly: AssemblyVersion("1.0.0.0")]
public class AedenthornUtils
{
	public static bool IgnoreKeyPresses(bool extra = false)
	{
		if (!extra)
		{
			int result;
			if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
			{
				Chat instance = Chat.instance;
				result = ((instance != null && instance.HasFocus()) ? 1 : 0);
			}
			else
			{
				result = 1;
			}
			return (byte)result != 0;
		}
		int result2;
		if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
		{
			Chat instance2 = Chat.instance;
			if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
			{
				TextViewer instance3 = TextViewer.instance;
				result2 = ((instance3 != null && instance3.IsVisible()) ? 1 : 0);
				goto IL_00d2;
			}
		}
		result2 = 1;
		goto IL_00d2;
		IL_00d2:
		return (byte)result2 != 0;
	}

	public static bool CheckKeyDown(string value)
	{
		try
		{
			string[] array = value.Split(new char[1] { ',' });
			foreach (string text in array)
			{
				if (Input.GetKeyDown(text.ToLower()))
				{
					return true;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	public static bool CheckKeyUp(string value)
	{
		try
		{
			string[] array = value.Split(new char[1] { ',' });
			foreach (string text in array)
			{
				if (Input.GetKeyUp(text.ToLower()))
				{
					return true;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	public static bool CheckKeyHeld(string value, bool req = true)
	{
		try
		{
			string[] array = value.Split(new char[1] { ',' });
			foreach (string text in array)
			{
				if (Input.GetKey(text.ToLower()))
				{
					return true;
				}
			}
		}
		catch
		{
		}
		return !req;
	}

	public static void ShuffleList<T>(List<T> list)
	{
		int num = list.Count;
		while (num > 1)
		{
			num--;
			int index = Random.Range(0, num);
			T value = list[index];
			list[index] = list[num];
			list[num] = value;
		}
	}

	public static string GetAssetPath(object obj, bool create = false)
	{
		return GetAssetPath(obj.GetType().Namespace, create);
	}

	public static string GetAssetPath(string name, bool create = false)
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), name);
		if (create && !Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		return text;
	}

	public static string GetTransformPath(Transform t)
	{
		if (!Object.op_Implicit((Object)(object)t.parent))
		{
			return ((Object)t).name;
		}
		return GetTransformPath(t.parent) + "/" + ((Object)t).name;
	}

	public static byte[] EncodeToPNG(Texture2D texture)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)0);
		Graphics.Blit((Texture)(object)texture, temporary);
		RenderTexture active = RenderTexture.active;
		RenderTexture.active = temporary;
		Texture2D val = new Texture2D(((Texture)texture).width, ((Texture)texture).height, (TextureFormat)4, true, false);
		val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0);
		val.Apply();
		RenderTexture.active = active;
		RenderTexture.ReleaseTemporary(temporary);
		Texture2D val2 = new Texture2D(((Texture)texture).width, ((Texture)texture).height);
		val2.SetPixels(val.GetPixels());
		val2.Apply();
		return ImageConversion.EncodeToPNG(val2);
	}
}
namespace CustomGraphicsSettings;

[BepInPlugin("aedenthorn.CustomGraphicsSettings", "Custom Graphics Settings", "0.9.1")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Settings), "ApplyQualitySettings")]
	private static class Settings_ApplyQualitySettings_Patch
	{
		private static void Postfix()
		{
			if (modEnabled.Value)
			{
				SetGraphicsSettings();
			}
		}
	}

	[HarmonyPatch(typeof(Terminal), "InputText")]
	private static class InputText_Patch
	{
		private static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				__instance.AddString(text);
				__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
				return false;
			}
			return true;
		}
	}

	private static readonly bool isDebug = true;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<int> nexusID;

	public static ConfigEntry<AnisotropicFiltering> anisotropicFiltering;

	public static ConfigEntry<int> antiAliasing;

	public static ConfigEntry<int> asyncUploadBufferSize;

	public static ConfigEntry<bool> asyncUploadPersistentBuffer;

	public static ConfigEntry<int> asyncUploadTimeSlice;

	public static ConfigEntry<bool> billboardsFaceCameraPosition;

	public static ConfigEntry<float> lodBias;

	public static ConfigEntry<int> masterTextureLimit;

	public static ConfigEntry<int> maximumLODLevel;

	public static ConfigEntry<int> maxQueuedFrames;

	public static ConfigEntry<int> particleRaycastBudget;

	public static ConfigEntry<int> pixelLightCount;

	public static ConfigEntry<bool> realtimeReflectionProbes;

	public static ConfigEntry<float> resolutionScalingFixedDPIFactor;

	public static ConfigEntry<float> shadowCascade2Split;

	public static ConfigEntry<Vector3> shadowCascade4Split;

	public static ConfigEntry<int> shadowCascades;

	public static ConfigEntry<float> shadowDistance;

	public static ConfigEntry<ShadowmaskMode> shadowmaskMode;

	public static ConfigEntry<float> shadowNearPlaneOffset;

	public static ConfigEntry<ShadowProjection> shadowProjection;

	public static ConfigEntry<ShadowResolution> shadowResolution;

	public static ConfigEntry<ShadowQuality> shadows;

	public static ConfigEntry<SkinWeights> skinWeights;

	public static ConfigEntry<bool> softParticles;

	public static ConfigEntry<bool> softVegetation;

	public static ConfigEntry<bool> streamingMipmapsActive;

	public static ConfigEntry<bool> streamingMipmapsAddAllCameras;

	public static ConfigEntry<int> streamingMipmapsMaxFileIORequests;

	public static ConfigEntry<int> streamingMipmapsMaxLevelReduction;

	public static ConfigEntry<float> streamingMipmapsMemoryBudget;

	public static ConfigEntry<int> vSyncCount;

	public static ConfigEntry<string> hotkey;

	public static ConfigEntry<bool> reloadOnChange;

	private static BepInExPlugin context;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 169, "Nexus mod ID for updates");
		hotkey = ((BaseUnityPlugin)this).Config.Bind<string>("Options", "Hotkey", "", "Hotkey to reload settings from config");
		reloadOnChange = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ReloadOnChange", true, "Reload graphics settings when config values are changed");
		anisotropicFiltering = ((BaseUnityPlugin)this).Config.Bind<AnisotropicFiltering>("QualitySettings", "anisotropicFiltering", QualitySettings.anisotropicFiltering, "Global anisotropic filtering mode.");
		antiAliasing = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "antiAliasing", QualitySettings.antiAliasing, "Set The AA Filtering option.");
		asyncUploadBufferSize = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "asyncUploadBufferSize", QualitySettings.asyncUploadBufferSize, "Asynchronous texture and mesh data upload provides timesliced async texture and mesh data upload on the render thread with tight control over memory and timeslicing. There are no allocations except for the ones which driver has to do. To read data and upload texture and mesh data, Unity re-uses a ringbuffer whose size can be controlled.Use asyncUploadBufferSize to set the buffer size for asynchronous texture and mesh data uploads. The size is in megabytes. The minimum value is 2 and the maximum value is 512. The buffer resizes automatically to fit the largest texture currently loading. To avoid re-sizing of the buffer, which can incur performance cost, set the value approximately to the size of biggest texture used in the Scene.");
		asyncUploadPersistentBuffer = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "asyncUploadPersistentBuffer", QualitySettings.asyncUploadPersistentBuffer, "This flag controls if the async upload pipeline's ring buffer remains allocated when there are no active loading operations. Set this to true, to make the ring buffer allocation persist after all upload operations have completed. If you have issues with excessive memory usage, you can set this to false. This means you reduce the runtime memory footprint, but memory fragmentation can occur. The default value is true.");
		asyncUploadTimeSlice = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "asyncUploadTimeSlice", QualitySettings.asyncUploadTimeSlice, "Async texture upload provides timesliced async texture upload on the render thread with tight control over memory and timeslicing. There are no allocations except for the ones which driver has to do. To read data and upload texture data a ringbuffer whose size can be controlled is re-used.Use asyncUploadTimeSlice to set the time-slice in milliseconds for asynchronous texture uploads per frame. Minimum value is 1 and maximum is 33.");
		billboardsFaceCameraPosition = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "billboardsFaceCameraPosition", QualitySettings.billboardsFaceCameraPosition, "If enabled, billboards will face towards camera position rather than camera orientation.");
		lodBias = ((BaseUnityPlugin)this).Config.Bind<float>("QualitySettings", "lodBias", QualitySettings.lodBias, "Global multiplier for the LOD's switching distance.");
		masterTextureLimit = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "masterTextureLimit", QualitySettings.masterTextureLimit, "A texture size limit applied to all textures.");
		maximumLODLevel = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "maximumLODLevel", QualitySettings.maximumLODLevel, "A maximum LOD level. All LOD groups.");
		maxQueuedFrames = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "maxQueuedFrames", QualitySettings.maxQueuedFrames, "Maximum number of frames queued up by graphics driver.");
		particleRaycastBudget = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "particleRaycastBudget", QualitySettings.particleRaycastBudget, "Budget for how many ray casts can be performed per frame for approximate collision testing.");
		pixelLightCount = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "pixelLightCount", QualitySettings.pixelLightCount, "The maximum number of pixel lights that should affect any object.");
		realtimeReflectionProbes = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "realtimeReflectionProbes", QualitySettings.realtimeReflectionProbes, "Enables realtime reflection probes.");
		resolutionScalingFixedDPIFactor = ((BaseUnityPlugin)this).Config.Bind<float>("QualitySettings", "resolutionScalingFixedDPIFactor", QualitySettings.resolutionScalingFixedDPIFactor, "In resolution scaling mode, this factor is used to multiply with the target Fixed DPI specified to get the actual Fixed DPI to use for this quality setting.");
		shadowCascade2Split = ((BaseUnityPlugin)this).Config.Bind<float>("QualitySettings", "shadowCascade2Split", QualitySettings.shadowCascade2Split, "The normalized cascade distribution for a 2 cascade setup. The value defines the position of the cascade with respect to Zero.");
		shadowCascade4Split = ((BaseUnityPlugin)this).Config.Bind<Vector3>("QualitySettings", "shadowCascade4Split", QualitySettings.shadowCascade4Split, "The normalized cascade start position for a 4 cascade setup. Each member of the vector defines the normalized position of the coresponding cascade with respect to Zero.");
		shadowCascades = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "shadowCascades", QualitySettings.shadowCascades, "Number of cascades to use for directional light shadows.");
		shadowDistance = ((BaseUnityPlugin)this).Config.Bind<float>("QualitySettings", "shadowDistance", QualitySettings.shadowDistance, "Shadow drawing distance.");
		shadowmaskMode = ((BaseUnityPlugin)this).Config.Bind<ShadowmaskMode>("QualitySettings", "shadowmaskMode", QualitySettings.shadowmaskMode, "The rendering mode of Shadowmask.");
		shadowNearPlaneOffset = ((BaseUnityPlugin)this).Config.Bind<float>("QualitySettings", "shadowNearPlaneOffset", QualitySettings.shadowNearPlaneOffset, "Offset shadow frustum near plane.");
		shadowProjection = ((BaseUnityPlugin)this).Config.Bind<ShadowProjection>("QualitySettings", "shadowProjection", QualitySettings.shadowProjection, "Directional light shadow projection.");
		shadowResolution = ((BaseUnityPlugin)this).Config.Bind<ShadowResolution>("QualitySettings", "shadowResolution", QualitySettings.shadowResolution, "The default resolution of the shadow maps.");
		shadows = ((BaseUnityPlugin)this).Config.Bind<ShadowQuality>("QualitySettings", "shadows", QualitySettings.shadows, "Realtime Shadows type to be used.");
		skinWeights = ((BaseUnityPlugin)this).Config.Bind<SkinWeights>("QualitySettings", "skinWeights", QualitySettings.skinWeights, "The maximum number of bone weights that can affect a vertex, for all skinned meshes in the project.");
		softParticles = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "softParticles", QualitySettings.softParticles, "Should soft blending be used for particles?");
		softVegetation = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "softVegetation", QualitySettings.softVegetation, "Use a two-pass shader for the vegetation in the terrain engine.");
		streamingMipmapsActive = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "streamingMipmapsActive", QualitySettings.streamingMipmapsActive, "Enable automatic streaming of texture mipmap levels based on their distance from all active cameras.");
		streamingMipmapsAddAllCameras = ((BaseUnityPlugin)this).Config.Bind<bool>("QualitySettings", "streamingMipmapsAddAllCameras", QualitySettings.streamingMipmapsAddAllCameras, "Process all enabled Cameras for texture streaming (rather than just those with StreamingController components).");
		streamingMipmapsMaxFileIORequests = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "streamingMipmapsMaxFileIORequests", QualitySettings.streamingMipmapsMaxFileIORequests, "The maximum number of active texture file IO requests from the texture streaming system.");
		streamingMipmapsMaxLevelReduction = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "streamingMipmapsMaxLevelReduction", QualitySettings.streamingMipmapsMaxLevelReduction, "The maximum number of mipmap levels to discard for each texture.");
		streamingMipmapsMemoryBudget = ((BaseUnityPlugin)this).Config.Bind<float>("QualitySettings", "streamingMipmapsMemoryBudget", QualitySettings.streamingMipmapsMemoryBudget, "The total amount of memory to be used by streaming and non-streaming textures.");
		vSyncCount = ((BaseUnityPlugin)this).Config.Bind<int>("QualitySettings", "vSyncCount", QualitySettings.vSyncCount, "The VSync Count.");
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		SetGraphicsSettings();
		foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in ((BaseUnityPlugin)this).Config)
		{
			if (item.Key.Section == "QualitySettings")
			{
				if (item.Value is ConfigEntry<bool>)
				{
					(item.Value as ConfigEntry<bool>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<int>)
				{
					(item.Value as ConfigEntry<int>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<float>)
				{
					(item.Value as ConfigEntry<float>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<AnisotropicFiltering>)
				{
					(item.Value as ConfigEntry<AnisotropicFiltering>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<ShadowmaskMode>)
				{
					(item.Value as ConfigEntry<ShadowmaskMode>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<ShadowProjection>)
				{
					(item.Value as ConfigEntry<ShadowProjection>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<ShadowResolution>)
				{
					(item.Value as ConfigEntry<ShadowResolution>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<ShadowQuality>)
				{
					(item.Value as ConfigEntry<ShadowQuality>).SettingChanged += BepInExPlugin_SettingChanged;
				}
				else if (item.Value is ConfigEntry<SkinWeights>)
				{
					(item.Value as ConfigEntry<SkinWeights>).SettingChanged += BepInExPlugin_SettingChanged;
				}
			}
		}
	}

	private void Update()
	{
		if (modEnabled.Value && AedenthornUtils.CheckKeyDown(hotkey.Value))
		{
			SetGraphicsSettings();
		}
	}

	private void BepInExPlugin_SettingChanged(object sender, EventArgs e)
	{
		if (modEnabled.Value && reloadOnChange.Value)
		{
			SetGraphicsSettings();
		}
	}

	private static void SetGraphicsSettings()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		if (modEnabled.Value)
		{
			QualitySettings.anisotropicFiltering = anisotropicFiltering.Value;
			QualitySettings.antiAliasing = antiAliasing.Value;
			QualitySettings.asyncUploadBufferSize = asyncUploadBufferSize.Value;
			QualitySettings.asyncUploadPersistentBuffer = asyncUploadPersistentBuffer.Value;
			QualitySettings.asyncUploadTimeSlice = asyncUploadTimeSlice.Value;
			QualitySettings.billboardsFaceCameraPosition = billboardsFaceCameraPosition.Value;
			QualitySettings.lodBias = lodBias.Value;
			QualitySettings.masterTextureLimit = masterTextureLimit.Value;
			QualitySettings.maximumLODLevel = maximumLODLevel.Value;
			QualitySettings.maxQueuedFrames = maxQueuedFrames.Value;
			QualitySettings.particleRaycastBudget = particleRaycastBudget.Value;
			QualitySettings.pixelLightCount = pixelLightCount.Value;
			QualitySettings.realtimeReflectionProbes = realtimeReflectionProbes.Value;
			QualitySettings.resolutionScalingFixedDPIFactor = resolutionScalingFixedDPIFactor.Value;
			QualitySettings.shadowCascade2Split = shadowCascade2Split.Value;
			QualitySettings.shadowCascade4Split = shadowCascade4Split.Value;
			QualitySettings.shadowCascades = shadowCascades.Value;
			QualitySettings.shadowDistance = shadowDistance.Value;
			QualitySettings.shadowmaskMode = shadowmaskMode.Value;
			QualitySettings.shadowNearPlaneOffset = shadowNearPlaneOffset.Value;
			QualitySettings.shadowProjection = shadowProjection.Value;
			QualitySettings.shadowResolution = shadowResolution.Value;
			QualitySettings.shadows = shadows.Value;
			QualitySettings.skinWeights = skinWeights.Value;
			QualitySettings.softParticles = softParticles.Value;
			QualitySettings.softVegetation = softVegetation.Value;
			QualitySettings.streamingMipmapsActive = streamingMipmapsActive.Value;
			QualitySettings.streamingMipmapsAddAllCameras = streamingMipmapsAddAllCameras.Value;
			QualitySettings.streamingMipmapsMaxFileIORequests = streamingMipmapsMaxFileIORequests.Value;
			QualitySettings.streamingMipmapsMaxLevelReduction = streamingMipmapsMaxLevelReduction.Value;
			QualitySettings.streamingMipmapsMemoryBudget = streamingMipmapsMemoryBudget.Value;
			QualitySettings.vSyncCount = vSyncCount.Value;
		}
	}
}