Mercurial > mm7
annotate LOD.cpp @ 2165:47ac9e87690c
isFileOpened
author | Ritor1 |
---|---|
date | Thu, 16 Jan 2014 17:34:48 +0600 |
parents | 9bd7522cdbbb |
children | daa61976637d |
rev | line source |
---|---|
0 | 1 #include "LOD.h" |
2 #include "Render.h" | |
3 #include "PaletteManager.h" | |
4 #include "Viewport.h" | |
5 | |
6 #include "mm7_data.h" | |
2152 | 7 #include "mm7_unsorted_subs.h" |
0 | 8 |
1016 | 9 #include "Sprites.h" |
0 | 10 |
11 | |
12 | |
13 | |
14 | |
15 | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
16 LODFile_IconsBitmaps *pEvents_LOD = nullptr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
17 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
18 LODFile_IconsBitmaps *pIcons_LOD = nullptr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
19 LODFile_IconsBitmaps *pIcons_LOD_mm6 = nullptr; |
1541 | 20 LODFile_IconsBitmaps *pIcons_LOD_mm8 = nullptr; |
0 | 21 |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
22 LODFile_IconsBitmaps *pBitmaps_LOD = nullptr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
23 LODFile_IconsBitmaps *pBitmaps_LOD_mm6 = nullptr; |
1541 | 24 LODFile_IconsBitmaps *pBitmaps_LOD_mm8 = nullptr; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
25 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
26 LODFile_Sprites *pSprites_LOD = nullptr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
27 LODFile_Sprites *pSprites_LOD_mm6 = nullptr; |
1541 | 28 LODFile_Sprites *pSprites_LOD_mm8 = nullptr; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
29 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
30 LODWriteableFile *pNew_LOD = nullptr; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
31 LODWriteableFile *pGames_LOD = nullptr; |
0 | 32 |
33 | |
34 | |
35 | |
36 int _6A0CA4_lod_binary_search; // weak | |
37 int _6A0CA8_lod_unused; // weak | |
38 | |
39 | |
762 | 40 // inlined |
41 //----- (mm6c::00408860) -------------------------------------------------- | |
42 void LODFile_IconsBitmaps::_inlined_sub2() | |
43 { | |
44 ++uTexturePacksCount; | |
45 if (!uNumPrevLoadedFiles) | |
46 uNumPrevLoadedFiles = uNumLoadedFiles; | |
47 } | |
48 | |
49 // inlined | |
50 //----- (mm6c::0045BE60) -------------------------------------------------- | |
51 void LODFile_IconsBitmaps::_inlined_sub1() | |
52 { | |
53 dword_11B84 = uNumLoadedFiles; | |
54 } | |
55 | |
56 // inlined | |
57 //----- (mm6c::0045C310) -------------------------------------------------- | |
58 void LODFile_Sprites::_inlined_sub1() | |
59 { | |
60 field_ECA0 = uNumLoadedSprites; | |
61 } | |
62 | |
63 // inlined | |
64 //----- (mm6c::0045C5B0) -------------------------------------------------- | |
65 void LODFile_IconsBitmaps::_inlined_sub0() | |
66 { | |
67 dword_11B80 = uNumLoadedFiles; | |
68 if (dword_11B84 < uNumLoadedFiles) | |
69 dword_11B84 = uNumLoadedFiles; | |
70 } | |
71 | |
72 | |
73 // inlined | |
74 //----- (mm6c::0045C660) -------------------------------------------------- | |
75 void LODFile_Sprites::_inlined_sub0() | |
76 { | |
77 field_ECA4 = uNumLoadedSprites; | |
78 if (field_ECA0 < uNumLoadedSprites) | |
79 field_ECA0 = uNumLoadedSprites; | |
80 } | |
0 | 81 |
82 //----- (004355F7) -------------------------------------------------------- | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
83 void LODFile_IconsBitmaps::RemoveTexturesFromTextureList() |
0 | 84 { |
85 if ( this->uTexturePacksCount ) | |
86 { | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
87 if ( (this->uNumLoadedFiles - 1) >= this->uNumPrevLoadedFiles ) |
0 | 88 { |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
89 for ( uint i = this->uNumLoadedFiles - 1; i >= this->uNumPrevLoadedFiles; --i ) |
0 | 90 { |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
91 this->pTextures[i].Release(); |
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
92 if ( this->pHardwareTextures ) |
0 | 93 { |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
94 if ( this->pHardwareTextures[i] ) |
0 | 95 { |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
96 this->pHardwareTextures[i]->Release(); |
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
97 this->pHardwareTextures[i] = 0; |
0 | 98 } |
99 } | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
100 if ( this->pHardwareSurfaces ) |
0 | 101 { |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
102 if ( this->pHardwareSurfaces[i] ) |
0 | 103 { |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
104 this->pHardwareSurfaces[i]->Release(); |
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
105 this->pHardwareSurfaces[i] = 0; |
0 | 106 } |
107 } | |
108 } | |
109 } | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
110 this->uNumLoadedFiles = this->uNumPrevLoadedFiles; |
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
111 this->uNumPrevLoadedFiles = 0; |
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
112 this->uTexturePacksCount = 0; |
0 | 113 } |
114 } | |
115 | |
116 //----- (004114F2) -------------------------------------------------------- | |
1405
c0b273d33338
RemoveTexturesPackFromTextureList and RemoveTexturesFromTextureList
Ritor1
parents:
1404
diff
changeset
|
117 void LODFile_IconsBitmaps::RemoveTexturesPackFromTextureList() |
0 | 118 { |
1404 | 119 if ( this->uTexturePacksCount ) |
0 | 120 { |
1404 | 121 this->uTexturePacksCount--; |
122 if ( !this->uTexturePacksCount ) | |
0 | 123 { |
1404 | 124 if ( (this->uNumLoadedFiles - 1) >= this->uNumPrevLoadedFiles ) |
0 | 125 { |
1404 | 126 for ( uint i = this->uNumLoadedFiles - 1; i >= this->uNumPrevLoadedFiles; --i ) |
0 | 127 { |
1404 | 128 this->pTextures[i].Release(); |
129 if ( this->pHardwareTextures ) | |
0 | 130 { |
1404 | 131 if ( this->pHardwareTextures[i] ) |
0 | 132 { |
1404 | 133 this->pHardwareTextures[i]->Release(); |
134 this->pHardwareTextures[i] = 0; | |
0 | 135 } |
136 } | |
1404 | 137 if ( this->pHardwareSurfaces ) |
0 | 138 { |
1404 | 139 if ( this->pHardwareSurfaces[i] ) |
0 | 140 { |
1404 | 141 this->pHardwareSurfaces[i]->Release(); |
142 this->pHardwareSurfaces[i] = 0; | |
0 | 143 } |
144 } | |
145 } | |
146 } | |
1404 | 147 this->uNumLoadedFiles = this->uNumPrevLoadedFiles; |
1402 | 148 this->uNumPrevLoadedFiles = 0; |
0 | 149 } |
150 } | |
151 } | |
152 | |
153 //----- (004AC67E) -------------------------------------------------------- | |
154 int LODFile_Sprites::LoadSpriteFromFile(LODSprite *pSpriteHeader, const char *pContainer) | |
155 { | |
156 FILE *v3; // eax@1 | |
157 FILE *v4; // ebx@1 | |
158 int result; // eax@2 | |
159 LODSprite *v6; // esi@3 | |
160 LODSprite_stru0 *v7; // eax@3 | |
161 size_t v8; // ST10_4@3 | |
162 int *v9; // ebx@3 | |
163 int v10; // eax@3 | |
164 void *v11; // eax@5 | |
165 LODSprite_stru0 *v12; // eax@6 | |
166 void *v13; // ecx@6 | |
167 LODSprite_stru0 *i; // edx@6 | |
168 FILE *File; // [sp+4h] [bp-4h]@1 | |
169 void *DstBufa; // [sp+10h] [bp+8h]@4 | |
170 int Sizea; // [sp+14h] [bp+Ch]@3 | |
171 | |
172 v3 = FindContainer(pContainer, 0); | |
173 v4 = v3; | |
174 File = v3; | |
175 if ( v3 ) | |
176 { | |
177 v6 = pSpriteHeader; | |
178 fread(pSpriteHeader, 1u, 0x20u, v3); | |
179 strcpy(pSpriteHeader->pName, pContainer); | |
180 Sizea = pSpriteHeader->uSpriteSize; | |
1583 | 181 v7 = (LODSprite_stru0 *)malloc(8 * v6->uHeight); |
0 | 182 v8 = 8 * pSpriteHeader->uHeight; |
183 pSpriteHeader->pSpriteLines = v7; | |
184 fread(v7, 1u, v8, v4); | |
185 v9 = &pSpriteHeader->uDecompressedSize; | |
186 v10 = pSpriteHeader->uDecompressedSize; | |
187 if ( v10 ) | |
188 { | |
1583 | 189 pSpriteHeader->pDecompressedBytes = malloc(v10); |
190 DstBufa = malloc(Sizea); | |
0 | 191 fread(DstBufa, 1u, Sizea, File); |
192 zlib::MemUnzip(v6->pDecompressedBytes, (unsigned int *)&v6->uDecompressedSize, DstBufa, v6->uSpriteSize); | |
193 v6->uSpriteSize = *v9; | |
1583 | 194 free(DstBufa); |
0 | 195 } |
196 else | |
197 { | |
1583 | 198 v11 = malloc(Sizea); |
0 | 199 pSpriteHeader->pDecompressedBytes = v11; |
200 fread(v11, 1u, Sizea, File); | |
201 } | |
202 v12 = v6->pSpriteLines; | |
203 v13 = v6->pDecompressedBytes; | |
204 for ( i = &v12[v6->uHeight]; v12 < i; i = &v6->pSpriteLines[v6->uHeight] ) | |
205 { | |
206 v12->ptr_4 = (char *)v12->ptr_4 + (unsigned int)v13; | |
207 ++v12; | |
208 } | |
209 result = 1; | |
210 } | |
211 else | |
212 { | |
213 result = -1; | |
214 } | |
215 return result; | |
216 } | |
217 | |
218 //----- (004AC795) -------------------------------------------------------- | |
219 bool LODFile_Sprites::LoadSprites(const char *pFilename) | |
220 { | |
221 if (LoadHeader(pFilename, 1)) | |
222 return false; | |
223 else | |
224 return LoadSubIndices("sprites08") == 0; | |
225 } | |
226 | |
227 //----- (004AC7C0) -------------------------------------------------------- | |
228 int LODFile_Sprites::LoadSprite(const char *pContainerName, unsigned int uPaletteID) | |
670 | 229 { |
230 | |
231 FILE *sprite_file; // eax@12 | |
232 LODSprite temp_sprite_hdr; // [sp+Ch] [bp-3Ch]@12 | |
233 int i, sprite_indx; | |
234 | |
235 //find if already loaded | |
2154 | 236 //if ( pRenderer->pRenderD3D ) |
670 | 237 { |
238 for (i=0; i<uNumLoadedSprites;++i) | |
239 { | |
1104 | 240 if (!(_stricmp(pHardwareSprites[i].pName, pContainerName))) |
670 | 241 return i; |
242 } | |
243 } | |
2154 | 244 /*else |
670 | 245 { |
246 for (i=0; i<uNumLoadedSprites;++i) | |
247 { | |
1104 | 248 if (!(_stricmp(pSpriteHeaders[i].pName, pContainerName))) |
670 | 249 return i; |
250 } | |
2154 | 251 }*/ |
670 | 252 |
700
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
253 if (uNumLoadedSprites >= 1500 ) |
670 | 254 return -1; |
255 //if not loaded - load from file | |
0 | 256 |
2154 | 257 //if ( pRenderer->pRenderD3D && can_load_hardware_sprites ) |
670 | 258 { |
259 if ( !pHardwareSprites ) | |
260 { | |
1583 | 261 pHardwareSprites = (Sprite *)malloc(1500*sizeof(Sprite));//0xEA60u |
670 | 262 for (i=0; i<1500;++i) |
263 { | |
264 pHardwareSprites[i].pName=NULL; | |
265 pHardwareSprites[i].pTextureSurface=NULL; | |
266 pHardwareSprites[i].pTexture=NULL; | |
267 } | |
268 } | |
269 temp_sprite_hdr.uHeight = 0; | |
270 temp_sprite_hdr.uPaletteId = 0; | |
271 temp_sprite_hdr.word_1A = 0; | |
272 temp_sprite_hdr.pSpriteLines = 0; | |
273 temp_sprite_hdr.pDecompressedBytes = 0; | |
274 sprite_file = FindContainer(pContainerName, 0); | |
275 if ( !sprite_file ) | |
276 return -1; | |
700
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
277 //fread(&temp_sprite_hdr, 1, sizeof(LODSprite), sprite_file); |
1d05543f522d
Some occasional crashes in PaletteManager and sprite loading fixed.
Nomad
parents:
670
diff
changeset
|
278 fread(&temp_sprite_hdr, 1, 0x20, sprite_file); |
670 | 279 pHardwareSprites[uNumLoadedSprites].uBufferWidth = temp_sprite_hdr.uWidth; |
280 pHardwareSprites[uNumLoadedSprites].uBufferHeight = temp_sprite_hdr.uHeight; | |
281 pSpriteHeaders[uNumLoadedSprites].uWidth = temp_sprite_hdr.uWidth; | |
282 pSpriteHeaders[uNumLoadedSprites].uHeight = temp_sprite_hdr.uHeight; | |
283 } | |
2154 | 284 /*else |
670 | 285 { |
286 sprite_indx = LoadSpriteFromFile( &pSpriteHeaders[uNumLoadedSprites], pContainerName); | |
287 pSpriteHeaders[uNumLoadedSprites].word_1A = 0; | |
288 | |
289 if ( sprite_indx != -1 ) | |
290 { | |
291 pSpriteHeaders[uNumLoadedSprites].uPaletteId = pPaletteManager->LoadPalette(pSpriteHeaders[uNumLoadedSprites].uPaletteId); | |
292 } | |
293 else | |
294 { | |
295 if ( uNumLoadedSprites<=0 ) | |
296 uNumLoadedSprites=0; | |
297 else | |
298 { | |
299 for (i=0; i<uNumLoadedSprites;++i) | |
300 { | |
1104 | 301 if (!(_stricmp(pSpriteHeaders[i].pName, "pending"))) |
670 | 302 return i; |
303 } | |
304 } | |
305 if ( LoadSpriteFromFile(&pSpriteHeaders[uNumLoadedSprites], "pending") == -1 ) | |
306 return -1; | |
307 pSpriteHeaders[uNumLoadedSprites].uPaletteId = pPaletteManager->LoadPalette(pSpriteHeaders[uNumLoadedSprites].uPaletteId); | |
308 } | |
2154 | 309 }*/ |
670 | 310 |
2154 | 311 //if ( pRenderer->pRenderD3D ) |
670 | 312 { |
1583 | 313 pHardwareSprites[uNumLoadedSprites].pName = (const char *)malloc(20); |
670 | 314 strcpy((char *)pHardwareSprites[uNumLoadedSprites].pName, pContainerName); |
315 pHardwareSprites[uNumLoadedSprites].uPaletteID = uPaletteID; | |
316 pRenderer->MoveSpriteToDevice(&pHardwareSprites[uNumLoadedSprites]); | |
317 } | |
318 ++uNumLoadedSprites; | |
319 return uNumLoadedSprites - 1; | |
320 | |
321 } | |
0 | 322 |
323 //----- (004ACADA) -------------------------------------------------------- | |
324 void LODFile_Sprites::ReleaseLostHardwareSprites() | |
325 { | |
326 LODFile_Sprites *v1; // esi@1 | |
327 signed int v2; // ebx@2 | |
328 int v3; // edi@3 | |
329 IDirectDrawSurface *v4; // eax@4 | |
330 IDirect3DTexture2 *v5; // eax@6 | |
331 IDirectDrawSurface *v6; // ST00_4@8 | |
332 | |
333 v1 = this; | |
334 if ( this->pHardwareSprites ) | |
335 { | |
336 v2 = 0; | |
337 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
338 { | |
339 v3 = 0; | |
340 do | |
341 { | |
342 v4 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface; | |
343 if ( v4 && v4->IsLost() == DDERR_SURFACELOST ) | |
344 { | |
345 v5 = v1->pHardwareSprites[v3].pTexture; | |
346 if ( v5 ) | |
347 { | |
348 v5->Release(); | |
349 v1->pHardwareSprites[v3].pTexture = 0; | |
350 } | |
351 v6 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface; | |
352 v6->Release(); | |
353 v1->pHardwareSprites[v3].pTextureSurface = 0; | |
354 pRenderer->MoveSpriteToDevice(&v1->pHardwareSprites[v3]); | |
355 } | |
356 ++v2; | |
357 ++v3; | |
358 } | |
359 while ( v2 < (signed int)v1->uNumLoadedSprites ); | |
360 } | |
361 } | |
362 } | |
363 | |
364 //----- (004ACB70) -------------------------------------------------------- | |
365 void LODFile_Sprites::ReleaseAll() | |
366 { | |
367 LODFile_Sprites *v1; // esi@1 | |
368 signed int v2; // ebx@2 | |
369 int v3; // edi@3 | |
370 Sprite *v4; // eax@4 | |
371 IDirect3DTexture2 *v5; // eax@5 | |
372 Sprite *v6; // eax@7 | |
373 IDirectDrawSurface *v7; // eax@8 | |
374 | |
375 v1 = this; | |
376 if ( this->pHardwareSprites ) | |
377 { | |
378 v2 = 0; | |
379 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
380 { | |
381 v3 = 0; | |
382 do | |
383 { | |
384 v4 = v1->pHardwareSprites; | |
385 if ( v4 ) | |
386 { | |
387 v5 = v4[v3].pTexture; | |
388 if ( v5 ) | |
389 { | |
390 v5->Release(); | |
391 v1->pHardwareSprites[v3].pTexture = 0; | |
392 } | |
393 v6 = v1->pHardwareSprites; | |
394 if ( v6 ) | |
395 { | |
396 v7 = (IDirectDrawSurface *)v6[v3].pTextureSurface; | |
397 if ( v7 ) | |
398 { | |
399 v7->Release(); | |
400 v1->pHardwareSprites[v3].pTextureSurface = 0; | |
401 } | |
402 } | |
403 } | |
404 ++v2; | |
405 ++v3; | |
406 } | |
407 while ( v2 < (signed int)v1->uNumLoadedSprites ); | |
408 } | |
409 } | |
410 } | |
411 | |
412 //----- (004ACBE0) -------------------------------------------------------- | |
413 void LODFile_Sprites::MoveSpritesToVideoMemory() | |
414 { | |
415 LODFile_Sprites *v1; // esi@1 | |
416 int v2; // ebx@1 | |
417 signed int v3; // edi@2 | |
418 | |
419 v1 = this; | |
420 v2 = 0; | |
421 if ( this->pHardwareSprites ) | |
422 { | |
423 v3 = 0; | |
424 if ( (signed int)this->uNumLoadedSprites > 0 ) | |
425 { | |
426 do | |
427 { | |
428 pRenderer->MoveSpriteToDevice(&v1->pHardwareSprites[v2]); | |
429 ++v3; | |
430 ++v2; | |
431 } | |
432 while ( v3 < (signed int)v1->uNumLoadedSprites ); | |
433 } | |
434 } | |
435 } | |
436 | |
437 //----- (004ACC38) -------------------------------------------------------- | |
733 | 438 int LODSprite::DrawSprite_sw(RenderBillboardTransform_local0 *a2, char a3) |
0 | 439 { |
440 RenderBillboardTransform_local0 *v3; // edi@1 | |
441 int result; // eax@1 | |
442 int v5; // esi@2 | |
443 int v6; // ST18_4@2 | |
444 signed int v7; // eax@2 | |
445 signed int v8; // ebx@2 | |
446 int v9; // ebx@2 | |
447 int *v10; // ecx@2 | |
448 int v11; // esi@2 | |
449 unsigned int v12; // edx@4 | |
450 int v13; // esi@13 | |
451 int v14; // esi@17 | |
452 int v15; // ecx@17 | |
453 char *v16; // edx@17 | |
454 int v17; // esi@17 | |
455 int v18; // ecx@18 | |
456 int v19; // esi@18 | |
457 LODSprite_stru0 *v20; // edx@21 | |
458 int v21; // eax@22 | |
459 int v22; // esi@22 | |
460 int v23; // eax@25 | |
461 int v24; // ecx@25 | |
462 signed __int64 v25; // qtt@27 | |
463 int v26; // eax@27 | |
464 unsigned __int16 *v27; // eax@29 | |
465 LODSprite_stru0 *v28; // edx@29 | |
466 signed int v29; // ecx@30 | |
467 int v30; // ecx@37 | |
468 int v31; // ecx@38 | |
469 signed int v32; // ecx@41 | |
470 int v33; // ecx@47 | |
471 int v34; // ecx@56 | |
472 int v35; // esi@58 | |
473 __int16 v36; // ax@58 | |
474 int v37; // ecx@59 | |
475 int v38; // eax@59 | |
476 int v39; // ecx@62 | |
477 signed int v40; // ST30_4@64 | |
478 signed __int64 v41; // qtt@64 | |
479 int v42; // ecx@64 | |
480 unsigned __int16 *v43; // eax@66 | |
481 LODSprite_stru0 *v44; // ecx@66 | |
482 int v45; // edx@69 | |
483 int v46; // edx@77 | |
2069 | 484 //unsigned __int16 *pTarget; // [sp+Ch] [bp-50h]@2 |
0 | 485 signed int v48; // [sp+10h] [bp-4Ch]@2 |
486 signed int v49; // [sp+14h] [bp-48h]@2 | |
487 int v50; // [sp+14h] [bp-48h]@19 | |
488 int v51; // [sp+14h] [bp-48h]@57 | |
489 int v52; // [sp+18h] [bp-44h]@13 | |
490 int v53; // [sp+1Ch] [bp-40h]@2 | |
491 int v54; // [sp+1Ch] [bp-40h]@22 | |
492 int v55; // [sp+1Ch] [bp-40h]@32 | |
493 int v56; // [sp+1Ch] [bp-40h]@69 | |
494 int v57; // [sp+20h] [bp-3Ch]@2 | |
495 int v58; // [sp+24h] [bp-38h]@1 | |
496 int v59; // [sp+28h] [bp-34h]@2 | |
497 int v60; // [sp+28h] [bp-34h]@13 | |
498 unsigned __int16 *v61; // [sp+2Ch] [bp-30h]@2 | |
499 int v62; // [sp+30h] [bp-2Ch]@2 | |
500 void *v63; // [sp+30h] [bp-2Ch]@29 | |
501 void *v64; // [sp+30h] [bp-2Ch]@66 | |
502 int v65; // [sp+34h] [bp-28h]@2 | |
503 int v66; // [sp+34h] [bp-28h]@22 | |
504 int v67; // [sp+34h] [bp-28h]@59 | |
505 int v68; // [sp+38h] [bp-24h]@13 | |
506 unsigned int v69; // [sp+3Ch] [bp-20h]@2 | |
507 int v70; // [sp+40h] [bp-1Ch]@2 | |
508 signed int v71; // [sp+40h] [bp-1Ch]@15 | |
509 int v72; // [sp+44h] [bp-18h]@2 | |
510 unsigned __int16 *v73; // [sp+44h] [bp-18h]@29 | |
511 unsigned __int16 *v74; // [sp+44h] [bp-18h]@66 | |
512 int v75; // [sp+48h] [bp-14h]@4 | |
513 int v76; // [sp+48h] [bp-14h]@22 | |
514 int v77; // [sp+48h] [bp-14h]@59 | |
515 LODSprite *v78; // [sp+4Ch] [bp-10h]@1 | |
516 int v79; // [sp+50h] [bp-Ch]@4 | |
517 int v80; // [sp+50h] [bp-Ch]@21 | |
518 int v81; // [sp+50h] [bp-Ch]@62 | |
519 int v82; // [sp+50h] [bp-Ch]@67 | |
520 int v83; // [sp+50h] [bp-Ch]@75 | |
521 int *pTargetZ; // [sp+54h] [bp-8h]@4 | |
522 int v85; // [sp+58h] [bp-4h]@18 | |
523 int v86; // [sp+58h] [bp-4h]@56 | |
524 signed int v87; // [sp+64h] [bp+8h]@2 | |
525 int v88; // [sp+68h] [bp+Ch]@18 | |
526 int v89; // [sp+68h] [bp+Ch]@56 | |
527 | |
528 v3 = a2; | |
529 v78 = this; | |
144
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
530 result = a2->_screenspace_x_scaler_packedfloat; |
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
531 v58 = a2->_screenspace_x_scaler_packedfloat; |
0 | 532 if ( result <= 0 ) |
533 return result; | |
144
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
534 v5 = a2->_screenspace_y_scaler_packedfloat; |
8ab4484c22e0
Billboard drawing's up (actors, decorations, misc sprites)
Nomad
parents:
17
diff
changeset
|
535 v6 = a2->_screenspace_x_scaler_packedfloat; |
0 | 536 v87 = (signed __int64)0x100000000ui64 / result; |
537 v48 = (signed __int64)0x100000000ui64 / result; | |
538 v62 = (signed __int64)0x100000000ui64 / v5; | |
539 v7 = this->uHeight; | |
540 v8 = (signed int)((signed __int64)0x100000000ui64 / v5) >> 1; | |
541 v53 = v8; | |
542 v70 = (this->uHeight << 16) - v8; | |
543 v49 = v7; | |
544 v69 = v3->uTargetPitch; | |
2069 | 545 |
546 __debugbreak(); // target surface will most likely be 32bit, but this sub awaits 16bits | |
547 auto pTarget = (unsigned __int16 *)v3->pTarget; | |
0 | 548 v57 = v3->sZValue; |
549 v61 = v3->pPalette; | |
550 v9 = (v6 * this->uWidth + 32768) >> 16; | |
551 v72 = v3->uScreenSpaceY; | |
552 result = (v5 * v7 + 32768) >> 16; | |
553 v10 = (int *)(v72 - result + 1); | |
554 v11 = v3->uScreenSpaceX - (v9 >> 1) + 1; | |
555 v65 = v72 - result + 1; | |
556 v59 = v11 + v9 - 1; | |
557 if ( BYTE1(v3->uFlags) & 8 ) | |
558 { | |
559 v10 = (int *)((char *)v10 + (v49 >> 1)); | |
560 v72 += v49 >> 1; | |
561 v65 = (int)v10; | |
562 } | |
563 v12 = v72; | |
564 pTargetZ = v10; | |
565 v75 = v3->uScreenSpaceX - (v9 >> 1) + 1; | |
566 v79 = v11 + v9 - 1; | |
567 if ( !(v3->uFlags & 8) ) | |
568 { | |
569 if ( v65 < (signed int)v3->uViewportY ) | |
570 pTargetZ = (int *)v3->uViewportY; | |
571 if ( v72 > (signed int)v3->uViewportW ) | |
572 v12 = v3->uViewportW; | |
573 if ( v11 < (signed int)v3->uViewportX ) | |
574 v75 = v3->uViewportX; | |
575 if ( v59 > (signed int)v3->uViewportZ ) | |
576 v79 = v3->uViewportZ; | |
577 } | |
578 v68 = v75 - v11; | |
579 v13 = -v62; | |
580 v60 = v59 - v79; | |
581 v52 = -v62; | |
582 if ( v3->uFlags & 1 ) | |
583 { | |
584 v13 = v62; | |
585 v70 = v53; | |
586 v52 = v62; | |
587 } | |
588 v71 = v13 * (v72 - v12) + v70; | |
589 if ( LOBYTE(viewparams->field_20) ) | |
590 { | |
591 if ( a3 ) | |
592 return result; | |
593 } | |
594 v14 = 5 * v12; | |
595 v15 = v69 * v12; | |
596 result = v12 - v72 + result - 1; | |
597 v16 = (char *)pTargetZ - v65; | |
598 v17 = v14 << 7; | |
599 if ( v3->uFlags & 4 ) | |
600 { | |
601 v34 = v79 + v15; | |
602 v89 = v34; | |
603 v86 = v79 + v17; | |
604 if ( result < (signed int)v16 ) | |
605 return result; | |
606 v51 = result - (int)v16 + 1; | |
607 while ( 1 ) | |
608 { | |
609 v35 = v71 >> 16; | |
610 v36 = LOWORD(v78->pSpriteLines[v35].dword_0); | |
611 if ( v36 == -1 ) | |
612 { | |
613 v34 -= v69; | |
614 v89 = v34; | |
615 goto LABEL_84; | |
616 } | |
617 v37 = v9 - ((unsigned __int64)(v36 * (signed __int64)v58) >> 16); | |
618 v67 = v87 * ((unsigned __int64)(LOWORD(v78->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16); | |
619 v38 = v9 - v60; | |
620 v77 = v9 - v60; | |
621 if ( v9 - v60 <= (signed int)(v9 | |
622 - ((unsigned __int64)(HIWORD(v78->pSpriteLines[v35].dword_0) * (signed __int64)v58) >> 16)) | |
623 || v68 >= v37 ) | |
624 { | |
625 v89 -= v69; | |
626 v34 = v89; | |
627 LABEL_84: | |
628 v86 -= 640; | |
629 goto LABEL_85; | |
630 } | |
631 if ( v38 < v37 ) | |
632 { | |
633 v81 = (v87 >> 1) + v87 * (v37 - v38); | |
634 } | |
635 else | |
636 { | |
637 v77 = v37; | |
638 v81 = v87 >> 1; | |
639 v39 = v37 - v9; | |
640 v89 += v39 + v60; | |
641 v86 += v60 + v39; | |
642 } | |
643 v40 = ((HIWORD(v78->pSpriteLines[v35].dword_0) + 1) << 16) - v81 - v67; | |
644 LODWORD(v41) = v40 << 16; | |
645 HIDWORD(v41) = v40 >> 16; | |
646 v42 = v77 - (((signed int)((unsigned __int64)(v41 / v48) - 32768) >> 16) + 1); | |
647 if ( v68 >= v42 ) | |
648 v42 = v68; | |
649 v43 = &pTarget[v89]; | |
650 v74 = &v43[v42 - v77 + 1]; | |
651 v44 = &v78->pSpriteLines[v35]; | |
652 v64 = v44->ptr_4; | |
653 if ( !v57 ) | |
654 { | |
655 v83 = v67 + v81; | |
656 if ( ((v83 - (LOWORD(v44->dword_0) << 16)) & 0xFFFF0000) < 0 ) | |
657 { | |
658 v83 += v87; | |
659 --v43; | |
660 --pTargetZ; | |
661 } | |
662 while ( v43 >= v74 ) | |
663 { | |
664 v46 = (v83 - ((signed int)LOWORD(v78->pSpriteLines[v35].dword_0) << 16)) >> 16; | |
665 if ( *((char *)v64 + v46) ) | |
666 *v43 = v61[*((char *)v64 + v46)]; | |
667 v83 += v87; | |
668 --v43; | |
669 } | |
670 goto LABEL_81; | |
671 } | |
672 pTargetZ = &v3->pTargetZ[v86]; | |
673 v82 = v67 + v81; | |
674 if ( ((v82 - (LOWORD(v44->dword_0) << 16)) & 0xFFFF0000) < 0 ) | |
675 goto LABEL_72; | |
676 LABEL_73: | |
677 if ( v43 >= v74 ) | |
678 break; | |
679 LABEL_81: | |
680 v89 += v9 - v77 - v60 - v69; | |
681 v34 = v89; | |
682 v86 = v86 + v9 - v77 - v60 - 640; | |
683 LABEL_85: | |
684 result = v52; | |
685 v71 += v52; | |
686 --v51; | |
687 if ( !v51 ) | |
688 return result; | |
689 } | |
690 v45 = (v82 - ((signed int)LOWORD(v78->pSpriteLines[v35].dword_0) << 16)) >> 16; | |
691 v56 = *((char *)v64 + v45); | |
692 if ( *((char *)v64 + v45) && v57 <= (unsigned int)*pTargetZ ) | |
693 { | |
694 *pTargetZ = v57; | |
695 *v43 = v61[v56]; | |
696 } | |
697 LABEL_72: | |
698 v82 += v87; | |
699 --v43; | |
700 --pTargetZ; | |
701 goto LABEL_73; | |
702 } | |
703 v18 = v75 + v15; | |
704 v19 = v75 + v17; | |
705 v88 = v18; | |
706 v85 = v19; | |
707 if ( result >= (signed int)v16 ) | |
708 { | |
709 v50 = result - (int)v16 + 1; | |
710 while ( 1 ) | |
711 { | |
712 v20 = &v78->pSpriteLines[v71 >> 16]; | |
713 v80 = v71 >> 16; | |
714 if ( LOWORD(v20->dword_0) != -1 ) | |
715 break; | |
716 v18 -= v69; | |
717 v85 = v19 - 640; | |
718 v88 = v18; | |
719 LABEL_54: | |
720 result = v52; | |
721 v71 += v52; | |
722 --v50; | |
723 if ( !v50 ) | |
724 return result; | |
725 v19 = v85; | |
726 } | |
727 v21 = (v58 * LOWORD(v20->dword_0) + 32768) >> 16; | |
728 v66 = v21 * v87; | |
729 v76 = v68; | |
730 v54 = HIWORD(v20->dword_0); | |
731 v22 = v9 - v60; | |
732 if ( v68 >= (v58 * v54 + 32768) >> 16 || v22 <= v21 ) | |
733 { | |
734 v88 -= v69; | |
735 v85 -= 640; | |
736 goto LABEL_51; | |
737 } | |
738 if ( v68 > v21 ) | |
739 { | |
740 v24 = (v87 >> 1) + v87 * (v68 - v21); | |
741 } | |
742 else | |
743 { | |
744 v76 = (v58 * LOWORD(v20->dword_0) + 32768) >> 16; | |
745 v23 = v21 - v68; | |
746 v88 += v23; | |
747 v24 = v87 >> 1; | |
748 v85 += v23; | |
749 } | |
750 LODWORD(v25) = (((v54 + 1) << 16) - v24 - v66) << 16; | |
751 HIDWORD(v25) = (((v54 + 1) << 16) - v24 - v66) >> 16; | |
752 v26 = v76 + ((signed int)(v25 / v48) >> 16) + 1; | |
753 if ( v22 > v26 ) | |
754 v22 = v26; | |
755 v27 = &pTarget[v88]; | |
756 v73 = &v27[v22 - v76 - 1]; | |
757 v28 = &v78->pSpriteLines[v80]; | |
758 v63 = v28->ptr_4; | |
759 if ( v57 ) | |
760 { | |
761 pTargetZ = &v3->pTargetZ[v85]; | |
762 v29 = v66 - (LOWORD(v28->dword_0) << 16) + v24; | |
763 if ( (v29 & 0xFFFF0000) >= 0 ) | |
764 goto LABEL_36; | |
765 while ( 1 ) | |
766 { | |
767 v29 += v87; | |
768 ++v27; | |
769 ++pTargetZ; | |
770 LABEL_36: | |
771 if ( v27 >= v73 ) | |
772 break; | |
773 v55 = *((char *)v63 + (v29 >> 16)); | |
774 if ( *((char *)v63 + (v29 >> 16)) && v57 <= (unsigned int)*pTargetZ ) | |
775 { | |
776 *pTargetZ = v57; | |
777 *v27 = v61[v55]; | |
778 } | |
779 } | |
780 v30 = v29 >> 16; | |
781 if ( v30 > HIWORD(v78->pSpriteLines[v80].dword_0) - (signed int)LOWORD(v78->pSpriteLines[v80].dword_0) | |
782 || (v31 = *((char *)v63 + v30)) == 0 | |
783 || v57 > (unsigned int)*pTargetZ ) | |
784 goto LABEL_50; | |
785 *pTargetZ = v57; | |
786 } | |
787 else | |
788 { | |
789 v32 = v66 - (LOWORD(v28->dword_0) << 16) + v24; | |
790 if ( (v32 & 0xFFFF0000) < 0 ) | |
791 { | |
792 v32 += v87; | |
793 ++v27; | |
794 ++pTargetZ; | |
795 } | |
796 while ( v27 < v73 ) | |
797 { | |
798 if ( *((char *)v63 + (v32 >> 16)) ) | |
799 *v27 = v61[*((char *)v63 + (v32 >> 16))]; | |
800 v32 += v87; | |
801 ++v27; | |
802 } | |
803 v33 = v32 >> 16; | |
804 if ( v33 > HIWORD(v78->pSpriteLines[v80].dword_0) - (signed int)LOWORD(v78->pSpriteLines[v80].dword_0) | |
805 || (v31 = *((char *)v63 + v33)) == 0 ) | |
806 goto LABEL_50; | |
807 } | |
808 *v27 = v61[v31]; | |
809 LABEL_50: | |
810 v88 += v68 - v76 - v69; | |
811 v85 = v85 + v68 - v76 - 640; | |
812 LABEL_51: | |
813 v18 = v88; | |
814 goto LABEL_54; | |
815 } | |
816 return result; | |
817 } | |
818 | |
819 //----- (004AD2D1) -------------------------------------------------------- | |
820 int LODSprite::_4AD2D1(struct RenderBillboardTransform_local0 *a2, int a3) | |
821 { | |
822 int result; // eax@1 | |
823 unsigned int v4; // esi@1 | |
824 int v5; // edi@1 | |
825 LODSprite_stru0 *v6; // edx@2 | |
826 __int16 v7; // bx@2 | |
827 int v8; // ecx@3 | |
828 unsigned __int16 *v9; // esi@3 | |
829 int v10; // ebx@3 | |
830 void *v11; // edx@3 | |
831 unsigned __int16 *v12; // ecx@3 | |
832 int v13; // ebx@4 | |
833 LODSprite *v14; // [sp+8h] [bp-10h]@1 | |
834 unsigned __int16 *v15; // [sp+10h] [bp-8h]@1 | |
835 unsigned __int16 *v16; // [sp+14h] [bp-4h]@1 | |
836 int i; // [sp+20h] [bp+8h]@1 | |
837 | |
838 result = (int)a2; | |
839 v14 = this; | |
840 v4 = a2->uTargetPitch; | |
2069 | 841 |
842 __debugbreak(); // sub expects 16bit target surface, we may have 32bit | |
843 v16 = (unsigned short *)a2->pTarget; | |
0 | 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; | |
1583 | 944 free(pSubIndices); |
945 free(pRoot); | |
837 | 946 pSubIndices = NULL; |
947 pRoot = NULL; | |
948 fclose(pFile); | |
2165 | 949 isFileOpened = false; |
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; | |
1583 | 991 free(pSubIndices); |
837 | 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 { | |
1583 | 1062 free(this->pDecompressedBytes); |
1063 free(v1->pSpriteLines); | |
0 | 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) | |
1583 | 1081 free((void *)pName); |
0 | 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 { | |
1583 | 1267 free(pDecompressedBytes); |
1268 free(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; | |
2154 | 1287 //can_load_hardware_sprites = 0; |
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; | |
2154 | 1369 //v1->can_load_hardware_sprites = 0; |
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 { | |
1545 | 1456 Assert(uNumSubDirs < 299); |
982 | 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; | |
1977 | 1519 insert_index=-1; |
2165 | 1520 if (!isFileOpened)//sometimes gives crash |
837 | 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 { | |
1977 | 1555 if (insert_index==-1) |
1556 { | |
837 | 1557 insert_index=i; |
1977 | 1558 break; |
1559 } | |
837 | 1560 } |
1561 } | |
1562 strcpy(Filename, "lod.tmp"); | |
1563 tmp_file = fopen(Filename, "wb+"); | |
1564 if ( !tmp_file ) | |
1565 return 5; | |
1566 if (!bRewrite_data) | |
1567 size_correction=0; | |
1568 else | |
1569 size_correction=pSubIndices[insert_index].uDataSize; | |
982 | 1570 |
837 | 1571 //create chapter index |
982 | 1572 LOD::Directory Lindx; |
837 | 1573 strcpy(Lindx.pFilename, "chapter"); |
1574 Lindx.dword_000018=0; | |
1575 Lindx.word_00001E=0; | |
1576 Lindx.uNumSubIndices= uNumSubDirs; | |
1577 Lindx.uOfsetFromSubindicesStart=sizeof(LOD::FileHeader)+sizeof(LOD::Directory); | |
1578 total_data_size=uLODDataSize+pDir->uDataSize-size_correction; | |
1579 if (!bRewrite_data) | |
1580 { | |
1581 total_data_size+=sizeof(LOD::Directory); | |
1582 Lindx.uNumSubIndices++; | |
1583 } | |
1584 | |
1585 Lindx.uDataSize=total_data_size; | |
1586 uNumSubDirs= Lindx.uNumSubIndices; | |
1587 //move indexes +1 after insert point | |
1588 if (!bRewrite_data&&(insert_index<uNumSubDirs)) | |
1589 { | |
1590 for(int i=uNumSubDirs;i>insert_index; --i) | |
1591 memcpy(&pSubIndices[i],&pSubIndices[i-1],sizeof(LOD::Directory)); | |
1592 | |
1593 } | |
1594 //insert | |
1595 memcpy(&pSubIndices[insert_index],pDir,sizeof(LOD::Directory)); | |
1596 //correct offsets to data | |
1597 if (uNumSubDirs>0) | |
1598 { | |
1599 offset_to_data=sizeof(LOD::Directory)*uNumSubDirs; | |
1600 for (int i=0;i<uNumSubDirs; i++) | |
1601 { | |
1602 pSubIndices[i].uOfsetFromSubindicesStart=offset_to_data; | |
1603 offset_to_data+=pSubIndices[i].uDataSize; | |
1604 } | |
1605 } | |
1606 | |
1607 //construct lod file with added data | |
1608 fwrite( &header, sizeof(LOD::FileHeader), 1, tmp_file); | |
1609 fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file); | |
1610 fseek(pFile,Lindx.uOfsetFromSubindicesStart, SEEK_SET); | |
1611 fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file); | |
1612 | |
1613 offset_to_data = sizeof(LOD::Directory) * uNumSubDirs; | |
1614 if ( !bRewrite_data ) | |
1615 offset_to_data -= sizeof(LOD::Directory); | |
1616 | |
1617 fseek(pFile, offset_to_data, SEEK_CUR); | |
1618 //copy from open lod to temp lod first half | |
1619 to_copy_size=pSubIndices[insert_index].uOfsetFromSubindicesStart-pSubIndices[0].uOfsetFromSubindicesStart; | |
1620 while(to_copy_size>0) | |
1621 { | |
1622 read_size = uIOBufferSize; | |
1623 if ( to_copy_size <= uIOBufferSize ) | |
1624 read_size = to_copy_size; | |
1625 fread(pIOBuffer, 1, read_size, pFile); | |
1626 fwrite(pIOBuffer, 1, read_size, tmp_file); | |
1627 to_copy_size-=read_size; | |
1628 } | |
1629 // add container data | |
1630 fwrite(pDirData, 1, pDir->uDataSize, tmp_file); | |
1631 if ( bRewrite_data ) | |
1632 fseek(pFile,size_correction , SEEK_CUR); | |
1633 | |
1634 //add remainng data last half | |
1635 curr_position = ftell(pFile); | |
1636 fseek(pFile, 0, SEEK_END); | |
1637 to_copy_size = ftell(pFile) - curr_position; | |
1638 fseek(pFile, curr_position, SEEK_SET); | |
1639 while ( to_copy_size > 0 ) | |
1640 { | |
1641 read_size = uIOBufferSize; | |
1642 if ( to_copy_size <= uIOBufferSize ) | |
1643 read_size = to_copy_size; | |
1644 fread(pIOBuffer, 1, read_size, pFile); | |
1645 fwrite(pIOBuffer, 1, read_size, tmp_file); | |
1646 to_copy_size-=read_size; | |
1647 } | |
1648 //replace old file by new with added data | |
1649 strcpy(NewFilename, pLODName); | |
1650 fclose(tmp_file); | |
1651 CloseWriteFile(); | |
1652 remove(NewFilename); | |
1653 rename(Filename, NewFilename); | |
1654 CloseWriteFile(); | |
1655 //reload new | |
1656 LoadFile(pLODName, 0); | |
1657 return 0; | |
0 | 1658 } |
1659 | |
1660 | |
1661 //----- (00461A43) -------------------------------------------------------- | |
1662 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting) | |
982 | 1663 { |
1664 if (bWriting & 1) | |
1665 pFile = fopen(pFilename, "rb"); | |
1666 else | |
1667 pFile = fopen(pFilename, "rb+"); | |
1668 if (!pFile) | |
2165 | 1669 return false;//íà÷àëî îøèáêè â ñîõðàíåíèè íà data\new.lod |
837 | 1670 |
982 | 1671 strcpy(pLODName, pFilename); |
1672 fread(&header, sizeof(LOD::FileHeader), 1, pFile); | |
1673 | |
1674 LOD::Directory lod_indx; | |
1675 fread( &lod_indx,sizeof(LOD::Directory), 1, pFile); | |
0 | 1676 |
982 | 1677 fseek(pFile, 0, SEEK_SET); |
1678 isFileOpened = true; | |
1679 strcpy(pContainerName, "chapter"); | |
1680 uCurrentIndexDir = 0; | |
1681 uLODDataSize = lod_indx.uDataSize; | |
1682 uNumSubDirs = lod_indx.uNumSubIndices; | |
1545 | 1683 Assert(uNumSubDirs <= 300); |
0 | 1684 |
982 | 1685 uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart; |
1686 fseek(pFile, uOffsetToSubIndex, SEEK_SET); | |
837 | 1687 |
982 | 1688 fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile); |
1689 return true; | |
1690 } | |
0 | 1691 |
1692 | |
1693 //----- (00461A11) -------------------------------------------------------- | |
1694 void LOD::File::FreeSubIndexAndIO() | |
1695 { | |
1583 | 1696 free(pSubIndices); |
1697 free(pIOBuffer);// delete [] pIOBuffer; | |
0 | 1698 pIOBuffer = nullptr; |
1699 pSubIndices = nullptr; | |
1700 } | |
1701 | |
1702 | |
1703 //----- (00461954) -------------------------------------------------------- | |
1704 void LOD::File::AllocSubIndicesAndIO(unsigned int uNumSubIndices, unsigned int uBufferSize) | |
1705 { | |
1706 if (pSubIndices) | |
1707 { | |
1708 MessageBoxA(0, "Attempt to reset a LOD subindex!", "MM6", MB_ICONEXCLAMATION); | |
1583 | 1709 free(pSubIndices); |
0 | 1710 pSubIndices = nullptr; |
1711 } | |
1583 | 1712 pSubIndices =(LOD::Directory *)malloc(32 * uNumSubIndices); |
837 | 1713 if (pIOBuffer) |
0 | 1714 { |
1715 MessageBoxA(0, "Attempt to reset a LOD IObuffer!", "MM6", MB_ICONEXCLAMATION); | |
1583 | 1716 free(pIOBuffer); |
837 | 1717 pIOBuffer = NULL; |
0 | 1718 uIOBufferSize = 0; |
1719 } | |
1720 if ( uBufferSize ) | |
1721 { | |
1583 | 1722 pIOBuffer = (unsigned __int8 *)malloc(uBufferSize); |
0 | 1723 uIOBufferSize = uBufferSize; |
1724 } | |
1725 } | |
1726 | |
1727 | |
1728 | |
1729 //----- (0046188A) -------------------------------------------------------- | |
1730 int LOD::File::LoadSubIndices(const char *pContainer) | |
1731 { | |
415 | 1732 |
0 | 1733 unsigned int uDir; // edi@1 |
415 | 1734 LOD::Directory *curr_index; // eax@7 |
0 | 1735 |
1736 ResetSubIndices(); | |
1737 uDir = 0; | |
415 | 1738 |
837 | 1739 for (uDir=0; uDir <header.uNumIndices;++uDir) |
1740 { | |
1741 if (!_stricmp(pContainer, pRoot[uDir].pFilename)) | |
1742 { | |
1743 strcpy( pContainerName, pContainer); | |
415 | 1744 uCurrentIndexDir = uDir; |
1745 curr_index=(LOD::Directory *)&pRoot[uDir]; | |
1746 uOffsetToSubIndex =curr_index->uOfsetFromSubindicesStart ; | |
837 | 1747 uNumSubDirs =curr_index->uNumSubIndices;// *(_WORD *)(v8 + 28); |
1748 fseek( pFile, uOffsetToSubIndex, SEEK_SET); | |
1583 | 1749 pSubIndices = (LOD::Directory *)malloc(sizeof(LOD::Directory)*(uNumSubDirs + 5)); |
415 | 1750 |
1751 if ( pSubIndices) | |
837 | 1752 fread( pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile); |
415 | 1753 return 0; |
837 | 1754 } |
1755 } | |
1756 return 3; | |
0 | 1757 } |
1758 | |
1759 //----- (004617D5) -------------------------------------------------------- | |
1760 bool LOD::File::LoadHeader(const char *pFilename, bool bWriting) | |
1761 { | |
1762 const char *v6; // [sp-4h] [bp-Ch]@4 | |
1763 | |
1764 if ( this->isFileOpened ) | |
1765 Close(); | |
1766 if ( bWriting & 1 ) | |
1767 v6 = "rb"; | |
1768 else | |
1769 v6 = "rb+"; | |
837 | 1770 |
1771 pFile = fopen(pFilename, v6); | |
1772 if ( pFile ) | |
0 | 1773 { |
837 | 1774 strcpy(pLODName, pFilename); |
1775 fread(&header, sizeof(LOD::FileHeader), 1u, pFile); | |
1583 | 1776 pRoot = (LOD::Directory *)malloc(160); |
837 | 1777 if ( pRoot ) |
0 | 1778 { |
837 | 1779 fread(pRoot, sizeof(LOD::Directory), header.uNumIndices, pFile); |
1780 fseek(pFile, 0, SEEK_SET); | |
2165 | 1781 isFileOpened = true; |
0 | 1782 return false; |
1783 } | |
1784 else | |
1785 { | |
837 | 1786 fclose(pFile); |
0 | 1787 return true; |
1788 } | |
1789 } | |
1790 return true; | |
1791 } | |
1792 | |
1793 | |
1794 //----- (00461790) -------------------------------------------------------- | |
1795 LOD::File::~File() | |
1796 { | |
1797 LOD::File *v1; // esi@1 | |
1798 | |
1799 v1 = this; | |
1800 if ( this->isFileOpened ) | |
1801 { | |
1802 fclose(this->pFile); | |
1583 | 1803 free(v1->pSubIndices); |
0 | 1804 } |
1805 } | |
1806 | |
1807 | |
1808 //----- (0046175B) -------------------------------------------------------- | |
1809 LOD::File::File(): | |
1810 pRoot(nullptr), | |
1811 isFileOpened(false) | |
1812 { | |
1813 memset(pLODName, 0, 256); | |
1814 memset(pContainerName, 0, 16); | |
2165 | 1815 this->pFile = 0; |
1816 this->pSubIndices = 0; | |
1817 this->pIOBuffer = 0; | |
1818 this->isFileOpened = false; | |
1819 this->uIOBufferSize = 0; | |
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 ) | |
1545 | 2082 Error("Unable to load %s", pContainer); |
2083 | |
0 | 2084 fread(&DstBuf, 1u, 0x30u, v4); |
2085 Argsa = DstBuf.uTextureSize; | |
2086 if ( DstBuf.uDecompressedSize ) | |
2087 { | |
2088 if ( a3 ) | |
705 | 2089 v6 = malloc(DstBuf.uDecompressedSize+1); |
0 | 2090 else |
1583 | 2091 v6 = malloc(DstBuf.uDecompressedSize+1); |
0 | 2092 v7 = v6; |
1583 | 2093 v8 = malloc(DstBuf.uTextureSize+1); |
0 | 2094 fread(v8, 1u, Argsa, File); |
2095 zlib::MemUnzip(v7, &DstBuf.uDecompressedSize, v8, DstBuf.uTextureSize); | |
2096 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
1583 | 2097 free(v8); |
0 | 2098 } |
2099 else | |
2100 { | |
2101 if ( a3 ) | |
705 | 2102 v9 = malloc(DstBuf.uTextureSize+1); |
0 | 2103 else |
1583 | 2104 v9 = malloc(DstBuf.uTextureSize+1); |
0 | 2105 v7 = v9; |
2106 fread(v9, 1u, Argsa, v5); | |
2107 } | |
2108 return v7; | |
2109 } | |
2110 | |
2111 | |
2112 | |
2113 //----- (00410522) -------------------------------------------------------- | |
2114 int LODFile_IconsBitmaps::_410522(Texture *pDst, const char *pContainer, unsigned int uTextureType) | |
2115 { | |
2116 LODFile_IconsBitmaps *v4; // edi@1 | |
2117 Texture *v5; // esi@5 | |
2118 unsigned int v6; // eax@5 | |
2119 void *v7; // eax@6 | |
2120 unsigned int v8; // ST28_4@6 | |
2121 void *v9; // ST2C_4@6 | |
2122 unsigned __int8 *v10; // eax@7 | |
2123 FILE *v11; // ST28_4@7 | |
2124 void *v12; // eax@9 | |
2125 FILE *v13; // ST28_4@9 | |
2126 signed int v14; // eax@12 | |
2127 int v15; // ecx@12 | |
2128 int v16; // ecx@12 | |
2129 int v17; // eax@12 | |
2130 signed int v18; // ebx@14 | |
2131 int v19; // eax@15 | |
2132 int v20; // edx@15 | |
2133 signed int v21; // ecx@18 | |
2134 signed int v22; // ecx@23 | |
1545 | 2135 //char Args[100]; // [sp+4h] [bp-68h]@3 |
0 | 2136 FILE *File; // [sp+68h] [bp-4h]@1 |
2137 | |
2138 v4 = this; | |
2139 File = FindContainer(pContainer, 0); | |
2140 if ( !File ) | |
2141 { | |
2142 File = FindContainer("pending", 0); | |
2143 if ( !File ) | |
1545 | 2144 Error("Can't find %s!", pContainer); |
2145 | |
0 | 2146 } |
2147 v5 = pDst; | |
2148 fread(pDst, 1u, 0x30u, File); | |
2149 strcpy(v5->pName, pContainer); | |
2150 pDst = (Texture *)v5->uTextureSize; | |
2151 v6 = v5->uDecompressedSize; | |
710 | 2152 v5->pLevelOfDetail0_prolly_alpha_mask = 0; |
0 | 2153 if ( v6 ) |
2154 { | |
1631 | 2155 v7 = malloc(v6); |
0 | 2156 v8 = v5->uTextureSize; |
710 | 2157 v5->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v7; |
1631 | 2158 pContainer = (const char *)malloc(v8); |
0 | 2159 fread((void *)pContainer, 1u, (size_t)pDst, File); |
710 | 2160 zlib::MemUnzip(v5->pLevelOfDetail0_prolly_alpha_mask, &v5->uDecompressedSize, pContainer, v5->uTextureSize); |
0 | 2161 v9 = (void *)pContainer; |
2162 v5->uTextureSize = v5->uDecompressedSize; | |
2163 free(v9); | |
2164 } | |
2165 else | |
2166 { | |
1631 | 2167 v10 = (unsigned __int8 *)malloc(0); |
0 | 2168 v11 = File; |
710 | 2169 v5->pLevelOfDetail0_prolly_alpha_mask = v10; |
0 | 2170 fread(v10, 1u, (size_t)pDst, v11); |
2171 } | |
2172 v5->pPalette24 = 0; | |
2173 if ( uTextureType == 1 ) | |
2174 { | |
1631 | 2175 v12 = malloc(0x300u); |
0 | 2176 v13 = File; |
2177 v5->pPalette24 = (unsigned __int8 *)v12; | |
2178 fread(v12, 1u, 0x300u, v13); | |
2179 LABEL_10: | |
2180 v5->pPalette16 = 0; | |
2181 goto LABEL_11; | |
2182 } | |
2183 if ( uTextureType != 2 ) | |
2184 goto LABEL_10; | |
2185 v18 = 0; | |
2186 v5->pPalette16 = 0; | |
1631 | 2187 v5->pPalette16 = (unsigned __int16 *)malloc(0x400u); |
0 | 2188 do |
2189 { | |
2190 fread((char *)&pContainer + 3, 1u, 1u, File); | |
2191 fread((char *)&uTextureType + 3, 1u, 1u, File); | |
2192 v19 = fread((char *)&pDst + 3, 1u, 1u, File); | |
2193 LOWORD(v19) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2194 v5->pPalette16[v18] = v19 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2195 LOWORD(v20) = (unsigned __int8)(BYTE3(uTextureType) >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2196 v5->pPalette16[v18] += v20 << v4->uTextureBlueBits; | |
2197 v5->pPalette16[v18] += (unsigned __int8)(BYTE3(pDst) >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2198 ++v18; | |
2199 } | |
2200 while ( v18 < 256 ); | |
2201 LABEL_11: | |
2202 if ( v5->pBits & 2 ) | |
2203 { | |
2204 v14 = v5->uSizeOfMaxLevelOfDetail; | |
710 | 2205 v15 = (int)&v5->pLevelOfDetail0_prolly_alpha_mask[v14]; |
0 | 2206 v5->pLevelOfDetail1 = (unsigned __int8 *)v15; |
2207 v16 = (v14 >> 2) + v15; | |
2208 v5->pLevelOfDetail2 = (unsigned __int8 *)v16; | |
2209 v17 = v16 + (v14 >> 4); | |
2210 } | |
2211 else | |
2212 { | |
2213 v17 = 0; | |
2214 v5->pLevelOfDetail2 = 0; | |
2215 v5->pLevelOfDetail1 = 0; | |
2216 } | |
2217 v5->pLevelOfDetail3 = (unsigned __int8 *)v17; | |
2218 v21 = 1; | |
2219 while ( 1 << v21 != v5->uTextureWidth ) | |
2220 { | |
2221 ++v21; | |
2222 if ( v21 >= 15 ) | |
2223 goto LABEL_23; | |
2224 } | |
2225 v5->uWidthLn2 = v21; | |
2226 LABEL_23: | |
2227 v22 = 1; | |
2228 while ( 1 << v22 != v5->uTextureHeight ) | |
2229 { | |
2230 ++v22; | |
2231 if ( v22 >= 15 ) | |
2232 goto LABEL_28; | |
2233 } | |
2234 v5->uHeightLn2 = v22; | |
2235 LABEL_28: | |
2236 switch ( v5->uWidthLn2 ) | |
2237 { | |
2238 case 2: | |
2239 v5->uWidthMinus1 = 3; | |
2240 break; | |
2241 case 3: | |
2242 v5->uWidthMinus1 = 7; | |
2243 break; | |
2244 case 4: | |
2245 v5->uWidthMinus1 = 15; | |
2246 break; | |
2247 case 5: | |
2248 v5->uWidthMinus1 = 31; | |
2249 break; | |
2250 case 6: | |
2251 v5->uWidthMinus1 = 63; | |
2252 break; | |
2253 case 7: | |
2254 v5->uWidthMinus1 = 127; | |
2255 break; | |
2256 case 8: | |
2257 v5->uWidthMinus1 = 255; | |
2258 break; | |
2259 case 9: | |
2260 v5->uWidthMinus1 = 511; | |
2261 break; | |
2262 case 10: | |
2263 v5->uWidthMinus1 = 1023; | |
2264 break; | |
2265 case 11: | |
2266 v5->uWidthMinus1 = 2047; | |
2267 break; | |
2268 case 12: | |
2269 v5->uWidthMinus1 = 4095; | |
2270 break; | |
2271 default: | |
2272 break; | |
2273 } | |
2274 switch ( v5->uHeightLn2 ) | |
2275 { | |
2276 case 2: | |
2277 v5->uHeightMinus1 = 3; | |
2278 break; | |
2279 case 3: | |
2280 v5->uHeightMinus1 = 7; | |
2281 break; | |
2282 case 4: | |
2283 v5->uHeightMinus1 = 15; | |
2284 break; | |
2285 case 5: | |
2286 v5->uHeightMinus1 = 31; | |
2287 break; | |
2288 case 6: | |
2289 v5->uHeightMinus1 = 63; | |
2290 break; | |
2291 case 7: | |
2292 v5->uHeightMinus1 = 127; | |
2293 break; | |
2294 case 8: | |
2295 v5->uHeightMinus1 = 255; | |
2296 break; | |
2297 case 9: | |
2298 v5->uHeightMinus1 = 511; | |
2299 break; | |
2300 case 10: | |
2301 v5->uHeightMinus1 = 1023; | |
2302 break; | |
2303 case 11: | |
2304 v5->uHeightMinus1 = 2047; | |
2305 break; | |
2306 case 12: | |
2307 v5->uHeightMinus1 = 4095; | |
2308 break; | |
2309 default: | |
2310 return 1; | |
2311 } | |
2312 return 1; | |
2313 } | |
2314 | |
2315 | |
2316 //----- (00410423) -------------------------------------------------------- | |
2317 void LODFile_IconsBitmaps::_410423_move_textures_to_device() | |
2318 { | |
2319 LODFile_IconsBitmaps *v1; // esi@1 | |
2320 unsigned int v2; // edi@1 | |
2321 char *v3; // ebx@2 | |
2322 size_t v4; // eax@9 | |
2323 char *v5; // ST1C_4@9 | |
2324 void *v6; // eax@12 | |
2325 signed int v7; // esi@13 | |
2326 | |
2327 v1 = this; | |
2328 v2 = this->uNumLoadedFiles - 1; | |
2329 if ( (v2 & 0x80000000u) == 0 ) | |
2330 { | |
2331 v3 = &this->pTextures[v2].pName[2]; | |
2332 do | |
2333 { | |
2334 if ( v1->ptr_011BB4[v2] ) | |
2335 { | |
2336 if ( *(v3 - 2) != 'w' || *(v3 - 1) != 't' || *v3 != 'r' || v3[1] != 'd' || v3[2] != 'r' ) | |
2337 { | |
2338 pRenderer->LoadTexture( | |
2339 v3 - 2, | |
2340 *((short *)v3 + 17), | |
2341 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2342 &v1->pHardwareTextures[v2]); | |
2343 } | |
2344 else | |
2345 { | |
2346 v4 = strlen(v3 - 2); | |
1631 | 2347 v5 = (char *)malloc(v4 + 2); |
0 | 2348 *v5 = 'h'; |
2349 strcpy(v5 + 1, v3 - 2); | |
2350 pRenderer->LoadTexture( | |
2351 v5, | |
2352 *((short *)v3 + 17), | |
2353 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2354 &v1->pHardwareTextures[v2]); | |
2355 free(v5); | |
2356 } | |
2357 } | |
2358 --v2; | |
2359 v3 -= 72; | |
2360 } | |
2361 while ( (v2 & 0x80000000u) == 0 ); | |
2362 } | |
2363 v6 = v1->ptr_011BB4; | |
2364 if ( v6 ) | |
2365 { | |
2366 v7 = v1->uNumLoadedFiles; | |
2367 if ( v7 > 1 ) | |
2368 memset(v6, 0, v7 - 1); | |
2369 } | |
2370 } | |
2371 | |
2372 | |
2373 //----- (004103BB) -------------------------------------------------------- | |
2374 void LODFile_IconsBitmaps::ReleaseHardwareTextures() | |
2375 { | |
2132 | 2376 //LODFile_IconsBitmaps *v1; // esi@1 |
0 | 2377 unsigned int v2; // edi@1 |
2132 | 2378 //struct IDirect3DTexture2 **v3; // eax@2 |
2379 //struct IDirect3DTexture2 *v4; // eax@3 | |
2380 //struct IDirectDrawSurface **v5; // eax@5 | |
2381 //struct IDirectDrawSurface *v6; // eax@6 | |
0 | 2382 |
2132 | 2383 //v1 = this; |
2384 | |
2385 //while ( 1 ) | |
2386 for ( uint i = 0; i < this->uNumLoadedFiles; i++ ) | |
0 | 2387 { |
2132 | 2388 |
2389 //if ( (v2 & 0x80000000u) != 0 ) | |
2390 //break; | |
2391 //v3 = this->pHardwareTextures; | |
2392 if ( this->pHardwareTextures ) | |
0 | 2393 { |
2132 | 2394 //v4 = this->pHardwareTextures[v2]; |
2395 if ( this->pHardwareTextures[i] ) | |
0 | 2396 { |
2132 | 2397 this->pHardwareTextures[i]->Release(); |
2398 this->pHardwareTextures[i] = 0; | |
2399 this->ptr_011BB4[i] = 1; | |
0 | 2400 } |
2401 } | |
2132 | 2402 //v5 = this->pHardwareSurfaces; |
2403 if ( this->pHardwareSurfaces ) | |
0 | 2404 { |
2132 | 2405 //v6 = this->pHardwareSurfaces[v2]; |
2406 if ( this->pHardwareSurfaces[i] ) | |
0 | 2407 { |
2132 | 2408 this->pHardwareSurfaces[i]->Release(); |
2409 this->pHardwareSurfaces[i] = 0; | |
2410 this->ptr_011BB4[i] = 1; | |
0 | 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 | |
1583 | 2548 //Allocator *v20; // ebx@29 |
0 | 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; | |
1980 | 2576 FILE* pFile = FindContainer(pContainer, false); |
0 | 2577 if (!pFile) |
2578 return -1; | |
2579 v8 = pOutTex; | |
2580 fread(pOutTex, 1u, 0x30u, pFile); | |
2581 strcpy(v8->pName, pContainer); | |
2154 | 2582 if (/*pRenderer->pRenderD3D &&*/ v8->pBits & 2) |
0 | 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); | |
1631 | 2615 v12 = (enum TEXTURE_TYPE)(int)malloc(v11 + 2); |
0 | 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 { | |
1583 | 2633 v32 = malloc(v15); |
710 | 2634 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v32; |
0 | 2635 fread(v32, 1u, (size_t)pOutTex, pFile); |
2636 } | |
2637 else | |
2638 { | |
2639 v17 = malloc(v8->uDecompressedSize); | |
2640 v18 = v8->uTextureSize; | |
2641 pContainer = (const char *)v17; | |
2642 v19 = malloc(v18); | |
2643 fread(v19, 1u, (size_t)pOutTex, pFile); | |
2644 zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize); | |
2645 v8->uTextureSize = *v16; | |
2646 free(v19); | |
2151 | 2647 if ( /*bUseLoResSprites*/false && v8->pBits & 2 ) |
0 | 2648 { |
2649 pOutTex = (Texture *)(((signed int)v8->uSizeOfMaxLevelOfDetail >> 2) | |
2650 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 4) | |
2651 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 6)); | |
1583 | 2652 v21 = malloc((unsigned int)pOutTex); |
0 | 2653 v22 = (size_t)pOutTex; |
2654 v23 = &pContainer[v8->uTextureWidth * v8->uTextureHeight]; | |
710 | 2655 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v21; |
0 | 2656 memcpy(v21, v23, v22); |
2657 v8->uTextureWidth = (signed __int16)v8->uTextureWidth >> 1; | |
2658 v24 = v8->uTextureWidth; | |
2659 v8->uTextureHeight = (signed __int16)v8->uTextureHeight >> 1; | |
2660 v25 = v8->uTextureHeight; | |
2661 --v8->uWidthLn2; | |
2662 --v8->uHeightLn2; | |
2663 v8->uWidthMinus1 = v24 - 1; | |
2664 v26 = v25 - 1; | |
2665 v27 = (signed __int16)v24 * (signed __int16)v25; | |
2666 v28 = pOutTex; | |
2667 v8->uHeightMinus1 = v26; | |
2668 v8->uSizeOfMaxLevelOfDetail = v27; | |
2669 v8->uTextureSize = (unsigned int)v28; | |
2670 } | |
2671 else | |
2672 { | |
2673 v29 = *v16; | |
1583 | 2674 v30 = malloc(v29); |
0 | 2675 v31 = v8->uDecompressedSize; |
710 | 2676 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v30; |
0 | 2677 memcpy(v30, pContainer, v31); |
2678 } | |
2679 free((void *)pContainer); | |
2680 } | |
1583 | 2681 free(v8->pPalette16); |
2682 free(v8->pPalette24); | |
0 | 2683 if ( eTextureType == TEXTURE_24BIT_PALETTE ) |
2684 { | |
1583 | 2685 v33 = malloc(0x300); |
0 | 2686 v8->pPalette24 = (unsigned __int8 *)v33; |
2687 fread(v33, 1u, 0x300u, pFile); | |
2688 } | |
2689 else | |
2690 { | |
2691 v8->pPalette24 = 0; | |
2692 if ( eTextureType == TEXTURE_16BIT_PALETTE ) | |
2693 { | |
1583 | 2694 v8->pPalette16 = (unsigned __int16 *)malloc(0x200); |
0 | 2695 v38 = 0; |
2696 do | |
2697 { | |
2698 fread((char *)&eTextureType + 3, 1u, 1u, pFile); | |
2699 fread((char *)&pContainer + 3, 1u, 1u, pFile); | |
2700 v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile); | |
2701 LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits))); | |
2702 v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits)); | |
2703 LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits))); | |
2704 v8->pPalette16[v38] += v40 << uTextureBlueBits; | |
2705 v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits))); | |
2706 ++v38; | |
2707 } | |
2708 while ( v38 < 256 ); | |
2709 goto LABEL_36; | |
2710 } | |
2711 } | |
2712 v8->pPalette16 = 0; | |
2713 LABEL_36: | |
2714 if ( v8->pBits & 2 ) | |
2715 { | |
2716 v34 = v8->uSizeOfMaxLevelOfDetail; | |
710 | 2717 v35 = &v8->pLevelOfDetail0_prolly_alpha_mask[v34]; |
0 | 2718 v8->pLevelOfDetail1 = v35; |
2719 v36 = &v35[v34 >> 2]; | |
2720 v8->pLevelOfDetail2 = v36; | |
2721 v37 = &v36[v34 >> 4]; | |
2722 } | |
2723 else | |
2724 { | |
2725 v37 = 0; | |
2726 v8->pLevelOfDetail2 = 0; | |
2727 v8->pLevelOfDetail1 = 0; | |
2728 } | |
2729 v8->pLevelOfDetail3 = v37; | |
2730 v41 = 1; | |
2731 while ( 1 << v41 != v8->uTextureWidth ) | |
2732 { | |
2733 ++v41; | |
2734 if ( v41 >= 15 ) | |
2735 goto LABEL_48; | |
2736 } | |
2737 v8->uWidthLn2 = v41; | |
2738 LABEL_48: | |
2739 v42 = 1; | |
2740 while ( 1 << v42 != v8->uTextureHeight ) | |
2741 { | |
2742 ++v42; | |
2743 if ( v42 >= 15 ) | |
2744 goto LABEL_53; | |
2745 } | |
2746 v8->uHeightLn2 = v42; | |
2747 LABEL_53: | |
2748 switch ( v8->uWidthLn2 ) | |
2749 { | |
2750 case 2: | |
2751 v8->uWidthMinus1 = 3; | |
2752 break; | |
2753 case 3: | |
2754 v8->uWidthMinus1 = 7; | |
2755 break; | |
2756 case 4: | |
2757 v8->uWidthMinus1 = 15; | |
2758 break; | |
2759 case 5: | |
2760 v8->uWidthMinus1 = 31; | |
2761 break; | |
2762 case 6: | |
2763 v8->uWidthMinus1 = 63; | |
2764 break; | |
2765 case 7: | |
2766 v8->uWidthMinus1 = 127; | |
2767 break; | |
2768 case 8: | |
2769 v8->uWidthMinus1 = 255; | |
2770 break; | |
2771 case 9: | |
2772 v8->uWidthMinus1 = 511; | |
2773 break; | |
2774 case 10: | |
2775 v8->uWidthMinus1 = 1023; | |
2776 break; | |
2777 case 11: | |
2778 v8->uWidthMinus1 = 2047; | |
2779 break; | |
2780 case 12: | |
2781 v8->uWidthMinus1 = 4095; | |
2782 break; | |
2783 default: | |
2784 break; | |
2785 } | |
2786 switch ( v8->uHeightLn2 ) | |
2787 { | |
2788 case 2: | |
2789 v8->uHeightMinus1 = 3; | |
2790 break; | |
2791 case 3: | |
2792 v8->uHeightMinus1 = 7; | |
2793 break; | |
2794 case 4: | |
2795 v8->uHeightMinus1 = 15; | |
2796 break; | |
2797 case 5: | |
2798 v8->uHeightMinus1 = 31; | |
2799 break; | |
2800 case 6: | |
2801 v8->uHeightMinus1 = 63; | |
2802 break; | |
2803 case 7: | |
2804 v8->uHeightMinus1 = 127; | |
2805 break; | |
2806 case 8: | |
2807 v8->uHeightMinus1 = 255; | |
2808 break; | |
2809 case 9: | |
2810 v8->uHeightMinus1 = 511; | |
2811 break; | |
2812 case 10: | |
2813 v8->uHeightMinus1 = 1023; | |
2814 break; | |
2815 case 11: | |
2816 v8->uHeightMinus1 = 2047; | |
2817 break; | |
2818 case 12: | |
2819 v8->uHeightMinus1 = 4095; | |
2820 break; | |
2821 default: | |
2822 return 1; | |
2823 } | |
2824 return 1; | |
2825 } | |
2826 | |
2827 | |
2828 Texture *LODFile_IconsBitmaps::LoadTexturePtr(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
2829 { | |
2830 uint id = LoadTexture(pContainer, uTextureType); | |
737 | 2831 |
1545 | 2832 Assert(id != -1 && L"Texture not found"); |
737 | 2833 |
0 | 2834 return &pTextures[id]; |
2835 } | |
2836 | |
2837 //----- (0040FB20) -------------------------------------------------------- | |
2838 unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
2839 { | |
2840 //LODFile_IconsBitmaps *v3; // esi@1 | |
2841 //unsigned int v4; // edi@1 | |
2842 //Texture *v5; // ebx@2 | |
2843 unsigned int v6; // ebx@8 | |
2844 const char *Sourcea; // [sp+14h] [bp+8h]@9 | |
2845 | |
2846 //v3 = this; | |
2847 //v4 = 0; | |
2848 areWeLoadingTexture = 1; | |
2849 | |
2850 for (uint i = 0; i < uNumLoadedFiles; ++i) | |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2851 if (!_stricmp(pContainer, pTextures[i].pName)) |
0 | 2852 return i; |
2853 | |
2854 // if (!uNumLoadedFiles) | |
2855 // { | |
2856 //LABEL_5: | |
1545 | 2857 Assert(uNumLoadedFiles < 1000); |
649 | 2858 /*if (uNumLoadedFiles >= 1000) |
0 | 2859 { |
2860 Log::Warning(L"Maximum texture number exceeded"); | |
2861 AbortWithError(); | |
649 | 2862 }*/ |
0 | 2863 if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) |
2864 { | |
2865 v6 = 0; | |
2866 if (uNumLoadedFiles > 0) | |
2867 { | |
2868 Sourcea = (const char *)pTextures; | |
1104 | 2869 while ( _stricmp(Sourcea, "pending") ) |
0 | 2870 { |
2871 Sourcea += 72; | |
2872 ++v6; | |
2873 if (v6 >= uNumLoadedFiles) | |
2874 goto LABEL_15; | |
2875 } | |
2876 return v6; | |
2877 } | |
2878 LABEL_15: | |
2879 LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); | |
2880 } | |
2881 areWeLoadingTexture = 0; | |
2882 ++uNumLoadedFiles; | |
2883 return uNumLoadedFiles - 1; | |
2884 // } | |
2885 // v5 = pTextures; | |
1104 | 2886 // while ( _stricmp(v5->pName, pContainer) ) |
0 | 2887 // { |
2888 // ++v4; | |
2889 // ++v5; | |
2890 // if (v4 >= uNumLoadedFiles ) | |
2891 // goto LABEL_5; | |
2892 // } | |
2893 // return v4; | |
2894 } | |
1297 | 2895 //----- (0046082C) -------------------------------------------------------- |
2896 bool Initialize_GamesLOD_NewLOD() | |
2897 { | |
2898 pGames_LOD = new LODWriteableFile; | |
2899 pGames_LOD->AllocSubIndicesAndIO(300, 0); | |
2900 if (pGames_LOD->LoadFile("data\\games.lod", 1)) | |
2901 { | |
2902 pNew_LOD = new LODWriteableFile; | |
2903 pNew_LOD->AllocSubIndicesAndIO(300, 100000); | |
2904 return true; | |
2905 } | |
2906 return false; | |
2907 } |