rework the header writing stuff

This commit is contained in:
rtldg 2025-07-15 20:35:20 +00:00
parent 524b3a79b9
commit 00073d6546
3 changed files with 53 additions and 39 deletions

View File

@ -365,6 +365,35 @@ stock void WriteReplayHeader(File fFile, int style, int track, float time, int s
fFile.WriteInt32(view_as<int>(fZoneOffset[1]));
}
stock void cell2buf(char[] buf, int& pos, int cell)
{
buf[pos++] = cell & 0xFF;
buf[pos++] = (cell >> 8) & 0xFF;
buf[pos++] = (cell >> 16) & 0xFF;
buf[pos++] = (cell >> 24) & 0xFF;
}
stock int WriteReplayHeaderToBuffer(char[] buf, int style, int track, float time, int steamid, int preframes, int postframes, float fZoneOffset[2], int totalframes, float tickrate, const char[] sMap)
{
int pos = FormatEx(buf, 512, "%d:%s\n%s", REPLAY_FORMAT_SUBVERSION, REPLAY_FORMAT_FINAL, sMap);
pos += 1; // skip pass NUL
buf[pos++] = style & 0xFF;
buf[pos++] = track & 0xFF;
cell2buf(buf, pos, preframes);
cell2buf(buf, pos, totalframes - preframes - postframes);
cell2buf(buf, pos, view_as<int>(time));
cell2buf(buf, pos, steamid);
cell2buf(buf, pos, postframes);
cell2buf(buf, pos, view_as<int>(tickrate));
cell2buf(buf, pos, view_as<int>(fZoneOffset[0]));
cell2buf(buf, pos, view_as<int>(fZoneOffset[1]));
return pos;
}
// file_a is usually used as the wr replay file.
// file_b is usually used as the duplicate/backup replay file.
stock void WriteReplayFrames(ArrayList playerrecording, int iSize, File file_a, File file_b)

View File

@ -15,30 +15,14 @@ typeset ReplaySavedCallback {
// Don't modify the `playerrecording` ArrayList until the ReplaySavedCallback is called... OR ELSE!!!!
native void SRCWRFloppy_AsyncSaveReplay(
// required & will throw an error if you don't use the supported versions...
char[] replayfmt
, int replaysubversion
// what to call when saved
, ReplaySavedCallback callback
// what to pass along to the callback
, any value
, char[] replayFolder
, char[] map
// copy of SaveReplay() params
, int style
, int track
, float time
, int steamid
, int preframes
ReplaySavedCallback callback // what to call when saved
, any value // what to pass along to the callback
, char[] wrpath
, char[] copypath
, char[] header
, int headersize
, ArrayList playerrecording
, int iSize
, int postframes
, int timestamp
, float fZoneOffset[2]
, bool saveCopy
, bool saveWR
, float tickrate
, int totalframes
);

View File

@ -417,26 +417,27 @@ void DoReplaySaverCallbacks(int iSteamID, int client, int style, float time, int
if (gB_Floppy)
{
char buf[512];
int headersize = WriteReplayHeaderToBuffer(buf, style, track, time, iSteamID, gI_PlayerPrerunFrames[client], postframes, fZoneOffset, gI_PlayerFrames[client], gF_Tickrate, gS_Map);
char wrpath[PLATFORM_MAX_PATH], copypath[PLATFORM_MAX_PATH];
if (makeReplay)
FormatEx(wrpath, sizeof(wrpath),
track>0?"%s/%d/%s%s_%d.replay" : "%s/%d/%s%s.replay",
gS_ReplayFolder, style, gS_Map, track
);
if (makeCopy)
FormatEx(copypath, sizeof(copypath), "%s/copy/%d_%d_%s.replay", gS_ReplayFolder, timestamp, iSteamID, gS_Map);
SRCWRFloppy_AsyncSaveReplay(
REPLAY_FORMAT_FINAL
, REPLAY_FORMAT_SUBVERSION
, FloppyAsynchronouslySavedMyReplayWhichWasNiceOfThem
FloppyAsynchronouslySavedMyReplayWhichWasNiceOfThem
, dp
, gS_ReplayFolder
, gS_Map
, style
, track
, time
, iSteamID
, gI_PlayerPrerunFrames[client]
, wrpath
, copypath
, buf
, headersize
, playerrecording
, gI_PlayerFrames[client]
, postframes
, timestamp
, fZoneOffset
, makeCopy
, makeReplay
, gF_Tickrate
);
}
else