Merge pull request #25 from Arkshine/feature-client_buy-forward
Implement CS_OnBuy forward + Do some clean up (bug 5906)
This commit is contained in:
@ -5,9 +5,14 @@ binary = AMXX.MetaModule(builder, 'cstrike')
|
||||
|
||||
binary.sources = [
|
||||
'sdk/amxxmodule.cpp',
|
||||
'amxx_api.cpp',
|
||||
'CstrikePlayer.cpp',
|
||||
'cstrike.cpp',
|
||||
'CstrikeNatives.cpp',
|
||||
'CstrikeHacks.cpp',
|
||||
'CstrikeUtils.cpp',
|
||||
'../../../public/memtools/MemoryUtils.cpp',
|
||||
'../../../public/memtools/CDetour/detours.cpp',
|
||||
'../../../public/memtools/CDetour/asm/asm.c',
|
||||
]
|
||||
|
||||
AMXX.modules += [builder.Add(binary)]
|
||||
|
217
dlls/cstrike/cstrike/cstrike.h → dlls/cstrike/cstrike/CstrikeDatas.h
Executable file → Normal file
217
dlls/cstrike/cstrike/cstrike.h → dlls/cstrike/cstrike/CstrikeDatas.h
Executable file → Normal file
@ -1,48 +1,39 @@
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
|
||||
// cstrike MODULE TO DO HERE: http://www.amxmodx.org/forums/viewtopic.php?t=45
|
||||
// This implementation uses Vexd's way (lightly modified) of setting models on players.
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
#ifndef CSTRIKE_DATA_H
|
||||
#define CSTRIKE_DATA_H
|
||||
|
||||
#include "amxxmodule.h"
|
||||
#include <extdll.h>
|
||||
#include <meta_api.h>
|
||||
#include "CstrikePlayer.h"
|
||||
|
||||
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
|
||||
#define GETCLIENTKEYVALUE (*g_engfuncs.pfnInfoKeyValue)
|
||||
#define CREATENAMEDENTITY (*g_engfuncs.pfnCreateNamedEntity)
|
||||
|
||||
#if defined(__linux__) || defined (__APPLE__)
|
||||
#define EXTRAOFFSET 5 // offsets 5 higher in Linux builds
|
||||
@ -52,7 +43,8 @@
|
||||
#define EXTRAOFFSET 0 // no change in Windows builds
|
||||
#define EXTRAOFFSET_WEAPONS 0
|
||||
#define ACTUAL_EXTRA_OFFSET 0
|
||||
#endif // defined(__linux__) || defined(__APPLE__)
|
||||
#endif
|
||||
|
||||
/*
|
||||
Offset history:
|
||||
041029:
|
||||
@ -61,9 +53,6 @@
|
||||
Also backpack ammo offsets were all obviously 5 steps too high since unknown time...
|
||||
|
||||
*/
|
||||
|
||||
#define HAS_SHIELD (1<<24) //16777216
|
||||
|
||||
// "player" entities
|
||||
#if !defined __amd64__
|
||||
// 32 bit offsets here
|
||||
@ -156,20 +145,80 @@
|
||||
#define OFFSET_HOSTAGEID 516 + EXTRAOFFSET // +29
|
||||
#endif
|
||||
|
||||
#if defined __linux__
|
||||
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6
|
||||
#elif defined __APPLE__
|
||||
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 5
|
||||
#if defined(__linux__)
|
||||
#define CS_IDENT_USEBOTARGS "UseBotArgs"
|
||||
#define CS_IDENT_BOTARGS "BotArgs"
|
||||
#define CS_IDENT_HIDDEN_STATE false
|
||||
#elif defined(__APPLE__)
|
||||
#define CS_IDENT_USEBOTARGS "UseBotArgs"
|
||||
#define CS_IDENT_BOTARGS "BotArgs"
|
||||
#define CS_IDENT_HIDDEN_STATE true
|
||||
#else
|
||||
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6
|
||||
#define CS_CLICMD_OFFS_USEBOTARGS 2
|
||||
#define CS_CLICMD_OFFS_BOTARGS 22
|
||||
#define CS_CLICMD_OFFS_USEBOTARGS 2
|
||||
#define CS_CLICMD_OFFS_BOTARGS 22
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CS_OnBuy forward
|
||||
*/
|
||||
#if defined(__linux__)
|
||||
#define CS_IDENT_CANBUYTHIS "_Z10CanBuyThisP11CBasePlayeri"
|
||||
#define CS_IDENT_BUYITEM "_Z7BuyItemP11CBasePlayeri"
|
||||
#define CS_IDENT_BUYGUNAMMO "_Z10BuyGunAmmoR11CBasePlayerR15CBasePlayerItemb"
|
||||
#define CS_IDENT_HIDDEN_STATE false
|
||||
#elif defined(__APPLE__)
|
||||
#define CS_IDENT_CANBUYTHIS "_Z10CanBuyThisP11CBasePlayeri"
|
||||
#define CS_IDENT_BUYITEM "_Z7BuyItemP11CBasePlayeri"
|
||||
#define CS_IDENT_BUYGUNAMMO "_Z10BuyGunAmmoR11CBasePlayerR15CBasePlayerItemb"
|
||||
#define CS_IDENT_HIDDEN_STATE true
|
||||
#elif defined(WIN32)
|
||||
#define CS_IDENT_CANBUYTHIS "\\x53\\x8B\\x2A\\x2A\\x2A\\x2A\\x2A\\x56\\x8B\\x2A\\x2A\\x2A\\x57"
|
||||
#define CS_IDENT_BUYITEM "\\x53\\x56\\x8B\\x2A\\x2A\\x2A\\xBB\\x2A\\x2A\\x2A\\x2A\\x57\\x53"
|
||||
#define CS_IDENT_BUYGUNAMMO "\\x56\\x57\\x8B\\x2A\\x2A\\x2A\\x6A\\x2A\\x8B\\x2A\\xE8\\x2A\\x2A\\x2A\\x2A\\x84\\x2A\\x0F"
|
||||
#define CS_IDENT_HIDDEN_STATE false
|
||||
#endif
|
||||
|
||||
#define CSI_P228 CSW_P228
|
||||
#define CSI_SCOUT CSW_SCOUT
|
||||
#define CSI_HEGRENADE CSW_HEGRENADE
|
||||
#define CSI_XM1014 CSW_XM1014
|
||||
#define CSI_C4 CSW_C4
|
||||
#define CSI_MAC10 CSW_MAC10
|
||||
#define CSI_AUG CSW_AUG
|
||||
#define CSI_SMOKEGRENADE CSW_SMOKEGRENADE
|
||||
#define CSI_ELITE CSW_ELITE
|
||||
#define CSI_FIVESEVEN CSW_FIVESEVEN
|
||||
#define CSI_UMP45 CSW_UMP45
|
||||
#define CSI_SG550 CSW_SG550
|
||||
#define CSI_GALI CSW_GALI
|
||||
#define CSI_FAMAS CSW_FAMAS
|
||||
#define CSI_USP CSW_USP
|
||||
#define CSI_GLOCK18 CSW_GLOCK18
|
||||
#define CSI_AWP CSW_AWP
|
||||
#define CSI_MP5NAVY CSW_MP5NAVY
|
||||
#define CSI_M249 CSW_M249
|
||||
#define CSI_M3 CSW_M3
|
||||
#define CSI_M4A1 CSW_M4A1
|
||||
#define CSI_TMP CSW_TMP
|
||||
#define CSI_G3SG1 CSW_G3SG1
|
||||
#define CSI_FLASHBANG CSW_FLASHBANG
|
||||
#define CSI_DEAGLE CSW_DEAGLE
|
||||
#define CSI_SG552 CSW_SG552
|
||||
#define CSI_AK47 CSW_AK47
|
||||
#define CSI_KNIFE CSW_KNIFE
|
||||
#define CSI_P90 CSW_P90
|
||||
#define CSI_SHIELDGUN CSW_SHIELDGUN
|
||||
#define CSI_VEST CSW_VEST // Custom
|
||||
#define CSI_VESTHELM CSW_VESTHELM // Custom
|
||||
#define CSI_DEFUSER 33 // Custom
|
||||
#define CSI_NVGS 34 // Custom
|
||||
#define CSI_PRIMAMMO 36 // Custom
|
||||
#define CSI_SECAMMO 37 // Custom
|
||||
|
||||
#define BITS_PISTOLS (1<<CSI_GLOCK18 | 1<<CSI_USP | 1<<CSI_P228 | 1<<CSI_DEAGLE | 1<<CSI_ELITE | 1<<CSI_FIVESEVEN)
|
||||
|
||||
// Ids of weapons in CS
|
||||
#define CSW_P228 1
|
||||
//#define CSW_SHIELD 2
|
||||
#define CSW_SCOUT 3
|
||||
#define CSW_HEGRENADE 4
|
||||
#define CSW_XM1014 5
|
||||
@ -200,6 +249,7 @@
|
||||
#define CSW_P90 30
|
||||
#define CSW_VEST 31 // Brand new invention!
|
||||
#define CSW_VESTHELM 32 // Brand new invention!
|
||||
#define CSW_SHIELDGUN 99
|
||||
|
||||
// These are used with armoury_entity:s.
|
||||
#define CSA_MP5NAVY 0
|
||||
@ -270,6 +320,9 @@
|
||||
#define CS_AUGSG552_ZOOM 0x37
|
||||
#define CS_NO_ZOOM 0x5A
|
||||
|
||||
#define HAS_SHIELD (1<<24) //16777216
|
||||
|
||||
|
||||
enum CS_Internal_Models {
|
||||
CS_DONTCHANGE = 0,
|
||||
CS_CT_URBAN = 1,
|
||||
@ -293,57 +346,5 @@ enum
|
||||
CS_SET_SECOND_ZOOM,
|
||||
CS_SET_AUGSG552_ZOOM,
|
||||
};
|
||||
// cstrike-specific defines above
|
||||
|
||||
extern CCstrikePlayer g_players[33];
|
||||
extern int g_zooming[33];
|
||||
extern bool g_precachedknife;
|
||||
extern bool g_noknives;
|
||||
// Globals above
|
||||
|
||||
void InitializeHacks();
|
||||
void ShutdownHacks();
|
||||
|
||||
#define CHECK_ENTITY(x) \
|
||||
if (x < 0 || x > gpGlobals->maxEntities) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \
|
||||
return 0; \
|
||||
} else { \
|
||||
if (x <= gpGlobals->maxClients) { \
|
||||
if (!MF_IsPlayerIngame(x)) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \
|
||||
return 0; \
|
||||
} \
|
||||
} else { \
|
||||
if (x != 0 && FNullEnt(INDEXENT(x))) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \
|
||||
return 0; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_PLAYER(x) \
|
||||
if (x < 1 || x > gpGlobals->maxClients) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \
|
||||
return 0; \
|
||||
} else { \
|
||||
if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_NONPLAYER(x) \
|
||||
if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \
|
||||
return 0; \
|
||||
} else { \
|
||||
if (FNullEnt(INDEXENT(x))) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define GETEDICT(n) \
|
||||
((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))
|
||||
|
||||
#endif // CSTRIKE_DATA_H
|
@ -1,237 +1,219 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "cstrike.h"
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
#include "CstrikeDatas.h"
|
||||
#include "CstrikeUtils.h"
|
||||
#include "CDetour/detours.h"
|
||||
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
#include <sys/mman.h>
|
||||
#define PAGE_EXECUTE_READWRITE PROT_READ|PROT_WRITE|PROT_EXEC
|
||||
|
||||
#if defined(__linux)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <mach-o/nlist.h>
|
||||
#endif
|
||||
|
||||
/* Utils */
|
||||
unsigned char *UTIL_CodeAlloc(size_t size);
|
||||
void UTIL_CodeFree(unsigned char *addr);
|
||||
void UTIL_MemProtect(void *addr, int length, int prot);
|
||||
bool UTIL_GetLibraryOfAddress(void *memInBase, char *buffer, size_t maxlength, uintptr_t *base);
|
||||
|
||||
/* Detours */
|
||||
void CtrlDetour_ClientCommand(bool set);
|
||||
int Detour_ClientCommand(edict_t *pEdict);
|
||||
void CtrlDetours_ClientCommand(bool set);
|
||||
void CtrlDetours_BuyCommands(bool set);
|
||||
|
||||
int g_CSCliCmdFwd = -1;
|
||||
int g_CSBuyCmdFwd = -1;
|
||||
|
||||
int *g_UseBotArgs = NULL;
|
||||
const char **g_BotArgs = NULL;
|
||||
|
||||
/* Called on startup */
|
||||
CDetour *g_ClientCommandDetour = NULL;
|
||||
CDetour *g_CanBuyThisDetour = NULL;
|
||||
CDetour *g_BuyItemDetour = NULL;
|
||||
CDetour *g_BuyGunAmmoDetour = NULL;
|
||||
|
||||
|
||||
void InitializeHacks()
|
||||
{
|
||||
CtrlDetour_ClientCommand(true);
|
||||
}
|
||||
#if defined AMD64
|
||||
#error UNSUPPORTED
|
||||
#endif
|
||||
|
||||
void OnPluginsLoaded()
|
||||
{
|
||||
g_CSCliCmdFwd = MF_RegisterForward("CS_InternalCommand", ET_STOP, FP_CELL, FP_STRING, FP_DONE);
|
||||
CtrlDetours_ClientCommand(true);
|
||||
CtrlDetours_BuyCommands(true);
|
||||
}
|
||||
|
||||
void ShutdownHacks()
|
||||
{
|
||||
CtrlDetour_ClientCommand(false);
|
||||
CtrlDetours_ClientCommand(false);
|
||||
CtrlDetours_BuyCommands(false);
|
||||
}
|
||||
|
||||
void CtrlDetour_ClientCommand(bool set)
|
||||
{
|
||||
#if defined AMD64
|
||||
#error UNSUPPORTED
|
||||
#endif
|
||||
static unsigned char DetourOps[] =
|
||||
{
|
||||
0x50, /* push eax ; just for safety */
|
||||
0xff, 0x74, 0x24, 0x08, /* push [esp+0x8] ; push the edict pointer */
|
||||
0xe8, 0x00, 0x00, 0x00, 0x00, /* call <gate> ; call our function */
|
||||
0x83, 0xc4, 0x08, /* add esp, 8 ; correct stack */
|
||||
0x85, 0xc0, /* test eax, eax ; do != 0 test */
|
||||
0x74, 0x01, /* je <cont> ; if == 0, jump to where old func is saved */
|
||||
0xc3 /* ret ; return otherwise */
|
||||
};
|
||||
static unsigned char DetourJmp = '\xE9';
|
||||
|
||||
const unsigned int DetourBytes = 18;
|
||||
const unsigned int DetourCallPos = 6;
|
||||
const unsigned int DetourJmpPos = DetourBytes + CS_DETOURCOPYBYTES_CLIENTCOMMAND;
|
||||
const unsigned int DetourJmpBytes = 5;
|
||||
static unsigned char *FullDetour = NULL;
|
||||
|
||||
void *target = (void *)MDLL_ClientCommand;
|
||||
unsigned char *paddr;
|
||||
|
||||
if (!g_UseBotArgs)
|
||||
{
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
/* Find the DLL */
|
||||
char dll[256];
|
||||
uintptr_t base;
|
||||
if (!UTIL_GetLibraryOfAddress(target, dll, sizeof(dll), &base))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if defined(__linux__)
|
||||
void *handle = dlopen(dll, RTLD_NOW);
|
||||
if (!handle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_UseBotArgs = (int *)dlsym(handle, "UseBotArgs");
|
||||
g_BotArgs = (const char **)dlsym(handle, "BotArgs");
|
||||
dlclose(handle);
|
||||
#elif defined(__APPLE__)
|
||||
/* Using dlsym on OS X won't work because the symbols are hidden */
|
||||
struct nlist symbols[3];
|
||||
memset(symbols, 0, sizeof(symbols));
|
||||
symbols[0].n_un.n_name = (char *)"_UseBotArgs";
|
||||
symbols[1].n_un.n_name = (char *)"_BotArgs";
|
||||
if (nlist(dll, symbols) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_UseBotArgs = (int *)(base + symbols[0].n_value);
|
||||
g_BotArgs = (const char **)(base + symbols[1].n_value);
|
||||
#endif
|
||||
#else /* Windows */
|
||||
/* Find the bot args addresses */
|
||||
paddr = (unsigned char *)target + CS_CLICMD_OFFS_USEBOTARGS;
|
||||
g_UseBotArgs = *(int **)paddr;
|
||||
paddr = (unsigned char *)target + CS_CLICMD_OFFS_BOTARGS;
|
||||
g_BotArgs = (const char **)*(const char **)paddr;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (set)
|
||||
{
|
||||
assert(FullDetour == NULL);
|
||||
FullDetour = UTIL_CodeAlloc(DetourBytes + CS_DETOURCOPYBYTES_CLIENTCOMMAND + DetourJmpBytes);
|
||||
|
||||
/* Copy the main trampoline function */
|
||||
memcpy(FullDetour, DetourOps, DetourBytes);
|
||||
|
||||
/* Copy our detour call into the trampoline */
|
||||
paddr = &FullDetour[DetourCallPos];
|
||||
*(unsigned long *)paddr = (unsigned long)Detour_ClientCommand - (unsigned long)(paddr + 4);
|
||||
|
||||
/* Copy original bytes onto the end of the function */
|
||||
memcpy(&FullDetour[DetourBytes], target, CS_DETOURCOPYBYTES_CLIENTCOMMAND);
|
||||
|
||||
/* Patch and copy the final jmp */
|
||||
paddr = &FullDetour[DetourJmpPos];
|
||||
*paddr++ = DetourJmp;
|
||||
*(unsigned long *)paddr = ((unsigned long)target + CS_DETOURCOPYBYTES_CLIENTCOMMAND)
|
||||
- (unsigned long)(paddr + 4);
|
||||
|
||||
/* Now overwrite the target function with our trampoline */
|
||||
UTIL_MemProtect(target, CS_DETOURCOPYBYTES_CLIENTCOMMAND + 10, PAGE_EXECUTE_READWRITE);
|
||||
paddr = (unsigned char *)target;
|
||||
*paddr++ = DetourJmp;
|
||||
*(unsigned long *)paddr = (unsigned long)FullDetour - (unsigned long)(paddr + 4);
|
||||
} else {
|
||||
assert(FullDetour != NULL);
|
||||
|
||||
/* Copy back the original function bytes */
|
||||
memcpy(target, &FullDetour[DetourBytes], CS_DETOURCOPYBYTES_CLIENTCOMMAND);
|
||||
|
||||
/* Free memory used */
|
||||
UTIL_CodeFree(FullDetour);
|
||||
FullDetour = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int Detour_ClientCommand(edict_t *pEdict)
|
||||
DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity)
|
||||
{
|
||||
if (*g_UseBotArgs)
|
||||
{
|
||||
int client = ENTINDEX(pEdict);
|
||||
const char *args = *g_BotArgs;
|
||||
return MF_ExecuteForward(g_CSCliCmdFwd, (cell)client, args);
|
||||
|
||||
if (MF_ExecuteForward(g_CSCliCmdFwd, static_cast<cell>(client), args) > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
DETOUR_STATIC_CALL(C_ClientCommand)(pEdict);
|
||||
}
|
||||
|
||||
unsigned char *UTIL_CodeAlloc(size_t size)
|
||||
DETOUR_DECL_STATIC2(CanBuyThis, bool, void*, pvPlayer, int, weaponId) // bool CanBuyThis(CBasePlayer *pPlayer, int weaponId)
|
||||
{
|
||||
#if defined WIN32
|
||||
return (unsigned char *)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
#elif defined __GNUC__
|
||||
#if defined __APPLE__
|
||||
unsigned char *addr = (unsigned char *)valloc(size);
|
||||
#else
|
||||
unsigned char *addr = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), size);
|
||||
#endif
|
||||
mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
|
||||
return addr;
|
||||
#endif
|
||||
if (weaponId != CSI_SHIELDGUN) // This will be handled before with BuyItem. Avoiding duplicated call.
|
||||
{
|
||||
int player = PrivateToIndex(pvPlayer);
|
||||
|
||||
if (MF_IsPlayerAlive(player) && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast<cell>(player), static_cast<cell>(weaponId)) > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return DETOUR_STATIC_CALL(CanBuyThis)(pvPlayer, weaponId);
|
||||
}
|
||||
|
||||
void UTIL_CodeFree(unsigned char *addr)
|
||||
DETOUR_DECL_STATIC2(BuyItem, void, void*, pvPlayer, int, iSlot) // void BuyItem(CBasePlayer *pPlayer, int iSlot)
|
||||
{
|
||||
#if defined WIN32
|
||||
VirtualFree(addr, 0, MEM_RELEASE);
|
||||
#else
|
||||
free(addr);
|
||||
#endif
|
||||
int player = PrivateToIndex(pvPlayer);
|
||||
|
||||
if (MF_IsPlayerAlive(player))
|
||||
{
|
||||
static const int itemSlotToWeaponId[] = {-1, CSI_VEST, CSI_VESTHELM, CSI_FLASHBANG, CSI_HEGRENADE, CSI_SMOKEGRENADE, CSI_NVGS, CSI_DEFUSER, CSI_SHIELDGUN};
|
||||
|
||||
if (iSlot >= 1 && iSlot <= 8 && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast<cell>(player), static_cast<cell>(itemSlotToWeaponId[iSlot])) > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DETOUR_STATIC_CALL(BuyItem)(pvPlayer, iSlot);
|
||||
}
|
||||
|
||||
void UTIL_MemProtect(void *addr, int length, int prot)
|
||||
DETOUR_DECL_STATIC3(BuyGunAmmo, bool, void*, pvPlayer, void*, pvWeapon, bool, bBlinkMoney) // bool BuyGunAmmo(CBasePlayer *player, CBasePlayerItem *weapon, bool bBlinkMoney)
|
||||
{
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
#define ALIGN(ar) ((long)ar & ~(sysconf(_SC_PAGESIZE)-1))
|
||||
void *addr2 = (void *)ALIGN(addr);
|
||||
mprotect(addr2, sysconf(_SC_PAGESIZE), prot);
|
||||
#else
|
||||
DWORD old_prot;
|
||||
VirtualProtect(addr, length, prot, &old_prot);
|
||||
#endif
|
||||
int player = PrivateToIndex(pvPlayer);
|
||||
|
||||
if (MF_IsPlayerAlive(player))
|
||||
{
|
||||
edict_t *pWeapon = PrivateToEdict(pvWeapon);
|
||||
|
||||
if (pWeapon)
|
||||
{
|
||||
int weaponId = *((int *)pWeapon->pvPrivateData + OFFSET_WEAPONTYPE);
|
||||
int ammoId = (1<<weaponId & BITS_PISTOLS) ? CSI_SECAMMO : CSI_PRIMAMMO;
|
||||
|
||||
if (MF_ExecuteForward(g_CSBuyCmdFwd, static_cast<cell>(player), static_cast<cell>(ammoId)) > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DETOUR_STATIC_CALL(BuyGunAmmo)(pvPlayer, pvWeapon, bBlinkMoney);
|
||||
}
|
||||
|
||||
bool UTIL_GetLibraryOfAddress(void *memInBase, char *buffer, size_t maxlength, uintptr_t *base)
|
||||
|
||||
void CtrlDetours_ClientCommand(bool set)
|
||||
{
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
Dl_info info;
|
||||
if (!dladdr(memInBase, &info))
|
||||
if (set)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!info.dli_fbase || !info.dli_fname)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const char *dllpath = info.dli_fname;
|
||||
snprintf(buffer, maxlength, "%s", dllpath);
|
||||
if (base)
|
||||
{
|
||||
*base = (uintptr_t)info.dli_fbase;
|
||||
}
|
||||
#else
|
||||
MEMORY_BASIC_INFORMATION mem;
|
||||
if (!VirtualQuery(memInBase, &mem, sizeof(mem)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mem.AllocationBase == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
HMODULE dll = (HMODULE)mem.AllocationBase;
|
||||
GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
|
||||
if (base)
|
||||
{
|
||||
*base = (uintptr_t)mem.AllocationBase;
|
||||
}
|
||||
void *target = (void *)MDLL_ClientCommand;
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
g_UseBotArgs = *(int **)((unsigned char *)target + CS_CLICMD_OFFS_USEBOTARGS);
|
||||
g_BotArgs = (const char **)*(const char **)((unsigned char *)target + CS_CLICMD_OFFS_BOTARGS);
|
||||
|
||||
#elif defined(__linux__) || defined(__APPLE__)
|
||||
|
||||
g_UseBotArgs = (int *)UTIL_FindAddressFromEntry(CS_IDENT_USEBOTARGS, CS_IDENT_HIDDEN_STATE);
|
||||
g_BotArgs = (const char **)UTIL_FindAddressFromEntry(CS_IDENT_BOTARGS, CS_IDENT_HIDDEN_STATE);
|
||||
|
||||
#endif
|
||||
return true;
|
||||
g_ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target);
|
||||
|
||||
if (g_ClientCommandDetour == NULL)
|
||||
{
|
||||
MF_Log("No Client Commands detour could be initialized - Disabled Client Command forward.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_ClientCommandDetour)
|
||||
g_ClientCommandDetour->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleDetour_ClientCommands(bool enable)
|
||||
{
|
||||
if (g_ClientCommandDetour)
|
||||
(enable) ? g_ClientCommandDetour->EnableDetour() : g_ClientCommandDetour->DisableDetour();
|
||||
}
|
||||
|
||||
|
||||
void CtrlDetours_BuyCommands(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
void *canBuyThisAddress = UTIL_FindAddressFromEntry(CS_IDENT_CANBUYTHIS, CS_IDENT_HIDDEN_STATE);
|
||||
void *buyItemAddress = UTIL_FindAddressFromEntry(CS_IDENT_BUYITEM, CS_IDENT_HIDDEN_STATE);
|
||||
void *buyGunAmmoAddress = UTIL_FindAddressFromEntry(CS_IDENT_BUYGUNAMMO, CS_IDENT_HIDDEN_STATE);
|
||||
|
||||
g_CanBuyThisDetour = DETOUR_CREATE_STATIC_FIXED(CanBuyThis, canBuyThisAddress);
|
||||
g_BuyItemDetour = DETOUR_CREATE_STATIC_FIXED(BuyItem, buyItemAddress);
|
||||
g_BuyGunAmmoDetour = DETOUR_CREATE_STATIC_FIXED(BuyGunAmmo, buyGunAmmoAddress);
|
||||
|
||||
if (g_CanBuyThisDetour == NULL || g_BuyItemDetour == NULL || g_BuyGunAmmoDetour == NULL)
|
||||
{
|
||||
MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_CanBuyThisDetour)
|
||||
g_CanBuyThisDetour->Destroy();
|
||||
|
||||
if (g_BuyItemDetour)
|
||||
g_BuyItemDetour->Destroy();
|
||||
|
||||
if (g_BuyGunAmmoDetour)
|
||||
g_BuyGunAmmoDetour->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleDetour_BuyCommands(bool enable)
|
||||
{
|
||||
if (g_CanBuyThisDetour)
|
||||
(enable) ? g_CanBuyThisDetour->EnableDetour() : g_CanBuyThisDetour->DisableDetour();
|
||||
|
||||
if (g_BuyItemDetour)
|
||||
(enable) ? g_BuyItemDetour->EnableDetour() : g_BuyItemDetour->DisableDetour();
|
||||
|
||||
if (g_BuyGunAmmoDetour)
|
||||
(enable) ? g_BuyGunAmmoDetour->EnableDetour() : g_BuyGunAmmoDetour->DisableDetour();
|
||||
}
|
126
dlls/cstrike/cstrike/cstrike.cpp → dlls/cstrike/cstrike/CstrikeNatives.cpp
Executable file → Normal file
126
dlls/cstrike/cstrike/cstrike.cpp → dlls/cstrike/cstrike/CstrikeNatives.cpp
Executable file → Normal file
@ -1,72 +1,44 @@
|
||||
#include "cstrike.h"
|
||||
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
#include "CstrikeDatas.h"
|
||||
#include "CstrikePlayer.h"
|
||||
#include "CstrikeUtils.h"
|
||||
|
||||
CCstrikePlayer g_players[33];
|
||||
int g_zooming[33] = {0};
|
||||
bool g_precachedknife = false;
|
||||
bool g_noknives = false;
|
||||
|
||||
// Utils first
|
||||
|
||||
bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer) {
|
||||
bool player = false;
|
||||
|
||||
if (strcmp(STRING(pPlayer->v.classname), "player") == 0)
|
||||
player = true;
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message)
|
||||
{
|
||||
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pPlayer);
|
||||
WRITE_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center
|
||||
WRITE_STRING(message);
|
||||
MESSAGE_END();
|
||||
/*
|
||||
The byte above seems to use these:
|
||||
#define HUD_PRINTNOTIFY 1
|
||||
#define HUD_PRINTCONSOLE 2
|
||||
#define HUD_PRINTTALK 3
|
||||
#define HUD_PRINTCENTER 4
|
||||
However both 1 and 2 seems to go to console with Steam CS.
|
||||
*/
|
||||
}
|
||||
|
||||
// Then natives
|
||||
|
||||
static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) // cs_set_user_money(index, money, flash = 1); = 3 arguments
|
||||
{
|
||||
// Give money to user
|
||||
@ -1339,8 +1311,8 @@ static cell AMX_NATIVE_CALL cs_user_spawn(AMX *amx, cell *params)
|
||||
MDLL_Think(pPlayer);
|
||||
|
||||
const char *auth = GETPLAYERAUTHID(pPlayer);
|
||||
if (((pPlayer->v.flags & FL_FAKECLIENT) == FL_FAKECLIENT || (auth && (strcmp(auth, "BOT") == 0))) && pPlayer->v.deadflag == DEAD_RESPAWNABLE) {
|
||||
MDLL_Spawn(pPlayer);
|
||||
if (((pPlayer->v.flags & FL_FAKECLIENT) == FL_FAKECLIENT || (auth && (strcmp(auth, "BOT") == 0))) && pPlayer->v.deadflag == DEAD_RESPAWNABLE) {
|
||||
MDLL_Spawn(pPlayer);
|
||||
}
|
||||
|
||||
// pPlayer->v.iuser1 = 0;
|
||||
@ -1777,7 +1749,7 @@ static cell AMX_NATIVE_CALL not_on_64(AMX* amx, cell* params)
|
||||
#endif
|
||||
|
||||
|
||||
AMX_NATIVE_INFO cstrike_Exports[] = {
|
||||
AMX_NATIVE_INFO cstrikeNatives[] = {
|
||||
{"cs_set_user_money", cs_set_user_money},
|
||||
{"cs_get_user_money", cs_get_user_money},
|
||||
{"cs_get_user_deaths", cs_get_user_deaths},
|
||||
@ -1918,24 +1890,4 @@ void PlayerPreThink(edict_t *pPlayer)
|
||||
}
|
||||
|
||||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
int AmxxCheckGame(const char *game)
|
||||
{
|
||||
if (strcasecmp(game, "cstrike") == 0 ||
|
||||
strcasecmp(game, "czero") == 0)
|
||||
{
|
||||
return AMXX_GAME_OK;
|
||||
}
|
||||
return AMXX_GAME_BAD;
|
||||
}
|
||||
void OnAmxxAttach()
|
||||
{
|
||||
MF_AddNatives(cstrike_Exports);
|
||||
InitializeHacks();
|
||||
}
|
||||
|
||||
void OnAmxxDetach()
|
||||
{
|
||||
ShutdownHacks();
|
||||
}
|
||||
}
|
142
dlls/cstrike/cstrike/CstrikeUtils.cpp
Normal file
142
dlls/cstrike/cstrike/CstrikeUtils.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
#include "amxxmodule.h"
|
||||
#include "MemoryUtils.h"
|
||||
|
||||
bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer)
|
||||
{
|
||||
bool player = false;
|
||||
|
||||
if (strcmp(STRING(pPlayer->v.classname), "player") == 0)
|
||||
{
|
||||
player = true;
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message)
|
||||
{
|
||||
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pPlayer);
|
||||
WRITE_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center, 5 = radio
|
||||
WRITE_STRING(message);
|
||||
MESSAGE_END();
|
||||
/*
|
||||
The byte above seems to use these:
|
||||
#define HUD_PRINTNOTIFY 1
|
||||
#define HUD_PRINTCONSOLE 2
|
||||
#define HUD_PRINTTALK 3
|
||||
#define HUD_PRINTCENTER 4
|
||||
#define HUD_PRINTRADIO 5
|
||||
However both 1 and 2 seems to go to console with Steam CS.
|
||||
*/
|
||||
}
|
||||
|
||||
void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden, const char *library)
|
||||
{
|
||||
void *addressInBase = NULL;
|
||||
void *finalAddress;
|
||||
|
||||
if (strcmp(library, "mod") == 0)
|
||||
{
|
||||
addressInBase = (void *)MDLL_Spawn;
|
||||
}
|
||||
else if (strcmp(library, "engine") == 0)
|
||||
{
|
||||
addressInBase = (void *)gpGlobals;
|
||||
}
|
||||
|
||||
finalAddress = NULL;
|
||||
|
||||
if (*entry != '\\')
|
||||
{
|
||||
#if defined(WIN32)
|
||||
|
||||
MEMORY_BASIC_INFORMATION mem;
|
||||
|
||||
if (VirtualQuery(addressInBase, &mem, sizeof(mem)))
|
||||
{
|
||||
finalAddress = g_MemUtils.ResolveSymbol(mem.AllocationBase, entry);
|
||||
}
|
||||
|
||||
#elif defined(__linux__) || defined(__APPLE__)
|
||||
|
||||
Dl_info info;
|
||||
void *handle = NULL;
|
||||
|
||||
if (dladdr(addressInBase, &info) != 0)
|
||||
{
|
||||
void *handle = dlopen(info.dli_fname, RTLD_NOW);
|
||||
if (handle)
|
||||
{
|
||||
if (isHidden)
|
||||
{
|
||||
finalAddress = g_MemUtils.ResolveSymbol(handle, entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
finalAddress = dlsym(handle, entry);
|
||||
}
|
||||
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
finalAddress = g_MemUtils.DecodeAndFindPattern(addressInBase, entry);
|
||||
}
|
||||
|
||||
return finalAddress != NULL ? finalAddress : NULL;
|
||||
}
|
||||
|
||||
bool UTIL_CheckForPublic(const char *publicname)
|
||||
{
|
||||
AMX* amx;
|
||||
int iFunctionIndex;
|
||||
int i = 0;
|
||||
char blah[64];
|
||||
|
||||
strncpy(blah, publicname, sizeof(blah)- 1);
|
||||
|
||||
while ((amx = MF_GetScriptAmx(i++)) != NULL)
|
||||
{
|
||||
if (MF_AmxFindPublic(amx, blah, &iFunctionIndex) == AMX_ERR_NONE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
121
dlls/cstrike/cstrike/CstrikeUtils.h
Normal file
121
dlls/cstrike/cstrike/CstrikeUtils.h
Normal file
@ -0,0 +1,121 @@
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
#ifndef CSTRIKE_UTILS_H
|
||||
#define CSTRIKE_UTILS_H
|
||||
|
||||
bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer);
|
||||
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message);
|
||||
void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden = false, const char *library = "mod");
|
||||
bool UTIL_CheckForPublic(const char *publicname);
|
||||
|
||||
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
|
||||
#define GETCLIENTKEYVALUE (*g_engfuncs.pfnInfoKeyValue)
|
||||
#define CREATENAMEDENTITY (*g_engfuncs.pfnCreateNamedEntity)
|
||||
|
||||
#define CHECK_ENTITY(x) \
|
||||
if (x < 0 || x > gpGlobals->maxEntities) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \
|
||||
return 0; \
|
||||
} else { \
|
||||
if (x <= gpGlobals->maxClients) { \
|
||||
if (!MF_IsPlayerIngame(x)) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \
|
||||
return 0; \
|
||||
} \
|
||||
} else { \
|
||||
if (x != 0 && FNullEnt(INDEXENT(x))) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \
|
||||
return 0; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_PLAYER(x) \
|
||||
if (x < 1 || x > gpGlobals->maxClients) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \
|
||||
return 0; \
|
||||
} else { \
|
||||
if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_NONPLAYER(x) \
|
||||
if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \
|
||||
return 0; \
|
||||
} else { \
|
||||
if (FNullEnt(INDEXENT(x))) { \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define GETEDICT(n) \
|
||||
((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))
|
||||
|
||||
|
||||
inline edict_t *PrivateToEdict(const void *pdata)
|
||||
{
|
||||
if (!pdata)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *ptr = (char*)pdata;
|
||||
ptr += 4;
|
||||
entvars_t *pev = *(entvars_t **)ptr;
|
||||
|
||||
if (!pev)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pev->pContainingEntity;
|
||||
};
|
||||
|
||||
inline int PrivateToIndex(const void *pdata)
|
||||
{
|
||||
edict_t *pEntity = PrivateToEdict(pdata);
|
||||
|
||||
if (!pEntity)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ENTINDEX(pEntity);
|
||||
};
|
||||
|
||||
#endif // CSTRIKE_UTILS_H
|
@ -14,7 +14,10 @@ MM_ROOT = ../../../../metamod/metamod
|
||||
|
||||
PROJECT = cstrike
|
||||
|
||||
OBJECTS = sdk/amxxmodule.cpp CstrikePlayer.cpp cstrike.cpp CstrikeHacks.cpp
|
||||
OBJECTS = sdk/amxxmodule.cpp amxx_api.cpp CstrikePlayer.cpp CstrikeNatives.cpp CstrikeHacks.cpp CstrikeUtils.cpp \
|
||||
../../../public/memtools/MemoryUtils.cpp \
|
||||
../../../public/memtools/CDetour/detours.cpp \
|
||||
../../../public/memtools/CDetour/asm/asm.c
|
||||
|
||||
##############################################
|
||||
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
|
||||
@ -29,7 +32,7 @@ CPP_OSX = clang
|
||||
|
||||
LINK =
|
||||
|
||||
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
|
||||
INCLUDE = -I. -I../../../public -I../../../public/amtl -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
|
||||
-I$(HLSDK)/public -I$(MM_ROOT) -Isdk
|
||||
|
||||
################################################
|
||||
|
75
dlls/cstrike/cstrike/amxx_api.cpp
Normal file
75
dlls/cstrike/cstrike/amxx_api.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/* AMX Mod X
|
||||
* Counter-Strike Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
#include "amxxmodule.h"
|
||||
#include "CstrikeUtils.h"
|
||||
|
||||
extern AMX_NATIVE_INFO cstrikeNatives[];
|
||||
|
||||
extern int g_CSCliCmdFwd;
|
||||
extern int g_CSBuyCmdFwd;
|
||||
|
||||
void InitializeHacks();
|
||||
void ShutdownHacks();
|
||||
void ToggleDetour_ClientCommands(bool enable);
|
||||
void ToggleDetour_BuyCommands(bool enable);
|
||||
|
||||
|
||||
int AmxxCheckGame(const char *game)
|
||||
{
|
||||
if (strcasecmp(game, "cstrike") == 0 ||
|
||||
strcasecmp(game, "czero") == 0)
|
||||
{
|
||||
return AMXX_GAME_OK;
|
||||
}
|
||||
return AMXX_GAME_BAD;
|
||||
}
|
||||
|
||||
void OnAmxxAttach()
|
||||
{
|
||||
MF_AddNatives(cstrikeNatives);
|
||||
InitializeHacks();
|
||||
}
|
||||
|
||||
void OnPluginsLoaded()
|
||||
{
|
||||
g_CSCliCmdFwd = MF_RegisterForward("CS_InternalCommand", ET_STOP, FP_CELL, FP_STRING, FP_DONE);
|
||||
g_CSBuyCmdFwd = MF_RegisterForward("CS_OnBuy", ET_STOP, FP_CELL, FP_CELL, FP_DONE);
|
||||
|
||||
ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand"));
|
||||
ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy"));
|
||||
}
|
||||
|
||||
void OnAmxxDetach()
|
||||
{
|
||||
ShutdownHacks();
|
||||
}
|
@ -62,7 +62,7 @@
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\..\..\public; ..\..\..\..\public\amtl;..\..\..\..\public\memtools;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CSTRIKE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -105,7 +105,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<AdditionalIncludeDirectories>..\;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\..\..\public; ..\..\..\..\public\amtl;..\..\..\..\public\memtools;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CSTRIKE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
@ -135,20 +135,29 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\cstrike.cpp" />
|
||||
<ClCompile Include="..\..\..\..\public\memtools\CDetour\asm\asm.c" />
|
||||
<ClCompile Include="..\..\..\..\public\memtools\CDetour\detours.cpp" />
|
||||
<ClCompile Include="..\..\..\..\public\memtools\MemoryUtils.cpp" />
|
||||
<ClCompile Include="..\amxx_api.cpp" />
|
||||
<ClCompile Include="..\CstrikeHacks.cpp" />
|
||||
<ClCompile Include="..\CstrikeNatives.cpp" />
|
||||
<ClCompile Include="..\CstrikePlayer.cpp" />
|
||||
<ClCompile Include="..\CstrikeUtils.cpp" />
|
||||
<ClCompile Include="..\sdk\amxxmodule.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\cstrike.h" />
|
||||
<ClInclude Include="..\..\..\..\public\memtools\CDetour\asm\asm.h" />
|
||||
<ClInclude Include="..\..\..\..\public\memtools\CDetour\detourhelpers.h" />
|
||||
<ClInclude Include="..\..\..\..\public\memtools\CDetour\detours.h" />
|
||||
<ClInclude Include="..\..\..\..\public\memtools\MemoryUtils.h" />
|
||||
<ClInclude Include="..\CstrikeDatas.h" />
|
||||
<ClInclude Include="..\CstrikePlayer.h" />
|
||||
<ClInclude Include="..\svn_version.h" />
|
||||
<ClInclude Include="..\sdk\moduleconfig.h" />
|
||||
<ClInclude Include="..\sdk\amxxmodule.h" />
|
||||
<ClInclude Include="..\CstrikeUtils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\plugins\include\cstrike.inc" />
|
||||
<None Include="..\..\..\..\plugins\include\cstrike.inc" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -18,11 +18,17 @@
|
||||
<Filter Include="Pawn Includes">
|
||||
<UniqueIdentifier>{7be12e0f-47b1-4d7e-880c-83e5d1c378d1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools">
|
||||
<UniqueIdentifier>{bbcd1d67-4670-423d-912f-695737e76bad}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools\CDetour">
|
||||
<UniqueIdentifier>{074d4da1-d1be-40ba-8417-1fc388d85568}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools\CDetour\asm">
|
||||
<UniqueIdentifier>{4f3c4a13-065a-49b1-83a1-f646a3ec3678}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\cstrike.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\CstrikeHacks.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -32,26 +38,56 @@
|
||||
<ClCompile Include="..\sdk\amxxmodule.cpp">
|
||||
<Filter>Module SDK\SDK Base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\amxx_api.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\public\memtools\MemoryUtils.cpp">
|
||||
<Filter>Memtools</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\public\memtools\CDetour\detours.cpp">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\public\memtools\CDetour\asm\asm.c">
|
||||
<Filter>Memtools\CDetour\asm</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\CstrikeNatives.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\CstrikeUtils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\cstrike.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\CstrikePlayer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\svn_version.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\sdk\moduleconfig.h">
|
||||
<Filter>Module SDK</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\sdk\amxxmodule.h">
|
||||
<Filter>Module SDK\SDK Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\CstrikeDatas.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\public\memtools\MemoryUtils.h">
|
||||
<Filter>Memtools</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\public\memtools\CDetour\detourhelpers.h">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\public\memtools\CDetour\detours.h">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\public\memtools\CDetour\asm\asm.h">
|
||||
<Filter>Memtools\CDetour\asm</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\CstrikeUtils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\plugins\include\cstrike.inc">
|
||||
<None Include="..\..\..\..\plugins\include\cstrike.inc">
|
||||
<Filter>Pawn Includes</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
Reference in New Issue
Block a user