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