Client>Server Communication
There is no singular function that is responsible for this task. In Apex, we rather have multiple of those working together.
Let's get started with the most common function, R5AC::PushViolation:
void __fastcall R5AC::PushViolation(
const __m128i *pszIdentifierStr,
char Severity,
__int64 ExtraDataPtr,
__int64 ExtraDataLen);
In case of client-side abnormalities being detected, it will be invoked like this:
LBL_ON_ABNORMALITY_FOUND:
v119 = v116();
v120 = 0;
v121 = 0i64;
do
{
v122 = *(_BYTE *)(v121 + 41489128); // these are just data and key, and the RVA can be computed with analysis of a runtime dump.
++v120;
v123 = *(_BYTE *)(v121 + 27928337);
v188[++v121 + 15] = v123 ^ v122;
}
while ( v120 < 0xC ); // C-String encryption using simple xor
sprintf_s_2(Buffer, 0x104ui64, Format, v119);
}
}
R5AC::PushViolation(v200, 1, v177, (__int64)Buffer);
It's purpose is to enqueue a new violation record into a list that is fetched and emptied by numerous callers, all originating from r5apex_dx12.exe. These are to be considered slaves because they simply check if there is any messages pending, use CLC_AntiCheat virtual method table to setup a new netmessage in source engine, and then puts the data of the anti-cheat violation/message into the netmsg and sends it to the game server.
__int64 R5AC::PopAnticheatMsg(_WORD* outBuffer, int* outSize){__int64 acContext = qword_5D553D0;
// Lock for thread safetyAcquireSRWLockExclusive(&R5AC::ViolationLock);
// Pre-processing hook (originally v2->vtable[3])(*(void (__fastcall**)(__int64))(acContext + 24))(acContext);
if (R5AC::NumSecondaryVIolations > 0){for (int idx = 0; idx < R5AC::NumSecondaryVIolations; ++idx){__int64 violationEntry = R5AC::SecondaryViolationList + 32LL * idx;if (*(_DWORD*)(violationEntry + 8)) // valid violation{int bufferOffset = 0;*outBuffer = 0; // null-terminate start_WORD* bufferPtr = outBuffer + 1;
for (int j = 0; j < R5AC::NumSecondaryVIolations; ++j){__int64 entryAddr = R5AC::SecondaryViolationList + 32LL * j;if (*(_DWORD*)(entryAddr + 8)){int msgLen = *(_DWORD*)(*(_QWORD*)entryAddr - 4);int extraLen = *(_DWORD*)(*(_QWORD*)(entryAddr + 24) - 4);int totalLen = msgLen + extraLen + 15;
if (totalLen > 512 - bufferOffset) // check overflowbreak;
// Copy first message segmentsse_memcpy(bufferPtr, *(const __m128i**)entryAddr, msgLen + 1);
// Append metadatachar* metaPtr = (char*)bufferPtr + msgLen + 1;*(_DWORD*)metaPtr = *(_DWORD*)(entryAddr + 8);metaPtr[4] = *(_BYTE*)(entryAddr + 12);*(_QWORD*)(metaPtr + 5) = *(_QWORD*)(entryAddr + 16);
// Copy second message segmentsse_memcpy((__m128i*)(metaPtr + 13), *(const __m128i**)(entryAddr + 24), extraLen + 1);
// Reset original entry to mark consumed*(_DWORD*)(entryAddr + 8) = 0;
// Move buffer pointerbufferPtr = (__m128i*)(metaPtr + 13 + extraLen + 1);bufferOffset += totalLen;}}
// Final buffer size*outSize = bufferOffset;
// Simple XOR "encryption" (skip first 2 bytes)if (bufferOffset != 2){uint64_t xorKey = 0x42A1110F96B5E116ULL;for (int k = 0; k < bufferOffset - 2; ++k){((char*)outBuffer)[k + 2] ^= ((char*)&xorKey)[k & 7];}}
ReleaseSRWLockExclusive(&R5AC::ViolationLock);return 1; // message popped successfully}}}
ReleaseSRWLockExclusive(&R5AC::ViolationLock);return 0; // no message}
_BYTE *__fastcall R5::BuildAnticheatMsg3(__int64 a1){if ( !*(_QWORD *)a1 || !*result )return result;v3 = 0;v4 = gpNetChan;if ( gpNetChan ){v14 = vft::CLC_AntiCheatMsg;v15 = 0;v17 = 0i64;v5 = 5;v16 = 1;// send all of them in bulkfor ( i = 0; (unsigned __int8)R5AC::PopAnticheatMsg(v20, &i); --v5 ){if ( !v5 )break;v18 = v20;v19 = i;C_NetChan::SendNetMsg(v4, &v14, 0, 0);C_NetChan::SendDatagram(v4, 0i64);}}