-
Notifications
You must be signed in to change notification settings - Fork 55
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
5 changed files
with
155 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Comfort.Common; | ||
using EFT.Interactive; | ||
using Fika.Core.Networking; | ||
using Fika.Core.Networking.Packets; | ||
using HarmonyLib; | ||
using LiteNetLib; | ||
using System.Reflection; | ||
using UnityEngine; | ||
|
||
namespace Fika.Core.Coop.Components | ||
{ | ||
internal class CorpsePositionSyncer : MonoBehaviour | ||
{ | ||
private FieldInfo ragdollDoneField = AccessTools.Field(typeof(RagdollClass), "bool_2"); | ||
|
||
private FikaServer server; | ||
private Corpse corpse; | ||
private GStruct129 data; | ||
|
||
public static void Create(GameObject gameObject, Corpse corpse) | ||
{ | ||
CorpsePositionSyncer corpsePositionSyncer = gameObject.AddComponent<CorpsePositionSyncer>(); | ||
corpsePositionSyncer.corpse = corpse; | ||
corpsePositionSyncer.server = Singleton<FikaServer>.Instance; | ||
corpsePositionSyncer.data = new() | ||
{ | ||
Id = corpse.GetNetId() | ||
}; | ||
} | ||
|
||
public void Start() | ||
{ | ||
if (corpse == null) | ||
{ | ||
FikaPlugin.Instance.FikaLogger.LogError("CorpsePositionSyncer::Start: Corpse was null!"); | ||
Destroy(this); | ||
} | ||
|
||
if (!corpse.HasRagdoll) | ||
{ | ||
FikaPlugin.Instance.FikaLogger.LogError("CorpsePositionSyncer::Start: Ragdoll was null!"); | ||
Destroy(this); | ||
} | ||
} | ||
|
||
public void FixedUpdate() | ||
{ | ||
if ((bool)ragdollDoneField.GetValue(corpse.Ragdoll)) | ||
{ | ||
data.Position = corpse.TrackableTransform.position; | ||
data.TransformSyncs = corpse.TransformSyncs; | ||
data.Done = true; | ||
CorpsePositionPacket endPacket = new() | ||
{ | ||
Data = data | ||
}; | ||
server.SendDataToAll(ref endPacket, DeliveryMethod.ReliableOrdered); | ||
Destroy(this); | ||
return; | ||
} | ||
|
||
data.Position = corpse.TrackableTransform.position; | ||
CorpsePositionPacket packet = new() | ||
{ | ||
Data = data | ||
}; | ||
|
||
server.SendDataToAll(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 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
49 changes: 49 additions & 0 deletions
49
Fika.Core/Networking/Packets/GameWorld/CorpsePositionPacket.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,49 @@ | ||
using LiteNetLib.Utils; | ||
|
||
namespace Fika.Core.Networking | ||
{ | ||
public struct CorpsePositionPacket : INetSerializable | ||
{ | ||
public GStruct129 Data; | ||
|
||
public void Deserialize(NetDataReader reader) | ||
{ | ||
Data = new() | ||
{ | ||
Id = reader.GetInt(), | ||
Position = reader.GetVector3(), | ||
Done = reader.GetBool() | ||
}; | ||
|
||
if (Data.Done) | ||
{ | ||
Data.TransformSyncs = new GStruct107[12]; | ||
for (int i = 0; i < 12; i++) | ||
{ | ||
Data.TransformSyncs[i] = new() | ||
{ | ||
Position = reader.GetVector3(), | ||
Rotation = reader.GetQuaternion() | ||
}; | ||
} | ||
} | ||
} | ||
|
||
public void Serialize(NetDataWriter writer) | ||
{ | ||
writer.Put(Data.Id); | ||
writer.Put(Data.Position); | ||
writer.Put(Data.Done); | ||
|
||
if (Data.Done && Data.TransformSyncs != null) | ||
{ | ||
GStruct107[] transforms = Data.TransformSyncs; | ||
for (int i = 0; i < 12; i++) | ||
{ | ||
writer.Put(transforms[i].Position); | ||
writer.Put(transforms[i].Rotation); | ||
} | ||
} | ||
} | ||
} | ||
} |