Mercurial > mm7
annotate LOD.cpp @ 2083:69af571f793b
Merge
author | Ritor1 |
---|---|
date | Fri, 06 Dec 2013 23:35:50 +0600 |
parents | 259df09dfb50 |
children | 49de109bbab5 |
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 { | |
2382 LODFile_IconsBitmaps *v1; // esi@1 | |
2383 unsigned int v2; // edi@1 | |
2384 struct IDirect3DTexture2 **v3; // eax@2 | |
2385 struct IDirect3DTexture2 *v4; // eax@3 | |
2386 struct IDirectDrawSurface **v5; // eax@5 | |
2387 struct IDirectDrawSurface *v6; // eax@6 | |
2388 | |
2389 v1 = this; | |
2390 v2 = this->uNumLoadedFiles; | |
2391 while ( 1 ) | |
2392 { | |
2393 --v2; | |
2394 if ( (v2 & 0x80000000u) != 0 ) | |
2395 break; | |
2396 v3 = v1->pHardwareTextures; | |
2397 if ( v3 ) | |
2398 { | |
2399 v4 = v3[v2]; | |
2400 if ( v4 ) | |
2401 { | |
2402 v4->Release(); | |
2403 v1->pHardwareTextures[v2] = 0; | |
2404 v1->ptr_011BB4[v2] = 1; | |
2405 } | |
2406 } | |
2407 v5 = v1->pHardwareSurfaces; | |
2408 if ( v5 ) | |
2409 { | |
2410 v6 = v5[v2]; | |
2411 if ( v6 ) | |
2412 { | |
2413 v6->Release(); | |
2414 v1->pHardwareSurfaces[v2] = 0; | |
2415 v1->ptr_011BB4[v2] = 1; | |
2416 } | |
2417 } | |
2418 } | |
2419 } | |
2420 | |
2421 | |
2422 //----- (0041033D) -------------------------------------------------------- | |
2423 void LODFile_IconsBitmaps::ReleaseLostHardwareTextures() | |
2424 { | |
2425 LODFile_IconsBitmaps *v1; // edi@1 | |
2426 unsigned int i; // ebx@1 | |
2427 struct IDirectDrawSurface **pHardwareSurfaces; // eax@2 | |
2428 int v4; // esi@3 | |
2429 struct IDirectDrawSurface *pSurface; // eax@3 | |
2430 struct IDirect3DTexture2 **v6; // eax@5 | |
2431 struct IDirect3DTexture2 *v7; // eax@6 | |
2432 | |
2433 v1 = this; | |
2434 for ( i = this->uNumLoadedFiles - 1; (i & 0x80000000u) == 0; --i ) | |
2435 { | |
2436 pHardwareSurfaces = v1->pHardwareSurfaces; | |
2437 if ( pHardwareSurfaces ) | |
2438 { | |
2439 v4 = i; | |
2440 pSurface = pHardwareSurfaces[i]; | |
2441 if ( pSurface ) | |
2442 { | |
2443 if ( pSurface->IsLost() == DDERR_SURFACELOST ) | |
2444 { | |
2445 v6 = v1->pHardwareTextures; | |
2446 if ( v6 ) | |
2447 { | |
2448 v7 = v6[v4]; | |
2449 if ( v7 ) | |
2450 { | |
2451 v7->Release(); | |
2452 v1->pHardwareTextures[v4] = 0; | |
2453 } | |
2454 } | |
2455 v1->pHardwareSurfaces[v4]->Release(); | |
2456 v1->pHardwareSurfaces[v4] = 0; | |
2457 v1->ptr_011BB4[i] = 1; | |
2458 } | |
2459 } | |
2460 } | |
2461 } | |
2462 } | |
2463 | |
2464 //----- (004101B1) -------------------------------------------------------- | |
2465 int LODFile_IconsBitmaps::ReloadTexture(Texture *pDst, const char *pContainer, int mode) | |
2466 { | |
2467 LODFile_IconsBitmaps *v4; // edi@1 | |
2468 FILE *v5; // eax@1 | |
2469 Texture *v6; // esi@2 | |
2470 unsigned int v7; // ebx@6 | |
2471 unsigned int v8; // ecx@6 | |
2472 signed int result; // eax@7 | |
2473 size_t *v10; // ebx@8 | |
2474 signed int v11; // ebx@12 | |
2475 int v12; // eax@13 | |
2476 int v13; // edx@13 | |
2477 FILE *File; // [sp+Ch] [bp-8h]@1 | |
2478 unsigned __int8 v15; // [sp+11h] [bp-3h]@13 | |
2479 unsigned __int8 v16; // [sp+12h] [bp-2h]@13 | |
2480 unsigned __int8 DstBuf; // [sp+13h] [bp-1h]@13 | |
2481 void *DstBufa; // [sp+1Ch] [bp+8h]@10 | |
2482 void *Sourcea; // [sp+20h] [bp+Ch]@10 | |
2483 unsigned int Counta; // [sp+24h] [bp+10h]@6 | |
2484 | |
2485 v4 = this; | |
2486 v5 = FindContainer(pContainer, 0); | |
2487 File = v5; | |
2488 if ( v5 | |
710 | 2489 && (v6 = pDst, pDst->pLevelOfDetail0_prolly_alpha_mask) |
0 | 2490 && mode == 2 |
2491 && pDst->pPalette16 | |
2492 && !pDst->pPalette24 | |
2493 && (v7 = pDst->uTextureSize, | |
2494 fread(pDst, 1u, 0x30u, v5), | |
2495 strcpy(pDst->pName, pContainer), | |
2496 v8 = pDst->uTextureSize, | |
2497 Counta = pDst->uTextureSize, | |
2498 (signed int)v8 <= (signed int)v7) ) | |
2499 { | |
2500 v10 = &pDst->uDecompressedSize; | |
2501 if ( !pDst->uDecompressedSize || v4->dword_011BA4 ) | |
2502 { | |
710 | 2503 fread(pDst->pLevelOfDetail0_prolly_alpha_mask, 1u, v8, File); |
0 | 2504 } |
2505 else | |
2506 { | |
2507 Sourcea = malloc(pDst->uDecompressedSize); | |
2508 DstBufa = malloc(pDst->uTextureSize); | |
2509 fread(DstBufa, 1u, Counta, File); | |
2510 zlib::MemUnzip(Sourcea, &v6->uDecompressedSize, DstBufa, v6->uTextureSize); | |
2511 v6->uTextureSize = *v10; | |
2512 free(DstBufa); | |
710 | 2513 memcpy(v6->pLevelOfDetail0_prolly_alpha_mask, Sourcea, *v10); |
0 | 2514 free(Sourcea); |
2515 } | |
2516 v11 = 0; | |
2517 do | |
2518 { | |
2519 fread(&DstBuf, 1u, 1u, File); | |
2520 fread(&v16, 1u, 1u, File); | |
2521 v12 = fread(&v15, 1u, 1u, File); | |
2522 LOWORD(v12) = (unsigned __int8)(DstBuf >> (8 - LOBYTE(v4->uTextureRedBits))); | |
2523 v6->pPalette16[v11] = v12 << (LOBYTE(v4->uTextureBlueBits) + LOBYTE(v4->uTextureGreenBits)); | |
2524 LOWORD(v13) = (unsigned __int8)(v16 >> (8 - LOBYTE(v4->uTextureGreenBits))); | |
2525 v6->pPalette16[v11] += v13 << v4->uTextureBlueBits; | |
2526 v6->pPalette16[v11] += (unsigned __int8)(v15 >> (8 - LOBYTE(v4->uTextureBlueBits))); | |
2527 ++v11; | |
2528 } | |
2529 while ( v11 < 256 ); | |
2530 result = 1; | |
2531 } | |
2532 else | |
2533 { | |
2534 result = -1; | |
2535 } | |
2536 return result; | |
2537 } | |
2538 | |
2539 | |
2540 //----- (0040FC08) -------------------------------------------------------- | |
2541 int LODFile_IconsBitmaps::LoadTextureFromLOD(Texture *pOutTex, const char *pContainer, enum TEXTURE_TYPE eTextureType) | |
2542 { | |
2543 Texture *v8; // esi@3 | |
2544 size_t v11; // eax@14 | |
2545 enum TEXTURE_TYPE v12; // eax@14 | |
2546 signed int v13; // esi@14 | |
2547 unsigned int v14; // eax@21 | |
2548 unsigned int v15; // ecx@25 | |
2549 unsigned int *v16; // ebx@25 | |
2550 void *v17; // eax@27 | |
2551 unsigned int v18; // ST28_4@27 | |
2552 void *v19; // ST3C_4@27 | |
1583 | 2553 //Allocator *v20; // ebx@29 |
0 | 2554 void *v21; // eax@29 |
2555 size_t v22; // ST2C_4@29 | |
2556 const void *v23; // ecx@29 | |
2557 unsigned __int16 v24; // ax@29 | |
2558 unsigned __int16 v25; // cx@29 | |
2559 __int16 v26; // dx@29 | |
2560 unsigned int v27; // ecx@29 | |
2561 Texture *v28; // eax@29 | |
2562 unsigned int v29; // ST28_4@30 | |
2563 void *v30; // eax@30 | |
2564 unsigned int v31; // ST2C_4@30 | |
2565 void *v32; // eax@32 | |
2566 void *v33; // eax@34 | |
2567 signed int v34; // eax@37 | |
2568 unsigned __int8 *v35; // ecx@37 | |
2569 unsigned __int8 *v36; // ecx@37 | |
2570 unsigned __int8 *v37; // eax@37 | |
2571 signed int v38; // ebx@39 | |
2572 int v39; // eax@40 | |
2573 int v40; // edx@40 | |
2574 signed int v41; // ecx@43 | |
2575 signed int v42; // ecx@48 | |
2576 | |
2577 //v4 = pContainer; | |
2578 //v5 = this; | |
2579 //v6 = FindContainer(pContainer, 0); | |
2580 //File = v6; | |
1980 | 2581 FILE* pFile = FindContainer(pContainer, false); |
0 | 2582 if (!pFile) |
2583 return -1; | |
2584 v8 = pOutTex; | |
2585 fread(pOutTex, 1u, 0x30u, pFile); | |
2586 strcpy(v8->pName, pContainer); | |
2587 if (pRenderer->pRenderD3D && v8->pBits & 2 && dword_011BA8) | |
2588 { | |
2589 if (!pHardwareSurfaces || !pHardwareTextures) | |
2590 { | |
2591 pHardwareSurfaces = new IDirectDrawSurface *[1000]; | |
2592 memset(pHardwareSurfaces, 0, 1000 * sizeof(IDirectDrawSurface4 *)); | |
2593 | |
2594 pHardwareTextures = new IDirect3DTexture2 *[1000]; | |
2595 memset(pHardwareTextures, 0, 1000 * sizeof(IDirect3DTexture2 *)); | |
2596 | |
2597 ptr_011BB4 = new char[1000]; | |
2598 memset(ptr_011BB4, 0, 1000); | |
2599 } | |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2600 if (_strnicmp(pContainer, "wtrdr", 5))//*v4 != 'w' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'd' || v4[4] != 'r' ) |
0 | 2601 { |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2602 if (_strnicmp(pContainer, "WtrTyl", 6))//if ( *v4 != 'W' || v4[1] != 't' || v4[2] != 'r' || v4[3] != 'T' || v4[4] != 'y' || v4[5] != 'l' ) |
0 | 2603 { |
2604 v14 = uNumLoadedFiles; | |
2605 } | |
2606 else | |
2607 { | |
265 | 2608 pRenderer->hd_water_tile_id = uNumLoadedFiles; |
0 | 2609 v14 = uNumLoadedFiles; |
2610 } | |
2611 v13 = pRenderer->LoadTexture( | |
2612 pContainer, | |
2613 v8->palette_id1, | |
2614 (IDirectDrawSurface4 **)&pHardwareSurfaces[v14], | |
2615 &pHardwareTextures[v14]); | |
2616 } | |
2617 else | |
2618 { | |
2619 v11 = strlen(pContainer); | |
1631 | 2620 v12 = (enum TEXTURE_TYPE)(int)malloc(v11 + 2); |
0 | 2621 eTextureType = v12; |
2622 *(char *)v12 = 104; | |
2623 strcpy((char *)(v12 + 1), pContainer); | |
2624 v13 = pRenderer->LoadTexture( | |
2625 (const char *)eTextureType, | |
2626 v8->palette_id1, | |
2627 (IDirectDrawSurface4 **)&pHardwareSurfaces[uNumLoadedFiles], | |
2628 &pHardwareTextures[uNumLoadedFiles]); | |
2629 free((void *)eTextureType); | |
2630 } | |
2631 return v13; | |
2632 } | |
2633 v15 = v8->uTextureSize; | |
2634 v16 = &v8->uDecompressedSize; | |
2635 pOutTex = (Texture *)v8->uTextureSize; | |
2636 if ( !v8->uDecompressedSize || dword_011BA4 ) | |
2637 { | |
1583 | 2638 v32 = malloc(v15); |
710 | 2639 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v32; |
0 | 2640 fread(v32, 1u, (size_t)pOutTex, pFile); |
2641 } | |
2642 else | |
2643 { | |
2644 v17 = malloc(v8->uDecompressedSize); | |
2645 v18 = v8->uTextureSize; | |
2646 pContainer = (const char *)v17; | |
2647 v19 = malloc(v18); | |
2648 fread(v19, 1u, (size_t)pOutTex, pFile); | |
2649 zlib::MemUnzip((void *)pContainer, &v8->uDecompressedSize, v19, v8->uTextureSize); | |
2650 v8->uTextureSize = *v16; | |
2651 free(v19); | |
2652 if ( bUseLoResSprites && v8->pBits & 2 ) | |
2653 { | |
2654 pOutTex = (Texture *)(((signed int)v8->uSizeOfMaxLevelOfDetail >> 2) | |
2655 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 4) | |
2656 + ((signed int)v8->uSizeOfMaxLevelOfDetail >> 6)); | |
1583 | 2657 v21 = malloc((unsigned int)pOutTex); |
0 | 2658 v22 = (size_t)pOutTex; |
2659 v23 = &pContainer[v8->uTextureWidth * v8->uTextureHeight]; | |
710 | 2660 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v21; |
0 | 2661 memcpy(v21, v23, v22); |
2662 v8->uTextureWidth = (signed __int16)v8->uTextureWidth >> 1; | |
2663 v24 = v8->uTextureWidth; | |
2664 v8->uTextureHeight = (signed __int16)v8->uTextureHeight >> 1; | |
2665 v25 = v8->uTextureHeight; | |
2666 --v8->uWidthLn2; | |
2667 --v8->uHeightLn2; | |
2668 v8->uWidthMinus1 = v24 - 1; | |
2669 v26 = v25 - 1; | |
2670 v27 = (signed __int16)v24 * (signed __int16)v25; | |
2671 v28 = pOutTex; | |
2672 v8->uHeightMinus1 = v26; | |
2673 v8->uSizeOfMaxLevelOfDetail = v27; | |
2674 v8->uTextureSize = (unsigned int)v28; | |
2675 } | |
2676 else | |
2677 { | |
2678 v29 = *v16; | |
1583 | 2679 v30 = malloc(v29); |
0 | 2680 v31 = v8->uDecompressedSize; |
710 | 2681 v8->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *)v30; |
0 | 2682 memcpy(v30, pContainer, v31); |
2683 } | |
2684 free((void *)pContainer); | |
2685 } | |
1583 | 2686 free(v8->pPalette16); |
2687 free(v8->pPalette24); | |
0 | 2688 if ( eTextureType == TEXTURE_24BIT_PALETTE ) |
2689 { | |
1583 | 2690 v33 = malloc(0x300); |
0 | 2691 v8->pPalette24 = (unsigned __int8 *)v33; |
2692 fread(v33, 1u, 0x300u, pFile); | |
2693 } | |
2694 else | |
2695 { | |
2696 v8->pPalette24 = 0; | |
2697 if ( eTextureType == TEXTURE_16BIT_PALETTE ) | |
2698 { | |
1583 | 2699 v8->pPalette16 = (unsigned __int16 *)malloc(0x200); |
0 | 2700 v38 = 0; |
2701 do | |
2702 { | |
2703 fread((char *)&eTextureType + 3, 1u, 1u, pFile); | |
2704 fread((char *)&pContainer + 3, 1u, 1u, pFile); | |
2705 v39 = fread((char *)&pOutTex + 3, 1u, 1u, pFile); | |
2706 LOWORD(v39) = (unsigned __int8)(BYTE3(eTextureType) >> (8 - LOBYTE(uTextureRedBits))); | |
2707 v8->pPalette16[v38] = v39 << (LOBYTE(uTextureBlueBits) + LOBYTE(uTextureGreenBits)); | |
2708 LOWORD(v40) = (unsigned __int8)(BYTE3(pContainer) >> (8 - LOBYTE(uTextureGreenBits))); | |
2709 v8->pPalette16[v38] += v40 << uTextureBlueBits; | |
2710 v8->pPalette16[v38] += (unsigned __int8)(BYTE3(pOutTex) >> (8 - LOBYTE(uTextureBlueBits))); | |
2711 ++v38; | |
2712 } | |
2713 while ( v38 < 256 ); | |
2714 goto LABEL_36; | |
2715 } | |
2716 } | |
2717 v8->pPalette16 = 0; | |
2718 LABEL_36: | |
2719 if ( v8->pBits & 2 ) | |
2720 { | |
2721 v34 = v8->uSizeOfMaxLevelOfDetail; | |
710 | 2722 v35 = &v8->pLevelOfDetail0_prolly_alpha_mask[v34]; |
0 | 2723 v8->pLevelOfDetail1 = v35; |
2724 v36 = &v35[v34 >> 2]; | |
2725 v8->pLevelOfDetail2 = v36; | |
2726 v37 = &v36[v34 >> 4]; | |
2727 } | |
2728 else | |
2729 { | |
2730 v37 = 0; | |
2731 v8->pLevelOfDetail2 = 0; | |
2732 v8->pLevelOfDetail1 = 0; | |
2733 } | |
2734 v8->pLevelOfDetail3 = v37; | |
2735 v41 = 1; | |
2736 while ( 1 << v41 != v8->uTextureWidth ) | |
2737 { | |
2738 ++v41; | |
2739 if ( v41 >= 15 ) | |
2740 goto LABEL_48; | |
2741 } | |
2742 v8->uWidthLn2 = v41; | |
2743 LABEL_48: | |
2744 v42 = 1; | |
2745 while ( 1 << v42 != v8->uTextureHeight ) | |
2746 { | |
2747 ++v42; | |
2748 if ( v42 >= 15 ) | |
2749 goto LABEL_53; | |
2750 } | |
2751 v8->uHeightLn2 = v42; | |
2752 LABEL_53: | |
2753 switch ( v8->uWidthLn2 ) | |
2754 { | |
2755 case 2: | |
2756 v8->uWidthMinus1 = 3; | |
2757 break; | |
2758 case 3: | |
2759 v8->uWidthMinus1 = 7; | |
2760 break; | |
2761 case 4: | |
2762 v8->uWidthMinus1 = 15; | |
2763 break; | |
2764 case 5: | |
2765 v8->uWidthMinus1 = 31; | |
2766 break; | |
2767 case 6: | |
2768 v8->uWidthMinus1 = 63; | |
2769 break; | |
2770 case 7: | |
2771 v8->uWidthMinus1 = 127; | |
2772 break; | |
2773 case 8: | |
2774 v8->uWidthMinus1 = 255; | |
2775 break; | |
2776 case 9: | |
2777 v8->uWidthMinus1 = 511; | |
2778 break; | |
2779 case 10: | |
2780 v8->uWidthMinus1 = 1023; | |
2781 break; | |
2782 case 11: | |
2783 v8->uWidthMinus1 = 2047; | |
2784 break; | |
2785 case 12: | |
2786 v8->uWidthMinus1 = 4095; | |
2787 break; | |
2788 default: | |
2789 break; | |
2790 } | |
2791 switch ( v8->uHeightLn2 ) | |
2792 { | |
2793 case 2: | |
2794 v8->uHeightMinus1 = 3; | |
2795 break; | |
2796 case 3: | |
2797 v8->uHeightMinus1 = 7; | |
2798 break; | |
2799 case 4: | |
2800 v8->uHeightMinus1 = 15; | |
2801 break; | |
2802 case 5: | |
2803 v8->uHeightMinus1 = 31; | |
2804 break; | |
2805 case 6: | |
2806 v8->uHeightMinus1 = 63; | |
2807 break; | |
2808 case 7: | |
2809 v8->uHeightMinus1 = 127; | |
2810 break; | |
2811 case 8: | |
2812 v8->uHeightMinus1 = 255; | |
2813 break; | |
2814 case 9: | |
2815 v8->uHeightMinus1 = 511; | |
2816 break; | |
2817 case 10: | |
2818 v8->uHeightMinus1 = 1023; | |
2819 break; | |
2820 case 11: | |
2821 v8->uHeightMinus1 = 2047; | |
2822 break; | |
2823 case 12: | |
2824 v8->uHeightMinus1 = 4095; | |
2825 break; | |
2826 default: | |
2827 return 1; | |
2828 } | |
2829 return 1; | |
2830 } | |
2831 | |
2832 | |
2833 Texture *LODFile_IconsBitmaps::LoadTexturePtr(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
2834 { | |
2835 uint id = LoadTexture(pContainer, uTextureType); | |
737 | 2836 |
1545 | 2837 Assert(id != -1 && L"Texture not found"); |
737 | 2838 |
0 | 2839 return &pTextures[id]; |
2840 } | |
2841 | |
2842 //----- (0040FB20) -------------------------------------------------------- | |
2843 unsigned int LODFile_IconsBitmaps::LoadTexture(const char *pContainer, enum TEXTURE_TYPE uTextureType) | |
2844 { | |
2845 //LODFile_IconsBitmaps *v3; // esi@1 | |
2846 //unsigned int v4; // edi@1 | |
2847 //Texture *v5; // ebx@2 | |
2848 unsigned int v6; // ebx@8 | |
2849 const char *Sourcea; // [sp+14h] [bp+8h]@9 | |
2850 | |
2851 //v3 = this; | |
2852 //v4 = 0; | |
2853 areWeLoadingTexture = 1; | |
2854 | |
2855 for (uint i = 0; i < uNumLoadedFiles; ++i) | |
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1104
diff
changeset
|
2856 if (!_stricmp(pContainer, pTextures[i].pName)) |
0 | 2857 return i; |
2858 | |
2859 // if (!uNumLoadedFiles) | |
2860 // { | |
2861 //LABEL_5: | |
1545 | 2862 Assert(uNumLoadedFiles < 1000); |
649 | 2863 /*if (uNumLoadedFiles >= 1000) |
0 | 2864 { |
2865 Log::Warning(L"Maximum texture number exceeded"); | |
2866 AbortWithError(); | |
649 | 2867 }*/ |
0 | 2868 if (LoadTextureFromLOD(&pTextures[uNumLoadedFiles], pContainer, uTextureType) == -1) |
2869 { | |
2870 v6 = 0; | |
2871 if (uNumLoadedFiles > 0) | |
2872 { | |
2873 Sourcea = (const char *)pTextures; | |
1104 | 2874 while ( _stricmp(Sourcea, "pending") ) |
0 | 2875 { |
2876 Sourcea += 72; | |
2877 ++v6; | |
2878 if (v6 >= uNumLoadedFiles) | |
2879 goto LABEL_15; | |
2880 } | |
2881 return v6; | |
2882 } | |
2883 LABEL_15: | |
2884 LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", uTextureType); | |
2885 } | |
2886 areWeLoadingTexture = 0; | |
2887 ++uNumLoadedFiles; | |
2888 return uNumLoadedFiles - 1; | |
2889 // } | |
2890 // v5 = pTextures; | |
1104 | 2891 // while ( _stricmp(v5->pName, pContainer) ) |
0 | 2892 // { |
2893 // ++v4; | |
2894 // ++v5; | |
2895 // if (v4 >= uNumLoadedFiles ) | |
2896 // goto LABEL_5; | |
2897 // } | |
2898 // return v4; | |
2899 } | |
1297 | 2900 //----- (0046082C) -------------------------------------------------------- |
2901 bool Initialize_GamesLOD_NewLOD() | |
2902 { | |
2903 pGames_LOD = new LODWriteableFile; | |
2904 pGames_LOD->AllocSubIndicesAndIO(300, 0); | |
2905 if (pGames_LOD->LoadFile("data\\games.lod", 1)) | |
2906 { | |
2907 pNew_LOD = new LODWriteableFile; | |
2908 pNew_LOD->AllocSubIndicesAndIO(300, 100000); | |
2909 return true; | |
2910 } | |
2911 return false; | |
2912 } | |
2913 //----- (00460706) -------------------------------------------------------- | |
2914 void TryLoadLevelFromLOD() | |
2915 { | |
2916 FILE *v0; // eax@1 | |
2917 FILE *v1; // esi@1 | |
2918 __int32 v2; // edi@2 | |
2919 char Ext[256]; // [sp+4h] [bp-40Ch]@1 | |
2920 char Dir[256]; // [sp+104h] [bp-30Ch]@1 | |
2921 char Filename[256]; // [sp+204h] [bp-20Ch]@1 | |
2922 char a1[260]; // [sp+304h] [bp-10Ch]@1 | |
2923 char Drive[4]; // [sp+408h] [bp-8h]@1 | |
2924 int DstBuf; // [sp+40Ch] [bp-4h]@2 | |
2925 | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
2926 strcpy(a1, pCurrentMapName); |
1297 | 2927 _splitpath(a1, Drive, Dir, Filename, Ext); |
2928 sprintf(a1, "levels\\%s%s", Filename, ".lod"); | |
2929 v0 = fopen(a1, "rb"); | |
2930 v1 = v0; | |
2931 if ( v0 ) | |
2932 { | |
2933 fseek(v0, 0, 2); | |
2934 v2 = ftell(v1); | |
2935 rewind(v1); | |
1583 | 2936 ptr_6A0D08 = malloc(v2); |
1297 | 2937 fread(ptr_6A0D08, v2, 1u, v1); |
2938 fseek(v1, v2 - 6, 0); | |
2939 DstBuf = 0; | |
2940 fread(&DstBuf, 4u, 1u, v1); | |
2941 fread(&_6A0D10_txt_lod_loading__unused, 2u, 1u, v1); | |
2942 _6A0D0C_txt_lod_loading = (int)((char *)ptr_6A0D08 + DstBuf); | |
2943 fclose(v1); | |
2944 } | |
2945 } | |
2946 | |
2947 //----- (0046080D) -------------------------------------------------------- | |
1458 | 2948 void sub_46080D() |
1297 | 2949 { |
1583 | 2950 free(ptr_6A0D08); |
1297 | 2951 ptr_6A0D08 = 0; |
2952 _6A0D0C_txt_lod_loading = 0; | |
2953 } |