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