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