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

57 lines
1.6 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:00:08 -04:00
utils::hook::detour db_fsinitialize_hook;
2022-04-15 12:54:49 -04:00
2022-05-02 19:00:08 -04:00
game::DB_FileSysInterface* db_fsinitialize_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
{
static const char* values[] = {
"BnetTACTVFSManager", // (load files from CASC)
"DiskFS", // (load files from disk)
nullptr
};
int default_value = (utils::io::directory_exists("Data/data") && utils::io::directory_exists("Data/config") && utils::io::directory_exists("Data/indices")) ? 0 : 1;
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:00:08 -04:00
db_fsinitialize_hook.create(game::DB_FSInitialize, db_fsinitialize_stub);
2022-04-15 12:54:49 -04:00
}
};
}
REGISTER_COMPONENT(database::component)