Dvars component + update dvar list

This commit is contained in:
Federico Cecchetto 2022-02-28 20:31:25 +01:00
parent fab4962c6e
commit 781e1f914d
7 changed files with 2998 additions and 460 deletions

View File

@ -7,7 +7,7 @@
#include "version.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "dvars.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
@ -46,7 +46,7 @@ namespace branding
localized_strings::override("MENU_MULTIPLAYER_CAPS", "H1-MOD: MULTIPLAYER");
}
dvars::override::Dvar_SetString("version", utils::string::va("H1-Mod %s", VERSION));
dvars::override::set_string("version", utils::string::va("H1-Mod %s", VERSION));
ui_get_formatted_build_number_hook.create(
SELECT_VALUE(0x1403B1C40, 0x1404E74C0), ui_get_formatted_build_number_stub);

View File

@ -0,0 +1,418 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "dvars.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
namespace dvars
{
struct dvar_base
{
unsigned int flags{};
};
struct dvar_bool : dvar_base
{
bool value{};
};
struct dvar_float : dvar_base
{
float value{};
float min{};
float max{};
};
struct dvar_vector2 : dvar_base
{
float x{};
float y{};
float min{};
float max{};
};
struct dvar_vector3 : dvar_base
{
float x{};
float y{};
float z{};
float min{};
float max{};
};
struct dvar_int : dvar_base
{
int value{};
int min{};
int max{};
};
struct dvar_string : dvar_base
{
std::string value{};
};
namespace
{
template <typename T>
T* find_dvar(std::unordered_map<std::string, T>& map, const std::string& name)
{
auto i = map.find(name);
if (i != map.end())
{
return &i->second;
}
return nullptr;
}
template <typename T>
T* find_dvar(std::unordered_map<std::string, T>& map, const int hash)
{
for (auto i = map.begin(); i != map.end(); ++i)
{
if (game::generateHashValue(i->first.data()) == hash)
{
return &i->second;
}
}
return nullptr;
}
bool find_dvar(std::unordered_set<std::string>& set, const std::string& name)
{
return set.find(name) != set.end();
}
bool find_dvar(std::unordered_set<std::string>& set, const int hash)
{
for (auto i = set.begin(); i != set.end(); ++i)
{
if (game::generateHashValue(i->data()) == hash)
{
return true;
}
}
return false;
}
}
namespace disable
{
static std::unordered_set<std::string> set_bool_disables;
static std::unordered_set<std::string> set_float_disables;
static std::unordered_set<std::string> set_int_disables;
static std::unordered_set<std::string> set_string_disables;
void set_bool(const std::string& name)
{
set_bool_disables.emplace(name);
}
void set_float(const std::string& name)
{
set_float_disables.emplace(name);
}
void set_int(const std::string& name)
{
set_int_disables.emplace(name);
}
void set_string(const std::string& name)
{
set_string_disables.emplace(name);
}
}
namespace override
{
static std::unordered_map<std::string, dvar_bool> register_bool_overrides;
static std::unordered_map<std::string, dvar_float> register_float_overrides;
static std::unordered_map<std::string, dvar_int> register_int_overrides;
static std::unordered_map<std::string, dvar_string> register_string_overrides;
static std::unordered_map<std::string, dvar_vector2> register_vector2_overrides;
static std::unordered_map<std::string, dvar_vector3> register_vector3_overrides;
static std::unordered_map<std::string, bool> set_bool_overrides;
static std::unordered_map<std::string, float> set_float_overrides;
static std::unordered_map<std::string, int> set_int_overrides;
static std::unordered_map<std::string, std::string> set_string_overrides;
void register_bool(const std::string& name, const bool value, const unsigned int flags)
{
dvar_bool values;
values.value = value;
values.flags = flags;
register_bool_overrides[name] = std::move(values);
}
void register_float(const std::string& name, const float value, const float min, const float max,
const unsigned int flags)
{
dvar_float values;
values.value = value;
values.min = min;
values.max = max;
values.flags = flags;
register_float_overrides[name] = std::move(values);
}
void register_int(const std::string& name, const int value, const int min, const int max,
const unsigned int flags)
{
dvar_int values;
values.value = value;
values.min = min;
values.max = max;
values.flags = flags;
register_int_overrides[name] = std::move(values);
}
void register_string(const std::string& name, const std::string& value,
const unsigned int flags)
{
dvar_string values;
values.value = value;
values.flags = flags;
register_string_overrides[name] = std::move(values);
}
void register_vec2(const std::string& name, float x, float y, float min, float max,
const unsigned int flags)
{
dvar_vector2 values;
values.x = x;
values.y = y;
values.min = min;
values.max = max;
values.flags = flags;
register_vector2_overrides[name] = std::move(values);
}
void register_vec3(const std::string& name, float x, float y, float z, float min,
float max, const unsigned int flags)
{
dvar_vector3 values;
values.x = x;
values.y = y;
values.z = z;
values.min = min;
values.max = max;
values.flags = flags;
register_vector3_overrides[name] = std::move(values);
}
void set_bool(const std::string& name, const bool value)
{
set_bool_overrides[name] = value;
}
void set_float(const std::string& name, const float value)
{
set_float_overrides[name] = value;
}
void set_int(const std::string& name, const int value)
{
set_int_overrides[name] = value;
}
void set_string(const std::string& name, const std::string& value)
{
set_string_overrides[name] = value;
}
}
utils::hook::detour dvar_register_bool_hook;
utils::hook::detour dvar_register_float_hook;
utils::hook::detour dvar_register_int_hook;
utils::hook::detour dvar_register_string_hook;
utils::hook::detour dvar_register_vector2_hook;
utils::hook::detour dvar_register_vector3_hook;
utils::hook::detour dvar_set_bool_hook;
utils::hook::detour dvar_set_float_hook;
utils::hook::detour dvar_set_int_hook;
utils::hook::detour dvar_set_string_hook;
game::dvar_t* dvar_register_bool(const int hash, const char* name, bool value, unsigned int flags)
{
auto* var = find_dvar(override::register_bool_overrides, hash);
if (var)
{
value = var->value;
flags = var->flags;
}
return dvar_register_bool_hook.invoke<game::dvar_t*>(hash, name, value, flags);
}
game::dvar_t* dvar_register_float(const int hash, const char* name, float value, float min, float max, unsigned int flags)
{
auto* var = find_dvar(override::register_float_overrides, hash);
if (var)
{
value = var->value;
min = var->min;
max = var->max;
flags = var->flags;
}
return dvar_register_float_hook.invoke<game::dvar_t*>(hash, name, value, min, max, flags);
}
game::dvar_t* dvar_register_int(const int hash, const char* name, int value, int min, int max, unsigned int flags)
{
auto* var = find_dvar(override::register_int_overrides, hash);
if (var)
{
value = var->value;
min = var->min;
max = var->max;
flags = var->flags;
}
return dvar_register_int_hook.invoke<game::dvar_t*>(hash, name, value, min, max, flags);
}
game::dvar_t* dvar_register_string(const int hash, const char* name, const char* value, unsigned int flags)
{
auto* var = find_dvar(override::register_string_overrides, hash);
if (var)
{
value = var->value.data();
flags = var->flags;
}
return dvar_register_string_hook.invoke<game::dvar_t*>(hash, name, value, flags);
}
game::dvar_t* dvar_register_vector2(const int hash, const char* name, float x, float y, float min, float max,
unsigned int flags)
{
auto* var = find_dvar(override::register_vector2_overrides, hash);
if (var)
{
x = var->x;
y = var->y;
min = var->min;
max = var->max;
flags = var->flags;
}
return dvar_register_vector2_hook.invoke<game::dvar_t*>(hash, name, x, y, min, max, flags);
}
game::dvar_t* dvar_register_vector3(const int hash, const char* name, float x, float y, float z, float min,
float max, unsigned int flags)
{
auto* var = find_dvar(override::register_vector3_overrides, hash);
if (var)
{
x = var->x;
y = var->y;
z = var->z;
min = var->min;
max = var->max;
flags = var->flags;
}
return dvar_register_vector3_hook.invoke<game::dvar_t*>(hash, name, x, y, z, min, max, flags);
}
void dvar_set_bool(game::dvar_t* dvar, bool boolean)
{
const auto disabled = find_dvar(disable::set_bool_disables, dvar->hash);
if (disabled)
{
return;
}
auto* var = find_dvar(override::set_bool_overrides, dvar->hash);
if (var)
{
boolean = *var;
}
return dvar_set_bool_hook.invoke<void>(dvar, boolean);
}
void dvar_set_float(game::dvar_t* dvar, float fl)
{
const auto disabled = find_dvar(disable::set_float_disables, dvar->hash);
if (disabled)
{
return;
}
auto* var = find_dvar(override::set_float_overrides, dvar->hash);
if (var)
{
fl = *var;
}
return dvar_set_float_hook.invoke<void>(dvar, fl);
}
void dvar_set_int(game::dvar_t* dvar, int integer)
{
const auto disabled = find_dvar(disable::set_int_disables, dvar->hash);
if (disabled)
{
return;
}
auto* var = find_dvar(override::set_int_overrides, dvar->hash);
if (var)
{
integer = *var;
}
return dvar_set_int_hook.invoke<void>(dvar, integer);
}
void dvar_set_string(game::dvar_t* dvar, const char* string)
{
const auto disabled = find_dvar(disable::set_string_disables, dvar->hash);
if (disabled)
{
return;
}
auto* var = find_dvar(override::set_string_overrides, dvar->hash);
if (var)
{
string = var->data();
}
return dvar_set_string_hook.invoke<void>(dvar, string);
}
class component final : public component_interface
{
public:
void post_unpack() override
{
dvar_register_bool_hook.create(SELECT_VALUE(0x1403C47E0, 0x1404FA540), &dvar_register_bool);
dvar_register_float_hook.create(SELECT_VALUE(0x1403C4BB0, 0x1404FA910), &dvar_register_float);
dvar_register_int_hook.create(SELECT_VALUE(0x1403C4CC0, 0x1404FAA20), &dvar_register_int);
dvar_register_string_hook.create(SELECT_VALUE(0x1403C4DA0, 0x1404FAB00), &dvar_register_string);
dvar_register_vector2_hook.create(SELECT_VALUE(0x1403C4E80, 0x1404FABE0), &dvar_register_vector2);
dvar_register_vector3_hook.create(SELECT_VALUE(0x1403C4FC0, 0x1404FACE0), &dvar_register_vector3);
dvar_set_bool_hook.create(SELECT_VALUE(0x1403C7020, 0x1404FCDF0), &dvar_set_bool);
dvar_set_float_hook.create(SELECT_VALUE(0x1403C7420, 0x1404FD360), &dvar_set_float);
dvar_set_int_hook.create(SELECT_VALUE(0x1403C76C0, 0x1404FD5E0), &dvar_set_int);
dvar_set_string_hook.create(SELECT_VALUE(0x1403C7900, 0x1404FD8D0), &dvar_set_string);
}
};
}
REGISTER_COMPONENT(dvars::component)

View File

@ -0,0 +1,27 @@
#pragma once
namespace dvars
{
namespace disable
{
void set_bool(const std::string& name);
void set_float(const std::string& name);
void set_int(const std::string& name);
void set_string(const std::string& name);
}
namespace override
{
void register_bool(const std::string& name, bool value, const unsigned int flags);
void register_float(const std::string& name, float value, float min, float max, const unsigned int flags);
void register_int(const std::string& name, int value, int min, int max, const unsigned int flags);
void register_string(const std::string& name, const std::string& value, const unsigned int flags);
void register_vec2(const std::string& name, float x, float y, float min, float max, const unsigned int flags);
void register_vec3(const std::string& name, float x, float y, float z, float min, float max, const unsigned int flags);
void set_bool(const std::string& name, bool boolean);
void set_float(const std::string& name, float fl);
void set_int(const std::string& name, int integer);
void set_string(const std::string& name, const std::string& string);
}
}

View File

@ -4,6 +4,8 @@
#include "command.hpp"
#include "network.hpp"
#include "console.hpp"
#include "dvars.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
@ -276,10 +278,10 @@ namespace network
utils::hook::call(0x140480E62, &net_compare_address);
// increase cl_maxpackets
dvars::override::register_int("cl_maxpackets", 1000, 1, 1000, game::DVAR_FLAG_SAVED, true);
dvars::override::register_int("cl_maxpackets", 1000, 1, 1000, game::DVAR_FLAG_SAVED);
// increase snaps
dvars::override::register_int("sv_remote_client_snapshot_msec", 33, 33, 100, game::DVAR_FLAG_NONE, true);
dvars::override::register_int("sv_remote_client_snapshot_msec", 33, 33, 100, game::DVAR_FLAG_NONE);
// ignore impure client
utils::hook::jump(0x140481B58, reinterpret_cast<void*>(0x140481BEE)); // H1MP64(1.4)

View File

@ -1,6 +1,8 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "dvars.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
@ -35,7 +37,6 @@ namespace patches
}
utils::hook::detour gscr_set_save_dvar_hook;
utils::hook::detour dvar_register_float_hook;
void gscr_set_save_dvar_stub()
{
@ -48,27 +49,6 @@ namespace patches
gscr_set_save_dvar_hook.invoke<void>();
}
game::dvar_t* cg_fov = nullptr;
game::dvar_t* cg_fovScale = nullptr;
game::dvar_t* dvar_register_float_stub(int hash, const char* dvarName, float value, float min, float max, unsigned int flags)
{
static const auto cg_fov_hash = game::generateHashValue("cg_fov");
static const auto cg_fov_scale_hash = game::generateHashValue("cg_fovscale");
if (hash == cg_fov_hash)
{
return cg_fov;
}
if (hash == cg_fov_scale_hash)
{
return cg_fovScale;
}
return dvar_register_float_hook.invoke<game::dvar_t*>(hash, dvarName, value, min, max, flags);
}
std::string get_login_username()
{
char username[UNLEN + 1];
@ -92,8 +72,6 @@ namespace patches
// Disable data validation error popup
dvars::register_int("data_validation_allow_drop", 0, 0, 0, game::DVAR_FLAG_NONE, true);
dvars::register_int("com_maxfps", 0, 10, 1000, game::DVAR_FLAG_SAVED, false);
}
return com_register_dvars_hook.invoke<void>();
@ -192,10 +170,8 @@ namespace patches
gscr_set_save_dvar_hook.create(SELECT_VALUE(0x1402AE020, 0x14036B600), &gscr_set_save_dvar_stub);
// Make cg_fov and cg_fovscale saved dvars
cg_fov = dvars::register_float("cg_fov", 65.f, 40.f, 200.f, game::DvarFlags::DVAR_FLAG_SAVED, true);
cg_fovScale = dvars::register_float("cg_fovScale", 1.f, 0.1f, 2.f, game::DvarFlags::DVAR_FLAG_SAVED, true);
dvar_register_float_hook.create(game::Dvar_RegisterFloat.get(), dvar_register_float_stub);
dvars::override::register_float("cg_fov", 65.f, 40.f, 200.f, game::DvarFlags::DVAR_FLAG_SAVED);
dvars::override::register_float("cg_fovScale", 1.f, 0.1f, 2.f, game::DvarFlags::DVAR_FLAG_SAVED);
if (game::environment::is_mp())
{
@ -232,15 +208,15 @@ namespace patches
utils::hook::set(0x1402877D0, 0xC3C033); // MAY BE WRONG H1(1.4)
// disable emblems
//dvars::override::register_int("emblems_active", 0, 0, 0, game::DVAR_FLAG_NONE);
//utils::hook::set<uint8_t>(0x140479590, 0xC3); // don't register commands
dvars::override::register_int("emblems_active", 0, 0, 0, game::DVAR_FLAG_NONE);
utils::hook::set<uint8_t>(0x140479590, 0xC3); // don't register commands
// disable elite_clan
dvars::override::register_int("elite_clan_active", 0, 0, 0, game::DVAR_FLAG_NONE);
utils::hook::set<uint8_t>(0x140585680, 0xC3); // don't register commands H1(1.4)
// disable codPointStore
dvars::override::register_int("codPointStore_enabled", 0, 0, 0, game::DVAR_FLAG_NONE, true);
dvars::override::register_int("codPointStore_enabled", 0, 0, 0, game::DVAR_FLAG_NONE);
// don't register every replicated dvar as a network dvar
utils::hook::nop(0x14039E58E, 5); // dvar_foreach H1(1.4)
@ -254,30 +230,29 @@ namespace patches
utils::hook::nop(0x140190C16, 5);
utils::hook::set<uint8_t>(0x14021D22A, 0xEB);
// some anti tamper thing that kills performance
dvars::override::register_int("dvl", 0, 0, 0, game::DVAR_FLAG_READ, true);
// unlock safeArea_*
utils::hook::jump(0x1402624F5, 0x140262503); // H1(1.4)
utils::hook::jump(0x14026251C, 0x140262547); // H1(1.4)
dvars::override::register_float("safeArea_adjusted_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED, true);
dvars::override::register_float("safeArea_adjusted_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED, true);
dvars::override::register_float("safeArea_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED, true);
dvars::override::register_float("safeArea_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED, true);
dvars::override::register_int("safeArea_adjusted_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED);
dvars::override::register_int("safeArea_adjusted_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED);
dvars::override::register_int("safeArea_horizontal", 1, 0, 1, game::DVAR_FLAG_SAVED);
dvars::override::register_int("safeArea_vertical", 1, 0, 1, game::DVAR_FLAG_SAVED);
// move chat position on the screen above menu splashes
//dvars::override::Dvar_RegisterVector2("cg_hudChatPosition", 5, 170, 0, 640, game::DVAR_FLAG_SAVED);
dvars::override::register_vec2("cg_hudChatPosition", 5, 170, 0, 640, game::DVAR_FLAG_SAVED);
// allow servers to check for new packages more often
dvars::override::register_int("sv_network_fps", 1000, 20, 1000, game::DVAR_FLAG_SAVED, true);
dvars::override::register_int("sv_network_fps", 1000, 20, 1000, game::DVAR_FLAG_SAVED);
// Massively increate timeouts
dvars::override::register_int("cl_timeout", 90, 90, 1800, game::DVAR_FLAG_NONE, true); // Seems unused
dvars::override::register_int("sv_timeout", 90, 90, 1800, game::DVAR_FLAG_NONE, true); // 30 - 0 - 1800
dvars::override::register_int("cl_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE, true); // Seems unused
dvars::override::register_int("sv_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE, true); // 60 - 0 - 1800
dvars::override::register_int("cl_timeout", 90, 90, 1800, game::DVAR_FLAG_NONE); // Seems unused
dvars::override::register_int("sv_timeout", 90, 90, 1800, game::DVAR_FLAG_NONE); // 30 - 0 - 1800
dvars::override::register_int("cl_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE); // Seems unused
dvars::override::register_int("sv_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE); // 60 - 0 - 1800
game::Dvar_RegisterInt(0, "scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED);
dvars::register_int("scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED);
dvars::override::register_int("com_maxfps", 0, 10, 1000, game::DVAR_FLAG_SAVED);
// Prevent clients from ending the game as non host by sending 'end_game' lui notification
// cmd_lui_notify_server_hook.create(0x140335A70, cmd_lui_notify_server_stub); // H1(1.4)

File diff suppressed because it is too large Load Diff

View File

@ -33,12 +33,4 @@ namespace dvars
game::dvar_t* register_string(const std::string& name, const char* value, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_float(const std::string& name, float value, float min, float max, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_vec4(const std::string& name, float x, float y, float z, float w, float min, float max, game::DvarFlags flags, bool add_to_list = true);
namespace override
{
game::dvar_t* register_int(const std::string& name, int value, int min, int max, const unsigned int flags, bool add_to_list = true);
void Dvar_SetString(const std::string& name, const std::string& string);
game::dvar_t* register_float(const std::string& name, float value, float min, float max, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_string(const std::string& name, const char* value, game::DvarFlags flags, bool add_to_list = true);
}
}