h1-mod/src/client/component/fastfiles.cpp

60 lines
1.4 KiB
C++
Raw Normal View History

2022-03-01 15:38:52 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "fastfiles.hpp"
#include "command.hpp"
#include "console.hpp"
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
namespace fastfiles
{
static utils::concurrency::container<std::string> current_fastfile;
namespace
{
utils::hook::detour db_try_load_x_file_internal_hook;
void db_try_load_x_file_internal(const char* zone_name, const int flags)
{
printf("Loading fastfile %s\n", zone_name);
current_fastfile.access([&](std::string& fastfile)
{
fastfile = zone_name;
});
db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags);
}
}
std::string get_current_fastfile()
{
return current_fastfile.access<std::string>([&](std::string& fastfile)
{
return fastfile;
});
}
2022-03-13 10:31:57 -04:00
void enum_assets(const game::XAssetType type,
const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride)
{
game::DB_EnumXAssets_Internal(type, static_cast<void(*)(game::XAssetHeader, void*)>([](game::XAssetHeader header, void* data)
{
const auto& cb = *static_cast<const std::function<void(game::XAssetHeader)>*>(data);
cb(header);
}), &callback, includeOverride);
}
2022-03-01 15:38:52 -05:00
class component final : public component_interface
{
public:
void post_unpack() override
{
db_try_load_x_file_internal_hook.create(
2022-05-18 20:27:46 -04:00
SELECT_VALUE(0, 0x39A620_b), &db_try_load_x_file_internal);
2022-03-01 15:38:52 -05:00
}
};
}
2022-05-18 20:27:46 -04:00
REGISTER_COMPONENT(fastfiles::component)