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