Code:
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include "MCommand.h"
#include "detours.h"
#include "CDetour.h"
#pragma comment( lib, "CDetour" )
std::ofstream File;
CDetour MMatchServerOnCommand;
bool __stdcall MMatchServerOnCommandHook( MCommand* pCmd )
{
switch( pCmd->m_pCommandDesc->m_nCommandId )
{
//! You will need to replace the "0x00" with the Packet ID's of each function
//! you wish to log. I remembered 1 Packet ID, which is /admin_wall, which is below
//! these comments.
case 0x1F5:
{
char szbuffer[1024];
sprintf_s( szBuffer, "[%d] : Announcement", pCmd->m_uidSender.uidHigh );
File << szBuffer;
break;
}
case 0x00:
{
break;
}
case 0x00:
{
break;
}
default:
break;
}
MMatchServerOnCommand.Org( pCmd );
return false;
}
bool Setup( )
{
File.open( "CommandsLog.txt", std::ios::out | std::ios::ate );
if( File == NULL )
{
MessageBox( NULL, "Failed to open CommandsLog.txt", "Error", MB_OK | MB_ICONEXCLAMATION );
return false;
}
//! To log to the file, you do this
//- char szBuffer[1024];
//- sprintf_s( szBuffer, "%d %d", Stuff, Stuff2 );
//- File << szBuffer;
//
//! And it will log to it.
return true;
}
bool __stdcall DllMain( HInstance hInstance, DWORD dwReason, LPVOID lpReserved )
{
if( dwReason == DLL_PROCESS_ATTACH )
{
Setup( );
MMatchServerOnCommand.Detour( (PBYTE)MMatchServer__OnCommandAddress, (PBYTE)MMatchServerOnCommandHook );
MMatchServerOnCommand.Apply( );
}
if( dwReason == DLL_PROCESS_ATTACH )
{
File.close( );
MMatchServerOnCommand.Remove( );
}
return true;
}
MCommand.h
Code:
#include <vector>
#include <list>
//! FIND THIS ADDRESSES
const unsigned long MMatchServer__OnCommandAddress = 0x00;
const unsigned long MAddSharedCommandTableAddress = 0x00;
const unsigned long ZNewCMDAddress = 0x00;
const unsigned long MCommand__AddParameterAddress = 0x00;
const unsigned long MCommand__GetParameterAddress = 0x00;
const unsigned long MCommand__GetParameterAddress2 = 0x00;
const unsigned long MCommandDesc__MCommandDescAddress = 0x00;
const unsigned long MCommandParameterDesc__MCommandParameterDescAddress = 0x00;
const unsigned long MCommandManager__AddCommandDescAddress = 0x00;
const unsigned long MCommandDesc__AddParameterDescAddress = 0x00;
const unsigned long MCommandParameterInt__MCommandParameterIntAddress = 0x00;
const unsigned long MCommandParameterUInt__MCommandParameterUIntAddress = 0x00;
const unsigned long MCommandParameterString__MCommandParameterStringAddress = 0x00;
const unsigned long MCommandParameterFloat__MCommandParameterFloatAddress = 0x00;
const unsigned long MCommandParameterMUID__MCommandParameterMUIDAddress = 0x00;
const unsigned long MCommandParameterBlob__MCommandParameterBlobAddress = 0x00;
enum MCommandParameterType
{
MPT_INT,
MPT_UINT,
MPT_FLOAT,
MPT_BOOL,
MPT_STRING,
MPT_VECTOR,
MPT_POS,
MPT_DIR,
MPT_COLOR,
MPT_MUID,
MPT_BLOB,
MPT_CHAR,
MPT_UCHAR,
MPT_SHORT,
MPT_USHORT,
MPT_INT64,
MPT_UINT64,
MPT_SVECTOR
};
struct MUID
{
unsigned long uidLow;
unsigned long uidHigh;
};
struct MCommandParameterDesc;
struct MCommandParameterInt;
struct MCommandParameterUInt;
struct MCommandParameterString;
struct MCommandParameterFloat;
struct MCommandParameterMUID;
struct MCommandParameterBlob;
typedef MCommandParameterDesc* (__thiscall* MCommandParameterDescTypedef)(MCommandParameterDesc*, unsigned long, const char*);
typedef MCommandParameterInt* (__thiscall* MCommandParameterIntTypedef) (MCommandParameterInt*, int);
typedef MCommandParameterUInt* (__thiscall* MCommandParameterUIntTypedef) (MCommandParameterUInt*, unsigned long);
typedef MCommandParameterString* (__thiscall* MCommandParameterStringTypedef) (MCommandParameterString*, char*);
typedef MCommandParameterFloat* (__thiscall* MCommandParameterFloatTypedef) (MCommandParameterFloat*, float);
typedef MCommandParameterMUID* (__thiscall* MCommandParameterMUIDTypedef) (MCommandParameterMUID*, MUID*);
typedef MCommandParameterBlob* (__thiscall* MCommandParameterBlobTypedef) (MCommandParameterBlob*, LPVOID, int);
MCommandParameterDescTypedef MCommandParameterDescConstructor = reinterpret_cast<MCommandParameterDescTypedef>(MCommandParameterDesc__MCommandParameterDescAddress);
MCommandParameterIntTypedef MCommandParameterIntConstructor = reinterpret_cast<MCommandParameterIntTypedef>(MCommandParameterInt__MCommandParameterIntAddress);
MCommandParameterUIntTypedef MCommandParameterUIntConstructor = reinterpret_cast<MCommandParameterUIntTypedef>(MCommandParameterUInt__MCommandParameterUIntAddress);
MCommandParameterStringTypedef MCommandParameterStringConstructor = reinterpret_cast<MCommandParameterStringTypedef>(MCommandParameterString__MCommandParameterStringAddress);
MCommandParameterFloatTypedef MCommandParameterFloatConstructor = reinterpret_cast<MCommandParameterFloatTypedef>(MCommandParameterFloat__MCommandParameterFloatAddress);
MCommandParameterMUIDTypedef MCommandParameterMUIDConstructor = reinterpret_cast<MCommandParameterMUIDTypedef>(MCommandParameterMUID__MCommandParameterMUIDAddress);
MCommandParameterBlobTypedef MCommandParameterBlobConstructor = reinterpret_cast<MCommandParameterBlobTypedef>(MCommandParameterBlob__MCommandParameterBlobAddress);
struct MCommandParameterDesc
{
LPVOID m_pPolymoprhism;
unsigned long m_nParamType;
char m_szDescription[64];
std::vector<LPVOID> m_pParameterConditions;
MCommandParameterDesc(unsigned long type, const char* desc)
{
MCommandParameterDescConstructor(this, type, desc);
}
};
struct MCommandParameter
{
LPVOID m_pPolymoprhism;
unsigned long m_nParamType;
};
struct MCommandParameterInt : public MCommandParameter
{
int m_Value;
MCommandParameterInt(int value)
{
MCommandParameterIntConstructor (this, value);
}
};
struct MCommandParameterUInt : public MCommandParameter
{
unsigned long m_Value;
MCommandParameterUInt(unsigned long value)
{
MCommandParameterUIntConstructor (this, value);
}
};
struct MCommandParameterString : public MCommandParameter
{
char* m_Value;
MCommandParameterString(char* value)
{
MCommandParameterStringConstructor (this, value);
}
};
struct MCommandParameterMUID : public MCommandParameter
{
MUID m_Value;
MCommandParameterMUID(MUID* value)
{
MCommandParameterMUIDConstructor (this, value);
}
};
struct MCommandParameterBlob : public MCommandParameter
{
char* m_Value;
int m_nSize;
static void MakeBlobHeader(char* data, int elementCount, int elementSize)
{
int total = (elementCount * elementSize) + 8;
data = new char[total+4];
memcpy(data, &total, 4);
memcpy(data+4, &elementSize, 4);
memcpy(data+8, &elementCount, 4);
}
static char* MMakeBlobArray(int nOneBlobSize, int nBlobCount)
{
char *result;
result = new char[(nBlobCount * nOneBlobSize + 8)];
*((DWORD *)result + 1) = nBlobCount;
*(DWORD *)result = nOneBlobSize;
return result;
}
static char *MGetBlobArrayElement(char *pBlob, unsigned long i)
{
char *result;
if (i < 0 || i >= *((DWORD *)pBlob + 1))
result = 0;
else
result = pBlob + (i * *(DWORD *)pBlob + 8);
return result;
}
MCommandParameterBlob(LPVOID value, int size)
{
MCommandParameterBlobConstructor (this, value, size);
}
};
struct MCommandDesc;
typedef MCommandDesc* (__thiscall* MCommandDescTypedef)(MCommandDesc*, unsigned long, const char*, const char*, int);
MCommandDescTypedef MCommandDescConstructor = reinterpret_cast<MCommandDescTypedef>(MCommandDesc__MCommandDescAddress);
struct MCommandManager
{
void AddCommandDesc(MCommandDesc* command)
{
((void (__thiscall*)(LPVOID, MCommandDesc*))MCommandManager__AddCommandDescAddress) (this, command);
}
};
struct MCommandDesc
{
LPVOID m_pPolymoprhism;
unsigned long m_nCommandId;
char m_szName[256];
char m_szDescription[256];
unsigned long m_nFlag;
std::vector<MCommandParameterDesc*> m_pParameterDescs;
MCommandDesc(unsigned long commandId, const char* name, const char* description, unsigned long flag)
{
MCommandDescConstructor (this, commandId, name, description, flag);
}
void AddParamDesc(MCommandParameterDesc* param)
{
((void (__thiscall*)(LPVOID, MCommandParameterDesc*))MCommandDesc__AddParameterDescAddress) (this, param);
}
};
struct MCommand
{
LPVOID CMemPool;
MCommand* m_pNextCommand;
MUID m_uidSender;
MUID m_uidReceiver;
MCommandDesc* m_pCommandDesc;
std::vector<MCommandParameter*> m_pCommandParams;
BYTE m_nSerialNumber;
bool AddParameter(MCommandParameter* param)
{
return ((bool (__thiscall *)(LPVOID,MCommandParameter*))MCommand__AddParameterAddress) (this, param);
}
bool GetParameter(void *pValue, int i, MCommandParameterType type, int bufferSize)
{
return ((bool (__thiscall *)(LPVOID,LPVOID,int,MCommandParameterType,int))MCommand__GetParameterAddress) (this, pValue, i, type, bufferSize);
}
MCommandParameter* GetParameter(unsigned long i)
{
return ((MCommandParameter* (__thiscall*)(LPVOID, unsigned long))MCommand__GetParameterAddress2)(this, i);
}
static MCommand* Create(unsigned long packetId)
{
return ((MCommand* (__cdecl*)(unsigned long))ZNewCMDAddress)(packetId);
}
};
struct MPacketHeader
{
unsigned long nMsg;
unsigned long nSize;
unsigned long nCheckSum;
};
struct MPacketCrypterKey
{
char szKey[32];
};
struct MPacketCrypter
{
LPVOID m_pPolymoprhism;
MPacketCrypterKey m_Key;
};
struct MCommandBuilder
{
LPVOID m_pPolymoprhism;
MUID m_uidSender;
MUID m_uidReceiver;
MCommandManager* m_pCommandManager;
char m_Buffer[0x4000];
unsigned long m_nBufferNext;
std::list<MCommand*> m_CommandList;
std::list<MPacketHeader*> m_NetCmdList;
MPacketCrypter* m_pPacketCrypter;
};
You will need to find the addresses for MatchServer, as well as finish off the MMatchServerOnCommandHook function, which I nicely placed some comments to help you.