-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.c
154 lines (130 loc) · 4.72 KB
/
cli.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "s3dat.h"
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#define MONITOR_MEMORY "alloc.log"
int main() {
#ifdef MONITOR_MEMORY
void* monitor_handle = s3util_get_default_ioset(S3UTIL_IOSET_LIBC)->open_func(MONITOR_MEMORY, true);
#endif
s3util_exception_t* ex = NULL;
DIR* gfx_dir = opendir("GFX");
DIR* snd_dir = opendir("SND");
if(!gfx_dir && !snd_dir) {
printf("No \"GFX\" , nor \"SND\" dir found!\n");
return 0;
}
int i = 0;
struct dirent* ent;
bool gfx = false;
while((gfx_dir && (ent = readdir(gfx_dir)) != NULL && (gfx = true)) || (snd_dir && (ent = readdir(snd_dir)) != NULL && (gfx = false))) {
if(ent->d_name[0] == '.') continue;
if(i != 0) printf("\n");
int len = strlen(ent->d_name);
char name[len+5];
if(gfx) {
name[0] = 'G';
name[1] = 'F';
name[2] = 'X';
name[3] = '/';
} else {
name[0] = 'S';
name[1] = 'N';
name[2] = 'D';
name[3] = '/';
}
strcpy(name+4, ent->d_name);
#ifdef MONITOR_MEMORY
s3dat_t* handle = s3dat_new_malloc_monitor(monitor_handle, s3util_get_default_ioset(S3UTIL_IOSET_LIBC), false);
#else
s3dat_t* handle = s3dat_new_malloc();
#endif
s3dat_readfile_name(handle, name, &ex);
printf("[%i] new file %s\n", i, name);
if(s3util_catch_exception(&ex)) {
if(s3dat_indexlen(handle, s3dat_snd) == 0) {
printf("[%i] %hu settler sequences\n", i, s3dat_indexlen(handle, s3dat_settler));
printf("[%i] %hu shadow sequences\n", i, s3dat_indexlen(handle, s3dat_shadow));
printf("[%i] %hu torso sequences\n", i, s3dat_indexlen(handle, s3dat_torso));
printf("[%i] %hu gui entries\n", i, s3dat_indexlen(handle, s3dat_gui));
printf("[%i] %hu animation entries\n", i, s3dat_indexlen(handle, s3dat_animation));
printf("[%i] %hu palette entries with %i bytes per line\n", i, s3dat_indexlen(handle, s3dat_palette), s3dat_palette_width(handle));
printf("[%i] %hu landscape entries\n", i, s3dat_indexlen(handle, s3dat_landscape));
printf("[%i] %hu string entries\n", i, s3dat_indexlen(handle, s3dat_string));
} else {
printf("[%i] %hu sound entries\n", i, s3dat_indexlen(handle, s3dat_snd));
}
}
s3dat_add_utf8_encoding(handle, &ex);
s3util_catch_exception(&ex);
/*uint16_t stringindex_len = s3dat_indexlen(handle, s3dat_string);
if(stringindex_len > 0 && false) {
for(uint32_t s = 0;s != stringindex_len;s++) {
s3dat_ref_t* strings[8];
for(uint16_t l = 0;l != 8;l++) {
strings[l] = s3dat_extract_string(handle, s, l, &ex);
if(s3util_catch_exception(&ex)) {
printf("%s", s3dat_strdata(strings[l]));
}
if(l != 7) printf("|");
}
s3dat_unref_array(strings, 8);
printf("\n");
}
}
uint16_t paletteindex_len = s3dat_indexlen(handle, s3dat_palette);
if(paletteindex_len > 0 && false) {
for(uint32_t p = 0;p != paletteindex_len;p++) {
char name[100];
snprintf(name, 100, "palette_dump-%i.data", p);
FILE* file = fopen(name, "wb");
s3dat_ref_t* bmp = s3dat_extract_palette(handle, p, &ex);
if(!s3dat_catch_exception(&ex)) {
fwrite(s3dat_bmpdata(bmp), s3dat_width(bmp)*s3dat_height(bmp), 4, file);
}
s3dat_unref(bmp);
fclose(file);
}
}
uint16_t animationindex_len = s3dat_indexlen(handle, s3dat_animation);
if(animationindex_len > 0 && false) {
for(uint32_t e = 0;e != animationindex_len;e++) {
printf("[%i] animation %i at %i\n", i, e, s3dat_indexaddr(handle, e, s3dat_animation));
s3dat_ref_t* ani_ref = s3dat_extract_animation(handle, e, &ex);
if(!s3dat_catch_exception(&ex)) {
uint16_t ani_len = 0;
for(uint16_t d = 0;d != ani_len;d++) {
s3dat_frame_t* frame = s3dat_frame(ani_ref, d);
printf("[%i] x=%hi y=%hi sfile=%hu sid=%hu sframe=%hu tfile=%hu tid=%hu tframe=%hu hfile=%hu hid=%hu flags={0x%x,0x%x}\n", i, frame->posx, frame->posy, frame->settler_file, frame->settler_id, frame->settler_frame, frame->torso_file, frame->torso_id, frame->torso_frame, frame->shadow_file, frame->shadow_id, frame->flag1, frame->flag2);
}
}
s3dat_unref(ani_ref);
}
}
uint16_t guiindex_len = s3dat_indexlen(handle, s3dat_gui);
if(guiindex_len > 0 && false) {
for(uint16_t gui = 0;gui != guiindex_len;gui++) {
s3dat_ref_t* bmp = s3dat_extract_gui(handle, gui, &ex);
if(s3util_catch_exception(&ex)) {
printf("%02hx: ", gui);
uint32_t guitype = *s3dat_gui_meta(bmp);
for(int32_t pi = 31;pi >= 0;pi--) {
printf("%i", (guitype>>pi)&1);
}
printf(" (%i)\n", guitype);
s3dat_unref(bmp);
}
}
}*/
s3dat_delete(handle);
i++;
}
if(gfx_dir) closedir(gfx_dir);
if(snd_dir) closedir(snd_dir);
#ifdef MONITOR_MEMORY
s3util_get_default_ioset(S3UTIL_IOSET_LIBC)->close_func(monitor_handle);
#endif
}