Player sync styff

This commit is contained in:
Aaro Varis
2025-03-08 22:36:48 +02:00
parent 252f6ba49a
commit 7bc1b21098
4 changed files with 101 additions and 71 deletions

View File

@@ -89,6 +89,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Data\ByteEncoder.cs" /> <Compile Include="Data\ByteEncoder.cs" />
<Compile Include="Data\EmebeddedAssetBundle.cs" />
<Compile Include="Data\PlayerScripts.cs" />
<Compile Include="Data\SpawnableManager.cs" /> <Compile Include="Data\SpawnableManager.cs" />
<Compile Include="Data\Structs.cs" /> <Compile Include="Data\Structs.cs" />
<Compile Include="Networking\Messages\DiscardSyncableMessage.cs" /> <Compile Include="Networking\Messages\DiscardSyncableMessage.cs" />

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using MelonLoader;
using UnityEngine;
namespace BoneSync.Data
{
public static class EmebeddedAssetBundle
{
// Credit to the "Entanglement" mod. The playerrep asset bundle is also by them.
public static AssetBundle LoadFromAssembly(string name)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string[] manifestResources = assembly.GetManifestResourceNames();
if (manifestResources.Contains(name))
{
MelonLogger.Msg($"Loading embedded bundle data {name}...");
byte[] bytes;
using (Stream str = assembly.GetManifestResourceStream(name))
using (MemoryStream memoryStream = new MemoryStream())
{
str.CopyTo(memoryStream);
bytes = memoryStream.ToArray();
}
MelonLogger.Msg($"Loading bundle from data {name}, please be patient...");
AssetBundle temp = AssetBundle.LoadFromMemory(bytes);
MelonLogger.Msg($"Done!");
return temp;
}
return null;
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StressLevelZero.Interaction;
using StressLevelZero.Player;
using StressLevelZero.Rig;
using StressLevelZero.VRMK;
using UnhollowerBaseLib;
using UnityEngine;
namespace BoneSync.Data
{
// copied from Entanglement mod
public static class PlayerScripts
{
public static RigManager playerRig;
public static PhysBody playerPhysBody;
public static Player_Health playerHealth;
public static PhysGrounder playerGrounder;
public static Hand playerLeftHand;
public static Hand playerRightHand;
public static bool reloadLevelOnDeath;
public static RuntimeAnimatorController playerAnimatorController;
public static Il2CppStringArray playerHandPoses = null;
public static void GetPlayerScripts()
{
GameObject localPlayerRig = GameObject.Find("[RigManager (Default Brett)]/[SkeletonRig (GameWorld Brett)]");
playerRig = localPlayerRig.GetComponentInChildren<RigManager>();
playerHealth = playerRig.playerHealth;
reloadLevelOnDeath = playerHealth.reloadLevelOnDeath;
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;
GetHandPoses();
}
public static void GetHandPoses()
{
// Checks if we already got the hand poses to prevent crashes
if (playerHandPoses == null)
CharacterAnimationManager.FetchHandPoseList(out playerHandPoses); // Lets hope this is constant!
}
}
}

View File

@@ -20,36 +20,6 @@ using UnhollowerBaseLib;
namespace BoneSync.Player namespace BoneSync.Player
{ {
public static class EmebeddedAssetBundle
{
// Credit to the "Entanglement" mod. The playerrep asset bundle is also by them.
public static AssetBundle LoadFromAssembly(string name)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string[] manifestResources = assembly.GetManifestResourceNames();
if (manifestResources.Contains(name))
{
MelonLogger.Msg($"Loading embedded bundle data {name}...");
byte[] bytes;
using (Stream str = assembly.GetManifestResourceStream(name))
using (MemoryStream memoryStream = new MemoryStream())
{
str.CopyTo(memoryStream);
bytes = memoryStream.ToArray();
}
MelonLogger.Msg($"Loading bundle from data {name}, please be patient...");
AssetBundle temp = AssetBundle.LoadFromMemory(bytes);
MelonLogger.Msg($"Done!");
return temp;
}
return null;
}
}
internal class PlayerRig internal class PlayerRig
{ {
private const float RIG_SYNC_FPS = 30; private const float RIG_SYNC_FPS = 30;
@@ -168,6 +138,8 @@ namespace BoneSync.Player
MelonLogger.Msg("playerRepBundle is null! Did you forget to load the bundle?"); MelonLogger.Msg("playerRepBundle is null! Did you forget to load the bundle?");
return null; return null;
} }
PlayerScripts.GetPlayerScripts();
PlayerRig rig = new PlayerRig(ownerId); PlayerRig rig = new PlayerRig(ownerId);
rig.EnsurePlayerRig(); rig.EnsurePlayerRig();
return rig; return rig;
@@ -185,7 +157,7 @@ namespace BoneSync.Player
if (playerRig != null) return; if (playerRig != null) return;
playerRig = GameObject.Instantiate(rigBundle.LoadAsset<GameObject>("PlayerRep")); playerRig = GameObject.Instantiate(rigBundle.LoadAsset<GameObject>("PlayerRep"));
playerRig.name = "PlayerRep"; playerRig.name = "PlayerRep (" + _ownerId + ")";
body = playerRig.GetComponentInChildren<SLZ_Body>(); body = playerRig.GetComponentInChildren<SLZ_Body>();
characterAnimationManager = playerRig.GetComponentInChildren<CharacterAnimationManager>(); characterAnimationManager = playerRig.GetComponentInChildren<CharacterAnimationManager>();
@@ -236,44 +208,4 @@ namespace BoneSync.Player
GameObject.Destroy(playerRig); GameObject.Destroy(playerRig);
} }
} }
// copied from Entanglement mod
public static class PlayerScripts
{
public static RigManager playerRig;
public static PhysBody playerPhysBody;
public static Player_Health playerHealth;
public static PhysGrounder playerGrounder;
public static Hand playerLeftHand;
public static Hand playerRightHand;
public static bool reloadLevelOnDeath;
public static RuntimeAnimatorController playerAnimatorController;
public static Il2CppStringArray playerHandPoses = null;
public static void GetPlayerScripts()
{
GameObject localPlayerRig = GameObject.Find("[RigManager (Default Brett)]/[SkeletonRig (GameWorld Brett)]");
playerRig = localPlayerRig.GetComponentInChildren<RigManager>();
playerHealth = playerRig.playerHealth;
reloadLevelOnDeath = playerHealth.reloadLevelOnDeath;
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;
GetHandPoses();
}
public static void GetHandPoses()
{
// Checks if we already got the hand poses to prevent crashes
if (playerHandPoses == null)
CharacterAnimationManager.FetchHandPoseList(out playerHandPoses); // Lets hope this is constant!
}
}
} }