Decompiled source of Reverse Camera Keybind v1.0.0

LCBackCam.dll

Decompiled 12 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("LethalCompanyInputUtils")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("LCBackCam")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Reverse Camera Keybind")]
[assembly: AssemblyTitle("LCBackCam")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 LCBackCam
{
	[BepInPlugin("raptureawaits.backcam", "Reverse Camera Keybind", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LCBackCamBase : BaseUnityPlugin
	{
		public class CreateKeybind : LcInputActions
		{
			[InputAction(/*Could not decode attribute arguments.*/)]
			public InputAction ReverseCamKey { get; set; }

			[InputAction(/*Could not decode attribute arguments.*/)]
			public InputAction CamInfoKey { get; set; }
		}

		private const string mod_guid = "raptureawaits.backcam";

		private const string mod_name = "Reverse Camera Keybind";

		private const string mod_version = "1.0.0";

		public static LCBackCamBase instance;

		public static ManualLogSource modlog;

		public static CreateKeybind keys;

		public static float cam_distance = 5f;

		private readonly Harmony harmony = new Harmony("raptureawaits.backcam");

		public int layer_mask;

		public Camera backcam;

		public Renderer visor_renderer;

		public bool cam_reversed = false;

		public void CreateBackCam(Camera gamecam)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			backcam = new GameObject().AddComponent<Camera>();
			backcam.CopyFrom(gamecam);
			((Object)backcam).name = "Backcam";
		}

		public void UpdateBackcamTransform(Camera gamecam)
		{
			//IL_0007: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			bool flag = Physics.Raycast(((Component)gamecam).transform.position, ((Component)gamecam).transform.forward, ref val, cam_distance + 0.5f, layer_mask);
			float num = cam_distance;
			if (flag)
			{
				num = ((RaycastHit)(ref val)).distance - 0.5f;
			}
			Vector3 val2 = ((Component)gamecam).transform.position + num * ((Component)gamecam).transform.forward;
			((Component)backcam).transform.SetPositionAndRotation(val2, ((Component)gamecam).transform.rotation);
			((Component)backcam).transform.LookAt(((Component)gamecam).transform);
		}

		public void LogCameraInfo(Camera c)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0089: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			modlog.LogInfo((object)"------------------------------ CAMERA --------------------------------");
			modlog.LogInfo((object)("Name: " + ((Object)c).name));
			modlog.LogInfo((object)$"- Enabled:   {((Behaviour)c).enabled}\n");
			modlog.LogInfo((object)$"- Pos:       {((Component)c).transform.position}");
			ManualLogSource obj = modlog;
			Quaternion val = ((Component)c).transform.rotation;
			obj.LogInfo((object)$"- Rot:       {((Quaternion)(ref val)).eulerAngles}\n");
			modlog.LogInfo((object)$"- Local Pos: {((Component)c).transform.position}");
			ManualLogSource obj2 = modlog;
			val = ((Component)c).transform.localRotation;
			obj2.LogInfo((object)$"- Local Rot: {((Quaternion)(ref val)).eulerAngles}");
			modlog.LogInfo((object)"----------------------------------------------------------------------\n");
		}

		public void Awake()
		{
			keys = new CreateKeybind();
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			modlog = Logger.CreateLogSource("BackCam");
			harmony.PatchAll();
			modlog.LogInfo((object)"Plugin raptureawaits.backcam is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCBackCam";

		public const string PLUGIN_NAME = "Reverse Camera Keybind";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LCBackCam.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class BackCamPatch
	{
		internal static ManualLogSource modlog = LCBackCamBase.modlog;

		internal static LCBackCamBase b = LCBackCamBase.instance;

		internal static LCBackCamBase.CreateKeybind keys = LCBackCamBase.keys;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(PlayerControllerB __instance, ref Camera ___gameplayCamera)
		{
			if (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled)
			{
				return;
			}
			if ((Object)(object)b.backcam == (Object)null)
			{
				b.CreateBackCam(___gameplayCamera);
				b.visor_renderer = ((Component)((Component)__instance.localVisor).transform.GetChild(0)).GetComponent<Renderer>();
				modlog.LogInfo((object)$"[{((NetworkBehaviour)__instance).OwnerClientId}] Created reverse camera.");
			}
			bool flag = !__instance.inTerminalMenu && !__instance.isPlayerDead && !__instance.isTypingChat && (Object)(object)b.backcam != (Object)null;
			if (keys.ReverseCamKey.IsPressed() && flag && !__instance.isCameraDisabled)
			{
				b.UpdateBackcamTransform(___gameplayCamera);
				if ((Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)b.backcam)
				{
					StartOfRound.Instance.SwitchCamera(b.backcam);
					((Behaviour)___gameplayCamera).enabled = false;
					((Renderer)__instance.thisPlayerModelArms).enabled = false;
					((Renderer)__instance.thisPlayerModel).shadowCastingMode = (ShadowCastingMode)1;
					b.visor_renderer.enabled = false;
					b.cam_reversed = true;
				}
			}
			if ((!keys.ReverseCamKey.IsPressed() || !flag) && b.cam_reversed && (Object)(object)StartOfRound.Instance.activeCamera == (Object)(object)b.backcam)
			{
				StartOfRound.Instance.SwitchCamera(___gameplayCamera);
				((Renderer)__instance.thisPlayerModelArms).enabled = true;
				((Renderer)__instance.thisPlayerModel).shadowCastingMode = (ShadowCastingMode)3;
				((Behaviour)b.backcam).enabled = false;
				b.visor_renderer.enabled = true;
				b.cam_reversed = false;
			}
			if (keys.CamInfoKey.triggered)
			{
				b.LogCameraInfo(StartOfRound.Instance.activeCamera);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class GetLayerMaskPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix(ref int ___collidersAndRoomMask)
		{
			LCBackCamBase.instance.layer_mask = ___collidersAndRoomMask;
			LCBackCamBase.instance.backcam = null;
			LCBackCamBase.instance.cam_reversed = false;
			LCBackCamBase.instance.visor_renderer = null;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}