Mercurial > mm7
annotate LOD.cpp @ 2191:48a28fe1f32f
pInventoryItemList->Reset()
author | Ritor1 |
---|---|
date | Thu, 30 Jan 2014 17:41:54 +0600 |
parents | 17b3e40daedc |
children | ff8920a40c21 |
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 //----- (00461F1E) -------------------------------------------------------- | |
1464 int LODWriteableFile::CreateTempFile() | |
1465 { | |
982 | 1466 if (!isFileOpened) |
1467 return 1; | |
1468 | |
1469 if (pIOBuffer && uIOBufferSize ) | |
0 | 1470 { |
982 | 1471 uCurrentIndexDir = 0; |
1472 uNumSubDirs = 0; | |
1473 pOutputFileHandle = fopen("lodapp.tmp", "wb+"); | |
1474 return pOutputFileHandle ? 1 : 7; | |
0 | 1475 } |
1476 else | |
982 | 1477 return 5; |
0 | 1478 } |
1479 | |
1480 //----- (00461EE9) -------------------------------------------------------- | |
1481 void LODWriteableFile::CloseWriteFile() | |
1482 { | |
1483 if (isFileOpened) | |
1484 { | |
1485 pContainerName[0] = 0; | |
1486 uCurrentIndexDir = 0; | |
1487 _6A0CA8_lod_unused = 0; | |
1488 | |
1489 isFileOpened = false; | |
1490 fflush(pFile); | |
1491 fclose(pFile); | |
1492 pFile = 0; | |
1493 } | |
1494 } | |
1495 // 6A0CA8: using guessed type int 6A0CA8_lod_unused; | |
1496 | |
1497 | |
1498 //----- (00461B48) -------------------------------------------------------- | |
1499 unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4) | |
982 | 1500 { |
2174 | 1501 char Filename[256]; |
1502 char NewFilename[256]; | |
1503 FILE *tmp_file; | |
2175 | 1504 int comp_res; |
2174 | 1505 bool bRewrite_data; |
1506 int offset_to_data; | |
1507 int total_data_size; | |
1508 int size_correction; | |
1509 int to_copy_size; | |
1510 int read_size; | |
1511 int curr_position; | |
1512 int insert_index; | |
0 | 1513 |
2174 | 1514 //insert new data in sorted index lod file |
1515 bRewrite_data = false; | |
1516 insert_index = -1; | |
2175 | 1517 if ( !isFileOpened )//sometimes gives crash |
2174 | 1518 return 1; |
1519 if ( !pSubIndices ) | |
1520 return 2; | |
1521 if ( !pIOBuffer || !uIOBufferSize ) | |
1522 return 3; | |
982 | 1523 |
2174 | 1524 for ( int i = 0; i < uNumSubDirs; i++ ) |
1525 { | |
2175 | 1526 comp_res = _stricmp(pSubIndices[i].pFilename, pDir->pFilename); |
1527 if( comp_res == 0 ) | |
2174 | 1528 { |
1529 insert_index = i; | |
1530 if ( a4 == 0 ) | |
1531 { | |
1532 bRewrite_data = true; | |
1533 break; | |
1534 } | |
1535 if ( a4 == 1 ) | |
1536 { | |
2175 | 1537 if ( pSubIndices[i].uNumSubIndices < pDir->uNumSubIndices ) |
837 | 1538 { |
2175 | 1539 if ( pSubIndices[i].word_00001E < pDir->word_00001E ) |
2174 | 1540 return 4; |
837 | 1541 } |
2174 | 1542 else |
2178 | 1543 bRewrite_data = true; |
2174 | 1544 break; |
1545 } | |
1546 if ( a4 == 2 ) | |
1547 return 4; | |
1548 } | |
2175 | 1549 else if ( comp_res > 0 ) |
2174 | 1550 { |
1551 if ( insert_index == -1 ) | |
1552 { | |
2175 | 1553 insert_index=i; |
2174 | 1554 break; |
1555 } | |
1556 } | |
1557 } | |
1558 strcpy(Filename, "lod.tmp"); | |
1559 tmp_file = fopen(Filename, "wb+"); | |
1560 if ( !tmp_file ) | |
1561 return 5; | |
1562 if (!bRewrite_data) | |
2177
e1199b655710
pParty->vPrevPosition.y = 1816; and pParty->vPrevPosition.z = 0;
Ritor1
parents:
2176
diff
changeset
|
1563 size_correction = 0; |
2174 | 1564 else |
2177
e1199b655710
pParty->vPrevPosition.y = 1816; and pParty->vPrevPosition.z = 0;
Ritor1
parents:
2176
diff
changeset
|
1565 size_correction = pSubIndices[insert_index].uDataSize; |
837 | 1566 |
2174 | 1567 //create chapter index |
1568 LOD::Directory Lindx; | |
1569 strcpy(Lindx.pFilename, "chapter"); | |
1570 Lindx.dword_000018 = 0; | |
1571 Lindx.word_00001E = 0; | |
1572 Lindx.uNumSubIndices = uNumSubDirs; | |
2175 | 1573 Lindx.uOfsetFromSubindicesStart = sizeof(LOD::FileHeader) + sizeof(LOD::Directory); |
1574 total_data_size = uLODDataSize + pDir->uDataSize-size_correction; | |
2174 | 1575 if (!bRewrite_data) |
1576 { | |
2175 | 1577 total_data_size += sizeof(LOD::Directory); |
2174 | 1578 Lindx.uNumSubIndices++; |
1579 } | |
837 | 1580 |
2175 | 1581 Lindx.uDataSize = total_data_size; |
2174 | 1582 uNumSubDirs = Lindx.uNumSubIndices; |
1583 //move indexes +1 after insert point | |
2178 | 1584 if ( !bRewrite_data && (insert_index < uNumSubDirs) )//ïåðåçàïèñûâàíèå ôàéëîâ äëÿ îñâîáîæäåíèÿ ìåñòà äëÿ íîâîãî ô-ëà |
2174 | 1585 { |
2175 | 1586 for( int i = uNumSubDirs; i > insert_index; --i ) |
2178 | 1587 memcpy(&pSubIndices[i], &pSubIndices[i - 1], sizeof(LOD::Directory)); |
2174 | 1588 } |
1589 //insert | |
2178 | 1590 memcpy(&pSubIndices[insert_index], pDir, sizeof(LOD::Directory));//çàïèñàòü òåêóùèé ôàéë |
2174 | 1591 //correct offsets to data |
1592 if (uNumSubDirs > 0) | |
1593 { | |
2175 | 1594 offset_to_data = sizeof(LOD::Directory) * uNumSubDirs; |
1595 for ( int i = 0; i < uNumSubDirs; i++ ) | |
2174 | 1596 { |
2175 | 1597 pSubIndices[i].uOfsetFromSubindicesStart = offset_to_data; |
1598 offset_to_data += pSubIndices[i].uDataSize; | |
2174 | 1599 } |
1600 } | |
1601 | |
1602 //construct lod file with added data | |
2175 | 1603 fwrite(&header, sizeof(LOD::FileHeader), 1, tmp_file); |
2174 | 1604 fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file); |
1605 fseek(pFile,Lindx.uOfsetFromSubindicesStart, SEEK_SET); | |
1606 fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file); | |
1607 | |
1608 offset_to_data = sizeof(LOD::Directory) * uNumSubDirs; | |
1609 if ( !bRewrite_data ) | |
1610 offset_to_data -= sizeof(LOD::Directory); | |
837 | 1611 |
2174 | 1612 fseek(pFile, offset_to_data, SEEK_CUR); |
1613 //copy from open lod to temp lod first half | |
2175 | 1614 to_copy_size = pSubIndices[insert_index].uOfsetFromSubindicesStart - pSubIndices[0].uOfsetFromSubindicesStart; |
1615 while(to_copy_size > 0) | |
2174 | 1616 { |
1617 read_size = uIOBufferSize; | |
1618 if ( to_copy_size <= uIOBufferSize ) | |
1619 read_size = to_copy_size; | |
1620 fread(pIOBuffer, 1, read_size, pFile); | |
1621 fwrite(pIOBuffer, 1, read_size, tmp_file); | |
2175 | 1622 to_copy_size -= read_size; |
2174 | 1623 } |
1624 // add container data | |
1625 fwrite(pDirData, 1, pDir->uDataSize, tmp_file); | |
1626 if ( bRewrite_data ) | |
1627 fseek(pFile,size_correction , SEEK_CUR); | |
1628 | |
1629 //add remainng data last half | |
1630 curr_position = ftell(pFile); | |
1631 fseek(pFile, 0, SEEK_END); | |
1632 to_copy_size = ftell(pFile) - curr_position; | |
1633 fseek(pFile, curr_position, SEEK_SET); | |
1634 while ( to_copy_size > 0 ) | |
1635 { | |
1636 read_size = uIOBufferSize; | |
1637 if ( to_copy_size <= uIOBufferSize ) | |
1638 read_size = to_copy_size; | |
1639 fread(pIOBuffer, 1, read_size, pFile); | |
1640 fwrite(pIOBuffer, 1, read_size, tmp_file); | |
2175 | 1641 to_copy_size -= read_size; |
2174 | 1642 } |
1643 //replace old file by new with added data | |
1644 strcpy(NewFilename, pLODName); | |
1645 fclose(tmp_file); | |
2179 | 1646 bool test_file_opened1 = isFileOpened; |
2174 | 1647 CloseWriteFile(); //isFileOpened == false, current file |
2179 | 1648 bool test_file_opened2 = isFileOpened; |
2174 | 1649 remove(NewFilename); |
2179 | 1650 bool test_file_opened3 = isFileOpened; |
2174 | 1651 rename(Filename, NewFilename); |
2179 | 1652 bool test_file_opened4 = isFileOpened; |
2174 | 1653 CloseWriteFile(); |
2179 | 1654 bool test_file_opened5 = isFileOpened; |
2174 | 1655 //reload new |
1656 LoadFile(pLODName, 0);//isFileOpened == true, next file | |
1657 if (isFileOpened == false) | |
2173 | 1658 __debugbreak(); |
2174 | 1659 return 0; |
1660 } | |
0 | 1661 |
1662 | |
1663 //----- (00461A43) -------------------------------------------------------- | |
1664 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting) | |
982 | 1665 { |
1666 if (bWriting & 1) | |
1667 pFile = fopen(pFilename, "rb"); | |
1668 else | |
1669 pFile = fopen(pFilename, "rb+"); | |
1670 if (!pFile) | |
2191 | 1671 { |
1672 __debugbreak(); | |
2179 | 1673 return false;// âîçìîæíî ôàéë íå çàêðûò, ïîýòîìó íå îòêðûâàåòñÿ |
2191 | 1674 } |
837 | 1675 |
982 | 1676 strcpy(pLODName, pFilename); |
1677 fread(&header, sizeof(LOD::FileHeader), 1, pFile); | |
1678 | |
1679 LOD::Directory lod_indx; | |
1680 fread( &lod_indx,sizeof(LOD::Directory), 1, pFile); | |
0 | 1681 |
982 | 1682 fseek(pFile, 0, SEEK_SET); |
1683 isFileOpened = true; | |
1684 strcpy(pContainerName, "chapter"); | |
1685 uCurrentIndexDir = 0; | |
1686 uLODDataSize = lod_indx.uDataSize; | |
1687 uNumSubDirs = lod_indx.uNumSubIndices; | |
1545 | 1688 Assert(uNumSubDirs <= 300); |
0 | 1689 |
982 | 1690 uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart; |
1691 fseek(pFile, uOffsetToSubIndex, SEEK_SET); | |
837 | 1692 |
982 | 1693 fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile); |
1694 return true; | |
1695 } | |
0 | 1696 |
1697 | |
1698 //----- (00461A11) -------------------------------------------------------- | |
1699 void LOD::File::FreeSubIndexAndIO() | |
1700 { | |
1583 | 1701 free(pSubIndices); |
1702 free(pIOBuffer);// delete [] pIOBuffer; | |
0 | 1703 pIOBuffer = nullptr; |
1704 pSubIndices = nullptr; | |
1705 } | |
1706 | |
1707 | |
1708 //----- (00461954) -------------------------------------------------------- | |
1709 void LOD::File::AllocSubIndicesAndIO(unsigned int uNumSubIndices, unsigned int uBufferSize) | |
1710 { | |
1711 if (pSubIndices) | |
1712 { | |
1713 MessageBoxA(0, "Attempt to reset a LOD subindex!", "MM6", MB_ICONEXCLAMATION); | |
1583 | 1714 free(pSubIndices); |
0 | 1715 pSubIndices = nullptr; |
1716 } | |
1583 | 1717 pSubIndices =(LOD::Directory *)malloc(32 * uNumSubIndices); |
837 | 1718 if (pIOBuffer) |
0 | 1719 { |
1720 MessageBoxA(0, "Attempt to reset a LOD IObuffer!", "MM6", MB_ICONEXCLAMATION); | |
1583 | 1721 free(pIOBuffer); |
837 | 1722 pIOBuffer = NULL; |
0 | 1723 uIOBufferSize = 0; |
1724 } | |
1725 if ( uBufferSize ) | |
1726 { | |
1583 | 1727 pIOBuffer = (unsigned __int8 *)malloc(uBufferSize); |
0 | 1728 uIOBufferSize = uBufferSize; |
1729 } | |
1730 } | |
1731 | |
1732 | |
1733 | |
1734 //----- (0046188A) -------------------------------------------------------- | |
1735 int LOD::File::LoadSubIndices(const char *pContainer) | |
1736 { | |
415 | 1737 |
0 | 1738 unsigned int uDir; // edi@1 |
415 | 1739 LOD::Directory *curr_index; // eax@7 |
0 | 1740 |
1741 ResetSubIndices(); | |
1742 uDir = 0; | |
415 | 1743 |
837 | 1744 for (uDir=0; uDir <header.uNumIndices;++uDir) |
1745 { | |
1746 if (!_stricmp(pContainer, pRoot[uDir].pFilename)) | |
1747 { | |
1748 strcpy( pContainerName, pContainer); | |
415 | 1749 uCurrentIndexDir = uDir; |
1750 curr_index=(LOD::Directory *)&pRoot[uDir]; | |
1751 uOffsetToSubIndex =curr_index->uOfsetFromSubindicesStart ; | |
837 | 1752 uNumSubDirs =curr_index->uNumSubIndices;// *(_WORD *)(v8 + 28); |
1753 fseek( pFile, uOffsetToSubIndex, SEEK_SET); | |
1583 | 1754 pSubIndices = (LOD::Directory *)malloc(sizeof(LOD::Directory)*(uNumSubDirs + 5)); |
415 | 1755 |
1756 if ( pSubIndices) | |
837 | 1757 fread( pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile); |
415 | 1758 return 0; |
837 | 1759 } |
1760 } | |
1761 return 3; | |
0 | 1762 } |
1763 | |
1764 //----- (004617D5) -------------------------------------------------------- | |
1765 bool LOD::File::LoadHeader(const char *pFilename, bool bWriting) | |
1766 { | |
1767 const char *v6; // [sp-4h] [bp-Ch]@4 | |
1768 | |
1769 if ( this->isFileOpened ) | |
1770 Close(); | |
1771 if ( bWriting & 1 ) | |
1772 v6 = "rb"; | |
1773 else | |
1774 v6 = "rb+"; | |
837 | 1775 |
1776 pFile = fopen(pFilename, v6); | |
1777 if ( pFile ) | |
0 | 1778 { |
837 | 1779 strcpy(pLODName, pFilename); |
2191 | 1780 fread(&header, sizeof(LOD::FileHeader), 1, pFile); |
1583 | 1781 pRoot = (LOD::Directory *)malloc(160); |
837 | 1782 if ( pRoot ) |
0 | 1783 { |
837 | 1784 fread(pRoot, sizeof(LOD::Directory), header.uNumIndices, pFile); |
1785 fseek(pFile, 0, SEEK_SET); | |
2165 | 1786 isFileOpened = true; |
0 | 1787 return false; |
1788 } | |
1789 else | |
1790 { | |
837 | 1791 fclose(pFile); |
0 | 1792 return true; |
1793 } | |
1794 } | |
1795 return true; | |
1796 } | |
1797 | |
1798 | |
1799 //----- (00461790) -------------------------------------------------------- | |
1800 LOD::File::~File() | |
1801 { | |
1802 LOD::File *v1; // esi@1 | |
1803 | |
1804 v1 = this; | |
1805 if ( this->isFileOpened ) | |
1806 { | |
1807 fclose(this->pFile); | |
1583 | 1808 free(v1->pSubIndices); |
0 | 1809 } |
1810 } | |
1811 | |
1812 | |
1813 //----- (0046175B) -------------------------------------------------------- | |
1814 LOD::File::File(): | |
1815 pRoot(nullptr), | |
1816 isFileOpened(false) | |
1817 { | |
1818 memset(pLODName, 0, 256); | |
1819 memset(pContainerName, 0, 16); | |
2165 | 1820 this->pFile = 0; |
1821 this->pSubIndices = 0; | |
1822 this->pIOBuffer = 0; | |
1823 this->isFileOpened = false; | |
1824 this->uIOBufferSize = 0; | |
0 | 1825 Close(); |
1826 } | |
1827 | |
1828 | |
1829 //----- (0046172B) -------------------------------------------------------- | |
1830 LOD::Directory::Directory() | |
1831 { | |
1832 memset(pFilename, 0, 16); | |
1833 this->pFilename[0] = 0; | |
1834 this->uOfsetFromSubindicesStart = 0; | |
1835 this->uDataSize = 0; | |
1836 this->uNumSubIndices = 0; | |
1837 this->dword_000018 = 0; | |
1838 this->word_00001E = 0; | |
1839 } | |
1840 | |
1841 //----- (0046165E) -------------------------------------------------------- | |
1842 int LOD::File::CalcIndexFast(int startIndex, int maxIndex, const char *pContainerName) | |
1843 { | |
1844 int v4; // esi@1 | |
1845 int v5; // ebx@2 | |
1846 int result; // eax@2 | |
1847 int v7; // edi@10 | |
1848 int v8; // esi@11 | |
1849 int v9; // esi@17 | |
1850 LOD::File *v10; // [sp+Ch] [bp-4h]@1 | |
1851 | |
1852 v4 = startIndex; | |
1853 v10 = this; | |
1854 while ( 1 ) // binary search in LOD indices | |
1855 { | |
1856 while ( 1 ) | |
1857 { | |
1858 v5 = maxIndex - v4; | |
1104 | 1859 result = _stricmp((const char *)pContainerName, (const char *)(&v10->pSubIndices[(maxIndex - v4) / 2] + v4)); |
0 | 1860 if ( !result ) |
1861 _6A0CA4_lod_binary_search = (maxIndex - v4) / 2 + v4; | |
1862 if ( v4 == maxIndex ) | |
1863 goto LABEL_14; | |
1864 if ( result < 0 ) | |
1865 break; | |
1866 if ( v5 <= 4 ) | |
1867 { | |
1868 v7 = v4; | |
1869 if ( v4 < maxIndex ) | |
1870 { | |
1871 v9 = v4; | |
1872 do | |
1873 { | |
1104 | 1874 result = _stricmp((const char *)pContainerName, (const char *)&v10->pSubIndices[v9]); |
0 | 1875 if ( !result ) |
1876 goto LABEL_21; | |
1877 ++v7; | |
1878 ++v9; | |
1879 } | |
1880 while ( v7 < maxIndex ); | |
1881 } | |
1882 LABEL_14: | |
1883 _6A0CA4_lod_binary_search = -1; | |
1884 return result; | |
1885 } | |
1886 v4 += (maxIndex - v4) / 2; | |
1887 } | |
1888 if ( v5 <= 4 ) | |
1889 break; | |
1890 maxIndex = (maxIndex - v4) / 2 + v4; | |
1891 } | |
1892 v7 = v4; | |
1893 if ( v4 >= maxIndex ) | |
1894 goto LABEL_14; | |
1895 v8 = v4; | |
1896 while ( 1 ) | |
1897 { | |
1104 | 1898 result = _stricmp((const char *)pContainerName, (const char *)&v10->pSubIndices[v8]); |
0 | 1899 if ( !result ) |
1900 break; | |
1901 ++v7; | |
1902 ++v8; | |
1903 if ( v7 >= maxIndex ) | |
1904 goto LABEL_14; | |
1905 } | |
1906 LABEL_21: | |
1907 _6A0CA4_lod_binary_search = v7; | |
1908 return result; | |
1909 } | |
1910 // 6A0CA4: using guessed type int _6A0CA4_lod_binary_search; | |
1911 | |
1912 | |
1913 //----- (0046161C) -------------------------------------------------------- | |
1914 bool LOD::File::DoesContainerExist(const char *pContainer) | |
1915 { | |
1916 LOD::File *this_dup; // esi@1 | |
1917 int i; // ebx@1 | |
1918 signed int i_dup; // edi@1 | |
1919 bool result; // eax@4 | |
1920 | |
1921 this_dup = this; | |
1922 i = 0; | |
1923 i_dup = 0; | |
837 | 1924 if ( (signed int)this->uNumSubDirs <= 0 ) |
0 | 1925 { |
1926 LABEL_4: | |
1927 result = 0; | |
1928 } | |
1929 else | |
1930 { | |
1104 | 1931 while ( _stricmp((const char *)pContainer, (const char *)&this_dup->pSubIndices[i]) ) |
0 | 1932 { |
1933 ++i_dup; | |
1934 ++i; | |
837 | 1935 if ( i_dup >= (signed int)this_dup->uNumSubDirs ) |
0 | 1936 goto LABEL_4; |
1937 } | |
1938 result = 1; | |
1939 } | |
1940 return result; | |
1941 } | |
1942 | |
1943 | |
1944 //----- (00461397) -------------------------------------------------------- | |
1945 int LODFile_Sprites::_461397() | |
1946 { | |
1947 int result; // eax@1 | |
737 | 1948 //int *pfield_ECA0; // edi@1 |
0 | 1949 int v3; // esi@1 |
1950 int v4; // ecx@3 | |
1951 | |
1952 result = this->uNumLoadedSprites; | |
737 | 1953 //pfield_ECA0 = &this->field_ECA0; |
0 | 1954 v3 = this->field_ECA0; |
1955 this->field_ECA8 = result; | |
1956 if ( result < v3 ) | |
1957 this->field_ECA8 = v3; | |
1958 v4 = this->field_ECA4; | |
1959 if ( v3 < v4 ) | |
737 | 1960 field_ECA0 = v4; |
0 | 1961 return result; |
1962 } | |
1963 | |
1964 //----- (00461580) -------------------------------------------------------- | |
837 | 1965 FILE *LOD::File::FindContainer(const char *pContainer_Name, bool bLinearSearch) |
0 | 1966 { |
1967 unsigned int v4; // eax@4 | |
1968 if (!isFileOpened) | |
1969 return 0; | |
1970 | |
1971 | |
1972 if (bLinearSearch) | |
1973 { | |
837 | 1974 for (uint i = 0; i < uNumSubDirs; ++i) |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
1975 if (!_stricmp(pContainer_Name, pSubIndices[i].pFilename)) |
0 | 1976 { |
1977 v4 = pSubIndices[i].uOfsetFromSubindicesStart; | |
1978 fseek(pFile, uOffsetToSubIndex + v4, SEEK_SET); | |
1979 return pFile; | |
1980 } | |
1981 | |
1982 return nullptr; | |
1983 } | |
1984 else | |
1985 { | |
837 | 1986 CalcIndexFast(0, uNumSubDirs, pContainer_Name); |
0 | 1987 if ( _6A0CA4_lod_binary_search < 0 ) |
1988 return 0; | |
1989 v4 = pSubIndices[_6A0CA4_lod_binary_search].uOfsetFromSubindicesStart; | |
1990 fseek(pFile, uOffsetToSubIndex + v4, SEEK_SET); | |
1991 return pFile; | |
1992 } | |
1993 } | |
1994 | |
1995 //----- (0041097D) -------------------------------------------------------- | |
1996 void LODFile_IconsBitmaps::SetupPalettes(unsigned int uTargetRBits, unsigned int uTargetGBits, unsigned int uTargetBBits) | |
1997 { | |
1998 int v4; // edx@1 | |
1999 LODFile_IconsBitmaps *v5; // esi@1 | |
2000 int v6; // ecx@1 | |
2001 unsigned __int8 v7; // zf@4 | |
2002 unsigned __int8 v8; // sf@4 | |
2003 unsigned __int16 **v9; // edi@5 | |
2004 FILE *v10; // eax@7 | |
2005 FILE *v11; // ebx@7 | |
2006 signed int v12; // ebx@8 | |
2007 int v13; // eax@9 | |
2008 int v14; // edx@9 | |
2009 int v16; // [sp+4Ch] [bp-8h]@4 | |
2010 FILE *File; // [sp+50h] [bp-4h]@7 | |
2011 | |
2012 v4 = uTargetGBits; | |
2013 v5 = this; | |
2014 v6 = uTargetBBits; | |
2015 if ( v5->uTextureRedBits != uTargetRBits | |
2016 || v5->uTextureGreenBits != uTargetGBits | |
2017 || v5->uTextureBlueBits != uTargetBBits ) | |
2018 { | |
2019 v16 = 0; | |
2020 v7 = v5->uNumLoadedFiles == 0; | |
2021 v8 = (v5->uNumLoadedFiles & 0x80000000u) != 0; | |
2022 v5->uTextureRedBits = uTargetRBits; | |
2023 v5->uTextureGreenBits = v4; | |
2024 v5->uTextureBlueBits = v6; | |
2025 if ( !(v8 | v7) ) | |
2026 { | |
2027 v9 = &v5->pTextures[0].pPalette16; | |
2028 do | |
2029 { | |
2030 Texture DstBuf; // [sp+4h] [bp-50h]@6 | |
2031 //Texture::Texture(&DstBuf); | |
2032 | |
2033 if ( *v9 ) | |
2034 { | |
2035 v10 = FindContainer((const char *)v9 - 64, 0); | |
2036 v11 = v10; | |
2037 File = v10; | |
2038 if ( v10 ) | |
2039 { | |
2040 fread(&DstBuf, 1u, 0x30u, v10); | |
2041 fseek(v11, DstBuf.uTextureSize, 1); | |
2042 v12 = 0; | |
2043 do | |
2044 { | |
2045 fread((char *)&uTargetRBits + 3, 1u, 1u, File); | |
2046 fread((char *)&uTargetBBits + 3, 1u, 1u, File); | |
2047 v13 = fread((char *)&uTargetGBits + 3, 1u, 1u, File); | |
2048 LOWORD(v13) = (unsigned __int8)(BYTE3(uTargetRBits) >> (8 - LOBYTE(v5->uTextureRedBits))); | |
2049 (*v9)[v12] = v13 << (LOBYTE(v5->uTextureGreenBits) + LOBYTE(v5->uTextureBlueBits)); | |
2050 LOWORD(v14) = (unsigned __int8)(BYTE3(uTargetBBits) >> (8 - LOBYTE(v5->uTextureGreenBits))); | |
2051 (*v9)[v12] |= v14 << v5->uTextureBlueBits; | |
2052 (*v9)[v12] |= BYTE3(uTargetGBits) >> (8 - LOBYTE(v5->uTextureBlueBits)); | |
2053 ++v12; | |
2054 } | |
2055 while ( v12 < 256 ); | |
2056 } | |
2057 } | |
2058 ++v16; | |
2059 v9 += 18; | |
2060 } | |
2061 while ( v16 < (signed int)v5->uNumLoadedFiles ); | |
2062 } | |
2063 } | |
2064 } | |
2065 | |
2066 | |
2067 | |
2068 //----- (0041088B) -------------------------------------------------------- | |
2069 void *LOD::File::LoadRaw(const char *pContainer, int a3) | |
2070 { | |
2071 LOD::File *v3; // esi@1 | |
2072 FILE *v4; // eax@1 | |
2073 FILE *v5; // esi@1 | |
2074 void *v6; // eax@5 | |
2075 void *v7; // ebx@7 | |
2076 void *v8; // edi@7 | |
2077 void *v9; // eax@9 | |
2078 Texture DstBuf; // [sp+Ch] [bp-4Ch]@1 | |
2079 FILE *File; // [sp+54h] [bp-4h]@1 | |
2080 unsigned int Argsa; // [sp+60h] [bp+8h]@3 | |
2081 | |
2082 v3 = this; | |
2083 v4 = FindContainer(pContainer, 0); | |
2084 v5 = v4; | |
2085 File = v4; | |
2086 if ( !v4 ) | |
1545 | 2087 Error("Unable to load %s", pContainer); |
2088 | |
0 | 2089 fread(&DstBuf, 1u, 0x30u, v4); |
2090 Argsa = DstBuf.uTextureSize; | |
2091 if ( DstBuf.uDecompressedSize ) | |
2092 { | |
2093 if ( a3 ) | |
705 | 2094 v6 = malloc(DstBuf.uDecompressedSize+1); |
0 | 2095 else |
1583 | 2096 v6 = malloc(DstBuf.uDecompressedSize+1); |
0 | 2097 v7 = v6; |
1583 | 2098 v8 = malloc(DstBuf.uTextureSize+1); |
0 | 2099 fread(v8, 1u, Argsa, File); |
2100 zlib::MemUnzip(v7, &DstBuf.uDecompressedSize, v8, DstBuf.uTextureSize); | |
2101 DstBuf.uTextureSize = DstBuf.uDecompressedSize; | |
1583 | 2102 free(v8); |
0 | 2103 } |
2104 else | |
2105 { | |
2106 if ( a3 ) | |
705 | 2107 v9 = malloc(DstBuf.uTextureSize+1); |
0 | 2108 else |
1583 | 2109 v9 = malloc(DstBuf.uTextureSize+1); |
0 | 2110 v7 = v9; |
2111 fread(v9, 1u, Argsa, v5); | |
2112 } | |
2113 return v7; | |
2114 } | |
2115 | |
2116 | |
2117 | |
2118 //----- (00410522) -------------------------------------------------------- | |
2119 int LODFile_IconsBitmaps::_410522(Texture *pDst, const char *pContainer, unsigned int uTextureType) | |
2120 { | |
2121 LODFile_IconsBitmaps *v4; // edi@1 | |
2122 Texture *v5; // esi@5 | |
2123 unsigned int v6; // eax@5 | |
2124 void *v7; // eax@6 | |
2125 unsigned int v8; // ST28_4@6 | |
2126 void *v9; // ST2C_4@6 | |
2127 unsigned __int8 *v10; // eax@7 | |
2128 FILE *v11; // ST28_4@7 | |
2129 void *v12; // eax@9 | |
2130 FILE *v13; // ST28_4@9 | |
2131 signed int v14; // eax@12 | |
2132 int v15; // ecx@12 | |
2133 int v16; // ecx@12 | |
2134 int v17; // eax@12 | |
2135 signed int v18; // ebx@14 | |
2136 int v19; // eax@15 | |
2137 int v20; // edx@15 | |
2138 signed int v21; // ecx@18 | |
2139 signed int v22; // ecx@23 | |
1545 | 2140 //char Args[100]; // [sp+4h] [bp-68h]@3 |
0 | 2141 FILE *File; // [sp+68h] [bp-4h]@1 |
2142 | |
2143 v4 = this; | |
2144 File = FindContainer(pContainer, 0); | |
2145 if ( !File ) | |
2146 { | |
2147 File = FindContainer("pending", 0); | |
2148 if ( !File ) | |
1545 | 2149 Error("Can't find %s!", pContainer); |
2150 | |
0 | 2151 } |
2152 v5 = pDst; | |
2153 fread(pDst, 1u, 0x30u, File); | |
2154 strcpy(v5->pName, pContainer); | |
2155 pDst = (Texture *)v5->uTextureSize; | |
2156 v6 = v5->uDecompressedSize; | |
710 | 2157 v5->pLevelOfDetail0_prolly_alpha_mask = 0; |
0 | 2158 if ( v6 ) |
2159 { | |
1631 | 2160 v7 = malloc(v6); |
0 | 2161 v8 = v5->uTextureSize; |
710 | 2162 v5->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v7; |
1631 | 2163 pContainer = (const char *)malloc(v8); |
0 | 2164 fread((void *)pContainer, 1u, (size_t)pDst, File); |
710 | 2165 zlib::MemUnzip(v5->pLevelOfDetail0_prolly_alpha_mask, &v5->uDecompressedSize, pContainer, v5->uTextureSize); |
0 | 2166 v9 = (void *)pContainer; |
2167 v5->uTextureSize = v5->uDecompressedSize; | |
2168 free(v9); | |
2169 } | |
2170 else | |
2171 { | |
1631 | 2172 v10 = (unsigned __int8 *)malloc(0); |
0 | 2173 v11 = File; |
710 | 2174 v5->pLevelOfDetail0_prolly_alpha_mask = v10; |
0 | 2175 fread(v10, 1u, (size_t)pDst, v11); |
2176 } | |
2177 v5->pPalette24 = 0; | |
2178 if ( uTextureType == 1 ) | |
2179 { | |
1631 | 2180 v12 = malloc(0x300u); |
0 | 2181 v13 = File; |
2182 v5->pPalette24 = (unsigned __int8 *)v12; | |
2183 fread(v12, 1u, 0x300u, v13); | |
2184 LABEL_10: | |
2185 v5->pPalette16 = 0; | |
2186 goto LABEL_11; | |
2187 } | |
2188 if ( uTextureType != 2 ) | |
2189 goto LABEL_10; | |
2190 v18 = 0; | |
2191 v5->pPalette16 = 0; | |
1631 | 2192 v5->pPalette16 = (unsigned __int16 *)malloc(0x400u); |
0 | 2193 do |
2194 { | |
2195 fread((char *)&pContainer + 3, 1u, 1u, File); | |
2196 fread((char *)&uTextureType + 3, 1u, 1u, File); | |
2197 v19 = fread((char *)&pDst + 3, 1u, 1u, File); | |
2198 LOWORD(v19) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2199 v5->pPalette16[v18] = v19 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2200 LOWORD(v20) = (unsigned __int8)(BYTE3(uTextureType) >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2201 v5->pPalette16[v18] += v20 << v4->uTextureBlueBits; | |
2202 v5->pPalette16[v18] += (unsigned __int8)(BYTE3(pDst) >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2203 ++v18; | |
2204 } | |
2205 while ( v18 < 256 ); | |
2206 LABEL_11: | |
2207 if ( v5->pBits & 2 ) | |
2208 { | |
2209 v14 = v5->uSizeOfMaxLevelOfDetail; | |
710 | 2210 v15 = (int)&v5->pLevelOfDetail0_prolly_alpha_mask[v14]; |
0 | 2211 v5->pLevelOfDetail1 = (unsigned __int8 *)v15; |
2212 v16 = (v14 >> 2) + v15; | |
2213 v5->pLevelOfDetail2 = (unsigned __int8 *)v16; | |
2214 v17 = v16 + (v14 >> 4); | |
2215 } | |
2216 else | |
2217 { | |
2218 v17 = 0; | |
2219 v5->pLevelOfDetail2 = 0; | |
2220 v5->pLevelOfDetail1 = 0; | |
2221 } | |
2222 v5->pLevelOfDetail3 = (unsigned __int8 *)v17; | |
2223 v21 = 1; | |
2224 while ( 1 << v21 != v5->uTextureWidth ) | |
2225 { | |
2226 ++v21; | |
2227 if ( v21 >= 15 ) | |
2228 goto LABEL_23; | |
2229 } | |
2230 v5->uWidthLn2 = v21; | |
2231 LABEL_23: | |
2232 v22 = 1; | |
2233 while ( 1 << v22 != v5->uTextureHeight ) | |
2234 { | |
2235 ++v22; | |
2236 if ( v22 >= 15 ) | |
2237 goto LABEL_28; | |
2238 } | |
2239 v5->uHeightLn2 = v22; | |
2240 LABEL_28: | |
2241 switch ( v5->uWidthLn2 ) | |
2242 { | |
2243 case 2: | |
2244 v5->uWidthMinus1 = 3; | |
2245 break; | |
2246 case 3: | |
2247 v5->uWidthMinus1 = 7; | |
2248 break; | |
2249 case 4: | |
2250 v5->uWidthMinus1 = 15; | |
2251 break; | |
2252 case 5: | |
2253 v5->uWidthMinus1 = 31; | |
2254 break; | |
2255 case 6: | |
2256 v5->uWidthMinus1 = 63; | |
2257 break; | |
2258 case 7: | |
2259 v5->uWidthMinus1 = 127; | |
2260 break; | |
2261 case 8: | |
2262 v5->uWidthMinus1 = 255; | |
2263 break; | |
2264 case 9: | |
2265 v5->uWidthMinus1 = 511; | |
2266 break; | |
2267 case 10: | |
2268 v5->uWidthMinus1 = 1023; | |
2269 break; | |
2270 case 11: | |
2271 v5->uWidthMinus1 = 2047; | |
2272 break; | |
2273 case 12: | |
2274 v5->uWidthMinus1 = 4095; | |
2275 break; | |
2276 default: | |
2277 break; | |
2278 } | |
2279 switch ( v5->uHeightLn2 ) | |
2280 { | |
2281 case 2: | |
2282 v5->uHeightMinus1 = 3; | |
2283 break; | |
2284 case 3: | |
2285 v5->uHeightMinus1 = 7; | |
2286 break; | |
2287 case 4: | |
2288 v5->uHeightMinus1 = 15; | |
2289 break; | |
2290 case 5: | |
2291 v5->uHeightMinus1 = 31; | |
2292 break; | |
2293 case 6: | |
2294 v5->uHeightMinus1 = 63; | |
2295 break; | |
2296 case 7: | |
2297 v5->uHeightMinus1 = 127; | |
2298 break; | |
2299 case 8: | |
2300 v5->uHeightMinus1 = 255; | |
2301 break; | |
2302 case 9: | |
2303 v5->uHeightMinus1 = 511; | |
2304 break; | |
2305 case 10: | |
2306 v5->uHeightMinus1 = 1023; | |
2307 break; | |
2308 case 11: | |
2309 v5->uHeightMinus1 = 2047; | |
2310 break; | |
2311 case 12: | |
2312 v5->uHeightMinus1 = 4095; | |
2313 break; | |
2314 default: | |
2315 return 1; | |
2316 } | |
2317 return 1; | |
2318 } | |
2319 | |
2320 | |
2321 //----- (00410423) -------------------------------------------------------- | |
2322 void LODFile_IconsBitmaps::_410423_move_textures_to_device() | |
2323 { | |
2324 LODFile_IconsBitmaps *v1; // esi@1 | |
2325 unsigned int v2; // edi@1 | |
2326 char *v3; // ebx@2 | |
2327 size_t v4; // eax@9 | |
2328 char *v5; // ST1C_4@9 | |
2329 void *v6; // eax@12 | |
2330 signed int v7; // esi@13 | |
2331 | |
2332 v1 = this; | |
2333 v2 = this->uNumLoadedFiles - 1; | |
2334 if ( (v2 & 0x80000000u) == 0 ) | |
2335 { | |
2336 v3 = &this->pTextures[v2].pName[2]; | |
2337 do | |
2338 { | |
2339 if ( v1->ptr_011BB4[v2] ) | |
2340 { | |
2341 if ( *(v3 - 2) != 'w' || *(v3 - 1) != 't' || *v3 != 'r' || v3[1] != 'd' || v3[2] != 'r' ) | |
2342 { | |
2343 pRenderer->LoadTexture( | |
2344 v3 - 2, | |
2345 *((short *)v3 + 17), | |
2346 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2347 &v1->pHardwareTextures[v2]); | |
2348 } | |
2349 else | |
2350 { | |
2351 v4 = strlen(v3 - 2); | |
1631 | 2352 v5 = (char *)malloc(v4 + 2); |
0 | 2353 *v5 = 'h'; |
2354 strcpy(v5 + 1, v3 - 2); | |
2355 pRenderer->LoadTexture( | |
2356 v5, | |
2357 *((short *)v3 + 17), | |
2358 (IDirectDrawSurface4 **)&v1->pHardwareSurfaces[v2], | |
2359 &v1->pHardwareTextures[v2]); | |
2360 free(v5); | |
2361 } | |
2362 } | |
2363 --v2; | |
2364 v3 -= 72; | |
2365 } | |
2366 while ( (v2 & 0x80000000u) == 0 ); | |
2367 } | |
2368 v6 = v1->ptr_011BB4; | |
2369 if ( v6 ) | |
2370 { | |
2371 v7 = v1->uNumLoadedFiles; | |
2372 if ( v7 > 1 ) | |
2373 memset(v6, 0, v7 - 1); | |
2374 } | |
2375 } | |
2376 | |
2377 | |
2378 //----- (004103BB) -------------------------------------------------------- | |
2379 void LODFile_IconsBitmaps::ReleaseHardwareTextures() | |
2380 { | |
2132 | 2381 //LODFile_IconsBitmaps *v1; // esi@1 |
0 | 2382 unsigned int v2; // edi@1 |
2132 | 2383 //struct IDirect3DTexture2 **v3; // eax@2 |
2384 //struct IDirect3DTexture2 *v4; // eax@3 | |
2385 //struct IDirectDrawSurface **v5; // eax@5 | |
2386 //struct IDirectDrawSurface *v6; // eax@6 | |
0 | 2387 |
2132 | 2388 //v1 = this; |
2389 | |
2390 //while ( 1 ) | |
2391 for ( uint i = 0; i < this->uNumLoadedFiles; i++ ) | |
0 | 2392 { |
2132 | 2393 |
2394 //if ( (v2 & 0x80000000u) != 0 ) | |
2395 //break; | |
2396 //v3 = this->pHardwareTextures; | |
2397 if ( this->pHardwareTextures ) | |
0 | 2398 { |
2132 | 2399 //v4 = this->pHardwareTextures[v2]; |
2400 if ( this->pHardwareTextures[i] ) | |
0 | 2401 { |
2132 | 2402 this->pHardwareTextures[i]->Release(); |
2403 this->pHardwareTextures[i] = 0; | |
2404 this->ptr_011BB4[i] = 1; | |
0 | 2405 } |
2406 } | |
2132 | 2407 //v5 = this->pHardwareSurfaces; |
2408 if ( this->pHardwareSurfaces ) | |
0 | 2409 { |
2132 | 2410 //v6 = this->pHardwareSurfaces[v2]; |
2411 if ( this->pHardwareSurfaces[i] ) | |
0 | 2412 { |
2132 | 2413 this->pHardwareSurfaces[i]->Release(); |
2414 this->pHardwareSurfaces[i] = 0; | |
2415 this->ptr_011BB4[i] = 1; | |
0 | 2416 } |
2417 } | |
2418 } | |
2419 } | |
2420 | |
2421 | |
2422 //----- (0041033D) -------------------------------------------------------- | |
2423 void LODFile_IconsBitmaps::ReleaseLostHardwareTextures() | |
2424 { | |
2425 LODFile_IconsBitmaps *v1; // edi@1 | |
2426 unsigned int i; // ebx@1 | |
2427 struct IDirectDrawSurface **pHardwareSurfaces; // eax@2 | |
2428 int v4; // esi@3 | |
2429 struct IDirectDrawSurface *pSurface; // eax@3 | |
2430 struct IDirect3DTexture2 **v6; // eax@5 | |
2431 struct IDirect3DTexture2 *v7; // eax@6 | |
2432 | |
2433 v1 = this; | |
2434 for ( i = this->uNumLoadedFiles - 1; (i & 0x80000000u) == 0; --i ) | |
2435 { | |
2436 pHardwareSurfaces = v1->pHardwareSurfaces; | |
2437 if ( pHardwareSurfaces ) | |
2438 { | |
2439 v4 = i; | |
2440 pSurface = pHardwareSurfaces[i]; | |
2441 if ( pSurface ) | |
2442 { | |
2443 if ( pSurface->IsLost() == DDERR_SURFACELOST ) | |
2444 { | |
2445 v6 = v1->pHardwareTextures; | |
2446 if ( v6 ) | |
2447 { | |
2448 v7 = v6[v4]; | |
2449 if ( v7 ) | |
2450 { | |
2451 v7->Release(); | |
2452 v1->pHardwareTextures[v4] = 0; | |
2453 } | |
2454 } | |
2455 v1->pHardwareSurfaces[v4]->Release(); | |
2456 v1->pHardwareSurfaces[v4] = 0; | |
2457 v1->ptr_011BB4[i] = 1; | |
2458 } | |
2459 } | |
2460 } | |
2461 } | |
2462 } | |
2463 | |
2464 //----- (004101B1) -------------------------------------------------------- | |
2465 int LODFile_IconsBitmaps::ReloadTexture(Texture *pDst, const char *pContainer, int mode) | |
2466 { | |
2467 LODFile_IconsBitmaps *v4; // edi@1 | |
2468 FILE *v5; // eax@1 | |
2469 Texture *v6; // esi@2 | |
2470 unsigned int v7; // ebx@6 | |
2471 unsigned int v8; // ecx@6 | |
2472 signed int result; // eax@7 | |
2473 size_t *v10; // ebx@8 | |
2474 signed int v11; // ebx@12 | |
2475 int v12; // eax@13 | |
2476 int v13; // edx@13 | |
2477 FILE *File; // [sp+Ch] [bp-8h]@1 | |
2478 unsigned __int8 v15; // [sp+11h] [bp-3h]@13 | |
2479 unsigned __int8 v16; // [sp+12h] [bp-2h]@13 | |
2480 unsigned __int8 DstBuf; // [sp+13h] [bp-1h]@13 | |
2481 void *DstBufa; // [sp+1Ch] [bp+8h]@10 | |
2482 void *Sourcea; // [sp+20h] [bp+Ch]@10 | |
2483 unsigned int Counta; // [sp+24h] [bp+10h]@6 | |
2484 | |
2485 v4 = this; | |
2486 v5 = FindContainer(pContainer, 0); | |
2487 File = v5; | |
2488 if ( v5 | |
710 | 2489 && (v6 = pDst, pDst->pLevelOfDetail0_prolly_alpha_mask) |
0 | 2490 && mode == 2 |
2491 && pDst->pPalette16 | |
2492 && !pDst->pPalette24 | |
2493 && (v7 = pDst->uTextureSize, | |
2494 fread(pDst, 1u, 0x30u, v5), | |
2495 strcpy(pDst->pName, pContainer), | |
2496 v8 = pDst->uTextureSize, | |
2497 Counta = pDst->uTextureSize, | |
2498 (signed int)v8 <= (signed int)v7) ) | |
2499 { | |
2500 v10 = &pDst->uDecompressedSize; | |
2501 if ( !pDst->uDecompressedSize || v4->dword_011BA4 ) | |
2502 { | |
710 | 2503 fread(pDst->pLevelOfDetail0_prolly_alpha_mask, 1u, v8, File); |
0 | 2504 } |
2505 else | |
2506 { | |
2507 Sourcea = malloc(pDst->uDecompressedSize); | |
2508 DstBufa = malloc(pDst->uTextureSize); | |
2509 fread(DstBufa, 1u, Counta, File); | |
2510 zlib::MemUnzip(Sourcea, &v6->uDecompressedSize, DstBufa, v6->uTextureSize); | |
2511 v6->uTextureSize = *v10; | |
2512 free(DstBufa); | |
710 | 2513 memcpy(v6->pLevelOfDetail0_prolly_alpha_mask, Sourcea, *v10); |
0 | 2514 free(Sourcea); |
2515 } | |
2516 v11 = 0; | |
2517 do | |
2518 { | |
2519 fread(&DstBuf, 1u, 1u, File); | |
2520 fread(&v16, 1u, 1u, File); | |
2521 v12 = fread(&v15, 1u, 1u, File); | |
2522 LOWORD(v12) = (unsigned __int8)(DstBuf >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2523 v6->pPalette16[v11] = v12 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2524 LOWORD(v13) = (unsigned __int8)(v16 >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2525 v6->pPalette16[v11] += v13 << v4->uTextureBlueBits; | |
2526 v6->pPalette16[v11] += (unsigned __int8)(v15 >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2527 ++v11; | |
2528 } | |
2529 while ( v11 < 256 ); | |
2530 result = 1; | |
2531 } | |
2532 else | |
2533 { | |
2534 result = -1; | |
2535 } | |
2536 return result; | |
2537 } | |
2538 | |
2539 | |
2540 //----- (0040FC08) -------------------------------------------------------- | |
2541 int LODFile_IconsBitmaps::LoadTextureFromLOD(Texture *pOutTex, const char *pContainer, enum TEXTURE_TYPE eTextureType) | |
2542 { | |
2543 Texture *v8; // esi@3 | |
2544 size_t v11; // eax@14 | |
2545 enum TEXTURE_TYPE v12; // eax@14 | |
2546 signed int v13; // esi@14 | |
2547 unsigned int v14; // eax@21 | |
2548 unsigned int v15; // ecx@25 | |
2549 unsigned int *v16; // ebx@25 | |
2550 void *v17; // eax@27 | |
2551 unsigned int v18; // ST28_4@27 | |
2552 void *v19; // ST3C_4@27 | |
1583 | 2553 //Allocator *v20; // ebx@29 |
0 | 2554 void *v21; // eax@29 |
2555 size_t v22; // ST2C_4@29 | |
2556 const void *v23; // ecx@29 | |
2557 unsigned __int16 v24; // ax@29 | |
2558 unsigned __int16 v25; // cx@29 | |
2559 __int16 v26; // dx@29 | |
2560 unsigned int v27; // ecx@29 | |
2561 Texture *v28; // eax@29 | |
2562 unsigned int v29; // ST28_4@30 | |
2563 void *v30; // eax@30 | |
2564 unsigned int v31; // ST2C_4@30 | |
2565 void *v32; // eax@32 | |
2566 void *v33; // eax@34 | |
2567 signed int v34; // eax@37 | |
2568 unsigned __int8 *v35; // ecx@37 | |
2569 unsigned __int8 *v36; // ecx@37 | |
2570 unsigned __int8 *v37; // eax@37 | |
2571 signed int v38; // ebx@39 | |
2572 int v39; // eax@40 | |
2573 int v40; // edx@40 | |
2574 signed int v41; // ecx@43 | |
2575 signed int v42; // ecx@48 | |
2576 | |
2577 //v4 = pContainer; | |
2578 //v5 = this; | |
2579 //v6 = FindContainer(pContainer, 0); | |
2580 //File = v6; | |
1980 | 2581 FILE* pFile = FindContainer(pContainer, false); |
0 | 2582 if (!pFile) |
2583 return -1; | |
2584 v8 = pOutTex; | |
2181 | 2585 fread(pOutTex, 1, 0x30, pFile); |
0 | 2586 strcpy(v8->pName, pContainer); |
2154 | 2587 if (/*pRenderer->pRenderD3D &&*/ v8->pBits & 2) |
0 | 2588 { |
2589 if (!pHardwareSurfaces || !pHardwareTextures) | |
2590 { | |
2591 pHardwareSurfaces = new IDirectDrawSurface *[1000]; | |
2592 memset(pHardwareSurfaces, 0, 1000 * sizeof(IDirectDrawSurface4 *)); | |
2593 | |
2594 pHardwareTextures = new IDirect3DTexture2 *[1000]; | |
2595 memset(pHardwareTextures, 0, 1000 * sizeof(IDirect3DTexture2 *)); | |
2596 | |
2597 ptr_011BB4 = new char[1000]; | |
2598 memset(ptr_011BB4, 0, 1000); | |
2599 } | |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2600 if (_strnicmp(pContainer, "wtrdr", 5))//*v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' ) |
0 | 2601 { |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2602 if (_strnicmp(pContainer, "WtrTyl", 6))//if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' ) |
0 | 2603 { |
2604 v14 = uNumLoadedFiles; | |
2605 } | |
2606 else | |
2607 { | |
265 | 2608 pRenderer->hd_water_tile_id = uNumLoadedFiles; |
0 | 2609 v14 = uNumLoadedFiles; |
2610 } | |
2181 | 2611 v13 = pRenderer->LoadTexture(pContainer, v8->palette_id1, (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], &pHardwareTextures[v14]); |
0 | 2612 } |
2613 else | |
2614 { | |
2615 v11 = strlen(pContainer); | |
1631 | 2616 v12 = (enum TEXTURE_TYPE)(int)malloc(v11 + 2); |
0 | 2617 eTextureType = v12; |
2618 *(char *)v12 = 104; | |
2619 strcpy((char *)(v12 + 1), pContainer); | |
2181 | 2620 v13 = pRenderer->LoadTexture((const char *)eTextureType, v8->palette_id1, |
2621 (IDirectDrawSurface4 **)&pHardwareSurfaces[uNumLoadedFiles], &pHardwareTextures[uNumLoadedFiles]); | |
0 | 2622 free((void *)eTextureType); |
2623 } | |
2624 return v13; | |
2625 } | |
2626 v15 = v8->uTextureSize; | |
2627 v16 = &v8->uDecompressedSize; | |
2628 pOutTex = (Texture *)v8->uTextureSize; | |
2629 if ( !v8->uDecompressedSize || dword_011BA4 ) | |
2630 { | |
1583 | 2631 v32 = malloc(v15); |
710 | 2632 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v32; |
2181 | 2633 fread(v32, 1, (size_t)pOutTex, pFile); |
0 | 2634 } |
2635 else | |
2636 { | |
2637 v17 = malloc(v8->uDecompressedSize); | |
2638 v18 = v8->uTextureSize; | |
2639 pContainer = (const char *)v17; | |
2640 v19 = malloc(v18); | |
2641 fread(v19, 1u, (size_t)pOutTex, pFile); | |
2642 zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize); | |
2643 v8->uTextureSize = *v16; | |
2644 free(v19); | |
2151 | 2645 if ( /*bUseLoResSprites*/false && v8->pBits & 2 ) |
0 | 2646 { |
2647 pOutTex = (Texture *)(((signed int)v8->uSizeOfMaxLevelOfDetail >> 2) | |
2648 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 4) | |
2649 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 6)); | |
1583 | 2650 v21 = malloc((unsigned int)pOutTex); |
0 | 2651 v22 = (size_t)pOutTex; |
2652 v23 = &pContainer[v8->uTextureWidth * v8->uTextureHeight]; | |
710 | 2653 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v21; |
0 | 2654 memcpy(v21, v23, v22); |
2181 | 2655 v8->uTextureWidth = (signed __int16)v8->uTextureWidth / 2; |
2656 //v24 = v8->uTextureWidth; | |
2657 v8->uTextureHeight = (signed __int16)v8->uTextureHeight / 2; | |
0 | 2658 v25 = v8->uTextureHeight; |
2659 --v8->uWidthLn2; | |
2660 --v8->uHeightLn2; | |
2181 | 2661 v8->uWidthMinus1 = v8->uTextureWidth - 1; |
0 | 2662 v26 = v25 - 1; |
2181 | 2663 v27 = (signed __int16)v8->uTextureWidth * (signed __int16)v25; |
0 | 2664 v28 = pOutTex; |
2665 v8->uHeightMinus1 = v26; | |
2666 v8->uSizeOfMaxLevelOfDetail = v27; | |
2667 v8->uTextureSize = (unsigned int)v28; | |
2668 } | |
2669 else | |
2670 { | |
2671 v29 = *v16; | |
1583 | 2672 v30 = malloc(v29); |
0 | 2673 v31 = v8->uDecompressedSize; |
710 | 2674 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v30; |
0 | 2675 memcpy(v30, pContainer, v31); |
2676 } | |
2677 free((void *)pContainer); | |
2678 } | |
1583 | 2679 free(v8->pPalette16); |
2680 free(v8->pPalette24); | |
0 | 2681 if ( eTextureType == TEXTURE_24BIT_PALETTE ) |
2682 { | |
1583 | 2683 v33 = malloc(0x300); |
0 | 2684 v8->pPalette24 = (unsigned __int8 *)v33; |
2685 fread(v33, 1u, 0x300u, pFile); | |
2686 } | |
2687 else | |
2688 { | |
2689 v8->pPalette24 = 0; | |
2690 if ( eTextureType == TEXTURE_16BIT_PALETTE ) | |
2691 { | |
1583 | 2692 v8->pPalette16 = (unsigned __int16 *)malloc(0x200); |
0 | 2693 v38 = 0; |
2694 do | |
2695 { | |
2696 fread((char *)&eTextureType + 3, 1u, 1u, pFile); | |
2697 fread((char *)&pContainer + 3, 1u, 1u, pFile); | |
2698 v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile); | |
2699 LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits))); | |
2700 v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits)); | |
2701 LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits))); | |
2702 v8->pPalette16[v38] += v40 << uTextureBlueBits; | |
2703 v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits))); | |
2704 ++v38; | |
2705 } | |
2706 while ( v38 < 256 ); | |
2707 goto LABEL_36; | |
2708 } | |
2709 } | |
2710 v8->pPalette16 = 0; | |
2711 LABEL_36: | |
2712 if ( v8->pBits & 2 ) | |
2713 { | |
2714 v34 = v8->uSizeOfMaxLevelOfDetail; | |
710 | 2715 v35 = &v8->pLevelOfDetail0_prolly_alpha_mask[v34]; |
0 | 2716 v8->pLevelOfDetail1 = v35; |
2717 v36 = &v35[v34 >> 2]; | |
2718 v8->pLevelOfDetail2 = v36; | |
2719 v37 = &v36[v34 >> 4]; | |
2720 } | |
2721 else | |
2722 { | |
2723 v37 = 0; | |
2724 v8->pLevelOfDetail2 = 0; | |
2725 v8->pLevelOfDetail1 = 0; | |
2726 } | |
2727 v8->pLevelOfDetail3 = v37; | |
2728 v41 = 1; | |
2729 while ( 1 << v41 != v8->uTextureWidth ) | |
2730 { | |
2731 ++v41; | |
2732 if ( v41 >= 15 ) | |
2733 goto LABEL_48; | |
2734 } | |
2735 v8->uWidthLn2 = v41; | |
2736 LABEL_48: | |
2737 v42 = 1; | |
2738 while ( 1 << v42 != v8->uTextureHeight ) | |
2739 { | |
2740 ++v42; | |
2741 if ( v42 >= 15 ) | |
2742 goto LABEL_53; | |
2743 } | |
2744 v8->uHeightLn2 = v42; | |
2745 LABEL_53: | |
2746 switch ( v8->uWidthLn2 ) | |
2747 { | |
2748 case 2: | |
2749 v8->uWidthMinus1 = 3; | |
2750 break; | |
2751 case 3: | |
2752 v8->uWidthMinus1 = 7; | |
2753 break; | |
2754 case 4: | |
2755 v8->uWidthMinus1 = 15; | |
2756 break; | |
2757 case 5: | |
2758 v8->uWidthMinus1 = 31; | |
2759 break; | |
2760 case 6: | |
2761 v8->uWidthMinus1 = 63; | |
2762 break; | |
2763 case 7: | |
2764 v8->uWidthMinus1 = 127; | |
2765 break; | |
2766 case 8: | |
2767 v8->uWidthMinus1 = 255; | |
2768 break; | |
2769 case 9: | |
2770 v8->uWidthMinus1 = 511; | |
2771 break; | |
2772 case 10: | |
2773 v8->uWidthMinus1 = 1023; | |
2774 break; | |
2775 case 11: | |
2776 v8->uWidthMinus1 = 2047; | |
2777 break; | |
2778 case 12: | |
2779 v8->uWidthMinus1 = 4095; | |
2780 break; | |
2781 default: | |
2782 break; | |
2783 } | |
2784 switch ( v8->uHeightLn2 ) | |
2785 { | |
2786 case 2: | |
2787 v8->uHeightMinus1 = 3; | |
2788 break; | |
2789 case 3: | |
2790 v8->uHeightMinus1 = 7; | |
2791 break; | |
2792 case 4: | |
2793 v8->uHeightMinus1 = 15; | |
2794 break; | |
2795 case 5: | |
2796 v8->uHeightMinus1 = 31; | |
2797 break; | |
2798 case 6: | |
2799 v8->uHeightMinus1 = 63; | |
2800 break; | |
2801 case 7: | |
2802 v8->uHeightMinus1 = 127; | |
2803 break; | |
2804 case 8: | |
2805 v8->uHeightMinus1 = 255; | |
2806 break; | |
2807 case 9: | |
2808 v8->uHeightMinus1 = 511; | |
2809 break; | |
2810 case 10: | |
2811 v8->uHeightMinus1 = 1023; | |
2812 break; | |
2813 case 11: | |
2814 v8->uHeightMinus1 = 2047; | |
2815 break; | |
2816 case 12: | |
2817 v8->uHeightMinus1 = 4095; | |
2818 break; | |
2819 default: | |
2820 return 1; | |
2821 } | |
2822 return 1; | |
2823 } | |
2824 | |
2825 | |
2826 Texture *LODFile_IconsBitmaps::LoadTexturePtr(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
2827 { | |
2828 uint id = LoadTexture(pContainer, uTextureType); | |
737 | 2829 |
1545 | 2830 Assert(id != -1 && L"Texture not found"); |
737 | 2831 |
0 | 2832 return &pTextures[id]; |
2833 } | |
2834 | |
2835 //----- (0040FB20) -------------------------------------------------------- | |
2836 unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
2837 { | |
2838 //LODFile_IconsBitmaps *v3; // esi@1 | |
2839 //unsigned int v4; // edi@1 | |
2840 //Texture *v5; // ebx@2 | |
2841 unsigned int v6; // ebx@8 | |
2842 const char *Sourcea; // [sp+14h] [bp+8h]@9 | |
2843 | |
2844 //v3 = this; | |
2845 //v4 = 0; | |
2846 areWeLoadingTexture = 1; | |
2847 | |
2848 for (uint i = 0; i < uNumLoadedFiles; ++i) | |
2181 | 2849 { |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2850 if (!_stricmp(pContainer, pTextures[i].pName)) |
0 | 2851 return i; |
2181 | 2852 } |
0 | 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 } |