Store dvar names & descriptions in resources

This commit is contained in:
fed 2023-12-13 19:32:00 +01:00
parent 0ccde7640a
commit ce12f0d9f5
No known key found for this signature in database
GPG Key ID: 1D2C630F04722996
10 changed files with 9421 additions and 11733 deletions

View File

@ -2,8 +2,10 @@
#include "loader/component_loader.hpp"
#include "dvars.hpp"
#include "console.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
@ -541,6 +543,25 @@ namespace dvars
class component final : public component_interface
{
public:
void post_start() override
{
try
{
const auto list_json = utils::nt::load_resource(DVAR_LIST);
const auto list = nlohmann::json::parse(list_json);
for (const auto& [_0, dvar_info] : list.items())
{
const auto name = dvar_info[0].get<std::string>();
const auto description = dvar_info[1].get<std::string>();
dvars::insert_dvar_info(name, description);
}
}
catch (const std::exception& e)
{
console::error("Failed to parse dvar list: %s\n", e.what());
}
}
void post_unpack() override
{
dvar_register_bool_hook.create(SELECT_VALUE(0x419220_b, 0x182340_b), &dvar_register_bool);

View File

@ -181,12 +181,12 @@ namespace game_console
{
input = utils::string::to_lower(input);
for (const auto& dvar : dvars::dvar_list)
for (const auto& [hash, dvar] : dvars::dvar_map)
{
auto name = utils::string::to_lower(dvar.name);
if (game::Dvar_FindVar(name.data()) && utils::string::match_compare(input, name, exact))
{
suggestions.push_back(dvar);
suggestions.emplace_back(dvar);
}
if (exact && suggestions.size() > 1)
@ -197,7 +197,7 @@ namespace game_console
if (suggestions.size() == 0 && game::Dvar_FindVar(input.data()))
{
suggestions.push_back({input, ""});
suggestions.emplace_back(input, "");
}
game::cmd_function_s* cmd = (*game::cmd_functions);
@ -209,7 +209,7 @@ namespace game_console
if (utils::string::match_compare(input, name, exact))
{
suggestions.push_back({cmd->name, ""});
suggestions.emplace_back(cmd->name, "");
}
if (exact && suggestions.size() > 1)

View File

@ -1157,4 +1157,4 @@ namespace party
};
}
REGISTER_COMPONENT(party::component)
REGISTER_COMPONENT(party::component)

View File

@ -68,7 +68,7 @@ namespace patches
void cg_set_client_dvar_from_server_stub(void* clientNum, void* cgameGlob, const char* dvar_hash, const char* value)
{
int hash = atoi(dvar_hash);
const auto hash = std::atoi(dvar_hash);
auto* dvar = game::Dvar_FindMalleableVar(hash);
if (hash == game::generateHashValue("cg_fov") ||
@ -223,7 +223,7 @@ namespace patches
utils::hook::detour init_network_dvars_hook;
void init_network_dvars_stub(game::dvar_t* dvar)
{
static const auto hash = game::generateHashValue("r_tonemapHighlightRange");
constexpr auto hash = dvars::generate_hash("r_tonemapHighlightRange");
if (dvar->hash == hash)
{
init_network_dvars_hook.invoke<void>(dvar);

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,11 @@ namespace dvars
{
std::string name;
std::string description;
int hash;
std::int32_t hash;
};
extern std::unordered_map<std::int32_t, dvar_info> dvar_map;
extern game::dvar_t* aimassist_enabled;
extern game::dvar_t* con_inputBoxColor;
@ -48,12 +50,57 @@ namespace dvars
extern game::dvar_t* cg_legacyCrashHandling;
extern std::vector<dvar_info> dvar_list;
constexpr int generate_hash(const char* string)
{
const char* v1;
char v2, v6;
int v4, v5, v7;
char* end_ptr;
v1 = string;
v2 = *string;
if (v2 == 48 && v1[1] == 120)
{
return strtoul(v1 + 2, &end_ptr, 16);
}
v4 = v2;
if ((v2 - 65) <= 0x19u)
{
v4 = v2 + 32;
}
v5 = 0xB3CB2E29 * static_cast<unsigned int>(v4 ^ 0x319712C3);
if (v2)
{
do
{
v6 = *++v1;
v7 = v6;
if ((v6 - 65) <= 0x19u)
{
v7 = v6 + 32;
}
v5 = 0xB3CB2E29 * static_cast<unsigned int>(v5 ^ v7);
} while (v6);
}
return v5;
}
std::int32_t generate_hash(const std::string& string);
void insert_dvar_info(const std::int32_t hash, const std::string& name, const std::string& description);
void insert_dvar_info(const std::string& name, const std::string& description);
std::string dvar_get_vector_domain(const int components, const game::dvar_limits& domain);
std::string dvar_get_domain(const game::dvar_type type, const game::dvar_limits& domain);
std::string dvar_get_description(const std::string& name);
std::optional<dvar_info> get_dvar_info_from_hash(const int hash);
std::optional<dvar_info> get_dvar_info_from_hash(const std::int32_t hash);
game::dvar_t* register_int(const std::string& name, int value, int min, int max,
unsigned int flags, const std::string& description);

View File

@ -20,3 +20,5 @@
#define LUI_UPDATER 310
#define LUA_JSON 311
#define DVAR_LIST 312

View File

@ -123,6 +123,8 @@ LUI_UPDATER RCDATA "resources/ui_scripts/updater.lua"
LUA_JSON RCDATA "resources/json.lua"
DVAR_LIST RCDATA "resources/dvar_list.json"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -91,7 +91,11 @@
#include <udis86.h>
#include <MinHook.h>
#include <tomcrypt.h>
#pragma warning(push)
#pragma warning(disable: 4459)
#include <json.hpp>
#pragma warning(pop)
#define RAPIDJSON_NOEXCEPT
#define RAPIDJSON_ASSERT(cond) if(cond); else throw std::runtime_error("rapidjson assert fail");