diff --git a/c/lib/ards_util/io.c b/c/lib/ards_util/io.c index efee2a0..7b50db7 100644 --- a/c/lib/ards_util/io.c +++ b/c/lib/ards_util/io.c @@ -102,7 +102,10 @@ void file_read_cheats_and_folders( } else { // If it's a folder and blank, just ignore it - if ((tmp_data.flag & 0x03) == 0x02 && tmp_data.num_entries == 0) + if ( + (tmp_data.flag & 0x03) == AR_FLAG_FOLDER && + tmp_data.num_entries == 0 + ) continue; // Add to vector and get a pointer @@ -111,7 +114,7 @@ void file_read_cheats_and_folders( } // Act based on it being either a folder or cheat code - switch ((ar_flag_t) header->flag & 0xFF) { + switch ((ar_flag_t) header->flag & 0x03) { case AR_FLAG_TERMINATE: /* * Go back 4 bytes and make previous call re-read so recursion @@ -123,7 +126,6 @@ void file_read_cheats_and_folders( return; case AR_FLAG_CODE: - case AR_FLAG_MASTER: // It's an AR code. // This means (8 * num_entries) bytes are read header->data = cn_vec_init(ar_line_t); @@ -136,8 +138,7 @@ void file_read_cheats_and_folders( break; - case AR_FLAG_FOLDER1: - case AR_FLAG_FOLDER2: + case AR_FLAG_FOLDER: header->data = cn_vec_init(ar_data_t); file_read_cheats_and_folders( fp, @@ -162,9 +163,8 @@ void file_read_names(FILE *fp, CN_VEC root) { it->desc = file_read_string(fp); if (it->data != NULL) { - switch ((ar_flag_t) it->flag & 0xFF) { - case AR_FLAG_FOLDER1: - case AR_FLAG_FOLDER2: + switch ((ar_flag_t) it->flag & 0x03) { + case AR_FLAG_FOLDER: // AR Folders are recursive file_read_names(fp, it->data); break; @@ -291,9 +291,8 @@ void ards_game_export_as_xml_rec(FILE *out, CN_VEC root, size_t depth) { cn_vec_traverse(root, it) { if (it->data != NULL) { - switch ((ar_flag_t) it->flag & 0xFF) { + switch ((ar_flag_t) it->flag & 0x03) { case AR_FLAG_CODE: - case AR_FLAG_MASTER: __tabs(out, depth + 2); fprintf(out, "\n"); @@ -311,7 +310,7 @@ void ards_game_export_as_xml_rec(FILE *out, CN_VEC root, size_t depth) { fprintf(out, ""); // If a Master Code, put "master" before the code hex - if (((ar_flag_t) it->flag & 0xFF) == AR_FLAG_MASTER) { + if ((ar_flag_t) it->flag & AR_FLAG_MASTER) { fprintf( out, "master%s", @@ -338,8 +337,7 @@ void ards_game_export_as_xml_rec(FILE *out, CN_VEC root, size_t depth) { fprintf(out, "\n"); break; - case AR_FLAG_FOLDER1: - case AR_FLAG_FOLDER2: + case AR_FLAG_FOLDER: __tabs(out, depth + 2); fprintf(out, "\n"); @@ -353,7 +351,7 @@ void ards_game_export_as_xml_rec(FILE *out, CN_VEC root, size_t depth) { } // Radio Button Folder (only 1 code allowed on at once) - if (((ar_flag_t) it->flag & 0xFF) == AR_FLAG_FOLDER2) { + if ((ar_flag_t) it->flag & AR_FLAG_ONLYONE) { __tabs(out, depth + 3); fprintf(out, "1\n"); } @@ -403,14 +401,13 @@ void library_obliterate(CN_VEC root) { free(it->desc); if (it->data != NULL) { - switch ((ar_flag_t) it->flag & 0xFF) { + switch ((ar_flag_t) it->flag & 0x03) { case AR_FLAG_CODE: // AR Code lists are just a list of ar_line_t cn_vec_free(it->data); break; - case AR_FLAG_FOLDER1: - case AR_FLAG_FOLDER2: + case AR_FLAG_FOLDER: // AR Folders are recursive library_obliterate(it->data); break; diff --git a/c/lib/ards_util/io.h b/c/lib/ards_util/io.h index 61ac48b..21adbef 100644 --- a/c/lib/ards_util/io.h +++ b/c/lib/ards_util/io.h @@ -100,11 +100,13 @@ typedef struct AR_LINE_T { */ typedef enum AR_FLAG_T { - AR_FLAG_TERMINATE = 0x00, - AR_FLAG_CODE = 0x01, - AR_FLAG_FOLDER1 = 0x02, - AR_FLAG_FOLDER2 = 0x06, - AR_FLAG_MASTER = 0x11 + AR_FLAG_TERMINATE = 0x0000, /* 0000 0000 0000 0000 */ + AR_FLAG_CODE = 0x0001, /* 0000 0000 0000 0001 */ + AR_FLAG_FOLDER = 0x0002, /* 0000 0000 0000 0010 */ + AR_FLAG_ONLYONE = 0x0004, /* 0000 0000 0000 0100 */ + AR_FLAG_ON_ALWAYS = 0x0008, /* 0000 0000 0000 1000 */ + AR_FLAG_MASTER = 0x0010, /* 0000 0000 0001 0000 */ + AR_FLAG_ON_DEFAULT = 0x8000 /* 1000 0000 0000 0000 */ } ar_flag_t; /* diff --git a/c/src/ards_game_ls.c b/c/src/ards_game_ls.c index 307c7f2..8f02879 100644 --- a/c/src/ards_game_ls.c +++ b/c/src/ards_game_ls.c @@ -179,24 +179,22 @@ int verify_code_segment( pos += 4; // Act based on flag - switch (flag) { + switch (flag & 0x03) { case AR_FLAG_CODE: - case AR_FLAG_MASTER: // All codes are 8 bytes. So n * 8. pos += 8 * num; c_found++; break; - case AR_FLAG_FOLDER1: - case AR_FLAG_FOLDER2: + case AR_FLAG_FOLDER: // ARDS doesn't allow nested folders. Cheat and avoid recursion for (j = 0; j < num; j++) { // They better be codes or else... in_flag = (ar_flag_t) (*(uint8_t *) &buf[pos ]); in_num = *(uint16_t *) &buf[pos + 2] ; - if (in_flag != AR_FLAG_CODE && in_flag != AR_FLAG_MASTER) { + if ((in_flag & 0x03) != AR_FLAG_CODE) { // Flag inside folder was not a code *err_pos = pos; return 2;