mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[OriginShift] Fix Spawnable & Object Sync cached net pos
This commit is contained in:
parent
ab8ccbb67f
commit
512ffe38b8
3 changed files with 100 additions and 1 deletions
|
@ -0,0 +1,46 @@
|
||||||
|
using ABI.CCK.Components;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NAK.OriginShift;
|
||||||
|
|
||||||
|
public class OriginShiftObjectSyncReceiver : MonoBehaviour
|
||||||
|
{
|
||||||
|
private CVRObjectSync _objectSync;
|
||||||
|
|
||||||
|
#region Unity Events
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_objectSync = GetComponent<CVRObjectSync>();
|
||||||
|
if (_objectSync == null)
|
||||||
|
{
|
||||||
|
OriginShiftMod.Logger.Error("OriginShiftObjectSyncReceiver: No CVRObjectSync found on GameObject: " + gameObject.name, this);
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
OriginShiftManager.OnOriginShifted += OnOriginShifted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
OriginShiftManager.OnOriginShifted += OnOriginShifted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
OriginShiftManager.OnOriginShifted -= OnOriginShifted;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Unity Events
|
||||||
|
|
||||||
|
#region Origin Shift Events
|
||||||
|
|
||||||
|
private void OnOriginShifted(Vector3 shift)
|
||||||
|
{
|
||||||
|
// idc, just shift all of them
|
||||||
|
_objectSync._oldData.position += shift;
|
||||||
|
_objectSync._currData.position += shift;
|
||||||
|
_objectSync._futureData.position += shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Origin Shift Events
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
using ABI.CCK.Components;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NAK.OriginShift;
|
||||||
|
|
||||||
|
public class OriginShiftSpawnableReceiver : MonoBehaviour
|
||||||
|
{
|
||||||
|
private CVRSpawnable _spawnable;
|
||||||
|
|
||||||
|
#region Unity Events
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_spawnable = GetComponent<CVRSpawnable>();
|
||||||
|
if (_spawnable == null)
|
||||||
|
{
|
||||||
|
OriginShiftMod.Logger.Error("OriginShiftSpawnableReceiver: No CVRSpawnable found on GameObject: " + gameObject.name, this);
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
OriginShiftManager.OnOriginShifted += OnOriginShifted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
OriginShiftManager.OnOriginShifted += OnOriginShifted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
OriginShiftManager.OnOriginShifted -= OnOriginShifted;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Unity Events
|
||||||
|
|
||||||
|
#region Origin Shift Events
|
||||||
|
|
||||||
|
private void OnOriginShifted(Vector3 shift)
|
||||||
|
{
|
||||||
|
_spawnable.futurePosition += shift;
|
||||||
|
_spawnable.currentPosition += shift;
|
||||||
|
_spawnable.pastPosition += shift; // not used by game, just cached ?
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Origin Shift Events
|
||||||
|
}
|
|
@ -63,9 +63,10 @@ internal static class CVRSpawnablePatches
|
||||||
[HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.Start))]
|
[HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.Start))]
|
||||||
private static void Postfix_CVRSpawnable_Start(ref CVRSpawnable __instance)
|
private static void Postfix_CVRSpawnable_Start(ref CVRSpawnable __instance)
|
||||||
{
|
{
|
||||||
Transform wrapper = __instance.transform.parent;
|
__instance.AddComponentIfMissing<OriginShiftSpawnableReceiver>();
|
||||||
|
|
||||||
// test adding to the wrapper of the spawnable
|
// test adding to the wrapper of the spawnable
|
||||||
|
Transform wrapper = __instance.transform.parent;
|
||||||
wrapper.AddComponentIfMissing<OriginShiftTransformReceiver>();
|
wrapper.AddComponentIfMissing<OriginShiftTransformReceiver>();
|
||||||
wrapper.AddComponentIfMissing<OriginShiftParticleSystemReceiver>();
|
wrapper.AddComponentIfMissing<OriginShiftParticleSystemReceiver>();
|
||||||
wrapper.AddComponentIfMissing<OriginShiftTrailRendererReceiver>();
|
wrapper.AddComponentIfMissing<OriginShiftTrailRendererReceiver>();
|
||||||
|
@ -215,6 +216,13 @@ internal static class CVRSyncHelperPatches
|
||||||
|
|
||||||
internal static class CVRObjectSyncPatches
|
internal static class CVRObjectSyncPatches
|
||||||
{
|
{
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.Start))]
|
||||||
|
private static void Postfix_CVRObjectSync_Start(ref CVRObjectSync __instance)
|
||||||
|
{
|
||||||
|
__instance.gameObject.AddComponentIfMissing<OriginShiftObjectSyncReceiver>();
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix] // inbound object sync
|
[HarmonyPrefix] // inbound object sync
|
||||||
[HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.receiveNetworkData))]
|
[HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.receiveNetworkData))]
|
||||||
[HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.receiveNetworkDataJoin))]
|
[HarmonyPatch(typeof(CVRObjectSync), nameof(CVRObjectSync.receiveNetworkDataJoin))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue