Cstrike: Move all hardcoded datas to its own gamedata files
This commit is contained in:
@ -16,153 +16,6 @@
|
||||
|
||||
#include "amxxmodule.h"
|
||||
|
||||
#if defined(__linux__) || defined (__APPLE__)
|
||||
#define EXTRAOFFSET 5 // offsets 5 higher in Linux builds
|
||||
#define EXTRAOFFSET_WEAPONS 4 // weapon offsets are obviously only 4 steps higher on Linux!
|
||||
#define ACTUAL_EXTRA_OFFSET 20 // actual, byte-addressable offset
|
||||
#else
|
||||
#define EXTRAOFFSET 0 // no change in Windows builds
|
||||
#define EXTRAOFFSET_WEAPONS 0
|
||||
#define ACTUAL_EXTRA_OFFSET 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
Offset history:
|
||||
041029:
|
||||
Confirmed (pretty much) ALL offsets for 32 bit Windows, 32 bit Linux and amd64 (yes that's all of them).
|
||||
Found out that weapon offsets are only +4 higher on Linux.
|
||||
Also backpack ammo offsets were all obviously 5 steps too high since unknown time...
|
||||
|
||||
*/
|
||||
// "player" entities
|
||||
#if !defined __amd64__
|
||||
// 32 bit offsets here
|
||||
#define OFFSET_ARMORTYPE 112 + EXTRAOFFSET
|
||||
#define OFFSET_TEAM 114 + EXTRAOFFSET
|
||||
#define OFFSET_CSMONEY 115 + EXTRAOFFSET
|
||||
#define OFFSET_PRIMARYWEAPON 116 + EXTRAOFFSET
|
||||
#define OFFSET_LASTACTIVITY 124 + EXTRAOFFSET
|
||||
#define OFFSET_INTERNALMODEL 126 + EXTRAOFFSET
|
||||
#define OFFSET_NVGOGGLES 129 + EXTRAOFFSET
|
||||
#define OFFSET_DEFUSE_PLANT 193 + EXTRAOFFSET
|
||||
#define OFFSET_MENU 205 + EXTRAOFFSET
|
||||
#define OFFSET_VIP 209 + EXTRAOFFSET
|
||||
#define OFFSET_TK 216 + EXTRAOFFSET // 040926
|
||||
#define OFFSET_HOSTAGEKILLS 217 + EXTRAOFFSET
|
||||
#define OFFSET_MAPZONE 235 + EXTRAOFFSET
|
||||
#define OFFSET_ISDRIVING 350 + EXTRAOFFSET // 040926
|
||||
#define OFFSET_STATIONARY 362 + EXTRAOFFSET // 040927 (363 works also!)
|
||||
#define OFFSET_ZOOMTYPE 363 + EXTRAOFFSET
|
||||
|
||||
#define OFFSET_AWM_AMMO 377 + EXTRAOFFSET // 041029: All of these *_AMMO:s were changed -5
|
||||
#define OFFSET_SCOUT_AMMO 378 + EXTRAOFFSET
|
||||
#define OFFSET_PARA_AMMO 379 + EXTRAOFFSET
|
||||
#define OFFSET_FAMAS_AMMO 380 + EXTRAOFFSET
|
||||
#define OFFSET_M3_AMMO 381 + EXTRAOFFSET
|
||||
#define OFFSET_USP_AMMO 382 + EXTRAOFFSET
|
||||
#define OFFSET_FIVESEVEN_AMMO 383 + EXTRAOFFSET
|
||||
#define OFFSET_DEAGLE_AMMO 384 + EXTRAOFFSET
|
||||
#define OFFSET_P228_AMMO 385 + EXTRAOFFSET
|
||||
#define OFFSET_GLOCK_AMMO 386 + EXTRAOFFSET
|
||||
#define OFFSET_FLASH_AMMO 387 + EXTRAOFFSET
|
||||
#define OFFSET_HE_AMMO 388 + EXTRAOFFSET
|
||||
#define OFFSET_SMOKE_AMMO 389 + EXTRAOFFSET
|
||||
#define OFFSET_C4_AMMO 390 + EXTRAOFFSET
|
||||
|
||||
#define OFFSET_CSDEATHS 444 + EXTRAOFFSET // 040926
|
||||
#define OFFSET_SHIELD 510 + EXTRAOFFSET
|
||||
// "weapon_*" entities
|
||||
#define OFFSET_WEAPONTYPE 43 + EXTRAOFFSET_WEAPONS
|
||||
#define OFFSET_CLIPAMMO 51 + EXTRAOFFSET_WEAPONS
|
||||
#define OFFSET_SILENCER_FIREMODE 74 + EXTRAOFFSET_WEAPONS
|
||||
// "hostage_entity" entities
|
||||
#define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET
|
||||
#define OFFSET_HOSTAGE_NEXTUSE 100 + EXTRAOFFSET
|
||||
#define OFFSET_HOSTAGE_LASTUSE 483 + EXTRAOFFSET
|
||||
#define OFFSET_HOSTAGEID 487 + EXTRAOFFSET
|
||||
// "armoury_entity"
|
||||
#define OFFSET_ARMOURY_TYPE 34 + EXTRAOFFSET_WEAPONS
|
||||
// C4 offsets
|
||||
#define OFFSET_C4_EXPLODE_TIME 100 + EXTRAOFFSET
|
||||
#define OFFSET_C4_DEFUSING 0x181 + ACTUAL_EXTRA_OFFSET
|
||||
#else
|
||||
// Amd64 offsets here
|
||||
#define OFFSET_ARMORTYPE 137 + EXTRAOFFSET
|
||||
#define OFFSET_TEAM 139 + EXTRAOFFSET // +25
|
||||
#define OFFSET_CSMONEY 140 + EXTRAOFFSET // +25
|
||||
#define OFFSET_PRIMARYWEAPON 141 + EXTRAOFFSET // +25
|
||||
#define OFFSET_INTERNALMODEL 152 + EXTRAOFFSET // +26
|
||||
#define OFFSET_NVGOGGLES 155 + EXTRAOFFSET // +26
|
||||
#define OFFSET_DEFUSE_PLANT 219 + EXTRAOFFSET // +26
|
||||
#define OFFSET_VIP 242 + EXTRAOFFSET // +27
|
||||
#define OFFSET_TK 249 + EXTRAOFFSET // +33 040927
|
||||
#define OFFSET_MAPZONE 268 + EXTRAOFFSET // +27
|
||||
#define OFFSET_ISDRIVING 386 + EXTRAOFFSET // 040927
|
||||
#define OFFSET_STATIONARY 400 + EXTRAOFFSET // 040927 (401 works also)
|
||||
#define OFFSET_ZOOMTYPE 402 + EXTRAOFFSET
|
||||
|
||||
#define OFFSET_AWM_AMMO 426 + EXTRAOFFSET // +44
|
||||
#define OFFSET_SCOUT_AMMO 427 + EXTRAOFFSET // +44
|
||||
#define OFFSET_PARA_AMMO 428 + EXTRAOFFSET // +44
|
||||
#define OFFSET_FAMAS_AMMO 429 + EXTRAOFFSET // +44
|
||||
#define OFFSET_M3_AMMO 430 + EXTRAOFFSET // +44
|
||||
#define OFFSET_USP_AMMO 431 + EXTRAOFFSET // +44
|
||||
#define OFFSET_FIVESEVEN_AMMO 432 + EXTRAOFFSET // +44
|
||||
#define OFFSET_DEAGLE_AMMO 433 + EXTRAOFFSET // +44
|
||||
#define OFFSET_P228_AMMO 434 + EXTRAOFFSET // +44
|
||||
#define OFFSET_GLOCK_AMMO 435 + EXTRAOFFSET // +44
|
||||
#define OFFSET_FLASH_AMMO 436 + EXTRAOFFSET // +44
|
||||
#define OFFSET_HE_AMMO 437 + EXTRAOFFSET // +44
|
||||
#define OFFSET_SMOKE_AMMO 438 + EXTRAOFFSET // +44
|
||||
#define OFFSET_C4_AMMO 439 + EXTRAOFFSET // +44
|
||||
|
||||
#define OFFSET_CSDEATHS 493 + EXTRAOFFSET // +49
|
||||
#define OFFSET_SHIELD 559 + EXTRAOFFSET
|
||||
// "weapon_*" entities
|
||||
#define OFFSET_WEAPONTYPE 57 + EXTRAOFFSET // +14
|
||||
#define OFFSET_CLIPAMMO 65 + EXTRAOFFSET // +14
|
||||
#define OFFSET_SILENCER_FIREMODE 88 + EXTRAOFFSET // +14
|
||||
// "hostage_entity" entities
|
||||
#define OFFSET_HOSTAGEFOLLOW 51 + EXTRAOFFSET // +21, long=51, int=107! (must use the long* offset because pointers on amd64 are stored the size of longs, 8 bytes, instead of the usual int 4 bytes.)
|
||||
#define OFFSET_HOSTAGEID 516 + EXTRAOFFSET // +29
|
||||
#endif
|
||||
|
||||
#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_CLICMD_OFFS_USEBOTARGS 2
|
||||
#define CS_CLICMD_OFFS_BOTARGS 22
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#define CS_IDENT_GIVENSHIELD "_ZN11CBasePlayer10GiveShieldEb" // CS_OnBuy forward
|
||||
#define CS_IDENT_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc" // CS_OnBuy forward
|
||||
#define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib" // CS_OnBuy forward
|
||||
#define CS_IDENT_CREATENAMEDENTITY "_Z19CREATE_NAMED_ENTITYj" // cs_create_entity
|
||||
#define CS_IDENT_UTIL_FINDENTITYBYSTRING "_Z23UTIL_FindEntityByStringP11CBaseEntityPKcS2_" // cs_create_entity
|
||||
#define CS_IDENT_HIDDEN_STATE false
|
||||
#elif defined(__APPLE__)
|
||||
#define CS_IDENT_GIVENSHIELD "_ZN11CBasePlayer10GiveShieldEb"
|
||||
#define CS_IDENT_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc"
|
||||
#define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib"
|
||||
#define CS_IDENT_CREATENAMEDENTITY "_Z19CREATE_NAMED_ENTITYj"
|
||||
#define CS_IDENT_UTIL_FINDENTITYBYSTRING "_Z23UTIL_FindEntityByStringP11CBaseEntityPKcS2_"
|
||||
#define CS_IDENT_HIDDEN_STATE true
|
||||
#elif defined(WIN32)
|
||||
#define CS_IDENT_GIVENSHIELD "\\x56\\x8B\\x2A\\x57\\x33\\x2A\\x8B\\x2A\\x2A\\x2A\\x2A\\x2A\\xB0"
|
||||
#define CS_IDENT_GIVENAMEDITEM "\\x8B\\x2A\\x2A\\x2A\\x56\\x57\\x8B\\x2A\\x8B\\x2A\\x2A\\x2A\\x2A\\x2A\\x2B"
|
||||
#define CS_IDENT_ADDACCOUNT "\\x8B\\x2A\\x2A\\x2A\\x56\\x8B\\x2A\\x8B\\x2A\\x2A\\x2A\\x2A\\x2A\\x03"
|
||||
#define CS_IDENT_CREATENAMEDENTITY "\\x56\\x57\\x8B\\x2A\\x2A\\x2A\\x57\\xFF\\x2A\\x2A\\x2A\\x2A\\x2A\\x8B"
|
||||
#define CS_IDENT_UTIL_FINDENTITYBYSTRING "\\x51\\x8B\\x2A\\x2A\\x2A\\x53\\x55\\x56\\x85\\x2A\\x57"
|
||||
#define CS_IDENT_HIDDEN_STATE false
|
||||
#endif
|
||||
|
||||
#define CSI_P228 CSW_P228
|
||||
#define CSI_SCOUT CSW_SCOUT
|
||||
#define CSI_HEGRENADE CSW_HEGRENADE
|
||||
@ -230,7 +83,7 @@
|
||||
#define CSW_DEAGLE 26
|
||||
#define CSW_SG552 27
|
||||
#define CSW_AK47 28
|
||||
//#define CSW_KNIFE 29
|
||||
#define CSW_KNIFE 29
|
||||
#define CSW_P90 30
|
||||
#define CSW_VEST 31 // Brand new invention!
|
||||
#define CSW_VESTHELM 32 // Brand new invention!
|
||||
@ -257,36 +110,72 @@
|
||||
#define CSA_VESTHELM 17
|
||||
#define CSA_SMOKEGRENADE 18
|
||||
|
||||
#define M4A1_SILENCED (1<<2)
|
||||
#define M4A1_ATTACHSILENCEANIM 6
|
||||
#define M4A1_DETACHSILENCEANIM 13
|
||||
#define USP_SILENCED (1<<0)
|
||||
#define USP_ATTACHSILENCEANIM 7
|
||||
#define USP_DETACHSILENCEANIM 15
|
||||
enum WeaponState
|
||||
{
|
||||
WPNSTATE_USP_SILENCED = (1 << 0),
|
||||
WPNSTATE_GLOCK18_BURST_MODE = (1 << 1),
|
||||
WPNSTATE_M4A1_SILENCED = (1 << 2),
|
||||
WPNSTATE_ELITE_LEFT = (1 << 3),
|
||||
WPNSTATE_FAMAS_BURST_MODE = (1 << 4),
|
||||
WPNSTATE_SHIELD_DRAWN = (1 << 5),
|
||||
};
|
||||
|
||||
#define GLOCK_SEMIAUTOMATIC 0
|
||||
#define GLOCK_BURSTMODE 2
|
||||
#define FAMAS_AUTOMATIC 0
|
||||
#define FAMAS_BURSTMODE 16
|
||||
enum m4a1_e
|
||||
{
|
||||
M4A1_IDLE,
|
||||
M4A1_SHOOT1,
|
||||
M4A1_SHOOT2,
|
||||
M4A1_SHOOT3,
|
||||
M4A1_RELOAD,
|
||||
M4A1_DRAW,
|
||||
M4A1_ATTACH_SILENCER,
|
||||
M4A1_UNSIL_IDLE,
|
||||
M4A1_UNSIL_SHOOT1,
|
||||
M4A1_UNSIL_SHOOT2,
|
||||
M4A1_UNSIL_SHOOT3,
|
||||
M4A1_UNSIL_RELOAD,
|
||||
M4A1_UNSIL_DRAW,
|
||||
M4A1_DETACH_SILENCER
|
||||
};
|
||||
|
||||
#define PLAYER_IS_VIP (1<<8)
|
||||
enum usp_e
|
||||
{
|
||||
USP_IDLE,
|
||||
USP_SHOOT1,
|
||||
USP_SHOOT2,
|
||||
USP_SHOOT3,
|
||||
USP_SHOOT_EMPTY,
|
||||
USP_RELOAD,
|
||||
USP_DRAW,
|
||||
USP_ATTACH_SILENCER,
|
||||
USP_UNSIL_IDLE,
|
||||
USP_UNSIL_SHOOT1,
|
||||
USP_UNSIL_SHOOT2,
|
||||
USP_UNSIL_SHOOT3,
|
||||
USP_UNSIL_SHOOT_EMPTY,
|
||||
USP_UNSIL_RELOAD,
|
||||
USP_UNSIL_DRAW,
|
||||
USP_DETACH_SILENCER
|
||||
};
|
||||
|
||||
#define PLAYER_IN_BUYZONE (1<<0)
|
||||
enum SignalState
|
||||
{
|
||||
SIGNAL_BUY = (1 << 0),
|
||||
SIGNAL_BOMB = (1 << 1),
|
||||
SIGNAL_RESCUE = (1 << 2),
|
||||
SIGNAL_ESCAPE = (1 << 3),
|
||||
SIGNAL_VIPSAFETY = (1 << 4),
|
||||
};
|
||||
|
||||
#define TEAM_UNASSIGNED 0
|
||||
#define TEAM_T 1
|
||||
#define TEAM_CT 2
|
||||
#define TEAM_SPECTATOR 3
|
||||
|
||||
#define CAN_PLANT_BOMB (1<<8) // 256
|
||||
#define HAS_DEFUSE_KIT (1<<16) // 65536
|
||||
|
||||
#define DEFUSER_COLOUR_R 0
|
||||
#define DEFUSER_COLOUR_G 160
|
||||
#define DEFUSER_COLOUR_B 0
|
||||
|
||||
#define HAS_NVGOGGLES (1<<0)
|
||||
|
||||
#define SCOREATTRIB_NOTHING 0
|
||||
#define SCOREATTRIB_DEAD 1
|
||||
#define SCOREATTRIB_BOMB 2 // t only
|
||||
@ -299,14 +188,11 @@
|
||||
#define CS_ARMOR_KEVLAR 1
|
||||
#define CS_ARMOR_ASSAULTSUIT 2
|
||||
|
||||
#define CS_FIRST_ZOOM 0x28
|
||||
#define CS_SECOND_AWP_ZOOM 0xA
|
||||
#define CS_SECOND_NONAWP_ZOOM 0xF
|
||||
#define CS_AUGSG552_ZOOM 0x37
|
||||
#define CS_NO_ZOOM 0x5A
|
||||
|
||||
#define HAS_SHIELD (1<<24) //16777216
|
||||
|
||||
#define CS_FIRST_ZOOM 40
|
||||
#define CS_SECOND_AWP_ZOOM 10
|
||||
#define CS_SECOND_NONAWP_ZOOM 15
|
||||
#define CS_AUGSG552_ZOOM 55
|
||||
#define CS_NO_ZOOM 90
|
||||
|
||||
enum CS_Internal_Models {
|
||||
CS_DONTCHANGE = 0,
|
||||
|
@ -33,6 +33,8 @@ CDetour *AddAccountDetour = NULL;
|
||||
|
||||
int CurrentItemId = 0;
|
||||
StringHashMap<int> ItemAliasList;
|
||||
int TeamOffset = 0;
|
||||
int MenuOffset = 0;
|
||||
|
||||
extern enginefuncs_t *g_pengfuncsTable;
|
||||
|
||||
@ -121,11 +123,11 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
|
||||
/* Menu_BuyItem */ { 0, CSI_VEST, CSI_VESTHELM, CSI_FLASHBANG, CSI_HEGRENADE, CSI_SMOKEGRENADE, CSI_NVGS, CSI_DEFUSER, CSI_SHIELDGUN }
|
||||
};
|
||||
|
||||
int menuId = *((int *)pEdict->pvPrivateData + OFFSET_MENU);
|
||||
int menuId = get_pdata<int>(pEdict, MenuOffset);
|
||||
|
||||
if (menuId >= Menu_Buy && menuId <= Menu_BuyItem)
|
||||
{
|
||||
int team = *((int *)pEdict->pvPrivateData + OFFSET_TEAM);
|
||||
switch (team)
|
||||
switch (get_pdata<int>(pEdict, TeamOffset))
|
||||
{
|
||||
case TEAM_T: itemId = menuItemsTe[menuId - 4][slot]; break; // -4 because array is zero-based and Menu_Buy* constants starts from 4.
|
||||
case TEAM_CT:itemId = menuItemsCt[menuId - 4][slot]; break;
|
||||
@ -236,30 +238,52 @@ void CtrlDetours_ClientCommand(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
void *target = (void *)MDLL_ClientCommand;
|
||||
void *base = reinterpret_cast<void *>(MDLL_ClientCommand);
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
UseBotArgs = *(int **)((unsigned char *)target + CS_CLICMD_OFFS_USEBOTARGS);
|
||||
BotArgs = (const char **)*(const char **)((unsigned char *)target + CS_CLICMD_OFFS_BOTARGS);
|
||||
int offset = 0;
|
||||
|
||||
if (MainConfig->GetOffset("UseBotArgs", &offset) && offset)
|
||||
{
|
||||
UseBotArgs = get_pdata<int*>(base, offset);
|
||||
}
|
||||
|
||||
if (MainConfig->GetOffset("BotArgs", &offset) && offset)
|
||||
{
|
||||
BotArgs = get_pdata<const char**>(base, offset);
|
||||
}
|
||||
|
||||
#elif defined(__linux__) || defined(__APPLE__)
|
||||
|
||||
UseBotArgs = (int *)UTIL_FindAddressFromEntry(CS_IDENT_USEBOTARGS, CS_IDENT_HIDDEN_STATE);
|
||||
BotArgs = (const char **)UTIL_FindAddressFromEntry(CS_IDENT_BOTARGS, CS_IDENT_HIDDEN_STATE);
|
||||
void *address = nullptr;
|
||||
|
||||
if (MainConfig->GetMemSig("UseBotArgs", &address) && address)
|
||||
{
|
||||
UseBotArgs = reinterpret_cast<int *>(address);
|
||||
}
|
||||
|
||||
if (MainConfig->GetMemSig("BotArgs", &address) && address)
|
||||
{
|
||||
BotArgs = reinterpret_cast<const char **>(address);
|
||||
}
|
||||
#endif
|
||||
ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target);
|
||||
ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, base);
|
||||
|
||||
if (!ClientCommandDetour)
|
||||
OffsetConfig->GetOffsetByClass("CBasePlayer", "m_iTeam", &TeamOffset);
|
||||
OffsetConfig->GetOffsetByClass("CBasePlayer", "m_iMenu", &MenuOffset);
|
||||
|
||||
if (!ClientCommandDetour || !UseBotArgs || !BotArgs || !TeamOffset || !MenuOffset)
|
||||
{
|
||||
MF_Log("ClientCommand is not available - forward client_command has been disabled");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ClientCommandDetour)
|
||||
if (ClientCommandDetour)
|
||||
{
|
||||
ClientCommandDetour->Destroy();
|
||||
}
|
||||
|
||||
ItemAliasList.clear();
|
||||
}
|
||||
@ -268,7 +292,9 @@ void CtrlDetours_ClientCommand(bool set)
|
||||
void ToggleDetour_ClientCommands(bool enable)
|
||||
{
|
||||
if (ClientCommandDetour)
|
||||
{
|
||||
(enable) ? ClientCommandDetour->EnableDetour() : ClientCommandDetour->DisableDetour();
|
||||
}
|
||||
|
||||
if (enable)
|
||||
{
|
||||
@ -329,13 +355,16 @@ void CtrlDetours_BuyCommands(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
void *giveShieldAddress = UTIL_FindAddressFromEntry(CS_IDENT_GIVENSHIELD , CS_IDENT_HIDDEN_STATE);
|
||||
void *giveNamedItemAddress = UTIL_FindAddressFromEntry(CS_IDENT_GIVENAMEDITEM, CS_IDENT_HIDDEN_STATE);
|
||||
void *addAccountAddress = UTIL_FindAddressFromEntry(CS_IDENT_ADDACCOUNT , CS_IDENT_HIDDEN_STATE);
|
||||
void *address = nullptr;
|
||||
|
||||
GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, giveShieldAddress);
|
||||
GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress);
|
||||
AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress);
|
||||
MainConfig->GetMemSig("GiveShield", &address);
|
||||
GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, address); address = nullptr;
|
||||
|
||||
MainConfig->GetMemSig("GiveNamedItem", &address);
|
||||
GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, address); address = nullptr;
|
||||
|
||||
MainConfig->GetMemSig("AddAccount", &address);
|
||||
AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, address); address = nullptr;
|
||||
|
||||
if (!GiveShieldDetour || !GiveNamedItemDetour || !AddAccountDetour)
|
||||
{
|
||||
@ -360,13 +389,19 @@ void CtrlDetours_BuyCommands(bool set)
|
||||
else
|
||||
{
|
||||
if (GiveShieldDetour)
|
||||
{
|
||||
GiveShieldDetour->Destroy();
|
||||
}
|
||||
|
||||
if (GiveNamedItemDetour)
|
||||
{
|
||||
GiveNamedItemDetour->Destroy();
|
||||
}
|
||||
|
||||
if (AddAccountDetour)
|
||||
{
|
||||
AddAccountDetour->Destroy();
|
||||
}
|
||||
|
||||
ItemAliasList.clear();
|
||||
}
|
||||
@ -375,11 +410,17 @@ void CtrlDetours_BuyCommands(bool set)
|
||||
void ToggleDetour_BuyCommands(bool enable)
|
||||
{
|
||||
if (GiveShieldDetour)
|
||||
{
|
||||
(enable) ? GiveShieldDetour->EnableDetour() : GiveShieldDetour->DisableDetour();
|
||||
}
|
||||
|
||||
if (GiveNamedItemDetour)
|
||||
{
|
||||
(enable) ? GiveNamedItemDetour->EnableDetour() : GiveNamedItemDetour->DisableDetour();
|
||||
}
|
||||
|
||||
if (AddAccountDetour)
|
||||
{
|
||||
(enable) ? AddAccountDetour->EnableDetour() : AddAccountDetour->DisableDetour();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,17 @@
|
||||
#ifndef CSTRIKE_UTILS_H
|
||||
#define CSTRIKE_UTILS_H
|
||||
|
||||
#include <IGameConfigs.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);
|
||||
char *UTIL_StringToLower(char *str);
|
||||
|
||||
extern IGameConfig *MainConfig;
|
||||
extern IGameConfig *OffsetConfig;
|
||||
|
||||
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
|
||||
#define GETCLIENTKEYVALUE (*g_engfuncs.pfnInfoKeyValue)
|
||||
@ -69,6 +74,52 @@ char *UTIL_StringToLower(char *str);
|
||||
((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))
|
||||
|
||||
|
||||
#define GET_OFFSET(classname, member) \
|
||||
static int member = -1; \
|
||||
if (member == -1) \
|
||||
{ \
|
||||
if (!OffsetConfig->GetOffsetByClass(classname, #member, &member) || !member)\
|
||||
{ \
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid %s offset. Native %s is disabled", #member, __FUNCTION__);\
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define GET_OFFSET_NO_ERROR(classname, member) \
|
||||
static int member = -1; \
|
||||
if (member == -1) \
|
||||
{ \
|
||||
if (!OffsetConfig->GetOffsetByClass(classname, #member, &member) || !member)\
|
||||
{ \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T& get_pdata(edict_t *pEntity, int offset, int element = 0)
|
||||
{
|
||||
return *reinterpret_cast<T*>(reinterpret_cast<int8*>(pEntity->pvPrivateData) + offset + element * sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T& get_pdata(void *pEntity, int offset, int element = 0)
|
||||
{
|
||||
return *reinterpret_cast<T*>(reinterpret_cast<int8*>(pEntity) + offset + element * sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void set_pdata(edict_t *pEntity, int offset, T value, int element = 0)
|
||||
{
|
||||
*reinterpret_cast<T*>(reinterpret_cast<int8*>(pEntity->pvPrivateData) + offset + element * sizeof(T)) = value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void set_pdata(void *pEntity, int offset, T value, int element = 0)
|
||||
{
|
||||
*reinterpret_cast<T*>(reinterpret_cast<int8*>(pEntity) + offset + element * sizeof(T)) = value;
|
||||
}
|
||||
|
||||
|
||||
inline edict_t *PrivateToEdict(const void *pdata)
|
||||
{
|
||||
if (!pdata)
|
||||
@ -100,4 +151,46 @@ inline int PrivateToIndex(const void *pdata)
|
||||
return ENTINDEX(pEntity);
|
||||
};
|
||||
|
||||
|
||||
class EHANDLE
|
||||
{
|
||||
private:
|
||||
|
||||
edict_t* m_pent;
|
||||
int m_serialnumber;
|
||||
|
||||
public:
|
||||
|
||||
edict_t* Get(void)
|
||||
{
|
||||
if (!FNullEnt(m_pent))
|
||||
{
|
||||
if (m_pent->serialnumber == m_serialnumber)
|
||||
{
|
||||
return m_pent;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
edict_t* Set(edict_t *pent)
|
||||
{
|
||||
if (!FNullEnt(pent))
|
||||
{
|
||||
m_pent = pent;
|
||||
m_serialnumber = m_pent->serialnumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pent = nullptr;
|
||||
m_serialnumber = 0;
|
||||
}
|
||||
|
||||
return pent;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // CSTRIKE_UTILS_H
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "CstrikeUtils.h"
|
||||
#include "CstrikeDatas.h"
|
||||
#include "CstrikeHLTypeConversion.h"
|
||||
#include <IGameConfigs.h>
|
||||
|
||||
extern AMX_NATIVE_INFO CstrikeNatives[];
|
||||
|
||||
@ -30,6 +31,10 @@ void ToggleDetour_BuyCommands(bool enable);
|
||||
CreateNamedEntityFunc CS_CreateNamedEntity = nullptr;
|
||||
UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString = nullptr;
|
||||
|
||||
IGameConfig *MainConfig;
|
||||
IGameConfig *OffsetConfig;
|
||||
IGameConfigManager *ConfigManager;
|
||||
|
||||
int AmxxCheckGame(const char *game)
|
||||
{
|
||||
if (strcasecmp(game, "cstrike") == 0 ||
|
||||
@ -44,23 +49,48 @@ void OnAmxxAttach()
|
||||
{
|
||||
MF_AddNatives(CstrikeNatives);
|
||||
|
||||
InitializeHacks();
|
||||
ConfigManager = MF_GetConfigManager();
|
||||
|
||||
// cs_create_entity()
|
||||
CS_CreateNamedEntity = reinterpret_cast<CreateNamedEntityFunc>(UTIL_FindAddressFromEntry(CS_IDENT_CREATENAMEDENTITY, CS_IDENT_HIDDEN_STATE));
|
||||
char error[256];
|
||||
error[0] = '\0';
|
||||
|
||||
if (CS_CreateNamedEntity <= 0)
|
||||
if (!ConfigManager->LoadGameConfigFile("modules.games", &MainConfig, error, sizeof(error)) && error[0] != '\0')
|
||||
{
|
||||
MF_Log("Could not read module.games gamedata: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
error[0] = '\0';
|
||||
|
||||
if (!ConfigManager->LoadGameConfigFile("common.games", &OffsetConfig, error, sizeof(error)) && error[0] != '\0')
|
||||
{
|
||||
MF_Log("Could not read common.games gamedata: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
void *address = nullptr;
|
||||
|
||||
if (MainConfig->GetMemSig("CreateNamedEntity", &address) && address) // cs_create_entity()
|
||||
{
|
||||
CS_CreateNamedEntity = reinterpret_cast<CreateNamedEntityFunc>(address);
|
||||
}
|
||||
|
||||
if (MainConfig->GetMemSig("FindEntityByString", &address) && address) // cs_find_ent_by_class()
|
||||
{
|
||||
CS_UTIL_FindEntityByString = reinterpret_cast<UTIL_FindEntityByStringFunc>(address);
|
||||
}
|
||||
|
||||
if (!CS_CreateNamedEntity)
|
||||
{
|
||||
MF_Log("CREATE_NAMED_ENITTY is not available - native cs_create_entity() has been disabled");
|
||||
}
|
||||
|
||||
// cs_find_ent_by_class()
|
||||
CS_UTIL_FindEntityByString = reinterpret_cast<UTIL_FindEntityByStringFunc>(UTIL_FindAddressFromEntry(CS_IDENT_UTIL_FINDENTITYBYSTRING, CS_IDENT_HIDDEN_STATE));
|
||||
|
||||
if (CS_UTIL_FindEntityByString <= 0)
|
||||
if (!CS_UTIL_FindEntityByString)
|
||||
{
|
||||
MF_Log("UTIL_FindEntByString is not available - native cs_find_ent_by_class() has been disabled");
|
||||
}
|
||||
|
||||
InitializeHacks();
|
||||
}
|
||||
|
||||
void OnPluginsLoaded()
|
||||
@ -88,5 +118,8 @@ void OnPluginsLoaded()
|
||||
|
||||
void OnAmxxDetach()
|
||||
{
|
||||
ConfigManager->CloseGameConfigFile(MainConfig);
|
||||
ConfigManager->CloseGameConfigFile(OffsetConfig);
|
||||
|
||||
ShutdownHacks();
|
||||
}
|
||||
|
Reference in New Issue
Block a user