Store dvar names & descriptions in resources

This commit is contained in:
fed 2023-12-11 02:59:05 +01:00
parent 2f16941e8b
commit 909514707e
No known key found for this signature in database
GPG Key ID: 1D2C630F04722996
8 changed files with 10865 additions and 10878 deletions

View File

@ -2,7 +2,10 @@
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "dvars.hpp"
#include "console.hpp"
#include <utils/hook.hpp>
@ -70,7 +73,7 @@ namespace dvars
}
template <typename T>
T* find_dvar(std::unordered_map<std::string, T>& map, const int hash)
T* find_dvar(std::unordered_map<std::string, T>& map, const std::uint32_t hash)
{
for (auto i = map.begin(); i != map.end(); ++i)
{
@ -89,7 +92,7 @@ namespace dvars
}
bool find_dvar(std::unordered_set<std::string>& set, const int hash)
bool find_dvar(std::unordered_set<std::string>& set, const std::uint32_t hash)
{
for (auto i = set.begin(); i != set.end(); ++i)
{
@ -423,6 +426,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& dvar_info : list.array())
{
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(0x140617BB0, &dvar_register_bool);

View File

@ -706,7 +706,7 @@ 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()) && match_compare(input, name, exact))

File diff suppressed because it is too large Load Diff

View File

@ -8,13 +8,13 @@ namespace dvars
{
struct dvar_info
{
dvar_info(const std::string& name, const std::string& description);
std::string name;
std::string description;
int hash;
std::uint32_t hash;
};
extern std::unordered_map<std::uint32_t, dvar_info> dvar_map;
extern game::dvar_t* con_inputBoxColor;
extern game::dvar_t* con_inputHintBoxColor;
extern game::dvar_t* con_outputBarColor;
@ -40,12 +40,13 @@ namespace dvars
WEAK game::symbol<game::dvar_t*> com_max_fps{0x14AE2C890};
WEAK game::symbol<game::dvar_t*> cg_draw_2d{0x141E39EC0};
extern std::vector<dvar_info> dvar_list;
void insert_dvar_info(const std::uint32_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::uint32_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

@ -75,11 +75,11 @@ namespace game
WEAK symbol<const char*(const dvar_t* dvar)> Dvar_DisplayableValue{0x140618EA0};
WEAK symbol<const char*(dvar_t* dvar, void* a2, void* value)> Dvar_ValueToString{0x14061B8F0};
WEAK symbol<void(int hash, const char* name, const char* buffer)> Dvar_SetCommand{0x14061A5C0};
WEAK symbol<void(const char* dvarName, const char* string, DvarSetSource source)> Dvar_SetFromStringFromSource{0x14061A910};
WEAK symbol<void(const dvar_t* dvar, const char* string, DvarSetSource source)> Dvar_SetFromStringFromSource{0x14061A910};
WEAK symbol<void(const dvar_t* dvar, const char* value)> Dvar_SetString{0x14061ABF0};
WEAK symbol<void(const dvar_t* dvar, DvarSetSource source)> Dvar_Reset{0x140619FE0};
WEAK symbol<int(const char* fname)> generateHashValue{0x140343D20};
WEAK symbol<unsigned int(const char* fname)> generateHashValue{0x140343D20};
WEAK symbol<bool()> CL_IsCgameInitialized{0x1403CA0C0};
WEAK symbol<void(const char* text, int maxChars, Font_s* font, float x, float y, float xScale, float yScale,

View File

@ -12,3 +12,5 @@
#define LUI_UPDATER 304
#define LUA_JSON 305
#define DVAR_LIST 306

View File

@ -102,6 +102,8 @@ LUI_UPDATER RCDATA "resources/ui_scripts/updater.lua"
LUA_JSON RCDATA "resources/json.lua"
DVAR_LIST RCDATA "resources/dvar_list.json"
#ifdef _DEBUG
TLS_DLL RCDATA "../../build/bin/x64/Debug/tlsdll.dll"
#else

File diff suppressed because it is too large Load Diff