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