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