Skip to content

Commit

Permalink
Added optional command line argument for out files
Browse files Browse the repository at this point in the history
- and also added README.md
  • Loading branch information
yobonez committed Aug 26, 2023
1 parent f10ad00 commit 2b5cde8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <export|read|pack> <filename> [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.
1 change: 1 addition & 0 deletions aos-lang-parser.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</ItemGroup>
<ItemGroup>
<None Include=".gitignore" />
<None Include="README.md" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
Expand Down
1 change: 1 addition & 0 deletions aos-lang-parser.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
</ItemGroup>
<ItemGroup>
<None Include=".gitignore" />
<None Include="README.md" />
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions aoslang_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions aoslang_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
int aoslang_export(FILE* langfile_ptr, const char* outfilename, const char* mode);
int aoslang_pack(const char* filename, const char* outfilename, const char* mode);
14 changes: 9 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <export|read|pack> <filename> \n", argv[0]); return 1; }
if (argc < 3 || !*argv[i]) { printf("Usage: %s <export|read|pack> <filename> [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;
Expand Down

0 comments on commit 2b5cde8

Please sign in to comment.