Skip to content

Commit

Permalink
Make player model glow preview animation speed independent of framerate
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Jan 24, 2025
1 parent ddec7ed commit 8e5a280
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Source/CS2/Classes/GlobalVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace cs2
{

struct GlobalVars {
PAD(52); // FIXME: get offset to curtime dynamically
PAD(48); // FIXME: get offsets to frametime and curtime dynamically
float frametime;
float curtime;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ class PlayerModelGlowPreview {
private:
void updateAnimationProgress() const noexcept
{
constexpr auto kFrameTime{1 / 60.0f}; // todo: get real frametime from globalVars
constexpr auto kDefaultFrameTime{1 / 60.0f};
const auto frameTime = hookContext.globalVars().frametime().valueOr(kDefaultFrameTime);

using namespace player_model_glow_preview_params;
if (kFrameTime < kAnimationCycleDuration - state().animationProgress)
state().animationProgress += kFrameTime;
if (frameTime < kAnimationCycleDuration - state().animationProgress)
state().animationProgress += frameTime;
else
state().animationProgress = 0.0f;
}
Expand Down
7 changes: 7 additions & 0 deletions Source/GameClasses/GlobalVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ struct GlobalVars {
return {};
}

[[nodiscard]] Optional<float> frametime() const noexcept
{
if (globalVars)
return globalVars->frametime;
return {};
}

cs2::GlobalVars* globalVars;
};

0 comments on commit 8e5a280

Please sign in to comment.