Skip to content

Commit 3985c89

Browse files
committed
thstd: use proper formats for th06
Turns out they are different: #80 (comment)
1 parent 6f2942c commit 3985c89

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

thstd/thstd.c

+35-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@
4141
#include "mygetopt.h"
4242

4343
unsigned int option_version;
44+
unsigned int game_version;
45+
46+
static const id_format_pair_t formats_v0_th06[] = {
47+
{ 0, "fff" },
48+
{ 1, "Cff" },
49+
{ 2, "fff" },
50+
{ 3, "SSS" },
51+
{ 4, "SSS" },
52+
{ 5, "SSS" },
53+
{ 0, NULL }
54+
};
4455

4556
/* Some of the S's here are actually colors. */
4657
static const id_format_pair_t formats_v0[] = {
@@ -128,6 +139,24 @@ static const id_format_pair_t formats_v2[] = {
128139
{ 0, NULL }
129140
};
130141

142+
static const id_format_pair_t*
143+
get_format_table(
144+
unsigned int version
145+
) {
146+
switch(version) {
147+
case 0:
148+
if (game_version == 6)
149+
return formats_v0_th06;
150+
return formats_v0;
151+
case 1:
152+
return formats_v1;
153+
case 2:
154+
return formats_v2;
155+
default:
156+
return NULL;
157+
}
158+
}
159+
131160
static thstd_t*
132161
std_read_file(
133162
FILE* in)
@@ -237,9 +266,7 @@ std_dump(
237266
std_object_instance_t *instance;
238267
std_instr_t *instr;
239268

240-
const id_format_pair_t *formats =
241-
option_version == 0 ? formats_v0 :
242-
option_version == 1 ? formats_v1 : formats_v2;
269+
const id_format_pair_t *formats = get_format_table(option_version);
243270

244271
uint16_t object_id;
245272
uint32_t time;
@@ -403,9 +430,7 @@ std_create(
403430

404431
uint32_t instr_time = 0;
405432

406-
const id_format_pair_t *formats =
407-
option_version == 0 ? formats_v0 :
408-
option_version == 1 ? formats_v1 : formats_v2;
433+
const id_format_pair_t *formats = get_format_table(option_version);
409434

410435
f = fopen(spec, "r");
411436
if (!f) {
@@ -840,7 +865,6 @@ main(
840865
argv0 = util_shortname(argv[0]);
841866
int opt;
842867
int ind=0;
843-
unsigned int version = 0;
844868
while(argv[util_optind]) {
845869
switch(opt = util_getopt(argc,argv,commands)) {
846870
case 'c':
@@ -851,7 +875,7 @@ main(
851875
exit(1);
852876
}
853877
command = opt;
854-
version = parse_version(util_optarg);
878+
game_version = parse_version(util_optarg);
855879
break;
856880
default:
857881
util_getopt_default(&ind,argv,opt,print_usage);
@@ -860,7 +884,7 @@ main(
860884
argc = ind;
861885
argv[argc] = NULL;
862886

863-
switch (version) {
887+
switch (game_version) {
864888
case 6:
865889
case 7:
866890
case 8:
@@ -888,10 +912,10 @@ main(
888912
break;
889913
default:
890914
if (command == 'c' || command == 'd') {
891-
if (version == 0)
915+
if (game_version == 0)
892916
fprintf(stderr, "%s: version must be specified\n", argv0);
893917
else
894-
fprintf(stderr, "%s: version %u is unsupported\n", argv0, version);
918+
fprintf(stderr, "%s: version %u is unsupported\n", argv0, game_version);
895919
exit(1);
896920
}
897921
}

0 commit comments

Comments
 (0)