Skip to content

Commit

Permalink
thcrap: always dump patched files when patched_files_dump is true
Browse files Browse the repository at this point in the history
Not overwriting the file when it already exists is a valid optimization only
when the file doesn't change. And patched files can change a lot more easily
than original files (usually, when I enable patched_files_dump, it's because
I want to see the result of a change).
  • Loading branch information
brliron committed Dec 17, 2024
1 parent dd1528d commit 1024b13
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions thcrap/src/bp_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ int BP_file_load(x86_reg_t *regs, json_t *bp_info)
}

// Cool function name.
int DumpDatFile(const char *dir, const char *name, const void *buffer, size_t size)
int DumpDatFile(const char *dir, const char *name, const void *buffer, size_t size, bool overwrite_existing)
{
if unexpected(!buffer || !name) {
return -1;
}

BUILD_VLA_STR(char, fn, dir, "/", name);
if (!PathFileExistsU(fn)) {
if (overwrite_existing || !PathFileExistsU(fn)) {
file_write(fn, buffer, size);
}
VLA_FREE(fn);
Expand All @@ -171,7 +171,7 @@ int BP_file_loaded(x86_reg_t *regs, json_t *bp_info)
}
dat_dump = runconfig_dat_dump_get();
if(dat_dump) {
DumpDatFile(dat_dump, fr->name, fr->game_buffer, fr->pre_json_size);
DumpDatFile(dat_dump, fr->name, fr->game_buffer, fr->pre_json_size, false);
}

file_rep_hooks_run(fr);
Expand Down
2 changes: 1 addition & 1 deletion thcrap/src/bp_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ TH_IMPORT int BP_file_size(x86_reg_t *regs, json_t *bp_info);
THCRAP_BREAKPOINT_API int BP_file_loaded(x86_reg_t *regs, json_t *bp_info);

// Cool function name.
THCRAP_API int DumpDatFile(const char *dir, const char *name, const void *buffer, size_t size);
THCRAP_API int DumpDatFile(const char *dir, const char *name, const void *buffer, size_t size, bool overwrite_existing);

int bp_file_init(void);
void bp_file_mod_thread_exit(void);
Expand Down
2 changes: 1 addition & 1 deletion thcrap/src/patchfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ int patchhooks_run(const patchhook_t *hook_array, void *file_inout, size_t size_
if (func(file_inout, size_out, size_in, fn, patch) > 0) {
const char *patched_files_dump = runconfig_patched_files_dump_get();
if unexpected(patched_files_dump) {
DumpDatFile(patched_files_dump, fn, file_inout, size_out);
DumpDatFile(patched_files_dump, fn, file_inout, size_out, true);
}
ret = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion thcrap_tasofro/src/tasofro_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void TasofroFile::replace_ReadFile_init(ReadFileStack *stack,
decrypt(this, (BYTE*)game_buffer, pre_json_size);

if unexpected(dat_dump) {
DumpDatFile(dat_dump, this->name, game_buffer, pre_json_size);
DumpDatFile(dat_dump, this->name, game_buffer, pre_json_size, false);
}
// If there are hooks and no replacement file
// then just pass the original file to the
Expand Down

0 comments on commit 1024b13

Please sign in to comment.