iw7-mod/src/client/component/patches.cpp

44 lines
936 B
C++
Raw Normal View History

2022-05-20 14:59:24 -04:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
2022-09-18 09:38:50 -04:00
#include "game/dvars.hpp"
2022-05-20 14:59:24 -04:00
#include <utils/hook.hpp>
#include <utils/string.hpp>
namespace patches
{
namespace
{
2022-09-18 09:38:50 -04:00
void dvar_write_single_variable_stub(const game::dvar_t* dvar, int* user_data)
{
if ((dvar->flags & game::DVAR_FLAG_SAVED) != 0)
{
const char* val = game::Dvar_DisplayableLatchedValue(dvar);
auto h = *user_data;
auto dvar_name = dvars::dvar_get_name(dvar);
if (!dvar_name.empty())
{
game::FS_Printf(h, "seta %s \"%s\"\n", dvar_name.data(), val);
}
else
{
game::FS_Printf(h, "setcl %d \"%s\"\n", dvar->checksum, val);
}
}
}
2022-05-20 14:59:24 -04:00
}
class component final : public component_interface
{
public:
void post_unpack() override
{
2022-09-18 09:38:50 -04:00
// write better config
utils::hook::jump(0xBB2A50_b, dvar_write_single_variable_stub);
2022-05-20 14:59:24 -04:00
}
};
}
REGISTER_COMPONENT(patches::component)