Skip to content

Commit

Permalink
Merge pull request #777 from shavitush/very_good_yes
Browse files Browse the repository at this point in the history
2.5.2
  • Loading branch information
shavitush authored Apr 5, 2019
2 parents 6828e11 + 8b2e335 commit 5fb84e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/include/shavit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#endif
#define _shavit_included

#define SHAVIT_VERSION "2.5.1"
#define SHAVIT_VERSION "2.5.2"
#define STYLE_LIMIT 256
#define MAX_ZONES 64
#define MAX_NAME_LENGTH_SQL 32
Expand Down
44 changes: 34 additions & 10 deletions addons/sourcemod/scripting/shavit-replay.sp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define REPLAY_FORMAT_V2 "{SHAVITREPLAYFORMAT}{V2}"
#define REPLAY_FORMAT_FINAL "{SHAVITREPLAYFORMAT}{FINAL}"
#define REPLAY_FORMAT_SUBVERSION 0x02
#define REPLAY_FORMAT_SUBVERSION 0x03
#define CELLS_PER_FRAME 8 // origin[3], angles[2], buttons, flags, movetype
#define FRAMES_PER_WRITE 100 // amounts of frames to write per read/write call

Expand Down Expand Up @@ -983,17 +983,44 @@ bool LoadReplay(int style, int track, const char[] path)

if(!fFile.ReadLine(sHeader, 64))
{
delete fFile;

return false;
}

TrimString(sHeader);
char sExplodedHeader[2][64];
ExplodeString(sHeader, ":", sExplodedHeader, 2, 64);

// TODO: split this piece of shit to different functions. cbf to keep it like this
if(StrEqual(sExplodedHeader[1], REPLAY_FORMAT_FINAL)) // hopefully, the last of them
{
gA_FrameCache[style][track].iReplayVersion = StringToInt(sExplodedHeader[0]);

// replay file integrity and preframes
if(gA_FrameCache[style][track].iReplayVersion >= 0x03)
{
char sMap[160];
fFile.ReadString(sMap, 160);

int iStyle = 0;
fFile.ReadUint8(iStyle);

int iTrack = 0;
fFile.ReadUint8(iTrack);

if(!StrEqual(sMap, gS_Map, false) || iStyle != style || iTrack != track)
{
delete fFile;

return false;
}

// whenever this is implemented
// fFile.ReadInt32(gA_FrameCache[style][track].iPreframes);
fFile.Seek(4, SEEK_CUR);
}

int iTemp = 0;
fFile.ReadInt32(iTemp);
gA_FrameCache[style][track].iFrameCount = iTemp;
Expand Down Expand Up @@ -1114,7 +1141,7 @@ bool LoadReplay(int style, int track, const char[] path)
return false;
}

bool SaveReplay(int style, int track, float time, char[] authid, char[] name)
bool SaveReplay(int style, int track, float time, char[] authid, char[] name, int preframes = 0)
{
char sTrack[4];
FormatEx(sTrack, 4, "_%d", track);
Expand All @@ -1130,14 +1157,16 @@ bool SaveReplay(int style, int track, float time, char[] authid, char[] name)
File fFile = OpenFile(sPath, "wb");
fFile.WriteLine("%d:" ... REPLAY_FORMAT_FINAL, REPLAY_FORMAT_SUBVERSION);

int iSize = gA_Frames[style][track].Length;
fFile.WriteString(gS_Map, true);
fFile.WriteInt8(style);
fFile.WriteInt8(track);
fFile.WriteInt32(preframes);

int iSize = gA_Frames[style][track].Length;
fFile.WriteInt32(iSize);
fFile.WriteInt32(view_as<int>(time));
fFile.WriteString(authid, true);

// if REPLAY_FORMAT_SUBVERSION is over 0x01 i'll add variables here

any aFrameData[CELLS_PER_FRAME];
any aWriteData[CELLS_PER_FRAME * FRAMES_PER_WRITE];
int iFramesWritten = 0;
Expand Down Expand Up @@ -2313,11 +2342,6 @@ void OpenReplaySubMenu(int client, int track, int item = 0)
menu.AddItem("-1", "ERROR");
}

else if(menu.ItemCount <= ((gEV_Type == Engine_CSS)? 8:7))
{
menu.Pagination = MENU_NO_PAGINATION;
}

menu.ExitBackButton = true;
menu.DisplayAt(client, item, 60);
}
Expand Down

0 comments on commit 5fb84e6

Please sign in to comment.