h2-mod/src/client/component/database.cpp

61 lines
1.7 KiB
C++
Raw Normal View History

2022-04-15 12:54:49 -04:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/dvars.hpp"
#include "game/game.hpp"
2022-05-02 19:00:08 -04:00
#include <utils/io.hpp>
2022-04-15 12:54:49 -04:00
#include <utils/hook.hpp>
namespace database
{
namespace
{
game::dvar_t* db_filesysImpl = nullptr;
2022-05-02 19:41:05 -04:00
utils::hook::detour db_fs_initialize_hook;
2022-04-15 12:54:49 -04:00
2022-05-02 19:41:05 -04:00
game::DB_FileSysInterface* db_fs_initialize_stub()
2022-04-15 12:54:49 -04:00
{
switch (db_filesysImpl->current.integer)
{
case 0:
return reinterpret_cast<game::DB_FileSysInterface*>(0x140BE82F8); // ptr to vtable of BnetTACTVFSManager (implements DB_FileSysInterface)
case 1:
return reinterpret_cast<game::DB_FileSysInterface*>(0x140BEFDC0); // ptr to vtable of DiskFS (implements DB_FileSysInterface)
default:
return nullptr; // this should not happen
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
2022-05-02 19:41:05 -04:00
static const char* values[] =
{
2022-04-15 12:54:49 -04:00
"BnetTACTVFSManager", // (load files from CASC)
"DiskFS", // (load files from disk)
nullptr
};
2022-05-02 19:41:05 -04:00
const auto default_value = static_cast<int>(!utils::io::directory_exists("Data/data")
|| !utils::io::directory_exists("Data/config")
|| !utils::io::directory_exists("Data/indices"));
2022-04-15 12:54:49 -04:00
db_filesysImpl = dvars::register_enum("db_filesysImpl", values, default_value, game::DVAR_FLAG_READ);
if (default_value == 1)
{
utils::hook::nop(0x1405A4868, 22); // TACT related stuff that's pointless if we're using DiskFS
2022-05-02 19:00:08 -04:00
utils::hook::nop(0x14071AF83, 45); // Skip setting Bink file OS callbacks (not necessary since we're loading from disk)
2022-04-15 12:54:49 -04:00
}
2022-05-02 19:41:05 -04:00
db_fs_initialize_hook.create(game::DB_FSInitialize, db_fs_initialize_stub);
2022-04-15 12:54:49 -04:00
}
};
}
REGISTER_COMPONENT(database::component)