Mag and gun sync fixes
This commit is contained in:
@@ -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\"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,23 @@ 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);
|
||||
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;
|
||||
if (!syncable.isOwner) return false; // only allow owner to fire
|
||||
|
||||
MelonLogger.Msg("Sending gun fire message: " + __instance.name);
|
||||
if (syncable.isOwner)
|
||||
{
|
||||
MelonLogger.Msg("Gun.OnFire: " + __instance.name + " is owner");
|
||||
GunSyncInfo gunSyncInfo = new GunSyncInfo()
|
||||
{
|
||||
cartridgeState = __instance.cartridgeState,
|
||||
@@ -40,22 +47,9 @@ namespace BoneSync.Patching
|
||||
|
||||
GunSyncMessage gunSyncMessage = new GunSyncMessage(gunSyncInfo);
|
||||
gunSyncMessage.Broadcast();
|
||||
|
||||
return true;
|
||||
MelonLogger.Msg("Gun.OnFire: " + __instance.name + " sent message");
|
||||
}
|
||||
|
||||
|
||||
[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
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
BIN
BoneSync/playerrep.eres
Normal file
Binary file not shown.
Reference in New Issue
Block a user