Decompiled source of First Person v1.0.5

ClassLibrary6.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ClassLibrary6")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary6")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("66d40910-6d0a-4bb0-9793-dd16290cc3c4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Foddy.FirstPerson3D;

[BepInPlugin("com.user.goi.firstperson3d", "Getting Over It First Person 3D", "2.5.0")]
[BepInProcess("GettingOverIt.exe")]
public class FirstPerson3DMod : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <InitializeFirstPersonPerspective>d__32 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public FirstPerson3DMod <>4__this;

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

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

		[DebuggerHidden]
		public <InitializeFirstPersonPerspective>d__32(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

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

		private bool MoveNext()
		{
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if ((Object)(object)<>4__this.player == (Object)null)
			{
				<>4__this.FindPlayerAndComponents();
				<>2__current = null;
				<>1__state = 1;
				return true;
			}
			<>4__this.PurgeCloudSystems();
			<>4__this.CachePlayerRenderers();
			<>4__this.mainCam = Camera.main;
			if ((Object)(object)<>4__this.mainCam != (Object)null)
			{
				<>4__this.cameraTransform = ((Component)<>4__this.mainCam).transform;
				<>4__this.cameraTransform.SetParent((Transform)null);
				<>4__this.mainCam.orthographic = false;
				<>4__this.mainCam.fieldOfView = <>4__this.targetFOV;
				<>4__this.mainCam.nearClipPlane = 0.05f;
				<>4__this.mainCam.farClipPlane = 100000f;
				<>4__this.rotationY = 0f;
				<>4__this.rotationX = 90f;
				<>4__this.facingBackward = false;
				<>4__this.isFlipped = false;
				<>4__this.cameraTransform.localRotation = Quaternion.Euler(0f, <>4__this.rotationX, 0f);
			}
			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();
		}
	}

	private GameObject player;

	private Camera mainCam;

	private Transform cameraTransform;

	private Transform physicsZTarget;

	private float rotationX = 90f;

	private float rotationY = 0f;

	private float lookSensitivity = 3f;

	private bool facingBackward = false;

	private bool isFlipped = false;

	private Vector3 baseEyeLevelOffset = new Vector3(0f, 1.5f, 0f);

	public static float ThirdAxisSliderValue = -0.2f;

	private float manualAdjustmentX = -0.2f;

	private float manualAdjustmentY = -0.5f;

	private float targetFOV = 75f;

	private float minFOV = 65f;

	private float maxFOV = 85f;

	private float zoomSensitivity = 5f;

	private float zoomLerpSpeed = 10f;

	private bool meshesDisabled = false;

	private List<Renderer> playerRenderers = new List<Renderer>();

	private Rect menuButtonRect = new Rect(20f, 20f, 160f, 35f);

	private void Awake()
	{
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

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

	private void Update()
	{
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null || (Object)(object)physicsZTarget == (Object)null)
		{
			FindPlayerAndComponents();
		}
		else
		{
			if ((Object)(object)cameraTransform == (Object)null || (Object)(object)mainCam == (Object)null)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)101))
			{
				facingBackward = !facingBackward;
				rotationX = (facingBackward ? 270f : 90f);
				if (!Input.GetMouseButton(0))
				{
					float num = (isFlipped ? 180f : 0f);
					cameraTransform.localRotation = Quaternion.Euler(0f - rotationY, rotationX, num);
				}
			}
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (Mathf.Abs(axis) > 0.01f)
			{
				targetFOV -= axis * zoomSensitivity * 10f;
				targetFOV = Mathf.Clamp(targetFOV, minFOV, maxFOV);
			}
			mainCam.fieldOfView = Mathf.Lerp(mainCam.fieldOfView, targetFOV, Time.deltaTime * zoomLerpSpeed);
			Vector2 val = Vector2.op_Implicit(Input.mousePosition);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(val.x, (float)Screen.height - val.y);
			bool flag = ((Rect)(ref menuButtonRect)).Contains(val2);
			bool flag2 = (Object)(object)EventSystem.current != (Object)null && EventSystem.current.IsPointerOverGameObject();
			if (Input.GetMouseButton(0) && !flag && !flag2)
			{
				Cursor.visible = false;
				Cursor.lockState = (CursorLockMode)1;
				float num2 = Input.GetAxis("Mouse Y") * lookSensitivity;
				rotationY += num2;
				float num3 = Mathf.Abs(rotationY % 360f);
				if ((num3 > 90f && num3 < 270f && !isFlipped) || ((num3 <= 90f || num3 >= 270f) && isFlipped))
				{
					isFlipped = !isFlipped;
				}
				float num4 = (isFlipped ? 180f : 0f);
				cameraTransform.localRotation = Quaternion.Euler(0f - rotationY, rotationX, num4);
			}
			else if (!Input.GetMouseButton(0))
			{
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
			}
		}
	}

	private void LateUpdate()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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)
		if ((Object)(object)player != (Object)null && (Object)(object)cameraTransform != (Object)null)
		{
			Transform val = physicsZTarget ?? player.transform;
			Vector3 position = player.transform.position + baseEyeLevelOffset;
			position.x += manualAdjustmentX;
			position.y += manualAdjustmentY;
			position.z = val.position.z + ThirdAxisSliderValue;
			cameraTransform.position = position;
		}
	}

	private void OnGUI()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player != (Object)null)
		{
			string text = (meshesDisabled ? "ENABLE MESHES" : "DISABLE ALL MESHES");
			if (GUI.Button(menuButtonRect, text))
			{
				TogglePlayerMeshVisibility();
			}
		}
	}

	private void TogglePlayerMeshVisibility()
	{
		meshesDisabled = !meshesDisabled;
		CachePlayerRenderers();
		foreach (Renderer playerRenderer in playerRenderers)
		{
			if ((Object)(object)playerRenderer != (Object)null)
			{
				playerRenderer.enabled = !meshesDisabled;
			}
		}
	}

	private void CachePlayerRenderers()
	{
		playerRenderers.Clear();
		if ((Object)(object)player == (Object)null)
		{
			return;
		}
		Renderer[] componentsInChildren = player.GetComponentsInChildren<Renderer>(true);
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if ((val is MeshRenderer || val is SkinnedMeshRenderer) && !IsNestedUnderHub(((Component)val).transform) && !IsHammerComponent(((Component)val).transform))
			{
				string name = ((Object)((Component)val).gameObject).name;
				if (name.IndexOf("eye", StringComparison.OrdinalIgnoreCase) >= 0 || string.Equals(name, "Mesh", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "Body", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "Dude", StringComparison.OrdinalIgnoreCase))
				{
					playerRenderers.Add(val);
				}
			}
		}
	}

	private bool IsNestedUnderHub(Transform targetTransform)
	{
		Transform parent = targetTransform.parent;
		while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)player.transform)
		{
			if (string.Equals(((Object)parent).name, "Hub", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			parent = parent.parent;
		}
		return false;
	}

	private bool IsHammerComponent(Transform targetTransform)
	{
		Transform val = targetTransform;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)player.transform)
		{
			string text = ((Object)val).name.ToLower();
			if (text.Contains("handle") || text.Contains("hinge") || text.Contains("hammer") || text.Contains("tip"))
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private void ResetAndFindPlayer()
	{
		player = null;
		physicsZTarget = null;
		mainCam = null;
		cameraTransform = null;
		playerRenderers.Clear();
		meshesDisabled = false;
		((MonoBehaviour)this).StartCoroutine(InitializeFirstPersonPerspective());
	}

	private void FindPlayerAndComponents()
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		player = GameObject.Find("Player") ?? GameObject.Find("Bennett");
		if ((Object)(object)player == (Object)null)
		{
			return;
		}
		object obj = player.transform.Find("Handle");
		if (obj == null)
		{
			obj = player.transform.Find("Hinge");
			if (obj == null)
			{
				Rigidbody componentInChildren = player.GetComponentInChildren<Rigidbody>();
				obj = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).transform : null);
			}
		}
		Transform val = (Transform)obj;
		GameObject val2 = GameObject.Find("Hammer");
		object obj2 = (((Object)(object)val2 != (Object)null) ? val2.transform : null);
		if (obj2 == null)
		{
			GameObject val3 = GameObject.Find("Tip");
			obj2 = (((Object)(object)val3 != (Object)null) ? val3.transform : null);
		}
		Transform val4 = (Transform)obj2;
		physicsZTarget = val ?? val4 ?? player.transform;
		if ((Object)(object)cameraTransform == (Object)null)
		{
			((MonoBehaviour)this).StartCoroutine(InitializeFirstPersonPerspective());
		}
	}

	[IteratorStateMachine(typeof(<InitializeFirstPersonPerspective>d__32))]
	private IEnumerator InitializeFirstPersonPerspective()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <InitializeFirstPersonPerspective>d__32(0)
		{
			<>4__this = this
		};
	}

	private void PurgeCloudSystems()
	{
		GameObject[] array = Object.FindObjectsOfType<GameObject>();
		GameObject[] array2 = array;
		foreach (GameObject val in array2)
		{
			string text = ((Object)val).name.ToLower();
			if (text.Contains("cloud system") || text.Contains("clouds"))
			{
				val.SetActive(false);
			}
		}
	}
}