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_api.dll" />
<EmbeddedResource Include="steam_api64.dll" /> <EmbeddedResource Include="steam_api64.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="playerrep.eres" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>xcopy /Y "$(TargetPath)" "A:\SteamLibrary\steamapps\common\BONEWORKS\BONEWORKS\Mods\" <PostBuildEvent>xcopy /Y "$(TargetPath)" "A:\SteamLibrary\steamapps\common\BONEWORKS\BONEWORKS\Mods\"

View File

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

View File

@@ -19,16 +19,23 @@ namespace BoneSync.Patching
[HarmonyPatch(nameof(Gun.Fire)), HarmonyPrefix] [HarmonyPatch(nameof(Gun.Fire)), HarmonyPrefix]
public static bool FirePatch(Gun __instance) public static bool FirePatch(Gun __instance)
{ {
if (CallPatchedMethods.allowPatchedMethodCall) return true; return true;
MelonLoader.MelonLogger.Msg("Gun fired: " + __instance.name); }
[HarmonyPatch(nameof(Gun.OnFire)), HarmonyPrefix]
public static bool OnFirePatch(Gun __instance)
{
if (CallPatchedMethods.allowPatchedMethodCall) return true; // this patch should always be called
MelonLoader.MelonLogger.Msg("Gun.OnFire: " + __instance.name);
if (!BoneSync.lobby.IsConnected()) return true; if (!BoneSync.lobby.IsConnected()) return true;
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); MelonLogger.Msg("Gun.OnFire: " + __instance.name + " is owner");
GunSyncInfo gunSyncInfo = new GunSyncInfo() GunSyncInfo gunSyncInfo = new GunSyncInfo()
{ {
cartridgeState = __instance.cartridgeState, cartridgeState = __instance.cartridgeState,
@@ -40,23 +47,10 @@ namespace BoneSync.Patching
GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo); GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo);
gunSyncMessage.Broadcast(); gunSyncMessage.Broadcast();
MelonLogger.Msg("Gun.OnFire: " + __instance.name + " sent message");
}
return true; return true;
} }
[HarmonyPatch(nameof(Gun.OnFire)), HarmonyPrefix]
public static bool OnFirePatch(Gun __instance)
{
//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
}
} }
} }

View File

@@ -177,6 +177,8 @@ namespace BoneSync.Sync.Components
return ""; return "";
} }
public void FindAndUpdateComponents() public void FindAndUpdateComponents()
{ {
ObjectSyncCache.RemoveSyncable(this); ObjectSyncCache.RemoveSyncable(this);
@@ -189,8 +191,14 @@ namespace BoneSync.Sync.Components
objectDestructable = GetComponent<ObjectDestructable>(); objectDestructable = GetComponent<ObjectDestructable>();
gun = GetComponent<Gun>(); gun = GetComponent<Gun>();
magazine = GetComponent<Magazine>(); magazine = GetComponent<Magazine>();
plugs = GetComponentsInChildren<AlignPlug>();
sockets = GetComponentsInChildren<Socket>(); 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>(); spawnFragment = GetComponent<SpawnFragment>();
UpdateTransformList(); UpdateTransformList();

BIN
BoneSync/playerrep.eres Normal file

Binary file not shown.