-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMODHierarchy.pas
425 lines (315 loc) · 8.29 KB
/
MMODHierarchy.pas
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
program MMODHierarchy;
uses dos,strutils;
var
FRec : SearchRec;
Fmmod : file;
Ftxt : text;
NbResource,
NbMesh,
NbAux,
NbGeomMesh,
NbConvexObject,
NbNote,
NbGroupParams,
NbAnimatinChannels,
NbGeom : integer;
const
PremiereRecherche : boolean = true;
Function ReadKeyWord : string;
var
LI : longint;
S : string;
begin
ReadKeyWord:=''; { valeur par défaut }
{$I-}
BlockRead(FMmod,LI,4); { lit la longueur du mot }
{$I+}
if IOResult<>0 then exit;
{$I-}
BlockRead(FMmod,S[1],LI); { lit le mot clef }
{$I+}
S[0]:=chr(LI);
if IOResult=0 then ReadKeyWord:=S; { met à jour la valeur de la fonction }
end;
Function StrMajuscule(s:string):string; { retourne la même chaine de caractère que S mais tout en majuscules }
var
i :integer;
s2 : string;
begin
S2:='';
for i:= 1 to length(s) do begin
case s[i] of
'a'..'z' : S2:=S2+chr(ord(S[i])-32);
else
S2:=S2+S[i]
end;
end;
StrMajuscule:=S2;
end;
Procedure ReadResource;
var
NbMesh : integer;
PosEnd, { position de la fin de la section Resource }
LI,
LSection,
PosNextSection : longint;
S,
KeyWord,
KeyWord2 : string;
KeyWordFound : boolean;
R : single;
begin
BlockRead(FMmod,LSection,4); { lire la longueur de la section }
PosEnd:=FilePos(FMmod)+LSection; { mémoriser la position de la fin de la section }
NbMesh:=0;
{ rechercher les 'Mesh' }
while FilePos(FMmod)<PosEnd do begin
KeyWord:=ReadKeyWord;
if KeyWord<>'' then begin
BlockRead(FMmod,LSection,4);
PosNextSection:=FilePos(FMmod)+LSection;
KeyWordFound:=false;
if (KeyWord='Mesh') or (KeyWord='MatrixIndexedMesh') then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : Mesh ',NbMesh);
inc(NbMesh);
end;
if KeyWord='Aux' then begin
KeyWordFound:=true;
while FilePos(FMmod)<PosNextSection do begin
KeyWord2:=ReadKeyWord;
if KeyWord2=('Identifier') then begin
BlockRead(FMmod,LI,4);
Write(FTxt,'Resource ',NbResource:3,' : Aux ',ReadKeyWord,' ');
BlockRead(FMmod,LI,4);
WriteLN(FTxt,LI);
Break;
end
else
begin
BlockRead(FMmod,LI,4);
Seek(FMmod,FilePos(FMmod)+LI);
end;
end;
inc(NbAux);
end;
if KeyWord='GeomMesh' then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : GeomMesh ',NbGeomMesh);
inc(NbGeomMesh);
end;
if KeyWord='ConvexObject' then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : ConvexObject ',NbConvexObject);
inc(NbConvexObject);
end;
if KeyWord='Note' then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : Note ',ReadKeyWord);
inc(NbNote);
end;
if KeyWord='GroupParams' then begin
KeyWordFound:=true;
BlockRead(FMmod,R,4);
Writeln(FTxt,'Resource ',NbResource:3,' : GroupParams ',R:14:6);
inc(NbGroupParams);
end;
if KeyWord='AnimationChannels' then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : AnimationChannels ',NbAnimatinChannels);
inc(NbAnimatinChannels);
end;
if KeyWord='Geom' then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : Geom ',NbGeom);
inc(NbGeom);
end;
if KeyWord='SceneError' then begin
KeyWordFound:=true;
Writeln(FTxt,'Resource ',NbResource:3,' : SceneError ');
end;
if KeyWordFound then begin
{ se placer sur la section suivante }
Seek(FMmod,PosNextSection);
end
else
begin
WriteLN('**************************');
Writeln(KeyWord,' UNKNOWN !!!');
WriteLN('**************************');
Writeln('Program stopped');
Writeln('Entrer to go on');
ReadLN;
halt;
end;
inc(NbResource);
end;
end;
Writeln(FTxt);
WriteLN(FTxt,'Nb Mesh : ',NbMesh);
Writeln(FTxt,'Nb GeomMesh : ',NbGeomMEsh);
WriteLN(Ftxt,'Nb Geom : ',NbGeom);
Writeln(FTxt,'Nb ConvexObject : ',NbConvexObject);
WriteLN(FTxt,'Nb Aux : ',NbAux);
WriteLN(FTxt,'Nb Note : ',NbNote);
WriteLN(FTxt,'Nb AnimatinChannels : ',NbAnimatinChannels);
WriteLN(FTxt,'Nb GroupParams : ',NbGroupParams);
end;
Procedure ReadHierarchy;
var
S : string;
i : integer;
NbItem : integer;
LI,
LSection,
NextSection,
PosEnd,
PosBeginItem,
PosEndItem : longint;
KeyWord : string;
begin
BlockRead(FMmod,LSection,4); { lire la longueur de la section }
PosEnd:=FilePos(FMmod)+LSection; { mémoriser la position de la fin de la section }
NbItem:=0;
while FilePos(FMmod)<PosEnd do begin
KeyWord:=ReadKeyWord;
if KeyWord='Item' then begin
Writeln(FTxt);
Write(FTxt,'Item ',NbItem:3,' : ');
BlockRead(FMmod,LSection,4);
PosBeginItem:=FilePos(FMmod);
PosEndItem:=FilePos(FMmod)+LSection;
{ trouver le nom de l'item }
While FilePos(FMmod)<PosEndItem do begin
if ReadKeyWord='Name' then begin
BlockRead(FMmod,LSection,4);
WriteLN(FTxt,ReadKeyWord);
Break;
end
else
begin
BlockRead(FMmod,LSection,4);
Seek(FMmod,FilePos(FMmod)+LSection);
end;
end;
{ lire les resources de l'item }
Seek(FMmod,PosBeginItem);
While FilePos(FMmod)<PosEndItem do begin
KeyWord:=ReadKeyWord;
BlockRead(FMmod,LSection,4);
NextSection:=FilePos(FMmod)+LSection;
if KeyWord='Parent' then begin
BlockRead(FMmod,LI,4);
WriteLN(FTxt,Chr(9),'Parent ',LI);
end;
if KeyWord='Resource' then begin
BlockRead(FMmod,LI,4);
Reset(FTxt);
for i:=0 to LI do ReadLN(Ftxt,S);
append(FTxt);
WriteLN(FTxt,Chr(9)+S);
end;
seek(FMmod,NextSection);
end;
inc(NbItem);
end;
end;
end;
Procedure ReadFMmod;
var
keyword : string;
LI : longint;
begin
{ initialisation des variables }
NbResource :=0;
NbMesh :=0;
NbAux :=0;
NbGeomMesh :=0;
NbConvexObject :=0;
NbNote :=0;
NbGroupParams :=0;
NbAnimatinChannels :=0;
NbGeom :=0;
if ReadKeyWord = 'MMOD' then begin
{ éjecter les deux nombres suivants }
BlockRead(FMmod,LI,4);
BlockRead(FMmod,LI,4);
{ Trouver 'Resource' }
Repeat
{ lire le mot clef }
KeyWord:=ReadKeyWord;
if KeyWord='Resource' then begin
{ Resource a été trouvé }
ReadResource;
end
else
begin
if KeyWord='Hierarchy' then begin
{ Hierarchy a été trouvé }
ReadHierarchy;
end
else
begin
{ ce n'est pas Resource }
if KeyWord<>'' then begin
{ il y a bien un mot clef - lire la longueur du block et se repositionner à la fin de celui-ci }
BlockRead(FMmod,LI,4);
Seek(FMmod,FilePos(FMmod)+LI);
end;
end;
end;
until KeyWord='';
end
else
begin
Writeln(' ================== ce fichier n''est pas au format MMOD ================ ');
ReadLN;
halt;
end;
end;
Function FindNextMmodFile(var NameF : string):boolean;
var
W : word;
i : integer;
Error : integer;
begin
if PremiereRecherche then FindFirst('*.mmod',W,FRec) else FindNext(FRec);
PremiereRecherche:=false;
Error:=DosError;
while (Error=0) and (StrMajuscule(RightStr(FRec.Name,5))<>'.MMOD') do begin
FindNext(FRec);
Error:=DosError;
end;
if Error=0 then NameF:=FRec.Name;
FindNextMmodFile:=Error=0;
end;
var
NameF : String;
NbFile : integer ; { Nb de fichiers convertis }
S : string;
begin
NbFile := 0;
while FindNextMmodFile(NameF) do begin
Writeln(NameF,' read');
assign(FMmod,NameF);
reset(FMmod,1);
NameF:=LeftStr(NameF,Length(NameF)-5);
assign(FTxt,NameF+'_Hierarchy.TXT');
Rewrite(FTxt);
ReadFMmod;
Close(FTxt);
close(FMmod);
inc(NbFile);
end;
str(NbFile,S);
WriteLN;
if NbFile=0 then
WriteLN('NO MMOD FILE FOUND !')
else
if NbFile=1 then
WriteLN('1 file read')
else
WriteLN(S+' files read');
WriteLN('Presse "ENTER" to go on.');
ReadLN(S);
end.