Fix CS_OnBuy* not triggered from alias containing uppercase letters

This commit is contained in:
Arkshine 2016-01-23 00:09:04 +01:00
parent 60ebc444ab
commit fafa1f11f0
3 changed files with 25 additions and 1 deletions

View File

@ -158,8 +158,11 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
if (get_pdata<CUnifiedSignals>(pEdict, SignalsDesc.fieldOffset).GetState() & SIGNAL_BUY) // Are we inside the buy zone?
{
AliasInfo info;
char commandLowered[32];
if (ItemsManager.GetAliasInfosFromBuy(command, &info))
UTIL_StringToLower(command, commandLowered, sizeof(commandLowered));
if (ItemsManager.GetAliasInfosFromBuy(commandLowered, &info))
{
CurrentItemId = info.itemid;
}

View File

@ -12,6 +12,7 @@
//
#include "amxxmodule.h"
#include <amtl/am-algorithm.h>
extern int MessageIdTextMsg;
@ -47,3 +48,22 @@ bool UTIL_CheckForPublic(const char *publicname)
return false;
}
void UTIL_StringToLower(const char *str, char *buffer, size_t maxlength)
{
auto length = ke::Min(strlen(str), maxlength - 1);
for (size_t i = 0; i < length; ++i)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
buffer[i] = tolower(str[i]);
}
else
{
buffer[i] = str[i];
}
}
buffer[length] = '\0';
}

View File

@ -21,6 +21,7 @@ extern HLTypeConversion TypeConversion;
bool UTIL_IsPlayer(edict_t *pPlayer);
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message);
bool UTIL_CheckForPublic(const char *publicname);
void UTIL_StringToLower(const char *str, char *buffer, size_t maxlength);
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)