Pryaxis / TSAPI

🛠🌳 The TShock Scaffold API enables developers to build plugins that hook directly into the Terraria game engine.
http://tshock.co/
GNU General Public License v3.0
109 stars 66 forks source link

GetDataEventArgs Length is greater by one than it should be. #181

Open AnzhelikaO opened 4 years ago

AnzhelikaO commented 4 years ago

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.

kevzhao2 commented 4 years ago

GetDataEventArgs includes the packet ID in the length.

AnzhelikaO commented 4 years ago

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 commented 4 years ago

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.