1 #define __STORMLIB_SELF__
10 WMORoot::WMORoot(std::string
&filename
) : filename(filename
)
13 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
18 MPQFile
f(filename
.c_str());
21 printf("No such file.\n");
38 size_t nextpos
= f
.getPos() + size
;
40 if (!strcmp(fourcc
,"MOHD"))//header
43 f
.read(&nTextures
, 4);
49 f
.read(&nDoodadSets
, 4);
57 else if (!strcmp(fourcc,"MOTX"))
61 else if (!strcmp(fourcc,"MOMT"))
65 else if (!strcmp(fourcc,"MOGN"))
69 else if (!strcmp(fourcc,"MOGI"))
73 else if (!strcmp(fourcc,"MOLT"))
77 else if (!strcmp(fourcc,"MODN"))
81 else if (!strcmp(fourcc,"MODS"))
85 else if (!strcmp(fourcc,"MODD"))
89 else if (!strcmp(fourcc,"MOSB"))
93 else if (!strcmp(fourcc,"MOPV"))
97 else if (!strcmp(fourcc,"MOPT"))
101 else if (!strcmp(fourcc,"MOPR"))
105 else if (!strcmp(fourcc,"MFOG"))
110 f
.seek((int)nextpos
);
115 //---------------------------------------------------------------------------
117 bool WMORoot::ConvertToVMAPRootWmo(FILE *pOutfile
)
119 //printf("Convert RootWmo...\n");
121 fwrite("VMAP002",1,8,pOutfile
);
122 unsigned int nVectors
= 0;
123 fwrite(&nVectors
,sizeof(nVectors
),1,pOutfile
); // will be filled later
124 fwrite(&nGroups
,4,1,pOutfile
);
128 //----------------------------------------------------------------------------
132 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
134 WMOGroup::WMOGroup(std::string
&filename
) : filename(filename
)
137 //---------------------------------------------------------------------------
138 bool WMOGroup::open()
140 MPQFile
f(filename
.c_str());
143 printf("No such file.\n");
155 if (!strcmp(fourcc
,"MOGP"))//Fix sizeoff = Data size.
160 size_t nextpos
= f
.getPos() + size
;
164 if (!strcmp(fourcc
,"MOGP"))//header
180 else if (!strcmp(fourcc
,"MOPY"))
182 MOPY
= new char[size
];
184 nTriangles
= (int)size
/ 2;
187 else if (!strcmp(fourcc
,"MOVI"))
189 MOVI
= new uint16
[size
/2];
193 else if (!strcmp(fourcc
,"MOVT"))
195 MOVT
= new float[size
/4];
197 nVertices
= (int)size
/ 12;
199 else if (!strcmp(fourcc
,"MONR"))
202 else if (!strcmp(fourcc
,"MOTV"))
205 else if (!strcmp(fourcc
,"MOBA"))
207 MOBA
= new uint16
[size
/2];
211 else if (!strcmp(fourcc
,"MLIQ"))
217 hlq_xverts
= hlq
.xverts
;
218 hlq_yverts
= hlq
.yverts
;
219 int noVer
= hlq
.xverts
* hlq
.yverts
;
220 float tilesize
= CHUNKSIZE
/ 8.0f
;
221 LiquEx_size
= sizeof(float) * 3 * noVer
;
222 LiquEx
= new float[sizeof(float) * 3 * noVer
];
225 for (int j
=0; j
<hlq
.yverts
; j
++)
227 for (int i
=0; i
<hlq
.xverts
; i
++)
229 LiquEx
[p
++] = hlq
.pos_x
+ tilesize
* i
;
230 LiquEx
[p
++] = hlq
.pos_z
;
231 LiquEx
[p
++] = ydir
* (hlq
.pos_y
+ tilesize
* j
);
236 f
.seek((int)nextpos
);
241 //----------------------------------------------------------------------------
242 int WMOGroup::ConvertToVMAPGroupWmo(FILE *output
, bool pPreciseVectorData
)
244 if(pPreciseVectorData
) {
245 fwrite(&liquflags
,sizeof(uint32
),1,output
);
247 fwrite(GRP
,1,4,output
);
250 int moba_batch
= moba_size
/12;
251 MobaEx
= new int[moba_batch
*4];
252 for(int i
=8; i
<moba_size
; i
+=12)
254 MobaEx
[k
++] = MOBA
[i
];
257 int moba_size_grp
= moba_batch
*4+4;
258 fwrite(&moba_size_grp
,4,1,output
);
259 fwrite(&moba_batch
,4,1,output
);
260 fwrite(MobaEx
,4,k
,output
);
263 uint32 nIdexes
= nTriangles
* 3;
265 if(fwrite("INDX",4, 1, output
) != 1) { printf("Error while writing file nbraches ID"); exit(0); }
266 int wsize
= sizeof(uint32
) + sizeof(unsigned short) * nIdexes
;
267 if(fwrite(&wsize
, sizeof(int), 1, output
) != 1) { printf("Error while writing file wsize"); }
268 if(fwrite(&nIdexes
, sizeof(uint32
), 1, output
) != 1) { printf("Error while writing file nIndexes"); exit(0); }
270 if(fwrite(MOVI
, sizeof(unsigned short), nIdexes
, output
) != nIdexes
) { printf("Error while writing file indexarray"); exit(0); }
273 if(fwrite("VERT",4, 1, output
) != 1) { printf("Error while writing file nbraches ID"); exit(0); }
274 wsize
= sizeof(int) + sizeof(float) * 3 * nVertices
;
275 if(fwrite(&wsize
, sizeof(int), 1, output
) != 1) { printf("Error while writing file wsize"); }
276 if(fwrite(&nVertices
, sizeof(int), 1, output
) != 1) { printf("Error while writing file nVertices"); exit(0); }
278 if(fwrite(MOVT
, sizeof(float)*3, nVertices
, output
) != nVertices
) { printf("Error while writing file vectors"); exit(0); }
283 int LIQU_h
[] = {0x5551494C,LiquEx_size
+8,hlq_xverts
,hlq_yverts
};// "LIQU"
284 fwrite(LIQU_h
,4,4,output
);
285 fwrite(LiquEx
,4,LiquEx_size
/4,output
);
291 //printf("Convert GroupWmo...\n");
292 //-------GRP -------------------------------------
293 fwrite(&liquflags
,sizeof(uint32
),1,output
);
295 fwrite(GRP
,1,4,output
);
297 int moba_batch
= moba_size
/12;
298 MobaEx
= new int[moba_batch
*4];
299 for(int i
=8; i
<moba_size
; i
+=12)
301 MobaEx
[k
++] = MOBA
[i
];
304 int moba_size_grp
= moba_batch
*4+4;
305 fwrite(&moba_size_grp
,4,1,output
);
306 fwrite(&moba_batch
,4,1,output
);
307 fwrite(MobaEx
,4,k
,output
);
310 //-------INDX------------------------------------
311 //-------MOPY--------
314 MopyEx
= new char[mopy_size
];
315 IndexExTr
= new int[mopy_size
];
316 for (int i
=0; i
<mopy_size
; i
+=2)
318 if ((int)MOPY
[i
]==0x00000008 ||(int)MOPY
[i
]==0x00000009 ||(int)MOPY
[i
]==0x00000020 ||(int)MOPY
[i
]==0x00000021 ||(int)MOPY
[i
]==0x00000022 ||(int)MOPY
[i
]==0x00000048 ||(int)MOPY
[i
]==0x00000049 ||(int)MOPY
[i
]==0x00000060 ||(int)MOPY
[i
]==0x00000061 ||(int)MOPY
[i
]==0x00000062 ||(int)MOPY
[i
]==0x0000000A ||(int)MOPY
[i
]==0x0000004A)
321 MopyEx
[(n
+1)] = MOPY
[(i
+1)];
332 //---------MOVI-----------
333 MoviEx
= new uint16
[IndexExTr_size
*3];
335 for (int i
=0; i
<IndexExTr_size
; i
++)
339 for (int x
=0; x
<3; x
++)
348 MoviExSort
= new uint16
[IndexExTr_size
*3];
349 for(int y
=0; y
<IndexExTr_size
*3; y
++)
351 MoviExSort
[y
]=MoviEx
[y
];
355 for (int pass
= 1; pass
< IndexExTr_size
*3; pass
++)
357 for (int i
=0; i
< IndexExTr_size
*3-1; i
++)
359 if (MoviExSort
[i
] > MoviExSort
[i
+1])
361 hold
= MoviExSort
[i
];
362 MoviExSort
[i
] = MoviExSort
[i
+1];
363 MoviExSort
[i
+1] = hold
;
367 if (MoviExSort
[i
] == MoviExSort
[i
+1])
368 MoviExSort
[i
+1] = 65535;
373 for (int i
=0; i
< IndexExTr_size
*3; i
++)
375 if (MoviExSort
[i
]!=65535)
377 MoviExSort
[s
] = MoviExSort
[i
];
381 MovtExSort
= new uint16
[s
];
382 for (int i
=0; i
< s
; i
++)
384 MovtExSort
[i
] = MoviExSort
[i
];
387 for (int i
=0; i
< IndexExTr_size
*3; i
++)
389 uint16 b
= MoviEx
[i
];
390 for (uint16 x
= 0; x
< s
; x
++)
392 if(MoviExSort
[x
] == b
)
401 int INDX
[] = {0x58444E49,IndexExTr_size
*6+4,IndexExTr_size
*3};
402 fwrite(INDX
,4,3,output
);
403 fwrite(MoviEx
,2,IndexExTr_size
*3,output
);
406 delete [] MoviExSort
;
409 //----------VERT---------
410 //-----MOVT----------
412 MovtEx
= new float[s
*3];
413 for (uint16 i
=0; i
<s
; i
++)
415 int c
=0;//!!!!data in MovtExSort[i] more uint16 in great group wmo files!!!!
417 for (int y
=0; y
<3; y
++)
424 int VERT
[] = {0x54524556,d
*4+4,d
*4/12};// "VERT"
425 fwrite(VERT
,4,3,output
);
426 fwrite(MovtEx
,4,d
,output
);
427 //------LIQU------------------------
430 int LIQU_h
[] = {0x5551494C,LiquEx_size
+8,hlq_xverts
,hlq_yverts
};// "LIQU"
431 fwrite(LIQU_h
,4,4,output
);
432 fwrite(LiquEx
,4,LiquEx_size
/4,output
);
438 delete [] MovtExSort
;
440 //---------------------------------------------
441 return IndexExTr_size
;
445 WMOGroup::~WMOGroup()
449 WMOInstance::WMOInstance(MPQFile
&f
,const char* WmoInstName
,const char*MapName
, FILE *pDirfile
)
456 pos
= Vec3D(ff
[0],ff
[1],ff
[2]);
458 rot
= Vec3D(ff
[0],ff
[1],ff
[2]);
460 pos2
= Vec3D(ff
[0],ff
[1],ff
[2]);
462 pos3
= Vec3D(ff
[0],ff
[1],ff
[2]);
466 doodadset
= (d2
& 0xFFFF0000) >> 16;
468 int realx1
= (int) ((float) pos2
.x
/ 533.333333f
);
469 int realy1
= (int) ((float) pos2
.z
/ 533.333333f
);
470 int realx2
= (int) ((float) pos3
.x
/ 533.333333f
);
471 int realy2
= (int) ((float) pos3
.z
/ 533.333333f
);
475 realx1
+=20; realx2
+=20;
479 realy1
+=20; realy2
+=20;
480 } // hack to prevent neg. values
482 //-----------add_in _dir_file----------------
485 // const char dirname[] = "buildings\\dir";
487 sprintf(tempname
, "buildings\\%s", WmoInstName
);
489 input
= fopen(tempname
, "r+b");
494 fseek(input
, 8, SEEK_SET
); // get the correct no of vertices
496 fread(&nVertices
, sizeof (int), 1, input
);
504 dirfile = fopen(dirname, "ab");
507 printf("Can't open dirfile!'%s'\n");
515 { x
= 533.33333f
*32; z
= 533.33333f
*32; }
516 fprintf(pDirfile
,"%s/%s %f,%f,%f_%f,%f,%f 1.0 %d %d %d,%d %d\n",
519 (float) x
, (float) pos
.y
, (float) z
,
520 (float) rot
.x
, (float) rot
.y
, (float) rot
.z
,