I don't think there is any proper way of knowing how many SubTypes some of the packets have, unless ofcourse you get hands on original CO source, you just come across them while logging packets from wherever you log your packets from. :P
Packets and how they are made....uhm; It's hard to explain.
The bytes from 0..1 (First two of the byte[] Array, (in C#)) are the size of Packet
1..2 are the Packet Type; Like for example the character spawn packet 0x3F6
Those first 4 bytes are always at same place; But the rest of them don't follow any pattern (Unless they're same PType of course)
Lets take the AuthResponse packet for example (Smallest packet perhaps? xD)
20 00 F1 04 XX XX XX XX YY YY YY YY II II II II II II II II II II II II II II II II PP PP RR RR
XX = KeyTwo
YY = KeyOne
II = IP
PP = GamePort
RR = Reserved
Excuse me for that gay format, but those values change in the packet, they're not preset :D
0..1 : Size
2..3 : Type (0x41F in this case)
4..7 : KeyTwo
8..11 : KeyOne
12..27 : The GameIP (Not always this long, reserved for xxx.xxx.xxx.xxx ip's)
28..29 : GamePort
30..31 : Nothing; It's just 00 00
Now! Let's make that to a something we can send!
Code:
// This style is mostly used in COEmu based things, unless using streams
public static byte[] AuthResponse(string IP, uint KeyOne, uint KeyTwo, ushort GamePort)
{
byte[] Packet = new byte[0x20]; // 0x20 in hex, 32 in dec
Packet[0] = (byte)(Packet.Length & 0xFF);
Packet[1] = (byte)((Packet.Length >> 8) & 0xFF);
Packet[2] = (byte)(0x41F & 0xFF);
Packet[3] = (byte)((0x41F >> 8) & 0xFF);
Packet[4] = (byte)(KeyTwo & 0xFF);
Packet[5] = (byte)((KeyTwo >> 8) & 0xFF);
Packet[6] = (byte)((KeyTwo >> 16) & 0xFF);
Packet[7] = (byte)((KeyTwo >> 24) & 0xFF);
Packet[8] = (byte)(KeyOne & 0xFF);
Packet[9] = (byte)((KeyOne >> 8) & 0xFF);
Packet[10] = (byte)((KeyOne >> 16) & 0xFF);
Packet[11] = (byte)((KeyOne >> 24) & 0xFF);
for(byte i = 0; i < IP.Length; i++)
Packet[12 + i] = (byte)IP[i];
Packet[28] = (byte)(GamePort & 0xFF);
Packet[29] = (byte)((GamePort >> 8) & 0xFF);
// 30..31 Don't have to be declared since they're alwayss 00
return Packet;
}
P.S If you copy this; It won't probably work for your server version;
P.P.S There might be _some_ errors, wrote it here; Didn't have compiler open :D