From f13461caee6a21a141a95757ebf8c71de899e4da Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 3 Jul 2015 19:28:26 +0200 Subject: [PATCH] Cstrike: Cache GET_USER_MSG_ID calls --- modules/cstrike/cstrike/CstrikeNatives.cpp | 36 ++++++++++-------- modules/cstrike/cstrike/CstrikeUtils.cpp | 4 +- modules/cstrike/cstrike/amxx_api.cpp | 43 ++++++++++++++++++++++ modules/cstrike/cstrike/moduleconfig.h | 2 +- 4 files changed, 68 insertions(+), 17 deletions(-) diff --git a/modules/cstrike/cstrike/CstrikeNatives.cpp b/modules/cstrike/cstrike/CstrikeNatives.cpp index 6ab8d8e7..1f0d3eed 100644 --- a/modules/cstrike/cstrike/CstrikeNatives.cpp +++ b/modules/cstrike/cstrike/CstrikeNatives.cpp @@ -21,9 +21,17 @@ int g_zooming[33] = {0}; bool g_precachedknife = false; bool g_noknives = false; -extern CreateNamedEntityFunc CS_CreateNamedEntity; +extern CreateNamedEntityFunc CS_CreateNamedEntity; extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString; +extern int MessageIdMoney; +extern int MessageIdScoreInfo; +extern int MessageIdArmorType; +extern int MessageIdTeamInfo; +extern int MessageIdStatusIcon; +extern int MessageIdScoreAttrib; +extern int MessageIdResetHUD; + // native cs_set_user_money(index, money, flash = 1); static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) { @@ -38,7 +46,7 @@ static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) set_pdata(pPlayer, m_iAccount, money); - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "Money", nullptr), nullptr, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdMoney, nullptr, pPlayer); WRITE_LONG(money); WRITE_BYTE(flash); MESSAGE_END(); @@ -86,7 +94,7 @@ static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params) set_pdata(pPlayer, m_iDeaths, deaths); - MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "ScoreInfo", nullptr)); + MESSAGE_BEGIN(MSG_ALL, MessageIdScoreInfo); WRITE_BYTE(index); WRITE_SHORT(static_cast(pPlayer->v.frags)); WRITE_SHORT(deaths); @@ -352,7 +360,7 @@ static cell AMX_NATIVE_CALL cs_set_user_armor(AMX *amx, cell *params) if (type == CS_ARMOR_KEVLAR || type == CS_ARMOR_ASSAULTSUIT) { - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "ArmorType", nullptr), nullptr, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdArmorType, nullptr, pPlayer); WRITE_BYTE(type == CS_ARMOR_ASSAULTSUIT ? 1 : 0); MESSAGE_END(); } @@ -428,7 +436,7 @@ static cell AMX_NATIVE_CALL cs_set_user_vip(AMX *amx, cell *params) scoreattrib = (pPlayer->v.deadflag == DEAD_NO && pPlayer->v.health > 0) ? SCOREATTRIB_NOTHING : SCOREATTRIB_DEAD; } - MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "ScoreAttrib", nullptr)); + MESSAGE_BEGIN(MSG_ALL, MessageIdScoreAttrib); WRITE_BYTE(index); WRITE_BYTE(scoreattrib); MESSAGE_END(); @@ -490,7 +498,7 @@ static cell AMX_NATIVE_CALL cs_set_user_team(AMX *amx, cell *params) default: sprintf(teaminfo, "TEAM_%i", team); } - MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "TeamInfo", nullptr)); + MESSAGE_BEGIN(MSG_ALL, MessageIdTeamInfo); WRITE_BYTE(index); WRITE_STRING(teaminfo); MESSAGE_END(); @@ -567,7 +575,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params) { if (icon) { - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", nullptr), nullptr, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdStatusIcon, nullptr, pPlayer); WRITE_BYTE(1); WRITE_STRING("c4"); WRITE_BYTE(DEFUSER_COLOUR_R); @@ -578,7 +586,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params) } else { - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", nullptr), nullptr, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdStatusIcon, nullptr, pPlayer); WRITE_BYTE(0); WRITE_STRING("c4"); MESSAGE_END(); @@ -639,7 +647,7 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) icon = MF_GetAmxString(amx, params[6], 1, &length); } - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", nullptr), nullptr, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdStatusIcon, nullptr, pPlayer); WRITE_BYTE(params[7] == 1 ? 2 : 1); WRITE_STRING(icon); WRITE_BYTE(colour[0]); @@ -649,7 +657,7 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) } else { - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", nullptr), nullptr, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdStatusIcon, nullptr, pPlayer); WRITE_BYTE(0); WRITE_STRING("defuser"); MESSAGE_END(); @@ -979,7 +987,7 @@ static cell AMX_NATIVE_CALL cs_set_user_tked(AMX *amx, cell *params) { pPlayer->v.frags -= subtract; - MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "ScoreInfo", nullptr)); + MESSAGE_BEGIN(MSG_ALL, MessageIdScoreInfo); WRITE_BYTE(index); WRITE_SHORT(static_cast(pPlayer->v.frags)); WRITE_SHORT(get_pdata(pPlayer, m_iDeaths)); @@ -1500,8 +1508,6 @@ static cell AMX_NATIVE_CALL cs_set_c4_defusing(AMX* amx, cell* params) return 1; } - - // cs_create_entity(const classname[]) static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params) { @@ -1612,7 +1618,7 @@ AMX_NATIVE_INFO CstrikeNatives[] = {"cs_create_entity", cs_create_entity }, {"cs_find_ent_by_class", cs_find_ent_by_class}, - {nullptr, nullptr} + {nullptr, nullptr} }; edict_s* FN_CreateNamedEntity(int classname) @@ -1641,7 +1647,7 @@ void FN_ServerDeactivate() void MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) { // Reset player model a short while (MODELRESETTIME) after this if they are using an edited model. - if(msg_type == GET_USER_MSG_ID(PLID, "ResetHUD", NULL)) + if(msg_type == MessageIdResetHUD) { int entityIndex = ENTINDEX(ed); diff --git a/modules/cstrike/cstrike/CstrikeUtils.cpp b/modules/cstrike/cstrike/CstrikeUtils.cpp index 316b2ba0..f56fd685 100644 --- a/modules/cstrike/cstrike/CstrikeUtils.cpp +++ b/modules/cstrike/cstrike/CstrikeUtils.cpp @@ -14,6 +14,8 @@ #include "amxxmodule.h" #include "MemoryUtils.h" +extern int MessageIdTextMsg; + bool UTIL_IsPlayer(edict_t *pPlayer) { return strcmp(STRING(pPlayer->v.classname), "player") == 0; @@ -21,7 +23,7 @@ bool UTIL_IsPlayer(edict_t *pPlayer) void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message) { - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pPlayer); + MESSAGE_BEGIN(MSG_ONE, MessageIdTextMsg, nullptr, pPlayer); WRITE_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center, 5 = radio WRITE_STRING(message); MESSAGE_END(); diff --git a/modules/cstrike/cstrike/amxx_api.cpp b/modules/cstrike/cstrike/amxx_api.cpp index b1104005..07ac0fac 100644 --- a/modules/cstrike/cstrike/amxx_api.cpp +++ b/modules/cstrike/cstrike/amxx_api.cpp @@ -35,6 +35,35 @@ IGameConfig *MainConfig; IGameConfig *OffsetConfig; IGameConfigManager *ConfigManager; +int MessageIdArmorType; +int MessageIdMoney; +int MessageIdResetHUD; +int MessageIdScoreAttrib; +int MessageIdScoreInfo; +int MessageIdStatusIcon; +int MessageIdTeamInfo; +int MessageIdTextMsg; + +struct UserMsg +{ + const char* name; + int* id; +}; + +UserMsg MessagesList[] = +{ + { "ArmorType" , &MessageIdArmorType }, + { "CurWeapon" , &MessageIdMoney }, + { "ResetHUD" , &MessageIdResetHUD }, + { "ScoreAttrib", &MessageIdScoreAttrib }, + { "ScoreInfo" , &MessageIdScoreInfo }, + { "StatusIcon" , &MessageIdStatusIcon }, + { "TeamInfo" , &MessageIdTeamInfo }, + { "TextMsg" , &MessageIdTextMsg }, + { nullptr , 0 } +}; + + int AmxxCheckGame(const char *game) { if (strcasecmp(game, "cstrike") == 0 || @@ -116,6 +145,20 @@ void OnPluginsLoaded() } } +int OnRegUserMsg_Post(const char *pszName, int iSize) +{ + for (size_t i = 0; MessagesList[i].name; ++i) + { + if (!*MessagesList[i].id && strcmp(MessagesList[i].name, pszName) == 0) + { + *MessagesList[i].id = META_RESULT_ORIG_RET(int); + break; + } + } + + RETURN_META_VALUE(MRES_IGNORED, 0); +} + void OnAmxxDetach() { ConfigManager->CloseGameConfigFile(MainConfig); diff --git a/modules/cstrike/cstrike/moduleconfig.h b/modules/cstrike/cstrike/moduleconfig.h index 52de1dfd..24db01f9 100644 --- a/modules/cstrike/cstrike/moduleconfig.h +++ b/modules/cstrike/cstrike/moduleconfig.h @@ -427,7 +427,7 @@ // #define FN_PEntityOfEntIndex_Post PEntityOfEntIndex_Post // #define FN_FindEntityByVars_Post FindEntityByVars_Post // #define FN_GetModelPtr_Post GetModelPtr_Post -// #define FN_RegUserMsg_Post RegUserMsg_Post +#define FN_RegUserMsg_Post OnRegUserMsg_Post // #define FN_AnimationAutomove_Post AnimationAutomove_Post // #define FN_GetBonePosition_Post GetBonePosition_Post // #define FN_FunctionFromName_Post FunctionFromName_Post