Decompiled source of MaxDrawDistancePlugin v1.5.1

MaxDrawDistance.dll

Decompiled a week ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using PluginUtilities;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Max Draw Distance")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HolloFox")]
[assembly: AssemblyProduct("Max Draw Distance")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e4deb5e-97f9-4901-bf67-6748a9c1229a")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.5.1.0")]
namespace MaxDrawDistance;

[BepInPlugin("org.hollofox.plugins.MaxDrawDistance", "MaxDrawDistance", "1.5.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MaxDrawDistance : DependencyUnityPlugin
{
	private const string Guid = "org.hollofox.plugins.MaxDrawDistance";

	public const string Version = "1.5.1.0";

	public const string Name = "MaxDrawDistance";

	private Harmony harmony;

	private float? defaultShadowDistance;

	private static ConfigEntry<float> MaxDraw { get; set; }

	private static ConfigEntry<float> MaxShadowDistance { get; set; }

	public void DoConfig(ConfigFile config)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		ConfigDescription val = new ConfigDescription("", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationAttributes
		{
			CallbackAction = delegate
			{
				SetDrawDistance();
			}
		} });
		ConfigDescription val2 = new ConfigDescription("", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationAttributes
		{
			CallbackAction = delegate
			{
				SetShadowDistance();
			}
		} });
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Awake");
		MaxDraw = config.Bind<float>("Draw Distance", "Render Distance", 3000f, val);
		MaxShadowDistance = config.Bind<float>("Draw Distance", "Shadow Distance", 500f, val2);
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Config Bound");
	}

	[UsedImplicitly]
	protected override void OnAwake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		DoConfig(((BaseUnityPlugin)this).Config);
		harmony = new Harmony("org.hollofox.plugins.MaxDrawDistance");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Patched.");
		defaultShadowDistance = QualitySettings.shadowDistance;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plug-in loaded");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	[UsedImplicitly]
	protected override void OnDestroyed()
	{
		harmony.UnpatchSelf();
		SceneManager.sceneLoaded -= OnSceneLoaded;
		if (defaultShadowDistance.HasValue)
		{
			QualitySettings.shadowDistance = defaultShadowDistance.Value;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plug-in unloaded");
	}

	private void SetDrawDistance()
	{
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Updating Draw Distance");
		Camera[] array = Object.FindObjectsOfType<Camera>();
		for (int i = 0; i < array.Length; i++)
		{
			array[i].farClipPlane = MaxDraw.Value;
		}
	}

	public void SetShadowDistance()
	{
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Updating Shadow Distance");
		QualitySettings.shadowDistance = MaxShadowDistance.Value;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		SetDrawDistance();
		SetShadowDistance();
	}
}