diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 32a5c2ab..26d9edd5 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,5 +1,5 @@ ;sfall configuration settings -;v4.2.0 +;v4.2 [Main] ;Change to 1 if you want to use command line args to tell sfall to use another ini file. diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index f6738b91..43483c3a 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -45,7 +45,7 @@ void BugFixes::DrugsSaveFix(HANDLE file) { bool BugFixes::DrugsLoadFix(HANDLE file) { DWORD count, sizeRead; ReadFile(file, &count, 4, &sizeRead, 0); - //if (sizeRead != 4) return true; + if (sizeRead != 4) return false; for (DWORD i = 0; i < count; i++) { DWORD pid; ReadFile(file, &pid, 4, &sizeRead, 0); diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index 04fedf56..bd96c719 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -229,8 +229,10 @@ static bool LoadGame_Before() { if (uID > UniqueID::Start) Objects::uniqueID = uID; ReadFile(h, &data, 4, &size, 0); Worldmap::SetAddedYears(data >> 16); - if (size != 4 || !Perks::load(h) || script::LoadArrays(h)) goto errorLoad; - if (BugFixes::DrugsLoadFix(h)) goto errorLoad; + if (size != 4 || !Perks::load(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); } else { dlogr("Cannot open sfallgv.sav - assuming non-sfall save.", DL_MAIN); @@ -245,12 +247,13 @@ static bool LoadGame_Before() { } else { dlogr("Cannot open sfalldb.sav.", DL_MAIN); } - return false; + ///////////////////////////////////////////////// errorLoad: CloseHandle(h); dlog_f("ERROR reading data: %s\n", DL_MAIN, buf); + fo::func::debug_printf("\n[SFALL] ERROR reading data: %s", buf); return (true & !isDebug); } diff --git a/sfall/Modules/Scripting/Arrays.cpp b/sfall/Modules/Scripting/Arrays.cpp index 045667af..b2332c7b 100644 --- a/sfall/Modules/Scripting/Arrays.cpp +++ b/sfall/Modules/Scripting/Arrays.cpp @@ -183,12 +183,13 @@ bool LoadArrayElement(sArrayElement* el, HANDLE h) return (el->len) ? (unused != el->len) : (unused != 4); } -static bool LoadArraysOld(HANDLE h) { - dlogr("Loading arrays (old fmt)", DL_MAIN); - +static long LoadArraysOld(HANDLE h) { DWORD count, unused, id; 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; sArrayVar varN; @@ -196,7 +197,7 @@ static bool LoadArraysOld(HANDLE h) { for (DWORD i = 0; i < count; i++) { ReadFile(h, &id, 4, &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.data = new char[var.len * var.datalen]; @@ -226,23 +227,25 @@ static bool LoadArraysOld(HANDLE h) { arrays.insert(array_pair(id, varN)); savedArrays[varN.key] = id; } - return false; + return 1; } -bool LoadArrays(HANDLE h) { +long LoadArrays(HANDLE h) { nextArrayID = 1; - if (LoadArraysOld(h)) return true; - - dlogr("Loading arrays (new fmt)", DL_MAIN); + long result = LoadArraysOld(h); + if (result) return result; DWORD count, unused, elCount; 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; 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(arrayVar.key.type) >= 4) { // partial compatibility with 3.4 arrayVar.key.intVal = static_cast(arrayVar.key.type); arrayVar.key.type = DataType::INT; @@ -250,12 +253,12 @@ bool LoadArrays(HANDLE h) { ReadFile(h, &arrayVar.flags, 4, &unused, 0); 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(); arrayVar.val.resize(elCount); 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 arrayVar.keyHash[arrayVar.val[j]] = j; } @@ -267,7 +270,7 @@ bool LoadArrays(HANDLE h) { savedArrays[arrayVar.key] = nextArrayID++; arrayVar.keyHash.clear(); } - return false; + return 0; } void SaveArrays(HANDLE h) { diff --git a/sfall/Modules/Scripting/Arrays.h b/sfall/Modules/Scripting/Arrays.h index f2a457c9..0d2ccfd4 100644 --- a/sfall/Modules/Scripting/Arrays.h +++ b/sfall/Modules/Scripting/Arrays.h @@ -151,7 +151,7 @@ extern DWORD arraysBehavior; // saved arrays: arrayKey => arrayId extern ArrayKeysMap savedArrays; -bool LoadArrays(HANDLE h); +long LoadArrays(HANDLE h); void SaveArrays(HANDLE h); int GetNumArrays(); void GetArrays(int* arrays); diff --git a/sfall/version.h b/sfall/version.h index d31d22a3..33d512a4 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -27,7 +27,7 @@ #define VERSION_BUILD 0 #define VERSION_REV 0 -#define VERSION_STRING "4.2.0" +#define VERSION_STRING "4.2" //#define CHECK_VAL (4)