Cstrike: Cache GET_USER_MSG_ID calls

This commit is contained in:
Arkshine 2015-07-03 19:28:26 +02:00
parent 84c320d539
commit f13461caee
4 changed files with 68 additions and 17 deletions

View File

@ -24,6 +24,14 @@ bool g_noknives = false;
extern CreateNamedEntityFunc CS_CreateNamedEntity; extern CreateNamedEntityFunc CS_CreateNamedEntity;
extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString; 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); // native cs_set_user_money(index, money, flash = 1);
static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) 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<int>(pPlayer, m_iAccount, money); set_pdata<int>(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_LONG(money);
WRITE_BYTE(flash); WRITE_BYTE(flash);
MESSAGE_END(); MESSAGE_END();
@ -86,7 +94,7 @@ static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params)
set_pdata<int>(pPlayer, m_iDeaths, deaths); set_pdata<int>(pPlayer, m_iDeaths, deaths);
MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "ScoreInfo", nullptr)); MESSAGE_BEGIN(MSG_ALL, MessageIdScoreInfo);
WRITE_BYTE(index); WRITE_BYTE(index);
WRITE_SHORT(static_cast<int>(pPlayer->v.frags)); WRITE_SHORT(static_cast<int>(pPlayer->v.frags));
WRITE_SHORT(deaths); 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) 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); WRITE_BYTE(type == CS_ARMOR_ASSAULTSUIT ? 1 : 0);
MESSAGE_END(); 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; 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(index);
WRITE_BYTE(scoreattrib); WRITE_BYTE(scoreattrib);
MESSAGE_END(); 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); 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_BYTE(index);
WRITE_STRING(teaminfo); WRITE_STRING(teaminfo);
MESSAGE_END(); MESSAGE_END();
@ -567,7 +575,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params)
{ {
if (icon) 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_BYTE(1);
WRITE_STRING("c4"); WRITE_STRING("c4");
WRITE_BYTE(DEFUSER_COLOUR_R); WRITE_BYTE(DEFUSER_COLOUR_R);
@ -578,7 +586,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params)
} }
else 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_BYTE(0);
WRITE_STRING("c4"); WRITE_STRING("c4");
MESSAGE_END(); 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); 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_BYTE(params[7] == 1 ? 2 : 1);
WRITE_STRING(icon); WRITE_STRING(icon);
WRITE_BYTE(colour[0]); WRITE_BYTE(colour[0]);
@ -649,7 +657,7 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params)
} }
else 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_BYTE(0);
WRITE_STRING("defuser"); WRITE_STRING("defuser");
MESSAGE_END(); MESSAGE_END();
@ -979,7 +987,7 @@ static cell AMX_NATIVE_CALL cs_set_user_tked(AMX *amx, cell *params)
{ {
pPlayer->v.frags -= subtract; pPlayer->v.frags -= subtract;
MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "ScoreInfo", nullptr)); MESSAGE_BEGIN(MSG_ALL, MessageIdScoreInfo);
WRITE_BYTE(index); WRITE_BYTE(index);
WRITE_SHORT(static_cast<int>(pPlayer->v.frags)); WRITE_SHORT(static_cast<int>(pPlayer->v.frags));
WRITE_SHORT(get_pdata<int>(pPlayer, m_iDeaths)); WRITE_SHORT(get_pdata<int>(pPlayer, m_iDeaths));
@ -1500,8 +1508,6 @@ static cell AMX_NATIVE_CALL cs_set_c4_defusing(AMX* amx, cell* params)
return 1; return 1;
} }
// cs_create_entity(const classname[]) // cs_create_entity(const classname[])
static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params) static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params)
{ {
@ -1641,7 +1647,7 @@ void FN_ServerDeactivate()
void MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) 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. // 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); int entityIndex = ENTINDEX(ed);

View File

@ -14,6 +14,8 @@
#include "amxxmodule.h" #include "amxxmodule.h"
#include "MemoryUtils.h" #include "MemoryUtils.h"
extern int MessageIdTextMsg;
bool UTIL_IsPlayer(edict_t *pPlayer) bool UTIL_IsPlayer(edict_t *pPlayer)
{ {
return strcmp(STRING(pPlayer->v.classname), "player") == 0; 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) 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_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center, 5 = radio
WRITE_STRING(message); WRITE_STRING(message);
MESSAGE_END(); MESSAGE_END();

View File

@ -35,6 +35,35 @@ IGameConfig *MainConfig;
IGameConfig *OffsetConfig; IGameConfig *OffsetConfig;
IGameConfigManager *ConfigManager; 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) int AmxxCheckGame(const char *game)
{ {
if (strcasecmp(game, "cstrike") == 0 || 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() void OnAmxxDetach()
{ {
ConfigManager->CloseGameConfigFile(MainConfig); ConfigManager->CloseGameConfigFile(MainConfig);

View File

@ -427,7 +427,7 @@
// #define FN_PEntityOfEntIndex_Post PEntityOfEntIndex_Post // #define FN_PEntityOfEntIndex_Post PEntityOfEntIndex_Post
// #define FN_FindEntityByVars_Post FindEntityByVars_Post // #define FN_FindEntityByVars_Post FindEntityByVars_Post
// #define FN_GetModelPtr_Post GetModelPtr_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_AnimationAutomove_Post AnimationAutomove_Post
// #define FN_GetBonePosition_Post GetBonePosition_Post // #define FN_GetBonePosition_Post GetBonePosition_Post
// #define FN_FunctionFromName_Post FunctionFromName_Post // #define FN_FunctionFromName_Post FunctionFromName_Post