Database changes

This commit is contained in:
Federico Cecchetto 2022-08-22 03:04:53 +02:00
parent 9d7dee67ca
commit 9bb33b1a59

View File

@ -49,7 +49,6 @@ namespace database
{ {
{".flac", "sound/"}, {".flac", "sound/"},
{".bik", "video/"}, {".bik", "video/"},
{".ff", "zone/"},
}; };
game::DB_FileSysInterface* db_fs_initialize_stub() game::DB_FileSysInterface* db_fs_initialize_stub()
@ -65,22 +64,52 @@ namespace database
} }
} }
std::string get_sound_file_name(unsigned short file_index, uint64_t packed_file_offset) // kinda sucks but whatever
std::optional<std::string> find_fastfile(const std::string& name)
{ {
if (sound_files.find(file_index) != sound_files.end() && std::string name_ = name;
sound_files[file_index].find(packed_file_offset) != sound_files[file_index].end())
if (game::DB_IsLocalized(name.data()))
{ {
return sound_files[file_index][packed_file_offset]; const auto language = game::SEH_GetCurrentLanguageName();
if (filesystem::exists(name))
{
return {name};
} }
return utils::string::va("soundfile_%i_%llX.flac", file_index, packed_file_offset); name_ = language + "/"s + name;
if (filesystem::exists(name_))
{
return {name_};
} }
std::string get_sound_file_name(game::StreamedSound* sound) name_ = "zone/" + name;
if (filesystem::exists(name_))
{ {
const auto file_index = sound->filename.fileIndex; return {name_};
const auto packed_file_offset = sound->filename.info.packed.offset; }
return get_sound_file_name(file_index, packed_file_offset);
name_ = "zone/"s + language + "/" + name;
if (filesystem::exists(name_))
{
return {name_};
}
}
else
{
if (filesystem::exists(name))
{
return {name};
}
name_ = "zone/" + name;
if (filesystem::exists(name_))
{
return {name_};
}
}
return {};
} }
game::DB_IFileSysFile* bnet_fs_open_file_stub(game::DB_FileSysInterface* this_, int folder, const char* file) game::DB_IFileSysFile* bnet_fs_open_file_stub(game::DB_FileSysInterface* this_, int folder, const char* file)
@ -95,10 +124,21 @@ namespace database
} }
}; };
if (name.ends_with(".ff"))
{
const auto found = find_fastfile(name);
if (found.has_value())
{
name = found.value();
}
}
else
{
for (const auto& [ext, path] : file_search_folders) for (const auto& [ext, path] : file_search_folders)
{ {
search_path(ext, path); search_path(ext, path);
} }
}
std::string path{}; std::string path{};
if (!filesystem::find_file(name, &path)) if (!filesystem::find_file(name, &path))
@ -257,6 +297,16 @@ namespace database
return true; return true;
} }
if (name.ends_with(".ff"))
{
const auto found = find_fastfile(name);
if (found.has_value())
{
return true;
}
}
else
{
for (const auto& [ext, path] : file_search_folders) for (const auto& [ext, path] : file_search_folders)
{ {
if (search_path(ext, path)) if (search_path(ext, path))
@ -264,6 +314,7 @@ namespace database
return true; return true;
} }
} }
}
return bnet_fs_exists_hook.invoke<bool>(this_, handle, filename); return bnet_fs_exists_hook.invoke<bool>(this_, handle, filename);
} }