Skip to content

Commit

Permalink
Added FileXT mod capability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apricot-ale committed Mar 2, 2023
1 parent 5573b36 commit 3df3878
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 16 deletions.
30 changes: 26 additions & 4 deletions Missionframework/functions/fn_doSave.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: fn_doSave.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2020-03-29
Last Update: 2020-05-10
Last Update: 2023-03-02
License: MIT License - http://www.opensource.org/licenses/MIT
Description:
Expand All @@ -17,6 +17,30 @@

if (!isServer) exitWith {false};

// 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", _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 {
["Framework is not initalized, skipping save!", "SAVE"] call KPLIB_fnc_log;
false
Expand All @@ -31,9 +55,7 @@ KPLIB_saving = true;

private _saveData = [] call KPLIB_fnc_getSaveData;

// Write data in the server profileNamespace
profileNamespace setVariable [KPLIB_save_key, str _saveData];
saveProfileNamespace;
[KPLIB_save_key, str _saveData] call fnc_saveData;

KPLIB_saving = false;

Expand Down
74 changes: 64 additions & 10 deletions Missionframework/functions/fn_getSaveableParam.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
File: fn_getSaveableParam.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-01-27
Last Update: 2020-08-06
Last Update: 2023-03-02
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.
Expand All @@ -27,17 +27,72 @@ 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;};

// We propably shoud not load parameters on SP environment
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 KPLIB_save_paramKey;
private _savedParams = [KPLIB_save_paramKey] call fnc_loadData;
_savedParams = parseSimpleArray _savedParams;

if(isNil "_savedParams") then {
if (KPLIB_savegame_debug > 0) then {["Param save data is corrupted, creating new.", "PARAM"] call KPLIB_fnc_log;};
Expand All @@ -57,17 +112,16 @@ switch (_action) do {
};
};

// Save params to profile namespace
profileNamespace setVariable [KPLIB_save_paramKey, _savedParams];
saveProfileNamespace;
[KPLIB_save_paramKey, str _savedParams] call fnc_saveData;
};
// Load from profileNamespace
// Load parameters
case 1: {
private _savedParams = profileNamespace getVariable KPLIB_save_paramKey;
private _savedParams = [KPLIB_save_paramKey] call fnc_loadData;
_savedParams = parseSimpleArray _savedParams;
if(isNil "_savedParams") then {
if (KPLIB_savegame_debug > 0) then {["Param save data is corrupted, can't load!", "PARAM"] call KPLIB_fnc_log;};
// Fix param save data
profileNamespace setVariable [KPLIB_save_paramKey, []];
[KPLIB_save_paramKey, ""] call fnc_saveData;
if (KPLIB_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 {
Expand Down
33 changes: 31 additions & 2 deletions Missionframework/scripts/server/game/save_manager.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,37 @@ stats_vehicles_recycled = 0;
_x setVariable ["KPLIB_edenObject", true];
} forEach (allMissionObjects "");

// Get possible save data
private _saveData = profileNamespace getVariable KPLIB_save_key;
// 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;
};
};

_saveData = [KPLIB_save_key] call fnc_loadData;

// Load save data, when retrieved
if (!isNil "_saveData") then {
Expand Down

0 comments on commit 3df3878

Please sign in to comment.