From 5404e3e87f935d004d06905f0b5d856b74aed34a Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Thu, 12 Oct 2023 02:26:58 +0200 Subject: [PATCH] Add config property that can make settings changes stay until restart --- addons/settings/fnc_clear.sqf | 2 +- addons/settings/fnc_init.sqf | 2 +- addons/settings/fnc_initDisplayMain.sqf | 6 ++++++ addons/settings/fnc_set.sqf | 4 ++-- addons/settings/initSettings.sqf | 3 +++ template/cba_settings_userconfig/config.cpp | 3 +++ 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/settings/fnc_clear.sqf b/addons/settings/fnc_clear.sqf index 00811a2137..ce8e2e3f84 100644 --- a/addons/settings/fnc_clear.sqf +++ b/addons/settings/fnc_clear.sqf @@ -77,7 +77,7 @@ switch (toLower _source) do { case "server": { if (!isServer) exitWith {}; - profileNamespace setVariable [QGVAR(hash), HASH_NULL]; + GVAR(serverHashNamespace) setVariable [QGVAR(hash), HASH_NULL]; saveProfileNamespace; GVAR(client) call CBA_fnc_deleteNamespace; GVAR(client) = [] call CBA_fnc_createNamespace; diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index 173b9aeb6c..be7b841c87 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -166,7 +166,7 @@ GVAR(default) setVariable [_setting, [_defaultValue, _setting, _settingType, _se private _settingInfo = GVAR(userconfig) getVariable _setting; if (isNil "_settingInfo") then { - private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + private _settingsHash = GVAR(serverHashNamespace) getVariable [QGVAR(hash), HASH_NULL]; _settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; }; diff --git a/addons/settings/fnc_initDisplayMain.sqf b/addons/settings/fnc_initDisplayMain.sqf index b741e9ffcc..402a5c8939 100644 --- a/addons/settings/fnc_initDisplayMain.sqf +++ b/addons/settings/fnc_initDisplayMain.sqf @@ -28,6 +28,12 @@ if (_file != "") then { uiNamespace setVariable [QGVAR(userconfig), compileFinal str _userconfig]; +private _volatile = getNumber (configFile >> QGVAR(volatile)) == 1; +uiNamespace setVariable [QGVAR(volatile), _volatile]; +if (_volatile) then { + WARNING("Server settings changes will be lost upon game restart."); +}; + private _ctrlAddonOptions = _display displayCtrl IDC_MAIN_ADDONOPTIONS; if (isNil QUOTE(ADDON)) then { diff --git a/addons/settings/fnc_set.sqf b/addons/settings/fnc_set.sqf index f7cbb1ba2b..24c98e9a61 100644 --- a/addons/settings/fnc_set.sqf +++ b/addons/settings/fnc_set.sqf @@ -118,7 +118,7 @@ switch (toLower _source) do { private _defaultValue = [_setting, "default"] call FUNC(get); private _defaultPriority = SANITIZE_PRIORITY(_setting,0,_source); - private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + private _settingsHash = GVAR(serverHashNamespace) getVariable [QGVAR(hash), HASH_NULL]; if ([_value, _priority] isEqualTo [_defaultValue, _defaultPriority]) then { [_settingsHash, toLower _setting] call CBA_fnc_hashRem; @@ -126,7 +126,7 @@ switch (toLower _source) do { [_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet; }; - profileNamespace setVariable [QGVAR(hash), _settingsHash]; + GVAR(serverHashNamespace) setVariable [QGVAR(hash), _settingsHash]; saveProfileNamespace; }; diff --git a/addons/settings/initSettings.sqf b/addons/settings/initSettings.sqf index 71d75f8673..56e3d3c3c0 100644 --- a/addons/settings/initSettings.sqf +++ b/addons/settings/initSettings.sqf @@ -10,6 +10,9 @@ if (isNil QGVAR(default)) then { if (isNil QGVAR(server)) then { GVAR(server) = NAMESPACE_NULL; + + private _volatile = uiNamespace getVariable QGVAR(volatile); + GVAR(serverHashNamespace) = [profileNamespace, uiNamespace] select _volatile; }; if (isServer) then { diff --git a/template/cba_settings_userconfig/config.cpp b/template/cba_settings_userconfig/config.cpp index fbd45cbb22..d09e8f0d88 100644 --- a/template/cba_settings_userconfig/config.cpp +++ b/template/cba_settings_userconfig/config.cpp @@ -12,3 +12,6 @@ class CfgPatches { authors[] = {"commy2"}; }; }; + +// Uncommenting this will make any changes to "Server" settings be lost upon game restart +// cba_settings_volatile = 1;