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