Mercurial > mm7
annotate LOD.cpp @ 793:290afbd48b6b
IndoorLocation::GetSector fixed (even better!)
author | Nomad |
---|---|
date | Mon, 25 Mar 2013 09:17:42 +0200 |
parents | cf2fbac6edc9 |
children | bebc19f3d2af |
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 { | |
978 LOD::File *v1; // esi@1 | |
979 LOD::Directory **v2; // edi@2 | |
980 FILE *v3; // ST00_4@2 | |
981 | |
982 v1 = this; | |
983 if ( this->isFileOpened ) | |
984 { | |
985 this->pContainerName[0] = 0; | |
986 this->uCurrentIndexDir = 0; | |
987 v2 = &this->pSubIndices; | |
988 pAllocator->FreeChunk(this->pSubIndices); | |
989 pAllocator->FreeChunk(v1->pRoot); | |
990 v3 = v1->pFile; | |
991 *v2 = 0; | |
992 v1->pRoot = 0; | |
993 fclose(v3); | |
994 v1->isFileOpened = 0; | |
995 _6A0CA8_lod_unused = 0; | |
996 } | |
997 } | |
998 | |
999 | |
1000 | |
1001 //----- (00461492) -------------------------------------------------------- | |
1002 int LODWriteableFile::_461492(LOD::FileHeader *pHeader, LOD::Directory *pDir, const char *Source) | |
1003 { | |
1004 if (isFileOpened) | |
1005 return 1; | |
1006 if ( !pDir->pFilename[0] ) | |
1007 return 2; | |
1008 strcpy(pHeader->pSignature, "LOD"); | |
1009 pHeader->LODSize = 100; | |
1010 pHeader->uNumIndices = 1; | |
1011 pDir->pFilename[15] = 0; | |
1012 pDir->uDataSize = 0; | |
1013 pDir->uOfsetFromSubindicesStart = 288; | |
1014 strcpy(pLODName, Source); | |
1015 | |
1016 pFile = fopen(pLODName, "wb+"); | |
1017 if (!pFile) | |
1018 return 3; | |
1019 | |
1020 fwrite(pHeader, 0x100, 1, pFile); | |
1021 fwrite(pDir, 0x20, 1, pFile); | |
1022 fclose(pFile); | |
1023 pFile = 0; | |
1024 return 0; | |
1025 } | |
1026 | |
1027 //----- (0046153F) -------------------------------------------------------- | |
1028 void LOD::File::ResetSubIndices() | |
1029 { | |
1030 LOD::Directory **pSubIndices_dup2; // esi@2 | |
1031 LOD::Directory *pSubIndices_dup; // ST00_4@2 | |
1032 | |
1033 if ( this->isFileOpened ) | |
1034 { | |
1035 pSubIndices_dup2 = &this->pSubIndices; | |
1036 this->pContainerName[0] = 0; | |
1037 this->uCurrentIndexDir = 0; | |
1038 pSubIndices_dup = this->pSubIndices; | |
1039 this->uOffsetToSubIndex = 0; | |
1040 this->uNumSubIndices = 0; | |
1041 this->uLODDataSize = 0; | |
1042 pAllocator->FreeChunk(pSubIndices_dup); | |
1043 *pSubIndices_dup2 = 0; | |
1044 } | |
1045 } | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | |
1053 //----- (00450C8B) -------------------------------------------------------- | |
1054 void LODFile_Sprites::DeleteSomeSprites() | |
1055 { | |
1056 int *v1; // esi@1 | |
1057 int *v2; // edi@1 | |
1058 | |
1059 v1 = (int *)&this->uNumLoadedSprites; | |
1060 v2 = &this->field_ECA8; | |
1061 DeleteSpritesRange(this->field_ECA8, this->uNumLoadedSprites); | |
1062 *v1 = *v2; | |
1063 } | |
1064 | |
1065 //----- (00450CA9) -------------------------------------------------------- | |
1066 void LODFile_Sprites::DeleteSpritesRange(int uStartIndex, int uStopIndex) | |
1067 { | |
1068 LODFile_Sprites *v3; // edi@1 | |
1069 int v4; // esi@3 | |
1070 LODSprite *v5; // ebx@3 | |
1071 LODSprite *v6; // esi@7 | |
1072 int v7; // edi@7 | |
1073 int a2a; // [sp+10h] [bp+8h]@3 | |
1074 | |
1075 v3 = this; | |
1076 if ( this->pHardwareSprites ) | |
1077 { | |
1078 if ( uStartIndex < uStopIndex ) | |
1079 { | |
1080 v4 = uStartIndex; | |
1081 v5 = &this->pSpriteHeaders[uStartIndex]; | |
1082 a2a = uStopIndex - uStartIndex; | |
1083 do | |
1084 { | |
1085 v5->Release(); | |
1086 pHardwareSprites[v4].Release(); | |
1087 ++v4; | |
1088 ++v5; | |
1089 --a2a; | |
1090 } | |
1091 while ( a2a ); | |
1092 } | |
1093 } | |
1094 else | |
1095 { | |
1096 if ( uStartIndex < uStopIndex ) | |
1097 { | |
1098 v6 = &this->pSpriteHeaders[uStartIndex]; | |
1099 v7 = uStopIndex - uStartIndex; | |
1100 do | |
1101 { | |
1102 v6->Release(); | |
1103 ++v6; | |
1104 --v7; | |
1105 } | |
1106 while ( v7 ); | |
1107 } | |
1108 } | |
1109 } | |
1110 | |
1111 //----- (00450D1D) -------------------------------------------------------- | |
1112 void LODSprite::Release() | |
1113 { | |
1114 LODSprite *v1; // esi@1 | |
1115 | |
1116 v1 = this; | |
1117 if ( !(HIBYTE(this->word_1A) & 4) ) | |
1118 { | |
1119 pAllocator->FreeChunk(this->pDecompressedBytes); | |
1120 pAllocator->FreeChunk(v1->pSpriteLines); | |
1121 } | |
1122 v1->word_1A = 0; | |
1123 v1->pDecompressedBytes = 0; | |
1124 v1->pSpriteLines = 0; | |
1125 v1->pName[0] = 0; | |
1126 v1->word_16 = 0; | |
1127 v1->uPaletteId = 0; | |
1128 v1->uTexturePitch = 0; | |
1129 v1->uHeight = 0; | |
1130 v1->uWidth = 0; | |
1131 v1->uSpriteSize = 0; | |
1132 } | |
1133 | |
1134 //----- (00450D68) -------------------------------------------------------- | |
1135 void Sprite::Release() | |
1136 { | |
1137 if (pName) | |
1138 pAllocator->FreeChunk((void *)pName); | |
1139 pName = nullptr; | |
1140 | |
1141 if (pTextureSurface) | |
1142 pTextureSurface->Release(); | |
1143 pTextureSurface = nullptr; | |
1144 | |
1145 if (pTexture) | |
1146 pTexture->Release(); | |
1147 pTexture = nullptr; | |
1148 } | |
1149 | |
1150 | |
1151 | |
1152 | |
1153 //----- (0040FA2E) -------------------------------------------------------- | |
1154 bool LODFile_IconsBitmaps::LoadBitmaps(const char *pFilename) | |
1155 { | |
1156 ReleaseAll(); | |
1157 if (LoadHeader(pFilename, 1)) | |
1158 return false; | |
1159 else | |
1160 return LoadSubIndices("bitmaps") == 0; | |
1161 } | |
1162 | |
1163 | |
1164 //----- (0040FAEE) -------------------------------------------------------- | |
1165 bool LODFile_IconsBitmaps::LoadIconsOrEvents(const char *pLODFilename) | |
1166 { | |
1167 ReleaseAll(); | |
1168 | |
1169 if (LoadHeader(pLODFilename, 1)) | |
1170 return false; | |
1171 else | |
1172 return LoadSubIndices("icons") == 0; | |
1173 } | |
1174 | |
1175 | |
1176 //----- (0040FA60) -------------------------------------------------------- | |
1177 void LODFile_IconsBitmaps::ReleaseAll() | |
1178 { | |
1179 LODFile_IconsBitmaps *v1; // esi@1 | |
1180 unsigned int v2; // edi@1 | |
1181 Texture *v3; // ebp@2 | |
1182 struct IDirect3DTexture2 **v4; // eax@3 | |
1183 struct IDirect3DTexture2 *v5; // eax@4 | |
1184 struct IDirectDrawSurface **v6; // eax@6 | |
1185 struct IDirectDrawSurface *v7; // eax@7 | |
1186 | |
1187 v1 = this; | |
1188 v2 = this->uNumLoadedFiles - 1; | |
1189 if ( (v2 & 0x80000000u) == 0 ) | |
1190 { | |
1191 v3 = &this->pTextures[v2]; | |
1192 do | |
1193 { | |
1194 v3->Release(); | |
1195 v4 = v1->pHardwareTextures; | |
1196 if ( v4 ) | |
1197 { | |
1198 v5 = v4[v2]; | |
1199 if ( v5 ) | |
1200 { | |
1201 v5->Release(); | |
1202 v1->pHardwareTextures[v2] = 0; | |
1203 } | |
1204 } | |
1205 v6 = v1->pHardwareSurfaces; | |
1206 if ( v6 ) | |
1207 { | |
1208 v7 = v6[v2]; | |
1209 if ( v7 ) | |
1210 { | |
1211 v7->Release(); | |
1212 v1->pHardwareSurfaces[v2] = 0; | |
1213 } | |
1214 } | |
1215 --v2; | |
1216 --v3; | |
1217 } | |
1218 while ( (v2 & 0x80000000u) == 0 ); | |
1219 } | |
1220 v1->uTexturePacksCount = 0; | |
1221 v1->uNumPrevLoadedFiles = 0; | |
1222 v1->dword_11B84 = 0; | |
1223 v1->dword_11B80 = 0; | |
1224 v1->uNumLoadedFiles = 0; | |
1225 } | |
1226 | |
1227 //----- (0040F9F0) -------------------------------------------------------- | |
1228 unsigned int LODFile_IconsBitmaps::FindTextureByName(const char *pName) | |
1229 { | |
1230 LODFile_IconsBitmaps *v2; // esi@1 | |
1231 unsigned int v3; // edi@1 | |
1232 Texture *v4; // ebx@2 | |
1233 unsigned int result; // eax@5 | |
1234 | |
1235 v2 = this; | |
1236 v3 = 0; | |
1237 if ( (signed int)this->uNumLoadedFiles <= 0 ) | |
1238 { | |
1239 LABEL_5: | |
1240 result = -1; | |
1241 } | |
1242 else | |
1243 { | |
1244 v4 = this->pTextures; | |
1245 while ( _strcmpi(v4->pName, pName) ) | |
1246 { | |
1247 ++v3; | |
1248 ++v4; | |
1249 if ( (signed int)v3 >= (signed int)v2->uNumLoadedFiles ) | |
1250 goto LABEL_5; | |
1251 } | |
1252 result = v3; | |
1253 } | |
1254 return result; | |
1255 } | |
1256 | |
1257 //----- (0040F9C5) -------------------------------------------------------- | |
1258 int LODFile_IconsBitmaps::_40F9C5() | |
1259 { | |
1260 signed int result; // eax@1 | |
1261 Texture *pTex; // edx@1 | |
1262 | |
1263 result = this->uNumLoadedFiles; | |
1264 for ( pTex = &this->pTextures[result]; !pTex->pName[0]; --pTex ) | |
1265 --result; | |
1266 if ( result < (signed int)this->uNumLoadedFiles ) | |
1267 { | |
1268 ++result; | |
1269 this->uNumLoadedFiles = result; | |
1270 } | |
1271 return result; | |
1272 } | |
1273 | |
1274 | |
1275 | |
1276 //----- (0046249B) -------------------------------------------------------- | |
1277 LODFile_Sprites::~LODFile_Sprites() | |
1278 { | |
1279 LODFile_Sprites *v1; // esi@1 | |
1280 signed int v2; // ebx@1 | |
1281 LODSprite *v3; // edi@3 | |
1282 char *v4; // edi@6 | |
1283 int thisa; // [sp+4h] [bp-10h]@3 | |
1284 LODSprite *thisb; // [sp+4h] [bp-10h]@7 | |
1285 | |
1286 v1 = this; | |
1287 v2 = 0; | |
1288 if ( this->pHardwareSprites ) | |
1289 { | |
1290 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
1291 { | |
1292 thisa = 0; | |
1293 v3 = this->pSpriteHeaders; | |
1294 do | |
1295 { | |
1296 v3->Release(); | |
1297 v1->pHardwareSprites[thisa].Release(); | |
1298 ++thisa; | |
1299 ++v2; | |
1300 ++v3; | |
1301 } | |
1302 while ( v2 < (signed int)v1->uNumLoadedSprites ); | |
1303 } | |
1304 } | |
1305 else | |
1306 { | |
1307 v4 = (char *)&this->uNumLoadedSprites; | |
1308 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
1309 { | |
1310 thisb = this->pSpriteHeaders; | |
1311 do | |
1312 { | |
1313 thisb->Release(); | |
1314 ++thisb; | |
1315 ++v2; | |
1316 } | |
1317 while ( v2 < *(int *)v4 ); | |
1318 } | |
1319 } | |
1320 //_eh_vector_destructor_iterator_(v1->pSpriteHeaders, 40, 1500, LODSprite::dtor); | |
1321 //LOD::File::vdtor((LOD::File *)v1); | |
1322 } | |
1323 // 4CC2B4: using guessed type int __stdcall _eh vector destructor iterator_(int, int, int, int); | |
1324 | |
1325 | |
1326 //----- (00462463) -------------------------------------------------------- | |
1327 LODSprite::~LODSprite() | |
1328 { | |
1329 LODSprite *v1; // esi@1 | |
1330 | |
1331 v1 = this; | |
1332 if ( !(HIBYTE(this->word_1A) & 4) ) | |
1333 { | |
1334 pAllocator->FreeChunk(this->pDecompressedBytes); | |
1335 pAllocator->FreeChunk(v1->pSpriteLines); | |
1336 } | |
1337 v1->pDecompressedBytes = 0; | |
1338 v1->pSpriteLines = 0; | |
1339 } | |
1340 | |
1341 //----- (004623E5) -------------------------------------------------------- | |
1342 LODFile_Sprites::LODFile_Sprites(): | |
1343 LOD::File() | |
1344 { | |
1345 /*_eh_vector_constructor_iterator_( | |
1346 v1->pSpriteHeaders, | |
1347 40, | |
1348 1500, | |
1349 (void (__thiscall *)(void *))LODSprite::LODSprite, | |
1350 (void (__thiscall *)(void *))LODSprite::dtor);*/ | |
1351 field_ECA4 = 0; | |
1352 field_ECA0 = 0; | |
1353 pHardwareSprites = 0; | |
1354 field_ECAC = 0; | |
1355 field_ECB4 = 0; | |
1356 uNumLoadedSprites = 0; | |
1357 } | |
1358 | |
1359 //----- (00462303) -------------------------------------------------------- | |
1360 LODFile_IconsBitmaps::~LODFile_IconsBitmaps() | |
1361 { | |
1362 LODFile_IconsBitmaps *v1; // esi@1 | |
1363 unsigned int v2; // edi@1 | |
1364 struct IDirect3DTexture2 **v3; // eax@3 | |
1365 struct IDirect3DTexture2 *v4; // eax@4 | |
1366 struct IDirectDrawSurface **v5; // eax@6 | |
1367 struct IDirectDrawSurface *v6; // eax@7 | |
1368 Texture *thisa; // [sp+4h] [bp-10h]@2 | |
1369 | |
1370 v1 = this; | |
1371 v2 = this->uNumLoadedFiles - 1; | |
1372 if ( (v2 & 0x80000000u) == 0 ) | |
1373 { | |
1374 thisa = &this->pTextures[v2]; | |
1375 do | |
1376 { | |
1377 thisa->Release(); | |
1378 v3 = v1->pHardwareTextures; | |
1379 if ( v3 ) | |
1380 { | |
1381 v4 = v3[v2]; | |
1382 if ( v4 ) | |
1383 { | |
1384 v4->Release(); | |
1385 v1->pHardwareTextures[v2] = 0; | |
1386 } | |
1387 } | |
1388 v5 = v1->pHardwareSurfaces; | |
1389 if ( v5 ) | |
1390 { | |
1391 v6 = v5[v2]; | |
1392 if ( v6 ) | |
1393 { | |
1394 v6->Release(); | |
1395 v1->pHardwareSurfaces[v2] = 0; | |
1396 } | |
1397 } | |
1398 --thisa; | |
1399 --v2; | |
1400 } | |
1401 while ( (v2 & 0x80000000u) == 0 ); | |
1402 } | |
1403 if ( v1->pHardwareSurfaces ) | |
1404 free(v1->pHardwareSurfaces); | |
1405 if ( v1->pHardwareTextures ) | |
1406 free(v1->pHardwareTextures); | |
1407 if ( v1->ptr_011BB4 ) | |
1408 free(v1->ptr_011BB4); | |
1409 //LOD::File::vdtor((LOD::File *)v1); | |
1410 } | |
1411 | |
1412 //----- (00462272) -------------------------------------------------------- | |
1413 LODFile_IconsBitmaps::LODFile_IconsBitmaps(): | |
1414 LOD::File() | |
1415 { | |
1416 LODFile_IconsBitmaps *v1; // esi@1 | |
1417 Texture *v2; // ebx@1 | |
1418 signed int v3; // [sp+4h] [bp-10h]@1 | |
1419 | |
1420 v1 = this; | |
1421 /*v2 = v1->pTextures; | |
1422 v3 = 1000; | |
1423 do | |
1424 { | |
1425 Texture::Texture(v2); | |
1426 ++v2; | |
1427 --v3; | |
1428 } | |
1429 while ( v3 );*/ | |
1430 v1->uTexturePacksCount = 0; | |
1431 v1->uNumPrevLoadedFiles = 0; | |
1432 v1->dword_11B84 = 0; | |
1433 v1->dword_11B80 = 0; | |
1434 v1->uNumLoadedFiles = 0; | |
1435 v1->dword_011BA4 = 0; | |
1436 v1->dword_011BA8 = 0; | |
1437 v1->pHardwareSurfaces = 0; | |
1438 v1->pHardwareTextures = 0; | |
1439 v1->ptr_011BB4 = 0; | |
1440 } | |
1441 | |
1442 | |
1443 //----- (004621A7) -------------------------------------------------------- | |
1444 bool LODWriteableFile::_4621A7() | |
1445 { | |
1446 CloseWriteFile(); | |
1447 return LoadFile(pLODName, 0); | |
1448 } | |
1449 | |
1450 | |
1451 //----- (00461FD4) -------------------------------------------------------- | |
1452 int LODWriteableFile::Save() | |
1453 { | |
1454 LODWriteableFile *v1; // esi@1 | |
1455 int v2; // edi@1 | |
1456 unsigned int v3; // edx@1 | |
1457 LOD::Directory *v4; // eax@2 | |
1458 unsigned int v5; // ecx@2 | |
1459 int v6; // eax@2 | |
1460 signed int v7; // ebx@5 | |
1461 int v8; // ecx@5 | |
1462 LOD::Directory **v9; // edi@6 | |
1463 int v10; // edx@6 | |
1464 LOD::Directory *v11; // eax@6 | |
1465 FILE *v12; // eax@9 | |
1466 FILE *v13; // ebx@9 | |
1467 signed int result; // eax@10 | |
1468 unsigned int v15; // eax@11 | |
1469 FILE *v16; // ST00_4@11 | |
1470 size_t v17; // edi@12 | |
1471 char OldFilename[256]; // [sp+Ch] [bp-228h]@9 | |
1472 char NewFilename[256]; // [sp+10Ch] [bp-128h]@15 | |
1473 //LOD::Directory v0; // [sp+20Ch] [bp-28h]@11 | |
1474 unsigned int v21; // [sp+22Ch] [bp-8h]@5 | |
1475 int v22; // [sp+230h] [bp-4h]@1 | |
1476 | |
1477 v1 = this; | |
1478 v2 = 0; | |
1479 v3 = this->uNumSubIndices; | |
1480 v22 = 0; | |
1481 if ( (signed int)v3 > 0 ) | |
1482 { | |
1483 v4 = this->pSubIndices; | |
1484 v5 = v3; | |
1485 v6 = (int)&v4->uDataSize; | |
1486 do | |
1487 { | |
1488 v2 += *(int *)v6; | |
1489 v6 += 32; | |
1490 --v5; | |
1491 } | |
1492 while ( v5 ); | |
1493 v22 = v2; | |
1494 } | |
1495 v7 = 0; | |
1496 v21 = 32 * v3 + v2; | |
1497 v8 = 32 * v3; | |
1498 if ( (signed int)v3 > 0 ) | |
1499 { | |
1500 v9 = &v1->pSubIndices; | |
1501 v10 = 0; | |
1502 v11 = v1->pSubIndices; | |
1503 do | |
1504 { | |
1505 v11[v10].uOfsetFromSubindicesStart = v8; | |
1506 v11 = *v9; | |
1507 v8 += (*v9)[v10].uDataSize; | |
1508 ++v7; | |
1509 ++v10; | |
1510 } | |
1511 while ( v7 < (signed int)v1->uNumSubIndices ); | |
1512 v2 = v22; | |
1513 } | |
1514 strcpy(OldFilename, "lod.tmp"); | |
1515 v12 = fopen(OldFilename, "wb+"); | |
1516 v13 = v12; | |
1517 if ( v12 ) | |
1518 { | |
1519 fwrite(&v1->header, 0x100, 1, v12); | |
1520 | |
1521 LOD::Directory v0; // [sp+20Ch] [bp-28h]@11 | |
1522 //LOD::Directory::LOD::Directory(&v0); | |
1523 | |
1524 strcpy((char *)&v0, "chapter"); | |
1525 v15 = v1->uOffsetToSubIndex; | |
1526 v0.dword_000018 = 0; | |
1527 v0.uOfsetFromSubindicesStart = v15; | |
1528 v0.word_00001E = 0; | |
1529 v0.uDataSize = v21; | |
1530 v0.uNumSubIndices = LOWORD(v1->uNumSubIndices); | |
1531 fwrite(&v0, 0x20, 1, v13); | |
1532 fwrite(v1->pSubIndices, 0x20, v1->uNumSubIndices, v13); | |
1533 v16 = v1->pOutputFileHandle; | |
1534 v22 = v2; | |
1535 fseek(v16, 0, 0); | |
1536 if ( v2 > 0 ) | |
1537 { | |
1538 do | |
1539 { | |
1540 v17 = v1->uIOBufferSize; | |
1541 if ( v22 <= (signed int)v17 ) | |
1542 v17 = v22; | |
1543 fread(v1->pIOBuffer, 1, v17, v1->pOutputFileHandle); | |
1544 fwrite(v1->pIOBuffer, 1, v17, v13); | |
1545 v22 -= v17; | |
1546 } | |
1547 while ( v22 > 0 ); | |
1548 } | |
1549 strcpy(NewFilename, (const char *)v1->pLODName); | |
1550 fclose(v13); | |
1551 fclose(v1->pOutputFileHandle); | |
1552 v1->CloseWriteFile(); | |
1553 remove("lodapp.tmp"); | |
1554 remove(NewFilename); | |
1555 rename(OldFilename, NewFilename); | |
1556 v1->CloseWriteFile(); | |
1557 v1->LoadFile(v1->pLODName, 0); | |
1558 result = 0; | |
1559 } | |
1560 else | |
1561 { | |
1562 result = 5; | |
1563 } | |
1564 return result; | |
1565 } | |
1566 | |
1567 | |
1568 //----- (00461F71) -------------------------------------------------------- | |
1569 bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData) | |
1570 { | |
1571 unsigned int v3; // edi@1 | |
1572 bool result; // eax@2 | |
1573 FILE *v5; // ST0C_4@3 | |
1574 | |
1575 v3 = this->uNumSubIndices; | |
1576 if ( (signed int)v3 < 299 ) | |
1577 { | |
1578 memcpy(&this->pSubIndices[v3], pDir, sizeof(this->pSubIndices[v3])); | |
1579 v5 = this->pOutputFileHandle; | |
1580 ++this->uNumSubIndices; | |
1581 fwrite(pData, 1u, pDir->uDataSize, v5); | |
1582 result = 1; | |
1583 } | |
1584 else | |
1585 { | |
1586 MessageBoxA(0, "Unable to append item!", "LOD::File", 0x30u); | |
1587 result = 0; | |
1588 } | |
1589 return result; | |
1590 } | |
1591 | |
1592 | |
1593 //----- (00461F1E) -------------------------------------------------------- | |
1594 int LODWriteableFile::CreateTempFile() | |
1595 { | |
1596 LODWriteableFile *v1; // esi@1 | |
1597 int result; // eax@2 | |
1598 FILE *pFile; // eax@5 | |
1599 int v4; // eax@5 | |
1600 | |
1601 v1 = this; | |
1602 if ( this->isFileOpened ) | |
1603 { | |
1604 if ( this->pIOBuffer && this->uIOBufferSize ) | |
1605 { | |
1606 this->uCurrentIndexDir = 0; | |
1607 this->uNumSubIndices = 0; | |
1608 pFile = fopen("lodapp.tmp", "wb+"); | |
1609 v1->pOutputFileHandle = pFile; | |
1610 v4 = -(pFile != 0); | |
1611 LOBYTE(v4) = v4 & 0xF9; | |
1612 result = v4 + 7; | |
1613 } | |
1614 else | |
1615 { | |
1616 result = 5; | |
1617 } | |
1618 } | |
1619 else | |
1620 { | |
1621 result = 1; | |
1622 } | |
1623 return result; | |
1624 } | |
1625 | |
1626 | |
1627 | |
1628 //----- (00461EE9) -------------------------------------------------------- | |
1629 void LODWriteableFile::CloseWriteFile() | |
1630 { | |
1631 if (isFileOpened) | |
1632 { | |
1633 pContainerName[0] = 0; | |
1634 uCurrentIndexDir = 0; | |
1635 _6A0CA8_lod_unused = 0; | |
1636 | |
1637 isFileOpened = false; | |
1638 fflush(pFile); | |
1639 fclose(pFile); | |
1640 pFile = 0; | |
1641 } | |
1642 } | |
1643 // 6A0CA8: using guessed type int 6A0CA8_lod_unused; | |
1644 | |
1645 | |
1646 //----- (00461B48) -------------------------------------------------------- | |
1647 unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4) | |
1648 { | |
1649 LODWriteableFile *v4; // ebx@1 | |
1650 int v5; // esi@1 | |
1651 unsigned __int8 v7; // zf@7 | |
1652 unsigned __int8 v8; // sf@7 | |
1653 const LOD::Directory *v9; // edi@9 | |
1654 int v10; // eax@9 | |
1655 unsigned __int8 v11; // of@15 | |
1656 unsigned __int16 v12; // dx@17 | |
1657 LOD::Directory *v13; // eax@17 | |
1658 unsigned __int16 v14; // cx@17 | |
1659 int v15; // edi@27 | |
1660 unsigned int v16; // eax@27 | |
1661 int v17; // eax@29 | |
1662 int v18; // edx@31 | |
1663 int v19; // eax@31 | |
1664 void *v20; // edi@32 | |
1665 LOD::Directory *v21; // edi@34 | |
1666 signed int v22; // esi@34 | |
1667 int v23; // eax@34 | |
1668 LOD::Directory *v24; // ecx@35 | |
1669 int v25; // edx@35 | |
1670 __int32 v26; // eax@37 | |
1671 int i; // esi@39 | |
1672 __int32 v28; // esi@46 | |
1673 char pFilename[256]; // [sp+Ch] [bp-230h]@22 | |
1674 char NewFilename[256]; // [sp+10Ch] [bp-130h]@51 | |
1675 //LOD::Directory Str; // [sp+20Ch] [bp-30h]@27 | |
1676 size_t v33; // [sp+22Ch] [bp-10h]@27 | |
1677 int v34; // [sp+230h] [bp-Ch]@7 | |
1678 __int32 v35; // [sp+234h] [bp-8h]@8 | |
1679 int v36; // [sp+238h] [bp-4h]@7 | |
1680 size_t Count; // [sp+244h] [bp+8h]@40 | |
1681 __int32 Countc; // [sp+244h] [bp+8h]@46 | |
1682 size_t Countb; // [sp+244h] [bp+8h]@47 | |
1683 FILE *pFile; // [sp+24Ch] [bp+10h]@22 | |
1684 | |
1685 v4 = this; | |
1686 v5 = 0; | |
1687 if ( !this->isFileOpened ) | |
1688 return 1; | |
1689 if ( !this->pSubIndices ) | |
1690 return 2; | |
1691 if ( !this->pIOBuffer || !this->uIOBufferSize ) | |
1692 return 3; | |
1693 v7 = this->uNumSubIndices == 0; | |
568 | 1694 v8 = false;//this->uNumSubIndices != 0; // v8 = (this->uNumSubIndices & 0x80000000u) != 0; |
0 | 1695 v36 = 0; |
1696 v34 = 0; | |
1697 if ( v8 | v7 ) | |
1698 { | |
1699 v9 = pDir; | |
1700 goto LABEL_22; | |
1701 } | |
1702 v35 = 0; | |
1703 while ( 1 ) | |
1704 { | |
1705 v9 = pDir; | |
568 | 1706 v10 = _strcmpi(v4->pSubIndices[v5].pFilename + v35, pDir->pFilename); |
0 | 1707 if ( v10 ) |
1708 { | |
1709 if ( v10 > 0 ) | |
1710 goto LABEL_22; | |
1711 goto LABEL_15; | |
1712 } | |
1713 if ( !a4 ) | |
1714 goto LABEL_20; | |
1715 if ( a4 == 1 ) | |
1716 break; | |
1717 if ( a4 == 2 ) | |
1718 return 4; | |
1719 LABEL_15: | |
1720 v35 += 32; | |
1721 ++v5; | |
1722 v11 = v5 >= v4->uNumSubIndices; | |
17 | 1723 v8 = (v5 - v4->uNumSubIndices) != 0;//v8 = ((v5 - v4->uNumSubIndices) & 0x80000000u) != 0; |
0 | 1724 v34 = v5; |
568 | 1725 //if ( !(v8 ^ v11) ) |
1726 if (v5 >= v4->uNumSubIndices) | |
0 | 1727 goto LABEL_22; |
1728 } | |
1729 v12 = pDir->uNumSubIndices; | |
1730 v13 = &v4->pSubIndices[v5]; | |
1731 v14 = v13->uNumSubIndices; | |
1732 if ( v14 >= v12 && (v14 != v12 || (unsigned __int16)v13->word_00001E >= pDir->word_00001E) ) | |
1733 return 4; | |
1734 LABEL_20: | |
1735 v36 = 1; | |
1736 LABEL_22: | |
1737 strcpy(pFilename, "lod.tmp"); | |
1738 pFile = fopen(pFilename, "wb+"); | |
1739 if ( !pFile ) | |
1740 return 5; | |
1741 if ( v36 ) | |
1742 v35 = v4->pSubIndices[v5].uDataSize; | |
1743 else | |
1744 v35 = 0; | |
1745 v33 = v9->uDataSize; | |
1746 v15 = v33 - v35; | |
1747 | |
1748 LOD::Directory Str; // [sp+20Ch] [bp-30h]@27 | |
1749 //LOD::Directory::LOD::Directory(&Str); | |
1750 | |
1751 strcpy((char *)&Str, "chapter"); | |
1752 v16 = v4->uLODDataSize; | |
1753 Str.uNumSubIndices = LOWORD(v4->uNumSubIndices); | |
1754 Str.dword_000018 = 0; | |
1755 Str.word_00001E = 0; | |
1756 if ( !v36 ) | |
1757 { | |
1758 ++Str.uNumSubIndices; | |
1759 v15 += 32; | |
1760 } | |
1761 v7 = v36 == 0; | |
1762 Str.uDataSize = v15 + v16; | |
1763 Str.uOfsetFromSubindicesStart = 288; | |
1764 v17 = (signed __int16)Str.uNumSubIndices; | |
1765 v4->uNumSubIndices = (signed __int16)Str.uNumSubIndices; | |
1766 if ( v7 && v17 > v5 ) | |
1767 { | |
1768 v18 = v17; | |
1769 v19 = v17 - v5; | |
1770 do | |
1771 { | |
1772 v20 = &v4->pSubIndices[v18]; | |
1773 --v18; | |
1774 --v19; | |
1775 memcpy(v20, (char *)v20 - 32, 0x20u); | |
1776 } | |
1777 while ( v19 ); | |
1778 v5 = v34; | |
1779 } | |
1780 v21 = v4->pSubIndices; | |
1781 v34 = 32 * v5; | |
1782 memcpy(&v21[v5], pDir, sizeof(v21[v5])); | |
1783 v22 = 0; | |
1784 v23 = 32 * v4->uNumSubIndices; | |
1785 if ( (signed int)v4->uNumSubIndices > 0 ) | |
1786 { | |
1787 v24 = v4->pSubIndices; | |
1788 v25 = 0; | |
1789 do | |
1790 { | |
1791 v24[v25].uOfsetFromSubindicesStart = v23; | |
1792 v24 = v4->pSubIndices; | |
1793 v23 += v24[v25].uDataSize; | |
1794 ++v22; | |
1795 ++v25; | |
1796 } | |
1797 while ( v22 < (signed int)v4->uNumSubIndices ); | |
1798 } | |
1799 fwrite(&v4->header, 0x100u, 1u, pFile); | |
1800 fwrite(&Str, 0x20, 1, pFile); | |
1801 fseek(v4->pFile, Str.uOfsetFromSubindicesStart, 0); | |
1802 fwrite(v4->pSubIndices, 0x20u, v4->uNumSubIndices, pFile); | |
1803 v26 = 32 * v4->uNumSubIndices; | |
1804 if ( !v36 ) | |
1805 v26 -= 32; | |
1806 fseek(v4->pFile, v26, 1); | |
1807 for ( i = *(unsigned int *)((char *)&v4->pSubIndices->uOfsetFromSubindicesStart + v34) | |
1808 - v4->pSubIndices->uOfsetFromSubindicesStart; i > 0; i -= Count ) | |
1809 { | |
1810 Count = v4->uIOBufferSize; | |
1811 if ( i <= (signed int)v4->uIOBufferSize ) | |
1812 Count = i; | |
1813 fread(v4->pIOBuffer, 1u, Count, v4->pFile); | |
1814 fwrite(v4->pIOBuffer, 1u, Count, pFile); | |
1815 } | |
1816 fwrite(pDirData, 1u, v33, pFile); | |
1817 if ( v36 ) | |
1818 fseek(v4->pFile, v35, 1); | |
1819 Countc = ftell(v4->pFile); | |
1820 fseek(v4->pFile, 0, 2); | |
1821 v28 = ftell(v4->pFile) - Countc; | |
1822 fseek(v4->pFile, Countc, 0); | |
1823 while ( v28 > 0 ) | |
1824 { | |
1825 Countb = v4->uIOBufferSize; | |
1826 if ( v28 <= (signed int)v4->uIOBufferSize ) | |
1827 Countb = v28; | |
1828 fread(v4->pIOBuffer, 1u, Countb, v4->pFile); | |
1829 fwrite(v4->pIOBuffer, 1u, Countb, pFile); | |
1830 v28 -= Countb; | |
1831 } | |
1832 strcpy(NewFilename, (const char *)v4->pLODName); | |
1833 fclose(pFile); | |
1834 v4->CloseWriteFile(); | |
1835 remove(NewFilename); | |
1836 rename(pFilename, NewFilename); | |
1837 v4->CloseWriteFile(); | |
1838 v4->LoadFile(v4->pLODName, 0); | |
1839 return 0; | |
1840 } | |
1841 | |
1842 | |
1843 //----- (00461A43) -------------------------------------------------------- | |
1844 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting) | |
1845 { | |
1846 LODWriteableFile *v3; // esi@1 | |
1847 FILE *pFile_dup; // eax@4 | |
1848 unsigned int v5; // ecx@5 | |
1849 __int32 v6; // eax@5 | |
1850 FILE *v7; // ST00_4@5 | |
1851 size_t v8; // edi@5 | |
1852 const char *v10; // [sp-4h] [bp-30h]@2 | |
1853 | |
1854 v3 = this; | |
1855 if ( bWriting & 1 ) | |
1856 v10 = "rb"; | |
1857 else | |
1858 v10 = "rb+"; | |
1859 pFile_dup = fopen(pFilename, v10); | |
1860 v3->pFile = pFile_dup; | |
1861 if ( !pFile_dup ) | |
1862 { | |
1863 isFileOpened = false; | |
1864 return 0; | |
1865 } | |
1866 strcpy(pLODName, pFilename); | |
1867 fread(&header, 0x100u, 1u, v3->pFile); | |
1868 | |
1869 LOD::Directory dir; // [sp+Ch] [bp-20h]@5 | |
1870 //LOD::Directory::LOD::Directory(&dir); | |
1871 | |
1872 fread(&dir, 0x20u, 1u, v3->pFile); | |
1873 fseek(v3->pFile, 0, 0); | |
1874 isFileOpened = 1; | |
1875 strcpy((char *)v3->pContainerName, "chapter"); | |
1876 v5 = (signed __int16)dir.uNumSubIndices; | |
1877 v6 = dir.uOfsetFromSubindicesStart; | |
1878 v3->uCurrentIndexDir = 0; | |
1879 v3->uOffsetToSubIndex = v6; | |
1880 v7 = v3->pFile; | |
1881 v3->uNumSubIndices = v5; | |
1882 v3->uLODDataSize = dir.uDataSize; | |
1883 fseek(v7, v6, SEEK_SET); | |
1884 v8 = v3->uNumSubIndices; | |
1885 if ( (signed int)v8 > 300 ) | |
1886 { | |
1887 MessageBoxA(0, "LODchapterPages exceed 300", "LOD::File", MB_ICONEXCLAMATION); | |
1888 fclose(v3->pFile); | |
1889 return 0; | |
1890 } | |
1891 fread(pSubIndices, 0x20u, v8, v3->pFile); | |
1892 return 1; | |
1893 } | |
1894 | |
1895 | |
1896 //----- (00461A11) -------------------------------------------------------- | |
1897 void LOD::File::FreeSubIndexAndIO() | |
1898 { | |
1899 void *v1; // edi@1 | |
1900 LOD::Directory **v2; // esi@1 | |
1901 | |
1902 v1 = this; | |
1903 v2 = &this->pSubIndices; | |
1904 pAllocator->FreeChunk(this->pSubIndices); | |
1905 v1 = (char *)v1 + 264; | |
1906 pAllocator->FreeChunk(pIOBuffer);// delete [] pIOBuffer; | |
1907 pIOBuffer = nullptr; | |
1908 pSubIndices = nullptr; | |
1909 } | |
1910 | |
1911 | |
1912 //----- (00461954) -------------------------------------------------------- | |
1913 void LOD::File::AllocSubIndicesAndIO(unsigned int uNumSubIndices, unsigned int uBufferSize) | |
1914 { | |
1915 //LOD::File *v3; // esi@1 | |
1916 LOD::Directory *pSubIndices_dup; // eax@3 | |
1917 char v5; // zf@3 | |
1918 | |
1919 //v3 = this; | |
1920 if (pSubIndices) | |
1921 { | |
1922 MessageBoxA(0, "Attempt to reset a LOD subindex!", "MM6", MB_ICONEXCLAMATION); | |
1923 pAllocator->FreeChunk(pSubIndices); | |
1924 pSubIndices = nullptr; | |
1925 } | |
1926 pSubIndices_dup = (LOD::Directory *)pAllocator->AllocNamedChunk( | |
1927 pSubIndices, | |
1928 32 * uNumSubIndices, | |
1929 "LODsub"); | |
1930 v5 = pIOBuffer == 0; | |
1931 pSubIndices = pSubIndices_dup; | |
1932 if ( !v5 ) | |
1933 { | |
1934 MessageBoxA(0, "Attempt to reset a LOD IObuffer!", "MM6", MB_ICONEXCLAMATION); | |
1935 pAllocator->FreeChunk(pIOBuffer); | |
1936 pIOBuffer = 0; | |
1937 uIOBufferSize = 0; | |
1938 } | |
1939 if ( uBufferSize ) | |
1940 { | |
1941 pIOBuffer = (unsigned __int8 *)pAllocator->AllocNamedChunk(pIOBuffer, uBufferSize, "LODio"); | |
1942 uIOBufferSize = uBufferSize; | |
1943 } | |
1944 } | |
1945 | |
1946 | |
1947 | |
1948 //----- (0046188A) -------------------------------------------------------- | |
1949 int LOD::File::LoadSubIndices(const char *pContainer) | |
1950 { | |
415 | 1951 |
0 | 1952 unsigned int uDir; // edi@1 |
415 | 1953 LOD::Directory *curr_index; // eax@7 |
0 | 1954 |
415 | 1955 |
0 | 1956 ResetSubIndices(); |
1957 uDir = 0; | |
415 | 1958 |
1959 if ( header.uNumIndices <= 0) | |
1960 return 3; | |
0 | 1961 else |
415 | 1962 { |
1963 while (stricmp(pContainer, pRoot[uDir].pFilename)) | |
1964 { | |
1965 ++uDir; | |
1966 if (uDir >= header.uNumIndices ) | |
1967 return 3; | |
1968 } | |
1969 strcpy( pContainerName, pContainer); | |
1970 uCurrentIndexDir = uDir; | |
1971 curr_index=(LOD::Directory *)&pRoot[uDir]; | |
1972 uOffsetToSubIndex =curr_index->uOfsetFromSubindicesStart ; | |
1973 uNumSubIndices =curr_index->uNumSubIndices;// *(_WORD *)(v8 + 28); | |
1974 fseek( pFile, uOffsetToSubIndex, 0); | |
1975 pSubIndices = (LOD::Directory *)pAllocator->AllocNamedChunk(pSubIndices, sizeof(LOD::Directory)*(uNumSubIndices + 5), "LOD Index"); | |
1976 | |
1977 if ( pSubIndices) | |
1978 fread( pSubIndices, sizeof(LOD::Directory), uNumSubIndices, pFile); | |
1979 return 0; | |
1980 } | |
0 | 1981 } |
1982 | |
1983 //----- (004617D5) -------------------------------------------------------- | |
1984 bool LOD::File::LoadHeader(const char *pFilename, bool bWriting) | |
1985 { | |
1986 LOD::File *this_dup; // esi@1 | |
1987 FILE *pFile_dup; // eax@6 | |
1988 void *pRoot_dup; // eax@7 | |
1989 const char *v6; // [sp-4h] [bp-Ch]@4 | |
1990 FILE *v7; // [sp-4h] [bp-Ch]@7 | |
1991 | |
1992 this_dup = this; | |
1993 if ( this->isFileOpened ) | |
1994 Close(); | |
1995 if ( bWriting & 1 ) | |
1996 v6 = "rb"; | |
1997 else | |
1998 v6 = "rb+"; | |
1999 pFile_dup = fopen(pFilename, v6); | |
2000 this_dup->pFile = pFile_dup; | |
2001 if ( pFile_dup ) | |
2002 { | |
2003 strcpy(this_dup->pLODName, pFilename); | |
2004 fread(&this_dup->header, 0x100u, 1u, this_dup->pFile); | |
2005 pRoot_dup = pAllocator->AllocNamedChunk(this_dup->pRoot, 0xA0u, "LOD CArray"); | |
2006 this_dup->pRoot = (LOD::Directory *)pRoot_dup; | |
2007 v7 = this_dup->pFile; | |
2008 if ( pRoot_dup ) | |
2009 { | |
2010 fread(pRoot_dup, 0x20u, this_dup->header.uNumIndices, v7); | |
2011 fseek(this_dup->pFile, 0, 0); | |
2012 this_dup->isFileOpened = 1; | |
2013 return false; | |
2014 } | |
2015 else | |
2016 { | |
2017 fclose(v7); | |
2018 return true; | |
2019 } | |
2020 } | |
2021 return true; | |
2022 } | |
2023 | |
2024 | |
2025 //----- (004617B6) -------------------------------------------------------- | |
2026 void LOD::FileHeader::Reset() | |
2027 { | |
2028 this->pSignature[0] = 0; | |
2029 this->LodVersion[0] = 0; | |
2030 this->LodDescription[0] = 0; | |
2031 this->LODSize = 0; | |
2032 this->dword_0000A8 = 0; | |
2033 this->uNumIndices = 0; | |
2034 } | |
2035 | |
2036 //----- (00461790) -------------------------------------------------------- | |
2037 LOD::File::~File() | |
2038 { | |
2039 LOD::File *v1; // esi@1 | |
2040 | |
2041 v1 = this; | |
2042 if ( this->isFileOpened ) | |
2043 { | |
2044 fclose(this->pFile); | |
2045 pAllocator->FreeChunk(v1->pSubIndices); | |
2046 } | |
2047 } | |
2048 | |
2049 | |
2050 //----- (0046175B) -------------------------------------------------------- | |
2051 LOD::File::File(): | |
2052 pRoot(nullptr), | |
2053 isFileOpened(false) | |
2054 { | |
2055 LOD::File *v1; // esi@1 | |
2056 | |
2057 memset(pLODName, 0, 256); | |
2058 memset(pContainerName, 0, 16); | |
2059 v1 = this; | |
2060 v1->pFile = 0; | |
2061 v1->pSubIndices = 0; | |
2062 v1->pIOBuffer = 0; | |
2063 v1->isFileOpened = 0; | |
2064 v1->uIOBufferSize = 0; | |
2065 Close(); | |
2066 } | |
2067 | |
2068 | |
2069 //----- (00461743) -------------------------------------------------------- | |
2070 LOD::Directory *LOD::Directory::Reset() | |
2071 { | |
2072 LOD::Directory *result; // eax@1 | |
2073 | |
2074 result = this; | |
2075 this->pFilename[0] = 0; | |
2076 this->uOfsetFromSubindicesStart = 0; | |
2077 this->uDataSize = 0; | |
2078 this->dword_000018 = 0; | |
2079 this->uNumSubIndices = 0; | |
2080 this->word_00001E = 0; | |
2081 return result; | |
2082 } | |
2083 | |
2084 | |
2085 //----- (0046172B) -------------------------------------------------------- | |
2086 LOD::Directory::Directory() | |
2087 { | |
2088 memset(pFilename, 0, 16); | |
2089 this->pFilename[0] = 0; | |
2090 this->uOfsetFromSubindicesStart = 0; | |
2091 this->uDataSize = 0; | |
2092 this->uNumSubIndices = 0; | |
2093 this->dword_000018 = 0; | |
2094 this->word_00001E = 0; | |
2095 } | |
2096 | |
2097 //----- (0046165E) -------------------------------------------------------- | |
2098 int LOD::File::CalcIndexFast(int startIndex, int maxIndex, const char *pContainerName) | |
2099 { | |
2100 int v4; // esi@1 | |
2101 int v5; // ebx@2 | |
2102 int result; // eax@2 | |
2103 int v7; // edi@10 | |
2104 int v8; // esi@11 | |
2105 int v9; // esi@17 | |
2106 LOD::File *v10; // [sp+Ch] [bp-4h]@1 | |
2107 | |
2108 v4 = startIndex; | |
2109 v10 = this; | |
2110 while ( 1 ) // binary search in LOD indices | |
2111 { | |
2112 while ( 1 ) | |
2113 { | |
2114 v5 = maxIndex - v4; | |
2115 result = _strcmpi((const char *)pContainerName, (const char *)(&v10->pSubIndices[(maxIndex - v4) / 2] + v4)); | |
2116 if ( !result ) | |
2117 _6A0CA4_lod_binary_search = (maxIndex - v4) / 2 + v4; | |
2118 if ( v4 == maxIndex ) | |
2119 goto LABEL_14; | |
2120 if ( result < 0 ) | |
2121 break; | |
2122 if ( v5 <= 4 ) | |
2123 { | |
2124 v7 = v4; | |
2125 if ( v4 < maxIndex ) | |
2126 { | |
2127 v9 = v4; | |
2128 do | |
2129 { | |
2130 result = _strcmpi((const char *)pContainerName, (const char *)&v10->pSubIndices[v9]); | |
2131 if ( !result ) | |
2132 goto LABEL_21; | |
2133 ++v7; | |
2134 ++v9; | |
2135 } | |
2136 while ( v7 < maxIndex ); | |
2137 } | |
2138 LABEL_14: | |
2139 _6A0CA4_lod_binary_search = -1; | |
2140 return result; | |
2141 } | |
2142 v4 += (maxIndex - v4) / 2; | |
2143 } | |
2144 if ( v5 <= 4 ) | |
2145 break; | |
2146 maxIndex = (maxIndex - v4) / 2 + v4; | |
2147 } | |
2148 v7 = v4; | |
2149 if ( v4 >= maxIndex ) | |
2150 goto LABEL_14; | |
2151 v8 = v4; | |
2152 while ( 1 ) | |
2153 { | |
2154 result = _strcmpi((const char *)pContainerName, (const char *)&v10->pSubIndices[v8]); | |
2155 if ( !result ) | |
2156 break; | |
2157 ++v7; | |
2158 ++v8; | |
2159 if ( v7 >= maxIndex ) | |
2160 goto LABEL_14; | |
2161 } | |
2162 LABEL_21: | |
2163 _6A0CA4_lod_binary_search = v7; | |
2164 return result; | |
2165 } | |
2166 // 6A0CA4: using guessed type int _6A0CA4_lod_binary_search; | |
2167 | |
2168 | |
2169 //----- (0046161C) -------------------------------------------------------- | |
2170 bool LOD::File::DoesContainerExist(const char *pContainer) | |
2171 { | |
2172 LOD::File *this_dup; // esi@1 | |
2173 int i; // ebx@1 | |
2174 signed int i_dup; // edi@1 | |
2175 bool result; // eax@4 | |
2176 | |
2177 this_dup = this; | |
2178 i = 0; | |
2179 i_dup = 0; | |
2180 if ( (signed int)this->uNumSubIndices <= 0 ) | |
2181 { | |
2182 LABEL_4: | |
2183 result = 0; | |
2184 } | |
2185 else | |
2186 { | |
2187 while ( _strcmpi((const char *)pContainer, (const char *)&this_dup->pSubIndices[i]) ) | |
2188 { | |
2189 ++i_dup; | |
2190 ++i; | |
2191 if ( i_dup >= (signed int)this_dup->uNumSubIndices ) | |
2192 goto LABEL_4; | |
2193 } | |
2194 result = 1; | |
2195 } | |
2196 return result; | |
2197 } | |
2198 | |
2199 | |
2200 //----- (00461397) -------------------------------------------------------- | |
2201 int LODFile_Sprites::_461397() | |
2202 { | |
2203 int result; // eax@1 | |
737 | 2204 //int *pfield_ECA0; // edi@1 |
0 | 2205 int v3; // esi@1 |
2206 int v4; // ecx@3 | |
2207 | |
2208 result = this->uNumLoadedSprites; | |
737 | 2209 //pfield_ECA0 = &this->field_ECA0; |
0 | 2210 v3 = this->field_ECA0; |
2211 this->field_ECA8 = result; | |
2212 if ( result < v3 ) | |
2213 this->field_ECA8 = v3; | |
2214 v4 = this->field_ECA4; | |
2215 if ( v3 < v4 ) | |
737 | 2216 field_ECA0 = v4; |
0 | 2217 return result; |
2218 } | |
2219 | |
2220 //----- (00461580) -------------------------------------------------------- | |
2221 FILE *LOD::File::FindContainer(const char *pContainerName, bool bLinearSearch) | |
2222 { | |
2223 unsigned int v4; // eax@4 | |
2224 if (!isFileOpened) | |
2225 return 0; | |
2226 | |
2227 | |
2228 if (bLinearSearch) | |
2229 { | |
2230 for (uint i = 0; i < uNumSubIndices; ++i) | |
2231 if (!strcmpi(pContainerName, pSubIndices[i].pFilename)) | |
2232 { | |
2233 v4 = pSubIndices[i].uOfsetFromSubindicesStart; | |
2234 fseek(pFile, uOffsetToSubIndex + v4, SEEK_SET); | |
2235 return pFile; | |
2236 } | |
2237 | |
2238 return nullptr; | |
2239 } | |
2240 else | |
2241 { | |
2242 CalcIndexFast(0, uNumSubIndices, pContainerName); | |
2243 if ( _6A0CA4_lod_binary_search < 0 ) | |
2244 return 0; | |
2245 v4 = pSubIndices[_6A0CA4_lod_binary_search].uOfsetFromSubindicesStart; | |
2246 fseek(pFile, uOffsetToSubIndex + v4, SEEK_SET); | |
2247 return pFile; | |
2248 } | |
2249 } | |
2250 | |
2251 //----- (0041097D) -------------------------------------------------------- | |
2252 void LODFile_IconsBitmaps::SetupPalettes(unsigned int uTargetRBits, unsigned int uTargetGBits, unsigned int uTargetBBits) | |
2253 { | |
2254 int v4; // edx@1 | |
2255 LODFile_IconsBitmaps *v5; // esi@1 | |
2256 int v6; // ecx@1 | |
2257 unsigned __int8 v7; // zf@4 | |
2258 unsigned __int8 v8; // sf@4 | |
2259 unsigned __int16 **v9; // edi@5 | |
2260 FILE *v10; // eax@7 | |
2261 FILE *v11; // ebx@7 | |
2262 signed int v12; // ebx@8 | |
2263 int v13; // eax@9 | |
2264 int v14; // edx@9 | |
2265 int v16; // [sp+4Ch] [bp-8h]@4 | |
2266 FILE *File; // [sp+50h] [bp-4h]@7 | |
2267 | |
2268 v4 = uTargetGBits; | |
2269 v5 = this; | |
2270 v6 = uTargetBBits; | |
2271 if ( v5->uTextureRedBits != uTargetRBits | |
2272 || v5->uTextureGreenBits != uTargetGBits | |
2273 || v5->uTextureBlueBits != uTargetBBits ) | |
2274 { | |
2275 v16 = 0; | |
2276 v7 = v5->uNumLoadedFiles == 0; | |
2277 v8 = (v5->uNumLoadedFiles & 0x80000000u) != 0; | |
2278 v5->uTextureRedBits = uTargetRBits; | |
2279 v5->uTextureGreenBits = v4; | |
2280 v5->uTextureBlueBits = v6; | |
2281 if ( !(v8 | v7) ) | |
2282 { | |
2283 v9 = &v5->pTextures[0].pPalette16; | |
2284 do | |
2285 { | |
2286 Texture DstBuf; // [sp+4h] [bp-50h]@6 | |
2287 //Texture::Texture(&DstBuf); | |
2288 | |
2289 if ( *v9 ) | |
2290 { | |
2291 v10 = FindContainer((const char *)v9 - 64, 0); | |
2292 v11 = v10; | |
2293 File = v10; | |
2294 if ( v10 ) | |
2295 { | |
2296 fread(&DstBuf, 1u, 0x30u, v10); | |
2297 fseek(v11, DstBuf.uTextureSize, 1); | |
2298 v12 = 0; | |
2299 do | |
2300 { | |
2301 fread((char *)&uTargetRBits + 3, 1u, 1u, File); | |
2302 fread((char *)&uTargetBBits + 3, 1u, 1u, File); | |
2303 v13 = fread((char *)&uTargetGBits + 3, 1u, 1u, File); | |
2304 LOWORD(v13) = (unsigned __int8)(BYTE3(uTargetRBits) >> (8 - LOBYTE(v5->uTextureRedBits))); | |
2305 (*v9)[v12] = v13 << (LOBYTE(v5->uTextureGreenBits) + LOBYTE(v5->uTextureBlueBits)); | |
2306 LOWORD(v14) = (unsigned __int8)(BYTE3(uTargetBBits) >> (8 - LOBYTE(v5->uTextureGreenBits))); | |
2307 (*v9)[v12] |= v14 << v5->uTextureBlueBits; | |
2308 (*v9)[v12] |= BYTE3(uTargetGBits) >> (8 - LOBYTE(v5->uTextureBlueBits)); | |
2309 ++v12; | |
2310 } | |
2311 while ( v12 < 256 ); | |
2312 } | |
2313 } | |
2314 ++v16; | |
2315 v9 += 18; | |
2316 } | |
2317 while ( v16 < (signed int)v5->uNumLoadedFiles ); | |
2318 } | |
2319 } | |
2320 } | |
2321 | |
2322 | |
2323 | |
2324 //----- (0041088B) -------------------------------------------------------- | |
2325 void *LOD::File::LoadRaw(const char *pContainer, int a3) | |
2326 { | |
2327 LOD::File *v3; // esi@1 | |
2328 FILE *v4; // eax@1 | |
2329 FILE *v5; // esi@1 | |
2330 void *v6; // eax@5 | |
2331 void *v7; // ebx@7 | |
2332 void *v8; // edi@7 | |
2333 void *v9; // eax@9 | |
2334 Texture DstBuf; // [sp+Ch] [bp-4Ch]@1 | |
2335 FILE *File; // [sp+54h] [bp-4h]@1 | |
2336 unsigned int Argsa; // [sp+60h] [bp+8h]@3 | |
2337 | |
2338 v3 = this; | |
2339 v4 = FindContainer(pContainer, 0); | |
2340 v5 = v4; | |
2341 File = v4; | |
2342 if ( !v4 ) | |
2343 Abortf("Unable to load %s", pContainer); | |
2344 fread(&DstBuf, 1u, 0x30u, v4); | |
2345 Argsa = DstBuf.uTextureSize; | |
2346 if ( DstBuf.uDecompressedSize ) | |
2347 { | |
2348 if ( a3 ) | |
705 | 2349 v6 = malloc(DstBuf.uDecompressedSize+1); |
0 | 2350 else |
705 | 2351 v6 = pAllocator->AllocNamedChunk(0, DstBuf.uDecompressedSize+1, DstBuf.pName); |
0 | 2352 v7 = v6; |
705 | 2353 v8 = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize+1, DstBuf.pName); |
0 | 2354 fread(v8, 1u, Argsa, File); |
2355 zlib::MemUnzip(v7, &DstBuf.uDecompressedSize, v8, DstBuf.uTextureSize); | |
2356 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
2357 pAllocator->FreeChunk(v8); | |
2358 } | |
2359 else | |
2360 { | |
2361 if ( a3 ) | |
705 | 2362 v9 = malloc(DstBuf.uTextureSize+1); |
0 | 2363 else |
705 | 2364 v9 = pAllocator->AllocNamedChunk(0, DstBuf.uTextureSize+1, DstBuf.pName); |
0 | 2365 v7 = v9; |
2366 fread(v9, 1u, Argsa, v5); | |
2367 } | |
2368 return v7; | |
2369 } | |
2370 | |
2371 | |
2372 | |
2373 //----- (00410522) -------------------------------------------------------- | |
2374 int LODFile_IconsBitmaps::_410522(Texture *pDst, const char *pContainer, unsigned int uTextureType) | |
2375 { | |
2376 LODFile_IconsBitmaps *v4; // edi@1 | |
2377 Texture *v5; // esi@5 | |
2378 unsigned int v6; // eax@5 | |
2379 void *v7; // eax@6 | |
2380 unsigned int v8; // ST28_4@6 | |
2381 void *v9; // ST2C_4@6 | |
2382 unsigned __int8 *v10; // eax@7 | |
2383 FILE *v11; // ST28_4@7 | |
2384 void *v12; // eax@9 | |
2385 FILE *v13; // ST28_4@9 | |
2386 signed int v14; // eax@12 | |
2387 int v15; // ecx@12 | |
2388 int v16; // ecx@12 | |
2389 int v17; // eax@12 | |
2390 signed int v18; // ebx@14 | |
2391 int v19; // eax@15 | |
2392 int v20; // edx@15 | |
2393 signed int v21; // ecx@18 | |
2394 signed int v22; // ecx@23 | |
2395 char Args[100]; // [sp+4h] [bp-68h]@3 | |
2396 FILE *File; // [sp+68h] [bp-4h]@1 | |
2397 | |
2398 v4 = this; | |
2399 File = FindContainer(pContainer, 0); | |
2400 if ( !File ) | |
2401 { | |
2402 File = FindContainer("pending", 0); | |
2403 if ( !File ) | |
2404 { | |
2405 sprintf(Args, "Can't find %s!", pContainer); | |
2406 Abortf(Args); | |
2407 } | |
2408 } | |
2409 v5 = pDst; | |
2410 fread(pDst, 1u, 0x30u, File); | |
2411 strcpy(v5->pName, pContainer); | |
2412 pDst = (Texture *)v5->uTextureSize; | |
2413 v6 = v5->uDecompressedSize; | |
710 | 2414 v5->pLevelOfDetail0_prolly_alpha_mask = 0; |
0 | 2415 if ( v6 ) |
2416 { | |
2417 v7 = operator new(v6); | |
2418 v8 = v5->uTextureSize; | |
710 | 2419 v5->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v7; |
0 | 2420 pContainer = (const char *)operator new(v8); |
2421 fread((void *)pContainer, 1u, (size_t)pDst, File); | |
710 | 2422 zlib::MemUnzip(v5->pLevelOfDetail0_prolly_alpha_mask, &v5->uDecompressedSize, pContainer, v5->uTextureSize); |
0 | 2423 v9 = (void *)pContainer; |
2424 v5->uTextureSize = v5->uDecompressedSize; | |
2425 free(v9); | |
2426 } | |
2427 else | |
2428 { | |
2429 v10 = (unsigned __int8 *)operator new(0); | |
2430 v11 = File; | |
710 | 2431 v5->pLevelOfDetail0_prolly_alpha_mask = v10; |
0 | 2432 fread(v10, 1u, (size_t)pDst, v11); |
2433 } | |
2434 v5->pPalette24 = 0; | |
2435 if ( uTextureType == 1 ) | |
2436 { | |
2437 v12 = operator new(0x300u); | |
2438 v13 = File; | |
2439 v5->pPalette24 = (unsigned __int8 *)v12; | |
2440 fread(v12, 1u, 0x300u, v13); | |
2441 LABEL_10: | |
2442 v5->pPalette16 = 0; | |
2443 goto LABEL_11; | |
2444 } | |
2445 if ( uTextureType != 2 ) | |
2446 goto LABEL_10; | |
2447 v18 = 0; | |
2448 v5->pPalette16 = 0; | |
2449 v5->pPalette16 = (unsigned __int16 *)operator new(0x400u); | |
2450 do | |
2451 { | |
2452 fread((char *)&pContainer + 3, 1u, 1u, File); | |
2453 fread((char *)&uTextureType + 3, 1u, 1u, File); | |
2454 v19 = fread((char *)&pDst + 3, 1u, 1u, File); | |
2455 LOWORD(v19) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2456 v5->pPalette16[v18] = v19 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2457 LOWORD(v20) = (unsigned __int8)(BYTE3(uTextureType) >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2458 v5->pPalette16[v18] += v20 << v4->uTextureBlueBits; | |
2459 v5->pPalette16[v18] += (unsigned __int8)(BYTE3(pDst) >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2460 ++v18; | |
2461 } | |
2462 while ( v18 < 256 ); | |
2463 LABEL_11: | |
2464 if ( v5->pBits & 2 ) | |
2465 { | |
2466 v14 = v5->uSizeOfMaxLevelOfDetail; | |
710 | 2467 v15 = (int)&v5->pLevelOfDetail0_prolly_alpha_mask[v14]; |
0 | 2468 v5->pLevelOfDetail1 = (unsigned __int8 *)v15; |
2469 v16 = (v14 >> 2) + v15; | |
2470 v5->pLevelOfDetail2 = (unsigned __int8 *)v16; | |
2471 v17 = v16 + (v14 >> 4); | |
2472 } | |
2473 else | |
2474 { | |
2475 v17 = 0; | |
2476 v5->pLevelOfDetail2 = 0; | |
2477 v5->pLevelOfDetail1 = 0; | |
2478 } | |
2479 v5->pLevelOfDetail3 = (unsigned __int8 *)v17; | |
2480 v21 = 1; | |
2481 while ( 1 << v21 != v5->uTextureWidth ) | |
2482 { | |
2483 ++v21; | |
2484 if ( v21 >= 15 ) | |
2485 goto LABEL_23; | |
2486 } | |
2487 v5->uWidthLn2 = v21; | |
2488 LABEL_23: | |
2489 v22 = 1; | |
2490 while ( 1 << v22 != v5->uTextureHeight ) | |
2491 { | |
2492 ++v22; | |
2493 if ( v22 >= 15 ) | |
2494 goto LABEL_28; | |
2495 } | |
2496 v5->uHeightLn2 = v22; | |
2497 LABEL_28: | |
2498 switch ( v5->uWidthLn2 ) | |
2499 { | |
2500 case 2: | |
2501 v5->uWidthMinus1 = 3; | |
2502 break; | |
2503 case 3: | |
2504 v5->uWidthMinus1 = 7; | |
2505 break; | |
2506 case 4: | |
2507 v5->uWidthMinus1 = 15; | |
2508 break; | |
2509 case 5: | |
2510 v5->uWidthMinus1 = 31; | |
2511 break; | |
2512 case 6: | |
2513 v5->uWidthMinus1 = 63; | |
2514 break; | |
2515 case 7: | |
2516 v5->uWidthMinus1 = 127; | |
2517 break; | |
2518 case 8: | |
2519 v5->uWidthMinus1 = 255; | |
2520 break; | |
2521 case 9: | |
2522 v5->uWidthMinus1 = 511; | |
2523 break; | |
2524 case 10: | |
2525 v5->uWidthMinus1 = 1023; | |
2526 break; | |
2527 case 11: | |
2528 v5->uWidthMinus1 = 2047; | |
2529 break; | |
2530 case 12: | |
2531 v5->uWidthMinus1 = 4095; | |
2532 break; | |
2533 default: | |
2534 break; | |
2535 } | |
2536 switch ( v5->uHeightLn2 ) | |
2537 { | |
2538 case 2: | |
2539 v5->uHeightMinus1 = 3; | |
2540 break; | |
2541 case 3: | |
2542 v5->uHeightMinus1 = 7; | |
2543 break; | |
2544 case 4: | |
2545 v5->uHeightMinus1 = 15; | |
2546 break; | |
2547 case 5: | |
2548 v5->uHeightMinus1 = 31; | |
2549 break; | |
2550 case 6: | |
2551 v5->uHeightMinus1 = 63; | |
2552 break; | |
2553 case 7: | |
2554 v5->uHeightMinus1 = 127; | |
2555 break; | |
2556 case 8: | |
2557 v5->uHeightMinus1 = 255; | |
2558 break; | |
2559 case 9: | |
2560 v5->uHeightMinus1 = 511; | |
2561 break; | |
2562 case 10: | |
2563 v5->uHeightMinus1 = 1023; | |
2564 break; | |
2565 case 11: | |
2566 v5->uHeightMinus1 = 2047; | |
2567 break; | |
2568 case 12: | |
2569 v5->uHeightMinus1 = 4095; | |
2570 break; | |
2571 default: | |
2572 return 1; | |
2573 } | |
2574 return 1; | |
2575 } | |
2576 | |
2577 | |
2578 //----- (00410423) -------------------------------------------------------- | |
2579 void LODFile_IconsBitmaps::_410423_move_textures_to_device() | |
2580 { | |
2581 LODFile_IconsBitmaps *v1; // esi@1 | |
2582 unsigned int v2; // edi@1 | |
2583 char *v3; // ebx@2 | |
2584 size_t v4; // eax@9 | |
2585 char *v5; // ST1C_4@9 | |
2586 void *v6; // eax@12 | |
2587 signed int v7; // esi@13 | |
2588 | |
2589 v1 = this; | |
2590 v2 = this->uNumLoadedFiles - 1; | |
2591 if ( (v2 & 0x80000000u) == 0 ) | |
2592 { | |
2593 v3 = &this->pTextures[v2].pName[2]; | |
2594 do | |
2595 { | |
2596 if ( v1->ptr_011BB4[v2] ) | |
2597 { | |
2598 if ( *(v3 - 2) != 'w' || *(v3 - 1) != 't' || *v3 != 'r' || v3[1] != 'd' || v3[2] != 'r' ) | |
2599 { | |
2600 pRenderer->LoadTexture( | |
2601 v3 - 2, | |
2602 *((short *)v3 + 17), | |
2603 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2604 &v1->pHardwareTextures[v2]); | |
2605 } | |
2606 else | |
2607 { | |
2608 v4 = strlen(v3 - 2); | |
2609 v5 = (char *)operator new(v4 + 2); | |
2610 *v5 = 'h'; | |
2611 strcpy(v5 + 1, v3 - 2); | |
2612 pRenderer->LoadTexture( | |
2613 v5, | |
2614 *((short *)v3 + 17), | |
2615 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2616 &v1->pHardwareTextures[v2]); | |
2617 free(v5); | |
2618 } | |
2619 } | |
2620 --v2; | |
2621 v3 -= 72; | |
2622 } | |
2623 while ( (v2 & 0x80000000u) == 0 ); | |
2624 } | |
2625 v6 = v1->ptr_011BB4; | |
2626 if ( v6 ) | |
2627 { | |
2628 v7 = v1->uNumLoadedFiles; | |
2629 if ( v7 > 1 ) | |
2630 memset(v6, 0, v7 - 1); | |
2631 } | |
2632 } | |
2633 | |
2634 | |
2635 //----- (004103BB) -------------------------------------------------------- | |
2636 void LODFile_IconsBitmaps::ReleaseHardwareTextures() | |
2637 { | |
2638 LODFile_IconsBitmaps *v1; // esi@1 | |
2639 unsigned int v2; // edi@1 | |
2640 struct IDirect3DTexture2 **v3; // eax@2 | |
2641 struct IDirect3DTexture2 *v4; // eax@3 | |
2642 struct IDirectDrawSurface **v5; // eax@5 | |
2643 struct IDirectDrawSurface *v6; // eax@6 | |
2644 | |
2645 v1 = this; | |
2646 v2 = this->uNumLoadedFiles; | |
2647 while ( 1 ) | |
2648 { | |
2649 --v2; | |
2650 if ( (v2 & 0x80000000u) != 0 ) | |
2651 break; | |
2652 v3 = v1->pHardwareTextures; | |
2653 if ( v3 ) | |
2654 { | |
2655 v4 = v3[v2]; | |
2656 if ( v4 ) | |
2657 { | |
2658 v4->Release(); | |
2659 v1->pHardwareTextures[v2] = 0; | |
2660 v1->ptr_011BB4[v2] = 1; | |
2661 } | |
2662 } | |
2663 v5 = v1->pHardwareSurfaces; | |
2664 if ( v5 ) | |
2665 { | |
2666 v6 = v5[v2]; | |
2667 if ( v6 ) | |
2668 { | |
2669 v6->Release(); | |
2670 v1->pHardwareSurfaces[v2] = 0; | |
2671 v1->ptr_011BB4[v2] = 1; | |
2672 } | |
2673 } | |
2674 } | |
2675 } | |
2676 | |
2677 | |
2678 //----- (0041033D) -------------------------------------------------------- | |
2679 void LODFile_IconsBitmaps::ReleaseLostHardwareTextures() | |
2680 { | |
2681 LODFile_IconsBitmaps *v1; // edi@1 | |
2682 unsigned int i; // ebx@1 | |
2683 struct IDirectDrawSurface **pHardwareSurfaces; // eax@2 | |
2684 int v4; // esi@3 | |
2685 struct IDirectDrawSurface *pSurface; // eax@3 | |
2686 struct IDirect3DTexture2 **v6; // eax@5 | |
2687 struct IDirect3DTexture2 *v7; // eax@6 | |
2688 | |
2689 v1 = this; | |
2690 for ( i = this->uNumLoadedFiles - 1; (i & 0x80000000u) == 0; --i ) | |
2691 { | |
2692 pHardwareSurfaces = v1->pHardwareSurfaces; | |
2693 if ( pHardwareSurfaces ) | |
2694 { | |
2695 v4 = i; | |
2696 pSurface = pHardwareSurfaces[i]; | |
2697 if ( pSurface ) | |
2698 { | |
2699 if ( pSurface->IsLost() == DDERR_SURFACELOST ) | |
2700 { | |
2701 v6 = v1->pHardwareTextures; | |
2702 if ( v6 ) | |
2703 { | |
2704 v7 = v6[v4]; | |
2705 if ( v7 ) | |
2706 { | |
2707 v7->Release(); | |
2708 v1->pHardwareTextures[v4] = 0; | |
2709 } | |
2710 } | |
2711 v1->pHardwareSurfaces[v4]->Release(); | |
2712 v1->pHardwareSurfaces[v4] = 0; | |
2713 v1->ptr_011BB4[i] = 1; | |
2714 } | |
2715 } | |
2716 } | |
2717 } | |
2718 } | |
2719 | |
2720 //----- (004101B1) -------------------------------------------------------- | |
2721 int LODFile_IconsBitmaps::ReloadTexture(Texture *pDst, const char *pContainer, int mode) | |
2722 { | |
2723 LODFile_IconsBitmaps *v4; // edi@1 | |
2724 FILE *v5; // eax@1 | |
2725 Texture *v6; // esi@2 | |
2726 unsigned int v7; // ebx@6 | |
2727 unsigned int v8; // ecx@6 | |
2728 signed int result; // eax@7 | |
2729 size_t *v10; // ebx@8 | |
2730 signed int v11; // ebx@12 | |
2731 int v12; // eax@13 | |
2732 int v13; // edx@13 | |
2733 FILE *File; // [sp+Ch] [bp-8h]@1 | |
2734 unsigned __int8 v15; // [sp+11h] [bp-3h]@13 | |
2735 unsigned __int8 v16; // [sp+12h] [bp-2h]@13 | |
2736 unsigned __int8 DstBuf; // [sp+13h] [bp-1h]@13 | |
2737 void *DstBufa; // [sp+1Ch] [bp+8h]@10 | |
2738 void *Sourcea; // [sp+20h] [bp+Ch]@10 | |
2739 unsigned int Counta; // [sp+24h] [bp+10h]@6 | |
2740 | |
2741 v4 = this; | |
2742 v5 = FindContainer(pContainer, 0); | |
2743 File = v5; | |
2744 if ( v5 | |
710 | 2745 && (v6 = pDst, pDst->pLevelOfDetail0_prolly_alpha_mask) |
0 | 2746 && mode == 2 |
2747 && pDst->pPalette16 | |
2748 && !pDst->pPalette24 | |
2749 && (v7 = pDst->uTextureSize, | |
2750 fread(pDst, 1u, 0x30u, v5), | |
2751 strcpy(pDst->pName, pContainer), | |
2752 v8 = pDst->uTextureSize, | |
2753 Counta = pDst->uTextureSize, | |
2754 (signed int)v8 <= (signed int)v7) ) | |
2755 { | |
2756 v10 = &pDst->uDecompressedSize; | |
2757 if ( !pDst->uDecompressedSize || v4->dword_011BA4 ) | |
2758 { | |
710 | 2759 fread(pDst->pLevelOfDetail0_prolly_alpha_mask, 1u, v8, File); |
0 | 2760 } |
2761 else | |
2762 { | |
2763 Sourcea = malloc(pDst->uDecompressedSize); | |
2764 DstBufa = malloc(pDst->uTextureSize); | |
2765 fread(DstBufa, 1u, Counta, File); | |
2766 zlib::MemUnzip(Sourcea, &v6->uDecompressedSize, DstBufa, v6->uTextureSize); | |
2767 v6->uTextureSize = *v10; | |
2768 free(DstBufa); | |
710 | 2769 memcpy(v6->pLevelOfDetail0_prolly_alpha_mask, Sourcea, *v10); |
0 | 2770 free(Sourcea); |
2771 } | |
2772 v11 = 0; | |
2773 do | |
2774 { | |
2775 fread(&DstBuf, 1u, 1u, File); | |
2776 fread(&v16, 1u, 1u, File); | |
2777 v12 = fread(&v15, 1u, 1u, File); | |
2778 LOWORD(v12) = (unsigned __int8)(DstBuf >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2779 v6->pPalette16[v11] = v12 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2780 LOWORD(v13) = (unsigned __int8)(v16 >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2781 v6->pPalette16[v11] += v13 << v4->uTextureBlueBits; | |
2782 v6->pPalette16[v11] += (unsigned __int8)(v15 >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2783 ++v11; | |
2784 } | |
2785 while ( v11 < 256 ); | |
2786 result = 1; | |
2787 } | |
2788 else | |
2789 { | |
2790 result = -1; | |
2791 } | |
2792 return result; | |
2793 } | |
2794 | |
2795 | |
2796 //----- (0040FC08) -------------------------------------------------------- | |
2797 int LODFile_IconsBitmaps::LoadTextureFromLOD(Texture *pOutTex, const char *pContainer, enum TEXTURE_TYPE eTextureType) | |
2798 { | |
2799 Texture *v8; // esi@3 | |
2800 size_t v11; // eax@14 | |
2801 enum TEXTURE_TYPE v12; // eax@14 | |
2802 signed int v13; // esi@14 | |
2803 unsigned int v14; // eax@21 | |
2804 unsigned int v15; // ecx@25 | |
2805 unsigned int *v16; // ebx@25 | |
2806 void *v17; // eax@27 | |
2807 unsigned int v18; // ST28_4@27 | |
2808 void *v19; // ST3C_4@27 | |
2809 Allocator *v20; // ebx@29 | |
2810 void *v21; // eax@29 | |
2811 size_t v22; // ST2C_4@29 | |
2812 const void *v23; // ecx@29 | |
2813 unsigned __int16 v24; // ax@29 | |
2814 unsigned __int16 v25; // cx@29 | |
2815 __int16 v26; // dx@29 | |
2816 unsigned int v27; // ecx@29 | |
2817 Texture *v28; // eax@29 | |
2818 unsigned int v29; // ST28_4@30 | |
2819 void *v30; // eax@30 | |
2820 unsigned int v31; // ST2C_4@30 | |
2821 void *v32; // eax@32 | |
2822 void *v33; // eax@34 | |
2823 signed int v34; // eax@37 | |
2824 unsigned __int8 *v35; // ecx@37 | |
2825 unsigned __int8 *v36; // ecx@37 | |
2826 unsigned __int8 *v37; // eax@37 | |
2827 signed int v38; // ebx@39 | |
2828 int v39; // eax@40 | |
2829 int v40; // edx@40 | |
2830 signed int v41; // ecx@43 | |
2831 signed int v42; // ecx@48 | |
2832 | |
2833 //v4 = pContainer; | |
2834 //v5 = this; | |
2835 //v6 = FindContainer(pContainer, 0); | |
2836 //File = v6; | |
2837 auto pFile = FindContainer(pContainer, false); | |
2838 if (!pFile) | |
2839 return -1; | |
2840 v8 = pOutTex; | |
2841 fread(pOutTex, 1u, 0x30u, pFile); | |
2842 strcpy(v8->pName, pContainer); | |
2843 if (pRenderer->pRenderD3D && v8->pBits & 2 && dword_011BA8) | |
2844 { | |
2845 if (!pHardwareSurfaces || !pHardwareTextures) | |
2846 { | |
2847 pHardwareSurfaces = new IDirectDrawSurface *[1000]; | |
2848 memset(pHardwareSurfaces, 0, 1000 * sizeof(IDirectDrawSurface4 *)); | |
2849 | |
2850 pHardwareTextures = new IDirect3DTexture2 *[1000]; | |
2851 memset(pHardwareTextures, 0, 1000 * sizeof(IDirect3DTexture2 *)); | |
2852 | |
2853 ptr_011BB4 = new char[1000]; | |
2854 memset(ptr_011BB4, 0, 1000); | |
2855 } | |
265 | 2856 if (strnicmp(pContainer, "wtrdr", 5))//*v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' ) |
0 | 2857 { |
265 | 2858 if (strnicmp(pContainer, "WtrTyl", 6))//if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' ) |
0 | 2859 { |
2860 v14 = uNumLoadedFiles; | |
2861 } | |
2862 else | |
2863 { | |
265 | 2864 pRenderer->hd_water_tile_id = uNumLoadedFiles; |
0 | 2865 v14 = uNumLoadedFiles; |
2866 } | |
2867 v13 = pRenderer->LoadTexture( | |
2868 pContainer, | |
2869 v8->palette_id1, | |
2870 (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], | |
2871 &pHardwareTextures[v14]); | |
2872 } | |
2873 else | |
2874 { | |
2875 v11 = strlen(pContainer); | |
2876 v12 = (enum TEXTURE_TYPE)(int)operator new(v11 + 2); | |
2877 eTextureType = v12; | |
2878 *(char *)v12 = 104; | |
2879 strcpy((char *)(v12 + 1), pContainer); | |
2880 v13 = pRenderer->LoadTexture( | |
2881 (const char *)eTextureType, | |
2882 v8->palette_id1, | |
2883 (IDirectDrawSurface4 **)&pHardwareSurfaces[uNumLoadedFiles], | |
2884 &pHardwareTextures[uNumLoadedFiles]); | |
2885 free((void *)eTextureType); | |
2886 } | |
2887 return v13; | |
2888 } | |
2889 v15 = v8->uTextureSize; | |
2890 v16 = &v8->uDecompressedSize; | |
2891 pOutTex = (Texture *)v8->uTextureSize; | |
2892 if ( !v8->uDecompressedSize || dword_011BA4 ) | |
2893 { | |
2894 v20 = pAllocator; | |
710 | 2895 v32 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0_prolly_alpha_mask, v15, v8->pName); |
2896 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v32; | |
0 | 2897 fread(v32, 1u, (size_t)pOutTex, pFile); |
2898 } | |
2899 else | |
2900 { | |
2901 v17 = malloc(v8->uDecompressedSize); | |
2902 v18 = v8->uTextureSize; | |
2903 pContainer = (const char *)v17; | |
2904 v19 = malloc(v18); | |
2905 fread(v19, 1u, (size_t)pOutTex, pFile); | |
2906 zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize); | |
2907 v8->uTextureSize = *v16; | |
2908 free(v19); | |
2909 if ( bUseLoResSprites && v8->pBits & 2 ) | |
2910 { | |
2911 v20 = pAllocator; | |
2912 pOutTex = (Texture *)(((signed int)v8->uSizeOfMaxLevelOfDetail >> 2) | |
2913 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 4) | |
2914 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 6)); | |
710 | 2915 v21 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0_prolly_alpha_mask, (unsigned int)pOutTex, v8->pName); |
0 | 2916 v22 = (size_t)pOutTex; |
2917 v23 = &pContainer[v8->uTextureWidth * v8->uTextureHeight]; | |
710 | 2918 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v21; |
0 | 2919 memcpy(v21, v23, v22); |
2920 v8->uTextureWidth = (signed __int16)v8->uTextureWidth >> 1; | |
2921 v24 = v8->uTextureWidth; | |
2922 v8->uTextureHeight = (signed __int16)v8->uTextureHeight >> 1; | |
2923 v25 = v8->uTextureHeight; | |
2924 --v8->uWidthLn2; | |
2925 --v8->uHeightLn2; | |
2926 v8->uWidthMinus1 = v24 - 1; | |
2927 v26 = v25 - 1; | |
2928 v27 = (signed __int16)v24 * (signed __int16)v25; | |
2929 v28 = pOutTex; | |
2930 v8->uHeightMinus1 = v26; | |
2931 v8->uSizeOfMaxLevelOfDetail = v27; | |
2932 v8->uTextureSize = (unsigned int)v28; | |
2933 } | |
2934 else | |
2935 { | |
2936 v29 = *v16; | |
2937 v20 = pAllocator; | |
710 | 2938 v30 = pAllocator->AllocNamedChunk(v8->pLevelOfDetail0_prolly_alpha_mask, v29, v8->pName); |
0 | 2939 v31 = v8->uDecompressedSize; |
710 | 2940 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v30; |
0 | 2941 memcpy(v30, pContainer, v31); |
2942 } | |
2943 free((void *)pContainer); | |
2944 } | |
2945 pAllocator->FreeChunk(v8->pPalette16); | |
2946 pAllocator->FreeChunk(v8->pPalette24); | |
2947 if ( eTextureType == TEXTURE_24BIT_PALETTE ) | |
2948 { | |
2949 v33 = pAllocator->AllocNamedChunk(v8->pPalette24, 0x300u, v8->pName); | |
2950 v8->pPalette24 = (unsigned __int8 *)v33; | |
2951 fread(v33, 1u, 0x300u, pFile); | |
2952 } | |
2953 else | |
2954 { | |
2955 v8->pPalette24 = 0; | |
2956 if ( eTextureType == TEXTURE_16BIT_PALETTE ) | |
2957 { | |
2958 v8->pPalette16 = (unsigned __int16 *)pAllocator->AllocNamedChunk(v8->pPalette16, 0x200u, v8->pName); | |
2959 v38 = 0; | |
2960 do | |
2961 { | |
2962 fread((char *)&eTextureType + 3, 1u, 1u, pFile); | |
2963 fread((char *)&pContainer + 3, 1u, 1u, pFile); | |
2964 v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile); | |
2965 LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits))); | |
2966 v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits)); | |
2967 LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits))); | |
2968 v8->pPalette16[v38] += v40 << uTextureBlueBits; | |
2969 v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits))); | |
2970 ++v38; | |
2971 } | |
2972 while ( v38 < 256 ); | |
2973 goto LABEL_36; | |
2974 } | |
2975 } | |
2976 v8->pPalette16 = 0; | |
2977 LABEL_36: | |
2978 if ( v8->pBits & 2 ) | |
2979 { | |
2980 v34 = v8->uSizeOfMaxLevelOfDetail; | |
710 | 2981 v35 = &v8->pLevelOfDetail0_prolly_alpha_mask[v34]; |
0 | 2982 v8->pLevelOfDetail1 = v35; |
2983 v36 = &v35[v34 >> 2]; | |
2984 v8->pLevelOfDetail2 = v36; | |
2985 v37 = &v36[v34 >> 4]; | |
2986 } | |
2987 else | |
2988 { | |
2989 v37 = 0; | |
2990 v8->pLevelOfDetail2 = 0; | |
2991 v8->pLevelOfDetail1 = 0; | |
2992 } | |
2993 v8->pLevelOfDetail3 = v37; | |
2994 v41 = 1; | |
2995 while ( 1 << v41 != v8->uTextureWidth ) | |
2996 { | |
2997 ++v41; | |
2998 if ( v41 >= 15 ) | |
2999 goto LABEL_48; | |
3000 } | |
3001 v8->uWidthLn2 = v41; | |
3002 LABEL_48: | |
3003 v42 = 1; | |
3004 while ( 1 << v42 != v8->uTextureHeight ) | |
3005 { | |
3006 ++v42; | |
3007 if ( v42 >= 15 ) | |
3008 goto LABEL_53; | |
3009 } | |
3010 v8->uHeightLn2 = v42; | |
3011 LABEL_53: | |
3012 switch ( v8->uWidthLn2 ) | |
3013 { | |
3014 case 2: | |
3015 v8->uWidthMinus1 = 3; | |
3016 break; | |
3017 case 3: | |
3018 v8->uWidthMinus1 = 7; | |
3019 break; | |
3020 case 4: | |
3021 v8->uWidthMinus1 = 15; | |
3022 break; | |
3023 case 5: | |
3024 v8->uWidthMinus1 = 31; | |
3025 break; | |
3026 case 6: | |
3027 v8->uWidthMinus1 = 63; | |
3028 break; | |
3029 case 7: | |
3030 v8->uWidthMinus1 = 127; | |
3031 break; | |
3032 case 8: | |
3033 v8->uWidthMinus1 = 255; | |
3034 break; | |
3035 case 9: | |
3036 v8->uWidthMinus1 = 511; | |
3037 break; | |
3038 case 10: | |
3039 v8->uWidthMinus1 = 1023; | |
3040 break; | |
3041 case 11: | |
3042 v8->uWidthMinus1 = 2047; | |
3043 break; | |
3044 case 12: | |
3045 v8->uWidthMinus1 = 4095; | |
3046 break; | |
3047 default: | |
3048 break; | |
3049 } | |
3050 switch ( v8->uHeightLn2 ) | |
3051 { | |
3052 case 2: | |
3053 v8->uHeightMinus1 = 3; | |
3054 break; | |
3055 case 3: | |
3056 v8->uHeightMinus1 = 7; | |
3057 break; | |
3058 case 4: | |
3059 v8->uHeightMinus1 = 15; | |
3060 break; | |
3061 case 5: | |
3062 v8->uHeightMinus1 = 31; | |
3063 break; | |
3064 case 6: | |
3065 v8->uHeightMinus1 = 63; | |
3066 break; | |
3067 case 7: | |
3068 v8->uHeightMinus1 = 127; | |
3069 break; | |
3070 case 8: | |
3071 v8->uHeightMinus1 = 255; | |
3072 break; | |
3073 case 9: | |
3074 v8->uHeightMinus1 = 511; | |
3075 break; | |
3076 case 10: | |
3077 v8->uHeightMinus1 = 1023; | |
3078 break; | |
3079 case 11: | |
3080 v8->uHeightMinus1 = 2047; | |
3081 break; | |
3082 case 12: | |
3083 v8->uHeightMinus1 = 4095; | |
3084 break; | |
3085 default: | |
3086 return 1; | |
3087 } | |
3088 return 1; | |
3089 } | |
3090 | |
3091 | |
3092 Texture *LODFile_IconsBitmaps::LoadTexturePtr(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
3093 { | |
3094 uint id = LoadTexture(pContainer, uTextureType); | |
737 | 3095 |
3096 assert(id != -1 && L"Texture not found"); | |
3097 | |
0 | 3098 return &pTextures[id]; |
3099 } | |
3100 | |
3101 //----- (0040FB20) -------------------------------------------------------- | |
3102 unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
3103 { | |
3104 //LODFile_IconsBitmaps *v3; // esi@1 | |
3105 //unsigned int v4; // edi@1 | |
3106 //Texture *v5; // ebx@2 | |
3107 unsigned int v6; // ebx@8 | |
3108 const char *Sourcea; // [sp+14h] [bp+8h]@9 | |
3109 | |
3110 //v3 = this; | |
3111 //v4 = 0; | |
3112 areWeLoadingTexture = 1; | |
3113 | |
3114 for (uint i = 0; i < uNumLoadedFiles; ++i) | |
3115 if (!strcmpi(pContainer, pTextures[i].pName)) | |
3116 return i; | |
3117 | |
3118 // if (!uNumLoadedFiles) | |
3119 // { | |
3120 //LABEL_5: | |
649 | 3121 assert(uNumLoadedFiles < 1000); |
3122 /*if (uNumLoadedFiles >= 1000) | |
0 | 3123 { |
3124 Log::Warning(L"Maximum texture number exceeded"); | |
3125 AbortWithError(); | |
649 | 3126 }*/ |
0 | 3127 if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) |
3128 { | |
3129 v6 = 0; | |
3130 if (uNumLoadedFiles > 0) | |
3131 { | |
3132 Sourcea = (const char *)pTextures; | |
3133 while ( _strcmpi(Sourcea, "pending") ) | |
3134 { | |
3135 Sourcea += 72; | |
3136 ++v6; | |
3137 if (v6 >= uNumLoadedFiles) | |
3138 goto LABEL_15; | |
3139 } | |
3140 return v6; | |
3141 } | |
3142 LABEL_15: | |
3143 LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); | |
3144 } | |
3145 areWeLoadingTexture = 0; | |
3146 ++uNumLoadedFiles; | |
3147 return uNumLoadedFiles - 1; | |
3148 // } | |
3149 // v5 = pTextures; | |
3150 // while ( _strcmpi(v5->pName, pContainer) ) | |
3151 // { | |
3152 // ++v4; | |
3153 // ++v5; | |
3154 // if (v4 >= uNumLoadedFiles ) | |
3155 // goto LABEL_5; | |
3156 // } | |
3157 // return v4; | |
3158 } |