Skip to content

Commit

Permalink
- Fixed cvar pointer registration to prevent crash
Browse files Browse the repository at this point in the history
- Fixed vector calculation
- Check path to prevent crash
  • Loading branch information
SmileYzn committed Mar 1, 2024
1 parent ff29a54 commit 2459506
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
35 changes: 17 additions & 18 deletions AccuracyFix/AccuracyFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,36 @@ void CAccuracyFix::ServerActivate()
{
if (SlotInfo->weaponName[0u] != '\0')
{
std::string cvarName = "af_distance_";
char cvarName[64] = { 0 };

cvarName.append(SlotInfo->weaponName);
Q_snprintf(cvarName, sizeof(cvarName), "af_distance_%s", SlotInfo->weaponName);

this->m_af_distance[WeaponID] = gAccuracyUtil.CvarRegister(cvarName.c_str(), "8192.0");
this->m_af_distance[WeaponID] = gAccuracyUtil.CvarRegister(cvarName, "8192.0");

cvarName = "af_accuracy_";
Q_snprintf(cvarName, sizeof(cvarName), "af_accuracy_%s", SlotInfo->weaponName);

cvarName.append(SlotInfo->weaponName);

this->m_af_accuracy[WeaponID] = gAccuracyUtil.CvarRegister(cvarName.c_str(), "9999.0");
this->m_af_accuracy[WeaponID] = gAccuracyUtil.CvarRegister(cvarName, "9999.0");

#ifdef ACCURACY_ENABLE_RECOIL_CONTROL
cvarName = "af_recoil_";

cvarName.append(SlotInfo->weaponName);
Q_snprintf(cvarName, sizeof(cvarName), "af_recoil_%s", SlotInfo->weaponName);

this->m_af_recoil[WeaponID] = gAccuracyUtil.CvarRegister(cvarName.c_str(), "1.0");
this->m_af_recoil[WeaponID] = gAccuracyUtil.CvarRegister(cvarName, "1.0");
#endif
}
}
}
}
}

gAccuracyUtil.ServerCommand("exec %s/accuracyfix.cfg", gAccuracyUtil.GetPath());
auto Path = gAccuracyUtil.GetPath();

if (Path)
{
if (Path[0u] != '\0')
{
gAccuracyUtil.ServerCommand("exec %s/accuracyfix.cfg", Path);
}
}
}

#ifdef ACCURACY_ENABLE_RECOIL_CONTROL
Expand Down Expand Up @@ -123,12 +127,7 @@ void CAccuracyFix::TraceLine(const float* vStart, const float* vEnd, int fNoMons

g_engfuncs.pfnMakeVectors(pentToSkip->v.v_angle);

auto vEndRes = Vector
(
(vStart[0] + (gpGlobals->v_forward[0] * fwdVelocity)),
(vStart[1] + (gpGlobals->v_forward[1] * fwdVelocity)),
(vStart[2] + (gpGlobals->v_forward[2] * fwdVelocity))
);
auto vEndRes = (Vector)vStart + gpGlobals->v_forward * fwdVelocity;

g_engfuncs.pfnTraceLine(vStart, vEndRes, fNoMonsters, pentToSkip, ptr);
}
Expand Down
12 changes: 6 additions & 6 deletions AccuracyFix/AccuracyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ CAccuracyUtil gAccuracyUtil;

cvar_t* CAccuracyUtil::CvarRegister(const char* Name, const char* Value)
{
cvar_t* CvarPointer = g_engfuncs.pfnCVarGetPointer(Name);
cvar_t* pCvar = g_engfuncs.pfnCVarGetPointer(Name);

if (CvarPointer == nullptr)
if (pCvar == nullptr)
{
this->m_CvarData[Name].name = Name;

Expand All @@ -16,15 +16,15 @@ cvar_t* CAccuracyUtil::CvarRegister(const char* Name, const char* Value)

g_engfuncs.pfnCVarRegister(&this->m_CvarData[Name]);

CvarPointer = g_engfuncs.pfnCVarGetPointer(this->m_CvarData[Name].name);
pCvar = g_engfuncs.pfnCVarGetPointer(this->m_CvarData[Name].name);

if (CvarPointer != nullptr)
if (pCvar != nullptr)
{
g_engfuncs.pfnCvar_DirectSet(CvarPointer, Value);
g_engfuncs.pfnCvar_DirectSet(pCvar, Value);
}
}

return CvarPointer;
return pCvar;
}

const char* CAccuracyUtil::GetPath()
Expand Down

0 comments on commit 2459506

Please sign in to comment.