Exemple #1
0
 static HookResult OnSendBytes(
     ref int remoteClient,
     ref byte[] data,
     ref int offset,
     ref int size,
     ref Terraria.Net.Sockets.SocketSendCallback callback,
     ref object state
     )
 {
     if (_hookManager.InvokeNetSendBytes(Netplay.Clients[remoteClient], data, offset, size))
     {
         return(HookResult.Cancel);
     }
     return(HookResult.Continue);
 }
        private OTAPI.HookResult SendBytesHandler(
            ref int playerIndex, ref byte[] data, ref int offset, ref int size,
            ref Terraria.Net.Sockets.SocketSendCallback callback, ref object state)
        {
            Debug.Assert(playerIndex >= 0 && playerIndex < Count);
            Debug.Assert(data != null);
            Debug.Assert(offset >= 0 && offset + size <= data.Length);
            Debug.Assert(size >= 3);

            var span     = data.AsSpan((offset + 2)..(offset + size));
            var packetId = span.At(0);

#if DEBUG
            //_log.Debug($"TX {(PacketId)packetId}");
#endif

            // The `SendBytes` event is only triggered for non-module packets.
            var handler = _onSendPacketHandlers[packetId] ?? OnSendPacket <UnknownPacket>;
            handler(playerIndex, span);
            return(OTAPI.HookResult.Cancel);
        }