From 9ff5d34ce7eff2ff18027fa8e57a7f529eae4f43 Mon Sep 17 00:00:00 2001 From: GhostIsSpooky <69561145+Salluci@users.noreply.github.com> Date: Sun, 30 Jan 2022 14:56:20 -0300 Subject: [PATCH] Common - Add cache to `fnc_isModLoaded` (#8794) * add isModLoaded cache * add missing brackets * missed one * Update fnc_handlePunjiTrapDamage.sqf * Update fnc_isModLoaded.sqf Co-authored-by: PabstMirror --- addons/advanced_ballistics/XEH_postInit.sqf | 2 +- addons/common/XEH_postInit.sqf | 7 +++++-- .../functions/fnc_deprecateComponent.sqf | 2 +- .../functions/fnc_endRadioTransmission.sqf | 6 +++--- addons/common/functions/fnc_isModLoaded.sqf | 15 +++++++++++---- .../gforces/functions/fnc_pfhUpdateGForces.sqf | 4 ++-- .../functions/fnc_flashbangExplosionEH.sqf | 4 ++-- .../nametags/functions/fnc_initIsSpeaking.sqf | 18 ++++++++++-------- addons/overheating/XEH_postInit.sqf | 2 +- .../functions/fnc_canCoolWeaponWithItem.sqf | 2 +- .../overpressure/functions/fnc_firedEHBB.sqf | 2 +- .../functions/fnc_overpressureDamage.sqf | 9 +++++---- .../functions/fnc_handleZeusUnitAssigned.sqf | 4 ++-- .../functions/fnc_handlePunjiTrapDamage.sqf | 2 +- 14 files changed, 46 insertions(+), 33 deletions(-) diff --git a/addons/advanced_ballistics/XEH_postInit.sqf b/addons/advanced_ballistics/XEH_postInit.sqf index 43299a0e38..9ff22efe95 100644 --- a/addons/advanced_ballistics/XEH_postInit.sqf +++ b/addons/advanced_ballistics/XEH_postInit.sqf @@ -28,7 +28,7 @@ if (!hasInterface) exitWith {}; //Add warnings for missing compat PBOs (only if AB is on) { _x params ["_modPBO", "_compatPBO"]; - if ((isClass (configFile >> "CfgPatches" >> _modPBO)) && {!isClass (configFile >> "CfgPatches" >> _compatPBO)}) then { + if ([_modPBO] call EFUNC(common,isModLoaded) && {!([_compatPBO] call EFUNC(common,isModLoaded))}) then { WARNING_2("Weapon Mod [%1] missing ace compat pbo [%2] (from @ace\optionals)",_modPBO,_compatPBO); }; } forEach [ diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 78a5091369..fb5247d329 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -78,10 +78,10 @@ if (_object isEqualTo ACE_Player && {_set > 0}) then { call FUNC(endRadioTransmission); }; - if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then { + if (["task_force_radio"] call FUNC(isModLoaded)) then { _object setVariable ["tf_unable_to_use_radio", _set > 0, true]; }; - if (isClass (configFile >> "CfgPatches" >> "acre_main")) then { + if (["acre_main"] call FUNC(isModLoaded)) then { _object setVariable ["acre_sys_core_isDisabled", _set > 0, true]; }; }] call CBA_fnc_addEventHandler; @@ -108,6 +108,9 @@ _object setMass _mass; }] call CBA_fnc_addEventHandler; +// Cache for FUNC(isModLoaded) +GVAR(isModLoadedCache) = createHashMap; + //Add a fix for BIS's zeus remoteControl module not reseting variables on DC when RC a unit //This variable is used for isPlayer checks if (isServer) then { diff --git a/addons/common/functions/fnc_deprecateComponent.sqf b/addons/common/functions/fnc_deprecateComponent.sqf index a723b733ec..834803bd45 100644 --- a/addons/common/functions/fnc_deprecateComponent.sqf +++ b/addons/common/functions/fnc_deprecateComponent.sqf @@ -22,7 +22,7 @@ params ["_oldComponent", "_newComponent", "_version"]; _oldComponent params ["_oldComponentName", "_oldSettingName"]; _newComponent params ["_newComponentName", "_newSettingName"]; -private _isReplacementAvailable = isClass (configFile >> "CfgPatches" >> _newComponentName); +private _isReplacementAvailable = [_newComponentName] call FUNC(isModLoaded); private _isDeprecatedLoaded = missionNamespace getvariable [_oldSettingName, false]; private _isReplacementLoaded = missionNamespace getvariable [_newSettingName, false]; diff --git a/addons/common/functions/fnc_endRadioTransmission.sqf b/addons/common/functions/fnc_endRadioTransmission.sqf index 196d0f4d4a..443bf3c9de 100644 --- a/addons/common/functions/fnc_endRadioTransmission.sqf +++ b/addons/common/functions/fnc_endRadioTransmission.sqf @@ -19,7 +19,7 @@ ["ace_endRadioTransmissions"] call CBA_fnc_localEvent; // ACRE -if (isClass (configFile >> "CfgPatches" >> "acre_main")) then { +if (["acre_main"] call FUNC(isModLoaded)) then { [-1] call acre_sys_core_fnc_handleMultiPttKeyPressUp; [0] call acre_sys_core_fnc_handleMultiPttKeyPressUp; [1] call acre_sys_core_fnc_handleMultiPttKeyPressUp; @@ -27,8 +27,8 @@ if (isClass (configFile >> "CfgPatches" >> "acre_main")) then { }; // TFAR -if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then { - if (isClass (configFile >> "CfgPatches" >> "tfar_core")) exitWith { // Beta TFAR, exit to avoid script errors from legacy functions not existing +if (["task_force_radio"] call FUNC(isModLoaded)) then { + if (["tfar_core"] call FUNC(isModLoaded)) exitWith { // Beta TFAR, exit to avoid script errors from legacy functions not existing ACE_Player call TFAR_fnc_releaseAllTangents; }; call TFAR_fnc_onSwTangentReleased; diff --git a/addons/common/functions/fnc_isModLoaded.sqf b/addons/common/functions/fnc_isModLoaded.sqf index b69086e39d..7692050257 100644 --- a/addons/common/functions/fnc_isModLoaded.sqf +++ b/addons/common/functions/fnc_isModLoaded.sqf @@ -1,10 +1,10 @@ #include "script_component.hpp" /* - * Author: Glowbal - * Check in cfgPatches if modification is loaded + * Author: Glowbal, GhostIsSpooky + * Check in CfgPatches if modification is loaded * * Arguments: - * 0: Mod Name or Classname of the mod in cfgPatches + * 0: Mod Name or Classname of the mod in CfgPatches * * Return Value: * if modification is loaded @@ -17,4 +17,11 @@ params [["_modName", "", [""]]]; -isClass (configFile >> "CfgPatches" >> _modName) // return +private _return = GVAR(isModLoadedCache) get _modName; + +if (isNil "_return") then { + _return = isClass (configFile >> "CfgPatches" >> _modName); + GVAR(isModLoadedCache) set [_modName, _return]; +}; + +_return diff --git a/addons/gforces/functions/fnc_pfhUpdateGForces.sqf b/addons/gforces/functions/fnc_pfhUpdateGForces.sqf index 77f144e2f7..990d754f54 100644 --- a/addons/gforces/functions/fnc_pfhUpdateGForces.sqf +++ b/addons/gforces/functions/fnc_pfhUpdateGForces.sqf @@ -61,7 +61,7 @@ if (_count > 0) then { }; private _classCoef = (ACE_player getVariable ["ACE_GForceCoef", - getNumber (configFile >> "CfgVehicles" >> (typeOf ACE_player) >> "ACE_GForceCoef")]) max 0.001; + getNumber ((configOf ACE_player) >> "ACE_GForceCoef")]) max 0.001; private _suitCoef = if ((uniform ACE_player) != "") then { (getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "ACE_GForceCoef")) max 0.001 } else { @@ -71,7 +71,7 @@ private _suitCoef = if ((uniform ACE_player) != "") then { private _gBlackOut = MAXVIRTUALG / _classCoef + MAXVIRTUALG / _suitCoef - MAXVIRTUALG; // Unconsciousness -if ((_average > _gBlackOut) and {isClass (configFile >> "CfgPatches" >> "ACE_Medical") and {!(ACE_player getVariable ["ACE_isUnconscious", false])}}) then { +if ((_average > _gBlackOut) && {["ACE_Medical"] call EFUNC(common,isModLoaded) && {!(ACE_player getVariable ["ACE_isUnconscious", false])}}) then { [ACE_player, true, (10 + floor(random 5)), true] call EFUNC(medical,setUnconscious); }; diff --git a/addons/grenades/functions/fnc_flashbangExplosionEH.sqf b/addons/grenades/functions/fnc_flashbangExplosionEH.sqf index 29bb46db8a..ecf8ade5be 100644 --- a/addons/grenades/functions/fnc_flashbangExplosionEH.sqf +++ b/addons/grenades/functions/fnc_flashbangExplosionEH.sqf @@ -110,14 +110,14 @@ if (hasInterface && {!isNull ACE_player} && {alive ACE_player}) then { _strength = _strength * _losCoefficient; // Add ace_hearing ear ringing sound effect - if (isClass (configFile >> "CfgPatches" >> "ACE_Hearing") && {_strength > 0 && {EGVAR(hearing,damageCoefficent) > 0.25}}) then { + if (["ACE_Hearing"] call EFUNC(common,isModLoaded) && {_strength > 0 && {EGVAR(hearing,damageCoefficent) > 0.25}}) then { private _earringingStrength = 40 * _strength; [_earringingStrength] call EFUNC(hearing,earRinging); TRACE_1("Earringing Strength",_earringingStrength); }; // add ace_medical pain effect: - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical") && {_strength > 0.1}) then { + if (["ACE_Medical"] call EFUNC(common,isModLoaded) && {_strength > 0.1}) then { [ACE_player, _strength / 2] call EFUNC(medical,adjustPainLevel); }; diff --git a/addons/nametags/functions/fnc_initIsSpeaking.sqf b/addons/nametags/functions/fnc_initIsSpeaking.sqf index a3d7f80ed2..5e322f6e69 100644 --- a/addons/nametags/functions/fnc_initIsSpeaking.sqf +++ b/addons/nametags/functions/fnc_initIsSpeaking.sqf @@ -36,20 +36,22 @@ if (!hasInterface) exitWith {}; }; }] call CBA_fnc_addPlayerEventHandler; -if (isClass (configFile >> "CfgPatches" >> "acre_api")) then { - INFO("ACRE Detected."); - DFUNC(isSpeaking) = { - params ["_unit"]; - ([_unit] call acre_api_fnc_isSpeaking) && {!(_unit getVariable ["ACE_isUnconscious", false])} +switch (true) do { + case (["acre_api"] call EFUNC(common,isModLoaded)): { + INFO("ACRE Detected."); + DFUNC(isSpeaking) = { + params ["_unit"]; + ([_unit] call acre_api_fnc_isSpeaking) && {!(_unit getVariable ["ACE_isUnconscious", false])} + }; }; -} else { - if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then { + case (["task_force_radio"] call EFUNC(common,isModLoaded)): { INFO("TFAR Detected."); DFUNC(isSpeaking) = { params ["_unit"]; (_unit getVariable ["tf_isSpeaking", false]) && {!(_unit getVariable ["ACE_isUnconscious", false])} }; - } else { + }; + default { //No Radio Mod - Start a PFEH to watch the internal VON icon //Note: class RscDisplayVoiceChat {idd = 55} - only present when talking diff --git a/addons/overheating/XEH_postInit.sqf b/addons/overheating/XEH_postInit.sqf index 66bb7bebfd..bbcd9da97f 100644 --- a/addons/overheating/XEH_postInit.sqf +++ b/addons/overheating/XEH_postInit.sqf @@ -92,7 +92,7 @@ if (hasInterface) then { [QGVAR(initiateSwapBarrelAssisted), DFUNC(swapBarrel)] call CBA_fnc_addEventHandler; // Add an action to allow hot weapons to be cooled off in AceX Field Rations water sources - if (isClass (configfile >> "CfgPatches" >> "acex_field_rations")) then { + if (["acex_field_rations"] call EFUNC(common,isModLoaded)) then { [ {EXGVAR(field_rations,enabled) || CBA_missionTime > 1}, { diff --git a/addons/overheating/functions/fnc_canCoolWeaponWithItem.sqf b/addons/overheating/functions/fnc_canCoolWeaponWithItem.sqf index ba31bbebc5..d91610d7ab 100644 --- a/addons/overheating/functions/fnc_canCoolWeaponWithItem.sqf +++ b/addons/overheating/functions/fnc_canCoolWeaponWithItem.sqf @@ -20,7 +20,7 @@ params ["_unit", "_player"]; TRACE_2("canCoolWeaponWithItem",_unit,_player); GVAR(enabled) -&& {isClass (configfile >> "CfgPatches" >> "acex_field_rations")} +&& {["acex_field_rations"] call EFUNC(common,isModLoaded)} && {!(_unit getVariable [QEGVAR(captives,isSurrendering), false])} // interaction point will overlap with ace_captives && {!(_unit getVariable [QEGVAR(captives,isHandcuffed), false])} && {[_unit, currentWeapon _unit] call FUNC(getWeaponTemperature) > (ambientTemperature select 0)} diff --git a/addons/overpressure/functions/fnc_firedEHBB.sqf b/addons/overpressure/functions/fnc_firedEHBB.sqf index 2d1d0f783c..758f00784c 100644 --- a/addons/overpressure/functions/fnc_firedEHBB.sqf +++ b/addons/overpressure/functions/fnc_firedEHBB.sqf @@ -51,7 +51,7 @@ if (_distance < _backblastRange) then { private _damage = _alpha * _beta * _backblastDamage; [_damage * 100] call BIS_fnc_bloodEffect; - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { + if (["ACE_Medical"] call EFUNC(common,isModLoaded)) then { [_unit, _damage, "body", "backblast", _unit] call EFUNC(medical,addDamageToUnit); } else { TRACE_1("",isDamageAllowed _unit); diff --git a/addons/overpressure/functions/fnc_overpressureDamage.sqf b/addons/overpressure/functions/fnc_overpressureDamage.sqf index 119c19ebb2..dd60fc25d3 100644 --- a/addons/overpressure/functions/fnc_overpressureDamage.sqf +++ b/addons/overpressure/functions/fnc_overpressureDamage.sqf @@ -53,12 +53,13 @@ TRACE_3("cache",_overpressureAngle,_overpressureRange,_overpressureDamage); private _damage = _alpha * _beta * _overpressureDamage; TRACE_1("",_damage); - // If the target is the ACE_player - if (_x == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; - TRACE_1("",isDamageAllowed _x); if (isDamageAllowed _x && {_x getVariable [QEGVAR(medical,allowDamage), true]}) then { - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { + // If the target is the ACE_player + if (_x isEqualTo ACE_player) then { + [_damage * 100] call BIS_fnc_bloodEffect + }; + if (["ACE_Medical"] call EFUNC(common,isModLoaded)) then { [_x, _damage, "body", "backblast", _firer] call EFUNC(medical,addDamageToUnit); } else { _x setDamage (damage _x + _damage); diff --git a/addons/zeus/functions/fnc_handleZeusUnitAssigned.sqf b/addons/zeus/functions/fnc_handleZeusUnitAssigned.sqf index 05bf5fdfb3..8e507ebb35 100644 --- a/addons/zeus/functions/fnc_handleZeusUnitAssigned.sqf +++ b/addons/zeus/functions/fnc_handleZeusUnitAssigned.sqf @@ -30,14 +30,14 @@ private _removeAddons = []; private _addon = _x; if (isArray _addon) then { { - if !(isClass (configFile >> "CfgPatches" >> _x)) exitWith { + if !([_x] call EFUNC(common,isModLoaded)) exitWith { _removeAddons pushBack (configName _addon); }; } forEach (getArray _addon); }; if (isText _addon) then { - if !(isClass (configFile >> "CfgPatches" >> getText _addon)) then { + if !([getText _addon] call EFUNC(common,isModLoaded)) then { _removeAddons pushBack (configName _addon); }; }; diff --git a/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf b/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf index 2448dcf7d0..241fdd8adf 100644 --- a/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf +++ b/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf @@ -16,7 +16,7 @@ */ params ["_trap"]; -if (isNull (configFile >> "CfgPatches" >> "ace_medical")) exitWith {}; +if (!(["ACE_Medical"] call EFUNC(common,isModLoaded))) exitWith {}; private _radius = getNumber (configOf _trap >> "indirectHitRange"); private _affectedUnits = (_trap nearEntities ["CAManBase", _radius]) select {local _x} select {isDamageAllowed _x};