A dude asked for an external console for TeknoMW3, and I decided to do it for him and for anyone else interested. This works with absolutely anything, Steam version, IW5M, no matter if Multiplayer or Singleplayer -- it should work for all versions.
Code:
#include <windows.h>
#include <stdio.h>
bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask) return 0;
return (*szMask) == NULL;
}
DWORD FindPattern(BYTE *bMask,char * szMask)
{
DWORD dwAddress = (DWORD)GetModuleHandleA("iw5mp.exe"), //make sure this is the right executable
dwLen = 0x1036000; //should have enough length
for(DWORD i=0; i<dwLen; i++)
if (Compare((BYTE*)(dwAddress+i),bMask,szMask)) return (DWORD)(dwAddress+i);
return 0;
}
DWORD WINAPI PatchMW3_Console(LPVOID lpParam)
{
DWORD addr = FindPattern(
(BYTE*)"\x83\x3d\x00\x00\x00\x00\x00\x75\x00\x6a\x00\xff\x15\x00\x00\x00\x00\x50\xe8\x00\x00\x00\x00\x83\xc4\x04",
"xx?????x?xxxx????xx????xxx");
// Calls Sys_CreateConsole
((void)(*)()addr)();
struct tagMSG Msg;
while(true)
{
if(GetMessageA(&Msg, NULL, NULL, NULL))
{
TranslateMessage(&Msg);
DispatchMessageA(&Msg);
}
}
return NULL;
}
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
CreateThread(NULL, NULL,
PatchMW3_Console, NULL, NULL, NULL);
}
return TRUE;
}