void L2Ex::WriteServerMemory(DWORD *pAddress, LPCVOID pData, BYTE length) { DWORD dwOldProtect = NULL; SIZE_T bWritten = NULL; if (!VirtualProtect((LPVOID)(pAddress), length, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { MessageBox(NULL, "Unable to change memory protection 1.", "Error", MB_OK); } if (!WriteProcessMemory(L2Server, (LPVOID)(pAddress), (LPCVOID)pData, length, &bWritten)) { MessageBox(NULL, "Unable to write to memory.", "Error", MB_OK); return; } if (!VirtualProtect((LPVOID)(pAddress), length, dwOldProtect, &dwOldProtect)) { MessageBox(NULL, "Unable to change memory protection 2.", "Error", MB_OK); } } void L2Ex::WriteServerHook(BYTE bType, DWORD *pAddress, DWORD *pFunction, BYTE bNops) { int iSizeBuffer = 5 + bNops; BYTE *bBuffer = new BYTE[iSizeBuffer]; bBuffer[0] = bType; *(DWORD *) (bBuffer + 1) = (DWORD)pFunction - (DWORD)(pAddress+5); int i = 5; while ( bNops > 0) { bBuffer[i] = (BYTE)NOP; ++i; --bNops; } WriteServerMemory((DWORD *)pAddress, (LPCVOID)&bBuffer, iSizeBuffer); delete[] bBuffer; }