2 * IDOS Stations Extractor
4 * (c) 2013 Tomas Pokorny <jethro@kam.mff.cuni.cz>
6 * This software can be freely distributed and used according
7 * to the terms of the GNU General Public License.
21 void print_stations(uint32_t offset
)
23 fseek(in
,offset
,SEEK_SET
);
28 fread(&len
,1,sizeof(len
),in
);
29 fread(&count
,1,sizeof(count
),in
);
32 printf("Will read %d stations\n",count
);
35 indexes
= malloc(sizeof(int32_t)*(count
+1));
38 for (int i
=0;i
<count
;i
++){
39 fread(indexes
+i
,1,sizeof(int32_t),in
);
41 indexes
[count
]=indexes
[count
-1];
44 fread(&len
,1,sizeof(len
),in
);
45 fread(&foo
,1,sizeof(count
),in
);
49 buf
= malloc(sizeof(char *)*count
);
52 for (int i
=0;i
<count
;i
++){
53 str_len
= indexes
[i
+1]-indexes
[i
];
54 buf
[i
] = malloc(str_len
);
55 fread(buf
[i
],str_len
,1,in
);
58 fread(&len
,1,sizeof(len
),in
);
59 fread(&count
,1,sizeof(count
),in
);
61 mincount
= (count
<mincount
)?count
:mincount
;
64 map
= malloc(sizeof(int32_t)*count
);
65 for (int i
=0;i
<count
;i
++)
67 fread(map
+i
,1,sizeof(int32_t),in
);
70 fread(&len
,1,sizeof(len
),in
);
71 fread(&count
,1,sizeof(count
),in
);
73 mincount
= (count
<mincount
)?count
:mincount
;
76 id
= malloc(sizeof(int16_t)*count
);
77 for (int i
=0;i
<count
;i
++)
79 fread(id
+i
,1,sizeof(int16_t),in
);
82 fread(&len
,1,sizeof(len
),in
);
83 fread(&count
,1,sizeof(count
),in
);
85 fseek(in
,offset
,SEEK_SET
); //skip first letter of station
87 fread(&len
,1,sizeof(len
),in
);
88 fread(&count
,1,sizeof(count
),in
);
90 fseek(in
,offset
,SEEK_SET
); //skip second letter of station
92 fseek(in
,4,SEEK_CUR
); //null skip
94 fread(&len
,1,sizeof(len
),in
);
95 fread(&count
,1,sizeof(count
),in
);
96 mincount
= (count
<mincount
)?count
:mincount
;
99 unk1
= malloc(sizeof(int16_t)*count
);
100 for (int i
=0;i
<count
;i
++)
102 fread(unk1
+i
,1,sizeof(int16_t),in
);
105 fseek(in
,12,SEEK_CUR
); //null skip
107 fread(&len
,1,sizeof(len
),in
);
108 fread(&count
,1,sizeof(count
),in
);
109 mincount
= (count
<mincount
)?count
:mincount
;
110 printf("Count: %d\n",count
);
113 unk2
= malloc(sizeof(int16_t)*count
);
114 for (int i
=0;i
<count
;i
++)
116 fread(unk2
+i
,1,sizeof(int16_t),in
);
121 out
= fopen("tt-data/stations.dat","w");
122 for (int i
=0;i
<mincount
;i
++)
124 len
= indexes
[i
+1]-indexes
[i
];
125 fprintf(out
,"%d ",len
);
126 for (int j
=0; j
<len
;j
++)
127 fprintf(out
,"%c",buf
[i
][j
]);
128 fprintf(out
," %d %d %d %d\n",map
[i
],id
[i
],unk1
[i
],unk2
[i
]);
136 int main(int argc
, char * argv
[])
138 in
= fopen(argv
[1], "r");
143 print_stations(next
);