Skip to content

Commit 6086b51

Browse files
committed
- fix zero save file size
- use new DNGUserProfileName - fix missionCompleted copy-paste typo
1 parent 4f0ad2a commit 6086b51

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

data/scripts/driverNGProfileSettings.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ local function CreateCustomSaveData()
5050
end
5151

5252
local nativeProfileSettings = ProfileSettings
53-
local CustomProfileSettings = {
53+
CustomProfileSettings = {
5454
customDataLoaded = false,
5555
data = CreateCustomSaveData()
5656
}
@@ -70,17 +70,18 @@ local function TryLoadProfileSettings()
7070
end
7171

7272
-- load file
73-
if localPlayer == nil or localPlayer.name == nil or localPlayer.name:len() == 0 then
73+
if DNGUserProfileName == nil then
74+
error("old Hook version used")
7475
return
7576
end
7677

7778
CustomProfileSettings.data = CreateCustomSaveData()
7879
CustomProfileSettings.customDataLoaded = true
7980

8081
print("--------- LOAD CUSTOM PROFILE SETTINGS ---------")
81-
print("player name ".. localPlayer.name)
82+
print("player name ".. DNGUserProfileName)
8283

83-
local saveFileName = UserDocumentsPath..localPlayer.name..AUTOSAVE_CUSTOM_PATH
84+
local saveFileName = UserDocumentsPath..DNGUserProfileName..AUTOSAVE_CUSTOM_PATH
8485
local file = io.open(saveFileName, "rb")
8586
if file == nil then
8687
print("No custom profile save data found at "..saveFileName)
@@ -91,6 +92,7 @@ local function TryLoadProfileSettings()
9192
local sig, version = struct.unpack('c4i', file:read(8))
9293
if sig ~= SAVE_SIGNATURE or version ~= SAVE_VERSION then
9394
print("Invalid save file "..saveFileName)
95+
file:close()
9496
return
9597
end
9698

@@ -115,14 +117,16 @@ local function TryLoadProfileSettings()
115117
print(tostring(err))
116118
print(debug.traceback())
117119
end)
120+
121+
file:close()
118122
end
119123

120124
local function TrySaveProfileSettings()
121125
print("--------- SAVE CUSTOM PROFILE SETTINGS ---------")
122126

123127
CustomProfileSettings.customDataLoaded = true
124128

125-
local saveFileName = UserDocumentsPath..localPlayer.name..AUTOSAVE_CUSTOM_PATH
129+
local saveFileName = UserDocumentsPath..DNGUserProfileName..AUTOSAVE_CUSTOM_PATH
126130
local file = io.open(saveFileName, "wb")
127131
if file == nil then
128132
print("Cannot store custom profile save data at "..saveFileName)
@@ -148,6 +152,7 @@ local function TrySaveProfileSettings()
148152
writeArray(file, data.challengeNew)
149153
writeArray(file, data.collectableUnlocked)
150154
writeArray(file, data.collectableOwned)
155+
file:close()
151156
end
152157

153158
-- Triggers an autosave (if enabled)
@@ -223,7 +228,7 @@ end
223228

224229
-- PARAM<1,MissionID>Set mission completed
225230
CustomProfileSettings.SetMissionCompleted = function(missionId)
226-
CustomProfileSettings.data.missionAttempted[missionId] = true
231+
CustomProfileSettings.data.missionCompleted[missionId] = true
227232
end
228233

229234
-- PARAM<1,MissionID>Get whether a mission is new or not

0 commit comments

Comments
 (0)