From 3599ceb88b58bc702b4085a51e41270da65ba24d Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:23:58 -0300 Subject: [PATCH] Arsenal - Improve base backpack checking --- addons/arsenal/XEH_PREP.hpp | 1 + addons/arsenal/XEH_preStart.sqf | 3 +- addons/arsenal/functions/fnc_baseBackpack.sqf | 52 +++++++++++++++++++ .../fnc_replaceUniqueItemsLoadout.sqf | 4 +- .../functions/fnc_updateCurrentItemsList.sqf | 2 +- .../functions/fnc_updateUniqueItemsList.sqf | 2 +- .../arsenal/functions/fnc_verifyLoadout.sqf | 2 +- 7 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 addons/arsenal/functions/fnc_baseBackpack.sqf diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index b69ff0cb749..689ccd8127a 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -17,6 +17,7 @@ PREP(attributeLoad); PREP(attributeMode); PREP(attributeSelect); PREP(baseAttachment); +PREP(baseBackpack); PREP(baseOptic); PREP(baseWeapon); PREP(buttonActionsPage); diff --git a/addons/arsenal/XEH_preStart.sqf b/addons/arsenal/XEH_preStart.sqf index 867d308874a..a90f836e10d 100644 --- a/addons/arsenal/XEH_preStart.sqf +++ b/addons/arsenal/XEH_preStart.sqf @@ -2,8 +2,9 @@ #include "XEH_PREP.hpp" -// Cache for FUNC(baseWeapon) +// Caches for FUNC(baseX) uiNamespace setVariable [QGVAR(baseWeaponNameCache), createHashMap]; +uiNamespace setVariable [QGVAR(baseBackpackCache), createHashMap]; // Caches for names, pictures, mod icons uiNamespace setVariable [QGVAR(addListBoxItemCache), createHashMap]; diff --git a/addons/arsenal/functions/fnc_baseBackpack.sqf b/addons/arsenal/functions/fnc_baseBackpack.sqf new file mode 100644 index 00000000000..74b6c85c320 --- /dev/null +++ b/addons/arsenal/functions/fnc_baseBackpack.sqf @@ -0,0 +1,52 @@ +#include "..\script_component.hpp" +/* + * Author: LinkIsGrim + * Returns base backpack for a preset (loaded/AI) backpack variant + * Basically CBA_fnc_getNonPresetClass with model checking, as some backpacks don't have variants with no cargo (#10346) + * + * Arguments: + * 0: Backpack classname + * + * Return Value: + * Most viable base backpack class, "" if not a backpack + * + * Example: + * "B_Kitbag_rgr_Exp" call ace_arsenal_fnc_baseBackpack + * + * Public: Yes + */ + +params [["_item", "", [""]]]; + +TRACE_1("looking up base backpack",_item); + +(uiNamespace getVariable QGVAR(baseBackpackCache)) getOrDefaultCall [toLowerANSI _item, { + private _config = configFile >> "CfgVehicles" >> _item; + // TODO: handle file extension differences (implicit vs explicit .p3d) + // model could have missing file extension in a variant and present in parent, but that's stupid, bad config. + // It'll be inherited and match 99% of the time. Good enough until it burns, see texture checking below. + private _model = getText (_config >> "model"); + + // Texture checking is a can of worms: we'd have to create a hashmap nConfigs + 1 times and see if they match... + // ...and it wouldn't handle small things like custom patches or name tags + // If this ever comes up (it likely will), we'll burn that bridge when we get to it. + // private _textures = getArray (_config >> "hiddenSelectionsTextures"); + + while { + (isClass _config) && + {getNumber (_config >> "scope") > 0} && // Some preset backpacks are scope = 1 + {getText (_config >> "model") == _model} + // && {getArray (_config >> "hiddenSelectionsTextures") isEqualTo _textures} + } do { + if ( + (count (_config >> "TransportItems") == 0) && + {count (_config >> "TransportMagazines") == 0} && + {count (_config >> "TransportWeapons") == 0} + ) then { + break; + }; + _config = inheritsFrom _config; + }; + + configName _config // return, will be "" if not a backpack +}, true] diff --git a/addons/arsenal/functions/fnc_replaceUniqueItemsLoadout.sqf b/addons/arsenal/functions/fnc_replaceUniqueItemsLoadout.sqf index 061180beaa6..9b65b64fb54 100644 --- a/addons/arsenal/functions/fnc_replaceUniqueItemsLoadout.sqf +++ b/addons/arsenal/functions/fnc_replaceUniqueItemsLoadout.sqf @@ -70,7 +70,7 @@ private _cfgVehicles = configFile >> "CfgVehicles"; if (_containerClass != "") then { if (_forEachIndex == IDX_LOADOUT_BACKPACK) then { // Check for non-preset first - _uniqueBaseCfgText = [_containerClass, "CfgVehicles"] call CBA_fnc_getNonPresetClass; + _uniqueBaseCfgText = _containerClass call FUNC(baseBackpack); if (_uniqueBaseCfgText != "") then { _containerClass = _uniqueBaseCfgText; @@ -102,7 +102,7 @@ private _cfgVehicles = configFile >> "CfgVehicles"; if (_containerClass != "") then { if (_isBackpack) then { // Check for non-preset first - _uniqueBaseCfgText = [_containerClass, "CfgVehicles"] call CBA_fnc_getNonPresetClass; + _uniqueBaseCfgText = _containerClass call FUNC(baseBackpack); if (_uniqueBaseCfgText != "") then { _containerClass = _uniqueBaseCfgText; diff --git a/addons/arsenal/functions/fnc_updateCurrentItemsList.sqf b/addons/arsenal/functions/fnc_updateCurrentItemsList.sqf index 0dcf3866b94..f9d8d7072a2 100644 --- a/addons/arsenal/functions/fnc_updateCurrentItemsList.sqf +++ b/addons/arsenal/functions/fnc_updateCurrentItemsList.sqf @@ -65,7 +65,7 @@ private _indexCurrentItems = -1; case IDX_LOADOUT_BACKPACK: { _x params [["_backpack", ""], ["_items", []]]; if (_backpack != "") then { - _backpack = [_backpack, "CfgVehicles"] call CBA_fnc_getNonPresetClass; + _backpack = _backpack call FUNC(baseBackpack); }; GVAR(currentItems) set [IDX_CURR_BACKPACK, _backpack]; GVAR(currentItems) set [IDX_CURR_BACKPACK_ITEMS, _items]; diff --git a/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf b/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf index 4cbdc4bcba0..b44dda2363b 100644 --- a/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf +++ b/addons/arsenal/functions/fnc_updateUniqueItemsList.sqf @@ -103,7 +103,7 @@ private _fnc_uniqueEquipment = { // Handle preset (loaded/AI) backpacks if (_containerClass != "" && _forEachIndex == IDX_LOADOUT_BACKPACK) then { - _containerClass = [_containerClass, "CfgVehicles"] call CBA_fnc_getNonPresetClass; + _containerClass = _containerClass call FUNC(baseBackpack); }; // Remove all unique equipment in tab; Add container as a unique equipment diff --git a/addons/arsenal/functions/fnc_verifyLoadout.sqf b/addons/arsenal/functions/fnc_verifyLoadout.sqf index 10cd9a25539..620bfd94607 100644 --- a/addons/arsenal/functions/fnc_verifyLoadout.sqf +++ b/addons/arsenal/functions/fnc_verifyLoadout.sqf @@ -50,7 +50,7 @@ private _fnc_filterLoadout = { _name = _name call FUNC(baseWeapon); if NOT_IN_ARSENAL then { // This could be a backpack - private _temp = [_name, "CfgVehicles"] call CBA_fnc_getNonPresetClass; + private _temp = _name call FUNC(baseBackpack); if (_temp == "") then { // It's not _unavailableItemsList pushBack _name; _name = "";