diff --git a/BoneSync/BoneSync.csproj b/BoneSync/BoneSync.csproj index 671feac..9f92ef2 100644 --- a/BoneSync/BoneSync.csproj +++ b/BoneSync/BoneSync.csproj @@ -89,6 +89,8 @@ + + diff --git a/BoneSync/Data/EmebeddedAssetBundle.cs b/BoneSync/Data/EmebeddedAssetBundle.cs new file mode 100644 index 0000000..27eaf8d --- /dev/null +++ b/BoneSync/Data/EmebeddedAssetBundle.cs @@ -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; + } + } +} diff --git a/BoneSync/Data/PlayerScripts.cs b/BoneSync/Data/PlayerScripts.cs new file mode 100644 index 0000000..7da651c --- /dev/null +++ b/BoneSync/Data/PlayerScripts.cs @@ -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(); + 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! + } + } +} diff --git a/BoneSync/Player/PlayerRig.cs b/BoneSync/Player/PlayerRig.cs index 51fc782..75604e7 100644 --- a/BoneSync/Player/PlayerRig.cs +++ b/BoneSync/Player/PlayerRig.cs @@ -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("PlayerRep")); - playerRig.name = "PlayerRep"; + playerRig.name = "PlayerRep (" + _ownerId + ")"; body = playerRig.GetComponentInChildren(); characterAnimationManager = playerRig.GetComponentInChildren(); @@ -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(); - 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! - } - } }