Mushroom Game Development

You are not logged in.

#1 2020-02-22 21:43:28

Registered: 2020-02-15
Posts: 7

[GMS v193+] Sending Packets w/ Encrypted OpCodes


MapleStory eventually add in OpCode encryption on packets from Client->Server.  This means you cannot just directly set the m_aSendBuff field to your buffer.

Solution #1
You can use the client generate the encrypted opcode for you by calling COutPacket::Init and then encoding the rest of the data. Keep in mind you still have to take care of the return address and thread id checks.

void SendPacket(int nType, unsigned char* pData, unsigned int uSize)
	COutPacket oPacket;
	COutPacket__Construct(&oPacket, NULL, nType);

	if (pData && uSize)
		COutPacket__EncodeBuffer(&oPacket, NULL, pData, uSize);

	catch (...)
		Log("[InjectPacket] Exception Caught");

	COutPacket__Destruct(&oPacket, NULL);

DWORD dwLen = 0;
BYTE* pBuffer = GetBuffer(szPacket, &dwLen); //Convert string to byte array

SendPacket(*((short*)pBuffer),pBuffer + 2,dwLen - 2);

Solution #2
If you are a private server and do not want to bother decrypting the OpCodes, then just overwrite the encrypted one with the original.

bool Hook_COutPacket__Init(bool enable)
	typedef void(__fastcall* COutPacket__Init_t)(COutPacket* pThis, void* edx, int nType, int bLoopback, int bTypeHeader1Byte);

	static auto COutPacket__Init = reinterpret_cast<COutPacket__Init_t>(0x00774580);

	COutPacket__Init_t Hook = [](COutPacket* pThis, void* edx, int nType, int bLoopback, int bTypeHeader1Byte) -> void
		unsigned int uOffset = pThis->m_uOffset;
		unsigned char uLO = nType & 0xFF;
		unsigned char uHI = (nType >> 8) & 0xFF;
		Log("COutPacket__Init: 0x%X", nType);
		COutPacket__Init(pThis, edx, nType, bLoopback, bTypeHeader1Byte);
		pThis->m_aSendBuff[uOffset + 0] = uLO;
		pThis->m_aSendBuff[uOffset + 1] = uHI;

	return SetHook(enable, reinterpret_cast<void**>(&COutPacket__Init), Hook);

Let me know if you have any questions.


Board footer

Powered by FluxBB