Decompiled source of PEAKsideDown v1.0.0

PEAKsideDown.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PEAKsideDown")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAKsideDown")]
[assembly: AssemblyTitle("PEAKsideDown")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace PEAKsideDown
{
	[BepInPlugin("PEAKsideDown", "PEAKside Down", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static ConfigEntry<bool> modEnabled;

		private static ConfigEntry<bool> flipCameraEnabled;

		private static ConfigEntry<bool> flipControlsEnabled;

		private static ConfigEntry<bool> restrictLookAngleEnabled;

		private static ConfigEntry<float> upsideDownAngle;

		private static ConfigEntry<float> minLookAngle;

		private static ConfigEntry<float> maxLookAngle;

		public static bool IsClimbingUpsideDown { get; set; }

		private void Awake()
		{
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Mod", true, "Enable or disable the entire mod.");
			flipCameraEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "Flip Camera", true, "Flip the camera upside down when climbing.");
			flipControlsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "Flip Controls", false, "Flip the movement controls when climbing.");
			restrictLookAngleEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "Restrict Look Angle", true, "Restrict how far you can look up/down while climbing.");
			upsideDownAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Values", "Upside Down Angle", 180f, "The angle (in degrees) to rotate the camera when climbing.");
			minLookAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Values", "Min Look Angle", -65f, "The minimum (up) look angle while climbing.");
			maxLookAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Values", "Max Look Angle", 5f, "The maximum (down) look angle while climbing.");
			if (!modEnabled.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"PEAKside Down is disabled in the config.");
				return;
			}
			Harmony val = new Harmony("PEAKsideDown");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin 'PEAKside Down' has loaded with it's config values.");
		}

		public static bool IsFlipCameraEnabled()
		{
			return flipCameraEnabled.Value;
		}

		public static bool IsFlipControlsEnabled()
		{
			return flipControlsEnabled.Value;
		}

		public static bool IsRestrictLookAngleEnabled()
		{
			return restrictLookAngleEnabled.Value;
		}

		public static float GetUpsideDownAngle()
		{
			return upsideDownAngle.Value;
		}

		public static float GetMinLookAngle()
		{
			return minLookAngle.Value;
		}

		public static float GetMaxLookAngle()
		{
			return maxLookAngle.Value;
		}
	}
	[HarmonyPatch(typeof(CharacterClimbing))]
	public static class ClimbingStatePatches
	{
		[HarmonyPatch("StartClimbRpc")]
		[HarmonyPostfix]
		private static void AfterStartClimb(CharacterClimbing __instance)
		{
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component != (Object)null && component.IsLocal)
			{
				Plugin.IsClimbingUpsideDown = true;
			}
		}

		[HarmonyPatch("StopClimbingRpc")]
		[HarmonyPostfix]
		private static void AfterStopClimb(CharacterClimbing __instance)
		{
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component != (Object)null && component.IsLocal)
			{
				Plugin.IsClimbingUpsideDown = false;
			}
		}
	}
	[HarmonyPatch(typeof(MainCameraMovement), "LateUpdate")]
	public static class CameraUpdatePatch
	{
		private static void Postfix()
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.IsClimbingUpsideDown)
			{
				if (Plugin.IsRestrictLookAngleEnabled())
				{
					Character localCharacter = Character.localCharacter;
					if ((Object)(object)localCharacter != (Object)null)
					{
						float y = Mathf.Clamp(localCharacter.data.lookValues.y, Plugin.GetMinLookAngle(), Plugin.GetMaxLookAngle());
						localCharacter.data.lookValues.y = y;
					}
				}
				if (Plugin.IsFlipCameraEnabled())
				{
					Camera main = Camera.main;
					if ((Object)(object)main != (Object)null)
					{
						Transform transform = ((Component)main).transform;
						Vector3 localEulerAngles = transform.localEulerAngles;
						transform.localEulerAngles = new Vector3(localEulerAngles.x, localEulerAngles.y, Plugin.GetUpsideDownAngle());
					}
				}
				return;
			}
			Camera main2 = Camera.main;
			if ((Object)(object)main2 != (Object)null)
			{
				Transform transform2 = ((Component)main2).transform;
				Vector3 localEulerAngles2 = transform2.localEulerAngles;
				if (Mathf.Abs(localEulerAngles2.z - Plugin.GetUpsideDownAngle()) < 1f || (Mathf.Abs(localEulerAngles2.z) > 1f && localEulerAngles2.z != 0f))
				{
					transform2.localEulerAngles = new Vector3(localEulerAngles2.x, localEulerAngles2.y, 0f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(CharacterClimbing), "GetRequestedPostition")]
	public static class FlipInputPatch
	{
		private static void Prefix(CharacterClimbing __instance)
		{
			if (Plugin.IsClimbingUpsideDown && Plugin.IsFlipControlsEnabled())
			{
				Character component = ((Component)__instance).GetComponent<Character>();
				if ((Object)(object)component != (Object)null && component.IsLocal)
				{
					component.input.movementInput.y *= -1f;
					component.input.movementInput.x *= -1f;
				}
			}
		}
	}
}