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