From 2b5cde89cf963c50e3b4eb4925574177967afd27 Mon Sep 17 00:00:00 2001 From: yobonez <59935203+yobonez@users.noreply.github.com> Date: Sat, 26 Aug 2023 17:23:50 +0200 Subject: [PATCH] Added optional command line argument for out files - and also added README.md --- README.md | 21 +++++++++++++++++++++ aos-lang-parser.vcxproj | 1 + aos-lang-parser.vcxproj.filters | 1 + aoslang_io.c | 16 ++++++++-------- aoslang_io.h | 4 ++-- main.c | 14 +++++++++----- 6 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..578a997 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# AoSLang-tool + +Tool for AoSLang-XX.bin files from Ben Aksoy's Ace of Spades voxlap game. + +You can read, export and pack them with it. + +## Usage +`aoslang-tool.exe [out filename]` + +`<> - required, [] - optional - for "export" & "pack"` + +## Usage examples + +`aoslang-tool.exe read AoSLang-EN.bin` +Reads the file and outputs strings and its respective offsets. + +`aoslang-tool.exe export AoSLang-EN.bin MyAoSLangExport.txt` +Exports all the strings to text file. + +`aoslang-tool.exe pack MyAoSLangExport.txt MyAosLangFile.bin` +Takes text file with strigns and converts it to aoslang binary file. \ No newline at end of file diff --git a/aos-lang-parser.vcxproj b/aos-lang-parser.vcxproj index e348387..b7d164a 100644 --- a/aos-lang-parser.vcxproj +++ b/aos-lang-parser.vcxproj @@ -28,6 +28,7 @@ + 16.0 diff --git a/aos-lang-parser.vcxproj.filters b/aos-lang-parser.vcxproj.filters index 785495d..ab360ef 100644 --- a/aos-lang-parser.vcxproj.filters +++ b/aos-lang-parser.vcxproj.filters @@ -32,5 +32,6 @@ + \ No newline at end of file diff --git a/aoslang_io.c b/aoslang_io.c index 9061412..0e1ceca 100644 --- a/aoslang_io.c +++ b/aoslang_io.c @@ -23,7 +23,7 @@ int check_header(FILE* langfile_ptr) { char header[5]; - if (fgets(header, 5, langfile_ptr) == NULL) { printf("Error occured while trying to check the header."); return -1; } + if (fgets(header, 5, langfile_ptr) == NULL) { printf("Error occured while trying to check the header.\n"); return -1; } if (strcmp(header, "STR0") != 0) { return -1; } rewind(langfile_ptr); @@ -34,8 +34,8 @@ FILE* aoslang_open(const char* filename) { FILE* aoslang_file; - if ((aoslang_file = _fsopen(filename, "rb", _SH_DENYWR)) == NULL) { printf("Error opening file: %s", filename); return NULL; } - if (check_header(aoslang_file) != 0) { printf("The selected file is not a valid AoSLang file or is corrupted."); return NULL; } + if ((aoslang_file = _fsopen(filename, "rb", _SH_DENYWR)) == NULL) { printf("Error opening file: %s\n", filename); return NULL; } + if (check_header(aoslang_file) != 0) { printf("The selected file is not a valid AoSLang file or is corrupted.\n"); return NULL; } return aoslang_file; } @@ -124,15 +124,15 @@ int aoslang_read(FILE* langfile_ptr, const char* mode) return 0; } -int aoslang_export(FILE* langfile_ptr, const char* mode) +int aoslang_export(FILE* langfile_ptr, const char* outfilename, const char* mode) { // determine amount of strings in lang file and its first string offset size_t strings_loc = aoslang_get_first_offset(langfile_ptr); size_t amount_of_strings = (strings_loc - 8) / 4; FILE* destination_file; - if ((destination_file = _fsopen("AoSLangExport.txt", "wb", _SH_DENYWR)) == NULL) { - printf("Error opening file: %s\n", "AoSLangExport.txt"); + if ((destination_file = _fsopen(outfilename, "wb", _SH_DENYWR)) == NULL) { + printf("Error opening file: %s\n", outfilename); return -1; } @@ -160,7 +160,7 @@ int aoslang_export(FILE* langfile_ptr, const char* mode) return 0; } -int aoslang_pack(const char* filename, const char* mode) +int aoslang_pack(const char* filename, const char* outfilename, const char* mode) { size_t strings_amount = 0; char lang_string[MAX_STR_LEN] = { 0 }; @@ -201,7 +201,7 @@ int aoslang_pack(const char* filename, const char* mode) // write FILE* out_aoslang; - if ((out_aoslang = _fsopen("AoSLang-PACKED.bin", "wb", SH_DENYWR)) == NULL) { printf("Error opening file: %s\n", "AoSLang-PACKED.bin"); return -1; } + if ((out_aoslang = _fsopen(outfilename, "wb", SH_DENYWR)) == NULL) { printf("Error opening file: %s\n", outfilename); return -1; } fwrite("STR0_\0\0\0", sizeof(char), 8, out_aoslang); // write 4 byte header and 4 bytes of unknown data diff --git a/aoslang_io.h b/aoslang_io.h index 74c5c47..8ece05e 100644 --- a/aoslang_io.h +++ b/aoslang_io.h @@ -6,5 +6,5 @@ //int check_header(FILE* langfile_ptr); FILE* aoslang_open(const char* aoslang_filename); int aoslang_read(FILE* langfile_ptr, const char* mode); -int aoslang_export(FILE* langfile_ptr, const char* mode); -int aoslang_pack(const char* filename); \ No newline at end of file +int aoslang_export(FILE* langfile_ptr, const char* outfilename, const char* mode); +int aoslang_pack(const char* filename, const char* outfilename, const char* mode); \ No newline at end of file diff --git a/main.c b/main.c index 1d404f2..bcdb895 100644 --- a/main.c +++ b/main.c @@ -10,24 +10,28 @@ int main(int argc, char* argv[]) { for(int i = 0; i < argc; i++) { - if (argc < 3 || !*argv[i]) { printf("Usage: %s \n", argv[0]); return 1; } + if (argc < 3 || !*argv[i]) { printf("Usage: %s [out filename]\n<> - required, \n[] - optional - for \"export\" & \"pack\"\n", argv[0]); return 1; } } const char* mode = argv[1]; const char* filename = argv[2]; if (strcmp(mode, "export") == 0) { - FILE* aoslang_file = aoslang_open(filename); + char outfilename[_MAX_PATH] = "AoSLangExport.txt"; + if (argv[3]) { strcpy_s(outfilename, sizeof(outfilename), argv[3]); } - if (aoslang_file == NULL || aoslang_export(aoslang_file, mode) != 0) { printf("An error occured.\n"); return -1; } + FILE* aoslang_file = aoslang_open(filename); + if (aoslang_file == NULL || aoslang_export(aoslang_file, outfilename, mode) != 0) { printf("An error occured.\n"); return -1; } } if (strcmp(mode, "read") == 0) { FILE* aoslang_file = aoslang_open(filename); - if (aoslang_file == NULL || aoslang_read(aoslang_file, mode) != 0) { printf("An error occured.\n"); return -1; } } if (strcmp(mode, "pack") == 0) { - if (aoslang_pack(filename, mode) != 0) { printf("An error occured.\n"); return -1; } + char outfilename[_MAX_PATH] = "AoSLang-PACKED.bin"; + if (argv[3]) { strcpy_s(outfilename, sizeof(outfilename), argv[3]); } + + if (aoslang_pack(filename, outfilename, mode) != 0) { printf("An error occured.\n"); return -1; } } return 0;