Decompiled source of MaxDrawDistancePlugin v1.4.5

MaxDrawDistance.dll

Decompiled 4 months ago
using System;
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 ModdingTales;
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.4.5.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.4.5.0")]
internal sealed class ConfigurationManagerAttributes
{
	public bool? ShowRangeAsPercent;

	public Func<ConfigEntryBase, GameObject> CustomDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;

	public Action<object> CallbackAction;
}
namespace MaxDrawDistance;

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

	public const string Version = "1.4.5.0";

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

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

	public void DoConfig(ConfigFile config)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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]
		{
			new ConfigurationManagerAttributes
			{
				CallbackAction = delegate
				{
					SetDrawDistance();
				}
			}
		});
		ConfigDescription val2 = new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				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");
	}

	public void DoPatching()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("org.hollofox.plugins.MaxDrawDistance").PatchAll();
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Patched.");
	}

	[UsedImplicitly]
	private void Awake()
	{
		Setup();
	}

	private void Setup()
	{
		DoConfig(((BaseUnityPlugin)this).Config);
		DoPatching();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plug-in loaded");
		ModdingUtils.AddPluginToMenuList((BaseUnityPlugin)(object)this, "HolloFoxes'");
		SetShadowDistance();
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	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();
	}
}