Decompiled source of NearHorizon v1.5.0

NearHorizon.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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 NearHorizon
{
	internal static class HorizonFarClip
	{
		private static class ViewCameras
		{
			[CompilerGenerated]
			private sealed class <Local>d__0 : IEnumerable<Camera>, IEnumerable, IEnumerator<Camera>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private Camera <>2__current;

				private int <>l__initialThreadId;

				private StartOfRound sor;

				public StartOfRound <>3__sor;

				Camera IEnumerator<Camera>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <Local>d__0(int <>1__state)
				{
					this.<>1__state = <>1__state;
					<>l__initialThreadId = Environment.CurrentManagedThreadId;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						PlayerControllerB localPlayerController = sor.localPlayerController;
						if ((Object)(object)localPlayerController?.gameplayCamera != (Object)null)
						{
							<>2__current = localPlayerController.gameplayCamera;
							<>1__state = 1;
							return true;
						}
						goto IL_005e;
					}
					case 1:
						<>1__state = -1;
						goto IL_005e;
					case 2:
						{
							<>1__state = -1;
							break;
						}
						IL_005e:
						if ((Object)(object)sor.spectateCamera != (Object)null)
						{
							<>2__current = sor.spectateCamera;
							<>1__state = 2;
							return true;
						}
						break;
					}
					return false;
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}

				[DebuggerHidden]
				IEnumerator<Camera> IEnumerable<Camera>.GetEnumerator()
				{
					<Local>d__0 <Local>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Local>d__ = this;
					}
					else
					{
						<Local>d__ = new <Local>d__0(0);
					}
					<Local>d__.sor = <>3__sor;
					return <Local>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<Camera>)this).GetEnumerator();
				}
			}

			[IteratorStateMachine(typeof(<Local>d__0))]
			internal static IEnumerable<Camera> Local(StartOfRound sor)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <Local>d__0(-2)
				{
					<>3__sor = sor
				};
			}
		}

		internal static void SyncLocalPlanes()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			float num = Plugin.ResolvedFarClip();
			foreach (Camera item in ViewCameras.Local(instance))
			{
				item.farClipPlane = num;
			}
			if (Plugin.DebugLogging.Value)
			{
				Debug.Log((object)$"[NearHorizon] farClipPlane={num}");
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Start")]
	internal static class NearHooks_PlayerStartFarClip
	{
		private static void Postfix(PlayerControllerB __instance)
		{
			if (!((Object)(object)StartOfRound.Instance == (Object)null) && !((Object)(object)__instance != (Object)(object)StartOfRound.Instance.localPlayerController))
			{
				HorizonFarClip.SyncLocalPlanes();
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject), "Start")]
	[HarmonyPriority(800)]
	internal static class NearHooks_GrabbableStartPropShadow
	{
		private static void Postfix(GrabbableObject __instance)
		{
			PropShadowTweaks.OnGrabbableStart(__instance);
		}
	}
	[BepInPlugin("mine9289.NearHorizon", "NearHorizon", "1.5.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "mine9289.NearHorizon";

		public const string PluginName = "NearHorizon";

		public const string PluginVersion = "1.5.0";

		internal const float BadClipFallback = 200f;

		private Harmony harmony;

		public static Plugin Instance { get; private set; }

		public static ConfigEntry<float> FarClipPlane { get; private set; }

		public static ConfigEntry<bool> DebugLogging { get; private set; }

		public static ConfigEntry<bool> StripLampLungShadows { get; private set; }

		private void Awake()
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			Instance = this;
			FarClipPlane = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FarClipPlane", 120f, "View distance in units. Vanilla is 400. (between 1 and 10000)");
			DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLogging", false, "Whether to display debug messages.");
			StripLampLungShadows = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StripLampLungShadows", true, "Fancy lamp & lung apparatus: Light shadows off");
			CoerceFarClipIfBad();
			FarClipPlane.SettingChanged += delegate
			{
				CoerceFarClipIfBad();
				HorizonFarClip.SyncLocalPlanes();
			};
			StripLampLungShadows.SettingChanged += delegate
			{
				PropShadowTweaks.OnStripSettingChanged();
			};
			harmony = new Harmony("mine9289.nearhorizon");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"mine9289 / NearHorizon 1.5.0");
		}

		internal static void CoerceFarClipIfBad()
		{
			float value = FarClipPlane.Value;
			if (float.IsNaN(value) || value < 1f || value > 10000f)
			{
				FarClipPlane.Value = 200f;
			}
		}

		internal static float ResolvedFarClip()
		{
			float value = FarClipPlane.Value;
			if (!float.IsNaN(value) && !(value < 1f) && !(value > 10000f))
			{
				return value;
			}
			return 200f;
		}
	}
	internal static class PropShadowTweaks
	{
		private static readonly Dictionary<string, LightShadows> Defaults = new Dictionary<string, LightShadows>();

		internal static void OnGrabbableStart(GrabbableObject g)
		{
			ApplyTo(g);
		}

		internal static void OnStripSettingChanged()
		{
			GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				ApplyTo(array[i]);
			}
		}

		private static void ApplyTo(GrabbableObject g)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Item itemProperties = g.itemProperties;
			if ((Object)(object)itemProperties == (Object)null)
			{
				return;
			}
			string name = ((Object)itemProperties).name;
			if (name != "FancyLamp" && name != "LungApparatus")
			{
				return;
			}
			Light componentInChildren = ((Component)g).GetComponentInChildren<Light>();
			if (!((Object)(object)componentInChildren == (Object)null))
			{
				if (!Defaults.ContainsKey(name))
				{
					Defaults[name] = componentInChildren.shadows;
				}
				if (Plugin.StripLampLungShadows.Value)
				{
					componentInChildren.shadows = (LightShadows)0;
				}
				else
				{
					componentInChildren.shadows = Defaults[name];
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "NearHorizon";

		public const string PLUGIN_NAME = "NearHorizon";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}