diff --git a/src/art.cc b/src/art.cc index f9d85cf..b81422b 100644 --- a/src/art.cc +++ b/src/art.cc @@ -146,15 +146,31 @@ int artInit() gArtLanguageInitialized = true; } + bool critterDbSelected = false; for (int objectType = 0; objectType < OBJ_TYPE_COUNT; objectType++) { gArtListDescriptions[objectType].flags = 0; sprintf(path, "%s%s%s\\%s.lst", _cd_path_base, "art\\", gArtListDescriptions[objectType].name, gArtListDescriptions[objectType].name); + int oldDb; + if (objectType == OBJ_TYPE_CRITTER) { + oldDb = _db_current(); + critterDbSelected = true; + _db_select(_critter_db_handle); + } + if (artReadList(path, &(gArtListDescriptions[objectType].fileNames), &(gArtListDescriptions[objectType].fileNamesLength)) != 0) { debugPrint("art_read_lst failed in art_init\n"); + if (critterDbSelected) { + _db_select(oldDb); + } cacheFree(&gArtCache); return -1; } + + if (objectType == OBJ_TYPE_CRITTER) { + critterDbSelected = false; + _db_select(oldDb); + } } _anon_alias = (int*)internal_malloc(sizeof(*_anon_alias) * gArtListDescriptions[OBJ_TYPE_CRITTER].fileNamesLength); @@ -848,8 +864,8 @@ bool artExists(int fid) int oldDb = -1; if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) { - oldDb = _db_current(1); - _db_current(_critter_db_handle); + oldDb = _db_current(); + _db_select(_critter_db_handle); } char* filePath = artBuildFilePath(fid); @@ -861,27 +877,38 @@ bool artExists(int fid) } if (oldDb != -1) { - _db_current(oldDb); + _db_select(oldDb); } return result; } +// NOTE: Exactly the same implementation as `artExists`. +// // 0x419930 bool _art_fid_valid(int fid) { - // NOTE: Original Code involves calling some unknown function. Check in debugger in mapper. + bool result = false; + int oldDb = -1; + + if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) { + oldDb = _db_current(); + _db_select(_critter_db_handle); + } + char* filePath = artBuildFilePath(fid); - if (filePath == NULL) { - return false; + if (filePath != NULL) { + int fileSize; + if (dbGetFileSize(filePath, &fileSize) != -1) { + result = true; + } } - int fileSize; - if (dbGetFileSize(filePath, &fileSize) == -1) { - return false; + if (oldDb != -1) { + _db_select(oldDb); } - return true; + return result; } // 0x419998 @@ -931,8 +958,8 @@ static int artCacheGetFileSizeImpl(int fid, int* sizePtr) int result = -1; if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) { - oldDb = _db_current(1); - _db_current(_critter_db_handle); + oldDb = _db_current(); + _db_select(_critter_db_handle); } char* artFilePath = artBuildFilePath(fid); @@ -967,7 +994,7 @@ static int artCacheGetFileSizeImpl(int fid, int* sizePtr) } if (oldDb != -1) { - _db_current(oldDb); + _db_select(oldDb); } return result; @@ -980,8 +1007,8 @@ static int artCacheReadDataImpl(int fid, int* sizePtr, unsigned char* data) int result = -1; if (FID_TYPE(fid) == OBJ_TYPE_CRITTER) { - oldDb = _db_current(1); - _db_current(_critter_db_handle); + oldDb = _db_current(); + _db_select(_critter_db_handle); } char* artFileName = artBuildFilePath(fid); @@ -1015,7 +1042,7 @@ static int artCacheReadDataImpl(int fid, int* sizePtr, unsigned char* data) } if (oldDb != -1) { - _db_current(oldDb); + _db_select(oldDb); } return result; diff --git a/src/db.cc b/src/db.cc index b0399b0..647a3fb 100644 --- a/src/db.cc +++ b/src/db.cc @@ -61,20 +61,22 @@ int dbOpen(const char* filePath1, int a2, const char* filePath2, int a4) return 0; } -// NOTE: This function simply returns 0, but it definitely accept one parameter -// via eax, as seen at every call site. This value is ignored. It's impossible -// to guess it's name. -// // 0x4C5D54 -int _db_current(int a1) +int _db_select(int dbHandle) +{ + return 0; +} + +// NOTE: Uncollapsed 0x4C5D54. +int _db_current() { return 0; } // 0x4C5D58 -bool _db_total() +int _db_total() { - return true; + return 0; } // 0x4C5D60 diff --git a/src/db.h b/src/db.h index f6206a6..986feb2 100644 --- a/src/db.h +++ b/src/db.h @@ -11,8 +11,9 @@ typedef void FileReadProgressHandler(); typedef char* StrdupProc(const char* string); int dbOpen(const char* filePath1, int a2, const char* filePath2, int a4); -int _db_current(int a1); -bool _db_total(); +int _db_select(int dbHandle); +int _db_current(); +int _db_total(); void dbExit(); int dbGetFileSize(const char* filePath, int* sizePtr); int dbGetFileContents(const char* filePath, void* ptr); diff --git a/src/game.cc b/src/game.cc index e77acd8..38ae806 100644 --- a/src/game.cc +++ b/src/game.cc @@ -1251,6 +1251,7 @@ static int gameDbInit() _critter_db_handle = dbOpen(main_file_name, 0, patch_file_name, 1); if (_critter_db_handle == -1) { + _db_select(_master_db_handle); showMesageBox("Could not find the critter datafile. Please make sure the FALLOUT CD is in the drive and that you are running FALLOUT from the directory you installed it to."); return -1; } @@ -1263,6 +1264,8 @@ static int gameDbInit() } } + _db_select(_master_db_handle); + return 0; } diff --git a/src/window_manager.cc b/src/window_manager.cc index 9840c71..5411ab1 100644 --- a/src/window_manager.cc +++ b/src/window_manager.cc @@ -132,7 +132,7 @@ int windowManagerInit(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitP gOrderedWindowIds[index] = -1; } - if (!_db_total()) { + if (_db_total() == 0) { if (dbOpen(NULL, 0, _path_patches, 1) == -1) { return WINDOW_MANAGER_ERR_INITIALIZING_DEFAULT_DATABASE; }