예제 #1
0
        public static bool ReceiveBytes(UnhollowerBaseLib.Il2CppStructArray <byte> bytes)
        {
            if (bytes.Length > JUNK_SIZE + sizeof(ushort))
            {
                for (int index = 0; index < JUNK_SIZE; index++)
                {
                    if (bytes[index] != 255)
                    {
                        return(false);
                    }
                }

                int    offset       = JUNK_SIZE;
                ushort replicatorID = Il2CppSystem.BitConverter.ToUInt16(bytes, offset);

                if (NET_Replicator.TryGetReplicator(replicatorID, out NET_Replicator replicator) && replicator.ShouldHandlePacket(bytes, ref offset))
                {
                    try
                    {
                        Log.Message("Received custom packet");
                        replicator.OnReceiveBytes(bytes, offset);
                    }
                    catch (Exception exception)
                    {
                        Debug.LogError("An exception occurred whilst handling a custom NET_Replicator: " + exception);
                    }
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
 public static bool AddReplicator(NET_Replicator replicator)
 {
     if (replicator != null && !replicators.ContainsKey(replicator.Key))
     {
         replicators.Add(replicator.Key, replicator);
         return(true);
     }
     return(false);
 }
예제 #3
0
        public static bool RemoveReplicator(NET_Replicator replicator)
        {
            if (replicator == null)
            {
                return(false);
            }

            return(replicators.Remove(replicator.Key));
        }
예제 #4
0
 public static bool TryGetReplicator(ushort key, out NET_Replicator replicator) => replicators.TryGetValue(key, out replicator);