mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Fixed the error handling on loading sfallgv.sav
* to improve backward compatibility with older saved games.
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
;sfall configuration settings
|
;sfall configuration settings
|
||||||
;v4.2.0
|
;v4.2
|
||||||
|
|
||||||
[Main]
|
[Main]
|
||||||
;Change to 1 if you want to use command line args to tell sfall to use another ini file.
|
;Change to 1 if you want to use command line args to tell sfall to use another ini file.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ void BugFixes::DrugsSaveFix(HANDLE file) {
|
|||||||
bool BugFixes::DrugsLoadFix(HANDLE file) {
|
bool BugFixes::DrugsLoadFix(HANDLE file) {
|
||||||
DWORD count, sizeRead;
|
DWORD count, sizeRead;
|
||||||
ReadFile(file, &count, 4, &sizeRead, 0);
|
ReadFile(file, &count, 4, &sizeRead, 0);
|
||||||
//if (sizeRead != 4) return true;
|
if (sizeRead != 4) return false;
|
||||||
for (DWORD i = 0; i < count; i++) {
|
for (DWORD i = 0; i < count; i++) {
|
||||||
DWORD pid;
|
DWORD pid;
|
||||||
ReadFile(file, &pid, 4, &sizeRead, 0);
|
ReadFile(file, &pid, 4, &sizeRead, 0);
|
||||||
|
|||||||
@@ -229,8 +229,10 @@ static bool LoadGame_Before() {
|
|||||||
if (uID > UniqueID::Start) Objects::uniqueID = uID;
|
if (uID > UniqueID::Start) Objects::uniqueID = uID;
|
||||||
ReadFile(h, &data, 4, &size, 0);
|
ReadFile(h, &data, 4, &size, 0);
|
||||||
Worldmap::SetAddedYears(data >> 16);
|
Worldmap::SetAddedYears(data >> 16);
|
||||||
if (size != 4 || !Perks::load(h) || script::LoadArrays(h)) goto errorLoad;
|
if (size != 4 || !Perks::load(h)) goto errorLoad;
|
||||||
if (BugFixes::DrugsLoadFix(h)) goto errorLoad;
|
long result = script::LoadArrays(h); // 1 - old save, -1 - broken save
|
||||||
|
if (result == -1) goto errorLoad;
|
||||||
|
if (!result && BugFixes::DrugsLoadFix(h)) goto errorLoad;
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
} else {
|
} else {
|
||||||
dlogr("Cannot open sfallgv.sav - assuming non-sfall save.", DL_MAIN);
|
dlogr("Cannot open sfallgv.sav - assuming non-sfall save.", DL_MAIN);
|
||||||
@@ -245,12 +247,13 @@ static bool LoadGame_Before() {
|
|||||||
} else {
|
} else {
|
||||||
dlogr("Cannot open sfalldb.sav.", DL_MAIN);
|
dlogr("Cannot open sfalldb.sav.", DL_MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
errorLoad:
|
errorLoad:
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
dlog_f("ERROR reading data: %s\n", DL_MAIN, buf);
|
dlog_f("ERROR reading data: %s\n", DL_MAIN, buf);
|
||||||
|
fo::func::debug_printf("\n[SFALL] ERROR reading data: %s", buf);
|
||||||
return (true & !isDebug);
|
return (true & !isDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,12 +183,13 @@ bool LoadArrayElement(sArrayElement* el, HANDLE h)
|
|||||||
return (el->len) ? (unused != el->len) : (unused != 4);
|
return (el->len) ? (unused != el->len) : (unused != 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool LoadArraysOld(HANDLE h) {
|
static long LoadArraysOld(HANDLE h) {
|
||||||
dlogr("Loading arrays (old fmt)", DL_MAIN);
|
|
||||||
|
|
||||||
DWORD count, unused, id;
|
DWORD count, unused, id;
|
||||||
ReadFile(h, &count, 4, &unused, 0); // count of saved arrays
|
ReadFile(h, &count, 4, &unused, 0); // count of saved arrays
|
||||||
if (unused != 4) return true;
|
if (unused != 4) return -1;
|
||||||
|
if (!count) return 0;
|
||||||
|
|
||||||
|
dlogr("Loading arrays (old fmt)", DL_MAIN);
|
||||||
|
|
||||||
sArrayVarOld var;
|
sArrayVarOld var;
|
||||||
sArrayVar varN;
|
sArrayVar varN;
|
||||||
@@ -196,7 +197,7 @@ static bool LoadArraysOld(HANDLE h) {
|
|||||||
for (DWORD i = 0; i < count; i++) {
|
for (DWORD i = 0; i < count; i++) {
|
||||||
ReadFile(h, &id, 4, &unused, 0);
|
ReadFile(h, &id, 4, &unused, 0);
|
||||||
ReadFile(h, &var, 8, &unused, 0);
|
ReadFile(h, &var, 8, &unused, 0);
|
||||||
if (unused != 8) return true;
|
if (unused != 8) return -1;
|
||||||
|
|
||||||
var.types = new DWORD[var.len];
|
var.types = new DWORD[var.len];
|
||||||
var.data = new char[var.len * var.datalen];
|
var.data = new char[var.len * var.datalen];
|
||||||
@@ -226,23 +227,25 @@ static bool LoadArraysOld(HANDLE h) {
|
|||||||
arrays.insert(array_pair(id, varN));
|
arrays.insert(array_pair(id, varN));
|
||||||
savedArrays[varN.key] = id;
|
savedArrays[varN.key] = id;
|
||||||
}
|
}
|
||||||
return false;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadArrays(HANDLE h) {
|
long LoadArrays(HANDLE h) {
|
||||||
nextArrayID = 1;
|
nextArrayID = 1;
|
||||||
|
|
||||||
if (LoadArraysOld(h)) return true;
|
long result = LoadArraysOld(h);
|
||||||
|
if (result) return result;
|
||||||
dlogr("Loading arrays (new fmt)", DL_MAIN);
|
|
||||||
|
|
||||||
DWORD count, unused, elCount;
|
DWORD count, unused, elCount;
|
||||||
ReadFile(h, &count, 4, &unused, 0); // count of saved arrays
|
ReadFile(h, &count, 4, &unused, 0); // count of saved arrays
|
||||||
if (unused != 4) return true;
|
if (unused != 4 && !result) return 1;
|
||||||
|
|
||||||
|
dlogr("Loading arrays (new fmt)", DL_MAIN);
|
||||||
|
if (unused != 4) return -1;
|
||||||
|
|
||||||
sArrayVar arrayVar;
|
sArrayVar arrayVar;
|
||||||
for (DWORD i = 0; i < count; i++) {
|
for (DWORD i = 0; i < count; i++) {
|
||||||
if (LoadArrayElement(&arrayVar.key, h)) return true;
|
if (LoadArrayElement(&arrayVar.key, h)) return -1;
|
||||||
if (arrayVar.key.intVal == 0 || static_cast<long>(arrayVar.key.type) >= 4) { // partial compatibility with 3.4
|
if (arrayVar.key.intVal == 0 || static_cast<long>(arrayVar.key.type) >= 4) { // partial compatibility with 3.4
|
||||||
arrayVar.key.intVal = static_cast<long>(arrayVar.key.type);
|
arrayVar.key.intVal = static_cast<long>(arrayVar.key.type);
|
||||||
arrayVar.key.type = DataType::INT;
|
arrayVar.key.type = DataType::INT;
|
||||||
@@ -250,12 +253,12 @@ bool LoadArrays(HANDLE h) {
|
|||||||
|
|
||||||
ReadFile(h, &arrayVar.flags, 4, &unused, 0);
|
ReadFile(h, &arrayVar.flags, 4, &unused, 0);
|
||||||
ReadFile(h, &elCount, 4, &unused, 0); // actual number of elements: keys+values
|
ReadFile(h, &elCount, 4, &unused, 0); // actual number of elements: keys+values
|
||||||
if (unused != 4) return true;
|
if (unused != 4) return -1;
|
||||||
|
|
||||||
bool isAssoc = arrayVar.isAssoc();
|
bool isAssoc = arrayVar.isAssoc();
|
||||||
arrayVar.val.resize(elCount);
|
arrayVar.val.resize(elCount);
|
||||||
for (size_t j = 0; j < elCount; j++) { // normal and associative arrays stored and loaded equally
|
for (size_t j = 0; j < elCount; j++) { // normal and associative arrays stored and loaded equally
|
||||||
if (LoadArrayElement(&arrayVar.val[j], h)) return true;
|
if (LoadArrayElement(&arrayVar.val[j], h)) return -1;
|
||||||
if (isAssoc && (j % 2) == 0) { // only difference is that keyHash is filled with appropriate indexes
|
if (isAssoc && (j % 2) == 0) { // only difference is that keyHash is filled with appropriate indexes
|
||||||
arrayVar.keyHash[arrayVar.val[j]] = j;
|
arrayVar.keyHash[arrayVar.val[j]] = j;
|
||||||
}
|
}
|
||||||
@@ -267,7 +270,7 @@ bool LoadArrays(HANDLE h) {
|
|||||||
savedArrays[arrayVar.key] = nextArrayID++;
|
savedArrays[arrayVar.key] = nextArrayID++;
|
||||||
arrayVar.keyHash.clear();
|
arrayVar.keyHash.clear();
|
||||||
}
|
}
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveArrays(HANDLE h) {
|
void SaveArrays(HANDLE h) {
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ extern DWORD arraysBehavior;
|
|||||||
// saved arrays: arrayKey => arrayId
|
// saved arrays: arrayKey => arrayId
|
||||||
extern ArrayKeysMap savedArrays;
|
extern ArrayKeysMap savedArrays;
|
||||||
|
|
||||||
bool LoadArrays(HANDLE h);
|
long LoadArrays(HANDLE h);
|
||||||
void SaveArrays(HANDLE h);
|
void SaveArrays(HANDLE h);
|
||||||
int GetNumArrays();
|
int GetNumArrays();
|
||||||
void GetArrays(int* arrays);
|
void GetArrays(int* arrays);
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
#define VERSION_BUILD 0
|
#define VERSION_BUILD 0
|
||||||
#define VERSION_REV 0
|
#define VERSION_REV 0
|
||||||
|
|
||||||
#define VERSION_STRING "4.2.0"
|
#define VERSION_STRING "4.2"
|
||||||
|
|
||||||
//#define CHECK_VAL (4)
|
//#define CHECK_VAL (4)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user