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