diff --git a/modules/cstrike/cstrike/AMBuilder b/modules/cstrike/cstrike/AMBuilder index bae60bed..44d9698d 100644 --- a/modules/cstrike/cstrike/AMBuilder +++ b/modules/cstrike/cstrike/AMBuilder @@ -14,6 +14,7 @@ binary.sources = [ 'CstrikeNatives.cpp', 'CstrikeHacks.cpp', 'CstrikeUtils.cpp', + 'CstrikeUserMessages.cpp', 'CstrikeHLTypeConversion.cpp', '../../../public/memtools/MemoryUtils.cpp', '../../../public/memtools/CDetour/detours.cpp', diff --git a/modules/cstrike/cstrike/CstrikeHacks.h b/modules/cstrike/cstrike/CstrikeHacks.h index b6d6769f..347f3223 100644 --- a/modules/cstrike/cstrike/CstrikeHacks.h +++ b/modules/cstrike/cstrike/CstrikeHacks.h @@ -23,15 +23,6 @@ void ShutdownHacks(); void ToggleDetour_ClientCommands(bool enable); void ToggleDetour_BuyCommands(bool enable); -extern int MessageIdArmorType; -extern int MessageIdMoney; -extern int MessageIdResetHUD; -extern int MessageIdScoreAttrib; -extern int MessageIdScoreInfo; -extern int MessageIdStatusIcon; -extern int MessageIdTeamInfo; -extern int MessageIdTextMsg; - extern AMX_NATIVE_INFO CstrikeNatives[]; extern IGameConfig *MainConfig; diff --git a/modules/cstrike/cstrike/CstrikeNatives.cpp b/modules/cstrike/cstrike/CstrikeNatives.cpp index 897f5775..26667767 100644 --- a/modules/cstrike/cstrike/CstrikeNatives.cpp +++ b/modules/cstrike/cstrike/CstrikeNatives.cpp @@ -15,23 +15,15 @@ #include "CstrikePlayer.h" #include "CstrikeUtils.h" #include "CstrikeHacks.h" +#include "CstrikeUserMessages.h" #include "CstrikeHLTypeConversion.h" #include CCstrikePlayer g_players[33]; -int g_zooming[33] = {0}; +int Zooming[33]; bool NoKifesMode = false; -int MessageIdArmorType; -int MessageIdMoney; -int MessageIdResetHUD; -int MessageIdScoreAttrib; -int MessageIdScoreInfo; -int MessageIdStatusIcon; -int MessageIdTeamInfo; -int MessageIdTextMsg; - // native cs_set_user_money(index, money, flash = 1); static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) { @@ -879,6 +871,8 @@ static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params) g_players[index].SetModel(modelName); g_players[index].SetModelled(true); + EnableMessageHooks(); + SETCLIENTKEYVALUE(index, GETINFOKEYBUFFER(pPlayer), "model", const_cast(g_players[index].GetModel())); return 1; @@ -1323,7 +1317,7 @@ static cell AMX_NATIVE_CALL cs_set_user_zoom(AMX *amx, cell *params) int mode = params[3]; int weapon = *static_cast(MF_PlayerPropAddr(index, Player_CurrentWeapon)); - g_zooming[index] = 0; + Zooming[index] = 0; if (type == CS_RESET_ZOOM) { @@ -1371,7 +1365,8 @@ static cell AMX_NATIVE_CALL cs_set_user_zoom(AMX *amx, cell *params) if (!mode) { - g_zooming[index] = value; + Zooming[index] = value; + EnableMessageHooks(); } set_pdata(pPlayer, m_iFOV, value); @@ -1772,31 +1767,11 @@ AMX_NATIVE_INFO CstrikeNatives[] = {nullptr, nullptr} }; -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 == MessageIdResetHUD) - { - int entityIndex = ENTINDEX(ed); - - if (g_zooming[entityIndex]) - g_zooming[entityIndex] = 0; - - if(g_players[entityIndex].GetModelled()) - g_players[entityIndex].SetInspectModel(true); - //g_players[ENTINDEX(ed)].SetTime(gpGlobals->time + MODELRESETTIME); - } - - RETURN_META(MRES_IGNORED); -} - - -/***GetEntityAPI2******************/ void ClientDisconnect(edict_t *pEntity) { int index = ENTINDEX(pEntity); g_players[index].SetModelled(false); - g_zooming[index] = 0; + Zooming[index] = 0; RETURN_META(MRES_IGNORED); } @@ -1830,16 +1805,3 @@ void PlayerPostThink(edict_t* pPlayer) } RETURN_META(MRES_IGNORED); } - -void PlayerPreThink(edict_t *pPlayer) -{ - GET_OFFSET_NO_ERROR("CBasePlayer", m_iFOV); - - int entityIndex = ENTINDEX(pPlayer); - if (g_zooming[entityIndex]) - { - set_pdata(pPlayer, m_iFOV, g_zooming[entityIndex]); - } - - RETURN_META(MRES_IGNORED); -} diff --git a/modules/cstrike/cstrike/CstrikePlayer.h b/modules/cstrike/cstrike/CstrikePlayer.h index 0674192d..e021beb3 100644 --- a/modules/cstrike/cstrike/CstrikePlayer.h +++ b/modules/cstrike/cstrike/CstrikePlayer.h @@ -34,4 +34,7 @@ private: char model[32]; }; +extern CCstrikePlayer g_players[33]; +extern int Zooming[33]; + #endif // !defined(INCLUDED_CCSTRIKEPLAYER) diff --git a/modules/cstrike/cstrike/CstrikeUserMessages.cpp b/modules/cstrike/cstrike/CstrikeUserMessages.cpp new file mode 100644 index 00000000..41d74ef6 --- /dev/null +++ b/modules/cstrike/cstrike/CstrikeUserMessages.cpp @@ -0,0 +1,157 @@ +// vim: set ts=4 sw=4 tw=99 noet: +// +// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). +// Copyright (C) The AMX Mod X Development Team. +// +// This software is licensed under the GNU General Public License, version 3 or higher. +// Additional exceptions apply. For full license details, see LICENSE.txt or visit: +// https://alliedmods.net/amxmodx-license + +// +// Counter-Strike Module +// + +#include +#include "CstrikeUserMessages.h" +#include "CstrikeUtils.h" +#include "CstrikeHacks.h" +#include "CstrikePlayer.h" + +bool ShouldBlock; +bool ShouldBlockHLTV; + +int MessageIdArmorType; +int MessageIdHLTV; +int MessageIdMoney; +int MessageIdResetHUD; +int MessageIdScoreAttrib; +int MessageIdScoreInfo; +int MessageIdSetFOV; +int MessageIdStatusIcon; +int MessageIdTeamInfo; +int MessageIdTextMsg; + +struct UserMsg +{ + const char* name; + int* id; +}; + +UserMsg MessagesList[] = +{ + { "ArmorType" , &MessageIdArmorType }, + { "HLTV" , &MessageIdHLTV }, + { "CurWeapon" , &MessageIdMoney }, + { "ResetHUD" , &MessageIdResetHUD }, + { "ScoreAttrib", &MessageIdScoreAttrib }, + { "ScoreInfo" , &MessageIdScoreInfo }, + { "SetFOV" , &MessageIdSetFOV }, + { "StatusIcon" , &MessageIdStatusIcon }, + { "TeamInfo" , &MessageIdTeamInfo }, + { "TextMsg" , &MessageIdTextMsg }, + { nullptr , nullptr } +}; + +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 OnMessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *pEntity) +{ + switch (msg_dest) + { + case MSG_ONE: + case MSG_ONE_UNRELIABLE: + { + if (msg_type == MessageIdSetFOV) + { + int index = ENTINDEX(pEntity); + + if (Zooming[index]) + { + GET_OFFSET_NO_ERROR("CBasePlayer", m_iFOV); + + if (get_pdata(pEntity, m_iFOV) != Zooming[index]) + { + set_pdata(pEntity, m_iFOV, Zooming[index]); + + ShouldBlock = true; + ShouldBlockHLTV = true; + + RETURN_META(MRES_SUPERCEDE); + } + } + } + else if (msg_type == MessageIdResetHUD) + { + int index = ENTINDEX(pEntity); + + if (Zooming[index]) + Zooming[index] = 0; + + if (g_players[index].GetModelled()) + g_players[index].SetInspectModel(true); + } + break; + } + case MSG_SPEC: + { + if (msg_type == MessageIdHLTV && ShouldBlockHLTV) + { + ShouldBlock = true; + ShouldBlockHLTV = false; + + RETURN_META(MRES_SUPERCEDE); + } + break; + } + } + + if (ShouldBlockHLTV) + { + ShouldBlockHLTV = false; + } + + RETURN_META(MRES_IGNORED); +} + +void OnWriteByte(int iValue) +{ + if (ShouldBlock) + { + RETURN_META(MRES_SUPERCEDE); + } + + RETURN_META(MRES_IGNORED); +} + +void OnMessageEnd(void) +{ + if (ShouldBlock) + { + ShouldBlock = false; + RETURN_META(MRES_SUPERCEDE); + } + + RETURN_META(MRES_IGNORED); +} + +void EnableMessageHooks() +{ + if (!g_pengfuncsTable->pfnMessageBegin) + { + g_pengfuncsTable->pfnMessageBegin = OnMessageBegin; + g_pengfuncsTable->pfnWriteByte = OnWriteByte; + g_pengfuncsTable->pfnMessageEnd = OnMessageEnd; + } +} diff --git a/modules/cstrike/cstrike/CstrikeUserMessages.h b/modules/cstrike/cstrike/CstrikeUserMessages.h new file mode 100644 index 00000000..7c1a66ac --- /dev/null +++ b/modules/cstrike/cstrike/CstrikeUserMessages.h @@ -0,0 +1,30 @@ +// vim: set ts=4 sw=4 tw=99 noet: +// +// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). +// Copyright (C) The AMX Mod X Development Team. +// +// This software is licensed under the GNU General Public License, version 3 or higher. +// Additional exceptions apply. For full license details, see LICENSE.txt or visit: +// https://alliedmods.net/amxmodx-license + +// +// Counter-Strike Module +// + +#ifndef CSTRIKE_USER_MESSAGES_H +#define CSTRIKE_USER_MESSAGES_H + +extern int MessageIdArmorType; +extern int MessageIdHLTV; +extern int MessageIdMoney; +extern int MessageIdResetHUD; +extern int MessageIdScoreAttrib; +extern int MessageIdScoreInfo; +extern int MessageIdSetFOV; +extern int MessageIdStatusIcon; +extern int MessageIdTeamInfo; +extern int MessageIdTextMsg; + +void EnableMessageHooks(); + +#endif // CSTRIKE_USER_MESSAGES_H diff --git a/modules/cstrike/cstrike/amxx_api.cpp b/modules/cstrike/cstrike/amxx_api.cpp index 2a2c9652..a5c059b0 100644 --- a/modules/cstrike/cstrike/amxx_api.cpp +++ b/modules/cstrike/cstrike/amxx_api.cpp @@ -22,25 +22,6 @@ IGameConfig *MainConfig; IGameConfig *OffsetConfig; IGameConfigManager *ConfigManager; -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 , nullptr } -}; - int AmxxCheckGame(const char *game) { if (strcasecmp(game, "cstrike") == 0 || @@ -100,20 +81,6 @@ 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 0ecc408a..42cdde5c 100644 --- a/modules/cstrike/cstrike/moduleconfig.h +++ b/modules/cstrike/cstrike/moduleconfig.h @@ -125,7 +125,7 @@ #define FN_ClientUserInfoChanged ClientUserInfoChanged /* pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure */ // #define FN_ServerActivate ServerActivate /* pfnServerActivate() (wd) Server is starting a new map */ // #define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */ -#define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */ +// #define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */ #define FN_PlayerPostThink PlayerPostThink /* pfnPlayerPostThink() */ // #define FN_StartFrame StartFrame /* pfnStartFrame() */ // #define FN_ParmsNewLevel ParmsNewLevel /* pfnParmsNewLevel() */ @@ -252,7 +252,7 @@ // #define FN_LightStyle LightStyle // #define FN_DecalIndex DecalIndex // #define FN_PointContents PointContents -#define FN_MessageBegin MessageBegin +// #define FN_MessageBegin MessageBegin // #define FN_MessageEnd MessageEnd // #define FN_WriteByte WriteByte // #define FN_WriteChar WriteChar diff --git a/modules/cstrike/cstrike/msvc12/cstrike.vcxproj b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj index d62bbb55..536e5df5 100644 --- a/modules/cstrike/cstrike/msvc12/cstrike.vcxproj +++ b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj @@ -149,6 +149,7 @@ + @@ -160,6 +161,7 @@ + diff --git a/modules/cstrike/cstrike/msvc12/cstrike.vcxproj.filters b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj.filters index 29a31039..81ae3dbf 100644 --- a/modules/cstrike/cstrike/msvc12/cstrike.vcxproj.filters +++ b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj.filters @@ -59,6 +59,9 @@ Source Files + + Source Files + @@ -91,6 +94,9 @@ Header Files + + Header Files +