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