[ThirdPerson] Set camera cull mask instead of disabling

Least hacky fix to correct nameplate issue.
This commit is contained in:
NotAKidoS 2023-05-07 22:19:15 -05:00
parent 6f17010cae
commit 82eeced7cc
4 changed files with 10 additions and 18 deletions

View file

@ -17,6 +17,7 @@ internal static class CameraLogic
private static float _scale = 1f;
private static Camera _ourCam;
private static Camera _desktopCam;
private static int _desktopCamMask;
private static CameraFovClone _cameraFovClone;
internal static CameraLocation CurrentLocation = CameraLocation.Default;
@ -36,14 +37,14 @@ internal static class CameraLogic
set
{
_state = value;
_desktopCam.enabled = !_state;
_desktopCam.cullingMask = _state ? 0 : _desktopCamMask;
_ourCam.gameObject.SetActive(_state);
}
}
private static bool _setupPostProcessing;
private static readonly FieldInfo _ppResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_Resources", BindingFlags.NonPublic | BindingFlags.Instance);
private static readonly FieldInfo _ppOldResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_OldResources", BindingFlags.NonPublic | BindingFlags.Instance);
static bool _setupPostProcessing;
static readonly FieldInfo _ppResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_Resources", BindingFlags.NonPublic | BindingFlags.Instance);
static readonly FieldInfo _ppOldResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_OldResources", BindingFlags.NonPublic | BindingFlags.Instance);
internal static IEnumerator SetupCamera()
{
@ -54,6 +55,7 @@ internal static class CameraLogic
_cameraFovClone = _ourCam.gameObject.AddComponent<CameraFovClone>();
_desktopCam = PlayerSetup.Instance.desktopCamera.GetComponent<Camera>();
_desktopCamMask = _desktopCam.cullingMask;
_cameraFovClone.targetCamera = _desktopCam;
_ourCam.transform.SetParent(_desktopCam.transform);
@ -178,7 +180,6 @@ internal static class CameraLogic
}
private static void ResetDist() => _dist = 0;
internal static void IncrementDist() { _dist += 0.25f; RelocateCam(CurrentLocation); }
internal static void DecrementDist() { _dist -= 0.25f; RelocateCam(CurrentLocation); }
internal static void ScrollDist(float sign) { _dist += sign * 0.25f; RelocateCam(CurrentLocation); }
internal static void AdjustScale(float height) { _scale = height; RelocateCam(CurrentLocation); }
}

View file

@ -1,9 +1,7 @@
using ABI.CCK.Components;
using ABI_RC.Core.Player;
using ABI_RC.Core.Util.Object_Behaviour;
using MelonLoader;
using System.Reflection;
using UnityEngine;
using static NAK.ThirdPerson.CameraLogic;
namespace NAK.ThirdPerson;
@ -24,16 +22,10 @@ internal static class Patches
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupIKScaling), BindingFlags.NonPublic | BindingFlags.Instance),
postfix: typeof(Patches).GetMethod(nameof(OnScaleAdjusted), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod()
);
harmony.Patch(
typeof(CameraFacingObject).GetMethod(nameof(CameraFacingObject.Start), BindingFlags.NonPublic | BindingFlags.Instance),
postfix: typeof(Patches).GetMethod(nameof(OnCameraFacingObjectStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod()
);
}
//Copy camera settings & postprocessing components
private static void OnWorldStart() => CopyPlayerCamValues();
//Adjust camera distance with height as modifier
private static void OnScaleAdjusted(float height) => AdjustScale(height);
//Fix bug when in thirdperson and desktop camera is disabled for performance
private static void OnCameraFacingObjectStart(ref Camera ___m_Camera) { if (___m_Camera == null) ___m_Camera = PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>(); }
}

View file

@ -20,7 +20,7 @@ using System.Reflection;
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
[assembly: MelonColor(255, 139, 0, 139)]
namespace NAK.ThirdPerson.Properties;
internal static class AssemblyInfoParams

View file

@ -1,5 +1,4 @@
using MelonLoader;
using System.Reflection;
using UnityEngine;
using static NAK.ThirdPerson.CameraLogic;
@ -22,8 +21,8 @@ public class ThirdPerson : MelonMod
// Prevents scrolling while in Menus or UnityExplorer
if (State && Cursor.lockState == CursorLockMode.Locked)
{
if (Input.GetAxis("Mouse ScrollWheel") > 0f) IncrementDist();
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) DecrementDist();
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll != 0f) ScrollDist(Mathf.Sign(scroll));
}
if (!Input.GetKey(KeyCode.LeftControl)) return;