Merge pull request #183 from diamante0018/fix-gamepad-vars
Fix gamepad vars
This commit is contained in:
commit
520fa6be43
@ -9,11 +9,11 @@ namespace Components
|
||||
{
|
||||
this->dvar = Game::Dvar_FindVar(dvarName.data());
|
||||
|
||||
if (!this->dvar)
|
||||
// If the dvar can't be found it will be registered as an empty string dvar
|
||||
if (this->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(dvarName.data(), "",
|
||||
Game::DvarSetSource::DVAR_SOURCE_INTERNAL));
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,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)
|
||||
return 0;
|
||||
|
||||
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 +52,52 @@ namespace Components
|
||||
|
||||
template <> unsigned int Dvar::Var::get()
|
||||
{
|
||||
return static_cast<unsigned int>(this->get<int>());
|
||||
if (this->dvar == nullptr)
|
||||
return 0u;
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
|
||||
{
|
||||
return this->dvar->current.unsignedInt;
|
||||
}
|
||||
|
||||
return 0u;
|
||||
}
|
||||
|
||||
template <> float Dvar::Var::get()
|
||||
{
|
||||
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
||||
if (this->dvar == nullptr)
|
||||
return 0.f;
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
||||
{
|
||||
return this->dvar->current.value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
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 && (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))
|
||||
if (this->dvar == nullptr)
|
||||
return vector;
|
||||
|
||||
if (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)
|
||||
return false;
|
||||
|
||||
if (this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
|
||||
{
|
||||
return this->dvar->current.enabled;
|
||||
}
|
||||
@ -89,11 +110,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 +258,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 +274,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);
|
||||
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 +366,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,13 @@ namespace Components
|
||||
{
|
||||
public:
|
||||
Var() : dvar(nullptr) {};
|
||||
Var(const Var &obj) { this->dvar = obj.dvar; };
|
||||
Var(const Var& obj) { this->dvar = obj.dvar; };
|
||||
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
|
||||
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
|
||||
Var(const std::string& dvarName);
|
||||
|
||||
template<typename T> T get();
|
||||
|
||||
void set(char* string);
|
||||
void set(const char* string);
|
||||
void set(const std::string& string);
|
||||
|
||||
@ -58,8 +57,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);
|
||||
|
@ -1730,7 +1730,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");
|
||||
|
||||
@ -1761,10 +1761,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();
|
||||
}
|
||||
@ -1907,7 +1907,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]);
|
||||
|
@ -259,25 +259,25 @@ 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);
|
||||
extern Dvar_SetStringByName_t Dvar_SetStringByName;
|
||||
|
||||
typedef void (__cdecl * Dvar_SetString_t)(dvar_t* cvar, const char* value);
|
||||
typedef void (__cdecl * Dvar_SetString_t)(const dvar_t* cvar, const char* value);
|
||||
extern Dvar_SetString_t Dvar_SetString;
|
||||
|
||||
typedef void (__cdecl * Dvar_SetBool_t)(dvar_t* cvar, bool enabled);
|
||||
typedef void (__cdecl * Dvar_SetBool_t)(const dvar_t* cvar, bool enabled);
|
||||
extern Dvar_SetBool_t Dvar_SetBool;
|
||||
|
||||
typedef void (__cdecl * Dvar_SetFloat_t)(dvar_t* cvar, float value);
|
||||
typedef void (__cdecl * Dvar_SetFloat_t)(const dvar_t* cvar, float value);
|
||||
extern Dvar_SetFloat_t Dvar_SetFloat;
|
||||
|
||||
typedef void (__cdecl * Dvar_SetInt_t)(dvar_t* cvar, int integer);
|
||||
typedef void (__cdecl * Dvar_SetInt_t)(const dvar_t* cvar, int integer);
|
||||
extern Dvar_SetInt_t Dvar_SetInt;
|
||||
|
||||
typedef void(__cdecl * Dvar_GetUnpackedColorByName_t)(const char* name, float* color);
|
||||
@ -289,7 +289,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