Skip to content

Commit cfea442

Browse files
committed
- automatically shrink chase replay size
1 parent ec39b00 commit cfea442

1 file changed

Lines changed: 56 additions & 8 deletions

File tree

Driver2CutsceneTool/cutscene_tool.cpp

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
#define MAX_FILE_CUTSCENES 15
1313
#define REPLAY_BUFFER_MINSIZE 2280
1414

15+
// replay definitions.
16+
// DO NOT EDIT, breaks compatibility!
17+
#define MAX_REPLAY_CAMERAS 60
18+
#define MAX_REPLAY_WAYPOINTS 150
19+
#define MAX_REPLAY_PINGS 400
20+
21+
#define DRIVER2_REPLAY_MAGIC 0x14793209
22+
#define REDRIVER2_CHASE_MAGIC (('D' << 24) | ('2' << 16) | ('C' << 8) | 'R' )
23+
1524
// TODO: Cutscene.h
1625

1726
struct CUTSCENE_INFO
@@ -26,6 +35,14 @@ struct CUTSCENE_HEADER
2635
CUTSCENE_INFO data[MAX_FILE_CUTSCENES];
2736
};
2837

38+
typedef struct _PING_PACKET
39+
{
40+
ushort frame;
41+
char carId;
42+
char cookieCount;
43+
} PING_PACKET;
44+
45+
2946
//----------------------------------------------------
3047

3148
// TODO: replay.h
@@ -108,6 +125,21 @@ struct PADRECORD
108125
ubyte run;
109126
};
110127

128+
struct PLAYBACKCAMERA
129+
{
130+
VECTOR_NOPAD position;
131+
SVECTOR angle;
132+
int FrameCnt;
133+
short CameraPosvy;
134+
short scr_z;
135+
short gCameraMaxDistance;
136+
short gCameraAngle;
137+
ubyte cameraview;
138+
ubyte next;
139+
ubyte prev;
140+
ubyte idx;
141+
};
142+
111143
struct STREAM_SOURCE
112144
{
113145
ubyte type;
@@ -156,7 +188,7 @@ void UnpackCutsceneFile(const char* filename)
156188
Msg("Max replay buffer size: %d\n", header.maxsize);
157189

158190
// make the folder
159-
sprintf(folderPath, "%s_files", cut_name.c_str());
191+
sprintf(folderPath, "%s", cut_name.c_str());
160192
mkdirRecursive(folderPath, true);
161193

162194
buffer = (char*)malloc(0x200000);
@@ -203,7 +235,7 @@ void UnpackCutsceneFile(const char* filename)
203235
}
204236

205237
// save separate file
206-
sprintf(folderPath, "%s_files/%s_%d.D2RP", cut_name.c_str(), cut_name.c_str(), i);
238+
sprintf(folderPath, "%s/%s_%d.D2RP", cut_name.c_str(), cut_name.c_str(), i);
207239

208240
FILE* wp = fopen(folderPath, "wb");
209241
if (wp)
@@ -236,7 +268,7 @@ void PackCutsceneFile(const char* foldername)
236268

237269
for (int i = 0; i < MAX_FILE_CUTSCENES; i++)
238270
{
239-
sprintf(folderPath, "%s_files/%s_%d.D2RP", foldername, foldername, i);
271+
sprintf(folderPath, "%s/%s_%d.D2RP", foldername, foldername, i);
240272
FILE* fp = fopen(folderPath, "rb");
241273
if (fp)
242274
{
@@ -281,6 +313,21 @@ void PackCutsceneFile(const char* foldername)
281313
header.maxsize = size * 2;
282314
}
283315
}
316+
317+
// optimize size for chases by removing camera block
318+
if (i >= 2)
319+
{
320+
hdr->magic = REDRIVER2_CHASE_MAGIC;
321+
322+
char* bufptr = (char*)sheader;
323+
char* pingBufferPtr = bufptr + sizeof(PLAYBACKCAMERA) * MAX_REPLAY_CAMERAS;
324+
325+
memmove(bufptr, pingBufferPtr, sizeof(PING_PACKET) * MAX_REPLAY_PINGS);
326+
327+
// shrink size
328+
repsizes[i] -= sizeof(PLAYBACKCAMERA) * MAX_REPLAY_CAMERAS;
329+
MsgAccept("\Shinking '%s', now %d bytes\n", folderPath, repsizes[i]);
330+
}
284331
}
285332
else
286333
{
@@ -358,12 +405,13 @@ void PackCutsceneFile(const char* foldername)
358405
header.data[i].offset = offset / 4; // because it use shorts we have an multiplier
359406
header.data[i].size = repsizes[replayId];
360407

361-
int sizeStep = repsizes[replayId] / 2048;
362-
if (sizeStep < 1)
363-
sizeStep = 1;
408+
int sizeStep = (repsizes[replayId] / 2048) * 2048;
409+
410+
if (sizeStep < 2048)
411+
sizeStep = 2048;
364412

365-
bufptr += sizeStep * 2048;
366-
offset += sizeStep * 2048;
413+
bufptr += sizeStep;
414+
offset += sizeStep;
367415
}
368416

369417
MsgInfo("Saved %d cutscenes and %d chase replays\n", numCutsceneReplays, numChaseReplays);

0 commit comments

Comments
 (0)