From cad948685d126cf31a9da45a054665711d945ee1 Mon Sep 17 00:00:00 2001 From: uniflare Date: Sun, 24 Apr 2022 06:09:27 +0200 Subject: [PATCH 1/2] !F (SaveLoad) Added FileXT mod capability. If FileXT isn't available, profileNamespace will be used. If there is no data in FileXT, the initial load will load from the profileNamespace for easy migration. --- Missionframework/functions/fn_doSave.sqf | 31 +++++++++++-- .../scripts/server/game/save_manager.sqf | 45 ++++++++++++++++++- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/Missionframework/functions/fn_doSave.sqf b/Missionframework/functions/fn_doSave.sqf index 8b09a9ce0..d1afd5315 100644 --- a/Missionframework/functions/fn_doSave.sqf +++ b/Missionframework/functions/fn_doSave.sqf @@ -17,6 +17,28 @@ if (!isServer) exitWith {false}; +// Write data to FileXT storage +// Param 0: (string) Filename +// Param 1: (string) Save data +fnc_saveFileXT = { + private _file = _this select 0; + private _data = _this select 1; + [_file] call filext_fnc_open; + [_file, "Data", _data] call filext_fnc_set; + [_file] call filext_fnc_write; + [_file] call filext_fnc_close; +}; + +// Write data in the server profileNamespace +// Param 0: (string) Variable name +// Param 1: (string) Save data +fnc_saveProfileNamespace = { + private _variable = _this select 0; + private _data = _this select 1; + profileNamespace setVariable [_variable, _data]; + saveProfileNamespace; +}; + if (!KPLIB_init) exitWith { ["Framework is not initalized, skipping save!", "SAVE"] call KPLIB_fnc_log; false @@ -31,9 +53,12 @@ kp_liberation_saving = true; private _saveData = [] call KPLIB_fnc_getSaveData; -// Write data in the server profileNamespace -profileNamespace setVariable [GRLIB_save_key, str _saveData]; -saveProfileNamespace; +// Check if FileXT is available +if (isClass(configFile >> "CfgPatches" >> "filext")) then { + [GRLIB_save_key + ".savedata", str _saveData] call fnc_saveFileXT; +} else { + [GRLIB_save_key, str _saveData] call fnc_saveProfileNamespace; +}; kp_liberation_saving = false; diff --git a/Missionframework/scripts/server/game/save_manager.sqf b/Missionframework/scripts/server/game/save_manager.sqf index 77cab506a..e55a44e99 100644 --- a/Missionframework/scripts/server/game/save_manager.sqf +++ b/Missionframework/scripts/server/game/save_manager.sqf @@ -161,8 +161,49 @@ stats_vehicles_recycled = 0; _x setVariable ["KP_liberation_edenObject", true]; } forEach (allMissionObjects ""); -// Get possible save data -private _saveData = profileNamespace getVariable GRLIB_save_key; +// Read data from FileXT storage +// Return: (string) Save data +// Param 0: (string) Filename +fnc_loadFileXT = { + private _file = _this select 0; + private _data = nil; + + [format ["Loading from FileXT."], "SAVE"] call KPLIB_fnc_log; + + [_file] call filext_fnc_open; + [_file] call filext_fnc_read; + _data = [_file, "Data"] call filext_fnc_get; + [_file] call filext_fnc_close; + if (!isNil "_data") then { + _data; + }; +}; + +// Write data in the server profileNamespace +// Return: (string) Save data +// Param 0: (string) Variable name +fnc_loadProfileNamespace = { + private _variable = _this select 0; + private _data = nil; + + [format ["Fallback - Loading from Profile Namespace."], "SAVE"] call KPLIB_fnc_log; + + _data = profileNamespace getVariable GRLIB_save_key; + if (!isNil "_data") then { + _data; + }; +}; + +// Check if FileXT is available +private _saveData = nil; +if (isClass(configFile >> "CfgPatches" >> "filext")) then { + _saveData = [GRLIB_save_key + ".savedata"] call fnc_loadFileXT; +}; + +// Fallback/Default to profileNamespace if _saveData is nil +if (isNil "_saveData") then { + _saveData = [GRLIB_save_key] call fnc_loadProfileNamespace; +}; // Load save data, when retrieved if (!isNil "_saveData") then { From 6358172eca8360153e5f859548d9237830f1272c Mon Sep 17 00:00:00 2001 From: uniflare Date: Fri, 6 May 2022 04:41:49 +0200 Subject: [PATCH 2/2] !XI (Integrate) ArmaLads_LIVE -> ArmaLads_FileXT @ 4240331 !FT (Save/Load) Added FileXT support for parameters with auto-migration. Simplified FileXT/profilenamespace save and load functions --- Missionframework/functions/fn_doSave.sqf | 47 ++++++----- .../functions/fn_getSaveableParam.sqf | 77 ++++++++++++++++--- .../scripts/server/game/save_manager.sqf | 54 +++++-------- 3 files changed, 109 insertions(+), 69 deletions(-) diff --git a/Missionframework/functions/fn_doSave.sqf b/Missionframework/functions/fn_doSave.sqf index d1afd5315..426c03f01 100644 --- a/Missionframework/functions/fn_doSave.sqf +++ b/Missionframework/functions/fn_doSave.sqf @@ -17,26 +17,28 @@ if (!isServer) exitWith {false}; -// Write data to FileXT storage -// Param 0: (string) Filename +// Write data to the FileXT storage, or failing that, the server profileNamespace +// Param 0: (string) File/Variable name // Param 1: (string) Save data -fnc_saveFileXT = { - private _file = _this select 0; - private _data = _this select 1; - [_file] call filext_fnc_open; - [_file, "Data", _data] call filext_fnc_set; - [_file] call filext_fnc_write; - [_file] call filext_fnc_close; -}; - -// Write data in the server profileNamespace -// Param 0: (string) Variable name -// Param 1: (string) Save data -fnc_saveProfileNamespace = { - private _variable = _this select 0; - private _data = _this select 1; - profileNamespace setVariable [_variable, _data]; - saveProfileNamespace; +fnc_saveData = { + params [ + ["_name", "", [""]], + ["_data", nil, []] + ]; + + // Check if FileXT is available + if (isClass(configFile >> "CfgPatches" >> "filext")) then { + [format ["Saving '%1' to FileXT.", _name], "SAVE"] call KPLIB_fnc_log; + _file = format ["%1.savedata", _name]; + [_file] call filext_fnc_open; + [_file, "Data", _data] call filext_fnc_set; + [_file] call filext_fnc_write; + [_file] call filext_fnc_close; + } else { + [format ["Fallback - Saving '%1' to Profile Namespace.", _name], "SAVE"] call KPLIB_fnc_log; + profileNamespace setVariable [_name, _data]; + saveProfileNamespace; + }; }; if (!KPLIB_init) exitWith { @@ -53,12 +55,7 @@ kp_liberation_saving = true; private _saveData = [] call KPLIB_fnc_getSaveData; -// Check if FileXT is available -if (isClass(configFile >> "CfgPatches" >> "filext")) then { - [GRLIB_save_key + ".savedata", str _saveData] call fnc_saveFileXT; -} else { - [GRLIB_save_key, str _saveData] call fnc_saveProfileNamespace; -}; +[GRLIB_save_key, str _saveData] call fnc_saveData; kp_liberation_saving = false; diff --git a/Missionframework/functions/fn_getSaveableParam.sqf b/Missionframework/functions/fn_getSaveableParam.sqf index 3ab50ab4c..fcf1d8bb8 100644 --- a/Missionframework/functions/fn_getSaveableParam.sqf +++ b/Missionframework/functions/fn_getSaveableParam.sqf @@ -2,11 +2,11 @@ File: fn_getSaveableParam.sqf Author: KP Liberation Dev Team - https://github.com/KillahPotatoes Date: 2018-01-27 - Last Update: 2020-04-17 + Last Update: 2022-05-06 License: MIT License - http://www.opensource.org/licenses/MIT Description: - Saves/loads/fetches mission parameter from profileNamespace depending on "_action" argument. + Saves/loads/fetches mission parameter from FileXT or profileNamespace depending on "_action" argument. If no action provided value from "KP_load_params" variable is used. On SP enviroment saving/loading is disabled. @@ -28,6 +28,60 @@ params [ private _saveKey = "KP_LIBERATION_" + (toUpper worldName) + "_SAVE_PARAMS"; private _value = nil; +// Read data from the FileXT storage, or failing that, the server profileNamespace +// Return : (string) Save data +// Param 0: (string) File/Variable name +fnc_loadData = { + params [ + ["_name", "", [""]] + ]; + private _data = nil; + + // Check if FileXT is available + if (isClass(configFile >> "CfgPatches" >> "filext")) then { + [format ["Loading '%1' from FileXT.", _name], "LOAD"] call KPLIB_fnc_log; + _file = format ["%1.savedata", _name]; + [_file] call filext_fnc_open; + [_file] call filext_fnc_read; + _data = [_file, "Data"] call filext_fnc_get; + [_file] call filext_fnc_close; + }; + + // Fallback to namespace if necessary + if (isNil "_data") then { + [format ["Fallback - Loading '%1' from Profile Namespace.", _name], "LOAD"] call KPLIB_fnc_log; + _data = profileNamespace getVariable _name; + }; + + if (!isNil "_data") then { + _data; + }; +}; + +// Write data to the FileXT storage, or failing that, the server profileNamespace +// Param 0: (string) File/Variable name +// Param 1: (string) Save data +fnc_saveData = { + params [ + ["_name", "", [""]], + ["_data", nil, []] + ]; + + // Check if FileXT is available + if (isClass(configFile >> "CfgPatches" >> "filext")) then { + [format ["Saving '%1' to FileXT.", _name], "SAVE"] call KPLIB_fnc_log; + _file = format ["%1.savedata", _name]; + [_file] call filext_fnc_open; + [_file, "Data", str _data] call filext_fnc_set; + [_file] call filext_fnc_write; + [_file] call filext_fnc_close; + } else { + [format ["Fallback - Saving '%1' to Profile Namespace.", _name], "SAVE"] call KPLIB_fnc_log; + profileNamespace setVariable [_name, _data]; + saveProfileNamespace; + }; +}; + // Use lobby value if no action specified if(isNil "_action") then {_action = KP_load_params;}; @@ -35,10 +89,11 @@ if(isNil "_action") then {_action = KP_load_params;}; if(!isMultiplayer) then {_action = 2}; switch (_action) do { - // Save to profileNamespace + // Save parameters case 0: { _value = [_paramName, _defaultValue] call bis_fnc_getParamValue; - private _savedParams = profileNamespace getVariable _saveKey; + private _savedParams = [_saveKey] call fnc_loadData; + _savedParams = parseSimpleArray _savedParams; if(isNil "_savedParams") then { if (KP_liberation_savegame_debug > 0) then {["Param save data is corrupted, creating new.", "PARAM"] call KPLIB_fnc_log;}; @@ -57,18 +112,18 @@ switch (_action) do { _singleParam set [1, _value]; }; }; - - // Save params to profile namespace - profileNamespace setVariable [_saveKey, _savedParams]; - saveProfileNamespace; + + [_saveKey, str _savedParams] call fnc_saveData; }; - // Load from profileNamespace + // Load parameters case 1: { - private _savedParams = profileNamespace getVariable _saveKey; + private _savedParams = [_saveKey] call fnc_loadData; + _savedParams = parseSimpleArray _savedParams; + if(isNil "_savedParams") then { if (KP_liberation_savegame_debug > 0) then {["Param save data is corrupted, can't load!", "PARAM"] call KPLIB_fnc_log;}; // Fix param save data - profileNamespace setVariable [_saveKey, []]; + [_saveKey, ""] call fnc_saveData; if (KP_liberation_savegame_debug > 0) then {[format ["No saved value for param: %1, fetching value.", _paramName], "PARAM"] call KPLIB_fnc_log;}; _value = [_paramName, _defaultValue] call bis_fnc_getParamValue; } else { diff --git a/Missionframework/scripts/server/game/save_manager.sqf b/Missionframework/scripts/server/game/save_manager.sqf index e55a44e99..6b60432ca 100644 --- a/Missionframework/scripts/server/game/save_manager.sqf +++ b/Missionframework/scripts/server/game/save_manager.sqf @@ -161,49 +161,37 @@ stats_vehicles_recycled = 0; _x setVariable ["KP_liberation_edenObject", true]; } forEach (allMissionObjects ""); -// Read data from FileXT storage -// Return: (string) Save data -// Param 0: (string) Filename -fnc_loadFileXT = { - private _file = _this select 0; +// Read data from the FileXT storage, or failing that, the server profileNamespace +// Return : (string) Save data +// Param 0: (string) File/Variable name +fnc_loadData = { + params [ + ["_name", "", [""]] + ]; private _data = nil; - [format ["Loading from FileXT."], "SAVE"] call KPLIB_fnc_log; - - [_file] call filext_fnc_open; - [_file] call filext_fnc_read; - _data = [_file, "Data"] call filext_fnc_get; - [_file] call filext_fnc_close; - if (!isNil "_data") then { - _data; + // Check if FileXT is available + if (isClass(configFile >> "CfgPatches" >> "filext")) then { + [format ["Loading '%1' from FileXT.", _name], "LOAD"] call KPLIB_fnc_log; + _file = format ["%1.savedata", _name]; + [_file] call filext_fnc_open; + [_file] call filext_fnc_read; + _data = [_file, "Data"] call filext_fnc_get; + [_file] call filext_fnc_close; }; -}; - -// Write data in the server profileNamespace -// Return: (string) Save data -// Param 0: (string) Variable name -fnc_loadProfileNamespace = { - private _variable = _this select 0; - private _data = nil; - [format ["Fallback - Loading from Profile Namespace."], "SAVE"] call KPLIB_fnc_log; + // Fallback to namespace if necessary + if (isNil "_data") then { + [format ["Fallback - Loading '%1' from Profile Namespace.", _name], "LOAD"] call KPLIB_fnc_log; + _data = profileNamespace getVariable _name; + }; - _data = profileNamespace getVariable GRLIB_save_key; if (!isNil "_data") then { _data; }; }; -// Check if FileXT is available -private _saveData = nil; -if (isClass(configFile >> "CfgPatches" >> "filext")) then { - _saveData = [GRLIB_save_key + ".savedata"] call fnc_loadFileXT; -}; - -// Fallback/Default to profileNamespace if _saveData is nil -if (isNil "_saveData") then { - _saveData = [GRLIB_save_key] call fnc_loadProfileNamespace; -}; +_saveData = [GRLIB_save_key] call fnc_loadData; // Load save data, when retrieved if (!isNil "_saveData") then {