From a5a87e2a9957309c4de7823ee7525236dde3b293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mat=C3=ADas?= <41979395+FEDERICOMB96@users.noreply.github.com> Date: Sun, 30 Jul 2023 21:22:48 -0300 Subject: [PATCH] `API`: Added new API natives (5) Added `mm_get_mod_enabled` Added `mm_get_mod_changemap_type` Added `mm_get_mod_maps` Added `mm_get_mod_cvars` Added `mm_get_mod_plugins` --- .../scripting/include/mm_incs/defines.inc | 2 +- .../scripting/include/mm_incs/natives.inc | 173 ++++++++++++++++++ .../include/multimod_manager_natives.inc | 58 +++++- addons/amxmodx/scripting/multimod_manager.sma | 7 +- 4 files changed, 237 insertions(+), 3 deletions(-) diff --git a/addons/amxmodx/scripting/include/mm_incs/defines.inc b/addons/amxmodx/scripting/include/mm_incs/defines.inc index cd6910a..ab888fb 100644 --- a/addons/amxmodx/scripting/include/mm_incs/defines.inc +++ b/addons/amxmodx/scripting/include/mm_incs/defines.inc @@ -6,7 +6,7 @@ #define PLUGIN_NAME "MultiMod Manager" #define MM_VERSION_MAJOR 2 -#define MM_VERSION_MINOR 0 +#define MM_VERSION_MINOR 1 #define MM_VERSION_PATCH 0 #define PLUGIN_VERSION fmt("v%d.%d.%d", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_PATCH) diff --git a/addons/amxmodx/scripting/include/mm_incs/natives.inc b/addons/amxmodx/scripting/include/mm_incs/natives.inc index 065ea6d..7fd8e3c 100644 --- a/addons/amxmodx/scripting/include/mm_incs/natives.inc +++ b/addons/amxmodx/scripting/include/mm_incs/natives.inc @@ -19,6 +19,39 @@ public _mm_get_mods_count(plugin_id, argc) return ArraySize(g_GlobalConfigs[Mods]); } +/** + * Return if the mod is enabled or not. + * + * @param iModId Mod index. + * + * @return (bool) true if the mod is enabled, false otherwise. + * + * native bool:mm_get_mod_enabled(const iModId); + */ +public bool:_mm_get_mod_enabled(plugin_id, argc) +{ + enum _:args_e { arg_modid = 1 }; + + if(argc != (args_e-1)) + { + abort(AMX_ERR_NATIVE, "'mm_get_mod_enabled' needs %d param(s) (count: %d)", (args_e-1), argc); + return false; + } + + new iModId = get_param(arg_modid); + + if(iModId < 0 || iModId >= ArraySize(g_GlobalConfigs[Mods])) + { + abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId); + return false; + } + + new aMods[ArrayMods_e]; + ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods); + + return aMods[Enabled]; +} + /** * Retrieves mod name. * @@ -99,6 +132,146 @@ public _mm_get_mod_tag(plugin_id, argc) return set_string(arg_output, aMods[ModTag], get_param(arg_len)); } +/** + * Return the mod changemap type. + * + * @note See 'ChangeMap_e' enum for more information. + * + * @param iModId Mod index. + * + * @return (int) 0 on change map timeleft. + * 1 on change map end of round. + * 2 on change map one more round. + * + * native ChangeMap_e:mm_get_mod_changemap_type(const iModId); + */ +public ChangeMap_e:_mm_get_mod_changemap_type(plugin_id, argc) +{ + enum _:args_e { arg_modid = 1 }; + + if(argc != (args_e-1)) + { + abort(AMX_ERR_NATIVE, "'mm_get_mod_changemap_type' needs %d param(s) (count: %d)", (args_e-1), argc); + return -1; + } + + new iModId = get_param(arg_modid); + new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]); + + if(iModId < 0 || iModId >= iArraySizeMods) + { + abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId); + return -1; + } + + new aMods[ArrayMods_e]; + ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods); + + return aMods[ChangeMapType]; +} + +/** + * Return the maps list of the mod. + * + * @param iModId Mod index. + * + * @return (Array) Maps list array handle, which must be freed via ArrayDestroy() + * + * native Array:mm_get_mod_maps(const iModId); + */ +public Array:_mm_get_mod_maps(plugin_id, argc) +{ + enum _:args_e { arg_modid = 1 }; + + if(argc != (args_e-1)) + { + abort(AMX_ERR_NATIVE, "'mm_get_mod_maps' needs %d param(s) (count: %d)", (args_e-1), argc); + return -1; + } + + new iModId = get_param(arg_modid); + new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]); + + if(iModId < 0 || iModId >= iArraySizeMods) + { + abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId); + return -1; + } + + new aMods[ArrayMods_e]; + ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods); + + return ArrayClone(aMods[Maps]); +} + +/** + * Return the cvars list of the mod. + * + * @param iModId Mod index. + * + * @return (Array) Cvars list array handle, which must be freed via ArrayDestroy() + * + * native Array:mm_get_mod_cvars(const iModId); + */ +public Array:_mm_get_mod_cvars(plugin_id, argc) +{ + enum _:args_e { arg_modid = 1 }; + + if(argc != (args_e-1)) + { + abort(AMX_ERR_NATIVE, "'mm_get_mod_cvars' needs %d param(s) (count: %d)", (args_e-1), argc); + return -1; + } + + new iModId = get_param(arg_modid); + new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]); + + if(iModId < 0 || iModId >= iArraySizeMods) + { + abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId); + return -1; + } + + new aMods[ArrayMods_e]; + ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods); + + return ArrayClone(aMods[Cvars]); +} + +/** + * Return the plugin list of the mod. + * + * @param iModId Mod index. + * + * @return (Array) Plugins list array handle, which must be freed via ArrayDestroy() + * + * native Array:mm_get_mod_plugins(const iModId); + */ +public Array:_mm_get_mod_plugins(plugin_id, argc) +{ + enum _:args_e { arg_modid = 1 }; + + if(argc != (args_e-1)) + { + abort(AMX_ERR_NATIVE, "'mm_get_mod_plugins' needs %d param(s) (count: %d)", (args_e-1), argc); + return -1; + } + + new iModId = get_param(arg_modid); + new iArraySizeMods = ArraySize(g_GlobalConfigs[Mods]); + + if(iModId < 0 || iModId >= iArraySizeMods) + { + abort(AMX_ERR_NATIVE, "Invalid array size (%d)", iModId); + return -1; + } + + new aMods[ArrayMods_e]; + ArrayGetArray(g_GlobalConfigs[Mods], iModId, aMods); + + return ArrayClone(aMods[Plugins]); +} + /** * Return the current mod index based on JSON position. * diff --git a/addons/amxmodx/scripting/include/multimod_manager_natives.inc b/addons/amxmodx/scripting/include/multimod_manager_natives.inc index cc36648..cc265f2 100644 --- a/addons/amxmodx/scripting/include/multimod_manager_natives.inc +++ b/addons/amxmodx/scripting/include/multimod_manager_natives.inc @@ -8,9 +8,16 @@ * Do not modify this! */ #define MM_VERSION_MAJOR 2 -#define MM_VERSION_MINOR 0 +#define MM_VERSION_MINOR 1 #define MM_VERSION_PATCH 0 +enum ChangeMap_e +{ + CHANGEMAP_TIMELEFT, + CHANGEMAP_END_OF_ROUND, + CHANGEMAP_ONE_MORE_ROUND, +}; + /* =========================================================================== * [ MULTIMOD MANAGER NATIVES ] * ============================================================================ */ @@ -22,6 +29,15 @@ */ native mm_get_mods_count(); +/** + * Return if the mod is enabled or not. + * + * @param iModId Mod index. + * + * @return (bool) true if the mod is enabled, false otherwise. + */ +native bool:mm_get_mod_enabled(const iModId); + /** * Retrieves mod name. * @@ -52,6 +68,46 @@ native mm_get_mod_name(const iModId, szOutput[], const iLen); */ native mm_get_mod_tag(const iModId, szOutput[], const iLen); +/** + * Return the mod changemap type. + * + * @note See 'ChangeMap_e' enum for more information. + * + * @param iModId Mod index. + * + * @return (int) 0 on change map timeleft. + * 1 on change map end of round. + * 2 on change map one more round. + */ +native ChangeMap_e:mm_get_mod_changemap_type(const iModId); + +/** + * Return the maps list of the mod. + * + * @param iModId Mod index. + * + * @return (Array) Maps list array handle, which must be freed via ArrayDestroy() + */ +native Array:mm_get_mod_maps(const iModId); + +/** + * Return the cvars list of the mod. + * + * @param iModId Mod index. + * + * @return (Array) Cvars list array handle, which must be freed via ArrayDestroy() + */ +native Array:mm_get_mod_cvars(const iModId); + +/** + * Return the plugin list of the mod. + * + * @param iModId Mod index. + * + * @return (Array) Plugins list array handle, which must be freed via ArrayDestroy() + */ +native Array:mm_get_mod_plugins(const iModId); + /** * Return the current mod index based on JSON position. * diff --git a/addons/amxmodx/scripting/multimod_manager.sma b/addons/amxmodx/scripting/multimod_manager.sma index da32465..0ea206b 100644 --- a/addons/amxmodx/scripting/multimod_manager.sma +++ b/addons/amxmodx/scripting/multimod_manager.sma @@ -19,8 +19,13 @@ public plugin_natives() { register_native("mm_get_mods_count", "_mm_get_mods_count"); + register_native("mm_get_mod_enabled", "_mm_get_mod_enabled"); register_native("mm_get_mod_name", "_mm_get_mod_name"); register_native("mm_get_mod_tag", "_mm_get_mod_tag"); + register_native("mm_get_mod_changemap_type", "_mm_get_mod_changemap_type"); + register_native("mm_get_mod_maps", "_mm_get_mod_maps"); + register_native("mm_get_mod_cvars", "_mm_get_mod_cvars"); + register_native("mm_get_mod_plugins", "_mm_get_mod_plugins"); register_native("mm_get_currentmod_id", "_mm_get_currentmod_id"); register_native("mm_get_nextmod_id", "_mm_get_nextmod_id"); register_native("mm_force_votemod", "_mm_force_votemod"); @@ -269,7 +274,7 @@ MultiMod_Init() } json_free(jObjectMod); - aMod[Plugins] = ArrayCreate(64); + aMod[Plugins] = ArrayCreate(PLATFORM_MAX_PATH); jObjectMod = json_object_get_value(jArrayValue, "plugins"); for(j = 0, iObjetCount = json_array_get_count(jObjectMod); j < iObjetCount; ++j) {