-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using Comfort.Common; | ||
using EFT.Interactive; | ||
using Fika.Core.Networking; | ||
using LiteNetLib; | ||
using UnityEngine; | ||
|
||
namespace Fika.Core.Coop.Components | ||
{ | ||
public class ItemPositionSyncer : MonoBehaviour | ||
{ | ||
private FikaServer server; | ||
private FikaClient client; | ||
private bool isServer; | ||
private ObservedLootItem lootItem; | ||
private GStruct128 data; | ||
|
||
private Rigidbody Rigidbody | ||
{ | ||
get | ||
{ | ||
return lootItem.RigidBody; | ||
} | ||
} | ||
|
||
public static void Create(GameObject gameObject, bool isServer, ObservedLootItem lootItem) | ||
{ | ||
ItemPositionSyncer posSync = gameObject.AddComponent<ItemPositionSyncer>(); | ||
posSync.isServer = isServer; | ||
if (isServer) | ||
{ | ||
posSync.server = Singleton<FikaServer>.Instance; | ||
} | ||
else | ||
{ | ||
posSync.client = Singleton<FikaClient>.Instance; | ||
} | ||
posSync.lootItem = lootItem; | ||
posSync.data = new() | ||
{ | ||
Id = lootItem.GetNetId() | ||
}; | ||
} | ||
|
||
public void Start() | ||
{ | ||
if (lootItem == null) | ||
{ | ||
FikaPlugin.Instance.FikaLogger.LogError("HostItemPositionSync::Start: LootItem was null!"); | ||
Destroy(this); | ||
} | ||
|
||
if (Rigidbody == null) | ||
{ | ||
FikaPlugin.Instance.FikaLogger.LogError("HostItemPositionSync::Start: Rigidbody was null!"); | ||
Destroy(this); | ||
} | ||
} | ||
|
||
public void FixedUpdate() | ||
{ | ||
if (Rigidbody == null) | ||
{ | ||
data.Position = lootItem.transform.position; | ||
data.Rotation = lootItem.transform.rotation; | ||
data.Velocity = Vector3.zero; | ||
data.AngularVelocity = Vector3.zero; | ||
data.Done = true; | ||
LootSyncPacket endPacket = new() | ||
{ | ||
Data = data | ||
}; | ||
if (isServer) | ||
{ | ||
server.SendDataToAll(ref endPacket, DeliveryMethod.ReliableOrdered); | ||
Destroy(this); | ||
return; | ||
} | ||
|
||
client.SendData(ref endPacket, DeliveryMethod.ReliableOrdered); | ||
Destroy(this); | ||
return; | ||
} | ||
|
||
data.Position = lootItem.transform.position; | ||
data.Rotation = lootItem.transform.rotation; | ||
data.Velocity = Rigidbody.velocity; | ||
data.AngularVelocity = Rigidbody.angularVelocity; | ||
LootSyncPacket packet = new() | ||
{ | ||
Data = data | ||
}; | ||
if (isServer) | ||
{ | ||
server.SendDataToAll(ref packet, DeliveryMethod.Unreliable); | ||
return; | ||
} | ||
|
||
client.SendData(ref packet, DeliveryMethod.Unreliable); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
Fika.Core/Coop/Patches/GameWorld/GameWorld_ThrowItem_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using EFT; | ||
using EFT.Interactive; | ||
using Fika.Core.Coop.Components; | ||
using Fika.Core.Coop.Utils; | ||
using HarmonyLib; | ||
using SPT.Reflection.Patching; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Fika.Core.Coop.Patches | ||
{ | ||
public class GameWorld_ThrowItem_Patch : ModulePatch | ||
{ | ||
protected override MethodBase GetTargetMethod() | ||
{ | ||
return typeof(GameWorld).GetMethods().First(x => x.Name == nameof(GameWorld.ThrowItem) && x.GetParameters().Length == 3); | ||
} | ||
|
||
[PatchPostfix] | ||
public static void Postfix(LootItem __result, IPlayer player) | ||
{ | ||
if (__result is ObservedLootItem observedLootItem) | ||
{ | ||
if (player.IsYourPlayer || player.IsAI) | ||
{ | ||
ItemPositionSyncer.Create(observedLootItem.gameObject, FikaBackendUtils.IsServer, observedLootItem); | ||
return; | ||
} | ||
|
||
Traverse.Create(observedLootItem).Field<bool>("bool_3").Value = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters