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