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