Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!F (SaveLoad) Added FileXT mod capability. #915

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions Missionframework/functions/fn_doSave.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ kp_liberation_saving = true;

private _saveData = [] call KPLIB_fnc_getSaveData;

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

kp_liberation_saving = false;

Expand Down
77 changes: 66 additions & 11 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-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.

Expand All @@ -28,17 +28,72 @@ 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;};

// 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 _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;};
Expand All @@ -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 {
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 ["KP_liberation_edenObject", true];
} forEach (allMissionObjects "");

// Get possible save data
private _saveData = profileNamespace getVariable GRLIB_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 = [GRLIB_save_key] call fnc_loadData;

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