more player sync stuff
This commit is contained in:
@@ -110,6 +110,7 @@
|
||||
<Compile Include="Patching\InteractableHostPatches.cs" />
|
||||
<Compile Include="Patching\ObjectHealthPatches.cs" />
|
||||
<Compile Include="Patching\PlugPatches.cs" />
|
||||
<Compile Include="Patching\SkeletonHandPatches.cs" />
|
||||
<Compile Include="Patching\ZonePatches.cs" />
|
||||
<Compile Include="Sync\Components\SyncableAI.cs" />
|
||||
<Compile Include="Sync\Components\SyncableBase.cs" />
|
||||
@@ -120,7 +121,6 @@
|
||||
<Compile Include="Sync\Components\SyncableProperties.cs" />
|
||||
<Compile Include="Sync\ObjectSync.cs" />
|
||||
<Compile Include="Sync\ObjectSyncCache.cs" />
|
||||
<Compile Include="Sync\PlayerSync.cs" />
|
||||
<Compile Include="Facepunch.Steamworks\Callbacks\CallResult.cs" />
|
||||
<Compile Include="Facepunch.Steamworks\Callbacks\ICallbackData.cs" />
|
||||
<Compile Include="Facepunch.Steamworks\Classes\AuthTicket.cs" />
|
||||
|
||||
@@ -304,24 +304,35 @@ namespace BoneSync.Data
|
||||
return mag;
|
||||
}
|
||||
|
||||
public void WriteCompressedFloat(float value)
|
||||
{
|
||||
// write a float in the range of 0-1 with 2 decimal places
|
||||
WriteByte((byte)(value * 100));
|
||||
}
|
||||
|
||||
public float ReadCompressedFloat()
|
||||
{
|
||||
return ReadByte() / 100f;
|
||||
}
|
||||
|
||||
public void WriteFingerCurl(SimpleFingerCurl fingerCurl)
|
||||
{
|
||||
WriteFloat(fingerCurl.thumb);
|
||||
WriteFloat(fingerCurl.index);
|
||||
WriteFloat(fingerCurl.middle);
|
||||
WriteFloat(fingerCurl.ring);
|
||||
WriteFloat(fingerCurl.pinky);
|
||||
WriteCompressedFloat(fingerCurl.thumb);
|
||||
WriteCompressedFloat(fingerCurl.index);
|
||||
WriteCompressedFloat(fingerCurl.middle);
|
||||
WriteCompressedFloat(fingerCurl.ring);
|
||||
WriteCompressedFloat(fingerCurl.pinky);
|
||||
}
|
||||
|
||||
public SimpleFingerCurl ReadFingerCurl()
|
||||
{
|
||||
SimpleFingerCurl fingerCurl = new SimpleFingerCurl()
|
||||
{
|
||||
thumb = ReadFloat(),
|
||||
index = ReadFloat(),
|
||||
middle = ReadFloat(),
|
||||
ring = ReadFloat(),
|
||||
pinky = ReadFloat()
|
||||
thumb = ReadCompressedFloat(),
|
||||
index = ReadCompressedFloat(),
|
||||
middle = ReadCompressedFloat(),
|
||||
ring = ReadCompressedFloat(),
|
||||
pinky = ReadCompressedFloat()
|
||||
};
|
||||
return fingerCurl;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MelonLoader;
|
||||
using StressLevelZero.Interaction;
|
||||
using StressLevelZero.Player;
|
||||
using StressLevelZero.Rig;
|
||||
@@ -35,12 +36,19 @@ namespace BoneSync.Data
|
||||
|
||||
playerHealth.reloadLevelOnDeath = !BoneSync.lobby.IsConnected();
|
||||
|
||||
PhysicsRig physicsRig = playerRig.physicsRig;
|
||||
playerPhysBody = physicsRig.physBody;
|
||||
playerGrounder = playerPhysBody.physG;
|
||||
playerLeftHand = physicsRig.leftHand;
|
||||
playerRightHand = physicsRig.rightHand;
|
||||
playerAnimatorController = playerRig.gameWorldSkeletonRig.characterAnimationManager.animator.runtimeAnimatorController;
|
||||
try
|
||||
{
|
||||
PhysicsRig physicsRig = playerRig.physicsRig;
|
||||
playerPhysBody = physicsRig.physBody;
|
||||
playerGrounder = playerPhysBody.physG;
|
||||
playerLeftHand = physicsRig.leftHand;
|
||||
playerRightHand = physicsRig.rightHand;
|
||||
playerAnimatorController = playerRig.gameWorldSkeletonRig.characterAnimationManager.animator.runtimeAnimatorController;
|
||||
} catch
|
||||
{
|
||||
MelonLogger.Warning("Failed to get physicsRig player scripts!");
|
||||
}
|
||||
|
||||
GetHandPoses();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,8 @@ namespace BoneSync
|
||||
public override void OnUpdate()
|
||||
{
|
||||
|
||||
transport.Tick();
|
||||
bool processPackets = transport.Tick();
|
||||
|
||||
//PlayerRig.Tick();
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.P))
|
||||
@@ -92,7 +93,7 @@ namespace BoneSync
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.N))
|
||||
{
|
||||
MelonLogger.Msg("Creting debug player rig");
|
||||
MelonLogger.Msg("Creating debug player rig");
|
||||
PlayerRig debugRig = PlayerRig.GetPlayerRig(0);
|
||||
PlayerSyncInfo? playerSyncInfo = PlayerRig.GetLocalSyncInfo();
|
||||
if (!playerSyncInfo.HasValue)
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace BoneSync.Networking.LobbyManager
|
||||
_lobbyInstance = lobby;
|
||||
MelonLogger.Msg("Created lobby " + lobby.Id);
|
||||
UpdateLobbyData();
|
||||
_lobbyInstance.SetPublic();
|
||||
};
|
||||
SteamMatchmaking.OnLobbyEntered += (Lobby lobby) =>
|
||||
{
|
||||
@@ -57,6 +58,9 @@ namespace BoneSync.Networking.LobbyManager
|
||||
ulong lobbyId = ulong.Parse(connectString.Split(':')[1]);
|
||||
JoinLobby(lobbyId);
|
||||
};
|
||||
|
||||
|
||||
//SteamMatchmaking.LobbyList.
|
||||
}
|
||||
|
||||
private Lobby _lobbyInstance;
|
||||
@@ -102,7 +106,6 @@ namespace BoneSync.Networking.LobbyManager
|
||||
SteamFriends.SetRichPresence("connect", null);
|
||||
SteamFriends.SetRichPresence("status", "Not in a multiplayer lobby");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void CreateLobby()
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace BoneSync.Networking.Messages
|
||||
{
|
||||
StateUpdate = 0,
|
||||
Fire = 1,
|
||||
EjectCartridge = 2,
|
||||
}
|
||||
|
||||
public struct GunSyncInfo
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
using BoneSync.Data;
|
||||
using BoneSync.Player;
|
||||
using BoneSync.Sync;
|
||||
using StressLevelZero.Player;
|
||||
using System;
|
||||
@@ -36,6 +37,10 @@ namespace BoneSync.Networking.Messages
|
||||
public SimpleSyncTransform rightHandPos;
|
||||
public SimpleFingerCurl leftHandFingerCurl;
|
||||
public SimpleFingerCurl rightHandFingerCurl;
|
||||
public byte poseIndexRight;
|
||||
public byte poseIndexLeft;
|
||||
public float poseRadiusRight;
|
||||
public float poseRadiusLeft;
|
||||
}
|
||||
|
||||
[PacketType(PacketType.PlayerSync), PacketReliability(PacketReliability.Unreliable)]
|
||||
@@ -53,6 +58,10 @@ namespace BoneSync.Networking.Messages
|
||||
byteEncoder.WriteSimpleTransform(_playerSyncInfo.rightHandPos);
|
||||
byteEncoder.WriteFingerCurl(_playerSyncInfo.leftHandFingerCurl);
|
||||
byteEncoder.WriteFingerCurl(_playerSyncInfo.rightHandFingerCurl);
|
||||
byteEncoder.WriteByte(_playerSyncInfo.poseIndexRight);
|
||||
byteEncoder.WriteByte(_playerSyncInfo.poseIndexLeft);
|
||||
byteEncoder.WriteFloat(_playerSyncInfo.poseRadiusRight);
|
||||
byteEncoder.WriteFloat(_playerSyncInfo.poseRadiusLeft);
|
||||
}
|
||||
|
||||
public PlayerSyncMessage(Packet packet)
|
||||
@@ -64,11 +73,15 @@ namespace BoneSync.Networking.Messages
|
||||
_playerSyncInfo.rightHandPos = byteEncoder.ReadSimpleTransform();
|
||||
_playerSyncInfo.leftHandFingerCurl = byteEncoder.ReadFingerCurl();
|
||||
_playerSyncInfo.rightHandFingerCurl = byteEncoder.ReadFingerCurl();
|
||||
_playerSyncInfo.poseIndexRight = byteEncoder.ReadByte();
|
||||
_playerSyncInfo.poseIndexLeft = byteEncoder.ReadByte();
|
||||
_playerSyncInfo.poseRadiusRight = byteEncoder.ReadFloat();
|
||||
_playerSyncInfo.poseRadiusLeft = byteEncoder.ReadFloat();
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
PlayerSync.OnPlayerSync(this);
|
||||
PlayerRig.OnPlayerSync(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
64
BoneSync/Patching/SkeletonHandPatches.cs
Normal file
64
BoneSync/Patching/SkeletonHandPatches.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using StressLevelZero.Rig;
|
||||
using BoneSync.Data;
|
||||
using StressLevelZero;
|
||||
|
||||
namespace BoneSync.Patching
|
||||
{
|
||||
[HarmonyPatch(typeof(SkeletonHand))]
|
||||
internal static class SkeletonHandPatches
|
||||
{
|
||||
public static byte poseIndexRight = 0;
|
||||
public static float radiusRight = 0.0f;
|
||||
|
||||
public static byte poseIndexLeft = 0;
|
||||
public static float radiusLeft = 0.0f;
|
||||
|
||||
[HarmonyPatch(nameof(SkeletonHand.SetHandPose)), HarmonyPostfix]
|
||||
private static void SetHandPosePostfix(SkeletonHand __instance, string handPoseName)
|
||||
{
|
||||
if (!__instance.GetCharacterAnimationManager()) return;
|
||||
MelonLogger.Msg($"SetHandPosePostfix: {handPoseName}");
|
||||
|
||||
int poseIndex = PlayerScripts.playerHandPoses.IndexOf(handPoseName);
|
||||
switch (__instance.handedness)
|
||||
{
|
||||
case Handedness.LEFT:
|
||||
poseIndexLeft = (byte)poseIndex;
|
||||
break;
|
||||
case Handedness.RIGHT:
|
||||
poseIndexRight = (byte)poseIndex;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(SkeletonHand.SetCylinderRadius)), HarmonyPostfix]
|
||||
private static void SetCylinderRadiusPrefix(SkeletonHand __instance, float radius)
|
||||
{
|
||||
if (!__instance.GetCharacterAnimationManager()) return;
|
||||
MelonLogger.Msg($"SetCylinderRadiusPrefix: {radius}");
|
||||
|
||||
switch (__instance.handedness)
|
||||
{
|
||||
case Handedness.LEFT:
|
||||
radiusLeft = radius;
|
||||
break;
|
||||
case Handedness.RIGHT:
|
||||
radiusRight = radius;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ using System.IO;
|
||||
using BoneSync.Data;
|
||||
using StressLevelZero.Interaction;
|
||||
using UnhollowerBaseLib;
|
||||
using BoneSync.Patching;
|
||||
|
||||
|
||||
namespace BoneSync.Player
|
||||
@@ -72,6 +73,7 @@ namespace BoneSync.Player
|
||||
|
||||
public void UpdatePlayerSync(PlayerSyncInfo playerSyncInfo)
|
||||
{
|
||||
//MelonLogger.Msg("Updating player sync for " + _ownerId);
|
||||
playerRig.transform.position = playerSyncInfo.rootPos;
|
||||
|
||||
headTransform.ApplySimpleTransform(playerSyncInfo.headPos);
|
||||
@@ -82,6 +84,19 @@ namespace BoneSync.Player
|
||||
SetFingerCurl(Handedness.RIGHT, playerSyncInfo.rightHandFingerCurl);
|
||||
}
|
||||
|
||||
public void UpdatePose(Handedness hand, int index)
|
||||
{
|
||||
Il2CppStringArray handPoses = PlayerScripts.playerHandPoses;
|
||||
if (handPoses.Count < index + 1)
|
||||
return;
|
||||
UpdatePose(hand, handPoses[index]);
|
||||
}
|
||||
|
||||
public void UpdatePose(Handedness hand, string pose) => characterAnimationManager?.SetHandPose(hand, pose);
|
||||
|
||||
public void UpdatePoseRadius(Handedness hand, float radius) => characterAnimationManager?.SetCylinderRadius(hand, radius);
|
||||
|
||||
|
||||
public static PlayerSyncInfo? GetLocalSyncInfo()
|
||||
{
|
||||
GameObject localPlayerRig = GameObject.Find("[RigManager (Default Brett)]/[SkeletonRig (GameWorld Brett)]");
|
||||
@@ -110,15 +125,25 @@ namespace BoneSync.Player
|
||||
rightHandPos = new SimpleSyncTransform(localRightHandTransform),
|
||||
//leftHandFingerCurl = new SimpleFingerCurl(PlayerScripts.playerLeftHand.fingerCurl),
|
||||
//rightHandFingerCurl = new SimpleFingerCurl(PlayerScripts.playerRightHand.fingerCurl)
|
||||
poseIndexLeft = SkeletonHandPatches.poseIndexLeft,
|
||||
poseIndexRight = SkeletonHandPatches.poseIndexRight,
|
||||
poseRadiusLeft = SkeletonHandPatches.radiusLeft,
|
||||
poseRadiusRight = SkeletonHandPatches.radiusRight
|
||||
|
||||
};
|
||||
|
||||
if (PlayerScripts.playerLeftHand)
|
||||
playerSyncInfo.leftHandFingerCurl = new SimpleFingerCurl(PlayerScripts.playerLeftHand.fingerCurl);
|
||||
if (PlayerScripts.playerRightHand)
|
||||
playerSyncInfo.rightHandFingerCurl = new SimpleFingerCurl(PlayerScripts.playerRightHand.fingerCurl);
|
||||
|
||||
return playerSyncInfo;
|
||||
}
|
||||
|
||||
private static void SendLocalPlayerSync()
|
||||
{
|
||||
if (!BoneSync.lobby.IsConnected()) return;
|
||||
//MelonLogger.Msg("Sending local player sync");
|
||||
PlayerSyncInfo? playerSyncInfo = GetLocalSyncInfo();
|
||||
if (!playerSyncInfo.HasValue) return;
|
||||
PlayerSyncMessage playerSyncMessage = new PlayerSyncMessage(playerSyncInfo.Value);
|
||||
@@ -129,7 +154,7 @@ namespace BoneSync.Player
|
||||
{
|
||||
if (_playerRigs.ContainsKey(ownerId))
|
||||
{
|
||||
MelonLogger.Msg("PlayerRig already exists for " + ownerId);
|
||||
//MelonLogger.Msg("PlayerRig already exists for " + ownerId);
|
||||
return _playerRigs[ownerId];
|
||||
}
|
||||
|
||||
@@ -138,10 +163,9 @@ namespace BoneSync.Player
|
||||
MelonLogger.Msg("playerRepBundle is null! Did you forget to load the bundle?");
|
||||
return null;
|
||||
}
|
||||
PlayerScripts.GetPlayerScripts();
|
||||
//PlayerScripts.GetPlayerScripts();
|
||||
|
||||
PlayerRig rig = new PlayerRig(ownerId);
|
||||
rig.EnsurePlayerRig();
|
||||
return rig;
|
||||
}
|
||||
|
||||
@@ -157,7 +181,7 @@ namespace BoneSync.Player
|
||||
if (playerRig != null) return;
|
||||
|
||||
playerRig = GameObject.Instantiate(rigBundle.LoadAsset<GameObject>("PlayerRep"));
|
||||
playerRig.name = "PlayerRep (" + _ownerId + ")";
|
||||
playerRig.name = "PlayerRep";
|
||||
|
||||
body = playerRig.GetComponentInChildren<SLZ_Body>();
|
||||
characterAnimationManager = playerRig.GetComponentInChildren<CharacterAnimationManager>();
|
||||
@@ -191,7 +215,11 @@ namespace BoneSync.Player
|
||||
body.FullBodyUpdate(repInputVel, Vector3.zero);
|
||||
body.ArtToBlender.UpdateBlender();
|
||||
}
|
||||
catch { }
|
||||
catch (Exception e)
|
||||
{
|
||||
MelonLogger.Warning("Failed to update player rig " + _ownerId);
|
||||
MelonLogger.Warning(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +229,14 @@ namespace BoneSync.Player
|
||||
_ownerId = id;
|
||||
}
|
||||
|
||||
public static void OnPlayerSync(PlayerSyncMessage playerSyncMessage)
|
||||
{
|
||||
//MelonLogger.Msg("Player Sync Received " + playerSyncMessage.senderId);
|
||||
PlayerRig playerRig = PlayerRig.GetPlayerRig(playerSyncMessage.senderId);
|
||||
if (playerRig == null) return;
|
||||
playerRig.UpdatePlayerSync(playerSyncMessage.playerSyncInfo);
|
||||
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace BoneSync.Sync.Components
|
||||
sockets = GetComponentsInChildren<Socket>();
|
||||
aiBrain = GetComponent<AIBrain>();
|
||||
buttonToggles = GetComponentsInChildren<ButtonToggle>();
|
||||
puppetMaster = aiBrain.puppetMaster;
|
||||
puppetMaster = aiBrain?.puppetMaster;
|
||||
if (sockets.Length == 0)
|
||||
{
|
||||
plugs = GetComponentsInChildren<AlignPlug>();
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace BoneSync.Sync.Components
|
||||
public void OnOwnershipTransferRequest(ulong newOwnerId)
|
||||
{
|
||||
//MelonLogger.Msg("Ownership transfer request for " + _syncId + " to " + newOwnerId);
|
||||
if (isOwner && !IsHolding())
|
||||
if (isOwner && !IsHolding() && !_isInHolster)
|
||||
{
|
||||
MelonLogger.Msg("Sending ownership transfer for " + _syncId + " to " + newOwnerId);
|
||||
OwnershipTransferMessageData data = new OwnershipTransferMessageData()
|
||||
|
||||
@@ -69,9 +69,15 @@ namespace BoneSync.Sync.Components
|
||||
BulletObject bulletObject = gunSyncInfo.bulletObject;
|
||||
StripDamage(ref bulletObject);
|
||||
gun.EjectCartridge();
|
||||
//PoolSpawner.SpawnProjectile(position, rotation, gunSyncInfo.bulletObject, "1911", null);
|
||||
PoolSpawner.SpawnProjectile(position, rotation, gunSyncInfo.bulletObject, "1911", null);
|
||||
PoolSpawner.SpawnMuzzleFlare(position, rotation, PoolSpawner.MuzzleFlareType.Default);
|
||||
return;
|
||||
}
|
||||
|
||||
if (gunSyncInfo.messageType == GunSyncMessageType.EjectCartridge)
|
||||
{
|
||||
gun.EjectCartridge();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
using BoneSync.Data;
|
||||
using BoneSync.Networking;
|
||||
using BoneSync.Networking.Messages;
|
||||
using BoneSync.Player;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BoneSync.Sync
|
||||
{
|
||||
internal static class PlayerSync
|
||||
{
|
||||
|
||||
private static GameObject _localPlayerRig;
|
||||
|
||||
public static void SyncPlayer()
|
||||
{
|
||||
PlayerSyncInfo playerSyncInfo = new PlayerSyncInfo();
|
||||
playerSyncInfo.headPos = new SimpleSyncTransform();
|
||||
playerSyncInfo.leftHandPos = new SimpleSyncTransform();
|
||||
playerSyncInfo.rightHandPos = new SimpleSyncTransform();
|
||||
|
||||
PlayerSyncMessage playerSyncMessage = new PlayerSyncMessage(playerSyncInfo);
|
||||
playerSyncMessage.Broadcast();
|
||||
}
|
||||
|
||||
public static void OnPlayerSync(PlayerSyncMessage playerSyncMessage)
|
||||
{
|
||||
PlayerRig playerRig = PlayerRig.GetPlayerRig(playerSyncMessage.senderId);
|
||||
if (playerRig == null) return;
|
||||
playerRig.UpdatePlayerSync(playerSyncMessage.playerSyncInfo);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user