From 6b6c0ad1cfcf904b953035fd9c54f51151373ece Mon Sep 17 00:00:00 2001 From: IRacle Date: Sun, 11 Aug 2024 14:15:05 +0300 Subject: [PATCH] new better `SendFakeSyncVar` method --- .../Exiled.API/Extensions/MirrorExtensions.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/EXILED/Exiled.API/Extensions/MirrorExtensions.cs b/EXILED/Exiled.API/Extensions/MirrorExtensions.cs index e85b54ed6..b2eea4eb9 100644 --- a/EXILED/Exiled.API/Extensions/MirrorExtensions.cs +++ b/EXILED/Exiled.API/Extensions/MirrorExtensions.cs @@ -363,6 +363,7 @@ public static void MessageTranslated(this Player player, string words, string tr /// 's type. /// Property name starting with Network. /// Value of send to target. + [Obsolete("Use overload with type-template instead.")] public static void SendFakeSyncVar(this Player target, NetworkIdentity behaviorOwner, Type targetType, string propertyName, object value) { if (!target.IsConnected) @@ -386,6 +387,38 @@ void CustomSyncVarGenerator(NetworkWriter targetWriter) } } + /// + /// Send fake values to client's . + /// + /// Target SyncVar property type. + /// Target to send. + /// of object that owns . + /// 's type. + /// Property name starting with Network. + /// Value of send to target. + public static void SendFakeSyncVar(this Player target, NetworkIdentity behaviorOwner, Type targetType, string propertyName, T value) + { + if (!target.IsConnected) + return; + + NetworkWriterPooled writer = NetworkWriterPool.Get(); + NetworkWriterPooled writer2 = NetworkWriterPool.Get(); + MakeCustomSyncWriter(behaviorOwner, targetType, null, CustomSyncVarGenerator, writer, writer2); + target.Connection.Send(new EntityStateMessage + { + netId = behaviorOwner.netId, + payload = writer.ToArraySegment(), + }); + + NetworkWriterPool.Return(writer); + NetworkWriterPool.Return(writer2); + void CustomSyncVarGenerator(NetworkWriter targetWriter) + { + targetWriter.WriteULong(SyncVarDirtyBits[$"{targetType.Name}.{propertyName}"]); + WriterExtensions[typeof(T)]?.Invoke(null, new object[2] { targetWriter, value }); + } + } + /// /// Force resync to client's . ///