Mercurial > mm7
annotate LOD.cpp @ 730:79ad0526166c
Some data movements.
author | Nomad |
---|---|
date | Fri, 22 Mar 2013 10:52:19 +0200 |
parents | 735dab8d3c9a |
children | 700b58aac975 |
rev | line source |
---|---|
0 | 1 #include "LOD.h" |
2 #include "Render.h" | |
3 #include "Allocator.h" | |
4 #include "PaletteManager.h" | |
5 #include "Viewport.h" | |
6 #include "Log.h" | |
7 | |
8 #include "mm7_data.h" | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 LODFile_IconsBitmaps *pEvents_LOD; | |
17 LODFile_IconsBitmaps *pIcons_LOD; | |
18 LODFile_Sprites *pSprites_LOD; | |
19 LODFile_IconsBitmaps *pBitmaps_LOD; | |
20 | |
21 LODWriteableFile *pNew_LOD; | |
22 LODWriteableFile *pGames_LOD; | |
23 | |
24 | |
25 | |
26 | |
27 int _6A0CA4_lod_binary_search; // weak | |
28 int _6A0CA8_lod_unused; // weak | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 //----- (004355F7) -------------------------------------------------------- | |
35 void LODFile_IconsBitmaps::_4355F7() | |
36 { | |
37 LODFile_IconsBitmaps *v1; // esi@1 | |
38 int v2; // edi@2 | |
39 Texture *v3; // ebp@3 | |
40 struct IDirect3DTexture2 **v4; // eax@4 | |
41 struct IDirect3DTexture2 *v5; // eax@5 | |
42 struct IDirectDrawSurface **v6; // eax@7 | |
43 struct IDirectDrawSurface *v7; // eax@8 | |
44 int v8; // eax@11 | |
45 | |
46 v1 = this; | |
47 if ( this->uTexturePacksCount ) | |
48 { | |
49 v2 = this->uNumLoadedFiles - 1; | |
50 if ( v2 >= this->uNumPrevLoadedFiles ) | |
51 { | |
52 v3 = &this->pTextures[v2]; | |
53 do | |
54 { | |
55 v3->Release(); | |
56 v4 = v1->pHardwareTextures; | |
57 if ( v4 ) | |
58 { | |
59 v5 = v4[v2]; | |
60 if ( v5 ) | |
61 { | |
62 v5->Release(); | |
63 v1->pHardwareTextures[v2] = 0; | |
64 } | |
65 } | |
66 v6 = v1->pHardwareSurfaces; | |
67 if ( v6 ) | |
68 { | |
69 v7 = v6[v2]; | |
70 if ( v7 ) | |
71 { | |
72 v7->Release(); | |
73 v1->pHardwareSurfaces[v2] = 0; | |
74 } | |
75 } | |
76 --v2; | |
77 --v3; | |
78 } | |
79 while ( v2 >= v1->uNumPrevLoadedFiles ); | |
80 } | |
81 v8 = v1->uNumPrevLoadedFiles; | |
82 v1->uNumPrevLoadedFiles = 0; | |
83 v1->uNumLoadedFiles = v8; | |
84 v1->uTexturePacksCount = 0; | |
85 } | |
86 } | |
87 | |
88 //----- (004114F2) -------------------------------------------------------- | |
89 void LODFile_IconsBitmaps::_4114F2() | |
90 { | |
91 LODFile_IconsBitmaps *v1; // esi@1 | |
92 int *pTexturePacksCount; // eax@1 | |
93 int v3; // ecx@1 | |
94 int v4; // ecx@2 | |
95 int v5; // edi@3 | |
96 Texture *v6; // ebx@4 | |
97 struct IDirect3DTexture2 **v7; // eax@5 | |
98 struct IDirect3DTexture2 *v8; // eax@6 | |
99 struct IDirectDrawSurface **v9; // eax@8 | |
100 struct IDirectDrawSurface *v10; // eax@9 | |
101 int v11; // eax@12 | |
102 | |
103 v1 = this; | |
104 pTexturePacksCount = &this->uTexturePacksCount; | |
105 v3 = this->uTexturePacksCount; | |
106 if ( v3 ) | |
107 { | |
108 v4 = v3 - 1; | |
109 *pTexturePacksCount = v4; | |
110 if ( !v4 ) | |
111 { | |
112 v5 = v1->uNumLoadedFiles - 1; | |
113 if ( v5 >= v1->uNumPrevLoadedFiles ) | |
114 { | |
115 v6 = &v1->pTextures[v5]; | |
116 do | |
117 { | |
118 v6->Release(); | |
119 v7 = v1->pHardwareTextures; | |
120 if ( v7 ) | |
121 { | |
122 v8 = v7[v5]; | |
123 if ( v8 ) | |
124 { | |
125 v8->Release(); | |
126 v1->pHardwareTextures[v5] = 0; | |
127 } | |
128 } | |
129 v9 = v1->pHardwareSurfaces; | |
130 if ( v9 ) | |
131 { | |
132 v10 = v9[v5]; | |
133 if ( v10 ) | |
134 { | |
135 v10->Release(); | |
136 v1->pHardwareSurfaces[v5] = 0; | |
137 } | |
138 } | |
139 --v5; | |
140 --v6; | |
141 } | |
142 while ( v5 >= v1->uNumPrevLoadedFiles ); | |
143 } | |
144 v11 = v1->uNumPrevLoadedFiles; | |
145 v1->uNumPrevLoadedFiles = 0; | |
146 v1->uNumLoadedFiles = v11; | |
147 } | |
148 } | |
149 } | |
150 | |
151 //----- (004AC67E) -------------------------------------------------------- | |
152 int LODFile_Sprites::LoadSpriteFromFile(LODSprite *pSpriteHeader, const char *pContainer) | |
153 { | |
154 FILE *v3; // eax@1 | |
155 FILE *v4; // ebx@1 | |
156 int result; // eax@2 | |
157 LODSprite *v6; // esi@3 | |
158 LODSprite_stru0 *v7; // eax@3 | |
159 size_t v8; // ST10_4@3 | |
160 int *v9; // ebx@3 | |
161 int v10; // eax@3 | |
162 void *v11; // eax@5 | |
163 LODSprite_stru0 *v12; // eax@6 | |
164 void *v13; // ecx@6 | |
165 LODSprite_stru0 *i; // edx@6 | |
166 FILE *File; // [sp+4h] [bp-4h]@1 | |
167 void *DstBufa; // [sp+10h] [bp+8h]@4 | |
168 int Sizea; // [sp+14h] [bp+Ch]@3 | |
169 | |
170 v3 = FindContainer(pContainer, 0); | |
171 v4 = v3; | |
172 File = v3; | |
173 if ( v3 ) | |
174 { | |
175 v6 = pSpriteHeader; | |
176 fread(pSpriteHeader, 1u, 0x20u, v3); | |
177 strcpy(pSpriteHeader->pName, pContainer); | |
178 Sizea = pSpriteHeader->uSpriteSize; | |
179 v7 = (LODSprite_stru0 *)pAllocator->AllocNamedChunk(v6->pSpriteLines, 8 * v6->uHeight, v6->pName); | |
180 v8 = 8 * pSpriteHeader->uHeight; | |
181 pSpriteHeader->pSpriteLines = v7; | |
182 fread(v7, 1u, v8, v4); | |
183 v9 = &pSpriteHeader->uDecompressedSize; | |
184 v10 = pSpriteHeader->uDecompressedSize; | |
185 if ( v10 ) | |
186 { | |
187 pSpriteHeader->pDecompressedBytes = pAllocator->AllocNamedChunk( | |
188 pSpriteHeader->pDecompressedBytes, | |
189 v10, | |
190 pSpriteHeader->pName); | |
191 DstBufa = pAllocator->AllocNamedChunk(0, Sizea, pSpriteHeader->pName); | |
192 fread(DstBufa, 1u, Sizea, File); | |
193 zlib::MemUnzip(v6->pDecompressedBytes, (unsigned int *)&v6->uDecompressedSize, DstBufa, v6->uSpriteSize); | |
194 v6->uSpriteSize = *v9; | |
195 pAllocator->FreeChunk(DstBufa); | |
196 } | |
197 else | |
198 { | |
199 v11 = pAllocator->AllocNamedChunk(pSpriteHeader->pDecompressedBytes, Sizea, pSpriteHeader->pName); | |
200 pSpriteHeader->pDecompressedBytes = v11; | |
201 fread(v11, 1u, Sizea, File); | |
202 } | |
203 v12 = v6->pSpriteLines; | |
204 v13 = v6->pDecompressedBytes; | |
205 for ( i = &v12[v6->uHeight]; v12 < i; i = &v6->pSpriteLines[v6->uHeight] ) | |
206 { | |
207 v12->ptr_4 = (char *)v12->ptr_4 + (unsigned int)v13; | |
208 ++v12; | |
209 } | |
210 result = 1; | |
211 } | |
212 else | |
213 { | |
214 result = -1; | |
215 } | |
216 return result; | |
217 } | |
218 | |
219 //----- (004AC795) -------------------------------------------------------- | |
220 bool LODFile_Sprites::LoadSprites(const char *pFilename) | |
221 { | |
222 if (LoadHeader(pFilename, 1)) | |
223 return false; | |
224 else | |
225 return LoadSubIndices("sprites08") == 0; | |
226 } | |
227 | |
228 //----- (004AC7C0) -------------------------------------------------------- | |
229 int LODFile_Sprites::LoadSprite(const char *pContainerName, unsigned int uPaletteID) | |
670 | 230 { |
231 | |
232 FILE *sprite_file; // eax@12 | |
233 LODSprite temp_sprite_hdr; // [sp+Ch] [bp-3Ch]@12 | |
234 int i, sprite_indx; | |
235 | |
236 //find if already loaded | |
237 if ( pRenderer->pRenderD3D ) | |
238 { | |
239 for (i=0; i<uNumLoadedSprites;++i) | |
240 { | |
241 if (!(_strcmpi(pHardwareSprites[i].pName, pContainerName))) | |
242 return i; | |
243 } | |
244 } | |
245 else | |
246 { | |
247 for (i=0; i<uNumLoadedSprites;++i) | |
248 { | |
249 if (!(_strcmpi(pSpriteHeaders[i].pName, pContainerName))) | |
250 return i; | |
251 } | |
252 } | |
253 | |
700
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
254 if (uNumLoadedSprites >= 1500 ) |
670 | 255 return -1; |
256 //if not loaded - load from file | |
0 | 257 |
670 | 258 if ( pRenderer->pRenderD3D && field_ECAC ) |
259 { | |
260 if ( !pHardwareSprites ) | |
261 { | |
262 pHardwareSprites = (Sprite *)pAllocator->AllocNamedChunk(0, 1500*sizeof(Sprite) , "hardSprites");//0xEA60u | |
263 for (i=0; i<1500;++i) | |
264 { | |
265 pHardwareSprites[i].pName=NULL; | |
266 pHardwareSprites[i].pTextureSurface=NULL; | |
267 pHardwareSprites[i].pTexture=NULL; | |
268 } | |
269 } | |
270 temp_sprite_hdr.uHeight = 0; | |
271 temp_sprite_hdr.uPaletteId = 0; | |
272 temp_sprite_hdr.word_1A = 0; | |
273 temp_sprite_hdr.pSpriteLines = 0; | |
274 temp_sprite_hdr.pDecompressedBytes = 0; | |
275 sprite_file = FindContainer(pContainerName, 0); | |
276 if ( !sprite_file ) | |
277 return -1; | |
700
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
278 //fread(&temp_sprite_hdr, 1, sizeof(LODSprite), sprite_file); |
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
279 fread(&temp_sprite_hdr, 1, 0x20, sprite_file); |
670 | 280 pHardwareSprites[uNumLoadedSprites].uBufferWidth = temp_sprite_hdr.uWidth; |
281 pHardwareSprites[uNumLoadedSprites].uBufferHeight = temp_sprite_hdr.uHeight; | |
282 pSpriteHeaders[uNumLoadedSprites].uWidth = temp_sprite_hdr.uWidth; | |
283 pSpriteHeaders[uNumLoadedSprites].uHeight = temp_sprite_hdr.uHeight; | |
284 } | |
285 else | |
286 { | |
287 sprite_indx = LoadSpriteFromFile( &pSpriteHeaders[uNumLoadedSprites], pContainerName); | |
288 pSpriteHeaders[uNumLoadedSprites].word_1A = 0; | |
289 | |
290 if ( sprite_indx != -1 ) | |
291 { | |
292 pSpriteHeaders[uNumLoadedSprites].uPaletteId = pPaletteManager->LoadPalette(pSpriteHeaders[uNumLoadedSprites].uPaletteId); | |
293 } | |
294 else | |
295 { | |
296 if ( uNumLoadedSprites<=0 ) | |
297 uNumLoadedSprites=0; | |
298 else | |
299 { | |
300 for (i=0; i<uNumLoadedSprites;++i) | |
301 { | |
302 if (!(_strcmpi(pSpriteHeaders[i].pName, "pending"))) | |
303 return i; | |
304 } | |
305 } | |
306 if ( LoadSpriteFromFile(&pSpriteHeaders[uNumLoadedSprites], "pending") == -1 ) | |
307 return -1; | |
308 pSpriteHeaders[uNumLoadedSprites].uPaletteId = pPaletteManager->LoadPalette(pSpriteHeaders[uNumLoadedSprites].uPaletteId); | |
309 } | |
310 } | |
311 | |
0 | 312 if ( pRenderer->pRenderD3D ) |
670 | 313 { |
314 pHardwareSprites[uNumLoadedSprites].pName = (const char *)pAllocator->AllocNamedChunk(pHardwareSprites[uNumLoadedSprites].pName, 20, pContainerName); | |
315 strcpy((char *)pHardwareSprites[uNumLoadedSprites].pName, pContainerName); | |
316 pHardwareSprites[uNumLoadedSprites].uPaletteID = uPaletteID; | |
317 pRenderer->MoveSpriteToDevice(&pHardwareSprites[uNumLoadedSprites]); | |
318 } | |
319 ++uNumLoadedSprites; | |
320 return uNumLoadedSprites - 1; | |
321 | |
322 } | |
0 | 323 |
324 //----- (004ACADA) -------------------------------------------------------- | |
325 void LODFile_Sprites::ReleaseLostHardwareSprites() | |
326 { | |
327 LODFile_Sprites *v1; // esi@1 | |
328 signed int v2; // ebx@2 | |
329 int v3; // edi@3 | |
330 IDirectDrawSurface *v4; // eax@4 | |
331 IDirect3DTexture2 *v5; // eax@6 | |
332 IDirectDrawSurface *v6; // ST00_4@8 | |
333 | |
334 v1 = this; | |
335 if ( this->pHardwareSprites ) | |
336 { | |
337 v2 = 0; | |
338 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
339 { | |
340 v3 = 0; | |
341 do | |
342 { | |
343 v4 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface; | |
344 if ( v4 && v4->IsLost() == DDERR_SURFACELOST ) | |
345 { | |
346 v5 = v1->pHardwareSprites[v3].pTexture; | |
347 if ( v5 ) | |
348 { | |
349 v5->Release(); | |
350 v1->pHardwareSprites[v3].pTexture = 0; | |
351 } | |
352 v6 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface; | |
353 v6->Release(); | |
354 v1->pHardwareSprites[v3].pTextureSurface = 0; | |
355 pRenderer->MoveSpriteToDevice(&v1->pHardwareSprites[v3]); | |
356 } | |
357 ++v2; | |
358 ++v3; | |
359 } | |
360 while ( v2 < (signed int)v1->uNumLoadedSprites ); | |
361 } | |
362 } | |
363 } | |
364 | |
365 //----- (004ACB70) -------------------------------------------------------- | |
366 void LODFile_Sprites::ReleaseAll() | |
367 { | |
368 LODFile_Sprites *v1; // esi@1 | |
369 signed int v2; // ebx@2 | |
370 int v3; // edi@3 | |
371 Sprite *v4; // eax@4 | |
372 IDirect3DTexture2 *v5; // eax@5 | |
373 Sprite *v6; // eax@7 | |
374 IDirectDrawSurface *v7; // eax@8 | |
375 | |
376 v1 = this; | |
377 if ( this->pHardwareSprites ) | |
378 { | |
379 v2 = 0; | |
380 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
381 { | |
382 v3 = 0; | |
383 do | |
384 { | |
385 v4 = v1->pHardwareSprites; | |
386 if ( v4 ) | |
387 { | |
388 v5 = v4[v3].pTexture; | |
389 if ( v5 ) | |
390 { | |
391 v5->Release(); | |
392 v1->pHardwareSprites[v3].pTexture = 0; | |
393 } | |
394 v6 = v1->pHardwareSprites; | |
395 if ( v6 ) | |
396 { | |
397 v7 = (IDirectDrawSurface *)v6[v3].pTextureSurface; | |
398 if ( v7 ) | |
399 { | |
400 v7->Release(); | |
401 v1->pHardwareSprites[v3].pTextureSurface = 0; | |
402 } | |
403 } | |
404 } | |
405 ++v2; | |
406 ++v3; | |
407 } | |
408 while ( v2 < (signed int)v1->uNumLoadedSprites ); | |
409 } | |
410 } | |
411 } | |
412 | |
413 //----- (004ACBE0) -------------------------------------------------------- | |
414 void LODFile_Sprites::MoveSpritesToVideoMemory() | |
415 { | |
416 LODFile_Sprites *v1; // esi@1 | |
417 int v2; // ebx@1 | |
418 signed int v3; // edi@2 | |
419 | |
420 v1 = this; | |
421 v2 = 0; | |
422 if ( this->pHardwareSprites ) | |
423 { | |
424 v3 = 0; | |
425 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
426 { | |
427 do | |
428 { | |
429 pRenderer->MoveSpriteToDevice(&v1->pHardwareSprites[v2]); | |
430 ++v3; | |
431 ++v2; | |
432 } | |
433 while ( v3 < (signed int)v1->uNumLoadedSprites ); | |
434 } | |
435 } | |
436 } | |
437 | |
438 //----- (004ACC38) -------------------------------------------------------- | |
439 int LODSprite::_4ACC38(RenderBillboardTransform_local0 *a2, char a3) | |
440 { | |
441 RenderBillboardTransform_local0 *v3; // edi@1 | |
442 int result; // eax@1 | |
443 int v5; // esi@2 | |
444 int v6; // ST18_4@2 | |
445 signed int v7; // eax@2 | |
446 signed int v8; // ebx@2 | |
447 int v9; // ebx@2 | |
448 int *v10; // ecx@2 | |
449 int v11; // esi@2 | |
450 unsigned int v12; // edx@4 | |
451 int v13; // esi@13 | |
452 int v14; // esi@17 | |
453 int v15; // ecx@17 | |
454 char *v16; // edx@17 | |
455 int v17; // esi@17 | |
456 int v18; // ecx@18 | |
457 int v19; // esi@18 | |
458 LODSprite_stru0 *v20; // edx@21 | |
459 int v21; // eax@22 | |
460 int v22; // esi@22 | |
461 int v23; // eax@25 | |
462 int v24; // ecx@25 | |
463 signed __int64 v25; // qtt@27 | |
464 int v26; // eax@27 | |
465 unsigned __int16 *v27; // eax@29 | |
466 LODSprite_stru0 *v28; // edx@29 | |
467 signed int v29; // ecx@30 | |
468 int v30; // ecx@37 | |
469 int v31; // ecx@38 | |
470 signed int v32; // ecx@41 | |
471 int v33; // ecx@47 | |
472 int v34; // ecx@56 | |
473 int v35; // esi@58 | |
474 __int16 v36; // ax@58 | |
475 int v37; // ecx@59 | |
476 int v38; // eax@59 | |
477 int v39; // ecx@62 | |
478 signed int v40; // ST30_4@64 | |
479 signed __int64 v41; // qtt@64 | |
480 int v42; // ecx@64 | |
481 unsigned __int16 *v43; // eax@66 | |
482 LODSprite_stru0 *v44; // ecx@66 | |
483 int v45; // edx@69 | |
484 int v46; // edx@77 | |
485 unsigned __int16 *pTarget; // [sp+Ch] [bp-50h]@2 | |
486 signed int v48; // [sp+10h] [bp-4Ch]@2 | |
487 signed int v49; // [sp+14h] [bp-48h]@2 | |
488 int v50; // [sp+14h] [bp-48h]@19 | |
489 int v51; // [sp+14h] [bp-48h]@57 | |
490 int v52; // [sp+18h] [bp-44h]@13 | |
491 int v53; // [sp+1Ch] [bp-40h]@2 | |
492 int v54; // [sp+1Ch] [bp-40h]@22 | |
493 int v55; // [sp+1Ch] [bp-40h]@32 | |
494 int v56; // [sp+1Ch] [bp-40h]@69 | |
495 int v57; // [sp+20h] [bp-3Ch]@2 | |
496 int v58; // [sp+24h] [bp-38h]@1 | |
497 int v59; // [sp+28h] [bp-34h]@2 | |
498 int v60; // [sp+28h] [bp-34h]@13 | |
499 unsigned __int16 *v61; // [sp+2Ch] [bp-30h]@2 | |
500 int v62; // [sp+30h] [bp-2Ch]@2 | |
501 void *v63; // [sp+30h] [bp-2Ch]@29 | |
502 void *v64; // [sp+30h] [bp-2Ch]@66 | |
503 int v65; // [sp+34h] [bp-28h]@2 | |
504 int v66; // [sp+34h] [bp-28h]@22 | |
505 int v67; // [sp+34h] [bp-28h]@59 | |
506 int v68; // [sp+38h] [bp-24h]@13 | |
507 unsigned int v69; // [sp+3Ch] [bp-20h]@2 | |
508 int v70; // [sp+40h] [bp-1Ch]@2 | |
509 signed int v71; // [sp+40h] [bp-1Ch]@15 | |
510 int v72; // [sp+44h] [bp-18h]@2 | |
511 unsigned __int16 *v73; // [sp+44h] [bp-18h]@29 | |
512 unsigned __int16 *v74; // [sp+44h] [bp-18h]@66 | |
513 int v75; // [sp+48h] [bp-14h]@4 | |
514 int v76; // [sp+48h] [bp-14h]@22 | |
515 int v77; // [sp+48h] [bp-14h]@59 | |
516 LODSprite *v78; // [sp+4Ch] [bp-10h]@1 | |
517 int v79; // [sp+50h] [bp-Ch]@4 | |
518 int v80; // [sp+50h] [bp-Ch]@21 | |
519 int v81; // [sp+50h] [bp-Ch]@62 | |
520 int v82; // [sp+50h] [bp-Ch]@67 | |
521 int v83; // [sp+50h] [bp-Ch]@75 | |
522 int *pTargetZ; // [sp+54h] [bp-8h]@4 | |
523 int v85; // [sp+58h] [bp-4h]@18 | |
524 int v86; // [sp+58h] [bp-4h]@56 | |
525 signed int v87; // [sp+64h] [bp+8h]@2 | |
526 int v88; // [sp+68h] [bp+Ch]@18 | |
527 int v89; // [sp+68h] [bp+Ch]@56 | |
528 | |
529 v3 = a2; | |
530 v78 = this; | |
144
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
531 result = a2->_screenspace_x_scaler_packedfloat; |
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
532 v58 = a2->_screenspace_x_scaler_packedfloat; |
0 | 533 if ( result <= 0 ) |
534 return result; | |
144
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
535 v5 = a2->_screenspace_y_scaler_packedfloat; |
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
536 v6 = a2->_screenspace_x_scaler_packedfloat; |
0 | 537 v87 = (signed __int64)0x100000000ui64 / result; |
538 v48 = (signed __int64)0x100000000ui64 / result; | |
539 v62 = (signed __int64)0x100000000ui64 / v5; | |
540 v7 = this->uHeight; | |
541 v8 = (signed int)((signed __int64)0x100000000ui64 / v5) >> 1; | |
542 v53 = v8; | |
543 v70 = (this->uHeight << 16) - v8; | |
544 v49 = v7; | |
545 v69 = v3->uTargetPitch; | |
546 pTarget = v3->pTarget; | |
547 v57 = v3->sZValue; | |
548 v61 = v3->pPalette; | |
549 v9 = (v6 * this->uWidth + 32768) >> 16; | |
550 v72 = v3->uScreenSpaceY; | |
551 result = (v5 * v7 + 32768) >> 16; | |
552 v10 = (int *)(v72 - result + 1); | |
553 v11 = v3->uScreenSpaceX - (v9 >> 1) + 1; | |
554 v65 = v72 - result + 1; | |
555 v59 = v11 + v9 - 1; | |
556 if ( BYTE1(v3->uFlags) & 8 ) | |
557 { | |
558 v10 = (int *)((char *)v10 + (v49 >> 1)); | |
559 v72 += v49 >> 1; | |
560 v65 = (int)v10; | |
561 } | |
562 v12 = v72; | |
563 pTargetZ = v10; | |
564 v75 = v3->uScreenSpaceX - (v9 >> 1) + 1; | |
565 v79 = v11 + v9 - 1; | |
566 if ( !(v3->uFlags & 8) ) | |
567 { | |
568 if ( v65 < (signed int)v3->uViewportY ) | |
569 pTargetZ = (int *)v3->uViewportY; | |
570 if ( v72 > (signed int)v3->uViewportW ) | |
571 v12 = v3->uViewportW; | |
572 if ( v11 < (signed int)v3->uViewportX ) | |
573 v75 = v3->uViewportX; | |
574 if ( v59 > (signed int)v3->uViewportZ ) | |
575 v79 = v3->uViewportZ; | |
576 } | |
577 v68 = v75 - v11; | |
578 v13 = -v62; | |
579 v60 = v59 - v79; | |
580 v52 = -v62; | |
581 if ( v3->uFlags & 1 ) | |
582 { | |
583 v13 = v62; | |
584 v70 = v53; | |
585 v52 = v62; | |
586 } | |
587 v71 = v13 * (v72 - v12) + v70; | |
588 if ( LOBYTE(viewparams->field_20) ) | |
589 { | |
590 if ( a3 ) | |
591 return result; | |
592 } | |
593 v14 = 5 * v12; | |
594 v15 = v69 * v12; | |
595 result = v12 - v72 + result - 1; | |
596 v16 = (char *)pTargetZ - v65; | |
597 v17 = v14 << 7; | |
598 if ( v3->uFlags & 4 ) | |
599 { | |
600 v34 = v79 + v15; | |
601 v89 = v34; | |
602 v86 = v79 + v17; | |
603 if ( result < (signed int)v16 ) | |
604 return result; | |
605 v51 = result - (int)v16 + 1; | |
606 while ( 1 ) | |
607 { | |
608 v35 = v71 >> 16; | |
609 v36 = LOWORD(v78->pSpriteLines[v35].dword_0); | |
610 if ( v36 == -1 ) | |
611 { | |
612 v34 -= v69; | |
613 v89 = v34; | |
614 goto LABEL_84; | |
615 } | |
616 v37 = v9 - ((unsigned __int64)(v36 * (signed __int64)v58) >> 16); | |
617 v67 = v87 * ((unsigned __int64)(LOWORD(v78->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16); | |
618 v38 = v9 - v60; | |
619 v77 = v9 - v60; | |
620 if ( v9 - v60 <= (signed int)(v9 | |
621 - ((unsigned __int64)(HIWORD(v78->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16)) | |
622 || v68 >= v37 ) | |
623 { | |
624 v89 -= v69; | |
625 v34 = v89; | |
626 LABEL_84: | |
627 v86 -= 640; | |
628 goto LABEL_85; | |
629 } | |
630 if ( v38 < v37 ) | |
631 { | |
632 v81 = (v87 >> 1) + v87 * (v37 - v38); | |
633 } | |
634 else | |
635 { | |
636 v77 = v37; | |
637 v81 = v87 >> 1; | |
638 v39 = v37 - v9; | |
639 v89 += v39 + v60; | |
640 v86 += v60 + v39; | |
641 } | |
642 v40 = ((HIWORD(v78->pSpriteLines[v35].dword_0) + 1) << 16) - v81 - v67; | |
643 LODWORD(v41) = v40 << 16; | |
644 HIDWORD(v41) = v40 >> 16; | |
645 v42 = v77 - (((signed int)((unsigned __int64)(v41 / v48) - 32768) >> 16) + 1); | |
646 if ( v68 >= v42 ) | |
647 v42 = v68; | |
648 v43 = &pTarget[v89]; | |
649 v74 = &v43[v42 - v77 + 1]; | |
650 v44 = &v78->pSpriteLines[v35]; | |
651 v64 = v44->ptr_4; | |
652 if ( !v57 ) | |
653 { | |
654 v83 = v67 + v81; | |
655 if ( ((v83 - (LOWORD(v44->dword_0) << 16)) & 0xFFFF0000) < 0 ) | |
656 { | |
657 v83 += v87; | |
658 --v43; | |
659 --pTargetZ; | |
660 } | |
661 while ( v43 >= v74 ) | |
662 { | |
663 v46 = (v83 - ((signed int)LOWORD(v78->pSpriteLines[v35].dword_0) << 16)) >> 16; | |
664 if ( *((char *)v64 + v46) ) | |
665 *v43 = v61[*((char *)v64 + v46)]; | |
666 v83 += v87; | |
667 --v43; | |
668 } | |
669 goto LABEL_81; | |
670 } | |
671 pTargetZ = &v3->pTargetZ[v86]; | |
672 v82 = v67 + v81; | |
673 if ( ((v82 - (LOWORD(v44->dword_0) << 16)) & 0xFFFF0000) < 0 ) | |
674 goto LABEL_72; | |
675 LABEL_73: | |
676 if ( v43 >= v74 ) | |
677 break; | |
678 LABEL_81: | |
679 v89 += v9 - v77 - v60 - v69; | |
680 v34 = v89; | |
681 v86 = v86 + v9 - v77 - v60 - 640; | |
682 LABEL_85: | |
683 result = v52; | |
684 v71 += v52; | |
685 --v51; | |
686 if ( !v51 ) | |
687 return result; | |
688 } | |
689 v45 = (v82 - ((signed int)LOWORD(v78->pSpriteLines[v35].dword_0) << 16)) >> 16; | |
690 v56 = *((char *)v64 + v45); | |
691 if ( *((char *)v64 + v45) && v57 <= (unsigned int)*pTargetZ ) | |
692 { | |
693 *pTargetZ = v57; | |
694 *v43 = v61[v56]; | |
695 } | |
696 LABEL_72: | |
697 v82 += v87; | |
698 --v43; | |
699 --pTargetZ; | |
700 goto LABEL_73; | |
701 } | |
702 v18 = v75 + v15; | |
703 v19 = v75 + v17; | |
704 v88 = v18; | |
705 v85 = v19; | |
706 if ( result >= (signed int)v16 ) | |
707 { | |
708 v50 = result - (int)v16 + 1; | |
709 while ( 1 ) | |
710 { | |
711 v20 = &v78->pSpriteLines[v71 >> 16]; | |
712 v80 = v71 >> 16; | |
713 if ( LOWORD(v20->dword_0) != -1 ) | |
714 break; | |
715 v18 -= v69; | |
716 v85 = v19 - 640; | |
717 v88 = v18; | |
718 LABEL_54: | |
719 result = v52; | |
720 v71 += v52; | |
721 --v50; | |
722 if ( !v50 ) | |
723 return result; | |
724 v19 = v85; | |
725 } | |
726 v21 = (v58 * LOWORD(v20->dword_0) + 32768) >> 16; | |
727 v66 = v21 * v87; | |
728 v76 = v68; | |
729 v54 = HIWORD(v20->dword_0); | |
730 v22 = v9 - v60; | |
731 if ( v68 >= (v58 * v54 + 32768) >> 16 || v22 <= v21 ) | |
732 { | |
733 v88 -= v69; | |
734 v85 -= 640; | |
735 goto LABEL_51; | |
736 } | |
737 if ( v68 > v21 ) | |
738 { | |
739 v24 = (v87 >> 1) + v87 * (v68 - v21); | |
740 } | |
741 else | |
742 { | |
743 v76 = (v58 * LOWORD(v20->dword_0) + 32768) >> 16; | |
744 v23 = v21 - v68; | |
745 v88 += v23; | |
746 v24 = v87 >> 1; | |
747 v85 += v23; | |
748 } | |
749 LODWORD(v25) = (((v54 + 1) << 16) - v24 - v66) << 16; | |
750 HIDWORD(v25) = (((v54 + 1) << 16) - v24 - v66) >> 16; | |
751 v26 = v76 + ((signed int)(v25 / v48) >> 16) + 1; | |
752 if ( v22 > v26 ) | |
753 v22 = v26; | |
754 v27 = &pTarget[v88]; | |
755 v73 = &v27[v22 - v76 - 1]; | |
756 v28 = &v78->pSpriteLines[v80]; | |
757 v63 = v28->ptr_4; | |
758 if ( v57 ) | |
759 { | |
760 pTargetZ = &v3->pTargetZ[v85]; | |
761 v29 = v66 - (LOWORD(v28->dword_0) << 16) + v24; | |
762 if ( (v29 & 0xFFFF0000) >= 0 ) | |
763 goto LABEL_36; | |
764 while ( 1 ) | |
765 { | |
766 v29 += v87; | |
767 ++v27; | |
768 ++pTargetZ; | |
769 LABEL_36: | |
770 if ( v27 >= v73 ) | |
771 break; | |
772 v55 = *((char *)v63 + (v29 >> 16)); | |
773 if ( *((char *)v63 + (v29 >> 16)) && v57 <= (unsigned int)*pTargetZ ) | |
774 { | |
775 *pTargetZ = v57; | |
776 *v27 = v61[v55]; | |
777 } | |
778 } | |
779 v30 = v29 >> 16; | |
780 if ( v30 > HIWORD(v78->pSpriteLines[v80].dword_0) - (signed int)LOWORD(v78->pSpriteLines[v80].dword_0) | |
781 || (v31 = *((char *)v63 + v30)) == 0 | |
782 || v57 > (unsigned int)*pTargetZ ) | |
783 goto LABEL_50; | |
784 *pTargetZ = v57; | |
785 } | |
786 else | |
787 { | |
788 v32 = v66 - (LOWORD(v28->dword_0) << 16) + v24; | |
789 if ( (v32 & 0xFFFF0000) < 0 ) | |
790 { | |
791 v32 += v87; | |
792 ++v27; | |
793 ++pTargetZ; | |
794 } | |
795 while ( v27 < v73 ) | |
796 { | |
797 if ( *((char *)v63 + (v32 >> 16)) ) | |
798 *v27 = v61[*((char *)v63 + (v32 >> 16))]; | |
799 v32 += v87; | |
800 ++v27; | |
801 } | |
802 v33 = v32 >> 16; | |
803 if ( v33 > HIWORD(v78->pSpriteLines[v80].dword_0) - (signed int)LOWORD(v78->pSpriteLines[v80].dword_0) | |
804 || (v31 = *((char *)v63 + v33)) == 0 ) | |
805 goto LABEL_50; | |
806 } | |
807 *v27 = v61[v31]; | |
808 LABEL_50: | |
809 v88 += v68 - v76 - v69; | |
810 v85 = v85 + v68 - v76 - 640; | |
811 LABEL_51: | |
812 v18 = v88; | |
813 goto LABEL_54; | |
814 } | |
815 return result; | |
816 } | |
817 | |
818 //----- (004AD2D1) -------------------------------------------------------- | |
819 int LODSprite::_4AD2D1(struct RenderBillboardTransform_local0 *a2, int a3) | |
820 { | |
821 int result; // eax@1 | |
822 unsigned int v4; // esi@1 | |
823 int v5; // edi@1 | |
824 LODSprite_stru0 *v6; // edx@2 | |
825 __int16 v7; // bx@2 | |
826 int v8; // ecx@3 | |
827 unsigned __int16 *v9; // esi@3 | |
828 int v10; // ebx@3 | |
829 void *v11; // edx@3 | |
830 unsigned __int16 *v12; // ecx@3 | |
831 int v13; // ebx@4 | |
832 LODSprite *v14; // [sp+8h] [bp-10h]@1 | |
833 unsigned __int16 *v15; // [sp+10h] [bp-8h]@1 | |
834 unsigned __int16 *v16; // [sp+14h] [bp-4h]@1 | |
835 int i; // [sp+20h] [bp+8h]@1 | |
836 | |
837 result = (int)a2; | |
838 v14 = this; | |
839 v4 = a2->uTargetPitch; | |
840 v16 = a2->pTarget; | |
841 v15 = a2->pPalette; | |
842 v5 = this->uHeight - 1; | |
843 for ( i = v4 * a2->uScreenSpaceY - (this->uWidth >> 1) + a2->uScreenSpaceX + 1; v5 >= 0; --v5 ) | |
844 { | |
845 v6 = &this->pSpriteLines[v5]; | |
846 v7 = LOWORD(v6->dword_0); | |
847 if ( LOWORD(v6->dword_0) != -1 ) | |
848 { | |
849 v8 = v7; | |
850 v9 = &v16[v7 + i]; | |
851 v10 = HIWORD(v6->dword_0); | |
852 v11 = v6->ptr_4; | |
853 v12 = &v9[v10 - v8]; | |
854 while ( v9 <= v12 ) | |
855 { | |
856 v13 = *(char *)v11; | |
857 v11 = (char *)v11 + 1; | |
858 if ( v13 ) | |
859 *v9 = v15[v13]; | |
860 ++v9; | |
861 } | |
862 v4 = *(int *)(result + 48); | |
863 //this = v14; | |
864 } | |
865 i -= v4; | |
866 } | |
867 return result; | |
868 } | |
869 | |
870 //----- (0046454B) -------------------------------------------------------- | |
871 void LODFile_IconsBitmaps::ReleaseAll2() | |
872 { | |
873 LODFile_IconsBitmaps *v1; // esi@1 | |
874 int v2; // edi@1 | |
875 Texture *v3; // ebx@2 | |
876 struct IDirect3DTexture2 **v4; // eax@3 | |
877 struct IDirect3DTexture2 *v5; // eax@4 | |
878 struct IDirectDrawSurface **v6; // eax@6 | |
879 struct IDirectDrawSurface *v7; // eax@7 | |
880 int v8; // eax@10 | |
881 | |
882 v1 = this; | |
883 v2 = this->uNumLoadedFiles - 1; | |
884 if ( v2 >= this->dword_11B84 ) | |
885 { | |
886 v3 = &this->pTextures[v2]; | |
887 do | |
888 { | |
889 v3->Release(); | |
890 v4 = v1->pHardwareTextures; | |
891 if ( v4 ) | |
892 { | |
893 v5 = v4[v2]; | |
894 if ( v5 ) | |
895 { | |
896 v5->Release(); | |
897 v1->pHardwareTextures[v2] = 0; | |
898 } | |
899 } | |
900 v6 = v1->pHardwareSurfaces; | |
901 if ( v6 ) | |
902 { | |
903 v7 = v6[v2]; | |
904 if ( v7 ) | |
905 { | |
906 v7->Release(); | |
907 v1->pHardwareSurfaces[v2] = 0; | |
908 } | |
909 } | |
910 --v2; | |
911 --v3; | |
912 } | |
913 while ( v2 >= v1->dword_11B84 ); | |
914 } | |
915 v8 = v1->dword_11B84; | |
916 v1->uTexturePacksCount = 0; | |
917 v1->uNumPrevLoadedFiles = 0; | |
918 v1->uNumLoadedFiles = v8; | |
919 } | |
920 | |
921 //----- (004645DC) -------------------------------------------------------- | |
922 void LODFile_Sprites::DeleteSomeOtherSprites() | |
923 { | |
924 int *v1; // esi@1 | |
925 int *v2; // edi@1 | |
926 | |
927 v1 = (int *)&this->uNumLoadedSprites; | |
928 v2 = &this->field_ECA0; | |
929 DeleteSpritesRange(field_ECA0, uNumLoadedSprites); | |
930 *v1 = *v2; | |
931 } | |
932 | |
933 | |
934 //----- (00461431) -------------------------------------------------------- | |
935 void LOD::File::Close() | |
936 { | |
937 LOD::File *v1; // esi@1 | |
938 LOD::Directory **v2; // edi@2 | |
939 FILE *v3; // ST00_4@2 | |
940 | |
941 v1 = this; | |
942 if ( this->isFileOpened ) | |
943 { | |
944 this->pContainerName[0] = 0; | |
945 this->uCurrentIndexDir = 0; | |
946 v2 = &this->pSubIndices; | |
947 pAllocator->FreeChunk(this->pSubIndices); | |
948 pAllocator->FreeChunk(v1->pRoot); | |
949 v3 = v1->pFile; | |
950 *v2 = 0; | |
951 v1->pRoot = 0; | |
952 fclose(v3); | |
953 v1->isFileOpened = 0; | |
954 _6A0CA8_lod_unused = 0; | |
955 } | |
956 } | |
957 | |
958 | |
959 | |
960 //----- (00461492) -------------------------------------------------------- | |
961 int LODWriteableFile::_461492(LOD::FileHeader *pHeader, LOD::Directory *pDir, const char *Source) | |
962 { | |
963 if (isFileOpened) | |
964 return 1; | |
965 if ( !pDir->pFilename[0] ) | |
966 return 2; | |
967 strcpy(pHeader->pSignature, "LOD"); | |
968 pHeader->LODSize = 100; | |
969 pHeader->uNumIndices = 1; | |
970 pDir->pFilename[15] = 0; | |
971 pDir->uDataSize = 0; | |
972 pDir->uOfsetFromSubindicesStart = 288; | |
973 strcpy(pLODName, Source); | |
974 | |
975 pFile = fopen(pLODName, "wb+"); | |
976 if (!pFile) | |
977 return 3; | |
978 | |
979 fwrite(pHeader, 0x100, 1, pFile); | |
980 fwrite(pDir, 0x20, 1, pFile); | |
981 fclose(pFile); | |
982 pFile = 0; | |
983 return 0; | |
984 } | |
985 | |
986 //----- (0046153F) -------------------------------------------------------- | |
987 void LOD::File::ResetSubIndices() | |
988 { | |
989 LOD::Directory **pSubIndices_dup2; // esi@2 | |
990 LOD::Directory *pSubIndices_dup; // ST00_4@2 | |
991 | |
992 if ( this->isFileOpened ) | |
993 { | |
994 pSubIndices_dup2 = &this->pSubIndices; | |
995 this->pContainerName[0] = 0; | |
996 this->uCurrentIndexDir = 0; | |
997 pSubIndices_dup = this->pSubIndices; | |
998 this->uOffsetToSubIndex = 0; | |
999 this->uNumSubIndices = 0; | |
1000 this->uLODDataSize = 0; | |
1001 pAllocator->FreeChunk(pSubIndices_dup); | |
1002 *pSubIndices_dup2 = 0; | |
1003 } | |
1004 } | |
1005 | |
1006 | |
1007 | |
1008 | |
1009 | |
1010 | |
1011 | |
1012 //----- (00450C8B) -------------------------------------------------------- | |
1013 void LODFile_Sprites::DeleteSomeSprites() | |
1014 { | |
1015 int *v1; // esi@1 | |
1016 int *v2; // edi@1 | |
1017 | |
1018 v1 = (int *)&this->uNumLoadedSprites; | |
1019 v2 = &this->field_ECA8; | |
1020 DeleteSpritesRange(this->field_ECA8, this->uNumLoadedSprites); | |
1021 *v1 = *v2; | |
1022 } | |
1023 | |
1024 //----- (00450CA9) -------------------------------------------------------- | |
1025 void LODFile_Sprites::DeleteSpritesRange(int uStartIndex, int uStopIndex) | |
1026 { | |
1027 LODFile_Sprites *v3; // edi@1 | |
1028 int v4; // esi@3 | |
1029 LODSprite *v5; // ebx@3 | |
1030 LODSprite *v6; // esi@7 | |
1031 int v7; // edi@7 | |
1032 int a2a; // [sp+10h] [bp+8h]@3 | |
1033 | |
1034 v3 = this; | |
1035 if ( this->pHardwareSprites ) | |
1036 { | |
1037 if ( uStartIndex < uStopIndex ) | |
1038 { | |
1039 v4 = uStartIndex; | |
1040 v5 = &this->pSpriteHeaders[uStartIndex]; | |
1041 a2a = uStopIndex - uStartIndex; | |
1042 do | |
1043 { | |
1044 v5->Release(); | |
1045 pHardwareSprites[v4].Release(); | |
1046 ++v4; | |
1047 ++v5; | |
1048 --a2a; | |
1049 } | |
1050 while ( a2a ); | |
1051 } | |
1052 } | |
1053 else | |
1054 { | |
1055 if ( uStartIndex < uStopIndex ) | |
1056 { | |
1057 v6 = &this->pSpriteHeaders[uStartIndex]; | |
1058 v7 = uStopIndex - uStartIndex; | |
1059 do | |
1060 { | |
1061 v6->Release(); | |
1062 ++v6; | |
1063 --v7; | |
1064 } | |
1065 while ( v7 ); | |
1066 } | |
1067 } | |
1068 } | |
1069 | |
1070 //----- (00450D1D) -------------------------------------------------------- | |
1071 void LODSprite::Release() | |
1072 { | |
1073 LODSprite *v1; // esi@1 | |
1074 | |
1075 v1 = this; | |
1076 if ( !(HIBYTE(this->word_1A) & 4) ) | |
1077 { | |
1078 pAllocator->FreeChunk(this->pDecompressedBytes); | |
1079 pAllocator->FreeChunk(v1->pSpriteLines); | |
1080 } | |
1081 v1->word_1A = 0; | |
1082 v1->pDecompressedBytes = 0; | |
1083 v1->pSpriteLines = 0; | |
1084 v1->pName[0] = 0; | |
1085 v1->word_16 = 0; | |
1086 v1->uPaletteId = 0; | |
1087 v1->uTexturePitch = 0; | |
1088 v1->uHeight = 0; | |
1089 v1->uWidth = 0; | |
1090 v1->uSpriteSize = 0; | |
1091 } | |
1092 | |
1093 //----- (00450D68) -------------------------------------------------------- | |
1094 void Sprite::Release() | |
1095 { | |
1096 if (pName) | |
1097 pAllocator->FreeChunk((void *)pName); | |
1098 pName = nullptr; | |
1099 | |
1100 if (pTextureSurface) | |
1101 pTextureSurface->Release(); | |
1102 pTextureSurface = nullptr; | |
1103 | |
1104 if (pTexture) | |
1105 pTexture->Release(); | |
1106 pTexture = nullptr; | |
1107 } | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 //----- (0040FA2E) -------------------------------------------------------- | |
1113 bool LODFile_IconsBitmaps::LoadBitmaps(const char *pFilename) | |
1114 { | |
1115 ReleaseAll(); | |
1116 if (LoadHeader(pFilename, 1)) | |
1117 return false; | |
1118 else | |
1119 return LoadSubIndices("bitmaps") == 0; | |
1120 } | |
1121 | |
1122 | |
1123 //----- (0040FAEE) -------------------------------------------------------- | |
1124 bool LODFile_IconsBitmaps::LoadIconsOrEvents(const char *pLODFilename) | |
1125 { | |
1126 ReleaseAll(); | |
1127 | |
1128 if (LoadHeader(pLODFilename, 1)) | |
1129 return false; | |
1130 else | |
1131 return LoadSubIndices("icons") == 0; | |
1132 } | |
1133 | |
1134 | |
1135 //----- (0040FA60) -------------------------------------------------------- | |
1136 void LODFile_IconsBitmaps::ReleaseAll() | |
1137 { | |
1138 LODFile_IconsBitmaps *v1; // esi@1 | |
1139 unsigned int v2; // edi@1 | |
1140 Texture *v3; // ebp@2 | |
1141 struct IDirect3DTexture2 **v4; // eax@3 | |
1142 struct IDirect3DTexture2 *v5; // eax@4 | |
1143 struct IDirectDrawSurface **v6; // eax@6 | |
1144 struct IDirectDrawSurface *v7; // eax@7 | |
1145 | |
1146 v1 = this; | |
1147 v2 = this->uNumLoadedFiles - 1; | |
1148 if ( (v2 & 0x80000000u) == 0 ) | |
1149 { | |
1150 v3 = &this->pTextures[v2]; | |
1151 do | |
1152 { | |
1153 v3->Release(); | |
1154 v4 = v1->pHardwareTextures; | |
1155 if ( v4 ) | |
1156 { | |
1157 v5 = v4[v2]; | |
1158 if ( v5 ) | |
1159 { | |
1160 v5->Release(); | |
1161 v1->pHardwareTextures[v2] = 0; | |
1162 } | |
1163 } | |
1164 v6 = v1->pHardwareSurfaces; | |
1165 if ( v6 ) | |
1166 { | |
1167 v7 = v6[v2]; | |
1168 if ( v7 ) | |
1169 { | |
1170 v7->Release(); | |
1171 v1->pHardwareSurfaces[v2] = 0; | |
1172 } | |
1173 } | |
1174 --v2; | |
1175 --v3; | |
1176 } | |
1177 while ( (v2 & 0x80000000u) == 0 ); | |
1178 } | |
1179 v1->uTexturePacksCount = 0; | |
1180 v1->uNumPrevLoadedFiles = 0; | |
1181 v1->dword_11B84 = 0; | |
1182 v1->dword_11B80 = 0; | |
1183 v1->uNumLoadedFiles = 0; | |
1184 } | |
1185 | |
1186 //----- (0040F9F0) -------------------------------------------------------- | |
1187 unsigned int LODFile_IconsBitmaps::FindTextureByName(const char *pName) | |
1188 { | |
1189 LODFile_IconsBitmaps *v2; // esi@1 | |
1190 unsigned int v3; // edi@1 | |
1191 Texture *v4; // ebx@2 | |
1192 unsigned int result; // eax@5 | |
1193 | |
1194 v2 = this; | |
1195 v3 = 0; | |
1196 if ( (signed int)this->uNumLoadedFiles <= 0 ) | |
1197 { | |
1198 LABEL_5: | |
1199 result = -1; | |
1200 } | |
1201 else | |
1202 { | |
1203 v4 = this->pTextures; | |
1204 while ( _strcmpi(v4->pName, pName) ) | |
1205 { | |
1206 ++v3; | |
1207 ++v4; | |
1208 if ( (signed int)v3 >= (signed int)v2->uNumLoadedFiles ) | |
1209 goto LABEL_5; | |
1210 } | |
1211 result = v3; | |
1212 } | |
1213 return result; | |
1214 } | |
1215 | |
1216 //----- (0040F9C5) -------------------------------------------------------- | |
1217 int LODFile_IconsBitmaps::_40F9C5() | |
1218 { | |
1219 signed int result; // eax@1 | |
1220 Texture *pTex; // edx@1 | |
1221 | |
1222 result = this->uNumLoadedFiles; | |
1223 for ( pTex = &this->pTextures[result]; !pTex->pName[0]; --pTex ) | |
1224 --result; | |
1225 if ( result < (signed int)this->uNumLoadedFiles ) | |
1226 { | |
1227 ++result; | |
1228 this->uNumLoadedFiles = result; | |
1229 } | |
1230 return result; | |
1231 } | |
1232 | |
1233 | |
1234 | |
1235 //----- (0046249B) -------------------------------------------------------- | |
1236 LODFile_Sprites::~LODFile_Sprites() | |
1237 { | |
1238 LODFile_Sprites *v1; // esi@1 | |
1239 signed int v2; // ebx@1 | |
1240 LODSprite *v3; // edi@3 | |
1241 char *v4; // edi@6 | |
1242 int thisa; // [sp+4h] [bp-10h]@3 | |
1243 LODSprite *thisb; // [sp+4h] [bp-10h]@7 | |
1244 | |
1245 v1 = this; | |
1246 v2 = 0; | |
1247 if ( this->pHardwareSprites ) | |
1248 { | |
1249 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
1250 { | |
1251 thisa = 0; | |
1252 v3 = this->pSpriteHeaders; | |
1253 do | |
1254 { | |
1255 v3->Release(); | |
1256 v1->pHardwareSprites[thisa].Release(); | |
1257 ++thisa; | |
1258 ++v2; | |
1259 ++v3; | |
1260 } | |
1261 while ( v2 < (signed int)v1->uNumLoadedSprites ); | |
1262 } | |
1263 } | |
1264 else | |
1265 { | |
1266 v4 = (char *)&this->uNumLoadedSprites; | |
1267 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
1268 { | |
1269 thisb = this->pSpriteHeaders; | |
1270 do | |
1271 { | |
1272 thisb->Release(); | |
1273 ++thisb; | |
1274 ++v2; | |
1275 } | |
1276 while ( v2 < *(int *)v4 ); | |
1277 } | |
1278 } | |
1279 //_eh_vector_destructor_iterator_(v1->pSpriteHeaders, 40, 1500, LODSprite::dtor); | |
1280 //LOD::File::vdtor((LOD::File *)v1); | |
1281 } | |
1282 // 4CC2B4: using guessed type int __stdcall _eh vector destructor iterator_(int, int, int, int); | |
1283 | |
1284 | |
1285 //----- (00462463) -------------------------------------------------------- | |
1286 LODSprite::~LODSprite() | |
1287 { | |
1288 LODSprite *v1; // esi@1 | |
1289 | |
1290 v1 = this; | |
1291 if ( !(HIBYTE(this->word_1A) & 4) ) | |
1292 { | |
1293 pAllocator->FreeChunk(this->pDecompressedBytes); | |
1294 pAllocator->FreeChunk(v1->pSpriteLines); | |
1295 } | |
1296 v1->pDecompressedBytes = 0; | |
1297 v1->pSpriteLines = 0; | |
1298 } | |
1299 | |
1300 //----- (004623E5) -------------------------------------------------------- | |
1301 LODFile_Sprites::LODFile_Sprites(): | |
1302 LOD::File() | |
1303 { | |
1304 /*_eh_vector_constructor_iterator_( | |
1305 v1->pSpriteHeaders, | |
1306 40, | |
1307 1500, | |
1308 (void (__thiscall *)(void *))LODSprite::LODSprite, | |
1309 (void (__thiscall *)(void *))LODSprite::dtor);*/ | |
1310 field_ECA4 = 0; | |
1311 field_ECA0 = 0; | |
1312 pHardwareSprites = 0; | |
1313 field_ECAC = 0; | |
1314 field_ECB4 = 0; | |
1315 uNumLoadedSprites = 0; | |
1316 } | |
1317 | |
1318 //----- (00462303) -------------------------------------------------------- | |
1319 LODFile_IconsBitmaps::~LODFile_IconsBitmaps() | |
1320 { | |
1321 LODFile_IconsBitmaps *v1; // esi@1 | |
1322 unsigned int v2; // edi@1 | |
1323 struct IDirect3DTexture2 **v3; // eax@3 | |
1324 struct IDirect3DTexture2 *v4; // eax@4 | |
1325 struct IDirectDrawSurface **v5; // eax@6 | |
1326 struct IDirectDrawSurface *v6; // eax@7 | |
1327 Texture *thisa; // [sp+4h] [bp-10h]@2 | |
1328 | |
1329 v1 = this; | |
1330 v2 = this->uNumLoadedFiles - 1; | |
1331 if ( (v2 & 0x80000000u) == 0 ) | |
1332 { | |
1333 thisa = &this->pTextures[v2]; | |
1334 do | |
1335 { | |
1336 thisa->Release(); | |
1337 v3 = v1->pHardwareTextures; | |
1338 if ( v3 ) | |
1339 { | |
1340 v4 = v3[v2]; | |
1341 if ( v4 ) | |
1342 { | |
1343 v4->Release(); | |
1344 v1->pHardwareTextures[v2] = 0; | |
1345 } | |
1346 } | |
1347 v5 = v1->pHardwareSurfaces; | |
1348 if ( v5 ) | |
1349 { | |
1350 v6 = v5[v2]; | |
1351 if ( v6 ) | |
1352 { | |
1353 v6->Release(); | |
1354 v1->pHardwareSurfaces[v2] = 0; | |
1355 } | |
1356 } | |
1357 --thisa; | |
1358 --v2; | |
1359 } | |
1360 while ( (v2 & 0x80000000u) == 0 ); | |
1361 } | |
1362 if ( v1->pHardwareSurfaces ) | |
1363 free(v1->pHardwareSurfaces); | |
1364 if ( v1->pHardwareTextures ) | |
1365 free(v1->pHardwareTextures); | |
1366 if ( v1->ptr_011BB4 ) | |
1367 free(v1->ptr_011BB4); | |
1368 //LOD::File::vdtor((LOD::File *)v1); | |
1369 } | |
1370 | |
1371 //----- (00462272) -------------------------------------------------------- | |
1372 LODFile_IconsBitmaps::LODFile_IconsBitmaps(): | |
1373 LOD::File() | |
1374 { | |
1375 LODFile_IconsBitmaps *v1; // esi@1 | |
1376 Texture *v2; // ebx@1 | |
1377 signed int v3; // [sp+4h] [bp-10h]@1 | |
1378 | |
1379 v1 = this; | |
1380 /*v2 = v1->pTextures; | |
1381 v3 = 1000; | |
1382 do | |
1383 { | |
1384 Texture::Texture(v2); | |
1385 ++v2; | |
1386 --v3; | |
1387 } | |
1388 while ( v3 );*/ | |
1389 v1->uTexturePacksCount = 0; | |
1390 v1->uNumPrevLoadedFiles = 0; | |
1391 v1->dword_11B84 = 0; | |
1392 v1->dword_11B80 = 0; | |
1393 v1->uNumLoadedFiles = 0; | |
1394 v1->dword_011BA4 = 0; | |
1395 v1->dword_011BA8 = 0; | |
1396 v1->pHardwareSurfaces = 0; | |
1397 v1->pHardwareTextures = 0; | |
1398 v1->ptr_011BB4 = 0; | |
1399 } | |
1400 | |
1401 | |
1402 //----- (004621A7) -------------------------------------------------------- | |
1403 bool LODWriteableFile::_4621A7() | |
1404 { | |
1405 CloseWriteFile(); | |
1406 return LoadFile(pLODName, 0); | |
1407 } | |
1408 | |
1409 | |
1410 //----- (00461FD4) -------------------------------------------------------- | |
1411 int LODWriteableFile::Save() | |
1412 { | |
1413 LODWriteableFile *v1; // esi@1 | |
1414 int v2; // edi@1 | |
1415 unsigned int v3; // edx@1 | |
1416 LOD::Directory *v4; // eax@2 | |
1417 unsigned int v5; // ecx@2 | |
1418 int v6; // eax@2 | |
1419 signed int v7; // ebx@5 | |
1420 int v8; // ecx@5 | |
1421 LOD::Directory **v9; // edi@6 | |
1422 int v10; // edx@6 | |
1423 LOD::Directory *v11; // eax@6 | |
1424 FILE *v12; // eax@9 | |
1425 FILE *v13; // ebx@9 | |
1426 signed int result; // eax@10 | |
1427 unsigned int v15; // eax@11 | |
1428 FILE *v16; // ST00_4@11 | |
1429 size_t v17; // edi@12 | |
1430 char OldFilename[256]; // [sp+Ch] [bp-228h]@9 | |
1431 char NewFilename[256]; // [sp+10Ch] [bp-128h]@15 | |
1432 //LOD::Directory v0; // [sp+20Ch] [bp-28h]@11 | |
1433 unsigned int v21; // [sp+22Ch] [bp-8h]@5 | |
1434 int v22; // [sp+230h] [bp-4h]@1 | |
1435 | |
1436 v1 = this; | |
1437 v2 = 0; | |
1438 v3 = this->uNumSubIndices; | |
1439 v22 = 0; | |
1440 if ( (signed int)v3 > 0 ) | |
1441 { | |
1442 v4 = this->pSubIndices; | |
1443 v5 = v3; | |
1444 v6 = (int)&v4->uDataSize; | |
1445 do | |
1446 { | |
1447 v2 += *(int *)v6; | |
1448 v6 += 32; | |
1449 --v5; | |
1450 } | |
1451 while ( v5 ); | |
1452 v22 = v2; | |
1453 } | |
1454 v7 = 0; | |
1455 v21 = 32 * v3 + v2; | |
1456 v8 = 32 * v3; | |
1457 if ( (signed int)v3 > 0 ) | |
1458 { | |
1459 v9 = &v1->pSubIndices; | |
1460 v10 = 0; | |
1461 v11 = v1->pSubIndices; | |
1462 do | |
1463 { | |
1464 v11[v10].uOfsetFromSubindicesStart = v8; | |
1465 v11 = *v9; | |
1466 v8 += (*v9)[v10].uDataSize; | |
1467 ++v7; | |
1468 ++v10; | |
1469 } | |
1470 while ( v7 < (signed int)v1->uNumSubIndices ); | |
1471 v2 = v22; | |
1472 } | |
1473 strcpy(OldFilename, "lod.tmp"); | |
1474 v12 = fopen(OldFilename, "wb+"); | |
1475 v13 = v12; | |
1476 if ( v12 ) | |
1477 { | |
1478 fwrite(&v1->header, 0x100, 1, v12); | |
1479 | |
1480 LOD::Directory v0; // [sp+20Ch] [bp-28h]@11 | |
1481 //LOD::Directory::LOD::Directory(&v0); | |
1482 | |
1483 strcpy((char *)&v0, "chapter"); | |
1484 v15 = v1->uOffsetToSubIndex; | |
1485 v0.dword_000018 = 0; | |
1486 v0.uOfsetFromSubindicesStart = v15; | |
1487 v0.word_00001E = 0; | |
1488 v0.uDataSize = v21; | |
1489 v0.uNumSubIndices = LOWORD(v1->uNumSubIndices); | |
1490 fwrite(&v0, 0x20, 1, v13); | |
1491 fwrite(v1->pSubIndices, 0x20, v1->uNumSubIndices, v13); | |
1492 v16 = v1->pOutputFileHandle; | |
1493 v22 = v2; | |
1494 fseek(v16, 0, 0); | |
1495 if ( v2 > 0 ) | |
1496 { | |
1497 do | |
1498 { | |
1499 v17 = v1->uIOBufferSize; | |
1500 if ( v22 <= (signed int)v17 ) | |
1501 v17 = v22; | |
1502 fread(v1->pIOBuffer, 1, v17, v1->pOutputFileHandle); | |
1503 fwrite(v1->pIOBuffer, 1, v17, v13); | |
1504 v22 -= v17; | |
1505 } | |
1506 while ( v22 > 0 ); | |
1507 } | |
1508 strcpy(NewFilename, (const char *)v1->pLODName); | |
1509 fclose(v13); | |
1510 fclose(v1->pOutputFileHandle); | |
1511 v1->CloseWriteFile(); | |
1512 remove("lodapp.tmp"); | |
1513 remove(NewFilename); | |
1514 rename(OldFilename, NewFilename); | |
1515 v1->CloseWriteFile(); | |
1516 v1->LoadFile(v1->pLODName, 0); | |
1517 result = 0; | |
1518 } | |
1519 else | |
1520 { | |
1521 result = 5; | |
1522 } | |
1523 return result; | |
1524 } | |
1525 | |
1526 | |
1527 //----- (00461F71) -------------------------------------------------------- | |
1528 bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData) | |
1529 { | |
1530 unsigned int v3; // edi@1 | |
1531 bool result; // eax@2 | |
1532 FILE *v5; // ST0C_4@3 | |
1533 | |
1534 v3 = this->uNumSubIndices; | |
1535 if ( (signed int)v3 < 299 ) | |
1536 { | |
1537 memcpy(&this->pSubIndices[v3], pDir, sizeof(this->pSubIndices[v3])); | |
1538 v5 = this->pOutputFileHandle; | |
1539 ++this->uNumSubIndices; | |
1540 fwrite(pData, 1u, pDir->uDataSize, v5); | |
1541 result = 1; | |
1542 } | |
1543 else | |
1544 { | |
1545 MessageBoxA(0, "Unable to append item!", "LOD::File", 0x30u); | |
1546 result = 0; | |
1547 } | |
1548 return result; | |
1549 } | |
1550 | |
1551 | |
1552 //----- (00461F1E) -------------------------------------------------------- | |
1553 int LODWriteableFile::CreateTempFile() | |
1554 { | |
1555 LODWriteableFile *v1; // esi@1 | |
1556 int result; // eax@2 | |
1557 FILE *pFile; // eax@5 | |
1558 int v4; // eax@5 | |
1559 | |
1560 v1 = this; | |
1561 if ( this->isFileOpened ) | |
1562 { | |
1563 if ( this->pIOBuffer && this->uIOBufferSize ) | |
1564 { | |
1565 this->uCurrentIndexDir = 0; | |
1566 this->uNumSubIndices = 0; | |
1567 pFile = fopen("lodapp.tmp", "wb+"); | |
1568 v1->pOutputFileHandle = pFile; | |
1569 v4 = -(pFile != 0); | |
1570 LOBYTE(v4) = v4 & 0xF9; | |
1571 result = v4 + 7; | |
1572 } | |
1573 else | |
1574 { | |
1575 result = 5; | |
1576 } | |
1577 } | |
1578 else | |
1579 { | |
1580 result = 1; | |
1581 } | |
1582 return result; | |
1583 } | |
1584 | |
1585 | |
1586 | |
1587 //----- (00461EE9) -------------------------------------------------------- | |
1588 void LODWriteableFile::CloseWriteFile() | |
1589 { | |
1590 if (isFileOpened) | |
1591 { | |
1592 pContainerName[0] = 0; | |
1593 uCurrentIndexDir = 0; | |
1594 _6A0CA8_lod_unused = 0; | |
1595 | |
1596 isFileOpened = false; | |
1597 fflush(pFile); | |
1598 fclose(pFile); | |
1599 pFile = 0; | |
1600 } | |
1601 } | |
1602 // 6A0CA8: using guessed type int 6A0CA8_lod_unused; | |
1603 | |
1604 | |
1605 //----- (00461B48) -------------------------------------------------------- | |
1606 unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4) | |
1607 { | |
1608 LODWriteableFile *v4; // ebx@1 | |
1609 int v5; // esi@1 | |
1610 unsigned __int8 v7; // zf@7 | |
1611 unsigned __int8 v8; // sf@7 | |
1612 const LOD::Directory *v9; // edi@9 | |
1613 int v10; // eax@9 | |
1614 unsigned __int8 v11; // of@15 | |
1615 unsigned __int16 v12; // dx@17 | |
1616 LOD::Directory *v13; // eax@17 | |
1617 unsigned __int16 v14; // cx@17 | |
1618 int v15; // edi@27 | |
1619 unsigned int v16; // eax@27 | |
1620 int v17; // eax@29 | |
1621 int v18; // edx@31 | |
1622 int v19; // eax@31 | |
1623 void *v20; // edi@32 | |
1624 LOD::Directory *v21; // edi@34 | |
1625 signed int v22; // esi@34 | |
1626 int v23; // eax@34 | |
1627 LOD::Directory *v24; // ecx@35 | |
1628 int v25; // edx@35 | |
1629 __int32 v26; // eax@37 | |
1630 int i; // esi@39 | |
1631 __int32 v28; // esi@46 | |
1632 char pFilename[256]; // [sp+Ch] [bp-230h]@22 | |
1633 char NewFilename[256]; // [sp+10Ch] [bp-130h]@51 | |
1634 //LOD::Directory Str; // [sp+20Ch] [bp-30h]@27 | |
1635 size_t v33; // [sp+22Ch] [bp-10h]@27 | |
1636 int v34; // [sp+230h] [bp-Ch]@7 | |
1637 __int32 v35; // [sp+234h] [bp-8h]@8 | |
1638 int v36; // [sp+238h] [bp-4h]@7 | |
1639 size_t Count; // [sp+244h] [bp+8h]@40 | |
1640 __int32 Countc; // [sp+244h] [bp+8h]@46 | |
1641 size_t Countb; // [sp+244h] [bp+8h]@47 | |
1642 FILE *pFile; // [sp+24Ch] [bp+10h]@22 | |
1643 | |
1644 v4 = this; | |
1645 v5 = 0; | |
1646 if ( !this->isFileOpened ) | |
1647 return 1; | |
1648 if ( !this->pSubIndices ) | |
1649 return 2; | |
1650 if ( !this->pIOBuffer || !this->uIOBufferSize ) | |
1651 return 3; | |
1652 v7 = this->uNumSubIndices == 0; | |
568 | 1653 v8 = false;//this->uNumSubIndices != 0; // v8 = (this->uNumSubIndices & 0x80000000u) != 0; |
0 | 1654 v36 = 0; |
1655 v34 = 0; | |
1656 if ( v8 | v7 ) | |
1657 { | |
1658 v9 = pDir; | |
1659 goto LABEL_22; | |
1660 } | |
1661 v35 = 0; | |
1662 while ( 1 ) | |
1663 { | |
1664 v9 = pDir; | |
568 | 1665 v10 = _strcmpi(v4->pSubIndices[v5].pFilename + v35, pDir->pFilename); |
0 | 1666 if ( v10 ) |
1667 { | |
1668 if ( v10 > 0 ) | |
1669 goto LABEL_22; | |
1670 goto LABEL_15; | |
1671 } | |
1672 if ( !a4 ) | |
1673 goto LABEL_20; | |
1674 if ( a4 == 1 ) | |
1675 break; | |
1676 if ( a4 == 2 ) | |
1677 return 4; | |
1678 LABEL_15: | |
1679 v35 += 32; | |
1680 ++v5; | |
1681 v11 = v5 >= v4->uNumSubIndices; | |
17 | 1682 v8 = (v5 - v4->uNumSubIndices) != 0;//v8 = ((v5 - v4->uNumSubIndices) & 0x80000000u) != 0; |
0 | 1683 v34 = v5; |
568 | 1684 //if ( !(v8 ^ v11) ) |
1685 if (v5 >= v4->uNumSubIndices) | |
0 | 1686 goto LABEL_22; |
1687 } | |
1688 v12 = pDir->uNumSubIndices; | |
1689 v13 = &v4->pSubIndices[v5]; | |
1690 v14 = v13->uNumSubIndices; | |
1691 if ( v14 >= v12 && (v14 != v12 || (unsigned __int16)v13->word_00001E >= pDir->word_00001E) ) | |
1692 return 4; | |
1693 LABEL_20: | |
1694 v36 = 1; | |
1695 LABEL_22: | |
1696 strcpy(pFilename, "lod.tmp"); | |
1697 pFile = fopen(pFilename, "wb+"); | |
1698 if ( !pFile ) | |
1699 return 5; | |
1700 if ( v36 ) | |
1701 v35 = v4->pSubIndices[v5].uDataSize; | |
1702 else | |
1703 v35 = 0; | |
1704 v33 = v9->uDataSize; | |
1705 v15 = v33 - v35; | |
1706 | |
1707 LOD::Directory Str; // [sp+20Ch] [bp-30h]@27 | |
1708 //LOD::Directory::LOD::Directory(&Str); | |
1709 | |
1710 strcpy((char *)&Str, "chapter"); | |
1711 v16 = v4->uLODDataSize; | |
1712 Str.uNumSubIndices = LOWORD(v4->uNumSubIndices); | |
1713 Str.dword_000018 = 0; | |
1714 Str.word_00001E = 0; | |
1715 if ( !v36 ) | |
1716 { | |
1717 ++Str.uNumSubIndices; | |
1718 v15 += 32; | |
1719 } | |
1720 v7 = v36 == 0; | |
1721 Str.uDataSize = v15 + v16; | |
1722 Str.uOfsetFromSubindicesStart = 288; | |
1723 v17 = (signed __int16)Str.uNumSubIndices; | |
1724 v4->uNumSubIndices = (signed __int16)Str.uNumSubIndices; | |
1725 if ( v7 && v17 > v5 ) | |
1726 { | |
1727 v18 = v17; | |
1728 v19 = v17 - v5; | |
1729 do | |
1730 { | |
1731 v20 = &v4->pSubIndices[v18]; | |
1732 --v18; | |
1733 --v19; | |
1734 memcpy(v20, (char *)v20 - 32, 0x20u); | |
1735 } | |
1736 while ( v19 ); | |
1737 v5 = v34; | |
1738 } | |
1739 v21 = v4->pSubIndices; | |
1740 v34 = 32 * v5; | |
1741 memcpy(&v21[v5], pDir, sizeof(v21[v5])); | |
1742 v22 = 0; | |
1743 v23 = 32 * v4->uNumSubIndices; | |
1744 if ( (signed int)v4->uNumSubIndices > 0 ) | |
1745 { | |
1746 v24 = v4->pSubIndices; | |
1747 v25 = 0; | |
1748 do | |
1749 { | |
1750 v24[v25].uOfsetFromSubindicesStart = v23; | |
1751 v24 = v4->pSubIndices; | |
1752 v23 += v24[v25].uDataSize; | |
1753 ++v22; | |
1754 ++v25; | |
1755 } | |
1756 while ( v22 < (signed int)v4->uNumSubIndices ); | |
1757 } | |
1758 fwrite(&v4->header, 0x100u, 1u, pFile); | |
1759 fwrite(&Str, 0x20, 1, pFile); | |
1760 fseek(v4->pFile, Str.uOfsetFromSubindicesStart, 0); | |
1761 fwrite(v4->pSubIndices, 0x20u, v4->uNumSubIndices, pFile); | |
1762 v26 = 32 * v4->uNumSubIndices; | |
1763 if ( !v36 ) | |
1764 v26 -= 32; | |
1765 fseek(v4->pFile, v26, 1); | |
1766 for ( i = *(unsigned int *)((char *)&v4->pSubIndices->uOfsetFromSubindicesStart + v34) | |
1767 - v4->pSubIndices->uOfsetFromSubindicesStart; i > 0; i -= Count ) | |
1768 { | |
1769 Count = v4->uIOBufferSize; | |
1770 if ( i <= (signed int)v4->uIOBufferSize ) | |
1771 Count = i; | |
1772 fread(v4->pIOBuffer, 1u, Count, v4->pFile); | |
1773 fwrite(v4->pIOBuffer, 1u, Count, pFile); | |
1774 } | |
1775 fwrite(pDirData, 1u, v33, pFile); | |
1776 if ( v36 ) | |
1777 fseek(v4->pFile, v35, 1); | |
1778 Countc = ftell(v4->pFile); | |
1779 fseek(v4->pFile, 0, 2); | |
1780 v28 = ftell(v4->pFile) - Countc; | |
1781 fseek(v4->pFile, Countc, 0); | |
1782 while ( v28 > 0 ) | |
1783 { | |
1784 Countb = v4->uIOBufferSize; | |
1785 if ( v28 <= (signed int)v4->uIOBufferSize ) | |
1786 Countb = v28; | |
1787 fread(v4->pIOBuffer, 1u, Countb, v4->pFile); | |
1788 fwrite(v4->pIOBuffer, 1u, Countb, pFile); | |
1789 v28 -= Countb; | |
1790 } | |
1791 strcpy(NewFilename, (const char *)v4->pLODName); | |
1792 fclose(pFile); | |
1793 v4->CloseWriteFile(); | |
1794 remove(NewFilename); | |
1795 rename(pFilename, NewFilename); | |
1796 v4->CloseWriteFile(); | |
1797 v4->LoadFile(v4->pLODName, 0); | |
1798 return 0; | |
1799 } | |
1800 | |
1801 | |
1802 //----- (00461A43) -------------------------------------------------------- | |
1803 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting) | |
1804 { | |
1805 LODWriteableFile *v3; // esi@1 | |
1806 FILE *pFile_dup; // eax@4 | |
1807 unsigned int v5; // ecx@5 | |
1808 __int32 v6; // eax@5 | |
1809 FILE *v7; // ST00_4@5 | |
1810 size_t v8; // edi@5 | |
1811 const char *v10; // [sp-4h] [bp-30h]@2 | |
1812 | |
1813 v3 = this; | |
1814 if ( bWriting & 1 ) | |
1815 v10 = "rb"; | |
1816 else | |
1817 v10 = "rb+"; | |
1818 pFile_dup = fopen(pFilename, v10); | |
1819 v3->pFile = pFile_dup; | |
1820 if ( !pFile_dup ) | |
1821 { | |
1822 isFileOpened = false; | |
1823 return 0; | |
1824 } | |
1825 strcpy(pLODName, pFilename); | |
1826 fread(&header, 0x100u, 1u, v3->pFile); | |
1827 | |
1828 LOD::Directory dir; // [sp+Ch] [bp-20h]@5 | |
1829 //LOD::Directory::LOD::Directory(&dir); | |
1830 | |
1831 fread(&dir, 0x20u, 1u, v3->pFile); | |
1832 fseek(v3->pFile, 0, 0); | |
1833 isFileOpened = 1; | |
1834 strcpy((char *)v3->pContainerName, "chapter"); | |
1835 v5 = (signed __int16)dir.uNumSubIndices; | |
1836 v6 = dir.uOfsetFromSubindicesStart; | |
1837 v3->uCurrentIndexDir = 0; | |
1838 v3->uOffsetToSubIndex = v6; | |
1839 v7 = v3->pFile; | |
1840 v3->uNumSubIndices = v5; | |
1841 v3->uLODDataSize = dir.uDataSize; | |
1842 fseek(v7, v6, SEEK_SET); | |
1843 v8 = v3->uNumSubIndices; | |
1844 if ( (signed int)v8 > 300 ) | |
1845 { | |
1846 MessageBoxA(0, "LODchapterPages exceed 300", "LOD::File", MB_ICONEXCLAMATION); | |
1847 fclose(v3->pFile); | |
1848 return 0; | |
1849 } | |
1850 fread(pSubIndices, 0x20u, v8, v3->pFile); | |
1851 return 1; | |
1852 } | |
1853 | |
1854 | |
1855 //----- (00461A11) -------------------------------------------------------- | |
1856 void LOD::File::FreeSubIndexAndIO() | |
1857 { | |
1858 void *v1; // edi@1 | |
1859 LOD::Directory **v2; // esi@1 | |
1860 | |
1861 v1 = this; | |
1862 v2 = &this->pSubIndices; | |
1863 pAllocator->FreeChunk(this->pSubIndices); | |
1864 v1 = (char *)v1 + 264; | |
1865 pAllocator->FreeChunk(pIOBuffer);// delete [] pIOBuffer; | |
1866 pIOBuffer = nullptr; | |
1867 pSubIndices = nullptr; | |
1868 } | |
1869 | |
1870 | |
1871 //----- (00461954) -------------------------------------------------------- | |
1872 void LOD::File::AllocSubIndicesAndIO(unsigned int uNumSubIndices, unsigned int uBufferSize) | |
1873 { | |
1874 //LOD::File *v3; // esi@1 | |
1875 LOD::Directory *pSubIndices_dup; // eax@3 | |
1876 char v5; // zf@3 | |
1877 | |
1878 //v3 = this; | |
1879 if (pSubIndices) | |
1880 { | |
1881 MessageBoxA(0, "Attempt to reset a LOD subindex!", "MM6", MB_ICONEXCLAMATION); | |
1882 pAllocator->FreeChunk(pSubIndices); | |
1883 pSubIndices = nullptr; | |
1884 } | |
1885 pSubIndices_dup = (LOD::Directory *)pAllocator->AllocNamedChunk( | |
1886 pSubIndices, | |
1887 32 * uNumSubIndices, | |
1888 "LODsub"); | |
1889 v5 = pIOBuffer == 0; | |
1890 pSubIndices = pSubIndices_dup; | |
1891 if ( !v5 ) | |
1892 { | |
1893 MessageBoxA(0, "Attempt to reset a LOD IObuffer!", "MM6", MB_ICONEXCLAMATION); | |
1894 pAllocator->FreeChunk(pIOBuffer); | |
1895 pIOBuffer = 0; | |
1896 uIOBufferSize = 0; | |
1897 } | |
1898 if ( uBufferSize ) | |
1899 { | |
1900 pIOBuffer = (unsigned __int8 *)pAllocator->AllocNamedChunk(pIOBuffer, uBufferSize, "LODio"); | |
1901 uIOBufferSize = uBufferSize; | |
1902 } | |
1903 } | |
1904 | |
1905 | |
1906 | |
1907 //----- (0046188A) -------------------------------------------------------- | |
1908 int LOD::File::LoadSubIndices(const char *pContainer) | |
1909 { | |
415 | 1910 |
0 | 1911 unsigned int uDir; // edi@1 |
415 | 1912 LOD::Directory *curr_index; // eax@7 |
0 | 1913 |
415 | 1914 |
0 | 1915 ResetSubIndices(); |
1916 uDir = 0; | |
415 | 1917 |
1918 if ( header.uNumIndices <= 0) | |
1919 return 3; | |
0 | 1920 else |
415 | 1921 { |
1922 while (stricmp(pContainer, pRoot[uDir].pFilename)) | |
1923 { | |
1924 ++uDir; | |
1925 if (uDir >= header.uNumIndices ) | |
1926 return 3; | |
1927 } | |
1928 strcpy( pContainerName, pContainer); | |
1929 uCurrentIndexDir = uDir; | |
1930 curr_index=(LOD::Directory *)&pRoot[uDir]; | |
1931 uOffsetToSubIndex =curr_index->uOfsetFromSubindicesStart ; | |
1932 uNumSubIndices =curr_index->uNumSubIndices;// *(_WORD *)(v8 + 28); | |
1933 fseek( pFile, uOffsetToSubIndex, 0); | |
1934 pSubIndices = (LOD::Directory *)pAllocator->AllocNamedChunk(pSubIndices, sizeof(LOD::Directory)*(uNumSubIndices + 5), "LOD Index"); | |
1935 | |
1936 if ( pSubIndices) | |
1937 fread( pSubIndices, sizeof(LOD::Directory), uNumSubIndices, pFile); | |
1938 return 0; | |
1939 } | |
0 | 1940 } |
1941 | |
1942 //----- (004617D5) -------------------------------------------------------- | |
1943 bool LOD::File::LoadHeader(const char *pFilename, bool bWriting) | |
1944 { | |
1945 LOD::File *this_dup; // esi@1 | |
1946 FILE *pFile_dup; // eax@6 | |
1947 void *pRoot_dup; // eax@7 | |
1948 const char *v6; // [sp-4h] [bp-Ch]@4 | |
1949 FILE *v7; // [sp-4h] [bp-Ch]@7 | |
1950 | |
1951 this_dup = this; | |
1952 if ( this->isFileOpened ) | |
1953 Close(); | |
1954 if ( bWriting & 1 ) | |
1955 v6 = "rb"; | |
1956 else | |
1957 v6 = "rb+"; | |
1958 pFile_dup = fopen(pFilename, v6); | |
1959 this_dup->pFile = pFile_dup; | |
1960 if ( pFile_dup ) | |
1961 { | |
1962 strcpy(this_dup->pLODName, pFilename); | |
1963 fread(&this_dup->header, 0x100u, 1u, this_dup->pFile); | |
1964 pRoot_dup = pAllocator->AllocNamedChunk(this_dup->pRoot, 0xA0u, "LOD CArray"); | |
1965 this_dup->pRoot = (LOD::Directory *)pRoot_dup; | |
1966 v7 = this_dup->pFile; | |
1967 if ( pRoot_dup ) | |
1968 { | |
1969 fread(pRoot_dup, 0x20u, this_dup->header.uNumIndices, v7); | |
1970 fseek(this_dup->pFile, 0, 0); | |
1971 this_dup->isFileOpened = 1; | |
1972 return false; | |
1973 } | |
1974 else | |
1975 { | |
1976 fclose(v7); | |
1977 return true; | |
1978 } | |
1979 } | |
1980 return true; | |
1981 } | |
1982 | |
1983 | |
1984 //----- (004617B6) -------------------------------------------------------- | |
1985 void LOD::FileHeader::Reset() | |
1986 { | |
1987 this->pSignature[0] = 0; | |
1988 this->LodVersion[0] = 0; | |
1989 this->LodDescription[0] = 0; | |
1990 this->LODSize = 0; | |
1991 this->dword_0000A8 = 0; | |
1992 this->uNumIndices = 0; | |
1993 } | |
1994 | |
1995 //----- (00461790) -------------------------------------------------------- | |
1996 LOD::File::~File() | |
1997 { | |
1998 LOD::File *v1; // esi@1 | |
1999 | |
2000 v1 = this; | |
2001 if ( this->isFileOpened ) | |
2002 { | |
2003 fclose(this->pFile); | |
2004 pAllocator->FreeChunk(v1->pSubIndices); | |
2005 } | |
2006 } | |
2007 | |
2008 | |
2009 //----- (0046175B) -------------------------------------------------------- | |
2010 LOD::File::File(): | |
2011 pRoot(nullptr), | |
2012 isFileOpened(false) | |
2013 { | |
2014 LOD::File *v1; // esi@1 | |
2015 | |
2016 memset(pLODName, 0, 256); | |
2017 memset(pContainerName, 0, 16); | |
2018 v1 = this; | |
2019 v1->pFile = 0; | |
2020 v1->pSubIndices = 0; | |
2021 v1->pIOBuffer = 0; | |
2022 v1->isFileOpened = 0; | |
2023 v1->uIOBufferSize = 0; | |
2024 Close(); | |
2025 } | |
2026 | |
2027 | |
2028 //----- (00461743) -------------------------------------------------------- | |
2029 LOD::Directory *LOD::Directory::Reset() | |
2030 { | |
2031 LOD::Directory *result; // eax@1 | |
2032 | |
2033 result = this; | |
2034 this->pFilename[0] = 0; | |
2035 this->uOfsetFromSubindicesStart = 0; | |
2036 this->uDataSize = 0; | |
2037 this->dword_000018 = 0; | |
2038 this->uNumSubIndices = 0; | |
2039 this->word_00001E = 0; | |
2040 return result; | |
2041 } | |
2042 | |
2043 | |
2044 //----- (0046172B) -------------------------------------------------------- | |
2045 LOD::Directory::Directory() | |
2046 { | |
2047 memset(pFilename, 0, 16); | |
2048 this->pFilename[0] = 0; | |
2049 this->uOfsetFromSubindicesStart = 0; | |
2050 this->uDataSize = 0; | |
2051 this->uNumSubIndices = 0; | |
2052 this->dword_000018 = 0; | |
2053 this->word_00001E = 0; | |
2054 } | |
2055 | |
2056 //----- (0046165E) -------------------------------------------------------- | |
2057 int LOD::File::CalcIndexFast(int startIndex, int maxIndex, const char *pContainerName) | |
2058 { | |
2059 int v4; // esi@1 | |
2060 int v5; // ebx@2 | |
2061 int result; // eax@2 | |
2062 int v7; // edi@10 | |
2063 int v8; // esi@11 | |
2064 int v9; // esi@17 | |
2065 LOD::File *v10; // [sp+Ch] [bp-4h]@1 | |
2066 | |
2067 v4 = startIndex; | |
2068 v10 = this; | |
2069 while ( 1 ) // binary search in LOD indices | |
2070 { | |
2071 while ( 1 ) | |
2072 { | |
2073 v5 = maxIndex - v4; | |
2074 result = _strcmpi((const char *)pContainerName, (const char *)(&v10->pSubIndices[(maxIndex - v4) / 2] + v4)); | |
2075 if ( !result ) | |
2076 _6A0CA4_lod_binary_search = (maxIndex - v4) / 2 + v4; | |
2077 if ( v4 == maxIndex ) | |
2078 goto LABEL_14; | |
2079 if ( result < 0 ) | |
2080 break; | |
2081 if ( v5 <= 4 ) | |
2082 { | |
2083 v7 = v4; | |
2084 if ( v4 < maxIndex ) | |
2085 { | |
2086 v9 = v4; | |
2087 do | |
2088 { | |
2089 result = _strcmpi((const char *)pContainerName, (const char *)&v10->pSubIndices[v9]); | |
2090 if ( !result ) | |
2091 goto LABEL_21; | |
2092 ++v7; | |
2093 ++v9; | |
2094 } | |
2095 while ( v7 < maxIndex ); | |
2096 } | |
2097 LABEL_14: | |
2098 _6A0CA4_lod_binary_search = -1; | |
2099 return result; | |
2100 } | |
2101 v4 += (maxIndex - v4) / 2; | |
2102 } | |
2103 if ( v5 <= 4 ) | |
2104 break; | |
2105 maxIndex = (maxIndex - v4) / 2 + v4; | |
2106 } | |
2107 v7 = v4; | |
2108 if ( v4 >= maxIndex ) | |
2109 goto LABEL_14; | |
2110 v8 = v4; | |
2111 while ( 1 ) | |
2112 { | |
2113 result = _strcmpi((const char *)pContainerName, (const char *)&v10->pSubIndices[v8]); | |
2114 if ( !result ) | |
2115 break; | |
2116 ++v7; | |
2117 ++v8; | |
2118 if ( v7 >= maxIndex ) | |
2119 goto LABEL_14; | |
2120 } | |
2121 LABEL_21: | |
2122 _6A0CA4_lod_binary_search = v7; | |
2123 return result; | |
2124 } | |
2125 // 6A0CA4: using guessed type int _6A0CA4_lod_binary_search; | |
2126 | |
2127 | |
2128 //----- (0046161C) -------------------------------------------------------- | |
2129 bool LOD::File::DoesContainerExist(const char *pContainer) | |
2130 { | |
2131 LOD::File *this_dup; // esi@1 | |
2132 int i; // ebx@1 | |
2133 signed int i_dup; // edi@1 | |
2134 bool result; // eax@4 | |
2135 | |
2136 this_dup = this; | |
2137 i = 0; | |
2138 i_dup = 0; | |
2139 if ( (signed int)this->uNumSubIndices <= 0 ) | |
2140 { | |
2141 LABEL_4: | |
2142 result = 0; | |
2143 } | |
2144 else | |
2145 { | |
2146 while ( _strcmpi((const char *)pContainer, (const char *)&this_dup->pSubIndices[i]) ) | |
2147 { | |
2148 ++i_dup; | |
2149 ++i; | |
2150 if ( i_dup >= (signed int)this_dup->uNumSubIndices ) | |
2151 goto LABEL_4; | |
2152 } | |
2153 result = 1; | |
2154 } | |
2155 return result; | |
2156 } | |
2157 | |
2158 | |
2159 //----- (00461397) -------------------------------------------------------- | |
2160 int LODFile_Sprites::_461397() | |
2161 { | |
2162 int result; // eax@1 | |
2163 int *pfield_ECA0; // edi@1 | |
2164 int v3; // esi@1 | |
2165 int v4; // ecx@3 | |
2166 | |
2167 result = this->uNumLoadedSprites; | |
2168 pfield_ECA0 = &this->field_ECA0; | |
2169 v3 = this->field_ECA0; | |
2170 this->field_ECA8 = result; | |
2171 if ( result < v3 ) | |
2172 this->field_ECA8 = v3; | |
2173 v4 = this->field_ECA4; | |
2174 if ( v3 < v4 ) | |
2175 *pfield_ECA0 = v4; | |
2176 return result; | |
2177 } | |
2178 | |
2179 //----- (00461580) -------------------------------------------------------- | |
2180 FILE *LOD::File::FindContainer(const char *pContainerName, bool bLinearSearch) | |
2181 { | |
2182 unsigned int v4; // eax@4 | |
2183 if (!isFileOpened) | |
2184 return 0; | |
2185 | |
2186 | |
2187 if (bLinearSearch) | |
2188 { | |
2189 for (uint i = 0; i < uNumSubIndices; ++i) | |
2190 if (!strcmpi(pContainerName, pSubIndices[i].pFilename)) | |
2191 { | |
2192 v4 = pSubIndices[i].uOfsetFromSubindicesStart; | |
2193 fseek(pFile, uOffsetToSubIndex + v4, SEEK_SET); | |
2194 return pFile; | |
2195 } | |
2196 | |
2197 return nullptr; | |
2198 } | |
2199 else | |
2200 { | |
2201 CalcIndexFast(0, uNumSubIndices, pContainerName); | |
2202 if ( _6A0CA4_lod_binary_search < 0 ) | |
2203 return 0; | |
2204 v4 = pSubIndices[_6A0CA4_lod_binary_search].uOfsetFromSubindicesStart; | |
2205 fseek(pFile, uOffsetToSubIndex + v4, SEEK_SET); | |
2206 return pFile; | |
2207 } | |
2208 } | |
2209 | |
2210 //----- (0041097D) -------------------------------------------------------- | |
2211 void LODFile_IconsBitmaps::SetupPalettes(unsigned int uTargetRBits, unsigned int uTargetGBits, unsigned int uTargetBBits) | |
2212 { | |
2213 int v4; // edx@1 | |
2214 LODFile_IconsBitmaps *v5; // esi@1 | |
2215 int v6; // ecx@1 | |
2216 unsigned __int8 v7; // zf@4 | |
2217 unsigned __int8 v8; // sf@4 | |
2218 unsigned __int16 **v9; // edi@5 | |
2219 FILE *v10; // eax@7 | |
2220 FILE *v11; // ebx@7 | |
2221 signed int v12; // ebx@8 | |
2222 int v13; // eax@9 | |
2223 int v14; // edx@9 | |
2224 int v16; // [sp+4Ch] [bp-8h]@4 | |
2225 FILE *File; // [sp+50h] [bp-4h]@7 | |
2226 | |
2227 v4 = uTargetGBits; | |
2228 v5 = this; | |
2229 v6 = uTargetBBits; | |
2230 if ( v5->uTextureRedBits != uTargetRBits | |
2231 || v5->uTextureGreenBits != uTargetGBits | |
2232 || v5->uTextureBlueBits != uTargetBBits ) | |
2233 { | |
2234 v16 = 0; | |
2235 v7 = v5->uNumLoadedFiles == 0; | |
2236 v8 = (v5->uNumLoadedFiles & 0x80000000u) != 0; | |
2237 v5->uTextureRedBits = uTargetRBits; | |
2238 v5->uTextureGreenBits = v4; | |
2239 v5->uTextureBlueBits = v6; | |
2240 if ( !(v8 | v7) ) | |
2241 { | |
2242 v9 = &v5->pTextures[0].pPalette16; | |
2243 do | |
2244 { | |
2245 Texture DstBuf; // [sp+4h] [bp-50h]@6 | |
2246 //Texture::Texture(&DstBuf); | |
2247 | |
2248 if ( *v9 ) | |
2249 { | |
2250 v10 = FindContainer((const char *)v9 - 64, 0); | |
2251 v11 = v10; | |
2252 File = v10; | |
2253 if ( v10 ) | |
2254 { | |
2255 fread(&DstBuf, 1u, 0x30u, v10); | |
2256 fseek(v11, DstBuf.uTextureSize, 1); | |
2257 v12 = 0; | |
2258 do | |
2259 { | |
2260 fread((char *)&uTargetRBits + 3, 1u, 1u, File); | |
2261 fread((char *)&uTargetBBits + 3, 1u, 1u, File); | |
2262 v13 = fread((char *)&uTargetGBits + 3, 1u, 1u, File); | |
2263 LOWORD(v13) = (unsigned __int8)(BYTE3(uTargetRBits) >> (8 - LOBYTE(v5->uTextureRedBits))); | |
2264 (*v9)[v12] = v13 << (LOBYTE(v5->uTextureGreenBits) + LOBYTE(v5->uTextureBlueBits)); | |
2265 LOWORD(v14) = (unsigned __int8)(BYTE3(uTargetBBits) >> (8 - LOBYTE(v5->uTextureGreenBits))); | |
2266 (*v9)[v12] |= v14 << v5->uTextureBlueBits; | |
2267 (*v9)[v12] |= BYTE3(uTargetGBits) >> (8 - LOBYTE(v5->uTextureBlueBits)); | |
2268 ++v12; | |
2269 } | |
2270 while ( v12 < 256 ); | |
2271 } | |
2272 } | |
2273 ++v16; | |
2274 v9 += 18; | |
2275 } | |
2276 while ( v16 < (signed int)v5->uNumLoadedFiles ); | |
2277 } | |
2278 } | |
2279 } | |
2280 | |
2281 | |
2282 | |
2283 //----- (0041088B) -------------------------------------------------------- | |
2284 void *LOD::File::LoadRaw(const char *pContainer, int a3) | |
2285 { | |
2286 LOD::File *v3; // esi@1 | |
2287 FILE *v4; // eax@1 | |
2288 FILE *v5; // esi@1 | |
2289 void *v6; // eax@5 | |
2290 void *v7; // ebx@7 | |
2291 void *v8; // edi@7 | |
2292 void *v9; // eax@9 | |
2293 Texture DstBuf; // [sp+Ch] [bp-4Ch]@1 | |
2294 FILE *File; // [sp+54h] [bp-4h]@1 | |
2295 unsigned int Argsa; // [sp+60h] [bp+8h]@3 | |
2296 | |
2297 v3 = this; | |
2298 v4 = FindContainer(pContainer, 0); | |
2299 v5 = v4; | |
2300 File = v4; | |
2301 if ( !v4 ) | |
2302 Abortf("Unable to load %s", pContainer); | |
2303 fread(&DstBuf, 1u, 0x30u, v4); | |
2304 Argsa = DstBuf.uTextureSize; | |
2305 if ( DstBuf.uDecompressedSize ) | |
2306 { | |
2307 if ( a3 ) | |
705 | 2308 v6 = malloc(DstBuf.uDecompressedSize+1); |
0 | 2309 else |
705 | 2310 v6 = pAllocator->AllocNamedChunk(0, DstBuf.uDecompressedSize+1, DstBuf.pName); |
0 | 2311 v7 = v6; |
705 | 2312 v8 = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize+1, DstBuf.pName); |
0 | 2313 fread(v8, 1u, Argsa, File); |
2314 zlib::MemUnzip(v7, &DstBuf.uDecompressedSize, v8, DstBuf.uTextureSize); | |
2315 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
2316 pAllocator->FreeChunk(v8); | |
2317 } | |
2318 else | |
2319 { | |
2320 if ( a3 ) | |
705 | 2321 v9 = malloc(DstBuf.uTextureSize+1); |
0 | 2322 else |
705 | 2323 v9 = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize+1, DstBuf.pName); |
0 | 2324 v7 = v9; |
2325 fread(v9, 1u, Argsa, v5); | |
2326 } | |
2327 return v7; | |
2328 } | |
2329 | |
2330 | |
2331 | |
2332 //----- (00410522) -------------------------------------------------------- | |
2333 int LODFile_IconsBitmaps::_410522(Texture *pDst, const char *pContainer, unsigned int uTextureType) | |
2334 { | |
2335 LODFile_IconsBitmaps *v4; // edi@1 | |
2336 Texture *v5; // esi@5 | |
2337 unsigned int v6; // eax@5 | |
2338 void *v7; // eax@6 | |
2339 unsigned int v8; // ST28_4@6 | |
2340 void *v9; // ST2C_4@6 | |
2341 unsigned __int8 *v10; // eax@7 | |
2342 FILE *v11; // ST28_4@7 | |
2343 void *v12; // eax@9 | |
2344 FILE *v13; // ST28_4@9 | |
2345 signed int v14; // eax@12 | |
2346 int v15; // ecx@12 | |
2347 int v16; // ecx@12 | |
2348 int v17; // eax@12 | |
2349 signed int v18; // ebx@14 | |
2350 int v19; // eax@15 | |
2351 int v20; // edx@15 | |
2352 signed int v21; // ecx@18 | |
2353 signed int v22; // ecx@23 | |
2354 char Args[100]; // [sp+4h] [bp-68h]@3 | |
2355 FILE *File; // [sp+68h] [bp-4h]@1 | |
2356 | |
2357 v4 = this; | |
2358 File = FindContainer(pContainer, 0); | |
2359 if ( !File ) | |
2360 { | |
2361 File = FindContainer("pending", 0); | |
2362 if ( !File ) | |
2363 { | |
2364 sprintf(Args, "Can't find %s!", pContainer); | |
2365 Abortf(Args); | |
2366 } | |
2367 } | |
2368 v5 = pDst; | |
2369 fread(pDst, 1u, 0x30u, File); | |
2370 strcpy(v5->pName, pContainer); | |
2371 pDst = (Texture *)v5->uTextureSize; | |
2372 v6 = v5->uDecompressedSize; | |
710 | 2373 v5->pLevelOfDetail0_prolly_alpha_mask = 0; |
0 | 2374 if ( v6 ) |
2375 { | |
2376 v7 = operator new(v6); | |
2377 v8 = v5->uTextureSize; | |
710 | 2378 v5->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v7; |
0 | 2379 pContainer = (const char *)operator new(v8); |
2380 fread((void *)pContainer, 1u, (size_t)pDst, File); | |
710 | 2381 zlib::MemUnzip(v5->pLevelOfDetail0_prolly_alpha_mask, &v5->uDecompressedSize, pContainer, v5->uTextureSize); |
0 | 2382 v9 = (void *)pContainer; |
2383 v5->uTextureSize = v5->uDecompressedSize; | |
2384 free(v9); | |
2385 } | |
2386 else | |
2387 { | |
2388 v10 = (unsigned __int8 *)operator new(0); | |
2389 v11 = File; | |
710 | 2390 v5->pLevelOfDetail0_prolly_alpha_mask = v10; |
0 | 2391 fread(v10, 1u, (size_t)pDst, v11); |
2392 } | |
2393 v5->pPalette24 = 0; | |
2394 if ( uTextureType == 1 ) | |
2395 { | |
2396 v12 = operator new(0x300u); | |
2397 v13 = File; | |
2398 v5->pPalette24 = (unsigned __int8 *)v12; | |
2399 fread(v12, 1u, 0x300u, v13); | |
2400 LABEL_10: | |
2401 v5->pPalette16 = 0; | |
2402 goto LABEL_11; | |
2403 } | |
2404 if ( uTextureType != 2 ) | |
2405 goto LABEL_10; | |
2406 v18 = 0; | |
2407 v5->pPalette16 = 0; | |
2408 v5->pPalette16 = (unsigned __int16 *)operator new(0x400u); | |
2409 do | |
2410 { | |
2411 fread((char *)&pContainer + 3, 1u, 1u, File); | |
2412 fread((char *)&uTextureType + 3, 1u, 1u, File); | |
2413 v19 = fread((char *)&pDst + 3, 1u, 1u, File); | |
2414 LOWORD(v19) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2415 v5->pPalette16[v18] = v19 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2416 LOWORD(v20) = (unsigned __int8)(BYTE3(uTextureType) >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2417 v5->pPalette16[v18] += v20 << v4->uTextureBlueBits; | |
2418 v5->pPalette16[v18] += (unsigned __int8)(BYTE3(pDst) >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2419 ++v18; | |
2420 } | |
2421 while ( v18 < 256 ); | |
2422 LABEL_11: | |
2423 if ( v5->pBits & 2 ) | |
2424 { | |
2425 v14 = v5->uSizeOfMaxLevelOfDetail; | |
710 | 2426 v15 = (int)&v5->pLevelOfDetail0_prolly_alpha_mask[v14]; |
0 | 2427 v5->pLevelOfDetail1 = (unsigned __int8 *)v15; |
2428 v16 = (v14 >> 2) + v15; | |
2429 v5->pLevelOfDetail2 = (unsigned __int8 *)v16; | |
2430 v17 = v16 + (v14 >> 4); | |
2431 } | |
2432 else | |
2433 { | |
2434 v17 = 0; | |
2435 v5->pLevelOfDetail2 = 0; | |
2436 v5->pLevelOfDetail1 = 0; | |
2437 } | |
2438 v5->pLevelOfDetail3 = (unsigned __int8 *)v17; | |
2439 v21 = 1; | |
2440 while ( 1 << v21 != v5->uTextureWidth ) | |
2441 { | |
2442 ++v21; | |
2443 if ( v21 >= 15 ) | |
2444 goto LABEL_23; | |
2445 } | |
2446 v5->uWidthLn2 = v21; | |
2447 LABEL_23: | |
2448 v22 = 1; | |
2449 while ( 1 << v22 != v5->uTextureHeight ) | |
2450 { | |
2451 ++v22; | |
2452 if ( v22 >= 15 ) | |
2453 goto LABEL_28; | |
2454 } | |
2455 v5->uHeightLn2 = v22; | |
2456 LABEL_28: | |
2457 switch ( v5->uWidthLn2 ) | |
2458 { | |
2459 case 2: | |
2460 v5->uWidthMinus1 = 3; | |
2461 break; | |
2462 case 3: | |
2463 v5->uWidthMinus1 = 7; | |
2464 break; | |
2465 case 4: | |
2466 v5->uWidthMinus1 = 15; | |
2467 break; | |
2468 case 5: | |
2469 v5->uWidthMinus1 = 31; | |
2470 break; | |
2471 case 6: | |
2472 v5->uWidthMinus1 = 63; | |
2473 break; | |
2474 case 7: | |
2475 v5->uWidthMinus1 = 127; | |
2476 break; | |
2477 case 8: | |
2478 v5->uWidthMinus1 = 255; | |
2479 break; | |
2480 case 9: | |
2481 v5->uWidthMinus1 = 511; | |
2482 break; | |
2483 case 10: | |
2484 v5->uWidthMinus1 = 1023; | |
2485 break; | |
2486 case 11: | |
2487 v5->uWidthMinus1 = 2047; | |
2488 break; | |
2489 case 12: | |
2490 v5->uWidthMinus1 = 4095; | |
2491 break; | |
2492 default: | |
2493 break; | |
2494 } | |
2495 switch ( v5->uHeightLn2 ) | |
2496 { | |
2497 case 2: | |
2498 v5->uHeightMinus1 = 3; | |
2499 break; | |
2500 case 3: | |
2501 v5->uHeightMinus1 = 7; | |
2502 break; | |
2503 case 4: | |
2504 v5->uHeightMinus1 = 15; | |
2505 break; | |
2506 case 5: | |
2507 v5->uHeightMinus1 = 31; | |
2508 break; | |
2509 case 6: | |
2510 v5->uHeightMinus1 = 63; | |
2511 break; | |
2512 case 7: | |
2513 v5->uHeightMinus1 = 127; | |
2514 break; | |
2515 case 8: | |
2516 v5->uHeightMinus1 = 255; | |
2517 break; | |
2518 case 9: | |
2519 v5->uHeightMinus1 = 511; | |
2520 break; | |
2521 case 10: | |
2522 v5->uHeightMinus1 = 1023; | |
2523 break; | |
2524 case 11: | |
2525 v5->uHeightMinus1 = 2047; | |
2526 break; | |
2527 case 12: | |
2528 v5->uHeightMinus1 = 4095; | |
2529 break; | |
2530 default: | |
2531 return 1; | |
2532 } | |
2533 return 1; | |
2534 } | |
2535 | |
2536 | |
2537 //----- (00410423) -------------------------------------------------------- | |
2538 void LODFile_IconsBitmaps::_410423_move_textures_to_device() | |
2539 { | |
2540 LODFile_IconsBitmaps *v1; // esi@1 | |
2541 unsigned int v2; // edi@1 | |
2542 char *v3; // ebx@2 | |
2543 size_t v4; // eax@9 | |
2544 char *v5; // ST1C_4@9 | |
2545 void *v6; // eax@12 | |
2546 signed int v7; // esi@13 | |
2547 | |
2548 v1 = this; | |
2549 v2 = this->uNumLoadedFiles - 1; | |
2550 if ( (v2 & 0x80000000u) == 0 ) | |
2551 { | |
2552 v3 = &this->pTextures[v2].pName[2]; | |
2553 do | |
2554 { | |
2555 if ( v1->ptr_011BB4[v2] ) | |
2556 { | |
2557 if ( *(v3 - 2) != 'w' || *(v3 - 1) != 't' || *v3 != 'r' || v3[1] != 'd' || v3[2] != 'r' ) | |
2558 { | |
2559 pRenderer->LoadTexture( | |
2560 v3 - 2, | |
2561 *((short *)v3 + 17), | |
2562 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2563 &v1->pHardwareTextures[v2]); | |
2564 } | |
2565 else | |
2566 { | |
2567 v4 = strlen(v3 - 2); | |
2568 v5 = (char *)operator new(v4 + 2); | |
2569 *v5 = 'h'; | |
2570 strcpy(v5 + 1, v3 - 2); | |
2571 pRenderer->LoadTexture( | |
2572 v5, | |
2573 *((short *)v3 + 17), | |
2574 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2575 &v1->pHardwareTextures[v2]); | |
2576 free(v5); | |
2577 } | |
2578 } | |
2579 --v2; | |
2580 v3 -= 72; | |
2581 } | |
2582 while ( (v2 & 0x80000000u) == 0 ); | |
2583 } | |
2584 v6 = v1->ptr_011BB4; | |
2585 if ( v6 ) | |
2586 { | |
2587 v7 = v1->uNumLoadedFiles; | |
2588 if ( v7 > 1 ) | |
2589 memset(v6, 0, v7 - 1); | |
2590 } | |
2591 } | |
2592 | |
2593 | |
2594 //----- (004103BB) -------------------------------------------------------- | |
2595 void LODFile_IconsBitmaps::ReleaseHardwareTextures() | |
2596 { | |
2597 LODFile_IconsBitmaps *v1; // esi@1 | |
2598 unsigned int v2; // edi@1 | |
2599 struct IDirect3DTexture2 **v3; // eax@2 | |
2600 struct IDirect3DTexture2 *v4; // eax@3 | |
2601 struct IDirectDrawSurface **v5; // eax@5 | |
2602 struct IDirectDrawSurface *v6; // eax@6 | |
2603 | |
2604 v1 = this; | |
2605 v2 = this->uNumLoadedFiles; | |
2606 while ( 1 ) | |
2607 { | |
2608 --v2; | |
2609 if ( (v2 & 0x80000000u) != 0 ) | |
2610 break; | |
2611 v3 = v1->pHardwareTextures; | |
2612 if ( v3 ) | |
2613 { | |
2614 v4 = v3[v2]; | |
2615 if ( v4 ) | |
2616 { | |
2617 v4->Release(); | |
2618 v1->pHardwareTextures[v2] = 0; | |
2619 v1->ptr_011BB4[v2] = 1; | |
2620 } | |
2621 } | |
2622 v5 = v1->pHardwareSurfaces; | |
2623 if ( v5 ) | |
2624 { | |
2625 v6 = v5[v2]; | |
2626 if ( v6 ) | |
2627 { | |
2628 v6->Release(); | |
2629 v1->pHardwareSurfaces[v2] = 0; | |
2630 v1->ptr_011BB4[v2] = 1; | |
2631 } | |
2632 } | |
2633 } | |
2634 } | |
2635 | |
2636 | |
2637 //----- (0041033D) -------------------------------------------------------- | |
2638 void LODFile_IconsBitmaps::ReleaseLostHardwareTextures() | |
2639 { | |
2640 LODFile_IconsBitmaps *v1; // edi@1 | |
2641 unsigned int i; // ebx@1 | |
2642 struct IDirectDrawSurface **pHardwareSurfaces; // eax@2 | |
2643 int v4; // esi@3 | |
2644 struct IDirectDrawSurface *pSurface; // eax@3 | |
2645 struct IDirect3DTexture2 **v6; // eax@5 | |
2646 struct IDirect3DTexture2 *v7; // eax@6 | |
2647 | |
2648 v1 = this; | |
2649 for ( i = this->uNumLoadedFiles - 1; (i & 0x80000000u) == 0; --i ) | |
2650 { | |
2651 pHardwareSurfaces = v1->pHardwareSurfaces; | |
2652 if ( pHardwareSurfaces ) | |
2653 { | |
2654 v4 = i; | |
2655 pSurface = pHardwareSurfaces[i]; | |
2656 if ( pSurface ) | |
2657 { | |
2658 if ( pSurface->IsLost() == DDERR_SURFACELOST ) | |
2659 { | |
2660 v6 = v1->pHardwareTextures; | |
2661 if ( v6 ) | |
2662 { | |
2663 v7 = v6[v4]; | |
2664 if ( v7 ) | |
2665 { | |
2666 v7->Release(); | |
2667 v1->pHardwareTextures[v4] = 0; | |
2668 } | |
2669 } | |
2670 v1->pHardwareSurfaces[v4]->Release(); | |
2671 v1->pHardwareSurfaces[v4] = 0; | |
2672 v1->ptr_011BB4[i] = 1; | |
2673 } | |
2674 } | |
2675 } | |
2676 } | |
2677 } | |
2678 | |
2679 //----- (004101B1) -------------------------------------------------------- | |
2680 int LODFile_IconsBitmaps::ReloadTexture(Texture *pDst, const char *pContainer, int mode) | |
2681 { | |
2682 LODFile_IconsBitmaps *v4; // edi@1 | |
2683 FILE *v5; // eax@1 | |
2684 Texture *v6; // esi@2 | |
2685 unsigned int v7; // ebx@6 | |
2686 unsigned int v8; // ecx@6 | |
2687 signed int result; // eax@7 | |
2688 size_t *v10; // ebx@8 | |
2689 signed int v11; // ebx@12 | |
2690 int v12; // eax@13 | |
2691 int v13; // edx@13 | |
2692 FILE *File; // [sp+Ch] [bp-8h]@1 | |
2693 unsigned __int8 v15; // [sp+11h] [bp-3h]@13 | |
2694 unsigned __int8 v16; // [sp+12h] [bp-2h]@13 | |
2695 unsigned __int8 DstBuf; // [sp+13h] [bp-1h]@13 | |
2696 void *DstBufa; // [sp+1Ch] [bp+8h]@10 | |
2697 void *Sourcea; // [sp+20h] [bp+Ch]@10 | |
2698 unsigned int Counta; // [sp+24h] [bp+10h]@6 | |
2699 | |
2700 v4 = this; | |
2701 v5 = FindContainer(pContainer, 0); | |
2702 File = v5; | |
2703 if ( v5 | |
710 | 2704 && (v6 = pDst, pDst->pLevelOfDetail0_prolly_alpha_mask) |
0 | 2705 && mode == 2 |
2706 && pDst->pPalette16 | |
2707 && !pDst->pPalette24 | |
2708 && (v7 = pDst->uTextureSize, | |
2709 fread(pDst, 1u, 0x30u, v5), | |
2710 strcpy(pDst->pName, pContainer), | |
2711 v8 = pDst->uTextureSize, | |
2712 Counta = pDst->uTextureSize, | |
2713 (signed int)v8 <= (signed int)v7) ) | |
2714 { | |
2715 v10 = &pDst->uDecompressedSize; | |
2716 if ( !pDst->uDecompressedSize || v4->dword_011BA4 ) | |
2717 { | |
710 | 2718 fread(pDst->pLevelOfDetail0_prolly_alpha_mask, 1u, v8, File); |
0 | 2719 } |
2720 else | |
2721 { | |
2722 Sourcea = malloc(pDst->uDecompressedSize); | |
2723 DstBufa = malloc(pDst->uTextureSize); | |
2724 fread(DstBufa, 1u, Counta, File); | |
2725 zlib::MemUnzip(Sourcea, &v6->uDecompressedSize, DstBufa, v6->uTextureSize); | |
2726 v6->uTextureSize = *v10; | |
2727 free(DstBufa); | |
710 | 2728 memcpy(v6->pLevelOfDetail0_prolly_alpha_mask, Sourcea, *v10); |
0 | 2729 free(Sourcea); |
2730 } | |
2731 v11 = 0; | |
2732 do | |
2733 { | |
2734 fread(&DstBuf, 1u, 1u, File); | |
2735 fread(&v16, 1u, 1u, File); | |
2736 v12 = fread(&v15, 1u, 1u, File); | |
2737 LOWORD(v12) = (unsigned __int8)(DstBuf >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2738 v6->pPalette16[v11] = v12 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2739 LOWORD(v13) = (unsigned __int8)(v16 >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2740 v6->pPalette16[v11] += v13 << v4->uTextureBlueBits; | |
2741 v6->pPalette16[v11] += (unsigned __int8)(v15 >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2742 ++v11; | |
2743 } | |
2744 while ( v11 < 256 ); | |
2745 result = 1; | |
2746 } | |
2747 else | |
2748 { | |
2749 result = -1; | |
2750 } | |
2751 return result; | |
2752 } | |
2753 | |
2754 | |
2755 //----- (0040FC08) -------------------------------------------------------- | |
2756 int LODFile_IconsBitmaps::LoadTextureFromLOD(Texture *pOutTex, const char *pContainer, enum TEXTURE_TYPE eTextureType) | |
2757 { | |
2758 Texture *v8; // esi@3 | |
2759 size_t v11; // eax@14 | |
2760 enum TEXTURE_TYPE v12; // eax@14 | |
2761 signed int v13; // esi@14 | |
2762 unsigned int v14; // eax@21 | |
2763 unsigned int v15; // ecx@25 | |
2764 unsigned int *v16; // ebx@25 | |
2765 void *v17; // eax@27 | |
2766 unsigned int v18; // ST28_4@27 | |
2767 void *v19; // ST3C_4@27 | |
2768 Allocator *v20; // ebx@29 | |
2769 void *v21; // eax@29 | |
2770 size_t v22; // ST2C_4@29 | |
2771 const void *v23; // ecx@29 | |
2772 unsigned __int16 v24; // ax@29 | |
2773 unsigned __int16 v25; // cx@29 | |
2774 __int16 v26; // dx@29 | |
2775 unsigned int v27; // ecx@29 | |
2776 Texture *v28; // eax@29 | |
2777 unsigned int v29; // ST28_4@30 | |
2778 void *v30; // eax@30 | |
2779 unsigned int v31; // ST2C_4@30 | |
2780 void *v32; // eax@32 | |
2781 void *v33; // eax@34 | |
2782 signed int v34; // eax@37 | |
2783 unsigned __int8 *v35; // ecx@37 | |
2784 unsigned __int8 *v36; // ecx@37 | |
2785 unsigned __int8 *v37; // eax@37 | |
2786 signed int v38; // ebx@39 | |
2787 int v39; // eax@40 | |
2788 int v40; // edx@40 | |
2789 signed int v41; // ecx@43 | |
2790 signed int v42; // ecx@48 | |
2791 | |
2792 //v4 = pContainer; | |
2793 //v5 = this; | |
2794 //v6 = FindContainer(pContainer, 0); | |
2795 //File = v6; | |
2796 auto pFile = FindContainer(pContainer, false); | |
2797 if (!pFile) | |
2798 return -1; | |
2799 v8 = pOutTex; | |
2800 fread(pOutTex, 1u, 0x30u, pFile); | |
2801 strcpy(v8->pName, pContainer); | |
2802 if (pRenderer->pRenderD3D && v8->pBits & 2 && dword_011BA8) | |
2803 { | |
2804 if (!pHardwareSurfaces || !pHardwareTextures) | |
2805 { | |
2806 pHardwareSurfaces = new IDirectDrawSurface *[1000]; | |
2807 memset(pHardwareSurfaces, 0, 1000 * sizeof(IDirectDrawSurface4 *)); | |
2808 | |
2809 pHardwareTextures = new IDirect3DTexture2 *[1000]; | |
2810 memset(pHardwareTextures, 0, 1000 * sizeof(IDirect3DTexture2 *)); | |
2811 | |
2812 ptr_011BB4 = new char[1000]; | |
2813 memset(ptr_011BB4, 0, 1000); | |
2814 } | |
265 | 2815 if (strnicmp(pContainer, "wtrdr", 5))//*v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' ) |
0 | 2816 { |
265 | 2817 if (strnicmp(pContainer, "WtrTyl", 6))//if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' ) |
0 | 2818 { |
2819 v14 = uNumLoadedFiles; | |
2820 } | |
2821 else | |
2822 { | |
265 | 2823 pRenderer->hd_water_tile_id = uNumLoadedFiles; |
0 | 2824 v14 = uNumLoadedFiles; |
2825 } | |
2826 v13 = pRenderer->LoadTexture( | |
2827 pContainer, | |
2828 v8->palette_id1, | |
2829 (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], | |
2830 &pHardwareTextures[v14]); | |
2831 } | |
2832 else | |
2833 { | |
2834 v11 = strlen(pContainer); | |
2835 v12 = (enum TEXTURE_TYPE)(int)operator new(v11 + 2); | |
2836 eTextureType = v12; | |
2837 *(char *)v12 = 104; | |
2838 strcpy((char *)(v12 + 1), pContainer); | |
2839 v13 = pRenderer->LoadTexture( | |
2840 (const char *)eTextureType, | |
2841 v8->palette_id1, | |
2842 (IDirectDrawSurface4 **)&pHardwareSurfaces[uNumLoadedFiles], | |
2843 &pHardwareTextures[uNumLoadedFiles]); | |
2844 free((void *)eTextureType); | |
2845 } | |
2846 return v13; | |
2847 } | |
2848 v15 = v8->uTextureSize; | |
2849 v16 = &v8->uDecompressedSize; | |
2850 pOutTex = (Texture *)v8->uTextureSize; | |
2851 if ( !v8->uDecompressedSize || dword_011BA4 ) | |
2852 { | |
2853 v20 = pAllocator; | |
710 | 2854 v32 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0_prolly_alpha_mask, v15, v8->pName); |
2855 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v32; | |
0 | 2856 fread(v32, 1u, (size_t)pOutTex, pFile); |
2857 } | |
2858 else | |
2859 { | |
2860 v17 = malloc(v8->uDecompressedSize); | |
2861 v18 = v8->uTextureSize; | |
2862 pContainer = (const char *)v17; | |
2863 v19 = malloc(v18); | |
2864 fread(v19, 1u, (size_t)pOutTex, pFile); | |
2865 zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize); | |
2866 v8->uTextureSize = *v16; | |
2867 free(v19); | |
2868 if ( bUseLoResSprites && v8->pBits & 2 ) | |
2869 { | |
2870 v20 = pAllocator; | |
2871 pOutTex = (Texture *)(((signed int)v8->uSizeOfMaxLevelOfDetail >> 2) | |
2872 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 4) | |
2873 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 6)); | |
710 | 2874 v21 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0_prolly_alpha_mask, (unsigned int)pOutTex, v8->pName); |
0 | 2875 v22 = (size_t)pOutTex; |
2876 v23 = &pContainer[v8->uTextureWidth * v8->uTextureHeight]; | |
710 | 2877 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v21; |
0 | 2878 memcpy(v21, v23, v22); |
2879 v8->uTextureWidth = (signed __int16)v8->uTextureWidth >> 1; | |
2880 v24 = v8->uTextureWidth; | |
2881 v8->uTextureHeight = (signed __int16)v8->uTextureHeight >> 1; | |
2882 v25 = v8->uTextureHeight; | |
2883 --v8->uWidthLn2; | |
2884 --v8->uHeightLn2; | |
2885 v8->uWidthMinus1 = v24 - 1; | |
2886 v26 = v25 - 1; | |
2887 v27 = (signed __int16)v24 * (signed __int16)v25; | |
2888 v28 = pOutTex; | |
2889 v8->uHeightMinus1 = v26; | |
2890 v8->uSizeOfMaxLevelOfDetail = v27; | |
2891 v8->uTextureSize = (unsigned int)v28; | |
2892 } | |
2893 else | |
2894 { | |
2895 v29 = *v16; | |
2896 v20 = pAllocator; | |
710 | 2897 v30 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0_prolly_alpha_mask, v29, v8->pName); |
0 | 2898 v31 = v8->uDecompressedSize; |
710 | 2899 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v30; |
0 | 2900 memcpy(v30, pContainer, v31); |
2901 } | |
2902 free((void *)pContainer); | |
2903 } | |
2904 pAllocator->FreeChunk(v8->pPalette16); | |
2905 pAllocator->FreeChunk(v8->pPalette24); | |
2906 if ( eTextureType == TEXTURE_24BIT_PALETTE ) | |
2907 { | |
2908 v33 = pAllocator->AllocNamedChunk(v8->pPalette24, 0x300u, v8->pName); | |
2909 v8->pPalette24 = (unsigned __int8 *)v33; | |
2910 fread(v33, 1u, 0x300u, pFile); | |
2911 } | |
2912 else | |
2913 { | |
2914 v8->pPalette24 = 0; | |
2915 if ( eTextureType == TEXTURE_16BIT_PALETTE ) | |
2916 { | |
2917 v8->pPalette16 = (unsigned __int16 *)pAllocator->AllocNamedChunk(v8->pPalette16, 0x200u, v8->pName); | |
2918 v38 = 0; | |
2919 do | |
2920 { | |
2921 fread((char *)&eTextureType + 3, 1u, 1u, pFile); | |
2922 fread((char *)&pContainer + 3, 1u, 1u, pFile); | |
2923 v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile); | |
2924 LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits))); | |
2925 v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits)); | |
2926 LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits))); | |
2927 v8->pPalette16[v38] += v40 << uTextureBlueBits; | |
2928 v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits))); | |
2929 ++v38; | |
2930 } | |
2931 while ( v38 < 256 ); | |
2932 goto LABEL_36; | |
2933 } | |
2934 } | |
2935 v8->pPalette16 = 0; | |
2936 LABEL_36: | |
2937 if ( v8->pBits & 2 ) | |
2938 { | |
2939 v34 = v8->uSizeOfMaxLevelOfDetail; | |
710 | 2940 v35 = &v8->pLevelOfDetail0_prolly_alpha_mask[v34]; |
0 | 2941 v8->pLevelOfDetail1 = v35; |
2942 v36 = &v35[v34 >> 2]; | |
2943 v8->pLevelOfDetail2 = v36; | |
2944 v37 = &v36[v34 >> 4]; | |
2945 } | |
2946 else | |
2947 { | |
2948 v37 = 0; | |
2949 v8->pLevelOfDetail2 = 0; | |
2950 v8->pLevelOfDetail1 = 0; | |
2951 } | |
2952 v8->pLevelOfDetail3 = v37; | |
2953 v41 = 1; | |
2954 while ( 1 << v41 != v8->uTextureWidth ) | |
2955 { | |
2956 ++v41; | |
2957 if ( v41 >= 15 ) | |
2958 goto LABEL_48; | |
2959 } | |
2960 v8->uWidthLn2 = v41; | |
2961 LABEL_48: | |
2962 v42 = 1; | |
2963 while ( 1 << v42 != v8->uTextureHeight ) | |
2964 { | |
2965 ++v42; | |
2966 if ( v42 >= 15 ) | |
2967 goto LABEL_53; | |
2968 } | |
2969 v8->uHeightLn2 = v42; | |
2970 LABEL_53: | |
2971 switch ( v8->uWidthLn2 ) | |
2972 { | |
2973 case 2: | |
2974 v8->uWidthMinus1 = 3; | |
2975 break; | |
2976 case 3: | |
2977 v8->uWidthMinus1 = 7; | |
2978 break; | |
2979 case 4: | |
2980 v8->uWidthMinus1 = 15; | |
2981 break; | |
2982 case 5: | |
2983 v8->uWidthMinus1 = 31; | |
2984 break; | |
2985 case 6: | |
2986 v8->uWidthMinus1 = 63; | |
2987 break; | |
2988 case 7: | |
2989 v8->uWidthMinus1 = 127; | |
2990 break; | |
2991 case 8: | |
2992 v8->uWidthMinus1 = 255; | |
2993 break; | |
2994 case 9: | |
2995 v8->uWidthMinus1 = 511; | |
2996 break; | |
2997 case 10: | |
2998 v8->uWidthMinus1 = 1023; | |
2999 break; | |
3000 case 11: | |
3001 v8->uWidthMinus1 = 2047; | |
3002 break; | |
3003 case 12: | |
3004 v8->uWidthMinus1 = 4095; | |
3005 break; | |
3006 default: | |
3007 break; | |
3008 } | |
3009 switch ( v8->uHeightLn2 ) | |
3010 { | |
3011 case 2: | |
3012 v8->uHeightMinus1 = 3; | |
3013 break; | |
3014 case 3: | |
3015 v8->uHeightMinus1 = 7; | |
3016 break; | |
3017 case 4: | |
3018 v8->uHeightMinus1 = 15; | |
3019 break; | |
3020 case 5: | |
3021 v8->uHeightMinus1 = 31; | |
3022 break; | |
3023 case 6: | |
3024 v8->uHeightMinus1 = 63; | |
3025 break; | |
3026 case 7: | |
3027 v8->uHeightMinus1 = 127; | |
3028 break; | |
3029 case 8: | |
3030 v8->uHeightMinus1 = 255; | |
3031 break; | |
3032 case 9: | |
3033 v8->uHeightMinus1 = 511; | |
3034 break; | |
3035 case 10: | |
3036 v8->uHeightMinus1 = 1023; | |
3037 break; | |
3038 case 11: | |
3039 v8->uHeightMinus1 = 2047; | |
3040 break; | |
3041 case 12: | |
3042 v8->uHeightMinus1 = 4095; | |
3043 break; | |
3044 default: | |
3045 return 1; | |
3046 } | |
3047 return 1; | |
3048 } | |
3049 | |
3050 | |
3051 Texture *LODFile_IconsBitmaps::LoadTexturePtr(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
3052 { | |
3053 uint id = LoadTexture(pContainer, uTextureType); | |
3054 if (id == -1) | |
3055 { | |
649 | 3056 assert(false); |
0 | 3057 Log::Warning(L"LOD error\\no container: \"%S\"", pContainer); |
3058 return nullptr; | |
3059 } | |
3060 return &pTextures[id]; | |
3061 } | |
3062 | |
3063 //----- (0040FB20) -------------------------------------------------------- | |
3064 unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
3065 { | |
3066 //LODFile_IconsBitmaps *v3; // esi@1 | |
3067 //unsigned int v4; // edi@1 | |
3068 //Texture *v5; // ebx@2 | |
3069 unsigned int v6; // ebx@8 | |
3070 const char *Sourcea; // [sp+14h] [bp+8h]@9 | |
3071 | |
3072 //v3 = this; | |
3073 //v4 = 0; | |
3074 areWeLoadingTexture = 1; | |
3075 | |
3076 for (uint i = 0; i < uNumLoadedFiles; ++i) | |
3077 if (!strcmpi(pContainer, pTextures[i].pName)) | |
3078 return i; | |
3079 | |
3080 // if (!uNumLoadedFiles) | |
3081 // { | |
3082 //LABEL_5: | |
649 | 3083 assert(uNumLoadedFiles < 1000); |
3084 /*if (uNumLoadedFiles >= 1000) | |
0 | 3085 { |
3086 Log::Warning(L"Maximum texture number exceeded"); | |
3087 AbortWithError(); | |
649 | 3088 }*/ |
0 | 3089 if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) |
3090 { | |
3091 v6 = 0; | |
3092 if (uNumLoadedFiles > 0) | |
3093 { | |
3094 Sourcea = (const char *)pTextures; | |
3095 while ( _strcmpi(Sourcea, "pending") ) | |
3096 { | |
3097 Sourcea += 72; | |
3098 ++v6; | |
3099 if (v6 >= uNumLoadedFiles) | |
3100 goto LABEL_15; | |
3101 } | |
3102 return v6; | |
3103 } | |
3104 LABEL_15: | |
3105 LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); | |
3106 } | |
3107 areWeLoadingTexture = 0; | |
3108 ++uNumLoadedFiles; | |
3109 return uNumLoadedFiles - 1; | |
3110 // } | |
3111 // v5 = pTextures; | |
3112 // while ( _strcmpi(v5->pName, pContainer) ) | |
3113 // { | |
3114 // ++v4; | |
3115 // ++v5; | |
3116 // if (v4 >= uNumLoadedFiles ) | |
3117 // goto LABEL_5; | |
3118 // } | |
3119 // return v4; | |
3120 } |