diff --git a/OriginShift/Main.cs b/OriginShift/Main.cs index 7989cab..313fa9d 100644 --- a/OriginShift/Main.cs +++ b/OriginShift/Main.cs @@ -44,6 +44,7 @@ public class OriginShiftMod : MelonMod ApplyPatches(typeof(Patches.DbJobsAvatarManagerPatches)); // dynamic bones ApplyPatches(typeof(Patches.CVRPortalManagerPatches)); // portals ApplyPatches(typeof(Patches.RCC_SkidmarksManagerPatches)); // skidmarks + ApplyPatches(typeof(Patches.CVRPickupObjectPatches)); // pickup object respawn height ApplyPatches(typeof(Patches.PortableCameraPatches)); // camera occlusion culling ApplyPatches(typeof(Patches.PathingCameraPatches)); // camera occlusion culling diff --git a/OriginShift/OriginShift/Player/OriginShiftObjectSyncReceiver.cs b/OriginShift/OriginShift/Player/OriginShiftObjectSyncReceiver.cs index 3aba111..f305c52 100644 --- a/OriginShift/OriginShift/Player/OriginShiftObjectSyncReceiver.cs +++ b/OriginShift/OriginShift/Player/OriginShiftObjectSyncReceiver.cs @@ -17,7 +17,6 @@ public class OriginShiftObjectSyncReceiver : MonoBehaviour OriginShiftMod.Logger.Error("OriginShiftObjectSyncReceiver: No CVRObjectSync found on GameObject: " + gameObject.name, this); enabled = false; } - OriginShiftManager.OnOriginShifted += OnOriginShifted; } private void OnEnable() diff --git a/OriginShift/OriginShift/Player/OriginShiftPickupObjectReceiver.cs b/OriginShift/OriginShift/Player/OriginShiftPickupObjectReceiver.cs new file mode 100644 index 0000000..e22ddee --- /dev/null +++ b/OriginShift/OriginShift/Player/OriginShiftPickupObjectReceiver.cs @@ -0,0 +1,43 @@ +using ABI.CCK.Components; +using UnityEngine; + +namespace NAK.OriginShift; + +public class OriginShiftPickupObjectReceiver : MonoBehaviour +{ + private CVRPickupObject _pickupObject; + + #region Unity Events + + private void Start() + { + _pickupObject = GetComponent(); + if (_pickupObject == null) + { + OriginShiftMod.Logger.Error("OriginShiftPickupObjectReceiver requires a CVRPickupObject component!"); + enabled = false; + return; + } + } + + private void OnEnable() + { + OriginShiftManager.OnOriginShifted += OnOriginShifted; + } + + private void OnDisable() + { + OriginShiftManager.OnOriginShifted -= OnOriginShifted; + } + + #endregion Unity Events + + #region Origin Shift Events + + private void OnOriginShifted(Vector3 shift) + { + _pickupObject._respawnHeight += shift.y; + } + + #endregion Origin Shift Events +} \ No newline at end of file diff --git a/OriginShift/OriginShift/Player/OriginShiftSpawnableReceiver.cs b/OriginShift/OriginShift/Player/OriginShiftSpawnableReceiver.cs index 41ffd23..f0e2ec0 100644 --- a/OriginShift/OriginShift/Player/OriginShiftSpawnableReceiver.cs +++ b/OriginShift/OriginShift/Player/OriginShiftSpawnableReceiver.cs @@ -17,7 +17,6 @@ public class OriginShiftSpawnableReceiver : MonoBehaviour OriginShiftMod.Logger.Error("OriginShiftSpawnableReceiver: No CVRSpawnable found on GameObject: " + gameObject.name, this); enabled = false; } - OriginShiftManager.OnOriginShifted += OnOriginShifted; } private void OnEnable() diff --git a/OriginShift/Patches.cs b/OriginShift/Patches.cs index 7e1c7e8..8e17cb0 100644 --- a/OriginShift/Patches.cs +++ b/OriginShift/Patches.cs @@ -63,7 +63,7 @@ internal static class CVRSpawnablePatches [HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.Start))] private static void Postfix_CVRSpawnable_Start(ref CVRSpawnable __instance) { - //__instance.AddComponentIfMissing(); //todo: investigate if this is needed + __instance.AddComponentIfMissing(); //todo: investigate if this is needed // test adding to the wrapper of the spawnable Transform wrapper = __instance.transform.parent; @@ -216,12 +216,12 @@ internal static class CVRSyncHelperPatches internal static class CVRObjectSyncPatches { - // [HarmonyPostfix] - // [HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.Start))] - // private static void Postfix_CVRObjectSync_Start(ref CVRObjectSync __instance) - // { - // __instance.gameObject.AddComponentIfMissing(); // todo: investigate if this is needed - // } + [HarmonyPostfix] + [HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.Start))] + private static void Postfix_CVRObjectSync_Start(ref CVRObjectSync __instance) + { + __instance.gameObject.AddComponentIfMissing(); // todo: investigate if this is needed + } [HarmonyPrefix] // inbound object sync [HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.receiveNetworkData))] @@ -282,4 +282,14 @@ internal static class CVRPortalManagerPatches } } +internal static class CVRPickupObjectPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(CVRPickupObject), nameof(CVRPickupObject.Start))] + private static void Postfix_CVRPickupObject_Start(ref CVRPickupObject __instance) + { + __instance.gameObject.AddComponentIfMissing(); + } +} + #endif \ No newline at end of file