#ifdef __GNUG__
    #pragma implementation "client.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "client.h"

DEFINE_EVENT_TYPE(mwEVT_USER_INFO)

wxString iptos(u_long in)
{
	u_char *p;

	p = (u_char *)&in;
	return wxString::Format("%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
}

client::client()
{
	m_handler = NULL;
}

client::~client()
{
}

wxUint32 csi[256] = {
         0, 0x77073096, 0xee0e612c, 0x990951ba,  0x76dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
 0xedb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,  0x9b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190,  0x1db7106, 0x98d220bc, 0xefd5102a, 0x71b18589,  0x6b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2,  0xf00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb,  0x86d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6,  0x3b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af,  0x4db2615, 0x73dc1683,
0xe3630b12, 0x94643b84,  0xd6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d,  0xa00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c,  0x26d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785,  0x5005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae,  0xcb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7,  0xbdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};

wxUint32 spr[] = {
  0x808200,          0,     0x8000,   0x808202,   0x808002,     0x8202,        0x2,     0x8000,
     0x200,   0x808200,   0x808202,      0x200,   0x800202,   0x808002,   0x800000,        0x2,
     0x202,   0x800200,   0x800200,     0x8200,     0x8200,   0x808000,   0x808000,   0x800202,
    0x8002,   0x800002,   0x800002,     0x8002,          0,      0x202,     0x8202,   0x800000,
    0x8000,   0x808202,        0x2,   0x808000,   0x808200,   0x800000,   0x800000,      0x200,
  0x808002,     0x8000,     0x8200,   0x800002,      0x200,        0x2,   0x800202,     0x8202,
  0x808202,     0x8002,   0x808000,   0x800202,   0x800002,      0x202,     0x8202,   0x808200,
     0x202,   0x800200,   0x800200,          0,     0x8002,     0x8200,          0,   0x808002,
0x40084010, 0x40004000,     0x4000,    0x84010,    0x80000,       0x10, 0x40080010, 0x40004010,
0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000,    0x80000,       0x10, 0x40080010,
   0x84000,    0x80010, 0x40004010,          0, 0x40000000,     0x4000,    0x84010, 0x40080000,
   0x80010, 0x40000010,          0,    0x84000,     0x4010, 0x40084000, 0x40080000,     0x4010,
         0,    0x84010, 0x40080010,    0x80000, 0x40004010, 0x40080000, 0x40084000,     0x4000,
0x40080000, 0x40004000,       0x10, 0x40084010,    0x84010,       0x10,     0x4000, 0x40000000,
    0x4010, 0x40084000,    0x80000, 0x40000010,    0x80010, 0x40004010, 0x40000010,    0x80010,
   0x84000,          0, 0x40004000,     0x4010, 0x40000000, 0x40080010, 0x40084010,    0x84000,
     0x104,  0x4010100,          0,  0x4010004,  0x4000100,          0,    0x10104,  0x4000100,
   0x10004,  0x4000004,  0x4000004,    0x10000,  0x4010104,    0x10004,  0x4010000,      0x104,
 0x4000000,        0x4,  0x4010100,      0x100,    0x10100,  0x4010000,  0x4010004,    0x10104,
 0x4000104,    0x10100,    0x10000,  0x4000104,        0x4,  0x4010104,      0x100,  0x4000000,
 0x4010100,  0x4000000,    0x10004,      0x104,    0x10000,  0x4010100,  0x4000100,          0,
     0x100,    0x10004,  0x4010104,  0x4000100,  0x4000004,      0x100,          0,  0x4010004,
 0x4000104,    0x10000,  0x4000000,  0x4010104,        0x4,    0x10104,    0x10100,  0x4000004,
 0x4010000,  0x4000104,      0x104,  0x4010000,    0x10104,        0x4,  0x4010004,    0x10100,
0x80401000, 0x80001040, 0x80001040,       0x40,   0x401040, 0x80400040, 0x80400000, 0x80001000,
         0,   0x401000,   0x401000, 0x80401040, 0x80000040,          0,   0x400040, 0x80400000,
0x80000000,     0x1000,   0x400000, 0x80401000,       0x40,   0x400000, 0x80001000,     0x1040,
0x80400040, 0x80000000,     0x1040,   0x400040,     0x1000,   0x401040, 0x80401040, 0x80000040,
  0x400040, 0x80400000,   0x401000, 0x80401040, 0x80000040,          0,          0,   0x401000,
    0x1040,   0x400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040,       0x40,
0x80401040, 0x80000040, 0x80000000,     0x1000, 0x80400000, 0x80001000,   0x401040, 0x80400040,
0x80001000,     0x1040,   0x400000, 0x80401000,       0x40,   0x400000,     0x1000,   0x401040,
      0x80,  0x1040080,  0x1040000, 0x21000080,    0x40000,       0x80, 0x20000000,  0x1040000,
0x20040080,    0x40000,  0x1000080, 0x20040080, 0x21000080, 0x21040000,    0x40080, 0x20000000,
 0x1000000, 0x20040000, 0x20040000,          0, 0x20000080, 0x21040080, 0x21040080,  0x1000080,
0x21040000, 0x20000080,          0, 0x21000000,  0x1040080,  0x1000000, 0x21000000,    0x40080,
   0x40000, 0x21000080,       0x80,  0x1000000, 0x20000000,  0x1040000, 0x21000080, 0x20040080,
 0x1000080, 0x20000000, 0x21040000,  0x1040080, 0x20040080,       0x80,  0x1000000, 0x21040000,
0x21040080,    0x40080, 0x21000000, 0x21040080,  0x1040000,          0, 0x20040000, 0x21000000,
   0x40080,  0x1000080, 0x20000080,    0x40000,          0, 0x20040000,  0x1040080, 0x20000080,
0x10000008, 0x10200000,     0x2000, 0x10202008, 0x10200000,        0x8, 0x10202008,   0x200000,
0x10002000,   0x202008,   0x200000, 0x10000008,   0x200008, 0x10002000, 0x10000000,     0x2008,
         0,   0x200008, 0x10002008,     0x2000,   0x202000, 0x10002008,        0x8, 0x10200008,
0x10200008,          0,   0x202008, 0x10202000,     0x2008,   0x202000, 0x10202000, 0x10000000,
0x10002000,        0x8, 0x10200008,   0x202000, 0x10202008,   0x200000,     0x2008, 0x10000008,
  0x200000, 0x10002000, 0x10000000,     0x2008, 0x10000008, 0x10202008,   0x202000, 0x10200000,
  0x202008, 0x10202000,          0, 0x10200008,        0x8,     0x2000, 0x10200000,   0x202008,
    0x2000,   0x200008, 0x10002008,          0, 0x10202000, 0x10000000,   0x200008, 0x10002008,
  0x100000,  0x2100001,  0x2000401,          0,      0x400,  0x2000401,   0x100401,  0x2100400,
 0x2100401,   0x100000,          0,  0x2000001,        0x1,  0x2000000,  0x2100001,      0x401,
 0x2000400,   0x100401,   0x100001,  0x2000400,  0x2000001,  0x2100000,  0x2100400,   0x100001,
 0x2100000,      0x400,      0x401,  0x2100401,   0x100400,        0x1,  0x2000000,   0x100400,
 0x2000000,   0x100400,   0x100000,  0x2000401,  0x2000401,  0x2100001,  0x2100001,        0x1,
  0x100001,  0x2000000,  0x2000400,   0x100000,  0x2100400,      0x401,   0x100401,  0x2100400,
     0x401,  0x2000001,  0x2100401,  0x2100000,   0x100400,          0,        0x1,  0x2100401,
         0,   0x100401,  0x2100000,      0x400,  0x2000001,  0x2000400,      0x400,   0x100001,
 0x8000820,      0x800,    0x20000,  0x8020820,  0x8000000,  0x8000820,       0x20,  0x8000000,
   0x20020,  0x8020000,  0x8020820,    0x20800,  0x8020800,    0x20820,      0x800,       0x20,
 0x8020000,  0x8000020,  0x8000800,      0x820,    0x20800,    0x20020,  0x8020020,  0x8020800,
     0x820,          0,          0,  0x8020020,  0x8000020,  0x8000800,    0x20820,    0x20000,
   0x20820,    0x20000,  0x8020800,      0x800,       0x20,  0x8020020,      0x800,    0x20820,
 0x8000800,       0x20,  0x8000020,  0x8020000,  0x8020020,  0x8000000,    0x20000,  0x8000820,
         0,  0x8020820,    0x20020,  0x8000020,  0x8020000,  0x8000800,  0x8000820,          0,
 0x8020820,    0x20800,    0x20800,      0x820,      0x820,    0x20020,  0x8000000,  0x8020800,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
         0,       0x80,          0,       0x80,     0x8000,     0x8080,     0x8000,     0x8080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
  0x800000,   0x800080,   0x800000,   0x800080,   0x808000,   0x808080,   0x808000,   0x808080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80000000, 0x80000080, 0x80000000, 0x80000080, 0x80008000, 0x80008080, 0x80008000, 0x80008080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
0x80800000, 0x80800080, 0x80800000, 0x80800080, 0x80808000, 0x80808080, 0x80808000, 0x80808080,
         0,          0,       0x80,       0x80,          0,          0,       0x80,       0x80,
    0x8000,     0x8000,     0x8080,     0x8080,     0x8000,     0x8000,     0x8080,     0x8080,
         0,          0,       0x80,       0x80,          0,          0,       0x80,       0x80,
    0x8000,     0x8000,     0x8080,     0x8080,     0x8000,     0x8000,     0x8080,     0x8080,
  0x800000,   0x800000,   0x800080,   0x800080,   0x800000,   0x800000,   0x800080,   0x800080,
  0x808000,   0x808000,   0x808080,   0x808080,   0x808000,   0x808000,   0x808080,   0x808080,
  0x800000,   0x800000,   0x800080,   0x800080,   0x800000,   0x800000,   0x800080,   0x800080,
  0x808000,   0x808000,   0x808080,   0x808080,   0x808000,   0x808000,   0x808080,   0x808080,
         0,          0,       0x80,       0x80,          0,          0,       0x80,       0x80,
    0x8000,     0x8000,     0x8080,     0x8080,     0x8000,     0x8000,     0x8080,     0x8080,
         0,          0,       0x80,       0x80,          0,          0,       0x80,       0x80,
    0x8000,     0x8000,     0x8080,     0x8080,     0x8000,     0x8000,     0x8080,     0x8080,
  0x800000,   0x800000,   0x800080,   0x800080,   0x800000,   0x800000,   0x800080,   0x800080,
  0x808000,   0x808000,   0x808080,   0x808080,   0x808000,   0x808000,   0x808080,   0x808080,
  0x800000,   0x800000,   0x800080,   0x800080,   0x800000,   0x800000,   0x800080,   0x800080,
  0x808000,   0x808000,   0x808080,   0x808080,   0x808000,   0x808000,   0x808080,   0x808080,
0x80000000, 0x80000000, 0x80000080, 0x80000080, 0x80000000, 0x80000000, 0x80000080, 0x80000080,
0x80008000, 0x80008000, 0x80008080, 0x80008080, 0x80008000, 0x80008000, 0x80008080, 0x80008080,
0x80000000, 0x80000000, 0x80000080, 0x80000080, 0x80000000, 0x80000000, 0x80000080, 0x80000080,
0x80008000, 0x80008000, 0x80008080, 0x80008080, 0x80008000, 0x80008000, 0x80008080, 0x80008080,
0x80800000, 0x80800000, 0x80800080, 0x80800080, 0x80800000, 0x80800000, 0x80800080, 0x80800080,
0x80808000, 0x80808000, 0x80808080, 0x80808080, 0x80808000, 0x80808000, 0x80808080, 0x80808080,
0x80800000, 0x80800000, 0x80800080, 0x80800080, 0x80800000, 0x80800000, 0x80800080, 0x80800080,
0x80808000, 0x80808000, 0x80808080, 0x80808080, 0x80808000, 0x80808000, 0x80808080, 0x80808080,
0x80000000, 0x80000000, 0x80000080, 0x80000080, 0x80000000, 0x80000000, 0x80000080, 0x80000080,
0x80008000, 0x80008000, 0x80008080, 0x80008080, 0x80008000, 0x80008000, 0x80008080, 0x80008080,
0x80000000, 0x80000000, 0x80000080, 0x80000080, 0x80000000, 0x80000000, 0x80000080, 0x80000080,
0x80008000, 0x80008000, 0x80008080, 0x80008080, 0x80008000, 0x80008000, 0x80008080, 0x80008080,
0x80800000, 0x80800000, 0x80800080, 0x80800080, 0x80800000, 0x80800000, 0x80800080, 0x80800080,
0x80808000, 0x80808000, 0x80808080, 0x80808080, 0x80808000, 0x80808000, 0x80808080, 0x80808080,
0x80800000, 0x80800000, 0x80800080, 0x80800080, 0x80800000, 0x80800000, 0x80800080, 0x80800080,
0x80808000, 0x80808000, 0x80808080, 0x80808080, 0x80808000, 0x80808000, 0x80808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0, 0x80000000,   0x800000, 0x80800000,     0x8000, 0x80008000,   0x808000, 0x80808000,
      0x80, 0x80000080,   0x800080, 0x80800080,     0x8080, 0x80008080,   0x808080, 0x80808080,
         0,          0,          0,          0,          0,          0,          0,          0,
         0,          0,          0,          0,          0,          0,          0,          0,
0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000,
0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000,
  0x800000,   0x800000,   0x800000,   0x800000,   0x800000,   0x800000,   0x800000,   0x800000,
  0x800000,   0x800000,   0x800000,   0x800000,   0x800000,   0x800000,   0x800000,   0x800000,
0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000,
0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000, 0x80800000,
    0x8000,     0x8000,     0x8000,     0x8000,     0x8000,     0x8000,     0x8000,     0x8000,
    0x8000,     0x8000,     0x8000,     0x8000,     0x8000,     0x8000,     0x8000,     0x8000,
0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000,
0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000,
  0x808000,   0x808000,   0x808000,   0x808000,   0x808000,   0x808000,   0x808000,   0x808000,
  0x808000,   0x808000,   0x808000,   0x808000,   0x808000,   0x808000,   0x808000,   0x808000,
0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000,
0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000, 0x80808000,
      0x80,       0x80,       0x80,       0x80,       0x80,       0x80,       0x80,       0x80,
      0x80,       0x80,       0x80,       0x80,       0x80,       0x80,       0x80,       0x80,
0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080,
0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080, 0x80000080,
  0x800080,   0x800080,   0x800080,   0x800080,   0x800080,   0x800080,   0x800080,   0x800080,
  0x800080,   0x800080,   0x800080,   0x800080,   0x800080,   0x800080,   0x800080,   0x800080,
0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080,
0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080, 0x80800080,
    0x8080,     0x8080,     0x8080,     0x8080,     0x8080,     0x8080,     0x8080,     0x8080,
    0x8080,     0x8080,     0x8080,     0x8080,     0x8080,     0x8080,     0x8080,     0x8080,
0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080,
0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080, 0x80008080,
  0x808080,   0x808080,   0x808080,   0x808080,   0x808080,   0x808080,   0x808080,   0x808080,
  0x808080,   0x808080,   0x808080,   0x808080,   0x808080,   0x808080,   0x808080,   0x808080,
0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080,
0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080, 0x80808080
};

// 617670
wxUint32 spr2[] = {
	0x2020101,  0x2020202,  0x2020201,  0x1020202,   0x202830, 0x31140c04,  0x5012129, 0x2a32150d,
	0xe060222, 0x232b3316, 0x170f0703, 0x1c242c34, 0x35181008,  0x91d252d, 0x2e361911, 0x120a1e26,
	0x272f371a, 0x1b130b1f,  0x4110b0e,   0x19171b, 0x1207160d, 0x18100905, 0x150c1402, 0x1a0f0801,
	0x1319040f, 0x101a0109,  0x8170b05,   0x11070c,  0xe0a0316, 0x181b1406
};

char crypt_buf[1024];

/*
:0061D77C 07 02 00 00 04 0D 00 00 05 00 00 00 03 00 00 00
:0061D78C 06 22 00 00 06 19 00 00 01 0A 00 00 11 08 00 00
:0061D79C 0B 20 00 00 04 13 00 00 02 29 00 00 15 01 00 00
:0061D7AC 28 04 00 00 21 12 00 00 00 09 00 00 01 12 00 00
:0061D7BC 38 08 00 00 30 20 00 00 08 1D 00 00 18 02 00 00
:0061D7CC 30 01 00 00 20 26 00 00 24 14 00 00 2A 00 00 00
:0061D7DC 10 04 00 00 00 24 00 00 15 12 00 00 0A 28 00 00
:0061D7EC 00 30 00 00 0A 04 00 00 02 32 00 00 00 00 00 00
:0061D7FC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/

wxUint32 dword_61D77C[32];

wxUint32 client::checksum(char *buf, int len)
{
	wxUint32 ax = 0xffffffff;
	for (int index=0; index<len; index++) {
		ax = (ax>>8) ^ csi[(buf[index]^ax)&0xff];
	}
	return ~ax;
}

void des_decrypt(int isdecrypt)
{
	wxUint32 var_4 = 0, var_8 = 0, var_C = 0;
	wxUint32 buf = 0;

	__asm {
                push    eax
                push    ebx
                push    ecx
                push    edx
                push    esi
                push    edi
                movzx   ecx, byte ptr crypt_buf[5]
                movzx   eax, byte ptr crypt_buf[0]
                shl     ecx, 2
                mov     buf, ecx
                movzx   ecx, byte ptr crypt_buf[6]
                movzx   edx, byte ptr crypt_buf[1]
                shl     ecx, 2
                mov     var_C, ecx
                movzx   ecx, byte ptr crypt_buf[7]
                movzx   ebx, byte ptr crypt_buf[4]
                shl     ecx, 2
                shl     eax, 2
                mov     var_8, ecx
                mov     ecx, spr[800h][eax]
                mov     eax, spr[0C00h][eax]
                shr     ecx, 1
                shr     eax, 1
                shl     edx, 2
                or      ecx, spr[800h][edx]
                or      eax, spr[0C00h][edx]
                push    esi
                movzx   esi, byte ptr crypt_buf[2]
                shr     ecx, 1
                shr     eax, 1
                shl     esi, 2
                or      ecx, spr[800h][esi]
                or      eax, spr[0C00h][esi]
                shr     ecx, 1
                push    edi
                movzx   edi, byte ptr crypt_buf[3]
                shr     eax, 1
                shl     ebx, 2
                shl     edi, 2
                or      ecx, spr[800h][edi]
                or      eax, spr[0C00h][edi]
                shr     ecx, 1
                or      ecx, spr[800h][ebx]
                mov     var_4, ebx
                mov     edx, ebx
                mov     esi, spr[0C00h][edx]
                mov     ebx, buf
                mov     edx, buf
                shr     eax, 1
                or      eax, esi
                mov     esi, spr[0C00h][edx]
                mov     edx, var_C
                shr     ecx, 1
                or      ecx, spr[800h][ebx]
                mov     ebx, var_C
                shr     eax, 1
                or      eax, esi
                mov     esi, spr[0C00h][edx]
                mov     edx, isdecrypt
                shr     ecx, 1
                or      ecx, spr[800h][ebx]
                mov     ebx, var_8
                shr     eax, 1
                or      eax, esi
                mov     esi, spr[0C00h][ebx]
                shr     ecx, 1
                or      ecx, spr[800h][ebx]
                shr     eax, 1
                or      eax, esi
                test    edx, edx
                jnz     loc_45D76D
                mov     edx, offset dword_61D77C
                mov     buf, edx

loc_45D6C2:                             ; CODE XREF: sub_45D5C0+1A2j
                mov     esi, eax
                shr     esi, 1Fh
                lea     edi, [eax+eax]
                or      esi, edi
                mov     edi, esi
                shl     edi, 1Ch
                mov     ebx, esi
                shr     ebx, 4
                or      edi, ebx
                xor     edi, [edx-4]
                xor     esi, [edx]
                mov     edx, edi
                shr     edx, 18h
                and     edx, 3Fh
                mov     edx, spr[edx*4]
                mov     ebx, edi
                shr     ebx, 10h
                and     ebx, 3Fh
                xor     edx, spr[200h][ebx*4]
                mov     ebx, esi
                shr     ebx, 18h
                and     ebx, 3Fh
                xor     edx, spr[100h][ebx*4]
                mov     ebx, edi
                shr     ebx, 8
                and     ebx, 3Fh
                xor     edx, spr[400h][ebx*4]
                mov     ebx, esi
                shr     ebx, 10h
                and     ebx, 3Fh
                xor     edx, spr[300h][ebx*4]
                mov     ebx, esi
                shr     ebx, 8
                and     ebx, 3Fh
                xor     edx, spr[500h][ebx*4]
                and     edi, 3Fh
                xor     edx, spr[600h][edi*4]
                and     esi, 3Fh
                xor     edx, spr[700h][esi*4]
                xor     edx, ecx
                mov     ecx, eax
                mov     eax, edx
                mov     edx, buf
                add     edx, 8
                cmp     edx, offset dword_61D77C+32*4
                mov     buf, edx
                jl      loc_45D6C2
                jmp     loc_45D81C
; ---------------------------------------------------------------------------

loc_45D76D:                             ; CODE XREF: sub_45D5C0+F3j
                mov     edx, offset dword_61D77C+30*4
                mov     buf, edx

loc_45D776:                             ; CODE XREF: sub_45D5C0+256j
                mov     esi, eax
                shr     esi, 1Fh
                lea     edi, [eax+eax]
                or      esi, edi
                mov     edi, esi
                shl     edi, 1Ch
                mov     ebx, esi
                shr     ebx, 4
                or      edi, ebx
                xor     edi, [edx-4]
                xor     esi, [edx]
                mov     edx, edi
                shr     edx, 18h
                and     edx, 3Fh
                mov     edx, spr[edx*4]
                mov     ebx, edi
                shr     ebx, 10h
                and     ebx, 3Fh
                xor     edx, spr[200h][ebx*4]
                mov     ebx, esi
                shr     ebx, 18h
                and     ebx, 3Fh
                xor     edx, spr[100h][ebx*4]
                mov     ebx, edi
                shr     ebx, 8
                and     ebx, 3Fh
                xor     edx, spr[400h][ebx*4]
                mov     ebx, esi
                shr     ebx, 10h
                and     ebx, 3Fh
                xor     edx, spr[300h][ebx*4]
                mov     ebx, esi
                shr     ebx, 8
                and     ebx, 3Fh
                xor     edx, spr[500h][ebx*4]
                and     edi, 3Fh
                xor     edx, spr[600h][edi*4]
                and     esi, 3Fh
                xor     edx, spr[700h][esi*4]
                xor     edx, ecx
                mov     ecx, eax
                mov     eax, edx
                mov     edx, buf
                sub     edx, 8
                cmp     edx, offset dword_61D77C
                mov     buf, edx
                jge     loc_45D776

loc_45D81C:                             ; CODE XREF: sub_45D5C0+1A8j
                movzx   edx, ch
                shl     edx, 2
                mov     var_C, edx
                mov     edx, eax
                shr     edx, 10h
                movzx   edx, dl
                shl     edx, 2
                mov     buf, eax
                mov     buf, edx
                mov     edx, ecx
                shr     edx, 10h
                movzx   edx, dl
                shl     edx, 2
                mov     esi, eax
                and     esi, 0FFh
                shl     esi, 2
                mov     isdecrypt, ecx
                mov     isdecrypt, edx
                mov     edx, spr[1000h][esi]
                shr     edx, 1
                mov     edi, ecx
                and     edi, 0FFh
                shl     edi, 2
                or      edx, spr[1000h][edi]
                movzx   ebx, ah
                shl     ebx, 2
                mov     var_4, ebx
                shr     edx, 1
                or      edx, spr[1000h][ebx]
                mov     ebx, var_C
                shr     edx, 1
                or      edx, spr[1000h][ebx]
                mov     ebx, buf
                shr     edx, 1
                or      edx, spr[1000h][ebx]
                mov     ebx, isdecrypt
                shr     edx, 1
                or      edx, spr[1000h][ebx]
                shr     eax, 18h
                shl     eax, 2
                mov     ebx, spr[1000h][eax]
                shr     edx, 1
                or      edx, ebx
                shr     ecx, 18h
                shl     ecx, 2
                mov     ebx, spr[1000h][ecx]
                shr     edx, 1
                or      edx, ebx
                mov     ebx, spr[1400h][esi]
                mov     esi, spr[1400h][edi]
                shr     ebx, 1
                or      ebx, esi
                mov     esi, var_4
                mov     edi, spr[1400h][esi]
                mov     esi, var_C
                shr     ebx, 1
                or      ebx, edi
                mov     edi, spr[1400h][esi]
                mov     esi, buf
                shr     ebx, 1
                or      ebx, edi
                mov     edi, spr[1400h][esi]
                mov     esi, isdecrypt
                shr     ebx, 1
                or      ebx, edi
                mov     edi, spr[1400h][esi]
                shr     ebx, 1
                or      ebx, edi
                mov     edi, spr[1400h][eax]
                mov     eax, spr[1400h][ecx]
                shr     ebx, 1
                or      ebx, edi
                shr     ebx, 1
                or      ebx, eax
                mov     eax, edx
                shr     eax, 18h
                mov     ecx, edx
                shr     ecx, 10h
                mov     byte ptr crypt_buf[0], al
                mov     byte ptr crypt_buf[1], cl
                mov     eax, edx
                shr     eax, 8
                mov     byte ptr crypt_buf[3], dl
                mov     byte ptr crypt_buf[2], al
                mov     ecx, ebx
                mov     edx, ebx
                mov     eax, ebx
                pop     edi
                shr     ecx, 18h
                shr     edx, 10h
                shr     eax, 8
                pop     esi
                mov     byte ptr crypt_buf[7], bl
                mov     byte ptr crypt_buf[4], cl
                mov     byte ptr crypt_buf[5], dl
                mov     byte ptr crypt_buf[6], al
				pop		edi
				pop		esi
				pop		edx
				pop		ecx
                pop     ebx
				pop		eax
	}
}

void set_key64(char *arg_0)
{
	wxUint32 var_ebp = 0;

	char varb[8];
	wxUint32 vari[3];

	__asm	{
				push	eax
                push    ebx
				push	ecx
				push	edx
                push    esi
                push    edi
                xor     edi, edi
                mov		var_ebp, 0
                mov     edx, offset spr2+10h
                mov     vari[0], 8

loc_45D3C8:                             ; CODE XREF: sub_45D3B0+51j
                mov     ecx, arg_0
                mov     al, [ecx]
                inc     ecx
                mov     arg_0, ecx
                mov     esi, 7

loc_45D3D8:                             ; CODE XREF: sub_45D3B0+4Bj
                test    al, al
                jns     short loc_45D3F7
                xor     ecx, ecx
                mov     cl, [edx]
                cmp     cl, 1Ch
                mov     ebx, 1
                jb      short loc_45D3F3
                sub     ecx, 1Ch
                shl     ebx, cl
                or      edi, ebx
                jmp     short loc_45D3F7
; ---------------------------------------------------------------------------

loc_45D3F3:                             ; CODE XREF: sub_45D3B0+38j
                shl     ebx, cl
                or      var_ebp, ebx

loc_45D3F7:                             ; CODE XREF: sub_45D3B0+2Aj
                                        ; sub_45D3B0+41j
                inc     edx
                shl     al, 1
                dec     esi
                jnz     short loc_45D3D8
                dec     vari[0]
                jnz     short loc_45D3C8
                mov     dword ptr vari[0], offset spr2
                mov     dword ptr vari[8], offset dword_61D77C

loc_45D413:                             ; CODE XREF: sub_45D3B0+175j
                mov     eax, dword ptr vari[0]
                movzx   eax, byte ptr [eax]
                mov     edx, 1Ch
                sub     edx, eax
                mov     esi, edi
                mov     ecx, edx
                shr     esi, cl
                mov     ecx, eax
                shl     edi, cl
                mov     ecx, edx
                mov     vari[4], 4
                or      esi, edi
                and     esi, 0FFFFFFFh
                mov     edi, esi
                mov     esi, var_ebp
                shr     esi, cl
                mov     ecx, eax
                shl     var_ebp, cl
                lea     eax, varb[0]
                or      esi, var_ebp
                and     esi, 0FFFFFFFh
                mov     var_ebp, esi
                mov     esi, offset spr2+48h
                lea     ebx, [ebx+0]

loc_45D460:                             ; CODE XREF: sub_45D3B0+D5j
                mov     byte ptr [eax], 0
                mov     dl, 20h

loc_45D465:                             ; CODE XREF: sub_45D3B0+C9j
                mov     cl, [esi]
                mov     ebx, edi
                shr     ebx, cl
                and     bl, 1
                inc     esi
                test    bl, bl
                jz      short loc_45D475
                or      [eax], dl

loc_45D475:                             ; CODE XREF: sub_45D3B0+C1j
                shr     dl, 1
                test    dl, dl
                jnz     short loc_45D465
                mov     ecx, dword ptr vari[4]
                inc     eax
                dec     ecx
                mov     dword ptr vari[4], ecx
                jnz     short loc_45D460
                mov     esi, offset spr2+60h
                mov     vari[4], 4

loc_45D494:                             ; CODE XREF: sub_45D3B0+110j
                mov     byte ptr [eax], 0
                mov     dl, 20h
//                lea     esp, [esp+0]

loc_45D4A0:                             ; CODE XREF: sub_45D3B0+104j
                mov     cl, [esi]
                mov     ebx, var_ebp
                shr     ebx, cl
                and     bl, 1
                inc     esi
                test    bl, bl
                jz      short loc_45D4B0
                or      [eax], dl

loc_45D4B0:                             ; CODE XREF: sub_45D3B0+FCj
                shr     dl, 1
                test    dl, dl
                jnz     short loc_45D4A0
                mov     ecx, dword ptr vari[4]
                inc     eax
                dec     ecx
                mov     dword ptr vari[4], ecx
                jnz     short loc_45D494
                movzx   edx, varb[2]
                movzx   eax, varb[4]
                xor     ecx, ecx
                mov     ch, varb[0]
                or      ecx, edx
                movzx   edx, varb[6]
                shl     ecx, 8
                or      ecx, eax
                mov     eax, dword ptr vari[8]
                shl     ecx, 8
                or      ecx, edx
                movzx   edx, varb[3]
                mov     [eax-4], ecx
                movzx   ecx, varb[1]
                shl     ecx, 8
                or      ecx, edx
                movzx   edx, varb[5]
                shl     ecx, 8
                or      ecx, edx
                movzx   edx, varb[7]
                shl     ecx, 8
                or      ecx, edx
                mov     edx, dword ptr vari[0]
                add     eax, 8
                mov     [eax-8], ecx
                inc     edx
                cmp     eax, offset dword_61D77C+32*4
                mov     dword ptr vari[8], eax
                mov     dword ptr vari[0], edx
                jl      loc_45D413
                pop     edi
                pop     esi
				pop		edx
				pop		ecx
                pop     ebx
				pop		eax
	}
}

struct card {
	char magic[4];
	char name[72];
	wxUint32 id[4];
};

card CARD = {"PFT", "", {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476} };

void gen_card_name(card *crd)
{
	wxUint32 var_ebp = 0;

	wxUint32 varr[16];

	wxUint32 var_44 = 0;

	__asm {
                push    eax
                push    ebx
                push    ecx
                push    edx
                push    esi
                push    edi
                mov     eax, crd
				// my
				mov		ecx, eax
				add		ecx, 4
				// my
                add     ecx, 2
                lea     esi, varr[0]
                mov     edi, 10h

loc_45A827:                             ; CODE XREF: sub_45A810+3Bj
                movzx   ebx, byte ptr [ecx-1]
                xor     edx, edx
                mov     dh, [ecx+1]
                add     esi, 4
                add     ecx, 4
                mov     dl, [ecx-4]
                shl     edx, 8
                or      edx, ebx
                movzx   ebx, byte ptr [ecx-6]
                shl     edx, 8
                or      edx, ebx
                dec     edi
                mov     [esi-4], edx
                jnz     short loc_45A827
                mov     esi, [eax+50h]
                mov     edi, [eax+54h]
                mov     edx, [eax+58h]
                mov     eax, [eax+4Ch]
					push eax
					mov  eax, varr[0]
					mov	 var_ebp, eax
					pop eax
                mov     ebx, edi
                and     ebx, esi
                mov     ecx, esi
                not     ecx
                and     ecx, edx
                or      ecx, ebx
                add     ecx, var_ebp
                lea     ecx, [eax+ecx-28955B88h]
					push eax
					mov  eax, varr[4]
					mov	 var_ebp, eax
					pop eax
                mov     eax, ecx
                shl     ecx, 7
                shr     eax, 19h
                or      eax, ecx
                add     eax, esi
                mov     ecx, eax
                not     ecx
                and     ecx, edi
                mov     ebx, esi
                and     ebx, eax
                or      ecx, ebx
                add     ecx, var_ebp
					push eax
					mov  eax, varr[8]
					mov	 var_ebp, eax
					pop eax
                lea     edx, [edx+ecx-173848AAh]
                mov     ecx, edx
                shl     edx, 0Ch
                shr     ecx, 14h
                or      ecx, edx
                add     ecx, eax
                mov     edx, ecx
                not     edx
                and     edx, esi
                mov     ebx, ecx
                and     ebx, eax
                or      edx, ebx
                add     edx, var_ebp
                lea     edi, [edi+edx+242070DBh]
                mov     edx, edi
					push eax
					mov  eax, varr[0Ch]
					mov	 var_ebp, eax
					pop eax
                shl     edi, 11h
                shr     edx, 0Fh
                or      edx, edi
                add     edx, ecx
                mov     edi, edx
                not     edi
                and     edi, eax
                mov     ebx, ecx
                and     ebx, edx
                or      edi, ebx
                add     edi, var_ebp
					push eax
					mov  eax, varr[10h]
					mov	 var_ebp, eax
					pop eax
                lea     edi, [esi+edi-3E423112h]
                mov     esi, edi
                shr     edi, 0Ah
                shl     esi, 16h
                or      esi, edi
                add     esi, edx
                mov     edi, esi
                not     edi
                and     edi, ecx
                mov     ebx, edx
                and     ebx, esi
                or      edi, ebx
                add     edi, var_ebp
					push eax
					mov  eax, varr[14h]
					mov	 var_ebp, eax
					pop eax
                lea     edi, [eax+edi-0A83F051h]
                mov     eax, edi
                shl     edi, 7
                shr     eax, 19h
                or      eax, edi
                add     eax, esi
                mov     edi, eax
                not     edi
                mov     ebx, esi
                and     edi, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [ecx+edi+4787C62Ah]
                mov     ecx, edi
                shl     edi, 0Ch
					push eax
					mov  eax, varr[18h]
					mov	 var_ebp, eax
					pop eax
                shr     ecx, 14h
                or      ecx, edi
                add     ecx, eax
                mov     edi, ecx
                not     edi
                and     edi, esi
                mov     ebx, ecx
                and     ebx, eax
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [edx+edi-57CFB9EDh]
                mov     edx, edi
                shl     edi, 11h
					push eax
					mov  eax, varr[1Ch]
					mov	 var_ebp, eax
					pop eax
                shr     edx, 0Fh
                or      edx, edi
                add     edx, ecx
                mov     edi, edx
                not     edi
                and     edi, eax
                mov     ebx, ecx
                and     ebx, edx
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [esi+edi-2B96AFFh]
                mov     esi, edi
                shr     edi, 0Ah
					push eax
					mov  eax, varr[20h]
					mov	 var_ebp, eax
					pop eax
                shl     esi, 16h
                or      esi, edi
                add     esi, edx
                mov     ebx, edx
                and     ebx, esi
                mov     edi, esi
                not     edi
                and     edi, ecx
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [eax+edi+698098D8h]
					push eax
					mov  eax, varr[24h]
					mov	 var_ebp, eax
					pop eax
                mov     eax, edi
                shl     edi, 7
                shr     eax, 19h
                or      eax, edi
                add     eax, esi
                mov     edi, eax
                not     edi
                and     edi, edx
                mov     ebx, esi
                and     ebx, eax
                or      edi, ebx
                add     edi, var_ebp
					push eax
					mov  eax, varr[28h]
					mov	 var_ebp, eax
					pop eax
                lea     edi, [ecx+edi-74BB0851h]
                mov     ecx, edi
                shl     edi, 0Ch
                shr     ecx, 14h
                or      ecx, edi
                add     ecx, eax
                mov     edi, ecx
                not     edi
                and     edi, esi
                mov     ebx, ecx
                and     ebx, eax
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [edx+edi-0A44Fh]
                mov     edx, edi
                shl     edi, 11h
                shr     edx, 0Fh
                or      edx, edi
                add     edx, ecx
                mov     edi, edx
                not     edi
                and     edi, eax
                mov     ebx, ecx
					push eax
					mov  eax, varr[2Ch]
					mov	 var_ebp, eax
					pop eax
                and     ebx, edx
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [esi+edi-76A32842h]
                mov     esi, edi
                shr     edi, 0Ah
					push eax
					mov  eax, varr[30h]
					mov	 var_ebp, eax
					pop eax
                shl     esi, 16h
                or      esi, edi
                add     esi, edx
                mov     edi, esi
                not     edi
                and     edi, ecx
                mov     ebx, edx
                and     ebx, esi
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [eax+edi+6B901122h]
					push eax
					mov  eax, varr[34h]
					mov	 var_ebp, eax
					pop eax
                mov     eax, edi
                shl     edi, 7
                shr     eax, 19h
                or      eax, edi
                add     eax, esi
                mov     edi, eax
                not     edi
                and     edi, edx
                mov     ebx, esi
                and     ebx, eax
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [ecx+edi-2678E6Dh]
                mov     ecx, edi
                shl     edi, 0Ch
                shr     ecx, 14h
                or      ecx, edi
                add     ecx, eax
                mov     edi, ecx
                not     edi
                mov     ebx, edi
                and     ebx, esi
                mov     var_ebp, ecx
                and     var_ebp, eax
                or      ebx, var_ebp
                add     ebx, varr[38h]
                lea     ebx, [edx+ebx-5986BC72h]
                mov     edx, ebx
                shl     ebx, 11h
                shr     edx, 0Fh
                or      edx, ebx
                add     edx, ecx
                mov     ebx, edx
                not     ebx
                mov     var_44, ebx
                and     ebx, eax
                mov     var_ebp, ecx
                and     var_ebp, edx
                or      ebx, var_ebp
					push eax
					mov  eax, varr[3Ch]
					mov	 var_ebp, eax
					pop eax
                add     ebx, var_ebp
                lea     ebx, [esi+ebx+49B40821h]
                mov     esi, ebx
                shr     ebx, 0Ah
                shl     esi, 16h
                or      esi, ebx
                and     edi, edx
                add     esi, edx
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, varr[4]
                lea     edi, [eax+edi-9E1DA9Eh]
                mov     eax, edi
                shl     edi, 5
                shr     eax, 1Bh
                or      eax, edi
                mov     edi, var_44
                add     eax, esi
                and     edi, esi
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[18h]
                lea     edi, [ecx+edi-3FBF4CC0h]
                mov     ecx, edi
                shl     edi, 9
                shr     ecx, 17h
                or      ecx, edi
                add     ecx, eax
                mov     edi, esi
                not     edi
                and     edi, eax
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, varr[2Ch]
                lea     edi, [edx+edi+265E5A51h]
                mov     edx, edi
                shl     edi, 0Eh
                shr     edx, 12h
                or      edx, edi
                add     edx, ecx
                mov     edi, eax
                not     edi
                and     edi, ecx
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[0]
                lea     edi, [esi+edi-16493856h]
                mov     esi, edi
                shr     edi, 0Ch
                shl     esi, 14h
                or      esi, edi
                add     esi, edx
                mov     edi, ecx
                not     edi
                and     edi, edx
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, varr[14h]
                lea     edi, [eax+edi-29D0EFA3h]
                mov     eax, edi
                shl     edi, 5
                shr     eax, 1Bh
                or      eax, edi
                mov     edi, edx
                not     edi
                and     edi, esi
                mov     ebx, edx
                add     eax, esi
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[28h]
                lea     edi, [ecx+edi+2441453h]
                mov     ecx, edi
                shl     edi, 9
                shr     ecx, 17h
                or      ecx, edi
                add     ecx, eax
                mov     edi, esi
                not     edi
                and     edi, eax
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, var_ebp
                lea     edi, [edx+edi-275E197Fh]
                mov     edx, edi
                shr     edx, 12h
                shl     edi, 0Eh
                or      edx, edi
                add     edx, ecx
                mov     edi, eax
                not     edi
                and     edi, ecx
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[10h]
                lea     edi, [esi+edi-182C0438h]
                mov     esi, edi
                shr     edi, 0Ch
                shl     esi, 14h
                or      esi, edi
                add     esi, edx
                mov     edi, ecx
                not     edi
                and     edi, edx
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, varr[24h]
                lea     edi, [eax+edi+21E1CDE6h]
                mov     eax, edi
                shl     edi, 5
                shr     eax, 1Bh
                or      eax, edi
                add     eax, esi
                mov     edi, edx
                not     edi
                and     edi, esi
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[38h]
                lea     edi, [ecx+edi-3CC8F82Ah]
                mov     ecx, edi
                shl     edi, 9
                shr     ecx, 17h
                or      ecx, edi
                add     ecx, eax
                mov     edi, esi
                not     edi
                and     edi, eax
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, varr[0Ch]
                lea     edi, [edx+edi-0B2AF279h]
                mov     edx, edi
                shl     edi, 0Eh
                shr     edx, 12h
                or      edx, edi
                add     edx, ecx
                mov     edi, eax
                not     edi
                and     edi, ecx
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[20h]
                lea     edi, [esi+edi+455A14EDh]
                mov     esi, edi
                shr     edi, 0Ch
                shl     esi, 14h
                or      esi, edi
                mov     edi, ecx
                not     edi
                add     esi, edx
                and     edi, edx
                mov     ebx, ecx
                and     ebx, esi
                or      edi, ebx
                add     edi, varr[34h]
                lea     edi, [eax+edi-561C16FBh]
                mov     eax, edi
                shr     eax, 1Bh
                shl     edi, 5
                or      eax, edi
                add     eax, esi
                mov     edi, edx
                not     edi
                and     edi, esi
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[8]
                lea     edi, [ecx+edi-3105C08h]
                mov     ecx, edi
                shl     edi, 9
                shr     ecx, 17h
                or      ecx, edi
                add     ecx, eax
                mov     ebx, ecx
                and     ebx, esi
                mov     edi, esi
                not     edi
                and     edi, eax
                or      edi, ebx
                add     edi, varr[1Ch]
                lea     edi, [edx+edi+676F02D9h]
                mov     edx, edi
                shl     edi, 0Eh
                shr     edx, 12h
                or      edx, edi
                add     edx, ecx
                mov     edi, eax
                not     edi
                and     edi, ecx
                mov     ebx, edx
                and     ebx, eax
                or      edi, ebx
                add     edi, varr[30h]
                mov     ebx, varr[14h]
                lea     edi, [esi+edi-72D5B376h]
                mov     esi, edi
                shr     edi, 0Ch
                shl     esi, 14h
                or      esi, edi
                mov     edi, ecx
                xor     edi, edx
                add     esi, edx
                xor     edi, esi
                add     edi, ebx
                mov     ebx, varr[20h]
                lea     edi, [eax+edi-5C6BEh]
                mov     eax, edi
                shl     edi, 4
                shr     eax, 1Ch
                or      eax, edi
                mov     edi, edx
                xor     edi, esi
                add     eax, esi
                xor     edi, eax
                add     edi, ebx
                mov     ebx, varr[2Ch]
                lea     ecx, [ecx+edi-788E097Fh]
                mov     edi, ecx
                shl     ecx, 0Bh
                shr     edi, 15h
                or      edi, ecx
                add     edi, eax
                mov     ecx, edi
                xor     ecx, esi
                xor     ecx, eax
                add     ecx, ebx
                lea     ecx, [edx+ecx+6D9D6122h]
                mov     edx, ecx
                shr     edx, 10h
                shl     ecx, 10h
                or      edx, ecx
                add     edx, edi
                mov     ebx, edi
                xor     ebx, edx
                mov     ecx, ebx
                xor     ecx, eax
                add     ecx, varr[38h]
                lea     esi, [esi+ecx-21AC7F4h]
                mov     ecx, esi
                shr     esi, 9
                shl     ecx, 17h
                or      ecx, esi
                mov     esi, varr[4]
                add     ecx, edx
                xor     ebx, ecx
                add     ebx, esi
                lea     ebx, [eax+ebx-5B4115BCh]
                mov     eax, ebx
                shl     ebx, 4
                shr     eax, 1Ch
                or      eax, ebx
                mov     ebx, varr[10h]
                add     eax, ecx
                mov     esi, edx
                xor     esi, ecx
                xor     esi, eax
                add     esi, ebx
                lea     edi, [edi+esi+4BDECFA9h]
                mov     esi, edi
                shl     edi, 0Bh
                mov     ebx, varr[1Ch]
                shr     esi, 15h
                or      esi, edi
                add     esi, eax
                mov     edi, esi
                xor     edi, ecx
                xor     edi, eax
                add     edi, ebx
                lea     edi, [edx+edi-944B4A0h]
                mov     edx, edi
                shl     edi, 10h
                shr     edx, 10h
                or      edx, edi
                add     edx, esi
                mov     edi, esi
                xor     edi, edx
                mov     ebx, edi
                xor     ebx, eax
                add     ebx, varr[28h]
                lea     ebx, [ecx+ebx-41404390h]
                mov     ecx, ebx
                shr     ebx, 9
                shl     ecx, 17h
                or      ecx, ebx
                mov     ebx, varr[34h]
                add     ecx, edx
                xor     edi, ecx
                add     edi, ebx
                mov     ebx, varr[0]
                lea     edi, [eax+edi+289B7EC6h]
                mov     eax, edi
                shl     edi, 4
                shr     eax, 1Ch
                or      eax, edi
                mov     edi, edx
                xor     edi, ecx
                add     eax, ecx
                xor     edi, eax
                add     edi, ebx
                mov     ebx, varr[0Ch]
                lea     edi, [esi+edi-155ED806h]
                mov     esi, edi
                shl     edi, 0Bh
                shr     esi, 15h
                or      esi, edi
                add     esi, eax
                mov     edi, esi
                xor     edi, ecx
                xor     edi, eax
                add     edi, ebx
                lea     edx, [edx+edi-2B10CF7Bh]
                mov     edi, edx
                shr     edi, 10h
                shl     edx, 10h
                or      edi, edx
                add     edi, esi
                mov     edx, esi
                xor     edx, edi
                mov     ebx, edx
                xor     ebx, eax
                add     ebx, varr[18h]
                lea     ebx, [ecx+ebx+4881D05h]
                mov     ecx, ebx
                shr     ebx, 9
                shl     ecx, 17h
                or      ecx, ebx
                add     ecx, edi
                mov     ebx, varr[24h]
                xor     edx, ecx
                add     edx, ebx
                mov     ebx, varr[30h]
                lea     edx, [eax+edx-262B2FC7h]
                mov     eax, edx
                shl     edx, 4
                shr     eax, 1Ch
                or      eax, edx
                mov     edx, edi
                xor     edx, ecx
                add     eax, ecx
                xor     edx, eax
                add     edx, ebx
                lea     esi, [esi+edx-1924661Bh]
                mov     edx, esi
                shl     esi, 0Bh
                mov     ebx, varr[8]
                shr     edx, 15h
                or      edx, esi
                add     edx, eax
                mov     esi, edx
                xor     esi, ecx
                xor     esi, eax
                add     esi, var_ebp
                lea     edi, [edi+esi+1FA27CF8h]
                mov     esi, edi
                shl     edi, 10h
                shr     esi, 10h
                or      esi, edi
                add     esi, edx
                mov     edi, edx
                xor     edi, esi
                xor     edi, eax
                add     edi, ebx
                lea     edi, [ecx+edi-3B53A99Bh]
                mov     ebx, varr[0]
                mov     ecx, edi
                shr     edi, 9
                shl     ecx, 17h
                or      ecx, edi
                mov     edi, edx
                not     edi
                add     ecx, esi
                or      edi, ecx
                xor     edi, esi
                add     edi, ebx
                mov     ebx, varr[1Ch]
                lea     edi, [eax+edi-0BD6DDBCh]
                mov     eax, edi
                shl     edi, 6
                shr     eax, 1Ah
                or      eax, edi
                add     eax, ecx
                mov     edi, esi
                not     edi
                or      edi, eax
                xor     edi, ecx
                add     edi, ebx
                mov     ebx, varr[38h]
                lea     edi, [edx+edi+432AFF97h]
                mov     edx, edi
                shl     edi, 0Ah
                shr     edx, 16h
                or      edx, edi
                mov     edi, ecx
                add     edx, eax
                not     edi
                or      edi, edx
                xor     edi, eax
                add     edi, ebx
                lea     edi, [esi+edi-546BDC59h]
                mov     esi, edi
                shl     edi, 0Fh
                mov     ebx, varr[14h]
                shr     esi, 11h
                or      esi, edi
                add     esi, edx
                mov     edi, eax
                not     edi
                or      edi, esi
                xor     edi, edx
                add     edi, ebx
                lea     edi, [ecx+edi-36C5FC7h]
                mov     ecx, edi
                shr     edi, 0Bh
                mov     ebx, varr[30h]
                shl     ecx, 15h
                or      ecx, edi
                add     ecx, esi
                mov     edi, edx
                not     edi
                or      edi, ecx
                xor     edi, esi
                add     edi, ebx
                lea     edi, [eax+edi+655B59C3h]
                mov     eax, edi
                shl     edi, 6
                mov     ebx, varr[0Ch]
                shr     eax, 1Ah
                or      eax, edi
                add     eax, ecx
                mov     edi, esi
                not     edi
                or      edi, eax
                xor     edi, ecx
                add     edi, ebx
                lea     edi, [edx+edi-70F3336Eh]
                mov     edx, edi
                shl     edi, 0Ah
                mov     ebx, varr[28h]
                shr     edx, 16h
                or      edx, edi
                add     edx, eax
                mov     edi, ecx
                not     edi
                or      edi, edx
                xor     edi, eax
                add     edi, ebx
                lea     edi, [esi+edi-100B83h]
                mov     ebx, varr[4]
                mov     esi, edi
                shl     edi, 0Fh
                shr     esi, 11h
                or      esi, edi
                mov     edi, eax
                not     edi
                add     esi, edx
                or      edi, esi
                xor     edi, edx
                add     edi, ebx
                mov     ebx, varr[20h]
                lea     edi, [ecx+edi-7A7BA22Fh]
                mov     ecx, edi
                shr     edi, 0Bh
                shl     ecx, 15h
                or      ecx, edi
                mov     edi, edx
                not     edi
                add     ecx, esi
                or      edi, ecx
                xor     edi, esi
                add     edi, ebx
                lea     edi, [eax+edi+6FA87E4Fh]
                mov     eax, edi
                shl     edi, 6
                shr     eax, 1Ah
                or      eax, edi
                mov     edi, esi
                add     eax, ecx
                not     edi
                or      edi, eax
                xor     edi, ecx
                add     edi, var_ebp
                lea     edi, [edx+edi-1D31920h]
                mov     edx, edi
                shl     edi, 0Ah
					push eax
					mov  eax, varr[18h]
					mov	 var_ebp, eax
					pop eax
                shr     edx, 16h
                or      edx, edi
                add     edx, eax
                mov     edi, ecx
                not     edi
                or      edi, edx
                xor     edi, eax
                add     edi, var_ebp
                lea     edi, [esi+edi-5CFEBCECh]
                mov     esi, edi
                shl     edi, 0Fh
					push eax
					mov  eax, varr[34h]
					mov	 var_ebp, eax
					pop eax
                shr     esi, 11h
                or      esi, edi
                add     esi, edx
                mov     edi, eax
                not     edi
                or      edi, esi
                xor     edi, edx
                add     edi, var_ebp
                lea     edi, [ecx+edi+4E0811A1h]
                mov     ecx, edi
                shr     edi, 0Bh
					push eax
					mov  eax, varr[10h]
					mov	 var_ebp, eax
					pop eax
                shl     ecx, 15h
                or      ecx, edi
                add     ecx, esi
                mov     edi, edx
                not     edi
                or      edi, ecx
                xor     edi, esi
                add     edi, var_ebp
                lea     edi, [eax+edi-8AC817Eh]
					push eax
					mov  eax, varr[2Ch]
					mov	 var_ebp, eax
					pop eax
                mov     eax, edi
                shl     edi, 6
                shr     eax, 1Ah
                or      eax, edi
                mov     edi, esi
                not     edi
                add     eax, ecx
                or      edi, eax
                xor     edi, ecx
                add     edi, var_ebp
					push eax
					mov  eax, varr[8]
					mov	 var_ebp, eax
					pop eax
                lea     edi, [edx+edi-42C50DCBh]
                mov     edx, edi
                shl     edi, 0Ah
                mov     ebx, varr[24h]
                shr     edx, 16h
                or      edx, edi
                add     edx, eax
                mov     edi, ecx
                not     edi
                or      edi, edx
                xor     edi, eax
                add     edi, var_ebp
                lea     esi, [esi+edi+2AD7D2BBh]
                mov     edi, esi
                shl     esi, 0Fh
                shr     edi, 11h
                or      edi, esi
                mov     esi, eax
                not     esi
                add     edi, edx
                or      esi, edi
                xor     esi, edx
                add     esi, ebx
                lea     ecx, [ecx+esi-14792C6Fh]
                mov     esi, crd
                mov     ebx, [esi+4Ch]
                add     ebx, eax
                mov     [esi+4Ch], ebx
                mov     eax, ecx
                mov     ebx, [esi+50h]
                shl     eax, 15h
                shr     ecx, 0Bh
                or      eax, ecx
                add     eax, ebx
                add     eax, edi
                mov     [esi+50h], eax
                mov     eax, [esi+54h]
                add     eax, edi
                mov     [esi+54h], eax
                mov     eax, [esi+58h]
                add     eax, edx
                mov     [esi+58h], eax

				pop		edi
				pop		esi
				pop		edx
				pop		ecx
                pop     ebx
				pop		eax
	}
}

void crypt(char *buf, int len, int param)
{
	len = (len+7)&0xfffffff8;

	while (len>=8) {
		memcpy(crypt_buf, buf, 8);
		des_decrypt(param);
		memcpy(buf, crypt_buf, 8);
		buf+=8;
		len-=8;
	}
}

void unpack_key(login_pkt *pkt)
{
	for (int index=0; index<8; index++) {
		char h[3];
		int c;
		strncpy(h, pkt->key+index*2, 2);
		h[2] = 0;
		sscanf(h, "%x", &c);
		pkt->key[index] = ~c;
	}
	pkt->key[7] = 0;
}

void bin2hex(unsigned char *bin, char *str, int len)
{
	*str = 0;
	for (int index=0; index<len; index++) {
		char h[8];
		sprintf(h, "%02X", bin[index]);
		strcat(str, h);
	}
}

bool client::Create(TCPSocket& socket, int port, int protocol, wxUint32 address)
{
	m_port = port;
	m_protocol = protocol;
	m_address = address;

	if (!m_sock.Attach(socket))
		return false;

	m_sock.SetBlockMode(true);

	if (wxThread::Create()!=wxTHREAD_NO_ERROR)
		return false;

	return true;
}

wxString unstr(const char *str, int len)
{
	wxString res;

	for (int index=0; index<len; index++) {
		if (str[index])
			res+=str[index];
	}

	return res;
}

wxString msg1 = _T("Âñåì ìîë÷àòü, ñáîëòíåòå - óáüþ :o)");
wxString msg2 = _T("Enjoy!");

void client::login1(char *keykey, login_pkt2 *request)
{
	wxUint32 cs;
	log_reply_pkt2 reply;

	wxString log_msg = wxString::Format("%s, server:%s, port:%d, protocol:%d", unstr(request->name, request->name_len*2), iptos(request->srv_addr), request->port, request->protocol);
	if (m_handler) {
		wxCommandEvent event(mwEVT_USER_INFO);

		event.SetString(log_msg);
		wxPostEvent(m_handler, event);
	}

	memset(&reply, 0, sizeof(reply));
	reply.len = 2;
	reply.log_ff = 0xff;
	reply.log_func = 0x0;
	reply.len+= 2;
	reply.enabled = 1;
	reply.len+= 4;

	//			reply.reserved1 = 0;
	//			reply.len+= 2;
	reply.srv_addr = request->srv_addr;
	reply.len+= 4;
	reply.port = request->port;
	reply.len+= 4;
	reply.protocol0 = request->protocol;
	reply.len+= 2;
	reply.protocol1 = request->protocol;
	reply.len+= 2;
	reply.protocol2 = request->protocol;
	reply.len+= 4;
	reply.protocol3 = 0x10038;
	//			reply.protocol3 = 0x10050;
	reply.len+= 4;

	memset(&reply.unknown, 0, sizeof(reply.unknown));
	reply.len+= 40;

	char *msg_area = reply.messages;
	strcpy(msg_area, msg1.c_str());
	msg_area+=msg1.Len()+1;
	reply.len+= msg1.Len()+1;
	strcpy(msg_area, msg2.c_str());
	reply.len+= msg2.Len()+1;

	reply.len = ((reply.len-2+7)&0xfffffff8)+2;
	reply.len+=8;

	set_key64(keykey);
	crypt((char *)&reply.log_ff, reply.len-2, 0);
	cs = checksum((char *)&reply.log_ff, reply.len-2);
	memcpy(((char *)&reply)+reply.len, &cs, 4);
	reply.len+=4;

	//			set_key64(keykey);
	//			crypt((char *)&reply.log_ff, reply.len-2, 1);

	m_sock.Send(&reply, reply.len);
}

void client::login2(char *keykey, login_pkt2 *request)
{
	wxUint32 cs;
	log_reply_pkt1055 reply;

	wxString log_msg = wxString::Format("%s, server:%s, port:%d, protocol:%d", unstr(request->name, request->name_len*2), iptos(request->srv_addr), request->port, request->protocol);
	if (m_handler) {
		wxCommandEvent event(mwEVT_USER_INFO);

		event.SetString(log_msg);
		wxPostEvent(m_handler, event);
	}

	memset(&reply, 0, sizeof(reply));
	reply.len = 2;
	reply.log_ff = 0xff;
	reply.log_func = 0x0;
	reply.len+= 2;
	reply.enabled = 1;
	reply.len+= 4;

	//			reply.reserved1 = 0;
	//			reply.len+= 2;
	reply.srv_addr = request->srv_addr;
	reply.len+= 4;
	reply.port = request->port;
	reply.len+= 4;
	reply.protocol0 = request->protocol;
	reply.len+= 2;
	reply.protocol1 = request->protocol;
	reply.len+= 2;
	reply.protocol2 = request->protocol;
	reply.len+= 4;
	reply.protocol3 = 0x10038;
	reply.len+= 4;

	reply.protocol4 = request->protocol;
	reply.len+= 4;
	reply.protocol5 = request->protocol;
	reply.len+= 4;
	reply.protocol6 = request->protocol;
	reply.len+= 4;
	reply.protocol7 = request->protocol;
	reply.len+= 4;

	memset(&reply.unknown, 0, sizeof(reply.unknown));
	reply.len+= 40;

	char *msg_area = reply.messages;
	strcpy(msg_area, msg1.c_str());
	msg_area+=msg1.Len()+1;
	reply.len+= msg1.Len()+1;
	strcpy(msg_area, msg2.c_str());
	reply.len+= msg2.Len()+1;

	reply.len = ((reply.len-2+7)&0xfffffff8)+2;
	reply.len+=8;

	set_key64(keykey);
	crypt((char *)&reply.log_ff, reply.len-2, 0);
	cs = checksum((char *)&reply.log_ff, reply.len-2);
	memcpy(((char *)&reply)+reply.len, &cs, 4);
	reply.len+=4;

	//			set_key64(keykey);
	//			crypt((char *)&reply.log_ff, reply.len-2, 1);

	m_sock.Send(&reply, reply.len);
}

void client::send_game_data(char *keykey, login_pkt2 *request)
{
	wxUint32 cs;
	game_data_pkt1056 reply;

	wxString log_msg = wxString::Format("Get [GameData]");
	if (m_handler) {
		wxCommandEvent event(mwEVT_USER_INFO);

		event.SetString(log_msg);
		wxPostEvent(m_handler, event);
	}

	memset(&reply, 0, sizeof(reply));
	reply.len = 2;
	reply.log_ff = 0xff;
	reply.log_func = 0x1;
	reply.len+= 2;
	reply.data1 = 0xFFFFDE4A;
	reply.len+= 4;
	reply.data2 = 0;
	reply.len+= 4;
	reply.data2 = 0;
	reply.len+= 4;


	reply.len = ((reply.len-2+7)&0xfffffff8)+2;
	reply.len+=8;

	set_key64(keykey);
	crypt((char *)&reply.log_ff, reply.len-2, 0);
	cs = checksum((char *)&reply.log_ff, reply.len-2);
	memcpy(((char *)&reply)+reply.len, &cs, 4);
	reply.len+=4;

	//			set_key64(keykey);
	//			crypt((char *)&reply.log_ff, reply.len-2, 1);

	m_sock.Send(&reply, reply.len);
}

wxThread::ExitCode client::Entry()
{
	wxUint32 cs;
	char buff[1024];

	int len = m_sock.Recv(buff, sizeof(buff));

	if (len<16 || *(wxUint16 *)&buff<16)
		return (ExitCode) wxTHREAD_NO_ERROR;

	if (*(wxUint16 *)&buff!=0x70) {
		// after 10.5.0
		login_pkt2 *request;
		request = (login_pkt2 *)buff;
		cs = *(wxUint32 *)(((char *)request)+request->len-4);
		if (cs==checksum(buff+2, request->len-4-2)) {
			char keykey[16];

			memcpy(keykey, (((char *)request)+request->len-12), 8);
			set_key64(keykey);
			crypt((char *)&request->reserved1, request->len-12, 1);

			switch (request->reserved1>>8) {
				case 03:
					send_game_data(keykey, request);
					break;
				case 00:
					switch (request->version) {
					case 1053:
					case 1054:
						login1(keykey, request);
						break;
					case 1055:
					case 1056:
						login2(keykey, request);
						break;
					default:
						login2(keykey, request);
						break;
					}
			}
		}
	} else	{
		// before 10.5.0
		login_pkt *request;
		request = (login_pkt *)buff;

		cs = request->cs0;
		request->cs0 = 0;
		if (cs==checksum(buff, request->len)) {
			memset(dword_61D77C, 0, 0x20);

			unpack_key(request);
			set_key64(request->key);
			crypt((char *)&request->version, 0x48, 1);

			set_key64(request->key);
			crypt((char *)&request->crypted_name, 40, 1);

			log_reply_pkt reply;
			memset(&reply, 0, sizeof(log_reply_pkt));
			reply.len = sizeof(log_reply_pkt);
			reply.version = 0x416;
			reply.enabled = 1;
			reply.port = request->port;
			reply.protocol = request->protocol;
			reply.srv_addr = request->srv_addr;

			//		reply.dummy1 = 0x6661;
			reply.name_cs = checksum(request->crypted_name, request->name_len*2); // ????
			//		reply.dummy3 = 0x66666663;
			//		reply.dummy4 = 0x66666664;

			memset(&CARD, sizeof(CARD), 0);
			strcpy(CARD.magic, "PFT");
			memcpy(CARD.name, request->crypted_name, request->name_len*2);

			CARD.name[request->name_len*2] = 0x80;
			CARD.name[0x38] = request->name_len<<4;

			CARD.id[0] = 0x67452301;
			CARD.id[1] = 0xEFCDAB89;
			CARD.id[2] = 0x98BADCFE;
			CARD.id[3] = 0x10325476;
			gen_card_name(&CARD);
			bin2hex((unsigned char *)&CARD.id, reply.card_num, 16);

			memcpy(&reply.name0, request->crypted_name, 8);
			set_key64(request->key);
			crypt((char *)&reply.name0, 8, 0);

			wxString msg1 = _T("Âñåì ìîë÷àòü, ñáîëòíåòå - óáüþ :o)");
			wxString msg2 = _T("Enjoy!");
			char *msg_area = reply.messages;
			strcpy(msg_area, msg1.c_str());
			msg_area+=msg1.Len()+1;
			strcpy(msg_area, msg2.c_str());
			reply.msg1_len = msg1.Len()+1;
			reply.msg2_len = msg2.Len()+1;


			wxString log_msg = wxString::Format("%s, server #%d, card '%s'", unstr(request->crypted_name, request->name_len*2), request->srv_num, reply.card_num);
			if (m_handler) {
				wxCommandEvent event(mwEVT_USER_INFO);

				event.SetString(log_msg);
				wxPostEvent(m_handler, event);
			}

			set_key64(request->key);
			crypt((char *)&reply.version, sizeof(log_reply_pkt)-8, 0);
			reply.cs0 = checksum((char *)&reply, sizeof(log_reply_pkt));
			m_sock.Send(&reply, sizeof(log_reply_pkt));
		}
	}
	return (ExitCode) wxTHREAD_NO_ERROR;
}
