holster sync fixes and gun sync fixes

This commit is contained in:
Aaro Varis
2025-03-07 18:58:39 +02:00
parent 54301cbf37
commit 28715ef80d
4 changed files with 25 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
using StressLevelZero.Combat; using StressLevelZero.Combat;
using StressLevelZero.Pool; using StressLevelZero.Pool;
using StressLevelZero.Props; using StressLevelZero.Props;
using StressLevelZero.Props.Weapons;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -31,6 +32,13 @@ namespace BoneSync.Patching
allowPatchedMethodCall = false; 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) public static Poolee InstantiatePoolee(Pool pool, Vector3 position, Quaternion rotation, Vector3 scale)
{ {
allowPatchedMethodCall = true; allowPatchedMethodCall = true;

View File

@@ -26,21 +26,20 @@ namespace BoneSync.Patching
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject); Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
if (syncable == null) return true; if (syncable == null) return true;
if (!syncable.Registered) 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); cartridgeState = __instance.cartridgeState,
GunSyncInfo gunSyncInfo = new GunSyncInfo() hammerState = __instance.hammerState,
{ syncId = syncable.GetSyncId(),
cartridgeState = __instance.cartridgeState, messageType = GunSyncMessageType.Fire,
hammerState = __instance.hammerState, bulletObject = __instance.chamberedCartridge
syncId = syncable.GetSyncId(), };
messageType = GunSyncMessageType.Fire,
};
GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo); GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo);
gunSyncMessage.Broadcast(); gunSyncMessage.Broadcast();
}
return true; return true;
} }
@@ -49,7 +48,7 @@ namespace BoneSync.Patching
[HarmonyPatch(nameof(Gun.OnFire)), HarmonyPrefix] [HarmonyPatch(nameof(Gun.OnFire)), HarmonyPrefix]
public static bool OnFirePatch(Gun __instance) 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); MelonLoader.MelonLogger.Msg("Gun.OnFire: " + __instance.name);
if (!BoneSync.lobby.IsConnected()) return true; if (!BoneSync.lobby.IsConnected()) return true;

View File

@@ -12,9 +12,10 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BoneSync.Patching namespace BoneSync.Patching
{ {
[HarmonyPatch(typeof(HandWeaponSlotReciever))]
internal class HolsterSlotPatches internal class HolsterSlotPatches
{ {
[HarmonyPatch(typeof(HandWeaponSlotReciever), nameof(HandWeaponSlotReciever.MakeStatic))] [HarmonyPatch(nameof(HandWeaponSlotReciever.MakeStatic)), HarmonyPrefix]
public static void StaticPatch(HandWeaponSlotReciever __instance) public static void StaticPatch(HandWeaponSlotReciever __instance)
{ {
MelonLogger.Msg("HandWeaponSlotReciever.MakeStatic: " + __instance.name); MelonLogger.Msg("HandWeaponSlotReciever.MakeStatic: " + __instance.name);
@@ -29,7 +30,7 @@ namespace BoneSync.Patching
syncable?.SetInHolster(true); syncable?.SetInHolster(true);
} }
[HarmonyPatch(typeof(HandWeaponSlotReciever), nameof(HandWeaponSlotReciever.MakeDynamic))] [HarmonyPatch(nameof(HandWeaponSlotReciever.MakeDynamic)), HarmonyPrefix]
public static void DynamicPatch(HandWeaponSlotReciever __instance) public static void DynamicPatch(HandWeaponSlotReciever __instance)
{ {
MelonLogger.Msg("HandWeaponSlotReciever.MakeDynamic: " + __instance.name); MelonLogger.Msg("HandWeaponSlotReciever.MakeDynamic: " + __instance.name);

View File

@@ -1,4 +1,5 @@
using BoneSync.Networking.Messages; using BoneSync.Networking.Messages;
using BoneSync.Patching;
using StressLevelZero.Combat; using StressLevelZero.Combat;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -54,7 +55,7 @@ namespace BoneSync.Sync.Components
if (gunSyncInfo.messageType == GunSyncMessageType.Fire) if (gunSyncInfo.messageType == GunSyncMessageType.Fire)
{ {
gun.Fire(); CallPatchedMethods.FireGun(gun);
} }
} }
} }