Skip to content

Commit

Permalink
gz-compress replays to make github happy
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfloogle committed Mar 26, 2024
1 parent 1a51981 commit bd3539e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion source/3ds/gui_hard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ void guiInit() {
STATIC_TEXT(&text_left, "Left");
STATIC_TEXT(&text_right, "Right");
STATIC_TEXT(&text_sound_error, "Error: couldn't initialize audio.\nDid you dump your DSP firmware?");
STATIC_TEXT(&text_debug_filenames, "Please share debug_info.txt and\ndebug_replay.bin in your bug report.");
STATIC_TEXT(&text_debug_filenames, "Please share debug_info.txt and\ndebug_replay.bin.gz in your bug\nreport.");
STATIC_TEXT(&text_anykeyexit, "Press any key to exit");
STATIC_TEXT(&text_about, VERSION "\nBy Floogle, danielps, & others\nHeavily based on Reality Boy by David Tucker\nMore info at:\ngithub.com/skyfloogle/red-viper");
STATIC_TEXT(&text_loading, "Loading...");
Expand Down
29 changes: 19 additions & 10 deletions source/3ds/replay.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <zlib.h>
#include "replay.h"
#include "v810_mem.h"
#include "vb_set.h"
Expand Down Expand Up @@ -51,18 +52,26 @@ void replay_update(HWORD inputs) {
replay_cursor->count++;
}

// returns 0 on success
static int gz_write_all(gzFile f, void *data, size_t size) {
int cursor = 0;
while (cursor < size) {
int bytes_written = gzwrite(f, data + cursor, size - cursor);
if (bytes_written == 0) return -1;
cursor += bytes_written;
}
return 0;
}

void replay_save(char *fn) {
FILE *f = fopen(fn, "wb");
gzFile f = gzopen(fn, "wb");
if (!f) return;
fwrite(&MAGIC, 4, 1, f);
fwrite(&REPLAY_VERSION, 4, 1, f);
fwrite(&tVBOpt.CRC32, 4, 1, f);
fwrite(&initial_sram_size, 4, 1, f);
if (initial_sram_size) {
fwrite(initial_sram, 1, initial_sram_size, f);
}
fwrite(replay_buf, sizeof(ReplayEntry), replay_cursor + 1 - replay_buf, f);
fclose(f);
u32 header[4] = {MAGIC, REPLAY_VERSION, tVBOpt.CRC32, initial_sram_size};
if (gz_write_all(f, header, sizeof(header))) goto bail;
if (gz_write_all(f, initial_sram, initial_sram_size)) goto bail;
if (gz_write_all(f, replay_buf, (replay_cursor + 1 - replay_buf) * sizeof(*replay_buf))) goto bail;
bail:
gzclose(f);
}

static FILE *current_replay;
Expand Down
2 changes: 1 addition & 1 deletion source/common/drc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ void drc_dumpDebugInfo(int code) {
debug_dumpvbram();
}

replay_save("debug_replay.bin");
replay_save("debug_replay.bin.gz");

fclose(f);
}

0 comments on commit bd3539e

Please sign in to comment.