From 28715ef80dc1399ad1c638459a5aa2a2f86ec5d1 Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Fri, 7 Mar 2025 18:58:39 +0200 Subject: [PATCH] holster sync fixes and gun sync fixes --- BoneSync/Patching/CallPatchedMethod.cs | 8 ++++++ BoneSync/Patching/GunPatches.cs | 25 +++++++++---------- BoneSync/Patching/HolsterSlotPatches.cs | 5 ++-- .../Sync/Components/SyncableProperties.cs | 3 ++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/BoneSync/Patching/CallPatchedMethod.cs b/BoneSync/Patching/CallPatchedMethod.cs index 1b58945..3287b47 100644 --- a/BoneSync/Patching/CallPatchedMethod.cs +++ b/BoneSync/Patching/CallPatchedMethod.cs @@ -1,6 +1,7 @@ using StressLevelZero.Combat; using StressLevelZero.Pool; using StressLevelZero.Props; +using StressLevelZero.Props.Weapons; using System; using System.Collections.Generic; using System.Linq; @@ -30,6 +31,13 @@ namespace BoneSync.Patching __instance.TAKEDAMAGE(damage, crit, attackType); allowPatchedMethodCall = false; } + + public static void FireGun(Gun __instance) + { + allowPatchedMethodCall = true; + __instance.Fire(); + allowPatchedMethodCall = false; + } public static Poolee InstantiatePoolee(Pool pool, Vector3 position, Quaternion rotation, Vector3 scale) { diff --git a/BoneSync/Patching/GunPatches.cs b/BoneSync/Patching/GunPatches.cs index af9e1b4..2c1b6c7 100644 --- a/BoneSync/Patching/GunPatches.cs +++ b/BoneSync/Patching/GunPatches.cs @@ -26,21 +26,20 @@ namespace BoneSync.Patching Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject); if (syncable == null) return true; if (!syncable.Registered) return true; + if (!syncable.isOwner) return false; // only allow owner to fire - if (syncable.isOwner) + MelonLogger.Msg("Sending gun fire message: " + __instance.name); + GunSyncInfo gunSyncInfo = new GunSyncInfo() { - MelonLogger.Msg("Sending gun fire message: " + __instance.name); - GunSyncInfo gunSyncInfo = new GunSyncInfo() - { - cartridgeState = __instance.cartridgeState, - hammerState = __instance.hammerState, - syncId = syncable.GetSyncId(), - messageType = GunSyncMessageType.Fire, - }; + cartridgeState = __instance.cartridgeState, + hammerState = __instance.hammerState, + syncId = syncable.GetSyncId(), + messageType = GunSyncMessageType.Fire, + bulletObject = __instance.chamberedCartridge + }; - GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo); - gunSyncMessage.Broadcast(); - } + GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo); + gunSyncMessage.Broadcast(); return true; } @@ -49,7 +48,7 @@ namespace BoneSync.Patching [HarmonyPatch(nameof(Gun.OnFire)), HarmonyPrefix] public static bool OnFirePatch(Gun __instance) { - if (CallPatchedMethods.allowPatchedMethodCall) return true; + //if (CallPatchedMethods.allowPatchedMethodCall) return true; // this patch should always be called MelonLoader.MelonLogger.Msg("Gun.OnFire: " + __instance.name); if (!BoneSync.lobby.IsConnected()) return true; diff --git a/BoneSync/Patching/HolsterSlotPatches.cs b/BoneSync/Patching/HolsterSlotPatches.cs index 0130d29..b46b626 100644 --- a/BoneSync/Patching/HolsterSlotPatches.cs +++ b/BoneSync/Patching/HolsterSlotPatches.cs @@ -12,9 +12,10 @@ using System.Text; using System.Threading.Tasks; namespace BoneSync.Patching { + [HarmonyPatch(typeof(HandWeaponSlotReciever))] internal class HolsterSlotPatches { - [HarmonyPatch(typeof(HandWeaponSlotReciever), nameof(HandWeaponSlotReciever.MakeStatic))] + [HarmonyPatch(nameof(HandWeaponSlotReciever.MakeStatic)), HarmonyPrefix] public static void StaticPatch(HandWeaponSlotReciever __instance) { MelonLogger.Msg("HandWeaponSlotReciever.MakeStatic: " + __instance.name); @@ -29,7 +30,7 @@ namespace BoneSync.Patching syncable?.SetInHolster(true); } - [HarmonyPatch(typeof(HandWeaponSlotReciever), nameof(HandWeaponSlotReciever.MakeDynamic))] + [HarmonyPatch(nameof(HandWeaponSlotReciever.MakeDynamic)), HarmonyPrefix] public static void DynamicPatch(HandWeaponSlotReciever __instance) { MelonLogger.Msg("HandWeaponSlotReciever.MakeDynamic: " + __instance.name); diff --git a/BoneSync/Sync/Components/SyncableProperties.cs b/BoneSync/Sync/Components/SyncableProperties.cs index e1df861..7628d26 100644 --- a/BoneSync/Sync/Components/SyncableProperties.cs +++ b/BoneSync/Sync/Components/SyncableProperties.cs @@ -1,4 +1,5 @@ using BoneSync.Networking.Messages; +using BoneSync.Patching; using StressLevelZero.Combat; using System; using System.Collections.Generic; @@ -54,7 +55,7 @@ namespace BoneSync.Sync.Components if (gunSyncInfo.messageType == GunSyncMessageType.Fire) { - gun.Fire(); + CallPatchedMethods.FireGun(gun); } } }