From 6e50a0effdd815752b485cffa060f8e41a5c5044 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 3 Jul 2014 10:10:18 +0200 Subject: [PATCH 1/9] Cstrike: Make CS_OnBuy forward more reliable - part 1 Purpose is to have the forward be called only on actual buying. This has been requested on the forum. --- dlls/cstrike/cstrike/CstrikeDatas.h | 6 ++++ dlls/cstrike/cstrike/CstrikeHacks.cpp | 48 ++++++++++++++++++++++----- public/memtools/CDetour/detours.h | 1 + 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeDatas.h b/dlls/cstrike/cstrike/CstrikeDatas.h index d64c773e..85a61d50 100644 --- a/dlls/cstrike/cstrike/CstrikeDatas.h +++ b/dlls/cstrike/cstrike/CstrikeDatas.h @@ -165,16 +165,22 @@ #define CS_IDENT_CANBUYTHIS "_Z10CanBuyThisP11CBasePlayeri" #define CS_IDENT_BUYITEM "_Z7BuyItemP11CBasePlayeri" #define CS_IDENT_BUYGUNAMMO "_Z10BuyGunAmmoR11CBasePlayerR15CBasePlayerItemb" + #define CS_IDENT_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc" + #define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib" #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_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc" + #define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib" #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_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_HIDDEN_STATE false #endif diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index e7703597..01f5f4c4 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -47,7 +47,8 @@ CDetour *g_ClientCommandDetour = NULL; CDetour *g_CanBuyThisDetour = NULL; CDetour *g_BuyItemDetour = NULL; CDetour *g_BuyGunAmmoDetour = NULL; - +CDetour *g_GiveNamedItemDetour = NULL; +CDetour *g_AddAccountDetour = NULL; void InitializeHacks() { @@ -137,6 +138,17 @@ DETOUR_DECL_STATIC3(BuyGunAmmo, bool, void*, pvPlayer, void*, pvWeapon, bool, bB return DETOUR_STATIC_CALL(BuyGunAmmo)(pvPlayer, pvWeapon, bBlinkMoney); } +DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlayer::GiveNamedItem(const char *pszName) +{ + DETOUR_MEMBER_CALL(GiveNamedItem)(pszName); +} + + +DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void CBasePlayer::AddAccount(int amount, bool bTrackChange) +{ + DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); +} + void CtrlDetours_ClientCommand(bool set) { @@ -180,15 +192,23 @@ 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); + 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); + void *giveNamedItemAddress = UTIL_FindAddressFromEntry(CS_IDENT_GIVENAMEDITEM, CS_IDENT_HIDDEN_STATE); + void *addAccountAddress = UTIL_FindAddressFromEntry(CS_IDENT_ADDACCOUNT , 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); + g_CanBuyThisDetour = DETOUR_CREATE_STATIC_FIXED(CanBuyThis, canBuyThisAddress); + g_BuyItemDetour = DETOUR_CREATE_STATIC_FIXED(BuyItem, buyItemAddress); + g_BuyGunAmmoDetour = DETOUR_CREATE_STATIC_FIXED(BuyGunAmmo, buyGunAmmoAddress); + g_GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); + g_AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); - if (g_CanBuyThisDetour == NULL || g_BuyItemDetour == NULL || g_BuyGunAmmoDetour == NULL) + if (g_CanBuyThisDetour == NULL || + g_BuyItemDetour == NULL || + g_BuyGunAmmoDetour == NULL || + g_GiveNamedItemDetour == NULL || + g_AddAccountDetour == NULL) { MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); } @@ -203,6 +223,12 @@ void CtrlDetours_BuyCommands(bool set) if (g_BuyGunAmmoDetour) g_BuyGunAmmoDetour->Destroy(); + + if (g_GiveNamedItemDetour) + g_GiveNamedItemDetour->Destroy(); + + if (g_AddAccountDetour) + g_AddAccountDetour->Destroy(); } } @@ -216,4 +242,10 @@ void ToggleDetour_BuyCommands(bool enable) if (g_BuyGunAmmoDetour) (enable) ? g_BuyGunAmmoDetour->EnableDetour() : g_BuyGunAmmoDetour->DisableDetour(); + + if (g_GiveNamedItemDetour) + (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); + + if (g_AddAccountDetour) + (enable) ? g_AddAccountDetour->EnableDetour() : g_AddAccountDetour->DisableDetour(); } \ No newline at end of file diff --git a/public/memtools/CDetour/detours.h b/public/memtools/CDetour/detours.h index dea92c42..89c2b238 100644 --- a/public/memtools/CDetour/detours.h +++ b/public/memtools/CDetour/detours.h @@ -136,6 +136,7 @@ ret name##Class::name(p1type p1name, p2type p2name, p3type p3name, p4type p4name #define GET_STATIC_TRAMPOLINE(name) (void **)&name##_Actual #define DETOUR_CREATE_MEMBER(name, gamedata, target) CDetourManager::CreateDetour(GET_MEMBER_CALLBACK(name), GET_MEMBER_TRAMPOLINE(name), gamedata, target); +#define DETOUR_CREATE_MEMBER_FIXED(name, address) CDetourManager::CreateDetour(GET_MEMBER_CALLBACK(name), GET_MEMBER_TRAMPOLINE(name), address); #define DETOUR_CREATE_STATIC(name, gamedata, target) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), gamedata, target); #define DETOUR_CREATE_STATIC_FIXED(name, address) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), address); From 0cf39307e071b6965e291551b60bc960c36757a5 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 3 Jul 2014 19:40:30 +0200 Subject: [PATCH 2/9] Cstrike: Make CS_OnBuy forward more reliable - part 2 Purpose is to have the forward be called only on actual buying. This has been requested on the forum. --- dlls/cstrike/cstrike/AMBuilder | 4 + dlls/cstrike/cstrike/CstrikeDatas.h | 21 +++ dlls/cstrike/cstrike/CstrikeHacks.cpp | 163 +++++++++++++++++++- dlls/cstrike/cstrike/CstrikePlayer.cpp | 8 - dlls/cstrike/cstrike/msvc10/cstrike.vcxproj | 4 +- 5 files changed, 182 insertions(+), 18 deletions(-) diff --git a/dlls/cstrike/cstrike/AMBuilder b/dlls/cstrike/cstrike/AMBuilder index fc243e71..ec1ac464 100644 --- a/dlls/cstrike/cstrike/AMBuilder +++ b/dlls/cstrike/cstrike/AMBuilder @@ -3,6 +3,10 @@ import os.path binary = AMXX.MetaModule(builder, 'cstrike') +binary.compiler.defines += [ + 'HAVE_STDINT_H', +] + binary.sources = [ 'sdk/amxxmodule.cpp', 'amxx_api.cpp', diff --git a/dlls/cstrike/cstrike/CstrikeDatas.h b/dlls/cstrike/cstrike/CstrikeDatas.h index 85a61d50..be68adf2 100644 --- a/dlls/cstrike/cstrike/CstrikeDatas.h +++ b/dlls/cstrike/cstrike/CstrikeDatas.h @@ -64,6 +64,7 @@ #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 @@ -353,4 +354,24 @@ enum CS_SET_AUGSG552_ZOOM, }; +typedef enum +{ + Menu_OFF, + Menu_ChooseTeam, + Menu_IGChooseTeam, + Menu_ChooseAppearance, + Menu_Buy, + Menu_BuyPistol, + Menu_BuyRifle, + Menu_BuyMachineGun, + Menu_BuyShotgun, + Menu_BuySubMachineGun, + Menu_BuyItem, + Menu_Radio1, + Menu_Radio2, + Menu_Radio3, + Menu_ClientBuy + +} Menu; + #endif // CSTRIKE_DATA_H \ No newline at end of file diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 01f5f4c4..25673cc1 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -33,6 +33,9 @@ #include "CstrikeDatas.h" #include "CstrikeUtils.h" #include "CDetour/detours.h" +#include + +using namespace SourceMod; // hashmap void CtrlDetours_ClientCommand(bool set); void CtrlDetours_BuyCommands(bool set); @@ -50,6 +53,9 @@ CDetour *g_BuyGunAmmoDetour = NULL; CDetour *g_GiveNamedItemDetour = NULL; CDetour *g_AddAccountDetour = NULL; +int g_CurrentItemId = 0; +StringHashMap g_ItemAliasList; + void InitializeHacks() { #if defined AMD64 @@ -66,9 +72,92 @@ void ShutdownHacks() CtrlDetours_BuyCommands(false); } +#undef CMD_ARGV + +const char *CMD_ARGV(int i) +{ + if (*g_UseBotArgs) + { + if (i < 4) + { + return g_BotArgs[i]; + } + + return NULL; + } + + return g_engfuncs.pfnCmd_Argv(i); +} DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientCommand(edict_t *pEntity) { + const char *command = CMD_ARGV(0); + + // A new command is triggered, reset current item. + g_CurrentItemId = 0; + + // Purpose is to retrieve an item id based on alias name or selected item from menu, + // to be used in OnBuy* forwards. + if (command && *command) + { + int itemId = 0; + + // Handling via menu. + if (!strcmp(command, "menuselect")) + { + int slot = atoi(CMD_ARGV(1)); + + if (slot > 0 && slot < 9) + { + static const int menuItemsTe[][9] = + { + /* Menu_Buy */ { 0, 0, 0, 0, 0, 0, CSI_PRIMAMMO, CSI_SECAMMO, 0 }, + /* Menu_BuyPistol */ { 0, CSI_GLOCK18, CSI_USP, CSI_P228, CSI_DEAGLE, CSI_ELITE, 0, 0, 0 }, + /* Menu_BuyRifle */ { 0, CSI_GALI, CSI_AK47, CSI_SCOUT, CSI_SG552, CSI_AWP, CSI_G3SG1, 0, 0 }, + /* Menu_BuyMachineGun */ { 0, CSI_M249, 0, 0, 0, 0, 0, 0, 0 }, + /* Menu_BuyShotgun */ { 0, CSI_M3, CSI_XM1014, 0, 0, 0, 0, 0, 0 }, + /* Menu_BuySubMachineGun */ { 0, CSI_MAC10, CSI_MP5NAVY, CSI_UMP45, CSI_P90, 0, 0, 0, 0 }, + /* Menu_BuyItem */ { 0, CSI_VEST, CSI_VESTHELM, CSI_FLASHBANG, CSI_HEGRENADE, CSI_SMOKEGRENADE, CSI_NVGS, 0, 0 } + }; + + static const int menuItemsCt[][9] = + { + /* Menu_Buy */ { 0, 0, 0, 0, 0, 0, CSI_PRIMAMMO, CSI_SECAMMO, 0 }, + /* Menu_BuyPistol */ { 0, CSI_GLOCK18, CSI_USP, CSI_P228, CSI_DEAGLE, CSI_FIVESEVEN, 0, 0, 0 }, + /* Menu_BuyRifle */ { 0, CSI_FAMAS, CSI_SCOUT, CSI_M4A1, CSI_AUG, CSI_SG550, CSI_AWP, 0, 0 }, + /* Menu_BuyMachineGun */ { 0, CSI_M249, 0, 0, 0, 0, 0, 0, 0 }, + /* Menu_BuyShotgun */ { 0, CSI_M3, CSI_XM1014, 0, 0, 0, 0, 0, 0 }, + /* Menu_BuySubMachineGun */ { 0, CSI_TMP, CSI_MP5NAVY, CSI_UMP45, CSI_P90, 0, 0, 0, 0 }, + /* 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); + if (menuId >= Menu_Buy && menuId <= Menu_BuyItem) + { + int team = *((int *)pEdict->pvPrivateData + OFFSET_TEAM); + switch (team) + { + 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; + } + + if (itemId) + { + g_CurrentItemId = itemId; + } + } + } + } + // Handling via alias + else + { + if (g_ItemAliasList.retrieve(command, &itemId)) + { + g_CurrentItemId = itemId; + } + } + } + if (*g_UseBotArgs) { int client = ENTINDEX(pEdict); @@ -89,9 +178,9 @@ DETOUR_DECL_STATIC2(CanBuyThis, bool, void*, pvPlayer, int, weaponId) // bool Ca { int player = PrivateToIndex(pvPlayer); - if (MF_IsPlayerAlive(player) && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(player), static_cast(weaponId)) > 0) + if (MF_IsPlayerAlive(player)) { - return false; + g_CurrentItemId = weaponId; } } @@ -106,9 +195,9 @@ DETOUR_DECL_STATIC2(BuyItem, void, void*, pvPlayer, int, iSlot) // void BuyItem( { 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(player), static_cast(itemSlotToWeaponId[iSlot])) > 0) + if (iSlot >= 1 && iSlot <= 8) { - return; + g_CurrentItemId = itemSlotToWeaponId[iSlot]; } } @@ -128,10 +217,7 @@ DETOUR_DECL_STATIC3(BuyGunAmmo, bool, void*, pvPlayer, void*, pvWeapon, bool, bB int weaponId = *((int *)pWeapon->pvPrivateData + OFFSET_WEAPONTYPE); int ammoId = (1<(player), static_cast(ammoId)) > 0) - { - return false; - } + g_CurrentItemId = ammoId; } } @@ -140,12 +226,25 @@ DETOUR_DECL_STATIC3(BuyGunAmmo, bool, void*, pvPlayer, void*, pvWeapon, bool, bB DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlayer::GiveNamedItem(const char *pszName) { + if (g_CurrentItemId && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(PrivateToIndex(this)), static_cast(g_CurrentItemId)) > 0) + { + return; + } + + g_CurrentItemId = 0; + DETOUR_MEMBER_CALL(GiveNamedItem)(pszName); } DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void CBasePlayer::AddAccount(int amount, bool bTrackChange) { + if (g_CurrentItemId) + { + g_CurrentItemId = 0; + return; + } + DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); } @@ -212,6 +311,52 @@ void CtrlDetours_BuyCommands(bool set) { MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); } + + // Build the item alias list. + // Used in ClientCommand to check and get fastly item id from aiias name. + typedef struct + { + char *alias; + int id; + + } itemBuyAliasInfo; + + itemBuyAliasInfo aliasToId[] = + { + { "p228" , CSI_P228 }, { "228compact" , CSI_P228 }, + { "scout" , CSI_SCOUT }, { "hegren" , CSI_HEGRENADE }, + { "xm1014" , CSI_XM1014 }, { "autoshotgun", CSI_XM1014 }, + { "mac10" , CSI_MAC10 }, { "aug" , CSI_AUG }, + { "bullpup" , CSI_AUG }, { "sgren" , CSI_SMOKEGRENADE }, + { "elites" , CSI_ELITE }, { "fn57" , CSI_FIVESEVEN }, + { "fiveseven" , CSI_FIVESEVEN }, { "ump45" , CSI_UMP45 }, + { "sg550" , CSI_SG550 }, { "krieg550" , CSI_SG550 }, + { "galil" , CSI_GALI }, { "defender" , CSI_GALI }, + { "famas" , CSI_FAMAS }, { "clarion" , CSI_FAMAS }, + { "usp" , CSI_USP }, { "km45" , CSI_USP }, + { "glock" , CSI_GLOCK18 }, { "9x19mm" , CSI_GLOCK18 }, + { "awp" , CSI_AWP }, { "magnum" , CSI_AWP }, + { "mp5" , CSI_MP5NAVY }, { "smg" , CSI_MP5NAVY }, + { "m249" , CSI_M249 }, { "m3" , CSI_M3 }, + { "12gauge" , CSI_M3 }, { "m4a1" , CSI_M4A1 }, + { "tmp" , CSI_TMP }, { "mp" , CSI_TMP }, + { "g3sg1" , CSI_G3SG1 }, { "d3au1" , CSI_G3SG1 }, + { "flash" , CSI_FLASHBANG }, { "deagle" , CSI_DEAGLE }, + { "nighthawk" , CSI_DEAGLE }, { "sg552" , CSI_SG552 }, + { "krieg552" , CSI_SG552 }, { "ak47" , CSI_AK47 }, + { "cv47" , CSI_AK47 }, { "p90" , CSI_P90 }, + { "c90" , CSI_P90 }, { "vest" , CSI_VEST }, + { "vesthelm" , CSI_VESTHELM }, { "defuser" , CSI_DEFUSER }, + { "nvgs" , CSI_NVGS }, { "shield" , CSI_SHIELDGUN }, + { "buyammo1" , CSI_PRIMAMMO }, { "primammo" , CSI_PRIMAMMO }, + { "buyammo2" , CSI_SECAMMO }, { "secammo" , CSI_SECAMMO }, + { NULL , 0 } + }; + + for (size_t i = 0; aliasToId[i].alias != NULL; ++i) + { + g_ItemAliasList.insert(aliasToId[i].alias, aliasToId[i].id); + } } else { @@ -229,6 +374,8 @@ void CtrlDetours_BuyCommands(bool set) if (g_AddAccountDetour) g_AddAccountDetour->Destroy(); + + g_ItemAliasList.clear(); } } diff --git a/dlls/cstrike/cstrike/CstrikePlayer.cpp b/dlls/cstrike/cstrike/CstrikePlayer.cpp index 72cee51e..cd72d55f 100755 --- a/dlls/cstrike/cstrike/CstrikePlayer.cpp +++ b/dlls/cstrike/cstrike/CstrikePlayer.cpp @@ -3,14 +3,6 @@ ////////////////////////////////////////////////////////////////////// #include "CstrikePlayer.h" - -#if defined _MSC_VER - #if _MSC_VER >= 1400 - // MSVC8 - disable deprecation warnings for "unsafe" CRT functions - #define _CRT_SECURE_NO_DEPRECATE - #endif -#endif - #include // strcpy() ////////////////////////////////////////////////////////////////////// diff --git a/dlls/cstrike/cstrike/msvc10/cstrike.vcxproj b/dlls/cstrike/cstrike/msvc10/cstrike.vcxproj index c19e1bda..2e39589c 100644 --- a/dlls/cstrike/cstrike/msvc10/cstrike.vcxproj +++ b/dlls/cstrike/cstrike/msvc10/cstrike.vcxproj @@ -63,7 +63,7 @@ Disabled ..\;..\..\..\..\public; ..\..\..\..\public\amtl;..\..\..\..\public\memtools;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;CSTRIKE_EXPORTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;HAVE_STDINT_H;_CRT_SECURE_NO_DEPRECATE;CSTRIKE_EXPORTS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug false @@ -106,7 +106,7 @@ MaxSpeed OnlyExplicitInline ..\;..\..\..\..\public; ..\..\..\..\public\amtl;..\..\..\..\public\memtools;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;CSTRIKE_EXPORTS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_STDINT_H;_CRT_SECURE_NO_DEPRECATE;CSTRIKE_EXPORTS;%(PreprocessorDefinitions) true MultiThreaded true From 884c5e964343c1d4c8423582790e879cbc44fb20 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 3 Jul 2014 21:14:11 +0200 Subject: [PATCH 3/9] Cstrike: Make CS_OnBuy forward more reliable - part 3 Remove unused hooks. --- dlls/cstrike/cstrike/CstrikeDatas.h | 9 --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 82 +-------------------------- 2 files changed, 1 insertion(+), 90 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeDatas.h b/dlls/cstrike/cstrike/CstrikeDatas.h index be68adf2..84488ef0 100644 --- a/dlls/cstrike/cstrike/CstrikeDatas.h +++ b/dlls/cstrike/cstrike/CstrikeDatas.h @@ -163,23 +163,14 @@ * CS_OnBuy forward */ #if defined(__linux__) - #define CS_IDENT_CANBUYTHIS "_Z10CanBuyThisP11CBasePlayeri" - #define CS_IDENT_BUYITEM "_Z7BuyItemP11CBasePlayeri" - #define CS_IDENT_BUYGUNAMMO "_Z10BuyGunAmmoR11CBasePlayerR15CBasePlayerItemb" #define CS_IDENT_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc" #define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib" #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_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc" #define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib" #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_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_HIDDEN_STATE false diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 25673cc1..83ec0e1d 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -172,58 +172,6 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma DETOUR_STATIC_CALL(C_ClientCommand)(pEdict); } -DETOUR_DECL_STATIC2(CanBuyThis, bool, void*, pvPlayer, int, weaponId) // bool CanBuyThis(CBasePlayer *pPlayer, int weaponId) -{ - if (weaponId != CSI_SHIELDGUN) // This will be handled before with BuyItem. Avoiding duplicated call. - { - int player = PrivateToIndex(pvPlayer); - - if (MF_IsPlayerAlive(player)) - { - g_CurrentItemId = weaponId; - } - } - - return DETOUR_STATIC_CALL(CanBuyThis)(pvPlayer, weaponId); -} - -DETOUR_DECL_STATIC2(BuyItem, void, void*, pvPlayer, int, iSlot) // void BuyItem(CBasePlayer *pPlayer, int iSlot) -{ - 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) - { - g_CurrentItemId = itemSlotToWeaponId[iSlot]; - } - } - - DETOUR_STATIC_CALL(BuyItem)(pvPlayer, iSlot); -} - -DETOUR_DECL_STATIC3(BuyGunAmmo, bool, void*, pvPlayer, void*, pvWeapon, bool, bBlinkMoney) // bool BuyGunAmmo(CBasePlayer *player, CBasePlayerItem *weapon, bool bBlinkMoney) -{ - 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<(PrivateToIndex(this)), static_cast(g_CurrentItemId)) > 0) @@ -291,23 +239,13 @@ 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); void *giveNamedItemAddress = UTIL_FindAddressFromEntry(CS_IDENT_GIVENAMEDITEM, CS_IDENT_HIDDEN_STATE); void *addAccountAddress = UTIL_FindAddressFromEntry(CS_IDENT_ADDACCOUNT , 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); g_GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); g_AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); - if (g_CanBuyThisDetour == NULL || - g_BuyItemDetour == NULL || - g_BuyGunAmmoDetour == NULL || - g_GiveNamedItemDetour == NULL || - g_AddAccountDetour == NULL) + if (g_GiveNamedItemDetour == NULL || g_AddAccountDetour == NULL) { MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); } @@ -360,15 +298,6 @@ void CtrlDetours_BuyCommands(bool set) } else { - if (g_CanBuyThisDetour) - g_CanBuyThisDetour->Destroy(); - - if (g_BuyItemDetour) - g_BuyItemDetour->Destroy(); - - if (g_BuyGunAmmoDetour) - g_BuyGunAmmoDetour->Destroy(); - if (g_GiveNamedItemDetour) g_GiveNamedItemDetour->Destroy(); @@ -381,15 +310,6 @@ void CtrlDetours_BuyCommands(bool set) 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(); - if (g_GiveNamedItemDetour) (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); From 0728fee7069780a775d7fe7be489cee723f27ec8 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 4 Jul 2014 00:17:55 +0200 Subject: [PATCH 4/9] Cstrike: Make CS_OnBuy forward more reliable - part 4 Added support for shield , which is a special case. Moved hashmap creation to OnPluginsLoaded. --- dlls/cstrike/cstrike/CstrikeDatas.h | 3 + dlls/cstrike/cstrike/CstrikeHacks.cpp | 93 ++++++++++++++++++--------- 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeDatas.h b/dlls/cstrike/cstrike/CstrikeDatas.h index 84488ef0..c1d138f1 100644 --- a/dlls/cstrike/cstrike/CstrikeDatas.h +++ b/dlls/cstrike/cstrike/CstrikeDatas.h @@ -163,14 +163,17 @@ * CS_OnBuy forward */ #if defined(__linux__) + #define CS_IDENT_GIVENSHIELD "_ZN11CBasePlayer10GiveShieldEb" #define CS_IDENT_GIVENAMEDITEM "_ZN11CBasePlayer13GiveNamedItemEPKc" #define CS_IDENT_ADDACCOUNT "_ZN11CBasePlayer10AddAccountEib" #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_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_HIDDEN_STATE false diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 83ec0e1d..342c9bc6 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -43,15 +43,13 @@ void CtrlDetours_BuyCommands(bool set); int g_CSCliCmdFwd = -1; int g_CSBuyCmdFwd = -1; -int *g_UseBotArgs = NULL; +int *g_UseBotArgs = NULL; const char **g_BotArgs = NULL; CDetour *g_ClientCommandDetour = NULL; -CDetour *g_CanBuyThisDetour = NULL; -CDetour *g_BuyItemDetour = NULL; -CDetour *g_BuyGunAmmoDetour = NULL; +CDetour *g_GiveShieldDetour = NULL; CDetour *g_GiveNamedItemDetour = NULL; -CDetour *g_AddAccountDetour = NULL; +CDetour *g_AddAccountDetour = NULL; int g_CurrentItemId = 0; StringHashMap g_ItemAliasList; @@ -93,7 +91,7 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma { const char *command = CMD_ARGV(0); - // A new command is triggered, reset current item. + // A new command is triggered, reset variable, always. g_CurrentItemId = 0; // Purpose is to retrieve an item id based on alias name or selected item from menu, @@ -102,7 +100,7 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma { int itemId = 0; - // Handling via menu. + // Handling buy via menu. if (!strcmp(command, "menuselect")) { int slot = atoi(CMD_ARGV(1)); @@ -148,8 +146,7 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma } } } - // Handling via alias - else + else // Handling buy via alias { if (g_ItemAliasList.retrieve(command, &itemId)) { @@ -174,26 +171,47 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlayer::GiveNamedItem(const char *pszName) { + // If the current item id is not null, this means player has triggers a buy command. if (g_CurrentItemId && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(PrivateToIndex(this)), static_cast(g_CurrentItemId)) > 0) { return; } + // From here, forward is not blocked, resetting this + // to ignore code in AddAccount which is called right after. g_CurrentItemId = 0; + // Give me my item! DETOUR_MEMBER_CALL(GiveNamedItem)(pszName); } - -DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void CBasePlayer::AddAccount(int amount, bool bTrackChange) +DETOUR_DECL_MEMBER1(GiveShield, void, bool, bRetire) // void CBasePlayer::GiveShield(bool bRetire) { - if (g_CurrentItemId) + // Special case for shield. Game doesn't use GiveNamedItem() to give a shield. + if (g_CurrentItemId == CSI_SHIELDGUN && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(PrivateToIndex(this)), CSI_SHIELDGUN) > 0) { - g_CurrentItemId = 0; return; } - DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); + // From here, forward is not blocked, resetting this + // to ignore code in AddAccount which is called right after. + g_CurrentItemId = 0; + + // Give me my shield! + DETOUR_MEMBER_CALL(GiveShield)(bRetire); +} + +DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void CBasePlayer::AddAccount(int amount, bool bTrackChange) +{ + // No buy command or forward not blocked. + // Resuming game flow. + if (!g_CurrentItemId) + { + DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); + } + + // Let's reset this right away to avoid issues. + g_CurrentItemId = 0; } @@ -239,9 +257,11 @@ 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); + g_GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, giveShieldAddress); g_GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); g_AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); @@ -249,9 +269,37 @@ void CtrlDetours_BuyCommands(bool set) { MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); } + } + else + { + if (g_GiveShieldDetour) + g_GiveShieldDetour->Destroy(); + if (g_GiveNamedItemDetour) + g_GiveNamedItemDetour->Destroy(); + + if (g_AddAccountDetour) + g_AddAccountDetour->Destroy(); + + g_ItemAliasList.clear(); + } +} + +void ToggleDetour_BuyCommands(bool enable) +{ + if (g_GiveShieldDetour) + (enable) ? g_GiveShieldDetour->EnableDetour() : g_GiveShieldDetour->DisableDetour(); + + if (g_GiveNamedItemDetour) + (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); + + if (g_AddAccountDetour) + (enable) ? g_AddAccountDetour->EnableDetour() : g_AddAccountDetour->DisableDetour(); + + if (enable) + { // Build the item alias list. - // Used in ClientCommand to check and get fastly item id from aiias name. + // Used in ClientCommand to check and get fastly item id from alias name. typedef struct { char *alias; @@ -298,21 +346,6 @@ void CtrlDetours_BuyCommands(bool set) } else { - if (g_GiveNamedItemDetour) - g_GiveNamedItemDetour->Destroy(); - - if (g_AddAccountDetour) - g_AddAccountDetour->Destroy(); - g_ItemAliasList.clear(); } -} - -void ToggleDetour_BuyCommands(bool enable) -{ - if (g_GiveNamedItemDetour) - (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); - - if (g_AddAccountDetour) - (enable) ? g_AddAccountDetour->EnableDetour() : g_AddAccountDetour->DisableDetour(); } \ No newline at end of file From 6c4cb27d3efa034c9b2c697d5783ec9493ec87f5 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 4 Jul 2014 10:33:55 +0200 Subject: [PATCH 5/9] Cstrike: Implement CS_OnBuyAttempt forward. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 9 +++++++++ dlls/cstrike/cstrike/CstrikeUtils.cpp | 11 +++++++++++ dlls/cstrike/cstrike/CstrikeUtils.h | 1 + dlls/cstrike/cstrike/amxx_api.cpp | 4 +++- plugins/include/cstrike.inc | 19 ++++++++++++++++--- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 342c9bc6..1411fd38 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -42,6 +42,7 @@ void CtrlDetours_BuyCommands(bool set); int g_CSCliCmdFwd = -1; int g_CSBuyCmdFwd = -1; +int g_CSBuyAttemptCmdFwd = -1; int *g_UseBotArgs = NULL; const char **g_BotArgs = NULL; @@ -98,6 +99,9 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma // to be used in OnBuy* forwards. if (command && *command) { + // Just for safety. + command = UTIL_StringToLower((char *)command); + int itemId = 0; // Handling buy via menu. @@ -166,6 +170,11 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma } } + if (g_CurrentItemId && MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast(ENTINDEX(pEdict)), static_cast(g_CurrentItemId)) > 0) + { + return; + } + DETOUR_STATIC_CALL(C_ClientCommand)(pEdict); } diff --git a/dlls/cstrike/cstrike/CstrikeUtils.cpp b/dlls/cstrike/cstrike/CstrikeUtils.cpp index 2c4fe6a3..76783b45 100644 --- a/dlls/cstrike/cstrike/CstrikeUtils.cpp +++ b/dlls/cstrike/cstrike/CstrikeUtils.cpp @@ -139,4 +139,15 @@ bool UTIL_CheckForPublic(const char *publicname) } return false; +} + +char *UTIL_StringToLower(char *str) +{ + char *p; + for (p = str; *p != '\0'; ++p) + { + *p = tolower(*p); + } + + return str; } \ No newline at end of file diff --git a/dlls/cstrike/cstrike/CstrikeUtils.h b/dlls/cstrike/cstrike/CstrikeUtils.h index ec2c7bc4..4a58d5df 100644 --- a/dlls/cstrike/cstrike/CstrikeUtils.h +++ b/dlls/cstrike/cstrike/CstrikeUtils.h @@ -37,6 +37,7 @@ 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); #define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer) #define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue) diff --git a/dlls/cstrike/cstrike/amxx_api.cpp b/dlls/cstrike/cstrike/amxx_api.cpp index 67088517..e647add2 100644 --- a/dlls/cstrike/cstrike/amxx_api.cpp +++ b/dlls/cstrike/cstrike/amxx_api.cpp @@ -37,6 +37,7 @@ extern AMX_NATIVE_INFO cstrikeNatives[]; extern int g_CSCliCmdFwd; extern int g_CSBuyCmdFwd; +extern int g_CSBuyAttemptCmdFwd; void InitializeHacks(); void ShutdownHacks(); @@ -64,9 +65,10 @@ 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); + g_CSBuyAttemptCmdFwd = MF_RegisterForward("CS_OnBuyAttempt", ET_STOP, FP_CELL, FP_CELL, FP_DONE); ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand")); - ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy")); + ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy") || UTIL_CheckForPublic("CS_OnBuyAttempt")); } void OnAmxxDetach() diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index 21001ec1..294eb31e 100755 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -357,7 +357,7 @@ forward CS_InternalCommand(id, const cmd[]); /** - * The following constants are used with CS_OnBuy forward. + * The following constants are used with CS_OnBuy[Attempt] forwards. */ #define CSI_P228 CSW_P228 #define CSI_SCOUT CSW_SCOUT @@ -397,9 +397,22 @@ forward CS_InternalCommand(id, const cmd[]); /** * Called when a player attempts to purchase an item. - * Return PLUGIN_CONTINUE to allow the purchase or return a higher action to deny. + * This is ususally called right away on buy commands issued by a player. + * + * @note Return PLUGIN_CONTINUE to allow the purchase or return a higher action to deny. * * @param index Player index. * @param item Item index, see CSI_* constants. */ -forward CS_OnBuy(index, item); +forward CS_OnBuyAttempt(index, item); + +/** + * Called when a player purchases an item. + * This usually called right before a player gets the purchased item. + * + * @note Return PLUGIN_CONTINUE to allow the purchase or return a higher action to deny. + * + * @param index Player index. + * @param item Item index, see CSI_* constants. + */ +forward CS_OnBuy(index, item); \ No newline at end of file From 58774361bbce73ddd98087134fe1f7c81e5fac3a Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 4 Jul 2014 10:48:21 +0200 Subject: [PATCH 6/9] Cstrike: Make sure to execute forwards on alive players. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 1411fd38..f761def3 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -159,9 +159,10 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma } } + int client = ENTINDEX(pEdict); + if (*g_UseBotArgs) { - int client = ENTINDEX(pEdict); const char *args = *g_BotArgs; if (MF_ExecuteForward(g_CSCliCmdFwd, static_cast(client), args) > 0) @@ -170,7 +171,7 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma } } - if (g_CurrentItemId && MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast(ENTINDEX(pEdict)), static_cast(g_CurrentItemId)) > 0) + if (g_CurrentItemId && MF_IsPlayerAlive(client) && MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast(client), static_cast(g_CurrentItemId)) > 0) { return; } @@ -181,9 +182,14 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlayer::GiveNamedItem(const char *pszName) { // If the current item id is not null, this means player has triggers a buy command. - if (g_CurrentItemId && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(PrivateToIndex(this)), static_cast(g_CurrentItemId)) > 0) + if (g_CurrentItemId) { - return; + int client = PrivateToIndex(this); + + if (MF_IsPlayerAlive(client) && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(client), static_cast(g_CurrentItemId)) > 0) + { + return; + } } // From here, forward is not blocked, resetting this @@ -197,9 +203,14 @@ DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlay DETOUR_DECL_MEMBER1(GiveShield, void, bool, bRetire) // void CBasePlayer::GiveShield(bool bRetire) { // Special case for shield. Game doesn't use GiveNamedItem() to give a shield. - if (g_CurrentItemId == CSI_SHIELDGUN && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(PrivateToIndex(this)), CSI_SHIELDGUN) > 0) + if (g_CurrentItemId == CSI_SHIELDGUN) { - return; + int client = PrivateToIndex(this); + + if (MF_IsPlayerAlive(client) && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(client), CSI_SHIELDGUN) > 0) + { + return; + } } // From here, forward is not blocked, resetting this From 7cb004c728e6b2abf43bd9af9608ade3751f54d8 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 4 Jul 2014 16:57:25 +0200 Subject: [PATCH 7/9] Cstrike: Fix forwards [un]loading at map change. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 101 ++++++++++++++------------ dlls/cstrike/cstrike/amxx_api.cpp | 19 +++-- 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index f761def3..92fcf643 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -97,7 +97,7 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma // Purpose is to retrieve an item id based on alias name or selected item from menu, // to be used in OnBuy* forwards. - if (command && *command) + if ((g_CSBuyAttemptCmdFwd != -1 || g_CSBuyCmdFwd != -1) && command && *command) { // Just for safety. command = UTIL_StringToLower((char *)command); @@ -161,7 +161,7 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma int client = ENTINDEX(pEdict); - if (*g_UseBotArgs) + if (g_CSCliCmdFwd != -1 && *g_UseBotArgs) { const char *args = *g_BotArgs; @@ -171,7 +171,10 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma } } - if (g_CurrentItemId && MF_IsPlayerAlive(client) && MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast(client), static_cast(g_CurrentItemId)) > 0) + if (g_CSBuyAttemptCmdFwd != -1 && + g_CurrentItemId && + MF_IsPlayerAlive(client) && + MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast(client), static_cast(g_CurrentItemId)) > 0) { return; } @@ -263,6 +266,8 @@ void CtrlDetours_ClientCommand(bool set) { if (g_ClientCommandDetour) g_ClientCommandDetour->Destroy(); + + g_ItemAliasList.clear(); } } @@ -270,51 +275,6 @@ void ToggleDetour_ClientCommands(bool enable) { if (g_ClientCommandDetour) (enable) ? g_ClientCommandDetour->EnableDetour() : g_ClientCommandDetour->DisableDetour(); -} - - -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); - - g_GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, giveShieldAddress); - g_GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); - g_AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); - - if (g_GiveNamedItemDetour == NULL || g_AddAccountDetour == NULL) - { - MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); - } - } - else - { - if (g_GiveShieldDetour) - g_GiveShieldDetour->Destroy(); - - if (g_GiveNamedItemDetour) - g_GiveNamedItemDetour->Destroy(); - - if (g_AddAccountDetour) - g_AddAccountDetour->Destroy(); - - g_ItemAliasList.clear(); - } -} - -void ToggleDetour_BuyCommands(bool enable) -{ - if (g_GiveShieldDetour) - (enable) ? g_GiveShieldDetour->EnableDetour() : g_GiveShieldDetour->DisableDetour(); - - if (g_GiveNamedItemDetour) - (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); - - if (g_AddAccountDetour) - (enable) ? g_AddAccountDetour->EnableDetour() : g_AddAccountDetour->DisableDetour(); if (enable) { @@ -368,4 +328,49 @@ void ToggleDetour_BuyCommands(bool enable) { g_ItemAliasList.clear(); } +} + + +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); + + g_GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, giveShieldAddress); + g_GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); + g_AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); + + if (g_GiveNamedItemDetour == NULL || g_AddAccountDetour == NULL) + { + MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); + } + } + else + { + if (g_GiveShieldDetour) + g_GiveShieldDetour->Destroy(); + + if (g_GiveNamedItemDetour) + g_GiveNamedItemDetour->Destroy(); + + if (g_AddAccountDetour) + g_AddAccountDetour->Destroy(); + + g_ItemAliasList.clear(); + } +} + +void ToggleDetour_BuyCommands(bool enable) +{ + if (g_GiveShieldDetour) + (enable) ? g_GiveShieldDetour->EnableDetour() : g_GiveShieldDetour->DisableDetour(); + + if (g_GiveNamedItemDetour) + (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); + + if (g_AddAccountDetour) + (enable) ? g_AddAccountDetour->EnableDetour() : g_AddAccountDetour->DisableDetour(); } \ No newline at end of file diff --git a/dlls/cstrike/cstrike/amxx_api.cpp b/dlls/cstrike/cstrike/amxx_api.cpp index e647add2..07326782 100644 --- a/dlls/cstrike/cstrike/amxx_api.cpp +++ b/dlls/cstrike/cstrike/amxx_api.cpp @@ -63,12 +63,21 @@ void OnAmxxAttach() 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); - g_CSBuyAttemptCmdFwd = MF_RegisterForward("CS_OnBuyAttempt", ET_STOP, FP_CELL, FP_CELL, FP_DONE); + 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); + g_CSBuyAttemptCmdFwd = MF_RegisterForward("CS_OnBuyAttempt" , ET_STOP, FP_CELL, FP_CELL, FP_DONE); - ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand")); - ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy") || UTIL_CheckForPublic("CS_OnBuyAttempt")); + // Checking whether such public forwards are used in plugins. + // Resetting variable to -1 to avoid running unnecessary code in ClientCommand. + + if (!UTIL_CheckForPublic("CS_InternalCommand")) { g_CSCliCmdFwd = -1; } + if (!UTIL_CheckForPublic("CS_OnBuy")) { g_CSBuyCmdFwd = -1; } + if (!UTIL_CheckForPublic("CS_OnBuyAttempt")) { g_CSBuyAttemptCmdFwd = -1; } + + // And enable/disable detours when necessary. + + ToggleDetour_ClientCommands(g_CSCliCmdFwd != -1 || g_CSBuyCmdFwd != -1 || g_CSBuyCmdFwd != -1); + ToggleDetour_BuyCommands(g_CSBuyCmdFwd != -1); } void OnAmxxDetach() From c2c78f67249f1f888bd47bc7137b29863d119955 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sat, 5 Jul 2014 00:04:20 +0200 Subject: [PATCH 8/9] Cstrike: Random cleanup. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 126 ++++++++++++------------ dlls/cstrike/cstrike/CstrikeNatives.cpp | 2 +- dlls/cstrike/cstrike/amxx_api.cpp | 28 +++--- 3 files changed, 77 insertions(+), 79 deletions(-) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 92fcf643..8fb4b7cf 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -40,20 +40,20 @@ using namespace SourceMod; // hashmap void CtrlDetours_ClientCommand(bool set); void CtrlDetours_BuyCommands(bool set); -int g_CSCliCmdFwd = -1; -int g_CSBuyCmdFwd = -1; -int g_CSBuyAttemptCmdFwd = -1; +int ForwardInternalCommand = -1; +int ForwardOnBuy = -1; +int ForwardOnBuyAttempt = -1; -int *g_UseBotArgs = NULL; -const char **g_BotArgs = NULL; +int *UseBotArgs = NULL; +const char **BotArgs = NULL; -CDetour *g_ClientCommandDetour = NULL; -CDetour *g_GiveShieldDetour = NULL; -CDetour *g_GiveNamedItemDetour = NULL; -CDetour *g_AddAccountDetour = NULL; +CDetour *ClientCommandDetour = NULL; +CDetour *GiveShieldDetour = NULL; +CDetour *GiveNamedItemDetour = NULL; +CDetour *AddAccountDetour = NULL; -int g_CurrentItemId = 0; -StringHashMap g_ItemAliasList; +int CurrentItemId = 0; +StringHashMap ItemAliasList; void InitializeHacks() { @@ -75,11 +75,11 @@ void ShutdownHacks() const char *CMD_ARGV(int i) { - if (*g_UseBotArgs) + if (*UseBotArgs) { if (i < 4) { - return g_BotArgs[i]; + return BotArgs[i]; } return NULL; @@ -93,11 +93,11 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma const char *command = CMD_ARGV(0); // A new command is triggered, reset variable, always. - g_CurrentItemId = 0; + CurrentItemId = 0; // Purpose is to retrieve an item id based on alias name or selected item from menu, // to be used in OnBuy* forwards. - if ((g_CSBuyAttemptCmdFwd != -1 || g_CSBuyCmdFwd != -1) && command && *command) + if ((ForwardOnBuyAttempt != -1 || ForwardOnBuy != -1) && command && *command) { // Just for safety. command = UTIL_StringToLower((char *)command); @@ -145,36 +145,36 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma if (itemId) { - g_CurrentItemId = itemId; + CurrentItemId = itemId; } } } } else // Handling buy via alias { - if (g_ItemAliasList.retrieve(command, &itemId)) + if (ItemAliasList.retrieve(command, &itemId)) { - g_CurrentItemId = itemId; + CurrentItemId = itemId; } } } int client = ENTINDEX(pEdict); - if (g_CSCliCmdFwd != -1 && *g_UseBotArgs) + if (ForwardInternalCommand != -1 && *UseBotArgs) { - const char *args = *g_BotArgs; + const char *args = *BotArgs; - if (MF_ExecuteForward(g_CSCliCmdFwd, static_cast(client), args) > 0) + if (MF_ExecuteForward(ForwardInternalCommand, static_cast(client), args) > 0) { return; } } - if (g_CSBuyAttemptCmdFwd != -1 && - g_CurrentItemId && - MF_IsPlayerAlive(client) && - MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast(client), static_cast(g_CurrentItemId)) > 0) + if (ForwardOnBuyAttempt != -1 && + CurrentItemId && + MF_IsPlayerAlive(client) && + MF_ExecuteForward(ForwardOnBuyAttempt, static_cast(client), static_cast(CurrentItemId)) > 0) { return; } @@ -185,11 +185,11 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlayer::GiveNamedItem(const char *pszName) { // If the current item id is not null, this means player has triggers a buy command. - if (g_CurrentItemId) + if (CurrentItemId) { int client = PrivateToIndex(this); - if (MF_IsPlayerAlive(client) && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(client), static_cast(g_CurrentItemId)) > 0) + if (MF_IsPlayerAlive(client) && MF_ExecuteForward(ForwardOnBuy, static_cast(client), static_cast(CurrentItemId)) > 0) { return; } @@ -197,7 +197,7 @@ DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlay // From here, forward is not blocked, resetting this // to ignore code in AddAccount which is called right after. - g_CurrentItemId = 0; + CurrentItemId = 0; // Give me my item! DETOUR_MEMBER_CALL(GiveNamedItem)(pszName); @@ -206,11 +206,11 @@ DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlay DETOUR_DECL_MEMBER1(GiveShield, void, bool, bRetire) // void CBasePlayer::GiveShield(bool bRetire) { // Special case for shield. Game doesn't use GiveNamedItem() to give a shield. - if (g_CurrentItemId == CSI_SHIELDGUN) + if (CurrentItemId == CSI_SHIELDGUN) { int client = PrivateToIndex(this); - if (MF_IsPlayerAlive(client) && MF_ExecuteForward(g_CSBuyCmdFwd, static_cast(client), CSI_SHIELDGUN) > 0) + if (MF_IsPlayerAlive(client) && MF_ExecuteForward(ForwardOnBuy, static_cast(client), CSI_SHIELDGUN) > 0) { return; } @@ -218,7 +218,7 @@ DETOUR_DECL_MEMBER1(GiveShield, void, bool, bRetire) // void CBasePlayer::GiveSh // From here, forward is not blocked, resetting this // to ignore code in AddAccount which is called right after. - g_CurrentItemId = 0; + CurrentItemId = 0; // Give me my shield! DETOUR_MEMBER_CALL(GiveShield)(bRetire); @@ -228,13 +228,13 @@ DETOUR_DECL_MEMBER2(AddAccount, void, int, amount, bool, bTrackChange) // void C { // No buy command or forward not blocked. // Resuming game flow. - if (!g_CurrentItemId) + if (!CurrentItemId) { DETOUR_MEMBER_CALL(AddAccount)(amount, bTrackChange); } // Let's reset this right away to avoid issues. - g_CurrentItemId = 0; + CurrentItemId = 0; } @@ -246,35 +246,35 @@ void CtrlDetours_ClientCommand(bool set) #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); + UseBotArgs = *(int **)((unsigned char *)target + CS_CLICMD_OFFS_USEBOTARGS); + 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); + UseBotArgs = (int *)UTIL_FindAddressFromEntry(CS_IDENT_USEBOTARGS, CS_IDENT_HIDDEN_STATE); + BotArgs = (const char **)UTIL_FindAddressFromEntry(CS_IDENT_BOTARGS, CS_IDENT_HIDDEN_STATE); #endif - g_ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target); + ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target); - if (g_ClientCommandDetour == NULL) + if (ClientCommandDetour == NULL) { MF_Log("No Client Commands detour could be initialized - Disabled Client Command forward."); } } else { - if (g_ClientCommandDetour) - g_ClientCommandDetour->Destroy(); + if (ClientCommandDetour) + ClientCommandDetour->Destroy(); - g_ItemAliasList.clear(); + ItemAliasList.clear(); } } void ToggleDetour_ClientCommands(bool enable) { - if (g_ClientCommandDetour) - (enable) ? g_ClientCommandDetour->EnableDetour() : g_ClientCommandDetour->DisableDetour(); + if (ClientCommandDetour) + (enable) ? ClientCommandDetour->EnableDetour() : ClientCommandDetour->DisableDetour(); if (enable) { @@ -321,12 +321,12 @@ void ToggleDetour_ClientCommands(bool enable) for (size_t i = 0; aliasToId[i].alias != NULL; ++i) { - g_ItemAliasList.insert(aliasToId[i].alias, aliasToId[i].id); + ItemAliasList.insert(aliasToId[i].alias, aliasToId[i].id); } } else { - g_ItemAliasList.clear(); + ItemAliasList.clear(); } } @@ -339,38 +339,38 @@ void CtrlDetours_BuyCommands(bool set) void *giveNamedItemAddress = UTIL_FindAddressFromEntry(CS_IDENT_GIVENAMEDITEM, CS_IDENT_HIDDEN_STATE); void *addAccountAddress = UTIL_FindAddressFromEntry(CS_IDENT_ADDACCOUNT , CS_IDENT_HIDDEN_STATE); - g_GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, giveShieldAddress); - g_GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); - g_AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); + GiveShieldDetour = DETOUR_CREATE_MEMBER_FIXED(GiveShield, giveShieldAddress); + GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress); + AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress); - if (g_GiveNamedItemDetour == NULL || g_AddAccountDetour == NULL) + if (GiveNamedItemDetour == NULL || AddAccountDetour == NULL) { MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward."); } } else { - if (g_GiveShieldDetour) - g_GiveShieldDetour->Destroy(); + if (GiveShieldDetour) + GiveShieldDetour->Destroy(); - if (g_GiveNamedItemDetour) - g_GiveNamedItemDetour->Destroy(); + if (GiveNamedItemDetour) + GiveNamedItemDetour->Destroy(); - if (g_AddAccountDetour) - g_AddAccountDetour->Destroy(); + if (AddAccountDetour) + AddAccountDetour->Destroy(); - g_ItemAliasList.clear(); + ItemAliasList.clear(); } } void ToggleDetour_BuyCommands(bool enable) { - if (g_GiveShieldDetour) - (enable) ? g_GiveShieldDetour->EnableDetour() : g_GiveShieldDetour->DisableDetour(); + if (GiveShieldDetour) + (enable) ? GiveShieldDetour->EnableDetour() : GiveShieldDetour->DisableDetour(); - if (g_GiveNamedItemDetour) - (enable) ? g_GiveNamedItemDetour->EnableDetour() : g_GiveNamedItemDetour->DisableDetour(); + if (GiveNamedItemDetour) + (enable) ? GiveNamedItemDetour->EnableDetour() : GiveNamedItemDetour->DisableDetour(); - if (g_AddAccountDetour) - (enable) ? g_AddAccountDetour->EnableDetour() : g_AddAccountDetour->DisableDetour(); + if (AddAccountDetour) + (enable) ? AddAccountDetour->EnableDetour() : AddAccountDetour->DisableDetour(); } \ No newline at end of file diff --git a/dlls/cstrike/cstrike/CstrikeNatives.cpp b/dlls/cstrike/cstrike/CstrikeNatives.cpp index 980f2cc1..756998b6 100644 --- a/dlls/cstrike/cstrike/CstrikeNatives.cpp +++ b/dlls/cstrike/cstrike/CstrikeNatives.cpp @@ -1749,7 +1749,7 @@ static cell AMX_NATIVE_CALL not_on_64(AMX* amx, cell* params) #endif -AMX_NATIVE_INFO cstrikeNatives[] = { +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}, diff --git a/dlls/cstrike/cstrike/amxx_api.cpp b/dlls/cstrike/cstrike/amxx_api.cpp index 07326782..bd1c9c3a 100644 --- a/dlls/cstrike/cstrike/amxx_api.cpp +++ b/dlls/cstrike/cstrike/amxx_api.cpp @@ -33,11 +33,11 @@ #include "amxxmodule.h" #include "CstrikeUtils.h" -extern AMX_NATIVE_INFO cstrikeNatives[]; +extern AMX_NATIVE_INFO CstrikeNatives[]; -extern int g_CSCliCmdFwd; -extern int g_CSBuyCmdFwd; -extern int g_CSBuyAttemptCmdFwd; +extern int ForwardInternalCommand; +extern int ForwardOnBuy; +extern int ForwardOnBuyAttempt; void InitializeHacks(); void ShutdownHacks(); @@ -57,27 +57,25 @@ int AmxxCheckGame(const char *game) void OnAmxxAttach() { - MF_AddNatives(cstrikeNatives); + 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); - g_CSBuyAttemptCmdFwd = MF_RegisterForward("CS_OnBuyAttempt" , ET_STOP, FP_CELL, FP_CELL, FP_DONE); + ForwardInternalCommand = MF_RegisterForward("CS_InternalCommand", ET_STOP, FP_CELL, FP_STRING, FP_DONE); + ForwardOnBuy = MF_RegisterForward("CS_OnBuy" , ET_STOP, FP_CELL, FP_CELL, FP_DONE); + ForwardOnBuyAttempt = MF_RegisterForward("CS_OnBuyAttempt" , ET_STOP, FP_CELL, FP_CELL, FP_DONE); // Checking whether such public forwards are used in plugins. // Resetting variable to -1 to avoid running unnecessary code in ClientCommand. - - if (!UTIL_CheckForPublic("CS_InternalCommand")) { g_CSCliCmdFwd = -1; } - if (!UTIL_CheckForPublic("CS_OnBuy")) { g_CSBuyCmdFwd = -1; } - if (!UTIL_CheckForPublic("CS_OnBuyAttempt")) { g_CSBuyAttemptCmdFwd = -1; } + if (!UTIL_CheckForPublic("CS_InternalCommand")) { ForwardInternalCommand = -1; } + if (!UTIL_CheckForPublic("CS_OnBuy")) { ForwardOnBuy = -1; } + if (!UTIL_CheckForPublic("CS_OnBuyAttempt")) { ForwardOnBuyAttempt = -1; } // And enable/disable detours when necessary. - - ToggleDetour_ClientCommands(g_CSCliCmdFwd != -1 || g_CSBuyCmdFwd != -1 || g_CSBuyCmdFwd != -1); - ToggleDetour_BuyCommands(g_CSBuyCmdFwd != -1); + ToggleDetour_ClientCommands(ForwardInternalCommand != -1 || ForwardOnBuy != -1 || ForwardOnBuy != -1); + ToggleDetour_BuyCommands(ForwardOnBuy != -1); } void OnAmxxDetach() From 5eaeaa8dc113f9f167459238f595fdb68c9a5a38 Mon Sep 17 00:00:00 2001 From: xPaw Date: Thu, 17 Jul 2014 20:28:40 +0200 Subject: [PATCH 9/9] Cstrike: Fix compilation. --- dlls/cstrike/cstrike/CstrikeHacks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/dlls/cstrike/cstrike/CstrikeHacks.cpp index 8fb4b7cf..d20a9d59 100644 --- a/dlls/cstrike/cstrike/CstrikeHacks.cpp +++ b/dlls/cstrike/cstrike/CstrikeHacks.cpp @@ -282,7 +282,7 @@ void ToggleDetour_ClientCommands(bool enable) // Used in ClientCommand to check and get fastly item id from alias name. typedef struct { - char *alias; + const char *alias; int id; } itemBuyAliasInfo;