From 2e90c30287e1411470f7a392f54786dcd907c458 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Sep 2022 23:08:16 -0400 Subject: [PATCH 1/2] Revert revert revert revert --- .../CommonCameraHandler.cs | 16 +++++++++++++ .../CommonCameraUtility/ICommonCameraAPI.cs | 13 ++++++++++ .../CameraPatches/NomaiRemoteCameraPatches.cs | 24 +++++++++++++++++++ .../{ => CameraPatches}/OWCameraPatch.cs | 3 ++- NewHorizons/manifest.json | 2 +- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs create mode 100644 NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs create mode 100644 NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs rename NewHorizons/Patches/{ => CameraPatches}/OWCameraPatch.cs (93%) diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs new file mode 100644 index 00000000..2aab1526 --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs @@ -0,0 +1,16 @@ +using NewHorizons.OtherMods.MenuFramework; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public static class CommonCameraHandler + { + private static ICommonCameraAPI _cameraAPI; + + static CommonCameraHandler() + { + _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); + } + + public static void RegisterCustomCamera(OWCamera camera) => _cameraAPI.RegisterCustomCamera(camera); + } +} diff --git a/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs new file mode 100644 index 00000000..bd49375b --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using UnityEngine.Events; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public interface ICommonCameraAPI + { + void RegisterCustomCamera(OWCamera OWCamera); + (OWCamera, Camera) CreateCustomCamera(string name); + UnityEvent EquipTool(); + UnityEvent UnequipTool(); + } +} diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs new file mode 100644 index 00000000..29719c0e --- /dev/null +++ b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using NewHorizons.OtherMods.CommonCameraUtility; +using UnityEngine; + +namespace NewHorizons.Patches.CameraPatches +{ + [HarmonyPatch] + public static class NomaiRemoteCameraPatches + { + [HarmonyPostfix] + [HarmonyPatch(typeof(NomaiRemoteCamera), nameof(NomaiRemoteCamera.Awake))] + public static void NomaiRemoteCamera_Awake(NomaiRemoteCamera __instance) + { + // Ensures that if the player is visible from the remote camera they look normal + CommonCameraHandler.RegisterCustomCamera(__instance._camera); + + // These layers were left on because it doesnt come up in base game (Dreamworld is inactive, player is far away) + __instance._camera.mainCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("DreamSimulation")); + __instance._camera.mainCamera.cullingMask &= ~(1 < Date: Wed, 14 Sep 2022 21:33:41 -0400 Subject: [PATCH 2/2] null check ig idk why a required mod wouldn't be downloaded --- .../CommonCameraUtility/CommonCameraHandler.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs index 2aab1526..e344a57f 100644 --- a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs +++ b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs @@ -1,4 +1,5 @@ using NewHorizons.OtherMods.MenuFramework; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.OtherMods.CommonCameraUtility { @@ -11,6 +12,16 @@ namespace NewHorizons.OtherMods.CommonCameraUtility _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); } - public static void RegisterCustomCamera(OWCamera camera) => _cameraAPI.RegisterCustomCamera(camera); + public static void RegisterCustomCamera(OWCamera camera) + { + if (_cameraAPI != null) + { + _cameraAPI.RegisterCustomCamera(camera); + } + else + { + Logger.LogError("Tried to register custom camera but Common Camera Utility was missing."); + } + } } }