Decompiled source of NightForcePlus v1.0.5

NightForcePlus.dll

Decompiled 2 weeks ago
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HLin_Mods.SharedBubble;
using HarmonyLib;
using OtherLoader;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace HLin_Mods.NightForcePlus
{
	[BepInPlugin("HLin_Mods.NightForcePlus", "NightForcePlus", "1.0.5")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class NightForcePlusPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "HLin_Mods.NightForcePlus");
			OtherLoader.RegisterDirectLoad(BasePath, "HLin_Mods.NightForcePlus", "", "", "hlin-nightforceplus", "");
		}
	}
	public class BubbleLevel : MonoBehaviour
	{
		[Header("FVRAttachment")]
		public GameObject baseObject = null;

		[Header("FVRAttachment")]
		public FVRFireArmAttachment attachment = null;

		[Header("LevelBubble")]
		public GameObject level_bubble = null;

		private void Start()
		{
		}

		private void Update()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			float num = ((!((Object)(object)attachment != (Object)null) || !((Object)(object)attachment.curMount != (Object)null)) ? baseObject.transform.eulerAngles.z : ((Component)attachment.curMount.GetRootMount()).transform.eulerAngles.z);
			if (180f < num && num < 360f)
			{
				num -= 360f;
			}
			Vector3 localPosition = level_bubble.transform.localPosition;
			localPosition.x = Mathf.Clamp(-0.0084f + num / 8f, -0.33f, 0.33f);
			level_bubble.transform.localPosition = localPosition;
		}
	}
}
namespace HLin_Mods.SharedBubble
{
	public static class GravityBubbleLevelMotion
	{
		public struct State
		{
			public float BubbleVelocity;

			public Transform BubbleTransform;

			public Transform MovementSpace;

			public Vector3 CachedGravity;

			public Vector3 CachedGravityDirection;

			public float CachedFullScaleAngle;

			public float CachedFullScaleGravity;

			public bool HasCachedGravityDirection;

			public bool HasCachedFullScaleGravity;

			public bool Initialized;
		}

		public static bool Initialize(GameObject baseObject, GameObject levelBubble, ref State state)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)baseObject == (Object)null || (Object)(object)levelBubble == (Object)null)
			{
				return false;
			}
			state.BubbleTransform = levelBubble.transform;
			state.MovementSpace = ((!((Object)(object)state.BubbleTransform.parent != (Object)null)) ? baseObject.transform : state.BubbleTransform.parent);
			RefreshGravityDirection(Physics.gravity, ref state);
			state.Initialized = (Object)(object)state.MovementSpace != (Object)null;
			return state.Initialized;
		}

		public static bool Step(GameObject baseObject, GameObject levelBubble, float centerLocalX, float minimumLocalX, float maximumLocalX, float fullScaleAngleDegrees, float restoringAcceleration, float fluidDrag, float staticFrictionDistance, float settleVelocity, float maximumVelocity, ref State state)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			if ((!state.Initialized || (Object)(object)state.BubbleTransform == (Object)null || (Object)(object)state.MovementSpace == (Object)null) && !Initialize(baseObject, levelBubble, ref state))
			{
				return false;
			}
			Vector3 gravity = Physics.gravity;
			if (state.HasCachedGravityDirection)
			{
				Vector3 val = gravity - state.CachedGravity;
				if (!(((Vector3)(ref val)).sqrMagnitude > 1E-06f))
				{
					goto IL_007f;
				}
			}
			RefreshGravityDirection(gravity, ref state);
			goto IL_007f;
			IL_007f:
			Vector3 right = state.MovementSpace.right;
			if (!state.HasCachedGravityDirection || ((Vector3)(ref right)).sqrMagnitude < 1E-06f)
			{
				return true;
			}
			float gravityAlongTravel = Mathf.Clamp(Vector3.Dot(state.CachedGravityDirection, right), -1f, 1f);
			float gravityTarget = GetGravityTarget(GetFullScaleTravel(gravityAlongTravel, fullScaleAngleDegrees, ref state), centerLocalX, minimumLocalX, maximumLocalX);
			Vector3 localPosition = state.BubbleTransform.localPosition;
			float num = gravityTarget - localPosition.x;
			if (Mathf.Abs(num) <= staticFrictionDistance && Mathf.Abs(state.BubbleVelocity) <= settleVelocity)
			{
				localPosition.x = gravityTarget;
				state.BubbleVelocity = 0f;
			}
			else
			{
				float num2 = restoringAcceleration * num - fluidDrag * state.BubbleVelocity;
				state.BubbleVelocity = Mathf.Clamp(state.BubbleVelocity + num2 * Time.fixedDeltaTime, 0f - maximumVelocity, maximumVelocity);
				float num3 = localPosition.x + state.BubbleVelocity * Time.fixedDeltaTime;
				if (num3 <= minimumLocalX)
				{
					localPosition.x = minimumLocalX;
					if (state.BubbleVelocity < 0f)
					{
						state.BubbleVelocity = 0f;
					}
				}
				else if (num3 >= maximumLocalX)
				{
					localPosition.x = maximumLocalX;
					if (state.BubbleVelocity > 0f)
					{
						state.BubbleVelocity = 0f;
					}
				}
				else
				{
					localPosition.x = num3;
				}
			}
			state.BubbleTransform.localPosition = localPosition;
			return true;
		}

		private static void RefreshGravityDirection(Vector3 gravity, ref State state)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			state.CachedGravity = gravity;
			float sqrMagnitude = ((Vector3)(ref gravity)).sqrMagnitude;
			if (sqrMagnitude < 1E-06f)
			{
				state.CachedGravityDirection = Vector3.zero;
				state.HasCachedGravityDirection = false;
			}
			else
			{
				state.CachedGravityDirection = gravity / Mathf.Sqrt(sqrMagnitude);
				state.HasCachedGravityDirection = true;
			}
		}

		private static float GetGravityTarget(float gravityAlongTravel, float centerLocalX, float minimumLocalX, float maximumLocalX)
		{
			if (gravityAlongTravel >= 0f)
			{
				return centerLocalX - gravityAlongTravel * (centerLocalX - minimumLocalX);
			}
			return centerLocalX - gravityAlongTravel * (maximumLocalX - centerLocalX);
		}

		private static float GetFullScaleTravel(float gravityAlongTravel, float fullScaleAngleDegrees, ref State state)
		{
			float num = Mathf.Clamp(fullScaleAngleDegrees, 1f, 45f);
			if (!state.HasCachedFullScaleGravity || Mathf.Abs(state.CachedFullScaleAngle - num) > 0.0001f)
			{
				state.CachedFullScaleAngle = num;
				state.CachedFullScaleGravity = Mathf.Sin(num * ((float)Math.PI / 180f));
				state.HasCachedFullScaleGravity = true;
			}
			return Mathf.Clamp(gravityAlongTravel / state.CachedFullScaleGravity, -1f, 1f);
		}
	}
}
namespace HLin_Mods.BubbleLevelScope
{
	public class BubbleLevelScope : MonoBehaviour
	{
		private const float ScopeCenterLocalX = -0.0084f;

		private const float ScopeMinimumLocalX = -0.33f;

		private const float ScopeMaximumLocalX = 0.33f;

		private const float ScopeFullScaleAngleDegrees = 2.64f;

		private const float ScopeRestoringAcceleration = 60f;

		private const float ScopeFluidDrag = 15f;

		private const float ScopeStaticFrictionDistance = 5E-05f;

		private const float ScopeSettleVelocity = 0.0005f;

		private const float ScopeMaximumVelocity = 1.2f;

		[Header("BaseObject")]
		public GameObject baseObject = null;

		[Header("FVRAttachment")]
		public FVRFireArmAttachment attachment = null;

		[Header("LevelBubble")]
		public GameObject level_bubble = null;

		private GravityBubbleLevelMotion.State motionState;

		private void Awake()
		{
			if (!GravityBubbleLevelMotion.Initialize(baseObject, level_bubble, ref motionState))
			{
				Debug.LogWarning((object)"BubbleLevelScope disabled because its base object or bubble reference is missing.", (Object)(object)this);
				((Behaviour)this).enabled = false;
			}
		}

		private void FixedUpdate()
		{
			if (!GravityBubbleLevelMotion.Step(baseObject, level_bubble, -0.0084f, -0.33f, 0.33f, 2.64f, 60f, 15f, 5E-05f, 0.0005f, 1.2f, ref motionState))
			{
				((Behaviour)this).enabled = false;
			}
		}
	}
}