Skip to content

Commit

Permalink
fix: sar_force_fov range with cheats
Browse files Browse the repository at this point in the history
Fixes #272

also, viewmodel fov is used as a float apparently
so why not support that

also also, remove tick operations because cvar
callbacks are plenty to keep it forced
  • Loading branch information
ThisAMJ committed Aug 22, 2024
1 parent 152559c commit bfce103
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
30 changes: 13 additions & 17 deletions src/Features/FovChanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Modules/Client.hpp"
#include "Modules/Console.hpp"
#include "Modules/Engine.hpp"
#include "Modules/Server.hpp"
#include "Variable.hpp"

FovChanger *fovChanger;
Expand All @@ -19,30 +20,25 @@ void FovChanger::SetFov(const int fov) {
this->defaultFov = fov;
this->Force();
}
void FovChanger::SetViewmodelFov(const int fov) {
void FovChanger::SetViewmodelFov(const float fov) {
this->viewmodelFov = fov;
this->Force();
}
void FovChanger::Force() {
if (this->defaultFov != 0) {
cl_fov.SetValue(this->defaultFov);
if (!sv_cheats.GetBool() && (this->defaultFov < 45 || this->defaultFov > 140)) {
this->defaultFov = 0;
} else {
if (cl_fov.GetInt() != this->defaultFov) {
cl_fov.SetValue(this->defaultFov);
}
}
}
if (this->viewmodelFov != 0) {
if (this->viewmodelFov != 0 && cl_viewmodelfov.GetFloat() != this->viewmodelFov) {
cl_viewmodelfov.SetValue(this->viewmodelFov);
}
}

ON_EVENT(SESSION_START) {
fovChanger->needToUpdate = true;
}

ON_EVENT(PRE_TICK) {
if (engine->demoplayer->IsPlaying()) return;
if (fovChanger->needToUpdate) {
fovChanger->Force();
}
}

// Commands

CON_COMMAND_COMPLETION(sar_force_fov, "sar_force_fov <fov> - forces player FOV\n", ({"0", "50", "60", "70", "80", "90", "100", "110", "120", "130", "140"})) {
Expand All @@ -56,7 +52,7 @@ CON_COMMAND_COMPLETION(sar_force_fov, "sar_force_fov <fov> - forces player FOV\n
return console->Print("Disabled forcing FOV!\n");
}

if (fov < 45 || fov > 140) {
if (!sv_cheats.GetBool() && (fov < 45 || fov > 140)) {
return console->Print("FOV value has to be between 45 to 140!\n");
}

Expand All @@ -69,12 +65,12 @@ CON_COMMAND(sar_force_viewmodel_fov, "sar_force_viewmodel_fov <fov> - forces vie
return console->Print(sar_force_viewmodel_fov.ThisPtr()->m_pszHelpString);
}

auto fov = std::atoi(args[1]);
auto fov = (float)std::atof(args[1]);
if (fov == 0) {
fovChanger->SetViewmodelFov(fov);
return console->Print("Disabled forcing viewmodel FOV!\n");
}

fovChanger->SetViewmodelFov(fov);
console->Print("Enabled forcing viewmodel FOV: %i\n", fov);
console->Print("Enabled forcing viewmodel FOV: %f\n", fov);
}
6 changes: 2 additions & 4 deletions src/Features/FovChanger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
class FovChanger : public Feature {
private:
int defaultFov;
int viewmodelFov;
float viewmodelFov;

public:
FovChanger();
void SetFov(const int fov);
void SetViewmodelFov(const int fov);
void SetViewmodelFov(const float fov);
void Force();

bool needToUpdate = false;
};

extern FovChanger *fovChanger;
8 changes: 6 additions & 2 deletions src/Modules/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ CMDECL(Client::GetPortalLocal, CPortalPlayerLocalData, m_PortalLocal);
CMDECL(Client::GetPlayerState, CPlayerState, pl);

DECL_CVAR_CALLBACK(cl_fov) {
if (engine->demoplayer->IsPlaying())
fovChanger->Force();
fovChanger->Force();
}

DECL_CVAR_CALLBACK(cl_viewmodelfov) {
fovChanger->Force();
}

ClientEnt *Client::GetPlayer(int index) {
Expand Down Expand Up @@ -1192,6 +1195,7 @@ bool Client::Init() {
say = Variable("say");

CVAR_HOOK_AND_CALLBACK(cl_fov);
CVAR_HOOK_AND_CALLBACK(cl_viewmodelfov);

return this->hasLoaded = this->g_ClientDLL && this->s_EntityList;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Modules/EngineDemoRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ static void preventOverwrite(const char *filename, int idx) {

// CDemoRecorder::StartRecording
DETOUR(EngineDemoRecorder::StartRecording, const char *filename, bool continuously) {
fovChanger->needToUpdate = true;

timescaleDetect->Spawn();

if (sar_demo_overwrite_bak.GetBool()) {
Expand Down

0 comments on commit bfce103

Please sign in to comment.