Valhalla Legends Forums Archive | Java Programming | At my wit's end...(Decompression function)

AuthorMessageTime
xsemaphorex
I made just about every attempt I could possibly make at porting Brand.X's decompression algorithm to java. I <i>used</i> to think I had some intelligence but I need another set of eyes to help me see what I am not seeing. Here's the algorithm in C:

//----------------------------------------------------------------------
// Packet Decompression Tables
//----------------------------------------------------------------------

unsigned int CharIndex[] = {
0x0247, 0x0236, 0x0225, 0x0214, 0x0203, 0x01F2, 0x01E1, 0x01D0,
0x01BF, 0x01AE, 0x019D, 0x018C, 0x017B, 0x016A, 0x0161, 0x0158,
0x014F, 0x0146, 0x013D, 0x0134, 0x012B, 0x0122, 0x0119, 0x0110,
0x0107, 0x00FE, 0x00F5, 0x00EC, 0x00E3, 0x00DA, 0x00D1, 0x00C8,
0x00BF, 0x00B6, 0x00AD, 0x00A8, 0x00A3, 0x009E, 0x0099, 0x0094,
0x008F, 0x008A, 0x0085, 0x0080, 0x007B, 0x0076, 0x0071, 0x006C,
0x0069, 0x0066, 0x0063, 0x0060, 0x005D, 0x005A, 0x0057, 0x0054,
0x0051, 0x004E, 0x004B, 0x0048, 0x0045, 0x0042, 0x003F, 0x003F,
0x003C, 0x003C, 0x0039, 0x0039, 0x0036, 0x0036, 0x0033, 0x0033,
0x0030, 0x0030, 0x002D, 0x002D, 0x002A, 0x002A, 0x0027, 0x0027,
0x0024, 0x0024, 0x0021, 0x0021, 0x001E, 0x001E, 0x001B, 0x001B,
0x0018, 0x0018, 0x0015, 0x0015, 0x0012, 0x0012, 0x0012, 0x0012,
0x000F, 0x000F, 0x000F, 0x000F, 0x000C, 0x000C, 0x000C, 0x000C,
0x0009, 0x0009, 0x0009, 0x0009, 0x0006, 0x0006, 0x0006, 0x0006,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};


unsigned char CharTable[] = {
0x00,0x00,0x01,0x00,0x01,0x04,0x00,0xFF,0x06,0x00,0x14,0x06,
0x00,0x13,0x06,0x00,0x05,0x06,0x00,0x02,0x06,0x00,0x80,0x07,
0x00,0x6D,0x07,0x00,0x69,0x07,0x00,0x68,0x07,0x00,0x67,0x07,
0x00,0x1E,0x07,0x00,0x15,0x07,0x00,0x12,0x07,0x00,0x0D,0x07,
0x00,0x0A,0x07,0x00,0x08,0x07,0x00,0x07,0x07,0x00,0x06,0x07,
0x00,0x04,0x07,0x00,0x03,0x07,0x00,0x6C,0x08,0x00,0x51,0x08,
0x00,0x20,0x08,0x00,0x1F,0x08,0x00,0x1D,0x08,0x00,0x18,0x08,
0x00,0x17,0x08,0x00,0x16,0x08,0x00,0x11,0x08,0x00,0x10,0x08,
0x00,0x0F,0x08,0x00,0x0C,0x08,0x00,0x0B,0x08,0x00,0x09,0x08,
0x01,0x96,0x09,0x97,0x09,0x01,0x90,0x09,0x95,0x09,0x01,0x64,
0x09,0x6B,0x09,0x01,0x62,0x09,0x63,0x09,0x01,0x56,0x09,0x58,
0x09,0x01,0x52,0x09,0x55,0x09,0x01,0x4D,0x09,0x50,0x09,0x01,
0x45,0x09,0x4C,0x09,0x01,0x40,0x09,0x43,0x09,0x01,0x31,0x09,
0x3B,0x09,0x01,0x28,0x09,0x30,0x09,0x01,0x1A,0x09,0x25,0x09,
0x01,0x0E,0x09,0x19,0x09,0x02,0xE2,0x0A,0xE8,0x0A,0xF0,0x0A,
0xF8,0x0A,0x02,0xC0,0x0A,0xC2,0x0A,0xCE,0x0A,0xE0,0x0A,0x02,
0xA0,0x0A,0xA2,0x0A,0xB0,0x0A,0xB8,0x0A,0x02,0x8A,0x0A,0x8F,
0x0A,0x93,0x0A,0x98,0x0A,0x02,0x81,0x0A,0x82,0x0A,0x83,0x0A,
0x89,0x0A,0x02,0x7C,0x0A,0x7D,0x0A,0x7E,0x0A,0x7F,0x0A,0x02,
0x77,0x0A,0x78,0x0A,0x79,0x0A,0x7A,0x0A,0x02,0x73,0x0A,0x74,
0x0A,0x75,0x0A,0x76,0x0A,0x02,0x6E,0x0A,0x6F,0x0A,0x70,0x0A,
0x72,0x0A,0x02,0x61,0x0A,0x65,0x0A,0x66,0x0A,0x6A,0x0A,0x02,
0x5D,0x0A,0x5E,0x0A,0x5F,0x0A,0x60,0x0A,0x02,0x57,0x0A,0x59,
0x0A,0x5A,0x0A,0x5B,0x0A,0x02,0x4A,0x0A,0x4B,0x0A,0x4E,0x0A,
0x53,0x0A,0x02,0x46,0x0A,0x47,0x0A,0x48,0x0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0xB5,0x0B,0xB6,0x0B,0xB7,0x0B,0xB9,0x0B,0xBA,0x0B,0x03,
0xA9,0x0B,0xAA,0x0B,0xAB,0x0B,0xAC,0x0B,0xAD,0x0B,0xAE,0x0B,
0xAF,0x0B,0xB1,0x0B,0x03,0x9F,0x0B,0xA1,0x0B,0xA3,0x0B,0xA4,
0x0B,0xA5,0x0B,0xA6,0x0B,0xA7,0x0B,0xA8,0x0B,0x03,0x92,0x0B,
0x94,0x0B,0x99,0x0B,0x9A,0x0B,0x9B,0x0B,0x9C,0x0B,0x9D,0x0B,
0x9E,0x0B,0x03,0x86,0x0B,0x87,0x0B,0x88,0x0B,0x8B,0x0B,0x8C,
0x0B,0x8D,0x0B,0x8E,0x0B,0x91,0x0B,0x03,0x2F,0x0B,0x4F,0x0B,
0x54,0x0B,0x5C,0x0B,0x71,0x0B,0x7B,0x0B,0x84,0x0B,0x85,0x0B
};

unsigned int BitMasks[] = {
0x0000,0x0001,0x0003,0x0007,0x000F,0x001F,0x003F,0x007F,
0x00FF,0x01FF,0x03FF,0x07FF,0x0FFF,0x1FFF,0x3FFF,0x7FFF
};

//----------------------------------------------------------------------
// GamePacketDecode
// Decompress a d2gs packet into data.
// Note: packets come in clumps. A single compressed packet may have
// several game packets, and its up to you to figure it out.
//
// indata: [in] compressed packet (without size byte)
// insize: [in] length of indata
// outdata: [out] output buffer
// outmax: [in] size of output buffer
// outsize: [out] location to store size of decoded data
// returns: 1 on successf decode, 0 if not enough room
//----------------------------------------------------------------------

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;
}

And here is my source:

public class PacketHelper {
private static final int[] charIndex = new int[] {
0x0247, 0x0236, 0x0225, 0x0214, 0x0203, 0x01F2, 0x01E1, 0x01D0,
0x01BF, 0x01AE, 0x019D, 0x018C, 0x017B, 0x016A, 0x0161, 0x0158,
0x014F, 0x0146, 0x013D, 0x0134, 0x012B, 0x0122, 0x0119, 0x0110,
0x0107, 0x00FE, 0x00F5, 0x00EC, 0x00E3, 0x00DA, 0x00D1, 0x00C8,
0x00BF, 0x00B6, 0x00AD, 0x00A8, 0x00A3, 0x009E, 0x0099, 0x0094,
0x008F, 0x008A, 0x0085, 0x0080, 0x007B, 0x0076, 0x0071, 0x006C,
0x0069, 0x0066, 0x0063, 0x0060, 0x005D, 0x005A, 0x0057, 0x0054,
0x0051, 0x004E, 0x004B, 0x0048, 0x0045, 0x0042, 0x003F, 0x003F,
0x003C, 0x003C, 0x0039, 0x0039, 0x0036, 0x0036, 0x0033, 0x0033,
0x0030, 0x0030, 0x002D, 0x002D, 0x002A, 0x002A, 0x0027, 0x0027,
0x0024, 0x0024, 0x0021, 0x0021, 0x001E, 0x001E, 0x001B, 0x001B,
0x0018, 0x0018, 0x0015, 0x0015, 0x0012, 0x0012, 0x0012, 0x0012,
0x000F, 0x000F, 0x000F, 0x000F, 0x000C, 0x000C, 0x000C, 0x000C,
0x0009, 0x0009, 0x0009, 0x0009, 0x0006, 0x0006, 0x0006, 0x0006,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};

private static final char[] charTable = new char[] {
0x00,0x00,0x01,0x00,0x01,0x04,0x00,0xFF,0x06,0x00,0x14,0x06,
0x00,0x13,0x06,0x00,0x05,0x06,0x00,0x02,0x06,0x00,0x80,0x07,
0x00,0x6D,0x07,0x00,0x69,0x07,0x00,0x68,0x07,0x00,0x67,0x07,
0x00,0x1E,0x07,0x00,0x15,0x07,0x00,0x12,0x07,0x00,0x0D,0x07,
0x00,0x0A,0x07,0x00,0x08,0x07,0x00,0x07,0x07,0x00,0x06,0x07,
0x00,0x04,0x07,0x00,0x03,0x07,0x00,0x6C,0x08,0x00,0x51,0x08,
0x00,0x20,0x08,0x00,0x1F,0x08,0x00,0x1D,0x08,0x00,0x18,0x08,
0x00,0x17,0x08,0x00,0x16,0x08,0x00,0x11,0x08,0x00,0x10,0x08,
0x00,0x0F,0x08,0x00,0x0C,0x08,0x00,0x0B,0x08,0x00,0x09,0x08,
0x01,0x96,0x09,0x97,0x09,0x01,0x90,0x09,0x95,0x09,0x01,0x64,
0x09,0x6B,0x09,0x01,0x62,0x09,0x63,0x09,0x01,0x56,0x09,0x58,
0x09,0x01,0x52,0x09,0x55,0x09,0x01,0x4D,0x09,0x50,0x09,0x01,
0x45,0x09,0x4C,0x09,0x01,0x40,0x09,0x43,0x09,0x01,0x31,0x09,
0x3B,0x09,0x01,0x28,0x09,0x30,0x09,0x01,0x1A,0x09,0x25,0x09,
0x01,0x0E,0x09,0x19,0x09,0x02,0xE2,0x0A,0xE8,0x0A,0xF0,0x0A,
0xF8,0x0A,0x02,0xC0,0x0A,0xC2,0x0A,0xCE,0x0A,0xE0,0x0A,0x02,
0xA0,0x0A,0xA2,0x0A,0xB0,0x0A,0xB8,0x0A,0x02,0x8A,0x0A,0x8F,
0x0A,0x93,0x0A,0x98,0x0A,0x02,0x81,0x0A,0x82,0x0A,0x83,0x0A,
0x89,0x0A,0x02,0x7C,0x0A,0x7D,0x0A,0x7E,0x0A,0x7F,0x0A,0x02,
0x77,0x0A,0x78,0x0A,0x79,0x0A,0x7A,0x0A,0x02,0x73,0x0A,0x74,
0x0A,0x75,0x0A,0x76,0x0A,0x02,0x6E,0x0A,0x6F,0x0A,0x70,0x0A,
0x72,0x0A,0x02,0x61,0x0A,0x65,0x0A,0x66,0x0A,0x6A,0x0A,0x02,
0x5D,0x0A,0x5E,0x0A,0x5F,0x0A,0x60,0x0A,0x02,0x57,0x0A,0x59,
0x0A,0x5A,0x0A,0x5B,0x0A,0x02,0x4A,0x0A,0x4B,0x0A,0x4E,0x0A,
0x53,0x0A,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B2,0x0B,0xB3,0x0B,0xB4,
0x0B,0xB5,0x0B,0xB6,0x0B,0xB7,0x0B,0xB9,0x0B,0xBA,0x0B,0x03,
0xA9,0x0B,0xAA,0x0B,0xAB,0x0B,0xAC,0x0B,0xAD,0x0B,0xAE,0x0B,
0xAF,0x0B,0xB1,0x0B,0x03,0x9F,0x0B,0xA1,0x0B,0xA3,0x0B,0xA4,
0x0B,0xA5,0x0B,0xA6,0x0B,0xA7,0x0B,0xA8,0x0B,0x03,0x92,0x0B,
0x94,0x0B,0x99,0x0B,0x9A,0x0B,0x9B,0x0B,0x9C,0x0B,0x9D,0x0B,
0x9E,0x0B,0x03,0x86,0x0B,0x87,0x0B,0x88,0x0B,0x8B,0x0B,0x8C,
0x0B,0x8D,0x0B,0x8E,0x0B,0x91,0x0B,0x03,0x2F,0x0B,0x4F,0x0B,
0x54,0x0B,0x5C,0x0B,0x71,0x0B,0x7B,0x0B,0x84,0x0B,0x85,0x0B
};
private static final int[] bitMasks = {
0x0000,0x0001,0x0003,0x0007,0x000F,0x001F,0x003F,0x007F,
0x00FF,0x01FF,0x03FF,0x07FF,0x0FFF,0x1FFF,0x3FFF,0x7FFF
};

public static final int decode(char[] src, char[] dest) {
int a = 0, b = 0, c = 0, d = 0, max = 0, index = 0, oindex = 0, sindex = 0, cnt = 0, size = 0;
int maxcnt = 0;
size = src.length;
max = dest.length;
maxcnt = max;
cnt = 0x20;

try {
while(true) {
if (cnt >= 8) {
while (size > 0 && cnt >= 8) {
cnt -= 8;
size--;
System.out.println("src[" + sindex + "]=" + Integer.toHexString(src[sindex]));
System.out.println("src[" + sindex + "]=" + src[sindex]);
System.out.println("a=" + Integer.toHexString(a));
System.out.println("a=" + a);
System.out.println("b=" + Integer.toHexString(b));
System.out.println("b=" + b);
System.out.println("cnt=" + Integer.toHexString(cnt));
System.out.println("cnt=" + cnt);
a = (src[sindex++] << cnt);
System.out.println("a=" + Integer.toHexString(a));
System.out.println("a=" + a);
b |= a;
System.out.println("b=" + Integer.toHexString(b));
}
}

System.out.println("a=" + Integer.toHexString(a));
b = b >> 0x18;
b = b & 0xFFFF;
System.out.println("b=" + Integer.toHexString(b));
index = charIndex[b];
System.out.println("index=" + Integer.toHexString(index));
b = b >> ((0x18 - a) & 0xFFFFFFFF);
System.out.println("b=" + Integer.toHexString(b));
d = b & bitMasks[a & 0xF];
System.out.println("d=" + Integer.toHexString(d));
System.out.println("looking up charTable[" + d + "]");
c = charTable[index + 2*d + 2];
System.out.println("c=" + Integer.toHexString(c));

cnt += c;
System.out.println("cnt=" + Integer.toHexString(cnt));
if (cnt > 0x20) {
return max - maxcnt;
}

if(maxcnt-- == 0)
return 0;

index += (2 * d + 1);
System.out.println("index=" + Integer.toHexString(index));
a = charTable[index];
System.out.println("a=" + Integer.toHexString(a));
dest[oindex++] = (char)(a & 0xFF);
System.out.println("dest[" + (oindex - 1) + "]=" + Integer.toHexString(dest[oindex - 1]));
System.out.println();

b = b << (c & 0xFF);
}
} catch(Exception _e) {
_e.printStackTrace();
return 0;
}
}
public static void main(String[] d) {
char[] b = new char[] {
(char)0x0e,(char)0x70,(char)0x4a,(char)0x40,
(char)0x91,(char)0x01,(char)0x78,(char)0x27,
(char)0x67,(char)0x50,(char)0x2c,(char)0xc2,
(char)0x83,(char)0x41,(char)0xa8,(char)0x18,
(char)0x95,(char)0xc3,(char)0x4c,(char)0x12,
(char)0x90,(char)0x24,(char)0x40,(char)0x5e,
(char)0x34,(char)0xad,(char)0x8c,(char)0xa6,
(char)0x91,(char)0x48,(char)0x3d,(char)0x05,
(char)0x88,(char)0x57,(char)0x03,(char)0x30,
(char)0xec,(char)0x34,(char)0xa2,(char)0x15,
(char)0x70,(char)0x4a,(char)0x40,(char)0x91,
(char)0x01,(char)0x7b,(char)0xc5,(char)0x6c,
(char)0x12,(char)0x90,(char)0x24,(char)0x40,
(char)0x5e,(char)0xf5,(char)0x23,(char)0xb8,
(char)0x12,(char)0x0b,(char)0xcd,(char)0x38,
(char)0x48,(char)0x33,(char)0x27,(char)0xb2,
(char)0xf4,(char)0x42,(char)0xcd,(char)0x80
};


char[] e = new char[b.length];
System.out.println("decode returned = " + decode(b, e));
for(int i = 0; i < b.length; i++) {
System.out.println("0x" + Integer.toHexString(e[i]));
}
}

}
November 24, 2003, 11:44 PM
iago
Although I didn't read that, don't forget that Java doesn't do unsigned, so make sure that's not a factor.
November 25, 2003, 12:12 AM
Myndfyr
ooh ooh I THINK I know....

Java's characters are all WIDE (that is, 16-bit Unicode), whereas ANSI C uses narrow (8-bit) characters. That COULD be an issue. This is interesting me, if you want to tell me WHERE you got this, I might be willing to help you further. =)
November 25, 2003, 2:19 AM
iago
btw, this is a very handy String constructor:
String(byte[] bytes, String charsetName)
Constructs a new String by decoding the specified array of bytes using the specified charset.

where charsetName = "US-Ascii".
November 25, 2003, 2:53 AM
xsemaphorex
Ahh.. Thank you all for your help. I finally got it to work. I found out the hard way that java has an obscure operator '>>>' that shifts right and inserts a 0. The rest of the method was quite easy.

Let me know if you would be interested in the ~20 line and 1 parameter method source ;) I'd post it now.. but my wife is giving me 'that look'...
November 28, 2003, 1:53 AM
iago
Sure, might as well post it .. why not? :)
November 28, 2003, 2:00 AM
Hostile
[quote author=iago link=board=34;threadid=3826;start=0#msg32158 date=1069984807]
Sure, might as well post it .. why not? :)
[/quote]

Though I'll leave out by comments regarding the certainty of semaphore's statement, I just want you to know how very badly you need to get laid Iago. :-*
November 28, 2003, 3:38 AM
iago
[quote author=Hostile link=board=34;threadid=3826;start=0#msg32171 date=1069990690]
[quote author=iago link=board=34;threadid=3826;start=0#msg32158 date=1069984807]
Sure, might as well post it .. why not? :)
[/quote]

Though I'll leave out by comments regarding the certainty of semaphore's statement, I just want you to know how very badly you need to get laid Iago. :-*
[/quote]

I don't see what you mean.

I understand the implication of what semephore was going to do, and I hope he enjoys it, but what's that have to do with him posting the source later?

[edit] Wait, are you coming onto me? eww!
November 28, 2003, 3:40 AM
Hostile
[quote author=iago link=board=34;threadid=3826;start=0#msg32173 date=1069990859]
Wait, are you coming onto me? eww!
[/quote]

You mean you haven't picked up on the signs :'(
hehe anyways sorry I thought you totally missed what he was implying there
November 28, 2003, 5:35 AM
iago
No, of course I realized, but I just didn't care :P


So yeah, I care more about the code. So?
November 28, 2003, 7:53 AM
Thing
"that look" might be the one that women give when they feel that you have been spending waaaay too much time doing whatever it is that you are doing and feel that it is in your best interest to pay attention to them for a while and knock off whatever it is that you are doing that is making them give you "that look" in the first place because it is obviously more important to keep them from having to give you "that look" and I'm surprised that you have the nerve to force me into giving you "that look"!

DAMN!

What's wrong with you?

The best way to combat "that look" is to reply with. "No problem, I was on my way out to get some hookers and beer anyway." They will never give you "that look" again. >:D
November 29, 2003, 12:16 AM
Crypticflare
the only "look" you'd be seeing is the back of their head as they walk out the door :P
November 29, 2003, 5:01 AM
Hitmen
[quote author=Crypticflare link=board=34;threadid=3826;start=0#msg32349 date=1070082117]
the only "look" you'd be seeing is the back of their head as they walk out the door :P
[/quote]
Only if they have a really bad sense of humor.
November 29, 2003, 5:04 AM
Hostile
Thing you almost made a point there until you showed us proof that you don't have a women (or were joking so shouldn't bothered to be taken seriously) :P
November 29, 2003, 6:05 AM
Tuberload
[quote author=Hostile link=board=34;threadid=3826;start=0#msg32363 date=1070085926]
Thing you almost made a point there until you showed us proof that you don't have a women (or were joking so shouldn't bothered to be taken seriously) :P
[/quote]

I have a woman and make comments like Thing suggested on a regular basis. Although those comments only result in more looks, but better that than some of the unneeded actions.;D
November 29, 2003, 10:48 AM

Search