Mag and gun sync fixes

This commit is contained in:
Aaro Varis
2025-03-07 23:07:39 +02:00
parent 28715ef80d
commit 0030f68f99
5 changed files with 33 additions and 26 deletions

View File

@@ -279,6 +279,9 @@
<EmbeddedResource Include="steam_api.dll" />
<EmbeddedResource Include="steam_api64.dll" />
</ItemGroup>
<ItemGroup>
<None Include="playerrep.eres" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y "$(TargetPath)" "A:\SteamLibrary\steamapps\common\BONEWORKS\BONEWORKS\Mods\"

View File

@@ -1,5 +1,6 @@
using BoneSync.Sync;
using BoneSync.Sync.Components;
using MelonLoader;
using StressLevelZero.Combat;
using StressLevelZero.Props.Weapons;
using System;
@@ -25,7 +26,7 @@ namespace BoneSync.Networking.Messages
public Gun.CartridgeStates cartridgeState;
}
[PacketType(PacketType.GunSync)]
[PacketType(PacketType.GunSync), PacketReliability(PacketReliability.Unreliable)]
public class GunSyncMessage : NetworkMessage
{
GunSyncInfo gunSyncInfo;
@@ -54,6 +55,7 @@ namespace BoneSync.Networking.Messages
{
Syncable syncable = ObjectSyncCache.GetSyncable(gunSyncInfo.syncId);
if (syncable == null) return;
MelonLogger.Msg("GunSyncMessage.Execute: " + gunSyncInfo.syncId + ":" + syncable.name);
syncable.OnWeaponSyncData(gunSyncInfo);
}
}

View File

@@ -19,28 +19,6 @@ namespace BoneSync.Patching
[HarmonyPatch(nameof(Gun.Fire)), HarmonyPrefix]
public static bool FirePatch(Gun __instance)
{
if (CallPatchedMethods.allowPatchedMethodCall) return true;
MelonLoader.MelonLogger.Msg("Gun fired: " + __instance.name);
if (!BoneSync.lobby.IsConnected()) return true;
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
MelonLogger.Msg("Sending gun fire message: " + __instance.name);
GunSyncInfo gunSyncInfo = new GunSyncInfo()
{
cartridgeState = __instance.cartridgeState,
hammerState = __instance.hammerState,
syncId = syncable.GetSyncId(),
messageType = GunSyncMessageType.Fire,
bulletObject = __instance.chamberedCartridge
};
GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo);
gunSyncMessage.Broadcast();
return true;
}
@@ -48,14 +26,30 @@ namespace BoneSync.Patching
[HarmonyPatch(nameof(Gun.OnFire)), HarmonyPrefix]
public static bool OnFirePatch(Gun __instance)
{
//if (CallPatchedMethods.allowPatchedMethodCall) return true; // this patch should always be called
if (CallPatchedMethods.allowPatchedMethodCall) return true; // this patch should always be called
MelonLoader.MelonLogger.Msg("Gun.OnFire: " + __instance.name);
if (!BoneSync.lobby.IsConnected()) return true;
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
if (syncable == null) return true;
if (!syncable.Registered) return true;
return syncable.isOwner; // only allow owner to fire
if (syncable.isOwner)
{
MelonLogger.Msg("Gun.OnFire: " + __instance.name + " is owner");
GunSyncInfo gunSyncInfo = new GunSyncInfo()
{
cartridgeState = __instance.cartridgeState,
hammerState = __instance.hammerState,
syncId = syncable.GetSyncId(),
messageType = GunSyncMessageType.Fire,
bulletObject = __instance.chamberedCartridge
};
GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo);
gunSyncMessage.Broadcast();
MelonLogger.Msg("Gun.OnFire: " + __instance.name + " sent message");
}
return true;
}
}

View File

@@ -177,6 +177,8 @@ namespace BoneSync.Sync.Components
return "";
}
public void FindAndUpdateComponents()
{
ObjectSyncCache.RemoveSyncable(this);
@@ -189,8 +191,14 @@ namespace BoneSync.Sync.Components
objectDestructable = GetComponent<ObjectDestructable>();
gun = GetComponent<Gun>();
magazine = GetComponent<Magazine>();
plugs = GetComponentsInChildren<AlignPlug>();
sockets = GetComponentsInChildren<Socket>();
if (sockets.Length == 0)
{
plugs = GetComponentsInChildren<AlignPlug>();
} else {
plugs = new AlignPlug[0]; // don't use plugs if sockets are present
}
spawnFragment = GetComponent<SpawnFragment>();
UpdateTransformList();

BIN
BoneSync/playerrep.eres Normal file

Binary file not shown.