Skip to content

Commit

Permalink
check replay header for time if replay-playback is unloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed Feb 24, 2022
1 parent 80e8480 commit 060ce5e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
5 changes: 0 additions & 5 deletions addons/sourcemod/scripting/include/shavit/replay-file.inc
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ stock File ReadReplayHeader(const char[] path, replay_header_t header, int style
replay_header_t empty_header;
header = empty_header;

if (!FileExists(path))
{
return null;
}

File file = OpenFile(path, "rb");

if (file == null)
Expand Down
7 changes: 7 additions & 0 deletions addons/sourcemod/scripting/include/shavit/replay-stocks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ stock bool Shavit_ReplayEnabledStyle(int style)
return !Shavit_GetStyleSettingBool(style, "unranked") && !Shavit_GetStyleSettingBool(style, "noreplay");
}

stock void Shavit_GetReplayFilePath(int style, int track, const char[] mapname, const char[] replayfolder, char sPath[PLATFORM_MAX_PATH])
{
char sTrack[4];
FormatEx(sTrack, 4, "_%d", track);
FormatEx(sPath, PLATFORM_MAX_PATH, "%s/%d/%s%s.replay", replayfolder, style, mapname, (track > 0)? sTrack:"");
}

stock bool Shavit_GetReplayFolderPath_Stock(char buffer[PLATFORM_MAX_PATH])
{
char sPath[PLATFORM_MAX_PATH];
Expand Down
11 changes: 2 additions & 9 deletions addons/sourcemod/scripting/shavit-replay-playback.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,17 +1819,10 @@ void AddReplayBots()
}
}

void GetReplayFilePath(int style, int track, const char[] mapname, char sPath[PLATFORM_MAX_PATH])
{
char sTrack[4];
FormatEx(sTrack, 4, "_%d", track);
FormatEx(sPath, PLATFORM_MAX_PATH, "%s/%d/%s%s.replay", gS_ReplayFolder, style, mapname, (track > 0)? sTrack:"");
}

bool DefaultLoadReplay(frame_cache_t cache, int style, int track)
{
char sPath[PLATFORM_MAX_PATH];
GetReplayFilePath(style, track, gS_Map, sPath);
Shavit_GetReplayFilePath(style, track, gS_Map, gS_ReplayFolder, sPath);

if (!LoadReplay(cache, style, track, sPath, gS_Map))
{
Expand Down Expand Up @@ -1857,7 +1850,7 @@ bool DefaultLoadReplay(frame_cache_t cache, int style, int track)
bool DeleteReplay(int style, int track, int accountid, const char[] mapname)
{
char sPath[PLATFORM_MAX_PATH];
GetReplayFilePath(style, track, mapname, sPath);
Shavit_GetReplayFilePath(style, track, mapname, gS_ReplayFolder, sPath);

if(!FileExists(sPath))
{
Expand Down
24 changes: 23 additions & 1 deletion addons/sourcemod/scripting/shavit-replay-recorder.sp
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,35 @@ void FinishGrabbingPostFrames(int client, finished_run_info info)
DoReplaySaverCallbacks(info.iSteamID, client, info.style, info.time, info.jumps, info.strafes, info.sync, info.track, info.oldtime, info.perfs, info.avgvel, info.maxvel, info.timestamp, info.fZoneOffset);
}

float ExistingWrReplayLength(int style, int track)
{
if (gB_ReplayPlayback)
{
return Shavit_GetReplayLength(style, track);
}

char sPath[PLATFORM_MAX_PATH];
Shavit_GetReplayFilePath(style, track, gS_Map, gS_ReplayFolder, sPath);

replay_header_t header;
File f = ReadReplayHeader(sPath, header, style, track);

if (f != null)
{
delete f;
return header.fTime;
}

return 0.0;
}

void DoReplaySaverCallbacks(int iSteamID, int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs, float avgvel, float maxvel, int timestamp, float fZoneOffset[2])
{
gA_PlayerFrames[client].Resize(gI_PlayerFrames[client]);

bool isTooLong = (gCV_TimeLimit.FloatValue > 0.0 && time > gCV_TimeLimit.FloatValue);

float length = gB_ReplayPlayback ? Shavit_GetReplayLength(style, track) : 999999999.0;
float length = ExistingWrReplayLength(style, track);
bool isBestReplay = (length == 0.0 || time < length);

Action action = Plugin_Continue;
Expand Down

0 comments on commit 060ce5e

Please sign in to comment.