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