diff --git a/mROA/Implementation/Backend/JsonSerialisationModule.cs b/mROA/Implementation/Backend/JsonSerialisationModule.cs index 731b971..9779539 100644 --- a/mROA/Implementation/Backend/JsonSerialisationModule.cs +++ b/mROA/Implementation/Backend/JsonSerialisationModule.cs @@ -41,9 +41,7 @@ public class JsonSerialisationModule : ISerialisationModule public void PostResponse(NetworkMessage message, int clientId) { - var texted = JsonSerializer.Serialize(message); - var binary = Encoding.UTF8.GetBytes(texted); - _dataSource!.SendTo(clientId, binary); + _dataSource!.SendTo(clientId, JsonSerializer.SerializeToUtf8Bytes(message)); } public void Inject(T dependency) diff --git a/mROA/Implementation/TransmittedSharedObject.cs b/mROA/Implementation/TransmittedSharedObject.cs index 6b2228c..f64f79c 100644 --- a/mROA/Implementation/TransmittedSharedObject.cs +++ b/mROA/Implementation/TransmittedSharedObject.cs @@ -14,21 +14,33 @@ public class TransmittedSharedObject where T : notnull throw new NullReferenceException( "DefaultContextRepository was not defined"); + private int _contextId = -1; + // ReSharper disable once MemberCanBePrivate.Global - public int ContextId { get; init; } = -1; + public int ContextId + { + get => _contextId; + init + { + _contextId = value; + Value = GetDefaultContextRepository().GetObject(_contextId)!; + } + } [JsonIgnore] - public T? Value => GetDefaultContextRepository().GetObject(ContextId); + public T Value { get; private set; } public TransmittedSharedObject() { } + // ReSharper disable once UnusedMember.Global public TransmittedSharedObject(T value) { - ContextId = GetDefaultContextRepository().GetObjectIndex(value); + Value = value; + _contextId = GetDefaultContextRepository().GetObjectIndex(value); } - public static implicit operator T(TransmittedSharedObject value) => value.Value!; + public static implicit operator T(TransmittedSharedObject value) => value.Value; public static implicit operator TransmittedSharedObject(T value) => new() { ContextId = GetDefaultContextRepository().GetObjectIndex(value) };