Receive MsgConnect (1052):
Code:
uint encryptCode = (packet.AccountId + packet.Data) ^ 0x4321;
client.Crypto.ChangeCode(packet.Data ^ encryptCode);
// send MsgTalk (1004) with NEW_ROLE or ANSWER_OK string and ChatAttribute.Entrance (2101)
ChangeCode:
Code:
public unsafe void ChangeCode(uint data)
{
_bufEncrypt3 = new byte[KEY_LENGTH];
_bufEncrypt4 = new byte[KEY_LENGTH];
uint data2 = data * data;
fixed (byte* pKey1 = _bufEncrypt1, pKey2 = _bufEncrypt2, pKey3 = _bufEncrypt3, pKey4 = _bufEncrypt4)
{
MSVCRT.memcpy(pKey3, pKey1, KEY_LENGTH);
MSVCRT.memcpy(pKey4, pKey2, KEY_LENGTH);
for (int i = 0; i < KEY_LENGTH; i += 4)
{
*((uint*)&pKey3[i]) ^= data;
*((uint*)&pKey4[i]) ^= data2;
}
}
_useAlternate = true;
}