Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ThirdPersonCameraCycle v0.1.4
plugins\F5CameraCycle.dll
Decompiled an hour agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 F5CameraCycle { [BepInPlugin("fan.f5cameracycle", "POV Switcher", "0.1.4")] public sealed class Plugin : BaseUnityPlugin { private enum ViewMode { FirstPerson, ThirdPersonBack, ThirdPersonFront } [HarmonyPatch(typeof(PlayerController), "Update")] private static class PlayerControllerUpdatePatch { [HarmonyPostfix] private static void Postfix() { if ((Object)(object)Instance != (Object)null) { Instance.TickInput(); } } } [HarmonyPatch(typeof(CameraPosition), "Update")] private static class CameraPositionUpdatePatch { [HarmonyPostfix] private static void Postfix() { if ((Object)(object)Instance != (Object)null) { Instance.TickCamera(); } } } public const string PluginGuid = "fan.f5cameracycle"; public const string PluginName = "POV Switcher"; public const string PluginVersion = "0.1.4"; private Harmony _harmony; private ViewMode _mode; private int _lastInputFrame = -1; private int _lastCameraFrame = -1; private bool _frontRotationApplied; private int _collisionMask; private const float CameraDistance = 3f; private const float CameraHeight = 1.82f; private const float CameraCollisionRadius = 0.2f; private const float CameraCollisionPadding = 0.12f; internal static Plugin Instance { get; private set; } private void Awake() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) Instance = this; _collisionMask = LayerMask.GetMask(new string[3] { "Default", "Ground", "Wall" }); if (_collisionMask == 0) { _collisionMask = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()); } _harmony = new Harmony("fan.f5cameracycle"); _harmony.PatchAll(Assembly.GetExecutingAssembly()); Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(OnCameraPreCull)); ((BaseUnityPlugin)this).Logger.LogInfo((object)"POV Switcher loaded. F5: back -> front -> first person."); } private void OnDestroy() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(OnCameraPreCull)); ResetToFirstPerson(); if (_harmony != null) { _harmony.UnpatchSelf(); _harmony = null; } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } private void OnDisable() { ResetToFirstPerson(); } internal void TickInput() { if (_lastInputFrame == Time.frameCount) { return; } _lastInputFrame = Time.frameCount; if (IsGameplayActive() && Input.GetKeyDown((KeyCode)286)) { if (_frontRotationApplied) { RestoreFrontCameraRotation(); } _mode = (ViewMode)((int)(_mode + 1) % 3); if (_mode == ViewMode.FirstPerson) { ResetToFirstPerson(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Camera mode: first person."); } else { ShowLocalPlayerModel(); ((BaseUnityPlugin)this).Logger.LogInfo((object)((_mode == ViewMode.ThirdPersonBack) ? "Camera mode: third person (back)." : "Camera mode: third person (front). ")); } } } internal void TickCamera() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_00ab: 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_00e9: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) if (_lastCameraFrame == Time.frameCount) { return; } _lastCameraFrame = Time.frameCount; if (_mode == ViewMode.FirstPerson) { return; } if (!TryGetCameraContext(out var cameraPosition, out var avatar, out var aimTransform)) { ResetToFirstPerson(); return; } Transform transform = ((Component)avatar).transform; Vector3 val = transform.position + Vector3.up * 1.82f; Vector3 val2; if (_mode == ViewMode.ThirdPersonBack) { Vector3 forward = aimTransform.forward; if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f) { forward = transform.forward; } val2 = -((Vector3)(ref forward)).normalized; } else { Vector3 forward2 = (((Object)(object)avatar.playerAvatarVisuals != (Object)null) ? ((Component)avatar.playerAvatarVisuals).transform : transform).forward; forward2.y = 0f; if (((Vector3)(ref forward2)).sqrMagnitude < 0.0001f) { forward2 = transform.forward; } forward2.y = 0f; val2 = ((Vector3)(ref forward2)).normalized; } Vector3 desiredPosition = val + val2 * 3f; Vector3 val3 = ResolveCameraCollision(val, desiredPosition); cameraPosition.OverridePosition(val3, 0.1f); ((Component)cameraPosition).transform.position = val3; ShowLocalPlayerModel(); } private Vector3 ResolveCameraCollision(Vector3 origin, Vector3 desiredPosition) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //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_001a: 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_0021: 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) //IL_0028: 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) //IL_0062: 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_0054: 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_005c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = desiredPosition - origin; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude <= 0.001f) { return desiredPosition; } Vector3 val2 = val / magnitude; RaycastHit val3 = default(RaycastHit); if (Physics.SphereCast(origin, 0.2f, val2, ref val3, magnitude, _collisionMask, (QueryTriggerInteraction)1)) { float num = Mathf.Max(0f, ((RaycastHit)(ref val3)).distance - 0.12f); return origin + val2 * num; } return desiredPosition; } private void OnCameraPreCull(Camera camera) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)camera == (Object)null || (Object)(object)camera != (Object)(object)Camera.main) { return; } CameraPosition cameraPosition; PlayerAvatar avatar; Transform aimTransform; if (_mode != ViewMode.ThirdPersonFront) { if (_frontRotationApplied) { RestoreFrontCameraRotation(); } } else if (TryGetCameraContext(out cameraPosition, out avatar, out aimTransform)) { Vector3 val = ((Component)avatar).transform.position + Vector3.up * 1.82f - ((Component)camera).transform.position; if (((Vector3)(ref val)).sqrMagnitude > 0.0001f) { ((Component)camera).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up); _frontRotationApplied = true; } } } private static bool TryGetCameraContext(out CameraPosition cameraPosition, out PlayerAvatar avatar, out Transform aimTransform) { cameraPosition = CameraPosition.instance; avatar = PlayerAvatar.instance; aimTransform = (((Object)(object)CameraAim.Instance != (Object)null) ? ((Component)CameraAim.Instance).transform : null); if (IsGameplayActive() && (Object)(object)cameraPosition != (Object)null && (Object)(object)avatar != (Object)null && (Object)(object)aimTransform != (Object)null) { return (Object)(object)cameraPosition.playerTransform != (Object)null; } return false; } private void RestoreFrontCameraRotation() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; Transform val = (((Object)(object)CameraAim.Instance != (Object)null) ? ((Component)CameraAim.Instance).transform : null); if ((Object)(object)main != (Object)null && (Object)(object)val != (Object)null) { ((Component)main).transform.rotation = val.rotation; } _frontRotationApplied = false; } private static bool IsGameplayActive() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 if ((Object)(object)GameDirector.instance == (Object)null) { return false; } if ((int)GameDirector.instance.currentState == 2 && (Object)(object)PlayerAvatar.instance != (Object)null && (Object)(object)CameraPosition.instance != (Object)null) { return (Object)(object)CameraAim.Instance != (Object)null; } return false; } private static void ShowLocalPlayerModel() { PlayerAvatar instance = PlayerAvatar.instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.playerAvatarVisuals != (Object)null) { instance.playerAvatarVisuals.ShowSelfOverride(0.15f); } } private static void ResetToFirstPerson() { //IL_0042: 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) Plugin instance = Instance; if ((Object)(object)instance != (Object)null) { if (instance._frontRotationApplied) { instance.RestoreFrontCameraRotation(); } instance._mode = ViewMode.FirstPerson; } CameraPosition instance2 = CameraPosition.instance; if ((Object)(object)instance2 != (Object)null && (Object)(object)instance2.playerTransform != (Object)null) { instance2.OverridePosition(Vector3.zero, 0f); ((Component)instance2).transform.localRotation = Quaternion.identity; } PlayerAvatar instance3 = PlayerAvatar.instance; if ((Object)(object)instance3 != (Object)null && (Object)(object)instance3.playerAvatarVisuals != (Object)null) { instance3.playerAvatarVisuals.ShowSelfOverride(0f); } } } }