From 37145904341fbce7767d9724d3d66792706ef744 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 4 May 2016 17:39:34 +0600 Subject: [PATCH] Added natives rg_set_weapon_info --- .../scripting/include/reapi_gamedll.inc | 11 +++ reapi/include/cssdk/dlls/regamedll_api.h | 1 - .../include/cssdk/dlls/regamedll_interfaces.h | 3 +- reapi/include/cssdk/dlls/weapontype.h | 1 + reapi/src/natives/natives_misc.cpp | 76 ++++++++++++++++--- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 275c191..53a3405 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -245,6 +245,17 @@ native rg_find_ent_by_owner(&start_index, const classname[], owner); */ native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +/** +* Sets specific values of weapons info. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Info type, see WI_* constants +* +* @return 1 if successfully, 0 otherwise +* +*/ +native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); + /** * Remove specifed the player's item by class name * diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index dda1fc2..716c5f1 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -246,7 +246,6 @@ struct ReGameFuncs_t { void (*EndRoundMessage)(const char *sentence, int event); class CBaseEntity *(*UTIL_FindEntityByString)(class CBaseEntity *pStartEntity, const char *szKeyword, const char *szValue); - struct WeaponInfoStruct *(*GetWeaponInfo)(int weaponID); }; class IReGameApi { diff --git a/reapi/include/cssdk/dlls/regamedll_interfaces.h b/reapi/include/cssdk/dlls/regamedll_interfaces.h index 8abddd4..aced5e1 100644 --- a/reapi/include/cssdk/dlls/regamedll_interfaces.h +++ b/reapi/include/cssdk/dlls/regamedll_interfaces.h @@ -2076,5 +2076,6 @@ class IReGameData { public: virtual ~IReGameData() {} - virtual class CGameRules** GetGameRules() = 0; + virtual class CGameRules* GetGameRules() = 0; + virtual struct WeaponInfoStruct *GetWeaponInfo(int weaponID) = 0; }; diff --git a/reapi/include/cssdk/dlls/weapontype.h b/reapi/include/cssdk/dlls/weapontype.h index c185b3e..8b1bd82 100644 --- a/reapi/include/cssdk/dlls/weapontype.h +++ b/reapi/include/cssdk/dlls/weapontype.h @@ -399,4 +399,5 @@ struct WeaponInfoStruct int maxRounds; int ammoType; char *entityName; + const char *ammoName; }; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 7dad29c..f5c9394 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -523,23 +523,23 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) return 0; } - WeaponInfoStruct *info = g_ReGameFuncs->GetWeaponInfo(weapon_id); + WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id); WpnInfo info_type = static_cast(params[arg_type]); switch (info_type) { case WI_COST: - return info->cost; + return info->cost; case WI_CLIP_COST: - return info->clipCost; + return info->clipCost; case WI_BUY_CLIP_SIZE: - return info->buyClipSize; + return info->buyClipSize; case WI_GUN_CLIP_SIZE: - return info->gunClipSize; + return info->gunClipSize; case WI_MAX_ROUNDS: - return info->maxRounds; + return info->maxRounds; case WI_AMMO_TYPE: - return info->ammoType; + return info->ammoType; case WI_NAME: { if (PARAMS_COUNT != arg_4) { @@ -550,17 +550,69 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) // native rg_get_weapon_info(id, WPINFO_NAME, output[], maxlength); cell* dest = getAmxAddr(amx, params[arg_3]); size_t length = *getAmxAddr(amx, params[arg_4]); + + if (info->entityName == nullptr) { + setAmxString(dest, "", 1); + return 0; + } + setAmxString(dest, info->entityName, length); return 1; } default: - { - MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); - return -1; - } + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); + return -1; } } +/** +* Sets specific values of weapons info. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Info type, see WI_* constants +* +* @return 1 if successfully, 0 otherwise +* +* native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +*/ +cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_weapon_id, arg_type, arg_value }; + + int weapon_id = params[arg_weapon_id]; + if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90) + { + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id); + return 0; + } + + cell* value = getAmxAddr(amx, params[arg_value]); + WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id); + WpnInfo info_type = static_cast(params[arg_type]); + + switch (info_type) + { + case WI_COST: + info->cost = *value; + break; + case WI_CLIP_COST: + info->clipCost = *value; + break; + case WI_BUY_CLIP_SIZE: + case WI_GUN_CLIP_SIZE: + case WI_MAX_ROUNDS: + case WI_AMMO_TYPE: + case WI_NAME: + MF_LogError(amx, AMX_ERR_NATIVE, "%s: this change will have no effect", __FUNCTION__); + return 0; + default: + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); + return 0; + } + + return 1; +} + /** * Remove all the player's stuff * @@ -653,7 +705,9 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_create_entity", rg_create_entity }, { "rg_find_ent_by_class", rg_find_ent_by_class }, { "rg_find_ent_by_owner", rg_find_ent_by_owner }, + { "rg_get_weapon_info", rg_get_weapon_info }, + { "rg_set_weapon_info", rg_set_weapon_info }, { "rg_remove_all_items", rg_remove_all_items }, { "rg_remove_item", rg_remove_item },