1- #include < math .h>
2-
1+ #include < stdlib .h>
2+ # include < stdio.h >
33#include < malloc.h>
4- #include " core/VirtualStream.h"
54#include " core/cmdlib.h"
6- #include " math/dktypes.h"
7- #include " util/image.h"
8- #include " util/util.h"
9- #include < string>
10- #include < DriverLevelTool/driver_routines/d2_types.h>
5+ #include " core/dktypes.h"
6+ #include < string.h>
7+ #include < nstd/Directory.hpp>
8+ #include < nstd/File.hpp>
9+ #include < nstd/String.hpp>
10+
11+ #include " math/psx_math_types.h"
1112
1213#define MAX_FILE_CUTSCENES 15
1314#define REPLAY_BUFFER_MINSIZE 2280
@@ -165,13 +166,10 @@ struct REPLAY_STREAM_HEADER
165166void UnpackCutsceneFile (const char * filename)
166167{
167168 // replace extension with .den
168- std::string cut_name = filename;
169-
170- size_t str_idx = cut_name.find_last_of (" ." );
171- cut_name = cut_name.substr (0 , str_idx);
169+ String cut_name = String::fromCString (filename);
170+ cut_name = File::basename (cut_name, File::extension (cut_name));
172171
173172 char * buffer;
174- char folderPath[512 ];
175173
176174 CUTSCENE_HEADER header;
177175 FILE* fp = fopen (filename, " rb" );
@@ -188,8 +186,8 @@ void UnpackCutsceneFile(const char* filename)
188186 Msg (" Max replay buffer size: %d\n " , header.maxsize );
189187
190188 // make the folder
191- sprintf ( folderPath, " %s " , cut_name. c_str ()) ;
192- mkdirRecursive (folderPath, true );
189+ String folderPath = cut_name;
190+ Directory::create (folderPath);
193191
194192 buffer = (char *)malloc (0x200000 );
195193
@@ -235,9 +233,7 @@ void UnpackCutsceneFile(const char* filename)
235233 }
236234
237235 // save separate file
238- sprintf (folderPath, " %s/%s_%d.D2RP" , cut_name.c_str (), cut_name.c_str (), i);
239-
240- FILE* wp = fopen (folderPath, " wb" );
236+ FILE* wp = fopen (String::fromPrintf (" %s/%s_%d.D2RP" , (char *)cut_name, (char *)cut_name, i), " wb" );
241237 if (wp)
242238 {
243239 MsgWarning (" \t Saving '%s', at %d, %d bytes\n " , folderPath, header.data [i].offset , header.data [i].size );
@@ -255,7 +251,6 @@ void PackCutsceneFile(const char* foldername)
255251{
256252 int offset;
257253 char * buffer;
258- char folderPath[512 ];
259254 CUTSCENE_HEADER header;
260255 header.maxsize = REPLAY_BUFFER_MINSIZE;
261256
@@ -268,8 +263,8 @@ void PackCutsceneFile(const char* foldername)
268263
269264 for (int i = 0 ; i < MAX_FILE_CUTSCENES; i++)
270265 {
271- sprintf ( folderPath, " %s/%s_%d.D2RP" , foldername, foldername, i);
272- FILE* fp = fopen (folderPath , " rb" );
266+ String folderPath = String::fromPrintf ( " %s/%s_%d.D2RP" , foldername, foldername, i);
267+ FILE* fp = fopen (String::fromPrintf ( " %s/%s_%d.D2RP " , foldername, foldername, i) , " rb" );
273268 if (fp)
274269 {
275270 if (i == 0 )
@@ -293,7 +288,7 @@ void PackCutsceneFile(const char* foldername)
293288 replays[i] = (char *)malloc (size);
294289 repsizes[i] = size;
295290
296- MsgWarning (" \t Loaded '%s', %d bytes\n " , folderPath, size);
291+ MsgWarning (" \t Loaded '%s', %d bytes\n " , ( char *) folderPath, size);
297292 fread (replays[i], 1 , size, fp);
298293 fclose (fp);
299294
@@ -322,11 +317,25 @@ void PackCutsceneFile(const char* foldername)
322317 char * bufptr = (char *)sheader;
323318 char * pingBufferPtr = bufptr + sizeof (PLAYBACKCAMERA) * MAX_REPLAY_CAMERAS;
324319
320+ // copy all pings to new position and remove deleted car pings too
321+ /* for (int j = 0; j < MAX_REPLAY_PINGS; j++)
322+ {
323+ PING_PACKET packet = *(PING_PACKET*)pingBufferPtr;
324+
325+ if(packet.carId != -1 && packet.frame != 0xffff)
326+ {
327+ *(PING_PACKET*)bufptr = packet;
328+ bufptr += sizeof(PING_PACKET);
329+ }
330+
331+ pingBufferPtr += sizeof(PING_PACKET);
332+ }*/
333+
325334 memmove (bufptr, pingBufferPtr, sizeof (PING_PACKET) * MAX_REPLAY_PINGS);
326335
327336 // shrink size
328337 repsizes[i] -= sizeof (PLAYBACKCAMERA) * MAX_REPLAY_CAMERAS;
329- MsgAccept (" \t Shrinking '%s', now %d bytes\n " , folderPath, repsizes[i]);
338+ MsgAccept (" \t Shrinking '%s', now %d bytes\n " , ( char *) folderPath, repsizes[i]);
330339 }
331340 }
332341 else
@@ -358,15 +367,16 @@ void PackCutsceneFile(const char* foldername)
358367 MsgWarning (" No chase replays\n " );
359368 }
360369
361- sprintf (folderPath, " %s_N.R" , foldername);
370+ String folderPath = String::fromPrintf (" %s_N.R" , foldername);
371+
362372 FILE* wp = fopen (folderPath, " wb" );
363373
364374 if (!wp)
365375 {
366376 for (int i = 0 ; i < MAX_FILE_CUTSCENES; i++)
367377 free (replays[i]);
368378
369- MsgError (" Unable to save '%s'\n " , folderPath);
379+ MsgError (" Unable to save '%s'\n " , ( char *) folderPath);
370380 return ;
371381 }
372382
0 commit comments