More Networking stuff
This commit is contained in:
@@ -116,6 +116,7 @@
|
|||||||
<Compile Include="Networking\Messages\ObjectDamageMessage.cs" />
|
<Compile Include="Networking\Messages\ObjectDamageMessage.cs" />
|
||||||
<Compile Include="Networking\Messages\ObjectSyncMessage.cs" />
|
<Compile Include="Networking\Messages\ObjectSyncMessage.cs" />
|
||||||
<Compile Include="Networking\Messages\RegisterSyncableMessage.cs" />
|
<Compile Include="Networking\Messages\RegisterSyncableMessage.cs" />
|
||||||
|
<Compile Include="Patching\CallPatchedMethod.cs" />
|
||||||
<Compile Include="Patching\InteractableHostPatches.cs" />
|
<Compile Include="Patching\InteractableHostPatches.cs" />
|
||||||
<Compile Include="Patching\ObjectHealthPatches.cs" />
|
<Compile Include="Patching\ObjectHealthPatches.cs" />
|
||||||
<Compile Include="Sync\Components\SyncableBase.cs" />
|
<Compile Include="Sync\Components\SyncableBase.cs" />
|
||||||
|
|||||||
@@ -194,5 +194,23 @@ namespace BoneSync.Networking
|
|||||||
WriteEnum(attack.attackType);
|
WriteEnum(attack.attackType);
|
||||||
WriteFloat(attack.damage);
|
WriteFloat(attack.damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WriteMatrix4x4(UnityEngine.Matrix4x4 matrix)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
WriteFloat(matrix[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnityEngine.Matrix4x4 ReadMatrix4x4()
|
||||||
|
{
|
||||||
|
UnityEngine.Matrix4x4 matrix = new UnityEngine.Matrix4x4();
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
matrix[i] = ReadFloat();
|
||||||
|
}
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
BoneSync/Patching/CallPatchedMethod.cs
Normal file
42
BoneSync/Patching/CallPatchedMethod.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using StressLevelZero.Combat;
|
||||||
|
using StressLevelZero.Pool;
|
||||||
|
using StressLevelZero.Props;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace BoneSync.Patching
|
||||||
|
{
|
||||||
|
public static class CallPatchedMethods
|
||||||
|
{
|
||||||
|
public static bool allowPatchedMethodCall
|
||||||
|
{
|
||||||
|
private set;
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
public static void TakeDamage(ObjectDestructable __instance, ref Vector3 normal, ref float damage, ref bool crit, ref AttackType attackType)
|
||||||
|
{
|
||||||
|
allowPatchedMethodCall = true;
|
||||||
|
__instance.TakeDamage(normal, damage, crit, attackType);
|
||||||
|
allowPatchedMethodCall = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TakeDamage(Prop_Health __instance, ref float damage, ref bool crit, ref AttackType attackType)
|
||||||
|
{
|
||||||
|
allowPatchedMethodCall = true;
|
||||||
|
__instance.TAKEDAMAGE(damage, crit, attackType);
|
||||||
|
allowPatchedMethodCall = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameObject PoolSpawn(Pool __instance, ref Vector3 position, ref Quaternion rotation, ref Il2CppSystem.Nullable<Vector3> scale, ref Il2CppSystem.Nullable<bool> autoEnable)
|
||||||
|
{
|
||||||
|
allowPatchedMethodCall = true;
|
||||||
|
GameObject result = __instance.Spawn(position, rotation, scale, autoEnable);
|
||||||
|
allowPatchedMethodCall = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,28 +14,6 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace BoneSync.Patching
|
namespace BoneSync.Patching
|
||||||
{
|
{
|
||||||
public static class CallPatchedMethods
|
|
||||||
{
|
|
||||||
public static bool allowDamageMethodCall
|
|
||||||
{
|
|
||||||
private set;
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
public static void TakeDamage(ObjectDestructable __instance, ref Vector3 normal, ref float damage, ref bool crit, ref AttackType attackType)
|
|
||||||
{
|
|
||||||
allowDamageMethodCall = true;
|
|
||||||
__instance.TakeDamage(normal, damage, crit, attackType);
|
|
||||||
allowDamageMethodCall = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TakeDamage(Prop_Health __instance, ref float damage, ref bool crit, ref AttackType attackType)
|
|
||||||
{
|
|
||||||
allowDamageMethodCall = true;
|
|
||||||
__instance.TAKEDAMAGE(damage, crit, attackType);
|
|
||||||
allowDamageMethodCall = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(ObjectDestructable))]
|
[HarmonyPatch(typeof(ObjectDestructable))]
|
||||||
public class ObjectDestructablePatches
|
public class ObjectDestructablePatches
|
||||||
{
|
{
|
||||||
@@ -43,7 +21,7 @@ namespace BoneSync.Patching
|
|||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
private static bool TakeDamagePatch(ObjectDestructable __instance, ref Vector3 normal, ref float damage, ref bool crit, ref AttackType attackType)
|
private static bool TakeDamagePatch(ObjectDestructable __instance, ref Vector3 normal, ref float damage, ref bool crit, ref AttackType attackType)
|
||||||
{
|
{
|
||||||
if (CallPatchedMethods.allowDamageMethodCall) return true;
|
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||||
MelonLoader.MelonLogger.Msg("ObjectDestructable.TakeDamage: " + damage);
|
MelonLoader.MelonLogger.Msg("ObjectDestructable.TakeDamage: " + damage);
|
||||||
Syncable syncable = ObjectSync.GetSyncableFromCache(__instance.gameObject);
|
Syncable syncable = ObjectSync.GetSyncableFromCache(__instance.gameObject);
|
||||||
if (syncable != null)
|
if (syncable != null)
|
||||||
@@ -67,7 +45,7 @@ namespace BoneSync.Patching
|
|||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
private static bool TakeDamagePatch(Prop_Health __instance, ref float damage, ref bool crit, ref AttackType attackType)
|
private static bool TakeDamagePatch(Prop_Health __instance, ref float damage, ref bool crit, ref AttackType attackType)
|
||||||
{
|
{
|
||||||
if (CallPatchedMethods.allowDamageMethodCall) return true;
|
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||||
MelonLoader.MelonLogger.Msg("Prop_Health.TAKEDAMAGE: " + damage);
|
MelonLoader.MelonLogger.Msg("Prop_Health.TAKEDAMAGE: " + damage);
|
||||||
Syncable syncable = ObjectSync.GetSyncableFromCache(__instance.gameObject);
|
Syncable syncable = ObjectSync.GetSyncableFromCache(__instance.gameObject);
|
||||||
if (syncable != null)
|
if (syncable != null)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
@@ -11,31 +12,31 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace BoneSync.Patching
|
namespace BoneSync.Patching
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
[HarmonyPatch(typeof(Pool))]
|
[HarmonyPatch(typeof(Pool))]
|
||||||
internal class PoolPatches
|
internal class PoolPatches
|
||||||
{
|
{
|
||||||
|
|
||||||
[HarmonyPatch(nameof(Pool.Spawn))]
|
[HarmonyPatch(nameof(Pool.Spawn))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void SpawnPatch(Pool __instance, ref GameObject __result)
|
private static void SpawnPatchPost(Pool __instance, ref GameObject __result)
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Spawned object: " + __result.name);
|
//MelonLogger.Msg("Spawned object: " + __result.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(Pool.FlagPooleeForRespawn))]
|
[HarmonyPatch(nameof(Pool.Spawn))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPrefix]
|
||||||
private static void FlagPooleeForRespawnPatch(Pool __instance, ref GameObject p)
|
private static bool SpawnPatchPre(Pool __instance, ref Vector3 position, ref Quaternion rotation, ref Il2CppSystem.Nullable<Vector3> scale, ref Il2CppSystem.Nullable<bool> autoEnable)
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Flagged object for respawn: " + p.name);
|
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||||
|
|
||||||
|
if (BoneSync.lobby.IsConnected())
|
||||||
|
{
|
||||||
|
MelonLogger.Msg("Patched Spawning object in pool: " + __instance.name);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
[HarmonyPatch(nameof(Pool.InstantiatePoolee))]
|
return true;
|
||||||
[HarmonyPostfix]
|
|
||||||
private static void InstantiatePooleePatch(Pool __instance, ref Poolee __result)
|
|
||||||
{
|
|
||||||
MelonLogger.Msg("Instantiated object: " + __result.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ using System.Collections;
|
|||||||
using StressLevelZero.Props;
|
using StressLevelZero.Props;
|
||||||
using BoneSync.Patching;
|
using BoneSync.Patching;
|
||||||
using StressLevelZero.Props.Weapons;
|
using StressLevelZero.Props.Weapons;
|
||||||
|
using StressLevelZero.AI;
|
||||||
|
using PuppetMasta;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
|
||||||
namespace BoneSync.Sync.Components
|
namespace BoneSync.Sync.Components
|
||||||
@@ -105,14 +108,13 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
private Plug[] plugs;
|
private Plug[] plugs;
|
||||||
|
|
||||||
|
private AIBrain aiBrain;
|
||||||
|
private PuppetMaster puppetMaster;
|
||||||
|
|
||||||
|
|
||||||
public void OnEnable()
|
public void OnEnable()
|
||||||
{
|
{
|
||||||
FindComponents();
|
FindComponents();
|
||||||
MelonLogger.Msg("Syncable enabled: " + transform.GetPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetSyncableWorldPath()
|
public string GetSyncableWorldPath()
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
private void UpdateTransformList()
|
private void UpdateTransformList()
|
||||||
{
|
{
|
||||||
Rigidbody[] rbs = UpdateRigidbodyList();
|
// get non-null rigidbodies
|
||||||
|
Rigidbody[] rbs = UpdateRigidbodyList().Where(rb => rb != null).ToArray();
|
||||||
rigidbodies = rbs;
|
rigidbodies = rbs;
|
||||||
_transforms = rbs.Select(rb => rb.transform).ToArray();
|
_transforms = rbs.Select(rb => rb.transform).ToArray();
|
||||||
}
|
}
|
||||||
@@ -82,5 +83,7 @@ namespace BoneSync.Sync.Components
|
|||||||
{
|
{
|
||||||
SetKinematic(_ownerId != BoneSync.lobby.GetLocalId() && Registered);
|
SetKinematic(_ownerId != BoneSync.lobby.GetLocalId() && Registered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on collision
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
namespace BoneSync.Sync
|
namespace BoneSync.Sync
|
||||||
{
|
{
|
||||||
@@ -87,6 +88,9 @@ namespace BoneSync.Sync
|
|||||||
}
|
}
|
||||||
private static Syncable _MakeOrGetSyncable(GameObject gameObject, bool deleteSubSyncabled = true)
|
private static Syncable _MakeOrGetSyncable(GameObject gameObject, bool deleteSubSyncabled = true)
|
||||||
{
|
{
|
||||||
|
//Scene scene = gameObject.scene;
|
||||||
|
//MelonLogger.Msg("Making or getting syncable for: " + gameObject.name + " in scene: " + scene.name);
|
||||||
|
|
||||||
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>();
|
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>();
|
||||||
Syncable syncable = gameObject.GetComponent<Syncable>();
|
Syncable syncable = gameObject.GetComponent<Syncable>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user