diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index 23a8db0..4dc00cc 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -30,10 +30,35 @@ native set_ucmd(const ucmd, const UCmd:var, any:...); */ native any:get_ucmd(const ucmd, const UCmd:var, any:...); +/* +* 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 get_key_value(const pbuffer, const key[], const value[], const maxlen); + +/* +* Sets value for key in buffer +* +* @param pbuffer Pointer to buffer +* @param key Key string +* @param value Value to set +* +* @noreturn +*/ +native set_key_value(const pbuffer, const key[], const value[]); + /* * Sets the name of the map. * -* @param mapname New map name. +* @param mapname New map name. * * @noreturn * @@ -43,10 +68,10 @@ native rh_set_mapname(const mapname[]); /* * Gets the name of the map. * -* @param output Buffer to copy map name to -* @param len Maximum buffer size -* @param type MNT_SET will return the name of the current map -* MNT_TRUE will return the original map name independant of the name set with via rh_set_mapname +* @param output Buffer to copy map name to +* @param len Maximum buffer size +* @param type MNT_SET will return the name of the current map +* MNT_TRUE will return the original map name independant of the name set with via rh_set_mapname * * @noreturn * @@ -64,18 +89,18 @@ native rh_reset_mapname(); /* * Emits a sound from an entity from the engine. * -* @param entity Entity index or use 0 to emit from worldspawn at the specified position -* @param recipient Recipient index or use 0 to make all clients hear it -* @param channel Channel to emit from -* @param sample Sound file to emit -* @param vol Volume in percents -* @param attn Sound attenuation -* @param flags Emit flags -* @param pitch Sound pitch -* @param emitFlags Additional Emit2 flags, look at the defines like SND_EMIT2_* -* @param origin Specify origin and only on "param" entity worldspawn that is 0 +* @param entity Entity index or use 0 to emit from worldspawn at the specified position +* @param recipient Recipient index or use 0 to make all clients hear it +* @param channel Channel to emit from +* @param sample Sound file to emit +* @param vol Volume in percents +* @param attn Sound attenuation +* @param flags Emit flags +* @param pitch Sound pitch +* @param emitFlags Additional Emit2 flags, look at the defines like SND_EMIT2_* +* @param origin Specify origin and only on "param" entity worldspawn that is 0 * -* @return true if the emission was successfull, false otherwise +* @return true if the emission was successfull, false otherwise * */ native bool:rh_emit_sound2(const entity, const recipient, const channel, const sample[], Float:vol = VOL_NORM, Float:attn = ATTN_NORM, const flags = 0, const pitch = PITCH_NORM, emitFlags = 0, const Float:origin[3] = {0.0,0.0,0.0}); @@ -88,28 +113,3 @@ 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/include/com_client.h b/reapi/include/com_client.h index c1c6cd8..a5a8013 100644 --- a/reapi/include/com_client.h +++ b/reapi/include/com_client.h @@ -36,6 +36,7 @@ // Key + value + 2 x slash + NULL const int MAX_INFO_STRING = 256; +const int MAX_KV_LEN = 127; typedef struct client_frame_s { diff --git a/reapi/src/natives/natives_common.cpp b/reapi/src/natives/natives_common.cpp index 5f113e3..be4d9ef 100644 --- a/reapi/src/natives/natives_common.cpp +++ b/reapi/src/natives/natives_common.cpp @@ -111,12 +111,63 @@ cell AMX_NATIVE_CALL amx_get_viewent(AMX *amx, cell *params) return indexOfEdictAmx(pClient->pViewEntity); } +/* +* 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 get_key_value(const pbuffer, const key[], const value[], const maxlen); +*/ +cell AMX_NATIVE_CALL amx_get_key_value(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_buffer, arg_key, arg_value, arg_maxlen }; + + char buffer[MAX_INFO_STRING], key[MAX_KV_LEN]; + Q_strlcpy(buffer, getAmxString(amx, params[arg_buffer])); + Q_strlcpy(key, getAmxString(amx, params[arg_key])); + + return g_amxxapi.SetAmxString(amx, params[arg_value], g_engfuncs.pfnInfoKeyValue(buffer, key), params[arg_maxlen]); +} + +/* +* Sets value for key in buffer +* +* @param pbuffer Pointer to buffer +* @param key Key string +* @param value Value to set +* +* @noreturn +* +* native set_key_value(const pbuffer, const key[], const value[]); +*/ +cell AMX_NATIVE_CALL amx_set_key_value(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_buffer, arg_key, arg_value }; + + char buffer[MAX_INFO_STRING], key[MAX_KV_LEN], value[MAX_KV_LEN]; + Q_strlcpy(buffer, getAmxString(amx, params[arg_buffer])); + Q_strlcpy(key, getAmxString(amx, params[arg_key])); + Q_strlcpy(value, getAmxString(amx, params[arg_value])); + + g_engfuncs.pfnSetKeyValue(buffer, key, value); + return TRUE; +} + AMX_NATIVE_INFO Natives_Common[] = { { "FClassnameIs", amx_FClassnameIs }, { "GetGrenadeType", amx_GetGrenadeType }, { "engset_view", amx_engset_view }, { "get_viewent", amx_get_viewent }, + { "get_key_value", amx_get_key_value }, + { "set_key_value", amx_set_key_value }, { nullptr, nullptr } }; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 627dca6..c1528d7 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2012,28 +2012,6 @@ 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 }, @@ -2041,8 +2019,6 @@ 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 1f30433..7fd5fca 100644 --- a/reapi/src/natives/natives_misc.h +++ b/reapi/src/natives/natives_misc.h @@ -1,11 +1,5 @@ #pragma once -enum -{ - MAX_KV_LEN = 127, - MAX_INFO_STRING = 256 -}; - enum WpnInfo { WI_ID,