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