This commit is contained in:
mischa 2023-07-27 12:32:19 +08:00
parent 7b2427ce76
commit a91f3a88c3
2 changed files with 5 additions and 4 deletions

View File

@ -280,9 +280,8 @@ public static T[] ReadArray<T>(this NetworkReader reader)
{
int length = reader.ReadInt();
// we write -1 for null
if (length < 0)
return null;
// 'null' is encoded as '-1'
if (length < 0) return null;
// todo throw an exception for other negative values (we never write them, likely to be attacker)

View File

@ -258,7 +258,7 @@ public static void WriteNetworkBehaviour(this NetworkWriter writer, NetworkBehav
writer.WriteUInt(0);
return;
}
// users might try to use unspawned / prefab NetworkBehaviours in
// rpcs/cmds/syncvars/messages. they would be null on the other
// end, and it might not be obvious why. let's make it obvious.
@ -352,11 +352,13 @@ public static void WriteHashSet<T>(this NetworkWriter writer, HashSet<T> hashSet
public static void WriteArray<T>(this NetworkWriter writer, T[] array)
{
// 'null' is encoded as '-1'
if (array is null)
{
writer.WriteInt(-1);
return;
}
writer.WriteInt(array.Length);
for (int i = 0; i < array.Length; i++)
writer.Write(array[i]);