changed some zone patch stuff
This commit is contained in:
@@ -53,8 +53,8 @@ namespace BoneSync
|
|||||||
|
|
||||||
public static void PatchAll()
|
public static void PatchAll()
|
||||||
{
|
{
|
||||||
HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("com.aarov.bonesync");
|
//HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("com.aarov.bonesync");
|
||||||
harmony.PatchAll();
|
//harmony.i
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ namespace BoneSync.Networking
|
|||||||
}
|
}
|
||||||
Queue<NetworkMessage> queue = _packetQueues[sceneIndex];
|
Queue<NetworkMessage> queue = _packetQueues[sceneIndex];
|
||||||
int processed = 0;
|
int processed = 0;
|
||||||
while (queue.Count > 0 && processed < 10)
|
while (queue.Count > 0 && processed < 10 && SceneSync.TimeSinceLastSceneChange > SceneSync.MAP_LOAD_GRACE_PERIOD)
|
||||||
{
|
{
|
||||||
processed++;
|
processed++;
|
||||||
NetworkMessage networkMessage = queue.Dequeue();
|
NetworkMessage networkMessage = queue.Dequeue();
|
||||||
|
|||||||
@@ -3,18 +3,23 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BoneSync.Sync.Components;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using PuppetMasta;
|
using PuppetMasta;
|
||||||
namespace BoneSync.Patching
|
namespace BoneSync.Patching
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
[HarmonyPatch(typeof(SubBehaviourHealth))]
|
[HarmonyPatch(typeof(SubBehaviourHealth))]
|
||||||
internal class AIHealthPatches
|
internal class AIHealthPatches
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(SubBehaviourHealth.TakeDamage)), HarmonyPostfix]
|
[HarmonyPatch(nameof(SubBehaviourHealth.TakeDamage)), HarmonyPrefix]
|
||||||
private static void DamagePrefix(SubBehaviourHealth __instance)
|
private static bool DamagePrefix(SubBehaviourHealth __instance)
|
||||||
{
|
{
|
||||||
|
if (!BoneSync.IsConnected) return true;
|
||||||
|
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||||
|
Syncable syncable = __instance.behaviour.GetComponentInParent<Syncable>();
|
||||||
|
if (syncable != null && syncable.Registered && !syncable.isOwner) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ namespace BoneSync.Patching
|
|||||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||||
if (!BoneSync.IsConnected) return true;
|
if (!BoneSync.IsConnected) return true;
|
||||||
if (damage < 0.05f) return true; // ignore small damage (e.g. a little bit of fall damage)
|
if (damage < 0.05f) return true; // ignore small damage (e.g. a little bit of fall damage)
|
||||||
MelonLoader.MelonLogger.Msg("ObjectDestructable.TakeDamage: " + damage);
|
//MelonLoader.MelonLogger.Msg("ObjectDestructable.TakeDamage: " + damage);
|
||||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
||||||
if (syncable != null)
|
if (syncable != null)
|
||||||
{
|
{
|
||||||
if (damage > 0.5f) syncable.RegisterSyncable(); // register syncable if damage is very significant, e.g. a bullet hit
|
if (damage > 0.5f) syncable.RegisterSyncable(); // register syncable if damage is very significant, e.g. a bullet hit
|
||||||
if (syncable.Registered && !syncable.isOwner) return false;
|
if (syncable.Registered && !syncable.isOwner) return false;
|
||||||
MelonLoader.MelonLogger.Msg("Patch: ObjectDestructable.TakeDamage: " + damage + " " + syncable.gameObject.name);
|
//MelonLoader.MelonLogger.Msg("Patch: ObjectDestructable.TakeDamage: " + damage + " " + syncable.gameObject.name);
|
||||||
ObjectHealthInfo objectHealthInfo = new ObjectHealthInfo(__instance._health, __instance._hits, normal, damage, crit, attackType);
|
ObjectHealthInfo objectHealthInfo = new ObjectHealthInfo(__instance._health, __instance._hits, normal, damage, crit, attackType);
|
||||||
|
|
||||||
ObjectSync.SendObjectDamageMessage(syncable, ObjectDamageType.DestructibleTakeDamage, objectHealthInfo);
|
ObjectSync.SendObjectDamageMessage(syncable, ObjectDamageType.DestructibleTakeDamage, objectHealthInfo);
|
||||||
@@ -67,13 +67,13 @@ namespace BoneSync.Patching
|
|||||||
{
|
{
|
||||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||||
if (!BoneSync.IsConnected) return true;
|
if (!BoneSync.IsConnected) return true;
|
||||||
MelonLoader.MelonLogger.Msg("Prop_Health.TAKEDAMAGE: " + damage);
|
//MelonLoader.MelonLogger.Msg("Prop_Health.TAKEDAMAGE: " + damage);
|
||||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
||||||
if (syncable != null)
|
if (syncable != null)
|
||||||
{
|
{
|
||||||
if (damage > 0.5f) syncable.RegisterSyncable();
|
if (damage > 0.5f) syncable.RegisterSyncable();
|
||||||
if (syncable.Registered && !syncable.isOwner) return false;
|
if (syncable.Registered && !syncable.isOwner) return false;
|
||||||
MelonLoader.MelonLogger.Msg("Patch: Prop_Health.TAKEDAMAGE: " + damage + " " + syncable.gameObject.name);
|
//MelonLoader.MelonLogger.Msg("Patch: Prop_Health.TAKEDAMAGE: " + damage + " " + syncable.gameObject.name);
|
||||||
ObjectHealthInfo objectHealthInfo = new ObjectHealthInfo(__instance.cur_Health, __instance.hits, Vector3.zero, damage, crit, attackType);
|
ObjectHealthInfo objectHealthInfo = new ObjectHealthInfo(__instance.cur_Health, __instance.hits, Vector3.zero, damage, crit, attackType);
|
||||||
|
|
||||||
ObjectSync.SendObjectDamageMessage(syncable, ObjectDamageType.PropHealthTakeDamage, objectHealthInfo);
|
ObjectSync.SendObjectDamageMessage(syncable, ObjectDamageType.PropHealthTakeDamage, objectHealthInfo);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BoneSync.Player;
|
||||||
using BoneSync.Sync.Components;
|
using BoneSync.Sync.Components;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
@@ -13,79 +14,6 @@ using UnityEngine;
|
|||||||
namespace BoneSync.Patching
|
namespace BoneSync.Patching
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class ZoneTrackingUtilities
|
|
||||||
{
|
|
||||||
public static Dictionary<SceneZone, int> zoneCount = new Dictionary<SceneZone, int>();
|
|
||||||
public static Dictionary<PlayerTrigger, int> triggerCount = new Dictionary<PlayerTrigger, int>();
|
|
||||||
|
|
||||||
public static void Increment(SceneZone zone)
|
|
||||||
{
|
|
||||||
if (!zoneCount.ContainsKey(zone))
|
|
||||||
zoneCount.Add(zone, 0);
|
|
||||||
|
|
||||||
zoneCount[zone]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Decrement(SceneZone zone)
|
|
||||||
{
|
|
||||||
if (!zoneCount.ContainsKey(zone))
|
|
||||||
zoneCount.Add(zone, 0);
|
|
||||||
|
|
||||||
zoneCount[zone]--;
|
|
||||||
zoneCount[zone] = Mathf.Clamp(zoneCount[zone], 0, int.MaxValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CanEnter(SceneZone zone)
|
|
||||||
{
|
|
||||||
if (!zoneCount.ContainsKey(zone))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return zoneCount[zone] <= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CanExit(SceneZone zone)
|
|
||||||
{
|
|
||||||
if (!zoneCount.ContainsKey(zone))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return zoneCount[zone] <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Increment(PlayerTrigger trigger)
|
|
||||||
{
|
|
||||||
if (!triggerCount.ContainsKey(trigger))
|
|
||||||
triggerCount.Add(trigger, 0);
|
|
||||||
|
|
||||||
triggerCount[trigger]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Decrement(PlayerTrigger trigger)
|
|
||||||
{
|
|
||||||
if (!triggerCount.ContainsKey(trigger))
|
|
||||||
triggerCount.Add(trigger, 0);
|
|
||||||
|
|
||||||
triggerCount[trigger]--;
|
|
||||||
triggerCount[trigger] = Mathf.Clamp(triggerCount[trigger], 0, int.MaxValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CanEnter(PlayerTrigger trigger)
|
|
||||||
{
|
|
||||||
if (!triggerCount.ContainsKey(trigger))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return triggerCount[trigger] <= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CanExit(PlayerTrigger trigger)
|
|
||||||
{
|
|
||||||
if (!triggerCount.ContainsKey(trigger))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return triggerCount[trigger] <= 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(ZoneSpawner))]
|
[HarmonyPatch(typeof(ZoneSpawner))]
|
||||||
public static class ZoneSpawnerPatch
|
public static class ZoneSpawnerPatch
|
||||||
{
|
{
|
||||||
@@ -127,7 +55,7 @@ namespace BoneSync.Patching
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SceneZone and PlayerTrigger patches are based on the ones from entanglement mod
|
// SceneZone and PlayerTrigger patches are based on the ones from entanglement mod
|
||||||
/*
|
|
||||||
[HarmonyPatch(typeof(SceneZone))]
|
[HarmonyPatch(typeof(SceneZone))]
|
||||||
public static class SceneZonePatch
|
public static class SceneZonePatch
|
||||||
{
|
{
|
||||||
@@ -136,9 +64,7 @@ namespace BoneSync.Patching
|
|||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
ZoneTrackingUtilities.Increment(__instance);
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
||||||
bool canEnter = ZoneTrackingUtilities.CanEnter(__instance);
|
|
||||||
return canEnter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -149,9 +75,7 @@ namespace BoneSync.Patching
|
|||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
ZoneTrackingUtilities.Decrement(__instance);
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
||||||
bool canExit = ZoneTrackingUtilities.CanExit(__instance);
|
|
||||||
return canExit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -166,9 +90,8 @@ namespace BoneSync.Patching
|
|||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
ZoneTrackingUtilities.Increment(__instance);
|
|
||||||
bool canEnter = ZoneTrackingUtilities.CanEnter(__instance);
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
||||||
return canEnter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -179,12 +102,11 @@ namespace BoneSync.Patching
|
|||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
ZoneTrackingUtilities.Decrement(__instance);
|
|
||||||
bool canExit = ZoneTrackingUtilities.CanExit(__instance);
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
||||||
return canExit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,8 +109,9 @@ namespace BoneSync.Player
|
|||||||
public void UpdatePoseRadius(Handedness hand, float radius) => characterAnimationManager?.SetCylinderRadius(hand, radius);
|
public void UpdatePoseRadius(Handedness hand, float radius) => characterAnimationManager?.SetCylinderRadius(hand, radius);
|
||||||
|
|
||||||
|
|
||||||
private static GameObject localPlayerRig;
|
public static GameObject localPlayerRig;
|
||||||
private static Transform localRigRoot;
|
public static Transform localRigRoot;
|
||||||
|
|
||||||
private static Transform localRigHeadTransform;
|
private static Transform localRigHeadTransform;
|
||||||
private static Transform localRigLeftHandTransform;
|
private static Transform localRigLeftHandTransform;
|
||||||
private static Transform localRigRightHandTransform;
|
private static Transform localRigRightHandTransform;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
public bool ShouldAutoSync()
|
public bool ShouldAutoSync()
|
||||||
{
|
{
|
||||||
if (SceneSync.TimeSinceLastSceneChange < 5f) return false; // don't sync if scene just changed, to prevent some weird stuff that happens when a level is loaded
|
if (SceneSync.TimeSinceLastSceneChange < SceneSync.MAP_LOAD_GRACE_PERIOD) return false; // don't sync if scene just changed, to prevent some weird stuff that happens when a level is loaded
|
||||||
if (InPoolManagerTransform()) return false;
|
if (InPoolManagerTransform()) return false;
|
||||||
if (!gameObject.activeInHierarchy) return false;
|
if (!gameObject.activeInHierarchy) return false;
|
||||||
if (poolee && poolee.pool) {
|
if (poolee && poolee.pool) {
|
||||||
@@ -207,6 +207,7 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
UpdateTransformList();
|
UpdateTransformList();
|
||||||
TryPatchUnityEvents();
|
TryPatchUnityEvents();
|
||||||
|
TrySendAttributeSync();
|
||||||
|
|
||||||
ObjectSyncCache.AddSyncable(this);
|
ObjectSyncCache.AddSyncable(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,28 @@ namespace BoneSync.Sync.Components
|
|||||||
{
|
{
|
||||||
public partial class Syncable : MonoBehaviour
|
public partial class Syncable : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
private const float ATTRIBUTE_SYNC_FPS = 0.2f;
|
||||||
|
private float _lastAttributeSyncTime;
|
||||||
|
|
||||||
private void StripDamage(ref BulletObject bulletObject)
|
private void StripDamage(ref BulletObject bulletObject)
|
||||||
{
|
{
|
||||||
AmmoVariables ammoVariables = bulletObject.ammoVariables;
|
AmmoVariables ammoVariables = bulletObject.ammoVariables;
|
||||||
ammoVariables.AttackDamage = 0f;
|
ammoVariables.AttackDamage = 0f;
|
||||||
bulletObject.ammoVariables = ammoVariables;
|
bulletObject.ammoVariables = ammoVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TrySendAttributeSync()
|
||||||
|
{
|
||||||
|
if (!Registered) return;
|
||||||
|
if (!isOwner) return;
|
||||||
|
if (Time.realtimeSinceStartup - _lastAttributeSyncTime > 1 / ATTRIBUTE_SYNC_FPS)
|
||||||
|
{
|
||||||
|
_SendAttributeSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void _SendAttributeSync()
|
private void _SendAttributeSync()
|
||||||
{
|
{
|
||||||
if (!isOwner) return;
|
|
||||||
_SendMagazineData();
|
_SendMagazineData();
|
||||||
}
|
}
|
||||||
public void ApplyMagazineData(MagazineSyncData magazineSyncData)
|
public void ApplyMagazineData(MagazineSyncData magazineSyncData)
|
||||||
@@ -68,7 +80,7 @@ namespace BoneSync.Sync.Components
|
|||||||
Quaternion rotation = firepointTransform.rotation;
|
Quaternion rotation = firepointTransform.rotation;
|
||||||
BulletObject bulletObject = gunSyncInfo.bulletObject;
|
BulletObject bulletObject = gunSyncInfo.bulletObject;
|
||||||
StripDamage(ref bulletObject);
|
StripDamage(ref bulletObject);
|
||||||
gun.EjectCartridge();
|
//gun.EjectCartridge();
|
||||||
PoolSpawner.SpawnProjectile(position, rotation, gunSyncInfo.bulletObject, "1911", null);
|
PoolSpawner.SpawnProjectile(position, rotation, gunSyncInfo.bulletObject, "1911", null);
|
||||||
PoolSpawner.SpawnMuzzleFlare(position, rotation, PoolSpawner.MuzzleFlareType.Default);
|
PoolSpawner.SpawnMuzzleFlare(position, rotation, PoolSpawner.MuzzleFlareType.Default);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ namespace BoneSync.Sync
|
|||||||
{
|
{
|
||||||
internal class SceneSync
|
internal class SceneSync
|
||||||
{
|
{
|
||||||
|
public const float MAP_LOAD_GRACE_PERIOD = 5f;
|
||||||
|
|
||||||
private static List<Scene> scenes = new List<Scene>();
|
private static List<Scene> scenes = new List<Scene>();
|
||||||
private static string _currentSceneName;
|
private static string _currentSceneName;
|
||||||
private static int _currentSceneIndex;
|
private static int _currentSceneIndex;
|
||||||
|
|||||||
Reference in New Issue
Block a user