Fix gamepad vars
This commit is contained in:
parent
0cf1143f94
commit
39f2f4ff62
@ -8,24 +8,39 @@ namespace Components
|
||||
Dvar::Var::Var(const std::string& dvarName) : Var()
|
||||
{
|
||||
this->dvar = Game::Dvar_FindVar(dvarName.data());
|
||||
this->dvarName = dvarName;
|
||||
}
|
||||
|
||||
if (!this->dvar)
|
||||
void Dvar::Var::registerDvar()
|
||||
{
|
||||
assert(!this->dvarName.empty() && this->dvar == nullptr);
|
||||
|
||||
auto* dvar = Game::Dvar_FindVar(this->dvarName.data());
|
||||
|
||||
// If the dvar can't be found it will be registered as an empty string dvar
|
||||
if (dvar == nullptr)
|
||||
{
|
||||
// Quick-register the dvar
|
||||
Game::Dvar_SetStringByName(dvarName.data(), "");
|
||||
this->dvar = Game::Dvar_FindVar(dvarName.data());
|
||||
this->dvar = const_cast<Game::dvar_t*>(Game::Dvar_SetFromStringByNameFromSource(this->dvarName.data(), "",
|
||||
Game::DvarSetSource::DVAR_SOURCE_INTERNAL));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->dvar = dvar;
|
||||
}
|
||||
}
|
||||
|
||||
template <> Game::dvar_t* Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar == nullptr)
|
||||
this->registerDvar();
|
||||
|
||||
return this->dvar;
|
||||
}
|
||||
|
||||
template <> const char* Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar == nullptr)
|
||||
return "";
|
||||
this->registerDvar();
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING
|
||||
|| this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
||||
@ -39,7 +54,10 @@ namespace Components
|
||||
|
||||
template <> int Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
||||
if (this->dvar == nullptr)
|
||||
this->registerDvar();
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT || this->dvar->type == Game::dvar_type::DVAR_TYPE_ENUM)
|
||||
{
|
||||
return this->dvar->current.integer;
|
||||
}
|
||||
@ -49,34 +67,51 @@ namespace Components
|
||||
|
||||
template <> unsigned int Dvar::Var::get()
|
||||
{
|
||||
return static_cast<unsigned int>(this->get<int>());
|
||||
}
|
||||
if (this->dvar == nullptr)
|
||||
this->registerDvar();
|
||||
|
||||
template <> float Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
|
||||
{
|
||||
return this->dvar->current.value;
|
||||
return this->dvar->current.unsignedInt;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <> float Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar == nullptr)
|
||||
this->registerDvar();
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
||||
{
|
||||
return this->dvar->current.value;
|
||||
}
|
||||
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
template <> float* Dvar::Var::get()
|
||||
{
|
||||
static float val[4] = { 0 };
|
||||
static Game::vec4_t vector{ 0.f, 0.f, 0.f, 0.f };
|
||||
|
||||
if (this->dvar == nullptr)
|
||||
this->registerDvar();
|
||||
|
||||
if (this->dvar && (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_2 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_3 || this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT_4))
|
||||
{
|
||||
return this->dvar->current.vector;
|
||||
}
|
||||
|
||||
return val;
|
||||
return vector;
|
||||
}
|
||||
|
||||
template <> bool Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
|
||||
if (this->dvar == nullptr)
|
||||
this->registerDvar();
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
|
||||
{
|
||||
return this->dvar->current.enabled;
|
||||
}
|
||||
@ -89,11 +124,6 @@ namespace Components
|
||||
return this->get<const char*>();
|
||||
}
|
||||
|
||||
void Dvar::Var::set(char* string)
|
||||
{
|
||||
this->set(const_cast<const char*>(string));
|
||||
}
|
||||
|
||||
void Dvar::Var::set(const char* string)
|
||||
{
|
||||
assert(this->dvar->type == Game::DVAR_TYPE_STRING);
|
||||
@ -242,7 +272,7 @@ namespace Components
|
||||
return Dvar::Register<const char*>(name, username.data(), Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).get<Game::dvar_t*>();
|
||||
}
|
||||
|
||||
Game::dvar_t* Dvar::SetFromStringByNameSafeExternal(const char* dvar, const char* value)
|
||||
void Dvar::SetFromStringByNameSafeExternal(const char* dvarName, const char* string)
|
||||
{
|
||||
static const char* exceptions[] =
|
||||
{
|
||||
@ -258,18 +288,19 @@ namespace Components
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(exceptions); ++i)
|
||||
{
|
||||
if (Utils::String::ToLower(dvar) == Utils::String::ToLower(exceptions[i]))
|
||||
if (Utils::String::ToLower(dvarName) == Utils::String::ToLower(exceptions[i]))
|
||||
{
|
||||
return Game::Dvar_SetFromStringByName(dvar, value);
|
||||
Game::Dvar_SetFromStringByNameFromSource(dvarName, string, Game::DvarSetSource::DVAR_SOURCE_INTERNAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return Dvar::SetFromStringByNameExternal(dvar, value);
|
||||
return Dvar::SetFromStringByNameExternal(dvarName, string);
|
||||
}
|
||||
|
||||
Game::dvar_t* Dvar::SetFromStringByNameExternal(const char* dvar, const char* value)
|
||||
void Dvar::SetFromStringByNameExternal(const char* dvarName, const char* string)
|
||||
{
|
||||
return Game::Dvar_SetFromStringByNameFromSource(dvar, value, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL);
|
||||
Game::Dvar_SetFromStringByNameFromSource(dvarName, string, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL);
|
||||
}
|
||||
|
||||
void Dvar::SaveArchiveDvar(const Game::dvar_t* var)
|
||||
@ -349,7 +380,7 @@ namespace Components
|
||||
Utils::Hook(0x63CDB5, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x635E47, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick();
|
||||
|
||||
// SetDvar
|
||||
// Script_SetDvar
|
||||
Utils::Hook(0x63444C, Dvar::SetFromStringByNameSafeExternal, HOOK_CALL).install()->quick();
|
||||
|
||||
// Slider
|
||||
|
@ -18,14 +18,14 @@ namespace Components
|
||||
{
|
||||
public:
|
||||
Var() : dvar(nullptr) {};
|
||||
Var(const Var &obj) { this->dvar = obj.dvar; };
|
||||
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
|
||||
Var(const Var& obj) { this->dvar = obj.dvar; this->dvarName = obj.dvarName; };
|
||||
Var(Game::dvar_t* _dvar) : dvar(_dvar), dvarName(_dvar->name) {};
|
||||
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
|
||||
Var(const std::string& dvarName);
|
||||
|
||||
void registerDvar();
|
||||
template<typename T> T get();
|
||||
|
||||
void set(char* string);
|
||||
void set(const char* string);
|
||||
void set(const std::string& string);
|
||||
|
||||
@ -38,6 +38,7 @@ namespace Components
|
||||
void setRaw(bool enabled);
|
||||
|
||||
private:
|
||||
std::string dvarName;
|
||||
Game::dvar_t* dvar;
|
||||
};
|
||||
|
||||
@ -58,8 +59,8 @@ namespace Components
|
||||
|
||||
static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description);
|
||||
|
||||
static Game::dvar_t* SetFromStringByNameExternal(const char* dvar, const char* value);
|
||||
static Game::dvar_t* SetFromStringByNameSafeExternal(const char* dvar, const char* value);
|
||||
static void SetFromStringByNameExternal(const char* dvar, const char* value);
|
||||
static void SetFromStringByNameSafeExternal(const char* dvar, const char* value);
|
||||
|
||||
static void SaveArchiveDvar(const Game::dvar_t* var);
|
||||
static void DvarSetFromStringByNameStub(const char* dvarName, const char* value);
|
||||
|
@ -1731,7 +1731,7 @@ namespace Components
|
||||
gpad_button_deadzone = Dvar::Register<float>("gpad_button_deadzone", 0.13f, 0.0f, 1.0f, Game::DVAR_FLAG_NONE, "Game pad button deadzone threshhold");
|
||||
gpad_button_lstick_deflect_max = Dvar::Register<float>("gpad_button_lstick_deflect_max", 1.0f, 0.0f, 1.0f, Game::DVAR_FLAG_NONE, "Game pad maximum pad stick pressed value");
|
||||
gpad_button_rstick_deflect_max = Dvar::Register<float>("gpad_button_rstick_deflect_max", 1.0f, 0.0f, 1.0f, Game::DVAR_FLAG_NONE, "Game pad maximum pad stick pressed value");
|
||||
gpad_use_hold_time = Dvar::Register<int>("gpad_use_hold_time", 250, 0, INT32_MAX, Game::DVAR_FLAG_NONE, "Time to hold the 'use' button on gamepads to activate use");
|
||||
gpad_use_hold_time = Dvar::Register<int>("gpad_use_hold_time", 250, 0, std::numeric_limits<int>::max(), Game::DVAR_FLAG_NONE, "Time to hold the 'use' button on gamepads to activate use");
|
||||
gpad_lockon_enabled = Dvar::Register<bool>("gpad_lockon_enabled", true, Game::DVAR_FLAG_SAVED, "Game pad lockon aim assist enabled");
|
||||
gpad_slowdown_enabled = Dvar::Register<bool>("gpad_slowdown_enabled", true, Game::DVAR_FLAG_SAVED, "Game pad slowdown aim assist enabled");
|
||||
|
||||
@ -1762,10 +1762,10 @@ namespace Components
|
||||
aim_lockon_strength = Dvar::Var("aim_lockon_strength");
|
||||
}
|
||||
|
||||
void Gamepad::IN_Init_Hk()
|
||||
void Gamepad::CG_RegisterDvars_Hk()
|
||||
{
|
||||
// Call original method
|
||||
Utils::Hook::Call<void()>(0x45D620)();
|
||||
Utils::Hook::Call<void()>(0x4F8DC0)();
|
||||
|
||||
InitDvars();
|
||||
}
|
||||
@ -1908,7 +1908,7 @@ namespace Components
|
||||
return;
|
||||
|
||||
// Initialize gamepad environment
|
||||
Utils::Hook(0x467C03, IN_Init_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x4059FE, CG_RegisterDvars_Hk, HOOK_CALL).install()->quick();
|
||||
|
||||
// package the forward and right move components in the move buttons
|
||||
Utils::Hook(0x60E38D, MSG_WriteDeltaUsercmdKeyStub, HOOK_JUMP).install()->quick();
|
||||
|
@ -187,7 +187,7 @@ namespace Components
|
||||
static void Scores_Toggle_f(Command::Params* params);
|
||||
|
||||
static void InitDvars();
|
||||
static void IN_Init_Hk();
|
||||
static void CG_RegisterDvars_Hk();
|
||||
|
||||
static const char* GetGamePadCommand(const char* command);
|
||||
static int Key_GetCommandAssignmentInternal_Hk(const char* cmd, int(*keys)[2]);
|
||||
|
@ -256,10 +256,10 @@ namespace Game
|
||||
typedef dvar_t* (__cdecl * Dvar_RegisterColor_t)(const char* name, float r, float g, float b, float a, int flags, const char* description);
|
||||
extern Dvar_RegisterColor_t Dvar_RegisterColor;
|
||||
|
||||
typedef dvar_t* (__cdecl * Dvar_SetFromStringByName_t)(const char* cvar, const char* value);
|
||||
typedef void(__cdecl * Dvar_SetFromStringByName_t)(const char* dvarName, const char* string);
|
||||
extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName;
|
||||
|
||||
typedef dvar_t* (__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* cvar, const char* value, DvarSetSource source);
|
||||
typedef const dvar_t* (__cdecl * Dvar_SetFromStringByNameFromSource_t)(const char* dvarName, const char* string, DvarSetSource source);
|
||||
extern Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource;
|
||||
|
||||
typedef void (__cdecl * Dvar_SetStringByName_t)(const char* cvar, const char* value);
|
||||
@ -286,7 +286,7 @@ namespace Game
|
||||
typedef char* (__cdecl* Dvar_InfoString_Big_t)(int typeMask);
|
||||
extern Dvar_InfoString_Big_t Dvar_InfoString_Big;
|
||||
|
||||
typedef dvar_t* (__cdecl * Dvar_SetCommand_t)(const char* name, const char* value);
|
||||
typedef void(__cdecl * Dvar_SetCommand_t)(const char* dvarName, const char* string);
|
||||
extern Dvar_SetCommand_t Dvar_SetCommand;
|
||||
|
||||
typedef const char* (__cdecl * Dvar_DisplayableValue_t)(const dvar_t* cvar);
|
||||
|
Loading…
Reference in New Issue
Block a user