-
Notifications
You must be signed in to change notification settings - Fork 2
/
replaytest.sp
55 lines (43 loc) · 1.47 KB
/
replaytest.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <sourcemod>
#include <shavit/replay-file>
#include <shavit/replay-stocks.sp>
void writeframe(File fout, int changed, any[] frame, int framesize)
{
for (int asdf = 0; asdf < framesize; asdf++) {
if (changed & (1 << asdf))
fout.WriteInt32(frame[asdf]);
}
}
void writeframediff(File fout, any[] oldframe, any[] newframe, int framesize)
{
int changed = 0;
for (int asdf = 0; asdf < framesize; asdf++) {
if (newframe[asdf] != oldframe[asdf])
changed |= (1 << asdf);
}
fout.WriteInt16(changed);
writeframe(fout, changed, newframe, framesize);
}
public void OnPluginStart()
{
char replayfolder[PLATFORM_MAX_PATH];
Shavit_GetReplayFolderPath_Stock(replayfolder);
char replayfile[PLATFORM_MAX_PATH];
Shavit_GetReplayFilePath(0, 0, "bhop_badges", replayfolder, replayfile);
frame_cache_t cache;
LoadReplayCache(cache, 0, 0, replayfile, "bhop_badges");
File fout = OpenFile("test.replay", "wb");
int totalframes = cache.iFrameCount+cache.iPreFrames+cache.iPostFrames;
WriteReplayHeader(fout, 0, 0, cache.fTime, cache.iSteamID, cache.iPreFrames, cache.iPostFrames, view_as<float>({0.0,0.0}), totalframes, cache.fTickrate, "bhop_badges");
frame_t oldframe;
cache.aFrames.GetArray(0, oldframe);
fout.WriteInt16(0x1FF);
writeframe(fout, -1, oldframe, sizeof(frame_t));
for (int i = 1; i < totalframes; i++) {
frame_t newframe;
cache.aFrames.GetArray(i, newframe);
writeframediff(fout, oldframe, newframe, sizeof(frame_t));
oldframe = newframe;
}
delete fout;
}