Skip to content

Instantly share code, notes, and snippets.

@mueschm
Created November 7, 2012 03:59
Show Gist options
  • Save mueschm/4029499 to your computer and use it in GitHub Desktop.
Save mueschm/4029499 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <stdio.h>
#include "Detour\CDetour.h"
DWORD dwClientNode_SendChatAddress = 0x0082D560;
DWORD dwClientNode_ShowChatAddress = dwClientNode_SendChatAddress + 0x110;
PDWORD pClientNodeInstance;
CDetour ClientNode_SendChatDet;
BYTE ShowChatOrg[] = { 0x83, 0x7E, 0x2C};
BYTE ShowChatFix[] = { 0xC2, 0x0C, 0x00};
void AppendShowChat(bool bFix = true)
{
DWORD dwOldProtect;
VirtualProtect((LPVOID)dwClientNode_ShowChatAddress, 3, PAGE_EXECUTE_READWRITE, &dwOldProtect);
for (int i = 0; i < 3; ++i)
{
if (bFix)
*(PBYTE)(dwClientNode_ShowChatAddress+ i) = ShowChatFix[i];
else
*(PBYTE)(dwClientNode_ShowChatAddress+ i) = ShowChatOrg[i];
}
}
#define START_GAME ""
int nSleep = 5;
void WINAPI ClientNode_SendChat(char* szMessage)
{
if (!stricmp(szMessage, "."))
{
pClientNodeInstance = (PDWORD)ClientNode_SendChatDet.GetThisPtr();
strcpy(szMessage, START_GAME);
}
else if (!memcmp(szMessage, ".delay ", 7))
{
sscanf(szMessage, ".delay %i", &nSleep);
strcpy(szMessage, START_GAME);
}
}
bool bSpam = false;
DWORD WINAPI KeyBindThread(LPVOID)
{
while(true)
{
if (GetAsyncKeyState(VK_MBUTTON)&1)
{
bSpam = true;
}
if (GetAsyncKeyState(0x60)&1)
bSpam = false;
else if (GetAsyncKeyState(VK_HOME)&1)
AppendShowChat();
else if (GetAsyncKeyState(VK_END)&1)
AppendShowChat(false);
if (bSpam)
{
if (pClientNodeInstance == NULL)
continue;
AppendShowChat();
char szBuffer[384];
strcpy(szBuffer, "/all ..");
for (int i = strlen("/all ..")-1; i < 384; ++i)
szBuffer[i] = '\n';
((int (__thiscall*)(PDWORD, char*))dwClientNode_SendChatAddress) (pClientNodeInstance, szBuffer);
}
Sleep(nSleep);
}
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
ClientNode_SendChatDet.Detour((PBYTE)dwClientNode_SendChatAddress, (PBYTE)ClientNode_SendChat, true);
ClientNode_SendChatDet.Apply();
CreateThread(NULL, NULL, KeyBindThread, NULL, NULL, NULL);
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment