mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-08-31 13:29:27 +00:00
killed RelativeSync, now its just RelativeSyncJitterFix
This commit is contained in:
parent
30c069388c
commit
c368daab4f
16 changed files with 100 additions and 878 deletions
|
@ -1,48 +0,0 @@
|
|||
using MelonLoader;
|
||||
using NAK.RelativeSync.Networking;
|
||||
using NAK.RelativeSync.Patches;
|
||||
|
||||
namespace NAK.RelativeSync;
|
||||
|
||||
public class RelativeSyncMod : MelonMod
|
||||
{
|
||||
internal static MelonLogger.Instance Logger;
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
Logger = LoggerInstance;
|
||||
|
||||
ModNetwork.Subscribe();
|
||||
ModSettings.Initialize();
|
||||
|
||||
// Experimental sync hack
|
||||
ApplyPatches(typeof(CVRSpawnablePatches));
|
||||
|
||||
// Send relative sync update after network root data update
|
||||
ApplyPatches(typeof(NetworkRootDataUpdatePatches));
|
||||
|
||||
// Add components if missing (for relative sync monitor and controller)
|
||||
ApplyPatches(typeof(PlayerSetupPatches));
|
||||
ApplyPatches(typeof(PuppetMasterPatches));
|
||||
|
||||
// Add components if missing (for relative sync markers)
|
||||
ApplyPatches(typeof(CVRSeatPatches));
|
||||
ApplyPatches(typeof(CVRMovementParentPatches));
|
||||
|
||||
// So we run after the client moves the remote player
|
||||
ApplyPatches(typeof(NetIKController_Patches));
|
||||
}
|
||||
|
||||
private void ApplyPatches(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
HarmonyInstance.PatchAll(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LoggerInstance.Msg($"Failed while patching {type.Name}!");
|
||||
LoggerInstance.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
using MelonLoader;
|
||||
using NAK.RelativeSync.Networking;
|
||||
|
||||
namespace NAK.RelativeSync;
|
||||
|
||||
internal static class ModSettings
|
||||
{
|
||||
internal const string ModName = nameof(RelativeSync);
|
||||
|
||||
#region Melon Preferences
|
||||
|
||||
private static readonly MelonPreferences_Category Category =
|
||||
MelonPreferences.CreateCategory(ModName);
|
||||
|
||||
private static readonly MelonPreferences_Entry<bool> DebugLogInbound =
|
||||
Category.CreateEntry("DebugLogInbound", false,
|
||||
"Debug Log Inbound", description: "Log inbound network messages.");
|
||||
|
||||
private static readonly MelonPreferences_Entry<bool> DebugLogOutbound =
|
||||
Category.CreateEntry("DebugLogOutbound", false,
|
||||
"Debug Log Outbound", description: "Log outbound network messages.");
|
||||
|
||||
private static readonly MelonPreferences_Entry<bool> ExpSyncedObjectHack =
|
||||
Category.CreateEntry("ExpSyncedObjectHack", true,
|
||||
"Exp Spawnable Sync Fix", description: "Forces CVRSpawnable to update position in FixedUpdate. May help reduce local jitter on synced movement parents.");
|
||||
|
||||
#endregion Melon Preferences
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
foreach (MelonPreferences_Entry setting in Category.Entries)
|
||||
setting.OnEntryValueChangedUntyped.Subscribe(OnSettingsChanged);
|
||||
|
||||
OnSettingsChanged();
|
||||
}
|
||||
|
||||
private static void OnSettingsChanged(object oldValue = null, object newValue = null)
|
||||
{
|
||||
ModNetwork.Debug_NetworkInbound = DebugLogInbound.Value;
|
||||
ModNetwork.Debug_NetworkOutbound = DebugLogOutbound.Value;
|
||||
Patches.CVRSpawnablePatches.UseHack = ExpSyncedObjectHack.Value;
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
using ABI_RC.Core.Networking;
|
||||
using ABI_RC.Systems.ModNetwork;
|
||||
using DarkRift;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.RelativeSync.Networking;
|
||||
|
||||
public static class ModNetwork
|
||||
{
|
||||
public static bool Debug_NetworkInbound = false;
|
||||
public static bool Debug_NetworkOutbound = false;
|
||||
|
||||
private static bool _isSubscribedToModNetwork;
|
||||
|
||||
private struct MovementParentSyncData
|
||||
{
|
||||
public bool HasSyncedThisData;
|
||||
public int MarkerHash;
|
||||
public Vector3 RootPosition;
|
||||
public Vector3 RootRotation;
|
||||
// public Vector3 HipPosition;
|
||||
// public Vector3 HipRotation;
|
||||
}
|
||||
|
||||
private static MovementParentSyncData _latestMovementParentSyncData;
|
||||
|
||||
#region Constants
|
||||
|
||||
private const string ModId = "MelonMod.NAK.RelativeSync";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
||||
private enum MessageType : byte
|
||||
{
|
||||
MovementParentOrChair = 0
|
||||
//RelativePickup = 1,
|
||||
//RelativeAttachment = 2,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mod Network Internals
|
||||
|
||||
internal static void Subscribe()
|
||||
{
|
||||
ModNetworkManager.Subscribe(ModId, OnMessageReceived);
|
||||
|
||||
_isSubscribedToModNetwork = ModNetworkManager.IsSubscribed(ModId);
|
||||
if (!_isSubscribedToModNetwork)
|
||||
Debug.LogError("Failed to subscribe to Mod Network!");
|
||||
}
|
||||
|
||||
// Called right after NetworkRootDataUpdate.Submit()
|
||||
internal static void SendRelativeSyncUpdate()
|
||||
{
|
||||
if (!_isSubscribedToModNetwork)
|
||||
return;
|
||||
|
||||
if (_latestMovementParentSyncData.HasSyncedThisData)
|
||||
return;
|
||||
|
||||
SendMessage(MessageType.MovementParentOrChair, _latestMovementParentSyncData.MarkerHash,
|
||||
_latestMovementParentSyncData.RootPosition, _latestMovementParentSyncData.RootRotation);
|
||||
|
||||
_latestMovementParentSyncData.HasSyncedThisData = true;
|
||||
}
|
||||
|
||||
public static void SetLatestRelativeSync(
|
||||
int markerHash,
|
||||
Vector3 position, Vector3 rotation)
|
||||
{
|
||||
// check if the data has changed
|
||||
if (_latestMovementParentSyncData.MarkerHash == markerHash
|
||||
&& _latestMovementParentSyncData.RootPosition == position
|
||||
&& _latestMovementParentSyncData.RootRotation == rotation)
|
||||
return; // no need to update (shocking)
|
||||
|
||||
_latestMovementParentSyncData.HasSyncedThisData = false; // reset
|
||||
_latestMovementParentSyncData.MarkerHash = markerHash;
|
||||
_latestMovementParentSyncData.RootPosition = position;
|
||||
_latestMovementParentSyncData.RootRotation = rotation;
|
||||
}
|
||||
|
||||
private static void SendMessage(MessageType messageType, int markerHash, Vector3 position, Vector3 rotation)
|
||||
{
|
||||
if (!IsConnectedToGameNetwork())
|
||||
return;
|
||||
|
||||
using ModNetworkMessage modMsg = new(ModId);
|
||||
modMsg.Write((byte)messageType);
|
||||
modMsg.Write(markerHash);
|
||||
modMsg.Write(position);
|
||||
modMsg.Write(rotation);
|
||||
modMsg.Send();
|
||||
|
||||
if (Debug_NetworkOutbound)
|
||||
Debug.Log(
|
||||
$"[Outbound] MessageType: {messageType}, MarkerHash: {markerHash}, Position: {position}, " +
|
||||
$"Rotation: {rotation}");
|
||||
}
|
||||
|
||||
private static void OnMessageReceived(ModNetworkMessage msg)
|
||||
{
|
||||
msg.Read(out byte msgTypeRaw);
|
||||
|
||||
if (!Enum.IsDefined(typeof(MessageType), msgTypeRaw))
|
||||
return;
|
||||
|
||||
switch ((MessageType)msgTypeRaw)
|
||||
{
|
||||
case MessageType.MovementParentOrChair:
|
||||
msg.Read(out int markerHash);
|
||||
msg.Read(out Vector3 receivedPosition);
|
||||
msg.Read(out Vector3 receivedRotation);
|
||||
// msg.Read(out Vector3 receivedHipPosition);
|
||||
// msg.Read(out Vector3 receivedHipRotation);
|
||||
|
||||
OnNetworkPositionUpdateReceived(msg.Sender, markerHash, receivedPosition, receivedRotation);
|
||||
|
||||
if (Debug_NetworkInbound)
|
||||
Debug.Log($"[Inbound] Sender: {msg.Sender}, MarkerHash: {markerHash}, " +
|
||||
$"Position: {receivedPosition}, Rotation: {receivedRotation}");
|
||||
break;
|
||||
default:
|
||||
Debug.LogError($"Invalid message type received from: {msg.Sender}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static bool IsConnectedToGameNetwork()
|
||||
{
|
||||
return NetworkManager.Instance != null
|
||||
&& NetworkManager.Instance.GameNetwork != null
|
||||
&& NetworkManager.Instance.GameNetwork.ConnectionState == ConnectionState.Connected;
|
||||
}
|
||||
|
||||
private static void OnNetworkPositionUpdateReceived(
|
||||
string sender, int markerHash,
|
||||
Vector3 position, Vector3 rotation)
|
||||
{
|
||||
RelativeSyncManager.ApplyRelativeSync(sender, markerHash, position, rotation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
using ABI_RC.Core.Base;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Networking.Jobs;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI.CCK.Components;
|
||||
using HarmonyLib;
|
||||
using NAK.RelativeSync.Components;
|
||||
using NAK.RelativeSync.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.RelativeSync.Patches;
|
||||
|
||||
internal static class PlayerSetupPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))]
|
||||
private static void Postfix_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
{
|
||||
__instance.AddComponentIfMissing<RelativeSyncMonitor>();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class PuppetMasterPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PuppetMaster), nameof(PuppetMaster.Start))]
|
||||
private static void Postfix_PuppetMaster_Start(ref PuppetMaster __instance)
|
||||
{
|
||||
__instance.AddComponentIfMissing<RelativeSyncController>();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class CVRSeatPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(CVRSeat), nameof(CVRSeat.Awake))]
|
||||
private static void Postfix_CVRSeat_Awake(ref CVRSeat __instance)
|
||||
{
|
||||
__instance.AddComponentIfMissing<RelativeSyncMarker>();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class CVRMovementParentPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(CVRMovementParent), nameof(CVRMovementParent.Start))]
|
||||
private static void Postfix_CVRMovementParent_Start(ref CVRMovementParent __instance)
|
||||
{
|
||||
__instance.AddComponentIfMissing<RelativeSyncMarker>();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class NetworkRootDataUpdatePatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(NetworkRootDataUpdate), nameof(NetworkRootDataUpdate.Submit))]
|
||||
private static void Postfix_NetworkRootDataUpdater_Submit()
|
||||
{
|
||||
ModNetwork.SendRelativeSyncUpdate(); // Send the relative sync update after the network root data update
|
||||
}
|
||||
}
|
||||
|
||||
internal static class CVRSpawnablePatches
|
||||
{
|
||||
internal static bool UseHack;
|
||||
|
||||
private static bool _canUpdate;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.Update))]
|
||||
private static bool Prefix_CVRSpawnable_Update()
|
||||
=> !UseHack || _canUpdate;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.FixedUpdate))]
|
||||
private static void Postfix_CVRSpawnable_FixedUpdate(ref CVRSpawnable __instance)
|
||||
{
|
||||
if (!UseHack) return;
|
||||
|
||||
_canUpdate = true;
|
||||
__instance.Update();
|
||||
_canUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class NetIKController_Patches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(NetIKController), nameof(NetIKController.LateUpdate))]
|
||||
private static void Postfix_NetIKController_LateUpdate(ref NetIKController __instance)
|
||||
{
|
||||
if (!RelativeSyncManager.NetIkControllersToRelativeSyncControllers.TryGetValue(__instance,
|
||||
out RelativeSyncController syncController))
|
||||
return;
|
||||
|
||||
// Apply relative sync after the network IK has been applied
|
||||
syncController.OnPostNetIkControllerLateUpdate();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NetIKController), nameof(NetIKController.GetLocalPlayerPosition))]
|
||||
private static bool Prefix_NetIKController_GetLocalPlayerPosition(ref NetIKController __instance, ref Vector3 __result)
|
||||
{
|
||||
// why is the original method so bad
|
||||
__result = PlayerSetup.Instance.activeCam.transform.position;
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
# RelativeSync
|
||||
|
||||
Relative sync for Movement Parent & Chairs. Requires both users to have the mod installed. Synced over Mod Network.
|
||||
|
||||
https://github.com/NotAKidoS/NAK_CVR_Mods/assets/37721153/ae6c6e4b-7529-42e2-bd2c-afa050849906
|
||||
|
||||
## Mod Settings
|
||||
- **Debug Network Inbound**: Log network messages received from other players.
|
||||
- **Debug Network Outbound**: Log network messages sent to other players.
|
||||
- **Exp Spawnable Sync Hack**: Forces CVRSpawnable to update position in FixedUpdate. This can help with local jitter while on a remote synced movement parent.
|
||||
- **Exp Disable Interpolation on BBCC**: Disables interpolation on BetterBetterCharacterController. This can help with local jitter while on any movement parent.
|
||||
|
||||
## Known Issues
|
||||
- Movement Parents on remote users will still locally jitter.
|
||||
- PuppetMaster/NetIkController applies received position updates in LateUpdate, while character controller updates in FixedUpdate.
|
||||
- Movement Parents using CVRObjectSync synced by remote users will still locally jitter.
|
||||
- CVRObjectSync applies received position updates in LateUpdate, while character controller updates in FixedUpdate.
|
||||
- Slight interpolation issue with humanoid avatar hips while standing on a Movement Parent.
|
||||
- Requires further investigation. I believe it to be because hips are not synced properly, requiring me to relative sync the hips as well.
|
||||
|
||||
---
|
||||
|
||||
Here is the block of text where I tell you this mod is not affiliated with or endorsed by ABI.
|
||||
https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games
|
||||
|
||||
> This mod is an independent creation not affiliated with, supported by, or approved by Alpha Blend Interactive.
|
||||
|
||||
> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use.
|
||||
|
||||
> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive.
|
|
@ -1,206 +0,0 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.Movement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.RelativeSync.Components;
|
||||
|
||||
[DefaultExecutionOrder(9000)] // make sure this runs after NetIKController, but before Totally Wholesome LineController (9999)
|
||||
public class RelativeSyncController : MonoBehaviour
|
||||
{
|
||||
private const float MaxMagnitude = 750000000000f;
|
||||
|
||||
private float _updateInterval = 0.05f;
|
||||
private float _lastUpdate;
|
||||
|
||||
private string _userId;
|
||||
private PuppetMaster puppetMaster { get; set; }
|
||||
private RelativeSyncMarker _relativeSyncMarker;
|
||||
|
||||
private RelativeSyncData _relativeSyncData;
|
||||
private RelativeSyncData _lastSyncData;
|
||||
|
||||
#region Unity Events
|
||||
|
||||
private void Start()
|
||||
{
|
||||
puppetMaster = GetComponent<PuppetMaster>();
|
||||
|
||||
_userId = puppetMaster._playerDescriptor.ownerId;
|
||||
RelativeSyncManager.RelativeSyncControllers.Add(_userId, this);
|
||||
RelativeSyncManager.NetIkControllersToRelativeSyncControllers.Add(puppetMaster.netIkController, this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
RelativeSyncManager.RelativeSyncControllers.Remove(_userId);
|
||||
|
||||
if (puppetMaster == null
|
||||
|| puppetMaster.netIkController == null)
|
||||
{
|
||||
// remove by value ?
|
||||
foreach (var kvp in RelativeSyncManager.NetIkControllersToRelativeSyncControllers)
|
||||
{
|
||||
if (kvp.Value != this) continue;
|
||||
RelativeSyncManager.NetIkControllersToRelativeSyncControllers.Remove(kvp.Key);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
RelativeSyncManager.NetIkControllersToRelativeSyncControllers.Remove(puppetMaster.netIkController);
|
||||
}
|
||||
|
||||
internal void OnPostNetIkControllerLateUpdate()
|
||||
{
|
||||
// if (puppetMaster._isHidden)
|
||||
// return;
|
||||
|
||||
if (_relativeSyncMarker == null)
|
||||
return;
|
||||
|
||||
if (!_relativeSyncMarker.IsComponentActive)
|
||||
return;
|
||||
|
||||
Animator animator = puppetMaster._animator;
|
||||
if (animator == null)
|
||||
return;
|
||||
|
||||
Transform avatarTransform = animator.transform;
|
||||
Transform hipTrans = (animator.avatar != null && animator.isHuman)
|
||||
? animator.GetBoneTransform(HumanBodyBones.Hips) : null;
|
||||
|
||||
Vector3 relativeHipPos = default;
|
||||
Quaternion relativeHipRot = default;
|
||||
if (hipTrans != null)
|
||||
{
|
||||
Vector3 worldRootPos = avatarTransform.position;
|
||||
Quaternion worldRootRot = avatarTransform.rotation;
|
||||
|
||||
Vector3 hipPos = hipTrans.position;
|
||||
Quaternion hipRot = hipTrans.rotation;
|
||||
|
||||
relativeHipPos = Quaternion.Inverse(worldRootRot) * (hipPos - worldRootPos);
|
||||
relativeHipRot = Quaternion.Inverse(worldRootRot) * hipRot;
|
||||
}
|
||||
|
||||
// TODO: handle the case where hip is not synced but is found on remote client
|
||||
|
||||
float lerp = Mathf.Min((Time.time - _lastUpdate) / _updateInterval, 1f);
|
||||
|
||||
ApplyRelativeRotation(avatarTransform, hipTrans, lerp);
|
||||
ApplyRelativePosition(hipTrans, lerp);
|
||||
|
||||
// idk if needed (both player root & avatar root are set to same world position) -_-_-_-
|
||||
avatarTransform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
|
||||
// fix hip syncing because it is not relative to root, it is synced in world space -_-
|
||||
if (hipTrans != null)
|
||||
{
|
||||
hipTrans.position = transform.position + transform.rotation * relativeHipPos;
|
||||
hipTrans.rotation = transform.rotation * relativeHipRot;
|
||||
}
|
||||
|
||||
// Reprocess the root distance so we don't fuck avatar distance hider
|
||||
NetIKController netIkController = puppetMaster.netIkController;
|
||||
netIkController._rootDistance = Vector3.Distance((netIkController._collider.transform.position + netIkController._collider.center),
|
||||
netIkController.GetLocalPlayerPosition()) - (netIkController._collider.radius + BetterBetterCharacterController.Instance.Radius);
|
||||
}
|
||||
|
||||
private void ApplyRelativeRotation(Transform avatarTransform, Transform hipTransform, float lerp)
|
||||
{
|
||||
if (!_relativeSyncMarker.ApplyRelativeRotation ||
|
||||
!(_relativeSyncData.LocalRootRotation.sqrMagnitude < MaxMagnitude))
|
||||
return; // not applying relative rotation or data is invalid
|
||||
|
||||
Quaternion markerRotation = _relativeSyncMarker.transform.rotation;
|
||||
Quaternion lastWorldRotation = markerRotation * Quaternion.Euler(_lastSyncData.LocalRootRotation);
|
||||
Quaternion worldRotation = markerRotation * Quaternion.Euler(_relativeSyncData.LocalRootRotation);
|
||||
|
||||
if (_relativeSyncMarker.OnlyApplyRelativeHeading)
|
||||
{
|
||||
Vector3 currentWorldUp = avatarTransform.up;
|
||||
|
||||
Vector3 currentForward = lastWorldRotation * Vector3.forward;
|
||||
Vector3 targetForward = worldRotation * Vector3.forward;
|
||||
|
||||
currentForward = Vector3.ProjectOnPlane(currentForward, currentWorldUp).normalized;
|
||||
targetForward = Vector3.ProjectOnPlane(targetForward, currentWorldUp).normalized;
|
||||
|
||||
lastWorldRotation = Quaternion.LookRotation(currentForward, currentWorldUp);
|
||||
worldRotation = Quaternion.LookRotation(targetForward, currentWorldUp);
|
||||
}
|
||||
|
||||
transform.rotation = Quaternion.Slerp(lastWorldRotation, worldRotation, lerp);
|
||||
}
|
||||
|
||||
private void ApplyRelativePosition(Transform hipTransform, float lerp)
|
||||
{
|
||||
if (!_relativeSyncMarker.ApplyRelativePosition ||
|
||||
!(_relativeSyncData.LocalRootPosition.sqrMagnitude < MaxMagnitude))
|
||||
return; // not applying relative position or data is invalid
|
||||
|
||||
Transform targetTransform = _relativeSyncMarker.transform;
|
||||
|
||||
Vector3 lastWorldPosition = targetTransform.TransformPoint(_lastSyncData.LocalRootPosition);
|
||||
Vector3 worldPosition = targetTransform.TransformPoint(_relativeSyncData.LocalRootPosition);
|
||||
transform.position = Vector3.Lerp(lastWorldPosition, worldPosition, lerp);
|
||||
|
||||
// if (hipTransform == null)
|
||||
// return;
|
||||
//
|
||||
// Vector3 lastWorldHipPosition = targetTransform.TransformPoint(_lastSyncData.LocalHipPosition);
|
||||
// Vector3 worldHipPosition = targetTransform.TransformPoint(_relativeSyncData.LocalHipPosition);
|
||||
// hipTransform.position = Vector3.Lerp(lastWorldHipPosition, worldHipPosition, lerp);
|
||||
}
|
||||
|
||||
#endregion Unity Events
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void SetRelativeSyncMarker(RelativeSyncMarker target)
|
||||
{
|
||||
if (_relativeSyncMarker == target)
|
||||
return;
|
||||
|
||||
_relativeSyncMarker = target;
|
||||
|
||||
// calculate relative position and rotation so lerp can smooth it out (hack)
|
||||
if (_relativeSyncMarker == null)
|
||||
return;
|
||||
|
||||
Animator avatarAnimator = puppetMaster._animator;
|
||||
if (avatarAnimator == null)
|
||||
return; // i dont care to bother
|
||||
|
||||
RelativeSyncManager.GetRelativeAvatarPositionsFromMarker(
|
||||
avatarAnimator, _relativeSyncMarker.transform,
|
||||
out Vector3 relativePosition, out Vector3 relativeRotation);
|
||||
|
||||
// set last sync data to current position and rotation so we don't lerp from the last marker
|
||||
_lastSyncData.LocalRootPosition = relativePosition;
|
||||
_lastSyncData.LocalRootRotation = relativeRotation;
|
||||
_lastUpdate = Time.time; // reset update time
|
||||
}
|
||||
|
||||
public void SetRelativePositions(Vector3 position, Vector3 rotation)
|
||||
{
|
||||
// calculate update interval
|
||||
float prevUpdate = _lastUpdate;
|
||||
_lastUpdate = Time.time;
|
||||
_updateInterval = _lastUpdate - prevUpdate;
|
||||
|
||||
// cycle last sync data
|
||||
_lastSyncData = _relativeSyncData;
|
||||
|
||||
// set new sync data
|
||||
_relativeSyncData.LocalRootPosition = position;
|
||||
_relativeSyncData.LocalRootRotation = rotation;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
private struct RelativeSyncData
|
||||
{
|
||||
public Vector3 LocalRootPosition;
|
||||
public Vector3 LocalRootRotation;
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.RelativeSync.Components;
|
||||
|
||||
public class RelativeSyncMarker : MonoBehaviour
|
||||
{
|
||||
public int pathHash { get; private set; }
|
||||
|
||||
public bool IsComponentActive
|
||||
=> _component.isActiveAndEnabled;
|
||||
|
||||
public bool ApplyRelativePosition = true;
|
||||
public bool ApplyRelativeRotation = true;
|
||||
public bool OnlyApplyRelativeHeading;
|
||||
|
||||
private MonoBehaviour _component;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RegisterWithManager();
|
||||
ConfigureForPotentialMovementParent();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
RelativeSyncManager.RelativeSyncTransforms.Remove(pathHash);
|
||||
}
|
||||
|
||||
public void OnHavingSoftTacosNow()
|
||||
=> RegisterWithManager();
|
||||
|
||||
private void RegisterWithManager()
|
||||
{
|
||||
// Remove old hash in case this is a re-registration
|
||||
RelativeSyncManager.RelativeSyncTransforms.Remove(pathHash);
|
||||
|
||||
string path = GetGameObjectPath(transform);
|
||||
int hash = path.GetHashCode();
|
||||
|
||||
// check if it already exists (this **should** only matter in worlds)
|
||||
if (RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash))
|
||||
{
|
||||
RelativeSyncMod.Logger.Warning($"Duplicate RelativeSyncMarker found at path {path}");
|
||||
if (!FindAvailableHash(ref hash)) // super lazy fix idfc
|
||||
{
|
||||
RelativeSyncMod.Logger.Error($"Failed to find available hash for RelativeSyncMarker after 16 tries! {path}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pathHash = hash;
|
||||
RelativeSyncManager.RelativeSyncTransforms.Add(hash, this);
|
||||
}
|
||||
|
||||
private void ConfigureForPotentialMovementParent()
|
||||
{
|
||||
if (!gameObject.TryGetComponent(out CVRMovementParent movementParent))
|
||||
{
|
||||
_component = GetComponent<CVRSeat>(); // users cant animate enabled state so i dont think matters
|
||||
return;
|
||||
}
|
||||
_component = movementParent;
|
||||
|
||||
// TODO: a refactor may be needed to handle the orientation mode being animated
|
||||
|
||||
// respect orientation mode & gravity zone
|
||||
ApplyRelativeRotation = movementParent.orientationMode == CVRMovementParent.OrientationMode.RotateWithParent;
|
||||
OnlyApplyRelativeHeading = movementParent.GetComponent<GravityZone>() == null;
|
||||
}
|
||||
|
||||
private static string GetGameObjectPath(Transform transform)
|
||||
{
|
||||
// props already have a unique instance identifier at root
|
||||
// worlds uhhhh, dont duplicate the same thing over and over thx
|
||||
// avatars on remote/local client have diff path, we need to account for it -_-
|
||||
|
||||
string path = transform.name;
|
||||
while (transform.parent != null)
|
||||
{
|
||||
transform = transform.parent;
|
||||
|
||||
// only true at root of local player object
|
||||
if (transform.CompareTag("Player"))
|
||||
{
|
||||
path = MetaPort.Instance.ownerId + "/" + path;
|
||||
break;
|
||||
} // remote player object root is already player guid
|
||||
|
||||
path = transform.name + "/" + path;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private static bool FindAvailableHash(ref int hash)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
hash += 1;
|
||||
if (!RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash)) return true;
|
||||
}
|
||||
|
||||
// failed to find a hash in 16 tries, dont care
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.Movement;
|
||||
using NAK.RelativeSync.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.RelativeSync.Components;
|
||||
|
||||
[DefaultExecutionOrder(int.MaxValue)]
|
||||
public class RelativeSyncMonitor : MonoBehaviour
|
||||
{
|
||||
private BetterBetterCharacterController _characterController { get; set; }
|
||||
|
||||
private RelativeSyncMarker _relativeSyncMarker;
|
||||
private RelativeSyncMarker _lastRelativeSyncMarker;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_characterController = GetComponent<BetterBetterCharacterController>();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (_characterController == null)
|
||||
return;
|
||||
|
||||
CheckForRelativeSyncMarker();
|
||||
|
||||
if (_relativeSyncMarker == null)
|
||||
{
|
||||
if (_lastRelativeSyncMarker == null)
|
||||
return;
|
||||
|
||||
// send empty position and rotation to stop syncing
|
||||
SendEmptyPositionAndRotation();
|
||||
_lastRelativeSyncMarker = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_lastRelativeSyncMarker = _relativeSyncMarker;
|
||||
|
||||
Animator avatarAnimator = PlayerSetup.Instance._animator;
|
||||
if (avatarAnimator == null)
|
||||
return; // i dont care to bother
|
||||
|
||||
RelativeSyncManager.GetRelativeAvatarPositionsFromMarker(
|
||||
avatarAnimator, _relativeSyncMarker.transform,
|
||||
out Vector3 relativePosition, out Vector3 relativeRotation);
|
||||
|
||||
ModNetwork.SetLatestRelativeSync(
|
||||
_relativeSyncMarker.pathHash,
|
||||
relativePosition, relativeRotation);
|
||||
}
|
||||
|
||||
private void CheckForRelativeSyncMarker()
|
||||
{
|
||||
if (_characterController._isSitting && _characterController._lastCvrSeat)
|
||||
{
|
||||
RelativeSyncMarker newMarker = _characterController._lastCvrSeat.GetComponent<RelativeSyncMarker>();
|
||||
_relativeSyncMarker = newMarker;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_characterController._previousMovementParent != null)
|
||||
{
|
||||
RelativeSyncMarker newMarker = _characterController._previousMovementParent.GetComponent<RelativeSyncMarker>();
|
||||
_relativeSyncMarker = newMarker;
|
||||
return;
|
||||
}
|
||||
|
||||
// none found
|
||||
_relativeSyncMarker = null;
|
||||
}
|
||||
|
||||
private void SendEmptyPositionAndRotation()
|
||||
{
|
||||
ModNetwork.SetLatestRelativeSync(RelativeSyncManager.NoTarget,
|
||||
Vector3.zero, Vector3.zero);
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
using ABI_RC.Core.Base;
|
||||
using ABI_RC.Core.Player;
|
||||
using NAK.RelativeSync.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.RelativeSync;
|
||||
|
||||
public static class RelativeSyncManager
|
||||
{
|
||||
public const int NoTarget = -1;
|
||||
|
||||
public static readonly Dictionary<int, RelativeSyncMarker> RelativeSyncTransforms = new();
|
||||
public static readonly Dictionary<string, RelativeSyncController> RelativeSyncControllers = new();
|
||||
public static readonly Dictionary<NetIKController, RelativeSyncController> NetIkControllersToRelativeSyncControllers = new();
|
||||
|
||||
public static void ApplyRelativeSync(string userId, int target, Vector3 position, Vector3 rotation)
|
||||
{
|
||||
if (!RelativeSyncControllers.TryGetValue(userId, out RelativeSyncController controller))
|
||||
{
|
||||
if (CVRPlayerManager.Instance.GetPlayerPuppetMaster(userId, out PuppetMaster pm))
|
||||
{
|
||||
controller = pm.AddComponentIfMissing<RelativeSyncController>();
|
||||
RelativeSyncMod.Logger.Msg($"Found PuppetMaster for user {userId}. This user is now eligible for relative sync.");
|
||||
}
|
||||
else
|
||||
{
|
||||
RelativeSyncControllers.Add(userId, null); // add null controller to prevent future lookups
|
||||
RelativeSyncMod.Logger.Warning($"Failed to find PuppetMaster for user {userId}. This is likely because the user is blocked or has blocked you. This user will not be eligible for relative sync until next game restart.");
|
||||
}
|
||||
}
|
||||
|
||||
if (controller == null)
|
||||
return;
|
||||
|
||||
// find target transform
|
||||
RelativeSyncMarker syncMarker = null;
|
||||
if (target != NoTarget) RelativeSyncTransforms.TryGetValue(target, out syncMarker);
|
||||
|
||||
controller.SetRelativeSyncMarker(syncMarker);
|
||||
controller.SetRelativePositions(position, rotation);
|
||||
}
|
||||
|
||||
public static void GetRelativeAvatarPositionsFromMarker(
|
||||
Animator avatarAnimator, Transform markerTransform,
|
||||
out Vector3 relativePosition, out Vector3 relativeRotation)
|
||||
// out Vector3 relativeHipPosition, out Vector3 relativeHipRotation)
|
||||
{
|
||||
Transform avatarTransform = avatarAnimator.transform;
|
||||
|
||||
// because our syncing is retarded, we need to sync relative from the avatar root...
|
||||
Vector3 avatarRootPosition = avatarTransform.position; // PlayerSetup.Instance.GetPlayerPosition()
|
||||
Quaternion avatarRootRotation = avatarTransform.rotation; // PlayerSetup.Instance.GetPlayerRotation()
|
||||
|
||||
relativePosition = markerTransform.InverseTransformPoint(avatarRootPosition);
|
||||
relativeRotation = (Quaternion.Inverse(markerTransform.rotation) * avatarRootRotation).eulerAngles;
|
||||
|
||||
// Transform hipTrans = (avatarAnimator.avatar != null && avatarAnimator.isHuman)
|
||||
// ? avatarAnimator.GetBoneTransform(HumanBodyBones.Hips) : null;
|
||||
//
|
||||
// if (hipTrans == null)
|
||||
// {
|
||||
// relativeHipPosition = Vector3.zero;
|
||||
// relativeHipRotation = Vector3.zero;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// relativeHipPosition = markerTransform.InverseTransformPoint(hipTrans.position);
|
||||
// relativeHipRotation = (Quaternion.Inverse(markerTransform.rotation) * hipTrans.rotation).eulerAngles;
|
||||
// }
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"_id": 211,
|
||||
"name": "RelativeSync",
|
||||
"modversion": "1.0.5",
|
||||
"gameversion": "2025r179",
|
||||
"loaderversion": "0.6.1",
|
||||
"modtype": "Mod",
|
||||
"author": "NotAKidoS",
|
||||
"description": "Relative sync for Movement Parent & Chairs. Requires both users to have the mod installed. Synced over Mod Network.\n\nProvides some Experimental settings to also fix local jitter on movement parents.",
|
||||
"searchtags": [
|
||||
"relative",
|
||||
"sync",
|
||||
"movement",
|
||||
"chair"
|
||||
],
|
||||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r46/RelativeSync.dll",
|
||||
"sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/RelativeSync/",
|
||||
"changelog": "- Recompiled for 2025r179\n- Fixed execution order of RelativeSyncController so moving at high speeds with passengers does not disrupt voice or avatar distance hider",
|
||||
"embedcolor": "#f61963"
|
||||
}
|
25
RelativeSyncJitterFix/Main.cs
Normal file
25
RelativeSyncJitterFix/Main.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using MelonLoader;
|
||||
|
||||
namespace NAK.RelativeSyncJitterFix;
|
||||
|
||||
public class RelativeSyncJitterFixMod : MelonMod
|
||||
{
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
// Experimental sync hack
|
||||
ApplyPatches(typeof(Patches.CVRSpawnablePatches));
|
||||
}
|
||||
|
||||
private void ApplyPatches(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
HarmonyInstance.PatchAll(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LoggerInstance.Msg($"Failed while patching {type.Name}!");
|
||||
LoggerInstance.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
22
RelativeSyncJitterFix/Patches.cs
Normal file
22
RelativeSyncJitterFix/Patches.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using ABI.CCK.Components;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace NAK.RelativeSyncJitterFix.Patches;
|
||||
|
||||
internal static class CVRSpawnablePatches
|
||||
{
|
||||
private static bool _canUpdate;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.FixedUpdate))]
|
||||
private static void Postfix_CVRSpawnable_FixedUpdate(ref CVRSpawnable __instance)
|
||||
{
|
||||
_canUpdate = true;
|
||||
__instance.Update();
|
||||
_canUpdate = false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(CVRSpawnable), nameof(CVRSpawnable.Update))]
|
||||
private static bool Prefix_CVRSpawnable_Update() => _canUpdate;
|
||||
}
|
|
@ -1,32 +1,32 @@
|
|||
using NAK.RelativeSync.Properties;
|
||||
using NAK.RelativeSyncJitterFix.Properties;
|
||||
using MelonLoader;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
|
||||
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
|
||||
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
|
||||
[assembly: AssemblyTitle(nameof(NAK.RelativeSync))]
|
||||
[assembly: AssemblyTitle(nameof(NAK.RelativeSyncJitterFix))]
|
||||
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
|
||||
[assembly: AssemblyProduct(nameof(NAK.RelativeSync))]
|
||||
[assembly: AssemblyProduct(nameof(NAK.RelativeSyncJitterFix))]
|
||||
|
||||
[assembly: MelonInfo(
|
||||
typeof(NAK.RelativeSync.RelativeSyncMod),
|
||||
nameof(NAK.RelativeSync),
|
||||
typeof(NAK.RelativeSyncJitterFix.RelativeSyncJitterFixMod),
|
||||
nameof(NAK.RelativeSyncJitterFix),
|
||||
AssemblyInfoParams.Version,
|
||||
AssemblyInfoParams.Author,
|
||||
downloadLink: "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/RelativeSync"
|
||||
downloadLink: "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/RelativeSyncJitterFix"
|
||||
)]
|
||||
|
||||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||
[assembly: MelonGame("ChilloutVR", "ChilloutVR")]
|
||||
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||
[assembly: MelonColor(255, 246, 25, 99)] // red-pink
|
||||
[assembly: MelonAuthorColor(255, 158, 21, 32)] // red
|
||||
[assembly: HarmonyDontPatchAll]
|
||||
|
||||
namespace NAK.RelativeSync.Properties;
|
||||
namespace NAK.RelativeSyncJitterFix.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.5";
|
||||
public const string Version = "1.0.0";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
21
RelativeSyncJitterFix/README.md
Normal file
21
RelativeSyncJitterFix/README.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# RelativeSyncJitterFix
|
||||
|
||||
Relative sync jitter fix is the single harmony patch that could not make it into the native release of RelativeSync.
|
||||
Changes when props apply their incoming sync data to be before the character controller simulation.
|
||||
|
||||
## Known Issues
|
||||
- Movement Parents on remote users will still locally jitter.
|
||||
- PuppetMaster/NetIkController applies received position updates in LateUpdate, while character controller updates in FixedUpdate.
|
||||
- Movement Parents using CVRObjectSync synced by remote users will still locally jitter.
|
||||
- CVRObjectSync applies received position updates in LateUpdate, while character controller updates in FixedUpdate.
|
||||
|
||||
---
|
||||
|
||||
Here is the block of text where I tell you this mod is not affiliated with or endorsed by ChilloutVR.
|
||||
https://docs.chilloutvr.net/official/legal/tos/#7-modding-our-games
|
||||
|
||||
> This mod is an independent creation not affiliated with, supported by, or approved by ChilloutVR.
|
||||
|
||||
> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use.
|
||||
|
||||
> To the best of my knowledge, I have adhered to the Modding Guidelines established by ChilloutVR.
|
23
RelativeSyncJitterFix/format.json
Normal file
23
RelativeSyncJitterFix/format.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"_id": -1,
|
||||
"name": "RelativeSyncJitterFix",
|
||||
"modversion": "1.0.0",
|
||||
"gameversion": "2025r180",
|
||||
"loaderversion": "0.7.2",
|
||||
"modtype": "Mod",
|
||||
"author": "NotAKidoS",
|
||||
"description": "Relative sync jitter fix is the single harmony patch that could not make it into the native release of RelativeSync.\nChanges when props apply their incoming sync data to be before the character controller simulation.",
|
||||
"searchtags": [
|
||||
"relative",
|
||||
"sync",
|
||||
"movement",
|
||||
"chair"
|
||||
],
|
||||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r47/RelativeSyncJitterFix.dll",
|
||||
"sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/RelativeSyncJitterFix/",
|
||||
"changelog": "- Removed RelativeSync except for a single harmony patch",
|
||||
"embedcolor": "#f61963"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue