From 05b4c125e6420932109435d83781a574b38a9b47 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 2 Sep 2023 17:19:51 +0300 Subject: [PATCH] Add target_save --- src/mapper/mp_targt.cc | 41 +++++++++++++++++++++++++++++++++++++++++ src/mapper/mp_targt.h | 1 + 2 files changed, 42 insertions(+) diff --git a/src/mapper/mp_targt.cc b/src/mapper/mp_targt.cc index c72ca2a..12b9cc9 100644 --- a/src/mapper/mp_targt.cc +++ b/src/mapper/mp_targt.cc @@ -139,6 +139,47 @@ int target_header_load() return 0; } +// 0x49B58C +int target_save(int pid) +{ + char path[COMPAT_MAX_PATH]; + size_t len; + char* extension; + FILE* stream; + TargetSubNode* subnode; + + if (target_ptr(pid, &subnode) == -1) { + return -1; + } + + target_make_path(path, pid); + + len = strlen(path); + path[len] = '\\'; + _proto_list_str(pid, path + len + 1); + + extension = strchr(path + len + 1, '.'); + if (extension != NULL) { + strcpy(extension + 1, "tgt"); + } else { + strcat(path, ".tgt"); + } + + stream = fopen(path, "wb"); + if (stream == NULL) { + return -1; + } + + while (subnode != NULL) { + fwrite(subnode, sizeof(TargetSubNode), 1, stream); + subnode = subnode->next; + } + + fclose(stream); + + return 0; +} + // 0x49B6BC int target_load(int pid, TargetSubNode** subnode_ptr) { diff --git a/src/mapper/mp_targt.h b/src/mapper/mp_targt.h index 9c65ed5..db84194 100644 --- a/src/mapper/mp_targt.h +++ b/src/mapper/mp_targt.h @@ -53,6 +53,7 @@ int target_init(); int target_exit(); int target_header_save(); int target_header_load(); +int target_save(int pid); int target_load(int pid, TargetSubNode** subnode_ptr); int target_find_free_subnode(TargetSubNode** subnode_ptr); int target_remove_all();