Player sync styff
This commit is contained in:
@@ -89,6 +89,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Data\ByteEncoder.cs" />
|
||||
<Compile Include="Data\EmebeddedAssetBundle.cs" />
|
||||
<Compile Include="Data\PlayerScripts.cs" />
|
||||
<Compile Include="Data\SpawnableManager.cs" />
|
||||
<Compile Include="Data\Structs.cs" />
|
||||
<Compile Include="Networking\Messages\DiscardSyncableMessage.cs" />
|
||||
|
||||
42
BoneSync/Data/EmebeddedAssetBundle.cs
Normal file
42
BoneSync/Data/EmebeddedAssetBundle.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
BoneSync/Data/PlayerScripts.cs
Normal file
54
BoneSync/Data/PlayerScripts.cs
Normal 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!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user