Skip to content

Commit

Permalink
Add hook for TAS Studio stop until stop frame (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo authored Nov 17, 2023
1 parent 1ee1987 commit 60f434a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@ void HwDLL::Clear()
free_cam_active = false;
extendPlayerTraceDistanceLimit = false;

tas_studio_norefresh_override = 0;

if (resetState == ResetState::NORMAL) {
input.Clear();
ResetTASPlaybackState();
Expand Down Expand Up @@ -2365,6 +2367,16 @@ void HwDLL::CallOnTASPlaybackStopped() {
}
}

extern "C" DLLEXPORT int bxt_tas_norefresh_until_last_frames() {
return CVars::bxt_tas_norefresh_until_last_frames.GetInt();
}

// Sets the effective frame to stop norefresh when using TAS Studio.
extern "C" DLLEXPORT void bxt_tas_studio_norefresh_override(int stop_frame) {
auto &hw = HwDLL::GetInstance();
hw.tas_studio_norefresh_override = stop_frame;
}

void HwDLL::ResetTASPlaybackState()
{
CallOnTASPlaybackStopped();
Expand Down Expand Up @@ -2459,6 +2471,10 @@ void HwDLL::StartTASPlayback()
}

auto norefresh_until_frames = CVars::bxt_tas_norefresh_until_last_frames.GetInt();
if (tas_studio_norefresh_override > 0 && norefresh_until_frames > 0) {
norefresh_until_frames = tas_studio_norefresh_override;
}

if (norefresh_until_frames > 0 && totalFrames > static_cast<size_t>(norefresh_until_frames))
ORIG_Cbuf_InsertText("_bxt_norefresh 1\n");

Expand Down Expand Up @@ -2497,6 +2513,8 @@ struct HwDLL::Cmd_BXT_TAS_LoadScript
if (hw.resetState != ResetState::NORMAL)
return;

hw.tas_studio_norefresh_override = 0;

hw.ResetTASPlaybackState();
hw.hltas_filename = fileName;

Expand Down Expand Up @@ -5720,6 +5738,10 @@ void HwDLL::InsertCommands()

--totalFrames;
auto norefresh_until_frames = CVars::bxt_tas_norefresh_until_last_frames.GetInt();

if (tas_studio_norefresh_override > 0 && norefresh_until_frames > 0)
norefresh_until_frames = tas_studio_norefresh_override;

if (norefresh_until_frames > 0 && totalFrames <= static_cast<size_t>(norefresh_until_frames)
&& CVars::_bxt_norefresh.GetBool())
ORIG_Cbuf_InsertText("_bxt_norefresh 0\n");
Expand Down Expand Up @@ -5993,6 +6015,8 @@ void HwDLL::InsertCommands()
if (currentFramebulk >= totalFramebulks) {
runningFrames = false;

tas_studio_norefresh_override = 0;

if (!exportFilename.empty()) {
auto error = exportResult.Save(exportFilename);
if (error.Code == HLTAS::ErrorCode::OK)
Expand Down
2 changes: 2 additions & 0 deletions BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ class HwDLL : public IHookableNameFilterOrdered
void TimerReset();
void TimerStart();

int tas_studio_norefresh_override = 0;

private:
// Make sure to have hl.exe last here, so that it is the lowest priority.
HwDLL() : IHookableNameFilterOrdered({ L"hw.dll", L"hw.so", L"sw.dll", L"hl.exe" }) {};
Expand Down

0 comments on commit 60f434a

Please sign in to comment.