diff --git a/LethalNetworkAPI/LethalNetworkAPI.csproj b/LethalNetworkAPI/LethalNetworkAPI.csproj
index 0fcc27b..43ffac1 100644
--- a/LethalNetworkAPI/LethalNetworkAPI.csproj
+++ b/LethalNetworkAPI/LethalNetworkAPI.csproj
@@ -23,15 +23,17 @@
LGPL-3.0-or-later
-
-
-
-
+
true
embedded
+ $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./
+
+
+
+
diff --git a/LethalNetworkAPI/Serializable/LethalNetworkSerializer.cs b/LethalNetworkAPI/Serializable/LethalNetworkSerializer.cs
index 3f9df34..ff7af2b 100644
--- a/LethalNetworkAPI/Serializable/LethalNetworkSerializer.cs
+++ b/LethalNetworkAPI/Serializable/LethalNetworkSerializer.cs
@@ -10,32 +10,19 @@ internal static class LethalNetworkSerializer
internal static byte[] Serialize(T value)
{
#if NETSTANDARD2_1
- return value switch
- {
- GameObject gameObject => SerializationUtility.SerializeValue((NetworkObjectReference)gameObject, DataFormat.Binary),
- NetworkObject networkObject => SerializationUtility.SerializeValue((NetworkObjectReference)networkObject, DataFormat.Binary),
- NetworkBehaviour gameObject => SerializationUtility.SerializeValue((NetworkBehaviourReference)gameObject, DataFormat.Binary),
- _ => SerializationUtility.SerializeValue(value, DataFormat.Binary)
- };
+ return SerializationUtility.SerializeValue(value, DataFormat.Binary);
#else
- return [];
+ return [];
#endif
}
internal static T Deserialize(byte[] data)
{
#if NETSTANDARD2_1
- T type = default!;
- return type switch
- {
- GameObject => (T)(object)(GameObject)SerializationUtility.DeserializeValue(data, DataFormat.Binary),
- NetworkObject => (T)(object)(NetworkObject)SerializationUtility.DeserializeValue(data, DataFormat.Binary),
- NetworkBehaviour => (T)(object)(NetworkBehaviour)SerializationUtility.DeserializeValue(data, DataFormat.Binary),
- _ => SerializationUtility.DeserializeValue(data, DataFormat.Binary)
- };
+ return SerializationUtility.DeserializeValue(data, DataFormat.Binary);
#else
T test = default!;
- return test;
+ return test;
#endif
}
}
\ No newline at end of file
diff --git a/LethalNetworkAPI/Serializable/NetworkBehaviourFormatter.cs b/LethalNetworkAPI/Serializable/NetworkBehaviourFormatter.cs
new file mode 100644
index 0000000..1e41c9c
--- /dev/null
+++ b/LethalNetworkAPI/Serializable/NetworkBehaviourFormatter.cs
@@ -0,0 +1,29 @@
+using LethalNetworkAPI.Serializable;
+
+#if NETSTANDARD2_1
+using OdinSerializer;
+
+[assembly: RegisterFormatter(typeof(NetworkBehaviourFormatter))]
+
+namespace LethalNetworkAPI.Serializable;
+
+
+///
+/// Custom formatter for the type.
+///
+public class NetworkBehaviourFormatter : MinimalBaseFormatter
+{
+ private static readonly Serializer NetworkBehaviourReferenceSerializer = Serializer.Get();
+
+ protected override void Read(ref NetworkBehaviour value, IDataReader reader)
+ {
+ value = NetworkBehaviourReferenceSerializer.ReadValue(reader);
+ }
+
+ protected override void Write(ref NetworkBehaviour value, IDataWriter writer)
+ {
+ NetworkBehaviourReferenceSerializer.WriteValue(value, writer);
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/LethalNetworkAPI/Serializable/NetworkObjectFormatter.cs b/LethalNetworkAPI/Serializable/NetworkObjectFormatter.cs
new file mode 100644
index 0000000..cb68f26
--- /dev/null
+++ b/LethalNetworkAPI/Serializable/NetworkObjectFormatter.cs
@@ -0,0 +1,47 @@
+using LethalNetworkAPI.Serializable;
+
+#if NETSTANDARD2_1
+using OdinSerializer;
+
+[assembly: RegisterFormatter(typeof(NetworkObjectFormatter))]
+[assembly: RegisterFormatter(typeof(GameObjectFormatter))]
+
+namespace LethalNetworkAPI.Serializable;
+
+///
+/// Custom formatter for the type.
+///
+public class NetworkObjectFormatter : MinimalBaseFormatter
+{
+ private static readonly Serializer NetworkObjectReferenceSerializer = Serializer.Get();
+
+ protected override void Read(ref NetworkObject value, IDataReader reader)
+ {
+ value = NetworkObjectReferenceSerializer.ReadValue(reader);
+ }
+
+ protected override void Write(ref NetworkObject value, IDataWriter writer)
+ {
+ NetworkObjectReferenceSerializer.WriteValue(value, writer);
+ }
+}
+
+///
+/// Custom formatter for the type.
+///
+public class GameObjectFormatter : MinimalBaseFormatter
+{
+ private static readonly Serializer NetworkObjectReferenceSerializer = Serializer.Get();
+
+ protected override void Read(ref GameObject value, IDataReader reader)
+ {
+ value = NetworkObjectReferenceSerializer.ReadValue(reader);
+ }
+
+ protected override void Write(ref GameObject value, IDataWriter writer)
+ {
+ NetworkObjectReferenceSerializer.WriteValue(value, writer);
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/LethalNetworkAPI/Variable/LethalNetworkVariable.cs b/LethalNetworkAPI/Variable/LethalNetworkVariable.cs
index 6d45ef1..03c5272 100644
--- a/LethalNetworkAPI/Variable/LethalNetworkVariable.cs
+++ b/LethalNetworkAPI/Variable/LethalNetworkVariable.cs
@@ -88,12 +88,11 @@ public TData Value
get => _value;
set
{
- if (!(
- _public ||
- (_ownerObject is null && NetworkManager.Singleton.IsServer) ||
- _ownerObject is null ||
- _ownerObject.OwnerClientId == NetworkManager.Singleton.LocalClientId
- )) return;
+ if (!(_public ||
+ NetworkManager.Singleton == null ||
+ _ownerObject is null && NetworkManager.Singleton.IsServer ||
+ _ownerObject is not null && _ownerObject.OwnerClientId == NetworkManager.Singleton.LocalClientId)
+ ) return;
if (value is null) return;