Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 18 additions & 37 deletions Addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,58 +75,39 @@ void CAddress::Initialize(eSAMPVersion sampVersion)
}
}
#else

FUNC_CConsole_AddStringVariable = FindPattern("\x55\x89\xE5\x56\x53\x83\xEC\x00\x8B\x75\x00\x85\xF6\x74\x00\x89\x34\x24", "xxxxxxx?xx?xxx?xxx");
FUNC_CConsole_SetStringVariable = FindPattern("\x55\x89\xE5\x83\xEC\x00\x89\x75\x00\x8B\x45\x00\x89\x7D\x00\x8B\x7D\x00\x89\x5D\x00\x89\x44\x24\x00\x8B\x45\x00", "xxxxx?xx?xx?xx?xx?xx?xxx?xx?");
FUNC_CConsole_SetIntVariable = FindPattern("\x74\x00\x83\x38\x00\x74\x00\xC9\x31\xC0\xC3\x8B\x40\x00\x8B\x00", "x?xx?x?xxxxxx?xx") - 0x1A;
FUNC_CConsole_ModifyVariableFlags = FindPattern("\x89\x04\x24\xE8\x00\x00\x00\x00\x85\xC0\x89\xC2\x74\x00\x8B\x45\x00", "xxxx????xxxxx?xx?") - 0x10;

FUNC_CFilterscripts_LoadFilterscript = FindPattern("\x89\x7D\x00\x8B\x45\x00\x8B\x7D\x00\x89\x5D\x00\x89\x44\x24\x00", "xx?xx?xx?xx?xxx?") - 0x9;
FUNC_CFilterscripts_UnLoadFilterscript = FindPattern("\x31\xF6\x53\x83\xEC\x00\x8B\x45\x00\x8B\x7D\x00\x89\xC3", "xxxxx?xx?xx?xx") - 0x5;

ADDR_CNetGame_GMX_GangZoneDelete = NULL;
FUNC_ContainsInvalidChars = FindPattern("\x53\x8B\x5D\x00\x0F\xB6\x0B\x84\xC9\x74\x00\x66\x90", "xxx?xxxxxx?xx") - 0x3;

switch(sampVersion)
{
case SAMP_VERSION_03Z:
{
VAR_pRestartWaitTime = 0x8150130;

FUNC_CConsole_AddStringVariable = 0x0809F590;
FUNC_CConsole_SetStringVariable = 0x0809EDB0;
FUNC_CConsole_SetIntVariable = 0x0809ED10;
FUNC_CConsole_ModifyVariableFlags = 0x0809EE60;

FUNC_CFilterscripts_LoadFilterscript = 0x0809FDB0;
FUNC_CFilterscripts_UnLoadFilterscript = 0x080A01E0;

ADDR_CNetGame_GMX_GangZoneDelete = NULL;
FUNC_ContainsInvalidChars = 0x080D2A50;
ADDR_RECEIVE_HOOKPOS = 0x80645D6;
VAR_pRestartWaitTime = 0x8150130;

ADDR_RECEIVE_HOOKPOS = 0x80645D6;
break;
}
case SAMP_VERSION_03Z_R2_2:
{
VAR_pRestartWaitTime = 0x8150B60;

FUNC_CConsole_AddStringVariable = 0x809F760;
FUNC_CConsole_SetStringVariable = 0x809F000;
FUNC_CConsole_SetIntVariable = 0x809EEE0;
FUNC_CConsole_ModifyVariableFlags = 0x809F030;

FUNC_CFilterscripts_LoadFilterscript = 0x0809FF80;
FUNC_CFilterscripts_UnLoadFilterscript = 0x080A03B0;
VAR_pRestartWaitTime = 0x8150B60;

ADDR_CNetGame_GMX_GangZoneDelete = NULL;
FUNC_ContainsInvalidChars = 0x080D2F50;
ADDR_RECEIVE_HOOKPOS = 0x80645D6;
ADDR_RECEIVE_HOOKPOS = 0x80645D6;
break;
}
case SAMP_VERSION_03Z_R3:
{
VAR_pRestartWaitTime = 0x8150B60;
VAR_pRestartWaitTime = 0x8150B60;

FUNC_CConsole_AddStringVariable = 0x809F760;
FUNC_CConsole_SetStringVariable = 0x809F000;
FUNC_CConsole_SetIntVariable = 0x809EEE0;
FUNC_CConsole_ModifyVariableFlags = 0x809F030;

FUNC_CFilterscripts_LoadFilterscript = 0x0809FF80; // done
FUNC_CFilterscripts_UnLoadFilterscript = 0x080A03B0; // done

ADDR_CNetGame_GMX_GangZoneDelete = NULL;
FUNC_ContainsInvalidChars = 0x080D2F50;
ADDR_RECEIVE_HOOKPOS = 0x80645D6;
ADDR_RECEIVE_HOOKPOS = 0x80645D6;
break;
}
}
Expand Down
57 changes: 28 additions & 29 deletions Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,39 +109,38 @@ void AssemblyRedirect(void * from, void * to, char * ret)
AssemblySwap((char *)from, ret, 5);
}

#ifdef WIN32
DWORD FindPattern(char *pattern, char *mask)
{
#ifdef WIN32
MODULEINFO mInfo = {0};
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(NULL), &mInfo, sizeof(MODULEINFO));
DWORD base = (DWORD)mInfo.lpBaseOfDll;
DWORD size = (DWORD)mInfo.SizeOfImage;
#else
#endif
DWORD patternLength = (DWORD)strlen(mask);
for(DWORD i = 0; i < size - patternLength; i++)
DWORD i;
DWORD size;
DWORD address;
#ifdef WIN32
MODULEINFO info = { 0 };

address = (DWORD)GetModuleHandle(NULL);
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(NULL), &info, sizeof(MODULEINFO));
size = (DWORD)info.SizeOfImage;
#else
address = 0x804b480; // around the elf base
size = 0x8128B80 - address;
#endif
for(i = 0; i < size; ++i)
{
bool found = true;
for(DWORD j = 0; j < patternLength; j++)
{
found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
}

if(found)
{
return base + i;
}
if(memory_compare((BYTE *)(address + i), (BYTE *)pattern, mask))
return (DWORD)(address + i);
}

return NULL;
}
#endif
return 0;
}

bool memory_compare(const BYTE *data, const BYTE *pattern, const char *mask)
{
for(; *mask; ++mask, ++data, ++pattern)
{
if(*mask == 'x' && *data != *pattern)
return false;
}
return (*mask) == NULL;
}

// From "amx.c", part of the PAWN language runtime:
// http://code.google.com/p/pawnscript/source/browse/trunk/amx/amx.c
Expand Down
4 changes: 2 additions & 2 deletions Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "SDK/amx/amx.h"
#include "SDK/plugincommon.h"
#include "CTypes.h"
#include "Inlines.h"

// Hopefully this will be optimised out
Expand All @@ -19,9 +20,8 @@ void AssemblyRedirect(void * from, void * to, char * ret);

void Redirect(AMX * amx, char const * const from, ucell to, AMX_NATIVE * store);

#ifdef WIN32
DWORD FindPattern(char *pattern, char *mask);
#endif
bool memory_compare(BYTE *data, const BYTE *pattern, const char *mask);

bool YSF_ContainsInvalidChars(char * szString);
void GetAddresses();
Expand Down