Hello.
I need some help with converting this code to VB.
int GamePacketDecode(unsigned char *indata, unsigned int insize,
unsigned char *outdata, unsigned int outmax,
unsigned int *outsize)
{
unsigned int a, b, c, d;
unsigned int maxcnt, index, cnt;
unsigned char *outptr, *inptr;
int size;
b = 0;
size = insize;
inptr = indata;
maxcnt = outmax;
outptr = outdata;
cnt = 0x20;
while (1) {
if (cnt >= 0x8) {
while (size > 0 && cnt >= 8) {
cnt -= 0x8;
size--;
a = *inptr++ << cnt;
b |= a;
};
}
index = CharIndex[b >> 0x18];
a = CharTable[index];
d = (b >> (0x18 - a)) & BitMasks[a];
c = CharTable[index + 2*d + 2];
cnt += c;
if (cnt > 0x20) {
*outsize = outmax - maxcnt;
return 1;
}
if (maxcnt-- == 0)
return 0;
a = CharTable[index + 2*d + 1];
*outptr++ = (unsigned char)a;
b <<= (c & 0xFF);
}
assert(0);
return 0;
}
So far I have converted everything but these 2 lines
a = *inptr++ << cnt;
*outptr++ = (unsigned char)a;
I took a guess, but no luck..heres my code
Dim lInptr As Long
lInptr = Len(Inptr)
lInptr = lInptr + 1
A = LeftShift(lInptr, CNT)
and..
Outptr = A
Any help would be greatly appreciated.
p.s: for those who don't know..this code decompress a d2gs packet into data.
It was found here: http://forum.valhallalegends.com/phpbbs/index.php?topic=585.0
MyndFyre explained alot of that here (http://forum.valhallalegends.com/phpbbs/index.php?topic=11497.0)
I persionaly wouldnt bother porting the tables to VB6, as its fairly slow.
a = *inptr++ << cnt;
Dim tmp_inptr As Integer
tmp_inptr= inptr + 1
a = LeftShift(tmp_inptr, cnt)
*outptr++ = (unsigned char)a;
Dim tmp_outptr As String
tmp_outptr = outptr + 1
tmp_outptr = a ' Convert a to a string (character) (Havn't used VB in a while, I forgot how to do that