packet encoding
hi!
i know its not the right forum (?) ... but since the people here have the most knowledege in that area i hope someone here can answer my (more general and not related to runuo) question. i always wanted to write a uo emulator myself up to the point where i can connect, walk and talk. then i can sleep well with having in mind the rest is "just" a "i could do it but i am too lazy because its a shitload of work" thing...
i am now at the point where i can connect, walk and talk so everything is fine ... the only problem is the one piece of code that is not my work because it is not obvious, the packet encoding. i took some open source emulators and wrote their packet encoders together but something is not working right and i have to hardcode some packets (just sending the sniffed packets from a normal shard). for example in the walking sequence whenever it is "compressed" to 2 bytes instead of 3 the encoded outgoing packet is just wrong ...
my packet encoding routine looks like that
[code:1]
int encode_packet(unsigned char *in_packet, unsigned char *out_packet, int length)
{
int actByte = 0;
int bitByte = 0;
int nrBits;
int value;
int pos;
while (length--)
{
pos = (int) *in_packet;
nrBits = (int) encode_table[pos][0];
value = (int) encode_table[pos][1];
*in_packet++;
while (nrBits--)
{
out_packet[actByte] = (out_packet[actByte] << 1) | (unsigned char) ((value >> nrBits) & '\x01');
bitByte = (bitByte + 1) & '\x07';
if (bitByte == 0) actByte++;
}
}
nrBits = encode_table[256][0];
value = encode_table[256][1];
while (nrBits--)
{
out_packet[actByte] = (out_packet[actByte] << 1) | (unsigned char) ((value >> nrBits) & '\x01');
bitByte = (bitByte + 1) & '\x07';
if (bitByte == 0) actByte++;
}
if (bitByte != 0)
{
while (bitByte < 8)
{
out_packet[actByte] <<= 1;
bitByte++;
}
actByte++;
}
return actByte;
}
[/code:1]
with encode_table beeing the usual encoding table which i tripple checked if it is right...
am i doing something wrong? thanks a lot in advance if you can help me, i know some of you people out there do this for breakfast
cal
hi!
i know its not the right forum (?) ... but since the people here have the most knowledege in that area i hope someone here can answer my (more general and not related to runuo) question. i always wanted to write a uo emulator myself up to the point where i can connect, walk and talk. then i can sleep well with having in mind the rest is "just" a "i could do it but i am too lazy because its a shitload of work" thing...
i am now at the point where i can connect, walk and talk so everything is fine ... the only problem is the one piece of code that is not my work because it is not obvious, the packet encoding. i took some open source emulators and wrote their packet encoders together but something is not working right and i have to hardcode some packets (just sending the sniffed packets from a normal shard). for example in the walking sequence whenever it is "compressed" to 2 bytes instead of 3 the encoded outgoing packet is just wrong ...
my packet encoding routine looks like that
[code:1]
int encode_packet(unsigned char *in_packet, unsigned char *out_packet, int length)
{
int actByte = 0;
int bitByte = 0;
int nrBits;
int value;
int pos;
while (length--)
{
pos = (int) *in_packet;
nrBits = (int) encode_table[pos][0];
value = (int) encode_table[pos][1];
*in_packet++;
while (nrBits--)
{
out_packet[actByte] = (out_packet[actByte] << 1) | (unsigned char) ((value >> nrBits) & '\x01');
bitByte = (bitByte + 1) & '\x07';
if (bitByte == 0) actByte++;
}
}
nrBits = encode_table[256][0];
value = encode_table[256][1];
while (nrBits--)
{
out_packet[actByte] = (out_packet[actByte] << 1) | (unsigned char) ((value >> nrBits) & '\x01');
bitByte = (bitByte + 1) & '\x07';
if (bitByte == 0) actByte++;
}
if (bitByte != 0)
{
while (bitByte < 8)
{
out_packet[actByte] <<= 1;
bitByte++;
}
actByte++;
}
return actByte;
}
[/code:1]
with encode_table beeing the usual encoding table which i tripple checked if it is right...
am i doing something wrong? thanks a lot in advance if you can help me, i know some of you people out there do this for breakfast
cal