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

@@ -20,36 +20,6 @@ using UnhollowerBaseLib;
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
{
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?");
return null;
}
PlayerScripts.GetPlayerScripts();
PlayerRig rig = new PlayerRig(ownerId);
rig.EnsurePlayerRig();
return rig;
@@ -185,7 +157,7 @@ namespace BoneSync.Player
if (playerRig != null) return;
playerRig = GameObject.Instantiate(rigBundle.LoadAsset<GameObject>("PlayerRep"));
playerRig.name = "PlayerRep";
playerRig.name = "PlayerRep (" + _ownerId + ")";
body = playerRig.GetComponentInChildren<SLZ_Body>();
characterAnimationManager = playerRig.GetComponentInChildren<CharacterAnimationManager>();
@@ -236,44 +208,4 @@ namespace BoneSync.Player
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!
}
}
}