TSAPI icon indicating copy to clipboard operation
TSAPI copied to clipboard

GetDataEventArgs Length is greater by one than it should be.

Open AnzhelikaO opened this issue 5 years ago • 3 comments

Console.WriteLine((PacketTypes.PlayerSpawn, args.Length, 10)); writes (PlayerSpawn, 11, 10) where 10 is the actual packet size (https://tshock.readme.io/docs/multiplayer-packet-structure#spawn-player-12). Same for other packets.

AnzhelikaO avatar Jul 14 '20 13:07 AnzhelikaO

GetDataEventArgs includes the packet ID in the length.

kevzhao2 avatar Jul 14 '20 19:07 kevzhao2

But why? args.Index is the start of the packet data, not packet type byte. I think it's logical that args.Msg.readBuffer.Skip(args.Index).Take(args.Length) returns packet data. But instead it's packet data plus next packet's length and we have to take args.Length - 1 for some reason.

AnzhelikaO avatar Jul 15 '20 08:07 AnzhelikaO

Also if i need to seek data at the end of the packet i instinctively use args.Msg.readBuffer[args.Index + args.Length - 1], which will return incorrect byte.

AnzhelikaO avatar Jul 15 '20 08:07 AnzhelikaO