From: Holger Schemel Date: Tue, 29 Jun 2021 10:20:21 +0000 (+0200) Subject: added option to write tape log file (for high score server) X-Git-Tag: 4.3.0.0~115 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=411da92d158734699a25a7925a89f29b18fb373f;p=rocksndiamonds.git added option to write tape log file (for high score server) --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 5f9c009a..ed4c2606 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1262,6 +1262,7 @@ void GetOptions(int argc, char *argv[], options.conf_directory = getPath2(base_path, CONF_DIRECTORY); options.execute_command = NULL; + options.tape_log_filename = NULL; options.special_flags = NULL; options.debug_mode = NULL; @@ -1428,6 +1429,15 @@ void GetOptions(int argc, char *argv[], // when doing batch processing, always enable verbose mode (warnings) options.verbose = TRUE; } + else if (strncmp(option, "-tape_logfile", option_len) == 0) + { + if (option_arg == NULL) + FailWithHelp("option '%s' requires an argument", option_str); + + options.tape_log_filename = getStringCopy(option_arg); + if (option_arg == next_option) + options_left++; + } #if defined(PLATFORM_MACOSX) else if (strPrefix(option, "-psn")) { diff --git a/src/libgame/system.h b/src/libgame/system.h index 40f3436b..bd3f4b8f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1050,6 +1050,7 @@ struct OptionInfo char *conf_directory; char *execute_command; + char *tape_log_filename; char *special_flags; char *debug_mode; diff --git a/src/tape.c b/src/tape.c index 14bf45bc..0c99d680 100644 --- a/src/tape.c +++ b/src/tape.c @@ -512,6 +512,27 @@ static void PrintTapeReplayProgress(boolean replay_finished) } } +static FILE *tape_log_file; + +static void OpenTapeLogfile(void) +{ + if (!(tape_log_file = fopen(options.tape_log_filename, MODE_WRITE))) + Warn("cannot write tape logfile '%s'", options.tape_log_filename); +} + +static void WriteTapeLogfile(byte action[MAX_TAPE_ACTIONS]) +{ + int i; + + for (i = 0; i < MAX_TAPE_ACTIONS; i++) + putFile8Bit(tape_log_file, action[i]); +} + +static void CloseTapeLogfile(void) +{ + fclose(tape_log_file); +} + // ============================================================================ // tape control functions @@ -936,6 +957,9 @@ byte *TapePlayAction(void) if (tape.auto_play) PrintTapeReplayProgress(FALSE); + if (options.tape_log_filename != NULL) + WriteTapeLogfile(action); + return action; } @@ -1313,6 +1337,9 @@ void AutoPlayTapes(void) // just finished auto-playing tape PrintTapeReplayProgress(TRUE); + if (options.tape_log_filename != NULL) + CloseTapeLogfile(); + if (global.autoplay_mode == AUTOPLAY_MODE_SAVE && tape.auto_play_level_solved) { @@ -1549,6 +1576,9 @@ void AutoPlayTapes(void) InitCounter(); + if (options.tape_log_filename != NULL) + OpenTapeLogfile(); + TapeStartGamePlaying(); TapeStartWarpForward(global.autoplay_mode);