From b06b1915eb23c363e0822a7196e81ffa01550481 Mon Sep 17 00:00:00 2001 From: asmodai Date: Sat, 17 Jun 2017 00:51:33 +0300 Subject: [PATCH] Add hook for SV_WriteFullClientUpdate (cherry picked from commit 77f6cfb8a713937c0ab424353a6ab83c08fb977d) # Conflicts: # reapi/src/hook_list.cpp --- gradle.properties | 2 +- .../scripting/include/reapi_engine.inc | 25 +++++++++++++++++++ .../scripting/include/reapi_engine_const.inc | 6 +++++ reapi/src/hook_callback.cpp | 20 +++++++++++++++ reapi/src/hook_callback.h | 1 + reapi/src/hook_list.cpp | 19 +++++++------- reapi/src/hook_list.h | 1 + reapi/src/natives/natives_misc.cpp | 24 ++++++++++++++++++ reapi/src/natives/natives_misc.h | 6 +++++ 9 files changed, 94 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8ab1c25..819bae3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ majorVersion=5 -minorVersion=1 +minorVersion=2 maintenanceVersion=0 diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index 803bf30..23a8db0 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -88,3 +88,28 @@ native bool:rh_emit_sound2(const entity, const recipient, const channel, const s * @noreturn */ native rh_update_user_info(playerEntIndex); + +/* +* Gets value for key in buffer +* +* @param pbuffer Pointer to buffer +* @param key Key string +* @param value Buffer to copy value to +* @param maxlen Maximum size of the buffer +* +* @return Number of cells written to buffer +* @error If the index is not within the range of 1 to MaxClients or +* the client is not connected, an error will be thrown. +*/ +native rh_get_key_value(const pbuffer, const key[], value[], maxlen) + +/* +* Sets value for key in buffer +* +* @param pbuffer Pointer to buffer +* @param key Key string +* @param value Value to set +* +* @noreturn +*/ +native rh_set_key_value(const pbuffer, const key[], const value[]) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 95fe9ed..1974acf 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -40,6 +40,12 @@ enum EngineFunc * Params: (pcvar, const value[]) */ RH_Cvar_DirectSet, + + /* + * Description: Receiver is player index or 0 when update will be sended to all. + * Params: (client, receiver, pinfo) + */ + RH_SV_WriteFullClientUpdate, }; enum EntVars diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index c5162f3..1152b75 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -46,6 +46,26 @@ void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char * callVoidForward(RH_Cvar_DirectSet, original, var, value); } +void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGameClient *client, char *info, size_t maxlen, sizebuf_t *sb, IGameClient *receiver) +{ + int receiver_id = 0; + if (receiver) + receiver_id = receiver->GetId() + 1; + + auto original = [chain, sb](int _client, int _receiver, int _pinfo) + { + sizebuf_t* dest = sb; + IGameClient* receiver = nullptr; + if (_receiver) { + receiver = g_RehldsSvs->GetClient(_receiver - 1); + dest = receiver->GetNetChan()->GetMessageBuf(); + } + chain->callNext(g_RehldsSvs->GetClient(_client - 1), (char *)_pinfo, MAX_INFO_STRING, dest, receiver); + }; + + callVoidForward(RH_SV_WriteFullClientUpdate, original, client->GetId() + 1, receiver_id, int(info)); +} + /* * ReGameDLL functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index d7b4195..8dee606 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -299,6 +299,7 @@ void SV_StartSound(IRehldsHook_SV_StartSound *chain, int recipients, edict_t *en void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *fmt); void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics); void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char *value); +void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGameClient *client, char *info, size_t maxlen, sizebuf_t *sb, IGameClient *receiver); // regamedll functions int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver); diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 1559795..be0eb9c 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -1,13 +1,13 @@ #include "precompiled.h" -inline size_t getFwdParamType(void(*)(int)) { return FP_CELL; } -inline size_t getFwdParamType(void(*)(short)) { return FP_CELL; } -inline size_t getFwdParamType(void(*)(bool)) { return FP_CELL; } -inline size_t getFwdParamType(void(*)(uint32)) { return FP_CELL; } -inline size_t getFwdParamType(void(*)(Vector&)) { return FP_ARRAY; } -inline size_t getFwdParamType(void(*)(PLAYER_ANIM)) { return FP_CELL; } -inline size_t getFwdParamType(void(*)(WeaponIdType)) { return FP_CELL; } -inline size_t getFwdParamType(void(*)(RewardType)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(int)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(size_t)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(short)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(bool)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(Vector&)) { return FP_ARRAY; } +inline size_t getFwdParamType(void(*)(PLAYER_ANIM)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(WeaponIdType)) { return FP_CELL; } +inline size_t getFwdParamType(void(*)(RewardType)) { return FP_CELL; } inline size_t getFwdParamType(void(*)(ScenarioEventEndRound)) { return FP_CELL; } inline size_t getFwdParamType(void(*)(ItemID)) { return FP_CELL; } inline size_t getFwdParamType(void(*)(ItemRestType)) { return FP_CELL; } @@ -74,7 +74,8 @@ hook_t hooklist_engine[] = { ENG(SV_StartSound), ENG(SV_DropClient), ENG(SV_ActivateServer), - ENG(Cvar_DirectSet) + ENG(Cvar_DirectSet), + ENG(SV_WriteFullClientUpdate) }; #define DLL(h) { {}, {}, #h, "ReGameDLL", [](){ return api_cfg.hasReGameDLL(); }, ((!(RG_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RG_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h) : regfunc(#h), [](){ g_ReGameHookchains->##h##()->registerHook(&##h); }, [](){ g_ReGameHookchains->##h##()->unregisterHook(&##h); }} diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 4e897f5..ca4fbed 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -80,6 +80,7 @@ enum EngineFunc RH_SV_DropClient, RH_SV_ActivateServer, RH_Cvar_DirectSet, + RH_SV_WriteFullClientUpdate // [...] }; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index c1528d7..627dca6 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2012,6 +2012,28 @@ cell AMX_NATIVE_CALL rh_update_user_info(AMX *amx, cell *params) return TRUE; } +cell AMX_NATIVE_CALL rh_get_key_value(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_buffer, arg_key, arg_value, arg_maxlen }; + + char *buffer = getAmxString(amx, params[arg_buffer]); + const char *key = getAmxString(amx, params[arg_key]); + + return g_amxxapi.SetAmxString(amx, params[arg_value], g_engfuncs.pfnInfoKeyValue(buffer, key), params[arg_maxlen]); +} + +cell AMX_NATIVE_CALL rh_set_key_value(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_buffer, arg_key, arg_value }; + + char *buffer = getAmxString(amx, params[arg_buffer]); + const char *key = getAmxString(amx, params[arg_key]); + const char *value = getAmxString(amx, params[arg_value]); + + g_engfuncs.pfnSetKeyValue(buffer, key, value); + return 1; +} + AMX_NATIVE_INFO Misc_Natives_RH[] = { { "rh_set_mapname", rh_set_mapname }, @@ -2019,6 +2041,8 @@ AMX_NATIVE_INFO Misc_Natives_RH[] = { "rh_reset_mapname", rh_reset_mapname }, { "rh_emit_sound2", rh_emit_sound2 }, { "rh_update_user_info", rh_update_user_info }, + { "rh_get_key_value", rh_get_key_value }, + { "rh_set_key_value", rh_set_key_value }, { nullptr, nullptr } }; diff --git a/reapi/src/natives/natives_misc.h b/reapi/src/natives/natives_misc.h index 7fd5fca..1f30433 100644 --- a/reapi/src/natives/natives_misc.h +++ b/reapi/src/natives/natives_misc.h @@ -1,5 +1,11 @@ #pragma once +enum +{ + MAX_KV_LEN = 127, + MAX_INFO_STRING = 256 +}; + enum WpnInfo { WI_ID,