Decompiled source of ImprovedCameraMovement v1.0.1

ukmod_improvedcamera.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using ULTRAKILL.Portal;
using UnityEngine;
using ukmod_improvedcamera.src.main;
using ukmod_improvedcamera.src.util;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ukmod_improvedcamera")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ukmod_improvedcamera")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("eaf9a541-f3ca-446e-90b8-e42e924004e9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ukmod_improvedcamera
{
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct PluginInfo
	{
		public const string PLUGIN_GUID = "com.gunnanthapop.ukmod_improvedcamera";

		public const string PLUGIN_NAME = "Improved Camera Movement";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("com.gunnanthapop.ukmod_improvedcamera", "Improved Camera Movement", "1.0.0")]
	public class MainPluginModule : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("com.gunnanthapop.ukmod_improvedcamera");
			val.PatchAll();
		}
	}
}
namespace ukmod_improvedcamera.src.util
{
	public class SpringFloat
	{
		public float frequency = 5f;

		public float dampingRatio = 0.5f;

		public float Target;

		public float Position;

		public float Velocity;

		public SpringFloat(float startingPosition, float target)
		{
			Position = startingPosition;
			Target = target;
			Velocity = 0f;
		}

		public void Reset()
		{
			Position = Target;
			Velocity = 0f;
		}

		public void Update(float deltaTime)
		{
			if (!(deltaTime <= 0f))
			{
				float num = frequency * 2f * (float)Math.PI;
				float num2 = Position - Target;
				float num3 = (0f - num) * num * num2 - 2f * dampingRatio * num * Velocity;
				Velocity += num3 * deltaTime;
				Position += Velocity * deltaTime;
			}
		}
	}
	public class SpringVector3
	{
		public float frequency = 5f;

		public float dampingRatio = 0.5f;

		public Vector3 Target;

		public Vector3 Position;

		public Vector3 Velocity;

		public SpringVector3(Vector3 startingPosition, Vector3 target)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Position = startingPosition;
			Target = target;
			Velocity = Vector3.zero;
		}

		public void Reset()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Position = Target;
			Velocity = Vector3.zero;
		}

		public void Update(float deltaTime)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (!(deltaTime <= 0f))
			{
				float num = frequency * 2f * (float)Math.PI;
				Vector3 val = Position - Target;
				Vector3 val2 = (0f - num) * num * val - 2f * dampingRatio * num * Velocity;
				Velocity += val2 * deltaTime;
				Position += Velocity * deltaTime;
			}
		}
	}
}
namespace ukmod_improvedcamera.src.patches
{
	[HarmonyPatch(typeof(Revolver), "Shoot")]
	internal class RevolverPatches
	{
		private static void Postfix(Revolver __instance, int shotType)
		{
			float num = 0.25f;
			if (__instance.altVersion)
			{
				num *= 2f;
			}
			if (shotType == 2)
			{
				num *= 2f;
			}
			MonoSingleton<CameraMovementController>.Instance.camShakeEffect.StartBasicShake(num);
		}
	}
}
namespace ukmod_improvedcamera.src.patches.newmovementpatches
{
	[HarmonyPatch(typeof(NewMovement), "OnTravel")]
	internal class OnTravelPatch
	{
		private static void Postfix(NewMovement __instance, PortalTravelDetails details)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			MonoSingleton<CameraMovementController>.Instance.viewRollEffect.OnPortalTravesal(details);
		}
	}
	[HarmonyPatch(typeof(NewMovement), "Awake")]
	internal class AwakePatch
	{
		private static void Postfix(NewMovement __instance)
		{
			__instance.rb.interpolation = (RigidbodyInterpolation)1;
		}
	}
}
namespace ukmod_improvedcamera.src.patches.cameracontroller
{
	[HarmonyPatch(typeof(CameraController), "Awake")]
	internal class AwakePatch
	{
		private static void Postfix(CameraController __instance)
		{
			((Component)__instance).gameObject.AddComponent<CameraMovementController>();
		}
	}
	[HarmonyPatch(typeof(CameraController), "LateUpdate")]
	internal class LateUpdatePatch
	{
		private static void Postfix(CameraController __instance)
		{
			__instance.StopShake();
			__instance.tiltRotationZ = 0f;
			__instance.tiltRotationZSmooth = 0f;
		}
	}
	[HarmonyPatch(typeof(CameraController), "CameraShake")]
	internal class CameraShakePatch
	{
		private static void Prefix(float shakeAmount)
		{
			MonoSingleton<CameraMovementController>.Instance.camShakeEffect.StartBasicShake(shakeAmount);
		}
	}
	[HarmonyPatch(typeof(CameraController), "ApplyRotations")]
	internal class ApplyRotationsPatch
	{
		private static bool Prefix(CameraController __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0039: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = MonoSingleton<CameraMovementController>.Instance.FinalResult;
			if (GameStateManager.Instance.CameraLocked)
			{
				val = Vector3.zero;
			}
			__instance.player.transform.localRotation = __instance.gravityRotation * Quaternion.AngleAxis(__instance.rotationY, Vector3.up);
			MonoSingleton<NewMovement>.Instance.rb.rotation = __instance.player.transform.rotation;
			((Component)__instance).transform.localRotation = Quaternion.AngleAxis(0f - __instance.rotationX, Vector3.right) * Quaternion.AngleAxis(__instance.transitionRotationZ, Vector3.forward) * Quaternion.AngleAxis(__instance.tiltRotationZ, Vector3.forward) * __instance.rotationOffset * Quaternion.Euler(val);
			((Component)__instance.hudCamera).transform.GetChild(0).localRotation = Quaternion.Euler(-val);
			return false;
		}
	}
}
namespace ukmod_improvedcamera.src.main
{
	public class CameraMovementController : MonoSingleton<CameraMovementController>
	{
		public Vector3 FinalResult;

		public List<Vector3> currentFrameVectorList = new List<Vector3>();

		public CameraShakeEffect camShakeEffect;

		public ViewRollEffect viewRollEffect;

		private void Awake()
		{
			camShakeEffect = ((Component)this).gameObject.AddComponent<CameraShakeEffect>();
			viewRollEffect = ((Component)this).gameObject.AddComponent<ViewRollEffect>();
		}

		private void Update()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			Vector3 val = Vector3.zero;
			foreach (Vector3 currentFrameVector in currentFrameVectorList)
			{
				val += currentFrameVector;
			}
			currentFrameVectorList.Clear();
			FinalResult = val;
		}
	}
	public class CameraShakeInstance
	{
		public float Amplitude;

		public float Frequency;

		public float Duration;

		public float FadeInDuration;

		public float FadeOutDuration;

		public float Age;

		public bool IsDestroyed()
		{
			return Age > Duration;
		}

		public CameraShakeInstance(float amplitude, float frequency, float duration, float fadeIn, float fadeOut)
		{
			Amplitude = amplitude;
			Frequency = frequency;
			Duration = duration;
			FadeInDuration = fadeIn;
			FadeOutDuration = fadeOut;
			Age = 0f;
		}

		public void Update(float deltaTime)
		{
			Age += deltaTime;
		}

		public Vector3 GetCurrentOffset()
		{
			//IL_0008: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (IsDestroyed())
			{
				return Vector3.zero;
			}
			float num = Age * Frequency;
			float num2 = Mathf.Sin(num);
			float num3 = Mathf.Cos(num / 2f);
			float num4 = Mathf.Sin(num / 2f);
			float num5 = 1f;
			if (Age < FadeInDuration)
			{
				num5 = Age / FadeInDuration;
			}
			else if (Age > Duration - FadeOutDuration)
			{
				float num6 = Duration - Age;
				num5 = num6 / FadeOutDuration;
			}
			return new Vector3(num2, num3, num4) * Amplitude * num5;
		}
	}
	public class CameraShakeEffect : MonoBehaviour
	{
		private List<CameraShakeInstance> activeShakes = new List<CameraShakeInstance>();

		public void StartBasicShake(float shakeAmount)
		{
			CameraShakeInstance item = new CameraShakeInstance(shakeAmount / 2f, 150f, Mathf.Max(shakeAmount / 3f, 0.5f), 0.05f, 0.275f);
			activeShakes.Add(item);
		}

		public void StartShake(float amplitude, float frequency, float duration, float fadein, float fadeout)
		{
			CameraShakeInstance item = new CameraShakeInstance(amplitude, frequency, duration, fadein, fadeout);
			activeShakes.Add(item);
		}

		private void Update()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			for (int num = activeShakes.Count - 1; num >= 0; num--)
			{
				CameraShakeInstance cameraShakeInstance = activeShakes[num];
				cameraShakeInstance.Update(Time.unscaledDeltaTime);
				if (cameraShakeInstance.IsDestroyed())
				{
					activeShakes.RemoveAt(num);
				}
				else
				{
					val += cameraShakeInstance.GetCurrentOffset();
				}
			}
			val *= MonoSingleton<PrefsManager>.Instance.GetFloat("screenShake", 0f);
			MonoSingleton<CameraMovementController>.Instance.currentFrameVectorList.Add(val);
		}
	}
	public class ViewRollEffect : MonoBehaviour
	{
		private Rigidbody rb;

		private Vector3 rbPosTarget;

		private SpringVector3 trackingSpring = new SpringVector3(Vector3.zero, Vector3.zero);

		private Vector3 SpringOffsetBeforePortal;

		private void Awake()
		{
			rb = ((Component)((Component)this).transform.parent).GetComponent<Rigidbody>();
		}

		private void Start()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			trackingSpring.Position = rb.position;
		}

		private void FixedUpdate()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			rbPosTarget = rb.position;
		}

		private void Update()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			trackingSpring.frequency = 2.5f;
			trackingSpring.dampingRatio = 0.5f;
			trackingSpring.Target = rbPosTarget;
			trackingSpring.Update(Time.deltaTime);
			float num = Vector3.Dot(trackingSpring.Position - trackingSpring.Target, ((Component)this).transform.up);
			float num2 = Vector3.Dot(trackingSpring.Position - trackingSpring.Target, ((Component)this).transform.right) * -0.5f;
			float num3 = Vector3.Dot(trackingSpring.Position - trackingSpring.Target, ((Component)this).transform.right);
			Vector3 item = default(Vector3);
			((Vector3)(ref item))..ctor(num, num2, num3);
			if (((Component)this).gameObject.GetComponent<CameraController>().tilt)
			{
				MonoSingleton<CameraMovementController>.Instance.currentFrameVectorList.Add(item);
			}
			SpringOffsetBeforePortal = trackingSpring.Position - trackingSpring.Target;
		}

		public void OnPortalTravesal(PortalTravelDetails details)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			trackingSpring.Position = rb.position + SpringOffsetBeforePortal;
			trackingSpring.Target = rb.position;
			rbPosTarget = rb.position;
		}
	}
}