Skip to content

Commit e5bb6cd

Browse files
author
Yuhki
committed
Update README and refactor JSON output functions in main.c
1 parent 874019e commit e5bb6cd

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## Information
44

5-
The `items.dat` file format has evolved through various versions, with changes in data structure and additional fields being introduced over time. Below is a summary of the modifications made to the data structure for each version:
5+
The `items.dat` file format has evolved through various versions, with changes in data structure and additional fields being introduced over time. Below is a summary of the modifications made to the data structure for each version (till recent update as of now):
66

77
# items.dat-decoder
88

9-
A small command-line tool and library for decoding Growtopia `items.dat` files into JSON and for working with the items schema.
9+
A small command-line tool and library for decoding Growtopia `items.dat` to `items.json`.
1010

1111
**Features**
1212
- Parse `items.dat` across multiple historical versions.

main.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ void escape_json_string(const char* input, char* output, size_t output_size) {
2727
output[j] = 0;
2828
}
2929

30+
void print_json_string_field(FILE* outf, const char* key, const char* str) {
31+
char escaped[1024];
32+
escape_json_string(str ? str : "", escaped, sizeof(escaped));
33+
fprintf(outf, " \"%s\": \"%s\",\n", key, escaped);
34+
}
35+
36+
void print_json_int_field(FILE* outf, const char* key, int value) {
37+
fprintf(outf, " \"%s\": %d,\n", key, value);
38+
}
39+
40+
void print_json_uint_field(FILE* outf, const char* key, unsigned value) {
41+
fprintf(outf, " \"%s\": %u,\n", key, value);
42+
}
43+
44+
void print_json_byte_array_field(FILE* outf, const char* key, const unsigned char* arr, size_t len) {
45+
fprintf(outf, " \"%s\": [", key);
46+
for (size_t k = 0; k < len; k++) {
47+
if (k) fprintf(outf, ", ");
48+
fprintf(outf, "%u", arr[k]);
49+
}
50+
fprintf(outf, "],\n");
51+
}
52+
3053
int main(int argc, char** argv) {
3154
ItemsDat items;
3255
itemsdat_init(&items);
@@ -96,29 +119,6 @@ int main(int argc, char** argv) {
96119
}
97120
}
98121

99-
void print_json_string_field(FILE* outf, const char* key, const char* str) {
100-
char escaped[1024];
101-
escape_json_string(str ? str : "", escaped, sizeof(escaped));
102-
fprintf(outf, " \"%s\": \"%s\",\n", key, escaped);
103-
}
104-
105-
void print_json_int_field(FILE* outf, const char* key, int value) {
106-
fprintf(outf, " \"%s\": %d,\n", key, value);
107-
}
108-
109-
void print_json_uint_field(FILE* outf, const char* key, unsigned value) {
110-
fprintf(outf, " \"%s\": %u,\n", key, value);
111-
}
112-
113-
void print_json_byte_array_field(FILE* outf, const char* key, const unsigned char* arr, size_t len) {
114-
fprintf(outf, " \"%s\": [", key);
115-
for (size_t k = 0; k < len; k++) {
116-
if (k) fprintf(outf, ", ");
117-
fprintf(outf, "%u", arr[k]);
118-
}
119-
fprintf(outf, "],\n");
120-
}
121-
122122
fprintf(outf, "{\n");
123123
fprintf(outf, " \"version\": %d,\n", items.meta.version);
124124
fprintf(outf, " \"item_count\": %d,\n", items.meta.itemCount);

0 commit comments

Comments
 (0)