private OTAPI.HookResult SendNetDataHandler( Terraria.Net.NetManager manager, Terraria.Net.Sockets.ISocket socket, ref Terraria.Net.NetPacket packet) { Debug.Assert(socket != null); Debug.Assert(packet.Buffer.Data != null); Debug.Assert(packet.Writer.BaseStream.Position >= 5); // Since we don't have an index, scan through the clients to find the player index. // // TODO: optimize this using a hash map, if needed var playerIndex = -1; for (var i = 0; i < Terraria.Netplay.MaxConnections; ++i) { if (Terraria.Netplay.Clients[i].Socket == socket) { playerIndex = i; break; } } Debug.Assert(playerIndex >= 0 && playerIndex < Count); var span = packet.Buffer.Data.AsSpan(2..((int)packet.Writer.BaseStream.Position)); var moduleId = Unsafe.ReadUnaligned <ushort>(ref span.At(1)); // The `SendBytes` event is only triggered for module packets. var handler = _onSendModuleHandlers[moduleId] ?? OnSendPacket <ModulePacket <UnknownModule> >; handler(playerIndex, span); return(OTAPI.HookResult.Cancel); }
public override void Run() { Terraria.Net.NetPacket packet = default; var vanilla = this.SourceDefinition.Type("Terraria.Net.NetManager").Method("SendData"); var callback = this.Method(() => OTAPI.Callbacks.Terraria.NetManager.SendData(