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

83 lines
2.1 KiB
C++
Raw Normal View History

2021-09-06 18:40:37 -04:00
#include <std_include.hpp>
2021-04-29 17:47:05 -04:00
#include "loader/component_loader.hpp"
#include "fastfiles.hpp"
#include "command.hpp"
#include "game_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)
{
game_console::print(game_console::con_type_info, "Loading fastfile %s\n", zone_name);
current_fastfile.access([&](std::string& fastfile)
{
fastfile = zone_name;
});
return db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags);
}
}
2022-01-02 17:51:38 -05: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);
}
2021-04-29 17:47:05 -04:00
std::string get_current_fastfile()
{
std::string fastfile_copy;
current_fastfile.access([&](std::string& fastfile)
{
fastfile_copy = fastfile;
});
return fastfile_copy;
}
class component final : public component_interface
{
public:
void post_unpack() override
{
db_try_load_x_file_internal_hook.create(0x4173B0_b, &db_try_load_x_file_internal);
2021-04-29 17:47:05 -04:00
command::add("loadzone", [](const command::params& params)
{
if (params.size() < 2)
{
game_console::print(game_console::con_type_info, "usage: loadzone <zone>\n");
return;
}
game::XZoneInfo info{};
info.name = params.get(1);
info.allocFlags = 1;
info.freeFlags = 0;
game::DB_LoadXAssets(&info, 1u, game::DBSyncMode::DB_LOAD_SYNC);
});
command::add("g_poolSizes", []()
{
for (auto i = 0; i < game::ASSET_TYPE_COUNT; i++)
{
game_console::print(game_console::con_type_info, "g_poolSize[%i]: %i // %s\n", i, game::g_poolSize[i], game::g_assetNames[i]);
}
});
}
};
}
REGISTER_COMPONENT(fastfiles::component)