Skip to content

Commit 3df3878

Browse files
committed
Added FileXT mod capability.
KillahPotatoes#915
1 parent 5573b36 commit 3df3878

File tree

3 files changed

+121
-16
lines changed

3 files changed

+121
-16
lines changed

Missionframework/functions/fn_doSave.sqf

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
File: fn_doSave.sqf
33
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
44
Date: 2020-03-29
5-
Last Update: 2020-05-10
5+
Last Update: 2023-03-02
66
License: MIT License - http://www.opensource.org/licenses/MIT
77
88
Description:
@@ -17,6 +17,30 @@
1717

1818
if (!isServer) exitWith {false};
1919

20+
// Write data to the FileXT storage, or failing that, the server profileNamespace
21+
// Param 0: (string) File/Variable name
22+
// Param 1: (string) Save data
23+
fnc_saveData = {
24+
params [
25+
["_name", "", [""]],
26+
["_data", nil, []]
27+
];
28+
29+
// Check if FileXT is available
30+
if (isClass(configFile >> "CfgPatches" >> "filext")) then {
31+
[format ["Saving '%1' to FileXT.", _name], "SAVE"] call KPLIB_fnc_log;
32+
_file = format ["%1.savedata", _name];
33+
[_file] call filext_fnc_open;
34+
[_file, "Data", _data] call filext_fnc_set;
35+
[_file] call filext_fnc_write;
36+
[_file] call filext_fnc_close;
37+
} else {
38+
[format ["Fallback - Saving '%1' to Profile Namespace.", _name], "SAVE"] call KPLIB_fnc_log;
39+
profileNamespace setVariable [_name, _data];
40+
saveProfileNamespace;
41+
};
42+
};
43+
2044
if (!KPLIB_init) exitWith {
2145
["Framework is not initalized, skipping save!", "SAVE"] call KPLIB_fnc_log;
2246
false
@@ -31,9 +55,7 @@ KPLIB_saving = true;
3155

3256
private _saveData = [] call KPLIB_fnc_getSaveData;
3357

34-
// Write data in the server profileNamespace
35-
profileNamespace setVariable [KPLIB_save_key, str _saveData];
36-
saveProfileNamespace;
58+
[KPLIB_save_key, str _saveData] call fnc_saveData;
3759

3860
KPLIB_saving = false;
3961

Missionframework/functions/fn_getSaveableParam.sqf

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
File: fn_getSaveableParam.sqf
33
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
44
Date: 2018-01-27
5-
Last Update: 2020-08-06
5+
Last Update: 2023-03-02
66
License: MIT License - http://www.opensource.org/licenses/MIT
77
88
Description:
9-
Saves/loads/fetches mission parameter from profileNamespace depending on "_action" argument.
9+
Saves/loads/fetches mission parameter from FileXT or profileNamespace depending on "_action" argument.
1010
If no action provided value from "KP_load_params" variable is used.
1111
On SP enviroment saving/loading is disabled.
1212
@@ -27,17 +27,72 @@ params [
2727

2828
private _value = nil;
2929

30+
// Read data from the FileXT storage, or failing that, the server profileNamespace
31+
// Return : (string) Save data
32+
// Param 0: (string) File/Variable name
33+
fnc_loadData = {
34+
params [
35+
["_name", "", [""]]
36+
];
37+
private _data = nil;
38+
39+
// Check if FileXT is available
40+
if (isClass(configFile >> "CfgPatches" >> "filext")) then {
41+
[format ["Loading '%1' from FileXT.", _name], "LOAD"] call KPLIB_fnc_log;
42+
_file = format ["%1.savedata", _name];
43+
[_file] call filext_fnc_open;
44+
[_file] call filext_fnc_read;
45+
_data = [_file, "Data"] call filext_fnc_get;
46+
[_file] call filext_fnc_close;
47+
};
48+
49+
// Fallback to namespace if necessary
50+
if (isNil "_data") then {
51+
[format ["Fallback - Loading '%1' from Profile Namespace.", _name], "LOAD"] call KPLIB_fnc_log;
52+
_data = profileNamespace getVariable _name;
53+
};
54+
55+
if (!isNil "_data") then {
56+
_data;
57+
};
58+
};
59+
60+
// Write data to the FileXT storage, or failing that, the server profileNamespace
61+
// Param 0: (string) File/Variable name
62+
// Param 1: (string) Save data
63+
fnc_saveData = {
64+
params [
65+
["_name", "", [""]],
66+
["_data", nil, []]
67+
];
68+
69+
// Check if FileXT is available
70+
if (isClass(configFile >> "CfgPatches" >> "filext")) then {
71+
[format ["Saving '%1' to FileXT.", _name], "SAVE"] call KPLIB_fnc_log;
72+
_file = format ["%1.savedata", _name];
73+
[_file] call filext_fnc_open;
74+
[_file, "Data", str _data] call filext_fnc_set;
75+
[_file] call filext_fnc_write;
76+
[_file] call filext_fnc_close;
77+
} else {
78+
[format ["Fallback - Saving '%1' to Profile Namespace.", _name], "SAVE"] call KPLIB_fnc_log;
79+
profileNamespace setVariable [_name, _data];
80+
saveProfileNamespace;
81+
};
82+
};
83+
3084
// Use lobby value if no action specified
3185
if(isNil "_action") then {_action = KP_load_params;};
3286

3387
// We propably shoud not load parameters on SP environment
3488
if(!isMultiplayer) then {_action = 2};
3589

3690
switch (_action) do {
37-
// Save to profileNamespace
91+
// Save parameters
3892
case 0: {
3993
_value = [_paramName, _defaultValue] call bis_fnc_getParamValue;
40-
private _savedParams = profileNamespace getVariable KPLIB_save_paramKey;
94+
private _savedParams = [KPLIB_save_paramKey] call fnc_loadData;
95+
_savedParams = parseSimpleArray _savedParams;
4196

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

60-
// Save params to profile namespace
61-
profileNamespace setVariable [KPLIB_save_paramKey, _savedParams];
62-
saveProfileNamespace;
115+
[KPLIB_save_paramKey, str _savedParams] call fnc_saveData;
63116
};
64-
// Load from profileNamespace
117+
// Load parameters
65118
case 1: {
66-
private _savedParams = profileNamespace getVariable KPLIB_save_paramKey;
119+
private _savedParams = [KPLIB_save_paramKey] call fnc_loadData;
120+
_savedParams = parseSimpleArray _savedParams;
67121
if(isNil "_savedParams") then {
68122
if (KPLIB_savegame_debug > 0) then {["Param save data is corrupted, can't load!", "PARAM"] call KPLIB_fnc_log;};
69123
// Fix param save data
70-
profileNamespace setVariable [KPLIB_save_paramKey, []];
124+
[KPLIB_save_paramKey, ""] call fnc_saveData;
71125
if (KPLIB_savegame_debug > 0) then {[format ["No saved value for param: %1, fetching value.", _paramName], "PARAM"] call KPLIB_fnc_log;};
72126
_value = [_paramName, _defaultValue] call bis_fnc_getParamValue;
73127
} else {

Missionframework/scripts/server/game/save_manager.sqf

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,37 @@ stats_vehicles_recycled = 0;
161161
_x setVariable ["KPLIB_edenObject", true];
162162
} forEach (allMissionObjects "");
163163

164-
// Get possible save data
165-
private _saveData = profileNamespace getVariable KPLIB_save_key;
164+
// Read data from the FileXT storage, or failing that, the server profileNamespace
165+
// Return : (string) Save data
166+
// Param 0: (string) File/Variable name
167+
fnc_loadData = {
168+
params [
169+
["_name", "", [""]]
170+
];
171+
private _data = nil;
172+
173+
// Check if FileXT is available
174+
if (isClass(configFile >> "CfgPatches" >> "filext")) then {
175+
[format ["Loading '%1' from FileXT.", _name], "LOAD"] call KPLIB_fnc_log;
176+
_file = format ["%1.savedata", _name];
177+
[_file] call filext_fnc_open;
178+
[_file] call filext_fnc_read;
179+
_data = [_file, "Data"] call filext_fnc_get;
180+
[_file] call filext_fnc_close;
181+
};
182+
183+
// Fallback to namespace if necessary
184+
if (isNil "_data") then {
185+
[format ["Fallback - Loading '%1' from Profile Namespace.", _name], "LOAD"] call KPLIB_fnc_log;
186+
_data = profileNamespace getVariable _name;
187+
};
188+
189+
if (!isNil "_data") then {
190+
_data;
191+
};
192+
};
193+
194+
_saveData = [KPLIB_save_key] call fnc_loadData;
166195

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

0 commit comments

Comments
 (0)