Decompiled source of Camera Enhancements v1.0.0

CameraControl.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CameraControl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CameraControl")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("C2047F6C-0CEA-4956-A09E-E5BAC9A35969")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CameraControl;

[BepInPlugin("CW-BetterCamera", "Better Camera", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static Harmony HARMONY;

	public static ManualLogSource LOGGER;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		HARMONY = new Harmony("CW-BetterCamera");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching CW-BetterCamera!");
		LOGGER = ((BaseUnityPlugin)this).Logger;
		HARMONY.PatchAll(typeof(Plugin));
	}

	[HarmonyPatch(typeof(MainCamera), "Awake")]
	[HarmonyPostfix]
	private static void PatchFOV(MainCamera __instance)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		LOGGER.LogInfo((object)"Setting Main Camera FOV!");
		Camera camera = (Camera)AccessTools.Field(typeof(MainCamera), "cam").GetValue(__instance);
		((Component)__instance).gameObject.AddComponent<Utils.CameraController>().SetCamera(camera);
	}

	[HarmonyPatch(typeof(Flashlight), "ConfigItem")]
	[HarmonyPrefix]
	private static void PatchLightRenderLayer(Flashlight __instance)
	{
		Utils.LIGHT_RENDER_LAYER_MASK = __instance.m_light.renderingLayerMask;
	}

	[HarmonyPatch(typeof(Player), "Awake")]
	[HarmonyPrefix]
	private static void PatchPlayerGlow(Player __instance)
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		LOGGER.LogInfo((object)"Adding Light to Player");
		Light val = ((Component)((Component)__instance).GetComponentsInChildren<Transform>().First((Transform x) => ((Object)((Component)x).gameObject).name.Equals("HeadPosition"))).gameObject.AddComponent<Light>();
		val.color = new Color(0.25f, 1f, 0.25f, 1f);
		val.intensity = 60f;
		val.range = 25f;
		val.shadows = (LightShadows)0;
		val.type = (LightType)2;
		((Component)__instance).gameObject.AddComponent<Utils.LightRenderLayerMaskPatcher>().SetLight(val);
	}

	[HarmonyPatch(typeof(PlayerItems), "DropItem")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> PatchPlayerThrowDistance(IEnumerable<CodeInstruction> il)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		List<CodeInstruction> list = il.ToList();
		for (int i = 0; i < list.Count; i++)
		{
			CodeInstruction val = list[i];
			if (!(val.opcode != OpCodes.Ldc_R4) && !(Math.Abs((float)val.operand - 15f) > float.Epsilon))
			{
				list.RemoveAt(i);
				list.Insert(i, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
				list.Insert(i + 1, new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerItems), "player")));
				list.Insert(i + 2, new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Player), "data")));
				list.Insert(i + 3, new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerData), "throwCharge")));
				list.Insert(i + 4, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Utils), "GetChargeFactorFor", (Type[])null, (Type[])null)));
				break;
			}
		}
		return list;
	}

	[HarmonyPatch(typeof(Player), "Ragdoll")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> PatchIsRagdoll(IEnumerable<CodeInstruction> il)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		return (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
		{
			new CodeInstruction(OpCodes.Ldarg_0, (object)null),
			new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Utils), "IsRagdoll", (Type[])null, (Type[])null)),
			new CodeInstruction(OpCodes.Ret, (object)null)
		};
	}

	[HarmonyPatch(typeof(PlayerController), "Start")]
	[HarmonyPostfix]
	private static void PatchPlayerFixedUpdate(PlayerController __instance)
	{
		((Component)__instance).gameObject.AddComponent<Utils.AdditionalPlayerControls>();
	}
}
public class Utils
{
	public class CameraController : MonoBehaviour
	{
		private Camera m_PlayerCamera;

		private int m_FieldOfView = 70;

		public void SetCamera(Camera cam)
		{
			m_PlayerCamera = cam;
		}

		private void Update()
		{
			if (!((Object)(object)m_PlayerCamera == (Object)null))
			{
				if (Input.GetKeyUp((KeyCode)57))
				{
					m_FieldOfView -= 5;
				}
				if (Input.GetKeyUp((KeyCode)48))
				{
					m_FieldOfView += 5;
				}
				m_FieldOfView = (int)Mathf.Clamp((float)m_FieldOfView, 70f, 120f);
				m_PlayerCamera.fieldOfView = m_FieldOfView;
			}
		}
	}

	public class LightRenderLayerMaskPatcher : MonoBehaviour
	{
		private Light m_Light;

		public void SetLight(Light light)
		{
			m_Light = light;
		}

		private void Update()
		{
			if (!((Object)(object)m_Light == (Object)null) && LIGHT_RENDER_LAYER_MASK != -1 && m_Light.renderingLayerMask != LIGHT_RENDER_LAYER_MASK)
			{
				m_Light.renderingLayerMask = LIGHT_RENDER_LAYER_MASK;
			}
		}
	}

	public class AdditionalPlayerControls : MonoBehaviour
	{
		private Player m_Player;

		private PlayerRagdoll m_Ragdoll;

		private bool m_IsLaunching;

		private float m_LaunchTheta;

		private float m_ShakeTheta;

		private void Start()
		{
			m_Player = ((Component)this).GetComponent<Player>();
			m_Ragdoll = ((Component)this).GetComponent<PlayerRagdoll>();
		}

		private void Update()
		{
			if (Input.GetKey((KeyCode)91) && !m_IsLaunching)
			{
				m_LaunchTheta += Time.deltaTime * 1f;
				m_ShakeTheta += Time.deltaTime;
				if (m_ShakeTheta > 0.2f)
				{
					AddCameraShake(Mathf.Clamp(m_LaunchTheta, 0f, 1f));
					m_ShakeTheta = 0f;
				}
				m_LaunchTheta = Mathf.Clamp(m_LaunchTheta, 0f, 5f);
				Plugin.LOGGER.LogInfo((object)$"Launch Theta: {m_LaunchTheta:F3}");
			}
			if (Input.GetKeyUp((KeyCode)91) && !m_IsLaunching)
			{
				((MonoBehaviour)this).StartCoroutine(DoRagdollLaunch());
			}
			if (Input.GetKeyUp((KeyCode)93))
			{
				ForceLocalPlayerToRagdoll = !ForceLocalPlayerToRagdoll;
			}
		}

		private IEnumerator DoRagdollLaunch()
		{
			m_IsLaunching = true;
			Vector3 lookDir = m_Player.data.lookDirection;
			ManualLogSource lOGGER = Plugin.LOGGER;
			Vector3 val = lookDir;
			lOGGER.LogInfo((object)("Look Dir -> " + ((object)(Vector3)(ref val)).ToString()));
			IsLocalPlayerInRagdoll = true;
			yield return (object)new WaitForSeconds(0.25f);
			((List<Rigidbody>)AccessTools.Field(typeof(PlayerRagdoll), "rigList").GetValue(m_Ragdoll)).ForEach(delegate(Rigidbody x)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				x.AddForce(lookDir * (150f * m_LaunchTheta), (ForceMode)1);
			});
			yield return (object)new WaitForSeconds(3f);
			IsLocalPlayerInRagdoll = false;
			m_LaunchTheta = 0f;
			m_ShakeTheta = 0f;
			yield return (object)new WaitForSeconds(5f);
			m_IsLaunching = false;
		}
	}

	public static int LIGHT_RENDER_LAYER_MASK = -1;

	public static bool ForceLocalPlayerToRagdoll = false;

	public static bool IsLocalPlayerInRagdoll = false;

	public static float GetChargeFactorFor(float charge)
	{
		if (!(charge > 0.9f))
		{
			return 15f;
		}
		return 45f;
	}

	public static bool IsRagdoll(Player player)
	{
		PlayerData data = player.data;
		if (!ForceLocalPlayerToRagdoll && !IsLocalPlayerInRagdoll && !data.dead)
		{
			return data.fallTime > 0f;
		}
		return true;
	}

	public static void AddCameraShake(float amount = 1f, float duration = 0.2f, float scale = 15f)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		GamefeelHandler instance = GamefeelHandler.instance;
		((PerlinShake)AccessTools.Field(typeof(GamefeelHandler), "perlin").GetValue(instance)).AddShake(amount, duration, scale);
	}
}