Decompiled source of ThirdPerson v0.0.1

NGA.ThirdPerson.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Sodalite.ModPanel;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("NGA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Persistent player progression! Raid, stash loot, and deploy with seemless scene/loadout saving.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("NGA.ThirdPerson")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace NGA
{
	[BepInPlugin("NGA.ThirdPerson", "ThirdPerson", "0.0.1")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInProcess("h3vr.exe")]
	public class ThirdPerson : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FVRSceneSettings))]
		[HarmonyPatch("UpdateSpectatorCamera")]
		public class FVRSceneSettingsUpdateSpectatorCamera : MonoBehaviour
		{
			private static void Postfix(FVRSceneSettings __instance)
			{
				if (CheckSkip())
				{
					return;
				}
				bool flag = false;
				bool flag2 = false;
				bool flag3 = (Object)(object)foundCamera != (Object)null && ((Behaviour)foundCamera).enabled;
				if (GM.CurrentMovementManager.Hands[1].Input.TouchpadNorthPressed && GM.CurrentMovementManager.Hands[1].Input.TouchpadDown && EnableThirdPerson.Value)
				{
					flag = true;
				}
				else if (GM.CurrentMovementManager.Hands[1].Input.TouchpadSouthPressed && GM.CurrentMovementManager.Hands[1].Input.TouchpadDown)
				{
					flag2 = true;
				}
				if (flag2)
				{
					if ((Object)(object)foundCamera != (Object)null)
					{
						foundCamera.depth = 0f;
						((Behaviour)foundCamera).enabled = false;
						((Behaviour)GM.CurrentPlayerBody.EyeCam).enabled = true;
					}
				}
				else if (flag || flag3)
				{
					if (flag3 && flag)
					{
						rightLeft *= -1f;
					}
					CreateCamera();
					if ((Object)(object)foundCamera == (Object)null)
					{
						Logger.LogError((object)"No foundCamera");
						return;
					}
					UpdateCameraRig();
					((Behaviour)GM.CurrentPlayerBody.EyeCam).enabled = false;
				}
			}
		}

		private static ConfigEntry<bool> GameEnabled;

		private static ConfigEntry<bool> EnableThirdPerson;

		private static ConfigEntry<int> UntilNextHat;

		private static ConfigEntry<float> DistScale;

		private static ConfigEntry<float> HeightScale;

		private static ConfigEntry<float> SideScale;

		private static ConfigEntry<float> CamRotation;

		private static ConfigEntry<float> CamScale;

		public static Camera eyeCam;

		public static Camera foundCamera;

		public static GameObject ThirdPersonRoot;

		public static GameObject ThirdPersonOffset;

		public static GameObject foundCameraObj;

		public static float rightLeft = 1f;

		public static bool isThirdPersonRn = false;

		public static bool addedNewCam = false;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("NGA.ThirdPerson");
			Logger.LogMessage((object)"New harmony");
			SetUpConfigFields();
			Logger.LogMessage((object)"Setted the fields");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from NGA.ThirdPerson 0.0.1");
		}

		private void SetUpConfigFields()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Expected O, but got Unknown
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			GameEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Overall", "ON/OFF", true, "Completely enable/disable mod");
			EnableThirdPerson = ((BaseUnityPlugin)this).Config.Bind<bool>("ThirdPerson", "ON/OFF", true, "Enter 3rd Person when selected in Spectator");
			DistScale = ((BaseUnityPlugin)this).Config.Bind<float>("ThirdPerson", "Forward-Back Dist from Body", -0.25f, new ConfigDescription("Camera will be a certain distance in front or behind character.", (AcceptableValueBase)new AcceptableValueFloatRangeStep(-100f, 100f, 0.05f), new object[0]));
			HeightScale = ((BaseUnityPlugin)this).Config.Bind<float>("ThirdPerson", "Up-down Dist from Body", 0.25f, new ConfigDescription("Camera will be a certain distance above or below character.", (AcceptableValueBase)new AcceptableValueFloatRangeStep(-100f, 100f, 0.05f), new object[0]));
			SideScale = ((BaseUnityPlugin)this).Config.Bind<float>("ThirdPerson", "Left-right Dist from Body", 0.75f, new ConfigDescription("Camera will be a certain distance on either side of the character.", (AcceptableValueBase)new AcceptableValueFloatRangeStep(-100f, 100f, 0.05f), new object[0]));
			CamRotation = ((BaseUnityPlugin)this).Config.Bind<float>("ThirdPerson", "Camera Rotation", -20f, new ConfigDescription("Camera offset angle left to right.", (AcceptableValueBase)new AcceptableValueFloatRangeStep(-360f, 360f, 1f), new object[0]));
			CamScale = ((BaseUnityPlugin)this).Config.Bind<float>("ThirdPerson", "(FOV) Camera Scale", 1f, new ConfigDescription("Change the scale of the world around you, requires adjusting above vars.", (AcceptableValueBase)new AcceptableValueFloatRangeStep(-100f, 100f, 0.0005f), new object[0]));
			UntilNextHat = ((BaseUnityPlugin)this).Config.Bind<int>("XXXXX", "XXXXX", 8, new ConfigDescription("XXXXXXX", (AcceptableValueBase)new AcceptableValueIntRangeStep(0, 1, 1), new object[0]));
		}

		private static bool CheckSkip()
		{
			return !GameEnabled.Value;
		}

		private static void CreateCamera()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)GameObject.Find("MyOwnCameraNGA") == (Object)null)
			{
				Logger.LogMessage((object)"New ThirdPersonOffset");
				foundCameraObj = new GameObject("MyOwnCameraNGA");
				foundCamera = foundCameraObj.AddComponent<Camera>();
			}
			else if ((Object)(object)foundCameraObj == (Object)null || (Object)(object)foundCamera == (Object)null)
			{
				foundCameraObj = GameObject.Find("MyOwnCameraNGA");
				foundCamera = foundCameraObj.GetComponent<Camera>();
			}
		}

		private static void UpdateCameraRig()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			((Behaviour)foundCamera).enabled = true;
			if (foundCamera.depth != -1f)
			{
				foundCamera.depth = -1f;
			}
			if ((int)foundCamera.stereoTargetEye != 3)
			{
				foundCamera.stereoTargetEye = (StereoTargetEyeMask)3;
			}
			if ((Object)(object)GameObject.Find("ThirdPersonRoot") == (Object)null)
			{
				Logger.LogMessage((object)"New ThirdPersonRoot");
				ThirdPersonRoot = new GameObject("ThirdPersonRoot");
			}
			else if ((Object)(object)ThirdPersonRoot == (Object)null)
			{
				ThirdPersonRoot = GameObject.Find("ThirdPersonRoot");
			}
			if ((Object)(object)GameObject.Find("ThirdPersonOffset") == (Object)null)
			{
				Logger.LogMessage((object)"New ThirdPersonOffset");
				ThirdPersonOffset = new GameObject("ThirdPersonOffset");
			}
			else if ((Object)(object)ThirdPersonOffset == (Object)null)
			{
				ThirdPersonOffset = GameObject.Find("ThirdPersonOffset");
			}
			ThirdPersonOffset.transform.SetParent(ThirdPersonRoot.transform);
			Transform transform = ((Component)foundCamera).transform;
			if ((Object)(object)transform.parent != (Object)(object)ThirdPersonOffset.transform)
			{
				transform.SetParent(ThirdPersonOffset.transform);
			}
			Transform transform2 = ((Component)GM.CurrentPlayerBody).transform;
			ThirdPersonRoot.transform.position = transform2.position;
			ThirdPersonRoot.transform.localRotation = transform2.localRotation;
			ThirdPersonOffset.transform.localRotation = Quaternion.Euler(0f, CamRotation.Value, 0f);
			ThirdPersonOffset.transform.localPosition = new Vector3(rightLeft * SideScale.Value, HeightScale.Value, DistScale.Value);
			ThirdPersonOffset.transform.localScale = new Vector3(CamScale.Value, CamScale.Value, CamScale.Value);
			transform.localRotation = Quaternion.identity;
			transform.localPosition = Vector3.zero;
		}
	}
}