changed some zone patch stuff

This commit is contained in:
Aaro Varis
2025-03-10 03:44:33 +02:00
parent a479fa8dd6
commit 68aa949591
9 changed files with 48 additions and 105 deletions

View File

@@ -53,8 +53,8 @@ namespace BoneSync
public static void PatchAll()
{
HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("com.aarov.bonesync");
harmony.PatchAll();
//HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("com.aarov.bonesync");
//harmony.i
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)

View File

@@ -170,7 +170,7 @@ namespace BoneSync.Networking
}
Queue<NetworkMessage> queue = _packetQueues[sceneIndex];
int processed = 0;
while (queue.Count > 0 && processed < 10)
while (queue.Count > 0 && processed < 10 && SceneSync.TimeSinceLastSceneChange > SceneSync.MAP_LOAD_GRACE_PERIOD)
{
processed++;
NetworkMessage networkMessage = queue.Dequeue();

View File

@@ -3,18 +3,23 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoneSync.Sync.Components;
using HarmonyLib;
using PuppetMasta;
namespace BoneSync.Patching
{
/*
[HarmonyPatch(typeof(SubBehaviourHealth))]
internal class AIHealthPatches
{
[HarmonyPatch(nameof(SubBehaviourHealth.TakeDamage)), HarmonyPostfix]
private static void DamagePrefix(SubBehaviourHealth __instance)
[HarmonyPatch(nameof(SubBehaviourHealth.TakeDamage)), HarmonyPrefix]
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;
}
}*/
}
}

View File

@@ -26,13 +26,13 @@ namespace BoneSync.Patching
if (CallPatchedMethods.allowPatchedMethodCall) return true;
if (!BoneSync.IsConnected) return true;
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);
if (syncable != null)
{
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;
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);
ObjectSync.SendObjectDamageMessage(syncable, ObjectDamageType.DestructibleTakeDamage, objectHealthInfo);
@@ -67,13 +67,13 @@ namespace BoneSync.Patching
{
if (CallPatchedMethods.allowPatchedMethodCall) 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);
if (syncable != null)
{
if (damage > 0.5f) syncable.RegisterSyncable();
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);
ObjectSync.SendObjectDamageMessage(syncable, ObjectDamageType.PropHealthTakeDamage, objectHealthInfo);

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoneSync.Player;
using BoneSync.Sync.Components;
using HarmonyLib;
using MelonLoader;
@@ -13,79 +14,6 @@ using UnityEngine;
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))]
public static class ZoneSpawnerPatch
{
@@ -127,7 +55,7 @@ namespace BoneSync.Patching
}
// SceneZone and PlayerTrigger patches are based on the ones from entanglement mod
/*
[HarmonyPatch(typeof(SceneZone))]
public static class SceneZonePatch
{
@@ -136,9 +64,7 @@ namespace BoneSync.Patching
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Increment(__instance);
bool canEnter = ZoneTrackingUtilities.CanEnter(__instance);
return canEnter;
return other.transform.IsChildOf(PlayerRig.localRigRoot);
}
return true;
@@ -149,9 +75,7 @@ namespace BoneSync.Patching
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Decrement(__instance);
bool canExit = ZoneTrackingUtilities.CanExit(__instance);
return canExit;
return other.transform.IsChildOf(PlayerRig.localRigRoot);
}
return true;
@@ -166,9 +90,8 @@ namespace BoneSync.Patching
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Increment(__instance);
bool canEnter = ZoneTrackingUtilities.CanEnter(__instance);
return canEnter;
return other.transform.IsChildOf(PlayerRig.localRigRoot);
}
return true;
@@ -179,12 +102,11 @@ namespace BoneSync.Patching
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Decrement(__instance);
bool canExit = ZoneTrackingUtilities.CanExit(__instance);
return canExit;
return other.transform.IsChildOf(PlayerRig.localRigRoot);
}
return true;
}
}*/
}
}

View File

@@ -109,8 +109,9 @@ namespace BoneSync.Player
public void UpdatePoseRadius(Handedness hand, float radius) => characterAnimationManager?.SetCylinderRadius(hand, radius);
private static GameObject localPlayerRig;
private static Transform localRigRoot;
public static GameObject localPlayerRig;
public static Transform localRigRoot;
private static Transform localRigHeadTransform;
private static Transform localRigLeftHandTransform;
private static Transform localRigRightHandTransform;

View File

@@ -156,7 +156,7 @@ namespace BoneSync.Sync.Components
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 (!gameObject.activeInHierarchy) return false;
if (poolee && poolee.pool) {
@@ -207,6 +207,7 @@ namespace BoneSync.Sync.Components
UpdateTransformList();
TryPatchUnityEvents();
TrySendAttributeSync();
ObjectSyncCache.AddSyncable(this);
}

View File

@@ -13,16 +13,28 @@ namespace BoneSync.Sync.Components
{
public partial class Syncable : MonoBehaviour
{
private const float ATTRIBUTE_SYNC_FPS = 0.2f;
private float _lastAttributeSyncTime;
private void StripDamage(ref BulletObject bulletObject)
{
AmmoVariables ammoVariables = bulletObject.ammoVariables;
ammoVariables.AttackDamage = 0f;
bulletObject.ammoVariables = ammoVariables;
}
private void TrySendAttributeSync()
{
if (!Registered) return;
if (!isOwner) return;
if (Time.realtimeSinceStartup - _lastAttributeSyncTime > 1 / ATTRIBUTE_SYNC_FPS)
{
_SendAttributeSync();
}
}
private void _SendAttributeSync()
{
if (!isOwner) return;
_SendMagazineData();
}
public void ApplyMagazineData(MagazineSyncData magazineSyncData)
@@ -68,7 +80,7 @@ namespace BoneSync.Sync.Components
Quaternion rotation = firepointTransform.rotation;
BulletObject bulletObject = gunSyncInfo.bulletObject;
StripDamage(ref bulletObject);
gun.EjectCartridge();
//gun.EjectCartridge();
PoolSpawner.SpawnProjectile(position, rotation, gunSyncInfo.bulletObject, "1911", null);
PoolSpawner.SpawnMuzzleFlare(position, rotation, PoolSpawner.MuzzleFlareType.Default);
return;

View File

@@ -14,6 +14,8 @@ namespace BoneSync.Sync
{
internal class SceneSync
{
public const float MAP_LOAD_GRACE_PERIOD = 5f;
private static List<Scene> scenes = new List<Scene>();
private static string _currentSceneName;
private static int _currentSceneIndex;