comparison Indoor.cpp @ 0:9c0607679772

init
author Ritor1
date Sat, 12 Jan 2013 09:45:18 +0600
parents
children fe0e317c0de0
comparison
equal deleted inserted replaced
-1:000000000000 0:9c0607679772
1 #include <assert.h>
2
3 #include "Outdoor.h"
4 #include "Render.h"
5 #include "LayingItem.h"
6 #include "Events.h"
7 #include "Game.h"
8 #include "Viewport.h"
9 #include "Time.h"
10 #include "Party.h"
11 #include "Math.h"
12 #include "Allocator.h"
13 #include "LOD.h"
14 #include "DecorationList.h"
15 #include "ObjectList.h"
16 #include "Actor.h"
17 #include "Chest.h"
18 #include "GUIProgressBar.h"
19 #include "stru123.h"
20 #include "AudioPlayer.h"
21 #include "Log.h"
22 #include "TurnEngine.h"
23 #include "PaletteManager.h"
24 #include "MapInfo.h"
25
26 #include "mm7_data.h"
27
28
29
30
31
32
33
34
35
36 IndoorLocation *pIndoor = new IndoorLocation;
37 BLVRenderParams *pBLVRenderParams = new BLVRenderParams;
38
39 struct DecorationList *pDecorationList;
40
41 LevelDecoration pLevelDecorations[3000];
42 size_t uNumLevelDecorations;
43 LevelDecoration *_5C3420_pDecoration;
44
45 LEVEL_TYPE uCurrentlyLoadedLevelType = LEVEL_null;
46
47 stru320 stru_F8AD28; // idb
48 stru337 stru_F81018;
49 stru167_wrap array_5118E8;
50 BspRenderer_stru2 stru_F8A590;
51 BspRenderer *pBspRenderer = new BspRenderer; // idb
52 stru141 stru_721530;
53 stru352 stru_F83B80[480];
54
55
56
57 unsigned __int16 pDoorSoundIDsByLocationID[78] =
58 {
59 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300,
60 300, 300, 300, 404, 302, 306, 308, 304, 308, 302, 400, 302, 300,
61 308, 308, 306, 308, 308, 304, 300, 404, 406, 300, 400, 406, 404,
62 306, 302, 408, 304, 300, 300, 300, 300, 300, 300, 300, 300, 300,
63 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 404, 304,
64 400, 300, 300, 404, 304, 400, 300, 300, 404, 304, 400, 300, 300
65 };
66
67
68
69 //----- (0043F39E) --------------------------------------------------------
70 void __fastcall PrepareDrawLists_BLV(IndoorLocation_drawstru *_this)
71 {
72 //int *v1; // ecx@1
73 //double v2; // ST30_8@3
74 //double v3; // ST30_8@6
75 //double v4; // ST28_8@6
76 int v5; // eax@4
77 int v6; // eax@7
78 unsigned int v7; // ebx@8
79 BLVSector *v8; // esi@8
80 unsigned __int16 *v9; // edi@8
81 int i; // [sp+18h] [bp-8h]@7
82 //unsigned __int8 v11; // [sp+1Ch] [bp-4h]@3
83 signed int v12; // [sp+1Ch] [bp-4h]@8
84
85 pBLVRenderParams->Reset(_this);
86 pMobileLightsStack->uNumLightsActive = 0;
87 //uNumMobileLightsApplied = 0;
88 uNumDecorationsDrawnThisFrame = 0;
89 _unused000 = 0;
90 uNumSpritesDrawnThisFrame = 0;
91 uNumBillboardsToDraw = 0;
92 if ( !byte_4D864C || !(pGame->uFlags & 0x1000) )
93 {
94 //v2 = pParty->flt_TorchlightColorB + 6.7553994e15;
95 //v11 = LOBYTE(v2);
96 v5 = 800;
97 if (pParty->TorchlightActive())
98 v5 *= pParty->pPartyBuffs[16].uPower;
99 //LOBYTE(v1) = byte_4E94D0;
100 //v4 = pParty->flt_TorchlightColorR + 6.7553994e15;
101 //v3 = pParty->flt_TorchlightColorG + 6.7553994e15;
102 pMobileLightsStack->AddLight(
103 pBLVRenderParams->vPartyPos.x,
104 pBLVRenderParams->vPartyPos.y,
105 pBLVRenderParams->vPartyPos.z,
106 pBLVRenderParams->uPartySectorID,
107 v5,
108 floorf(pParty->flt_TorchlightColorR + 0.5f),
109 floorf(pParty->flt_TorchlightColorG + 0.5f),
110 floorf(pParty->flt_TorchlightColorB + 0.5f),
111 byte_4E94D0);
112 }
113 PrepareBspRenderList_BLV();
114 PrepareItemsRenderList_BLV();
115 PrepareActorRenderList_BLV();
116 v6 = 0;
117 for ( i = 0; i < pBspRenderer->uNumVisibleNotEmptySectors; ++i )
118 {
119 v7 = pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6];
120 v12 = 0;
121 v8 = &pIndoor->pSectors[pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6]];
122 v9 = v8->pDecorationIDs;
123 if ( v8->uNumDecorations > 0 )
124 {
125 do
126 PrepareDecorationsRenderList_BLV(v9[v12++], v7);
127 while ( v12 < v8->uNumDecorations );
128 }
129 v6 = i + 1;
130 }
131 MessWithBillboards_BLV();
132 pGame->PrepareBloodsplats();
133 }
134
135
136
137 //----- (004407D9) --------------------------------------------------------
138 int BLVRenderParams::Reset(IndoorLocation_drawstru *a2)
139 {
140 IndoorLocation_drawstru *v2; // ebx@1
141 BLVRenderParams *v3; // esi@1
142 int v4; // ST08_4@1
143 int v5; // ST04_4@1
144 int v6; // ST00_4@1
145 int v7; // eax@1
146 int v8; // ST08_4@2
147 int v9; // ST04_4@2
148 int v10; // ST00_4@2
149 unsigned int v11; // edi@4
150 unsigned int v12; // ecx@4
151 int v13; // edx@4
152 signed int v14; // ecx@4
153 unsigned int v15; // edx@4
154 unsigned int v16; // eax@4
155 double v17; // st7@5
156 int v18; // eax@5
157 double v19; // st7@5
158 int v20; // eax@5
159 double v21; // st7@5
160 int v22; // eax@5
161 unsigned int v23; // edx@5
162 unsigned int v24; // ecx@5
163 int v25; // eax@5
164 int v26; // eax@5
165 signed int v27; // eax@6
166 int result; // eax@6
167 int v29; // [sp+24h] [bp+8h]@5
168
169 v2 = a2;
170 v3 = this;
171 this->field_0_timer_ = a2->field_0_timer;
172 this->uFlags = a2->uFlags;
173 this->vPartyPos.x = a2->vPosition.x;
174 this->vPartyPos.y = a2->vPosition.y;
175 this->vPartyPos.z = a2->vPosition.z;
176 v4 = this->vPartyPos.z;
177 v5 = this->vPartyPos.y;
178 this->sPartyRotY = a2->sRotationY;
179 v6 = this->vPartyPos.x;
180 this->sPartyRotX = a2->sRotationX;
181 v7 = pIndoor->GetSector(v6, v5, v4);
182 v3->uPartySectorID = v7;
183 if ( !v7 )
184 {
185 v8 = v3->vPartyPos.z;
186 v3->vPartyPos.x = pParty->vPosition.x;
187 v9 = pParty->vPosition.y;
188 v10 = v3->vPartyPos.x;
189 v3->vPartyPos.y = pParty->vPosition.y;
190 v3->uPartySectorID = pIndoor->GetSector(v10, v9, v8);
191 }
192 if ( pRenderer->pRenderD3D )
193 {
194 v3->sCosineY = stru_5C6E00->SinCos(v3->sPartyRotY);
195 v3->sSineY = stru_5C6E00->SinCos(v3->sPartyRotY - stru_5C6E00->uIntegerHalfPi);
196 v3->sCosineNegX = stru_5C6E00->SinCos(-v3->sPartyRotX);
197 v3->sSineNegX = stru_5C6E00->SinCos(-v3->sPartyRotX - stru_5C6E00->uIntegerHalfPi);
198 v3->fCosineY = cos((3.141592653589793 + 3.141592653589793) * (double)v3->sPartyRotY * 0.00048828125);
199 v3->fSineY = sin((3.141592653589793 + 3.141592653589793) * (double)v3->sPartyRotY * 0.00048828125);
200 v3->fCosineNegX = cos((3.141592653589793 + 3.141592653589793) * (double)-v3->sPartyRotX * 0.00048828125);
201 v3->fSineNegX = sin((3.141592653589793 + 3.141592653589793) * (double)-v3->sPartyRotX * 0.00048828125);
202 v3->field_64 = a2->field_3C;
203 v11 = v3->uViewportW;
204 v12 = v3->uViewportX;
205 v13 = v3->uViewportZ - v12;
206 v14 = v3->uViewportZ + v12;
207 v3->field_70 = v13 + 1;
208 v15 = v3->uViewportY;
209 v3->uViewportHeight = v11 - v15 + 1;
210 v16 = v3->uViewportW;
211 v3->uViewportCenterX = v14 >> 1;
212 v3->uViewportCenterY = (signed int)(v16 + v15) >> 1;
213 }
214 else
215 {
216 v3->sCosineY = stru_5C6E00->SinCos(-v3->sPartyRotY);
217 v3->sSineY = stru_5C6E00->SinCos(-v3->sPartyRotY - stru_5C6E00->uIntegerHalfPi);
218 v3->sCosineNegX = stru_5C6E00->SinCos(-v3->sPartyRotX);
219 v3->sSineNegX = stru_5C6E00->SinCos(-v3->sPartyRotX - stru_5C6E00->uIntegerHalfPi);
220 v17 = cos((double)-v3->sPartyRotY * 0.0030664064);
221 v18 = v3->sPartyRotY;
222 v3->fCosineY = v17;
223 v19 = sin((double)-v18 * 0.0030664064);
224 v20 = v3->sPartyRotX;
225 v3->fSineY = v19;
226 v21 = cos((double)-v20 * 0.0030664064);
227 v22 = v3->sPartyRotX;
228 v3->fCosineNegX = v21;
229 v3->fSineNegX = sin((double)-v22 * 0.0030664064);
230 v23 = v3->uViewportX;
231 v3->field_64 = a2->field_3C;
232 v24 = v3->uViewportZ;
233 v3->field_70 = v3->uViewportZ - v23 + 1;
234 v25 = v3->uViewportW - v3->uViewportY + 1;
235 v3->uViewportHeight = v25;
236 v29 = v25;
237 v26 = v3->field_64;
238 v3->uViewportCenterX = (signed int)(v24 + v23) >> 1;
239 v3->uViewportCenterY = v3->uViewportW - ((unsigned __int64)(v26 * (signed __int64)v29) >> 16);
240 }
241 v27 = (unsigned int)(signed __int64)((double)v3->field_70 * 0.5 / tan((double)(v2->field_1C_mb_fov >> 1) * 0.01745329)
242 + 0.5) << 16;
243 v3->field_40 = v27;
244 LODWORD(v3->field_44) = 4294967296i64 / v27;
245 v3->pRenderTarget = v2->pRenderTarget;
246 v3->uTargetWidth = v2->uTargetWidth;
247 v3->uTargetHeight = v2->uTargetHeight;
248 v3->uViewportX = v2->uViewportX;
249 v3->uViewportY = v2->uViewportY;
250 v3->uViewportZ = v2->uViewportZ;
251 v3->uViewportW = v2->uViewportW;
252 v3->pTargetZBuffer = v2->pTargetZ;
253 result = 0;
254 v3->field_8C = 0;
255 v3->field_84 = 0;
256 v3->uNumFacesRenderedThisFrame = 0;
257 v3->field_88 = 0;
258 pBLVRenderParams->field_90 = 64;
259 pBLVRenderParams->field_94 = 6;
260 return result;
261 }
262
263 //----- (00440B44) --------------------------------------------------------
264 void IndoorLocation::ExecDraw(bool bD3D)
265 {
266 int v2; // eax@3
267 IndoorCameraD3D_Vec4 *v3; // edx@4
268 unsigned int v5; // ecx@9
269 RenderVertexSoft *v6; // [sp-4h] [bp-8h]@4
270
271 if (bD3D)
272 {
273 pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
274 for (uint i = 0; i < pBspRenderer->uNumFaceIDs; ++i)
275 {
276 v2 = pBspRenderer->pFaceIDs[2 * i + 1];
277 if ( pBspRenderer->field_FA8[v2].std__vector_0007A8 == -1 )
278 {
279 v6 = 0;
280 v3 = 0;
281 }
282 else
283 {
284 v3 = pBspRenderer->field_FA8[v2].std__vector_0007AC;
285 v6 = pBspRenderer->field_FA8[v2].pVertices;
286 }
287 IndoorLocation::ExecDraw_d3d(pBspRenderer->pFaceIDs[2 * i], v3, 4, v6);
288 }
289 }
290 else
291 {
292 for (uint j = 0; j < pBspRenderer->uNumFaceIDs; ++j )
293 {
294 v5 = pBspRenderer->pFaceIDs[2 * j];
295 pBLVRenderParams->field_7C = &pBspRenderer->field_FA8[pBspRenderer->pFaceIDs[2 * j + 1]].field_C;
296 IndoorLocation::ExecDraw_sw(v5);
297 }
298 }
299 }
300
301 //----- (00440BED) --------------------------------------------------------
302 void __fastcall sub_440BED(IndoorLocation_drawstru *_this)
303 {
304 unsigned __int16 *v1; // edi@7
305 char *v2; // esi@8
306 int v3; // ecx@9
307 unsigned int v4; // edx@9
308 char *v5; // eax@10
309 signed int v6; // [sp+8h] [bp-8h]@7
310 int v7; // [sp+Ch] [bp-4h]@8
311
312 PrepareDrawLists_BLV(_this);
313 if (pBLVRenderParams->uPartySectorID)
314 IndoorLocation::ExecDraw(pRenderer->pRenderD3D != 0);
315 pRenderer->DrawBillboardList_BLV();
316 if ( !pRenderer->pRenderD3D )
317 {
318 if ( pBLVRenderParams->uFlags & 2 )
319 stru170_sub_4B0967();
320 if ( pBLVRenderParams->uFlags & 1 )
321 {
322 v1 = pBLVRenderParams->pRenderTarget;
323 v6 = 0;
324 if ( (signed int)pBspRenderer->std__vector_000FA8 > 0 )
325 {
326 v7 = 0;
327 v2 = (char *)&pBspRenderer->field_FA8[0].field_C._viewport_space_w;
328 do
329 {
330 v3 = *((int *)v2 - 1);
331 v4 = pRenderer->uTargetSurfacePitch * *((int *)v2 - 1);
332 if ( v3 <= *(int *)v2 )
333 {
334 v5 = (char *)&pBspRenderer->field_FA8[0].field_C.array_3D8[v3 + v7];
335 do
336 {
337 v1[v4 + *((short *)v5 - 480)] = 255;
338 ++v3;
339 v1[v4 + *(short *)v5] = 255;
340 v4 += pRenderer->uTargetSurfacePitch;
341 v5 += 2;
342 }
343 while ( v3 <= *(int *)v2 );
344 }
345 ++v6;
346 v7 += 1126;
347 v2 += 2252;
348 }
349 while ( v6 < (signed int)pBspRenderer->std__vector_000FA8 );
350 }
351 }
352 }
353 }
354
355
356
357
358
359 //----- (00441BD4) --------------------------------------------------------
360 void IndoorLocation::Draw()
361 {
362 int v0; // eax@1
363 IndoorLocation_drawstru _this; // [sp+0h] [bp-4Ch]@5
364 int v2; // [sp+44h] [bp-8h]@5
365 int v3; // [sp+48h] [bp-4h]@5
366
367 v0 = 0;
368 if ( viewparams->field_50_draw_debug_outlines )
369 v0 = 1;
370 if ( viewparams->field_54 )
371 LOBYTE(v0) = v0 | 2;
372 _this.field_0_timer = pEventTimer->uTotalGameTimeElapsed;
373 _this.uFlags = v0;
374 _this.vPosition.x = pParty->vPosition.x
375 - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY)
376 * (signed __int64)pParty->field_18) >> 16);
377 v2 = stru_5C6E00->SinCos(pParty->sRotationY - stru_5C6E00->uIntegerHalfPi);
378 v3 = (unsigned __int64)(v2 * (signed __int64)pParty->field_18) >> 16;
379 _this.field_1C_mb_fov = 65;
380 _this.vPosition.y = pParty->vPosition.y - v3;
381 _this.sRotationY = pParty->sRotationY;
382 _this.sRotationX = pParty->sRotationX;
383 _this.pRenderTarget = pRenderer->pTargetSurface;
384 _this.uViewportX = pViewport->uScreenX;
385 _this.uViewportY = pViewport->uScreenY;
386 _this.uViewportZ = pViewport->uScreenZ;
387 _this.uViewportW = pViewport->uScreenW;
388 _this.field_3C = pViewport->field_30;
389 _this.vPosition.z = pParty->vPosition.z + pParty->sEyelevel;
390 _this.uTargetWidth = 640;
391 _this.uTargetHeight = 480;
392 _this.pTargetZ = pRenderer->pActiveZBuffer;
393 sub_440BED(&_this);
394 pParty->uFlags &= 0xFFFFFFFDu;
395 pGame->DrawParticles();
396 array_5118E8._440F07();
397 }
398
399 //----- (004C0EF2) --------------------------------------------------------
400 void BLVFace::FromODM(ODMFace *a2)
401 {
402 this->pFacePlane_old.vNormal.x = a2->pFacePlane.vNormal.x;
403 this->pFacePlane_old.vNormal.y = a2->pFacePlane.vNormal.y;
404 this->pFacePlane_old.vNormal.z = a2->pFacePlane.vNormal.z;
405 this->pFacePlane_old.dist = a2->pFacePlane.dist;
406 this->pFacePlane.vNormal.x = (double)(a2->pFacePlane.vNormal.x & 0xFFFF) * 0.000015259022
407 + (double)(a2->pFacePlane.vNormal.x >> 16);
408 this->pFacePlane.vNormal.y = (double)(a2->pFacePlane.vNormal.y & 0xFFFF) * 0.000015259022
409 + (double)(a2->pFacePlane.vNormal.y >> 16);
410 this->pFacePlane.vNormal.z = (double)(a2->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022
411 + (double)(a2->pFacePlane.vNormal.z >> 16);
412 this->pFacePlane.dist = (double)(a2->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(a2->pFacePlane.dist >> 16);
413 this->uAttributes = a2->uAttributes;
414 this->pBounding.x1 = a2->pBoundingBox.x1;
415 this->pBounding.y1 = a2->pBoundingBox.y1;
416 this->pBounding.z1 = a2->pBoundingBox.z1;
417 this->pBounding.x2 = a2->pBoundingBox.x2;
418 this->pBounding.y2 = a2->pBoundingBox.y2;
419 this->pBounding.z2 = a2->pBoundingBox.z2;
420 this->zCalc1 = a2->zCalc1;
421 this->zCalc2 = a2->zCalc2;
422 this->zCalc3 = a2->zCalc3;
423 this->pXInterceptDisplacements = a2->pXInterceptDisplacements;
424 this->pYInterceptDisplacements = a2->pYInterceptDisplacements;
425 this->pZInterceptDisplacements = a2->pZInterceptDisplacements;
426 this->uPolygonType = (PolygonType)a2->uPolygonType;
427 this->uNumVertices = a2->uNumVertices;
428 this->uBitmapID = a2->uTextureID;
429 this->pVertexIDs = a2->pVertexIDs;
430 }
431
432 //----- (004B0A25) --------------------------------------------------------
433 void IndoorLocation::ExecDraw_d3d(unsigned int uFaceID, IndoorCameraD3D_Vec4 *pVertices, unsigned int uNumVertices, RenderVertexSoft *a4)
434 {
435 //unsigned int v4; // esi@1
436 char *v5; // eax@4
437 signed int v6; // ecx@4
438 char *v7; // eax@8
439 signed int v8; // ecx@8
440 //BLVFace *v9; // esi@13
441 //IndoorCameraD3D *v10; // edi@16
442 //int v11; // ebx@17
443 //Vec3_short_ *v12; // ecx@18
444 //char *v13; // edx@18
445 //int v14; // eax@19
446 //unsigned __int8 v15; // sf@19
447 //unsigned __int8 v16; // of@19
448 int v17; // ebx@25
449 //double v18; // st7@27
450 //double v19; // st6@27
451 //double v20; // st5@27
452 //char v21; // dl@27
453 //unsigned int v22; // eax@44
454 unsigned int v23; // eax@35
455 //DWORD v24; // eax@37
456 //int v25; // eax@38
457 //char *v26; // edi@38
458 IDirect3DTexture2 *v27; // eax@42
459 Texture *v28; // [sp+Ch] [bp-1Ch]@15
460 //int i; // [sp+10h] [bp-18h]@38
461 //LightmapBuilder *pStru4; // [sp+14h] [bp-14h]@16
462 //IndoorCameraD3D *v31; // [sp+18h] [bp-10h]@16
463 //IndoorCameraD3D_Vec4 *a7; // [sp+1Ch] [bp-Ch]@1
464 //unsigned int uFaceID_; // [sp+20h] [bp-8h]@1
465 unsigned int uNumVerticesa; // [sp+24h] [bp-4h]@17
466 int a4a; // [sp+34h] [bp+Ch]@25
467 //unsigned int a4b; // [sp+34h] [bp+Ch]@38
468
469 //v4 = uFaceID;
470 //a7 = pVertices;
471 //uFaceID_ = uFaceID;
472 if (uFaceID >= pIndoor->uNumFaces)
473 return;
474
475 static RenderVertexSoft static_vertices_F7C228[64];
476 static RenderVertexSoft static_vertices_F7B628[64];
477 static stru154 stru_F7B60C; // idb
478
479 //v9 = &pIndoor->pFaces[uFaceID];
480 auto pFace = &pIndoor->pFaces[uFaceID];
481 if (pFace->uNumVertices < 3)
482 return;
483
484
485 if (pFace->Invisible())
486 return;
487
488 ++pBLVRenderParams->uNumFacesRenderedThisFrame;
489 pFace->uAttributes |= 0x80u;
490
491 if (!pFace->GetTexture())
492 return;
493
494 v28 = pFace->GetTexture();
495
496 if (!pGame->pIndoorCameraD3D->IsCulled(pFace))
497 {
498 uNumVerticesa = pFace->uNumVertices;
499 for (uint i = 0; i < pFace->uNumVertices; ++i)
500 {
501 static_vertices_F7C228[i].vWorldPosition.x = pIndoor->pVertices[pFace->pVertexIDs[i]].x;
502 static_vertices_F7C228[i].vWorldPosition.y = pIndoor->pVertices[pFace->pVertexIDs[i]].y;
503 static_vertices_F7C228[i].vWorldPosition.z = pIndoor->pVertices[pFace->pVertexIDs[i]].z;
504 static_vertices_F7C228[i].u = (signed short)pFace->pVertexUIDs[i];
505 static_vertices_F7C228[i].v = (signed short)pFace->pVertexVIDs[i];
506 }
507
508 if (!pVertices ||
509 (pGame->pStru9Instance->_498377(a4, 4u, pVertices, static_vertices_F7C228, &uNumVerticesa), uNumVerticesa) )
510 {
511 if (pGame->pIndoorCameraD3D->_437285_prolly_colide_vertices_against_frustrum(
512 static_vertices_F7C228,
513 &uNumVerticesa,
514 static_vertices_F7B628,
515 pGame->pIndoorCameraD3D->std__vector_000034_prolly_frustrum,
516 4,
517 false,
518 0) != 1
519 || uNumVerticesa )
520 {
521 a4a = SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel);
522 v17 = (248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) | (((248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) | ((248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) << 8)) << 8);
523 sub_4B0E07(uFaceID);
524 pGame->pLightmapBuilder->ApplyLights_IndoorFace(uFaceID);
525 pDecalBuilder->ApplyBloodsplatDecals_IndoorFace(uFaceID);
526 pGame->pIndoorCameraD3D->ViewTransfrom_OffsetUV(static_vertices_F7B628, uNumVerticesa, array_507D30, &stru_F8AD28);
527 pGame->pIndoorCameraD3D->Project(array_507D30, uNumVerticesa, 0);
528 pGame->pLightmapBuilder->std__vector_000004_size = 0;
529 if (stru_F8AD28.uNumLightsApplied > 0 ||
530 pDecalBuilder->uNumDecals > 0)
531 {
532 stru_F7B60C.face_plane.vNormal.x = pFace->pFacePlane.vNormal.x;
533 stru_F7B60C.polygonType = pFace->uPolygonType;
534 stru_F7B60C.face_plane.vNormal.y = pFace->pFacePlane.vNormal.y;
535 stru_F7B60C.face_plane.vNormal.z = pFace->pFacePlane.vNormal.z;
536 stru_F7B60C.face_plane.dist = pFace->pFacePlane.dist;
537 }
538
539 if (stru_F8AD28.uNumLightsApplied > 0 &&
540 !(pFace->uAttributes & 0x400000))
541 pGame->pLightmapBuilder->ApplyLights(
542 &stru_F8AD28,
543 &stru_F7B60C,
544 uNumVerticesa,
545 array_507D30,
546 pVertices,
547 0);
548
549 if (pDecalBuilder->uNumDecals > 0)
550 pDecalBuilder->ApplyDecals(
551 a4a,
552 1,
553 &stru_F7B60C,
554 uNumVerticesa,
555 array_507D30,
556 pVertices,
557 0,
558 pFace->uSectorID);
559
560 if (pFace->Animated() &&
561 pFace->uBitmapID == pRenderer->field_1036AC_bitmapid )
562 {
563 __debugbreak();
564 v23 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
565 goto LABEL_42;
566 }
567
568 if (pFace->Animated())
569 {
570 //auto v24 = GetTickCount() / 4;
571 //auto v25 = v24 - stru_5C6E00->uIntegerHalfPi;
572 uint eightSeconds = GetTickCount() % 8000;
573 float angle = (eightSeconds / 8000.0f) * 2 * 3.1415f;
574
575 //animte lava back and forth
576 for (uint i = 0; i < uNumVerticesa; ++i)
577 //array_507D30[i].v += (double)(pBitmaps_LOD->pTextures[pFace->uBitmapID].uHeightMinus1 & (unsigned int)(stru_5C6E00->SinCos(v25) >> 8));
578 array_507D30[i].v += pBitmaps_LOD->pTextures[pFace->uBitmapID].uHeightMinus1 * cosf(angle);
579
580 v23 = pFace->uBitmapID;
581 goto LABEL_42;
582 }
583 else if (pFace->uAttributes & 0x4000)
584 {
585 v23 = pTextureFrameTable->GetFrameTexture(
586 pFace->uBitmapID,
587 pBLVRenderParams->field_0_timer_);
588 LABEL_42:
589 v27 = pBitmaps_LOD->pHardwareTextures[v23];
590 if (pFace->uAttributes & 0x400000)
591 _479A53_draw_some_blv_poly(uNumVerticesa, uFaceID);
592 else
593 pRenderer->DrawIndoorPolygon(uNumVerticesa, pFace, v27, v28, 8 * uFaceID | 6, v17, 0);
594 return;
595 }
596 }
597 }
598 }
599 }
600
601 //----- (004AFF79) --------------------------------------------------------
602 void IndoorLocation::ExecDraw_sw(unsigned int uFaceID)
603 {
604 unsigned int v1; // ebx@1
605 BLVFace *v2; // esi@3
606 unsigned int v3; // eax@3
607 Texture *v4; // eax@8
608 Texture *v5; // edi@8
609 int v6; // eax@9
610 int v7; // eax@9
611 int v8; // ecx@17
612 int v9; // ebx@17
613 int v10; // eax@17
614 int v11; // esi@17
615 unsigned int v12; // eax@17
616 int j; // ecx@19
617 int v14; // edx@20
618 int v15; // eax@20
619 int v16; // edx@20
620 int i; // ebx@22
621 int v18; // ecx@23
622 int v19; // eax@23
623 int v20; // eax@23
624 int v21; // eax@24
625 unsigned __int8 *v22; // ecx@24
626 int v23; // ebx@24
627 int v24; // esi@25
628 int v25; // eax@28
629 unsigned __int16 *v26; // eax@28
630 unsigned int v27; // eax@29
631 int v28; // eax@30
632 char *v29; // esi@31
633 int v30; // eax@33
634 int v31; // eax@33
635 int v32; // eax@35
636 int v33; // edx@35
637 signed int v34; // ebx@35
638 int v35; // eax@35
639 int v36; // ebx@35
640 signed int v37; // ebx@35
641 signed int v38; // edi@35
642 unsigned int v39; // edi@36
643 int v40; // edx@40
644 int v41; // ecx@40
645 signed int v42; // edx@40
646 int v43; // edx@42
647 int v44; // eax@42
648 unsigned __int16 *v45; // eax@43
649 int *v46; // esi@44
650 unsigned __int16 *v47; // edi@44
651 unsigned int v48; // edx@44
652 int v49; // ebx@44
653 char v50; // cl@44
654 char v51; // ch@44
655 unsigned int v52; // ebx@46
656 int v53; // edx@46
657 unsigned int v54; // ebx@46
658 int v55; // edx@46
659 unsigned int v56; // ebx@47
660 int v57; // edx@47
661 int v58; // ebx@47
662 int v59; // edx@47
663 unsigned __int16 *v60; // eax@50
664 int *v61; // esi@51
665 unsigned __int16 *v62; // edi@51
666 unsigned int v63; // edx@51
667 int v64; // ebx@51
668 char v65; // cl@51
669 char v66; // ch@51
670 unsigned int v67; // ebx@53
671 int v68; // edx@53
672 unsigned int v69; // ebx@53
673 int v70; // edx@53
674 unsigned int v71; // ebx@54
675 int v72; // edx@54
676 int v73; // ebx@54
677 int v74; // edx@54
678 unsigned __int16 *v75; // eax@58
679 int *v76; // esi@59
680 int v77; // edi@59
681 unsigned int v78; // edx@59
682 int v79; // ebx@59
683 char v80; // cl@59
684 char v81; // ch@59
685 int v82; // ebx@61
686 int v83; // edx@61
687 unsigned int v84; // ebx@62
688 int v85; // edx@62
689 unsigned __int16 *v86; // eax@65
690 int *v87; // esi@66
691 int v88; // edi@66
692 unsigned int v89; // edx@66
693 int v90; // ebx@66
694 char v91; // cl@66
695 char v92; // ch@66
696 int v93; // ebx@68
697 int v94; // edx@68
698 unsigned __int16 v95; // bx@69
699 int v96; // edx@69
700 unsigned __int8 *v97; // [sp+Ch] [bp-9Ch]@24
701 unsigned __int8 *v98; // [sp+10h] [bp-98h]@24
702 unsigned __int8 *v99; // [sp+14h] [bp-94h]@24
703 unsigned __int8 *v100; // [sp+18h] [bp-90h]@24
704 int v101; // [sp+1Ch] [bp-8Ch]@40
705 int v102; // [sp+20h] [bp-88h]@31
706 BLVFace *v103; // [sp+24h] [bp-84h]@3
707 unsigned __int16 *v104; // [sp+28h] [bp-80h]@24
708 int v105; // [sp+2Ch] [bp-7Ch]@30
709 int v106; // [sp+30h] [bp-78h]@24
710 int v107; // [sp+34h] [bp-74h]@9
711 Texture *v108; // [sp+38h] [bp-70h]@8
712 int v109; // [sp+3Ch] [bp-6Ch]@9
713 unsigned int v110; // [sp+40h] [bp-68h]@24
714 unsigned int v111; // [sp+44h] [bp-64h]@1
715 int *k; // [sp+48h] [bp-60h]@31
716 int v113; // [sp+4Ch] [bp-5Ch]@35
717 int v114; // [sp+50h] [bp-58h]@35
718 int v115; // [sp+54h] [bp-54h]@42
719 unsigned __int8 *v116; // [sp+58h] [bp-50h]@35
720 int v117; // [sp+5Ch] [bp-4Ch]@33
721 int a1; // [sp+60h] [bp-48h]@27
722 int v119; // [sp+64h] [bp-44h]@17
723 int v120; // [sp+68h] [bp-40h]@23
724 unsigned int v121; // [sp+6Ch] [bp-3Ch]@40
725 unsigned int v122; // [sp+70h] [bp-38h]@35
726 int v123; // [sp+74h] [bp-34h]@30
727 int v124; // [sp+78h] [bp-30h]@17
728 int v125; // [sp+7Ch] [bp-2Ch]@35
729 unsigned int v126; // [sp+80h] [bp-28h]@9
730 int v127; // [sp+84h] [bp-24h]@17
731 int v128; // [sp+88h] [bp-20h]@9
732 int *pZPixel; // [sp+8Ch] [bp-1Ch]@28
733 int a2; // [sp+90h] [bp-18h]@16
734 unsigned int v131; // [sp+94h] [bp-14h]@17
735 unsigned __int16 *pColorPixel; // [sp+98h] [bp-10h]@28
736 int v133; // [sp+9Ch] [bp-Ch]@17
737 int v134; // [sp+A0h] [bp-8h]@17
738 int v135; // [sp+A4h] [bp-4h]@24
739
740 v1 = uFaceID;
741 v111 = pRenderer->uTargetSurfacePitch;
742 if ( (uFaceID & 0x80000000u) == 0 )
743 {
744 if ( (signed int)uFaceID < (signed int)pIndoor->uNumFaces )
745 {
746 v2 = &pIndoor->pFaces[uFaceID];
747 v103 = v2;
748 v3 = v2->uAttributes;
749 if ( !(BYTE1(v3) & 0x20) )
750 {
751 if ( v3 & 0x400000 )
752 {
753 sub_4ADD1D(uFaceID);
754 return;
755 }
756 if ( !(v3 & 0x10) || (sub_4AD504(uFaceID), pRenderer->pRenderD3D) )
757 {
758 v4 = v2->GetTexture();
759 ++pBLVRenderParams->uNumFacesRenderedThisFrame;
760 v5 = v4;
761 v108 = v4;
762 if ( v4 )
763 {
764 v6 = v4->palette_id2;
765 LOBYTE(v2->uAttributes) |= 0x80u;
766 v109 = v6;
767 sub_4AE5F1(v1);
768 v126 = stru_F8AD28.pDeltaUV[0];
769 v128 = stru_F8AD28.pDeltaUV[1];
770 v107 = bUseLoResSprites;
771 v7 = sub_423B5D(v1);
772 if ( v7 )
773 {
774 if ( sub_424829(v7, &stru_F8A590, pBLVRenderParams->field_7C, v1) )
775 {
776 if ( v2->uPolygonType == 1 )
777 {
778 for ( i = 0; i < stru_F8AD28.uNumLightsApplied; stru_F8AD28._blv_lights_ys[v18] = v20 )
779 {
780 v18 = i;
781 v120 = stru_F8AD28._blv_lights_xs[i];
782 v134 = (unsigned __int64)(v120 * (signed __int64)-stru_F8AD28.plane_4.vNormal.y) >> 16;
783 v133 = stru_F8AD28.plane_4.vNormal.x;
784 v120 = stru_F8AD28._blv_lights_ys[i];
785 v133 = (unsigned __int64)(v120 * (signed __int64)stru_F8AD28.plane_4.vNormal.x) >> 16;
786 v19 = v128;
787 stru_F8AD28._blv_lights_xs[i] = v126
788 + v134
789 + ((unsigned __int64)(v120
790 * (signed __int64)stru_F8AD28.plane_4.vNormal.x) >> 16);
791 v20 = v19 - stru_F8AD28._blv_lights_zs[i++];
792 }
793 }
794 else
795 {
796 if ( v2->uPolygonType != 3 )
797 {
798 if ( v2->uPolygonType == 4 )
799 {
800 LABEL_16:
801 a2 = 0;
802 if ( stru_F8AD28.uNumLightsApplied > 0 )
803 {
804 do
805 {
806 v8 = a2;
807 v9 = stru_F8AD28._blv_lights_xs[a2];
808 v131 = stru_F8AD28._blv_lights_ys[a2];
809 v10 = stru_F8AD28._blv_lights_zs[a2];
810 v11 = (signed int)(v10 * stru_F8AD28.plane_4.vNormal.z
811 + stru_F8AD28.plane_4.dist
812 + v9 * stru_F8AD28.plane_4.vNormal.x
813 + v131 * stru_F8AD28.plane_4.vNormal.y) >> 16;
814 v119 = v9
815 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
816 * (signed __int64)((signed int)(v10 * stru_F8AD28.plane_4.vNormal.z
817 + stru_F8AD28.plane_4.dist
818 + v9 * stru_F8AD28.plane_4.vNormal.x
819 + v131 * stru_F8AD28.plane_4.vNormal.y) >> 16)) >> 16);
820 v131 -= (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)v11) >> 16;
821 v127 = v10 - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z * (signed __int64)v11) >> 16);
822 stru_F8AD28._blv_lights_xs[a2] = ((unsigned __int64)(v119
823 * (signed __int64)stru_F8AD28.vec_14.x) >> 16)
824 + ((unsigned __int64)((signed int)v131
825 * (signed __int64)stru_F8AD28.vec_14.y) >> 16);
826 v124 = (unsigned __int64)(v119 * (signed __int64)stru_F8AD28.vec_20.x) >> 16;
827 v134 = (unsigned __int64)((signed int)v131 * (signed __int64)stru_F8AD28.vec_20.y) >> 16;
828 v133 = (unsigned __int64)(v127 * (signed __int64)stru_F8AD28.vec_20.z) >> 16;
829 v12 = v126;
830 stru_F8AD28._blv_lights_ys[v8] = v124
831 + ((unsigned __int64)((signed int)v131
832 * (signed __int64)stru_F8AD28.vec_20.y) >> 16)
833 + ((unsigned __int64)(v127
834 * (signed __int64)stru_F8AD28.vec_20.z) >> 16);
835 stru_F8AD28._blv_lights_xs[v8] += v12;
836 stru_F8AD28._blv_lights_ys[v8] += v128;
837 ++a2;
838 }
839 while ( a2 < stru_F8AD28.uNumLightsApplied );
840 v2 = v103;
841 }
842 goto LABEL_24;
843 }
844 if ( v2->uPolygonType != 5 )
845 {
846 if ( v2->uPolygonType != 6 )
847 goto LABEL_24;
848 goto LABEL_16;
849 }
850 }
851 for ( j = 0; j < stru_F8AD28.uNumLightsApplied; *(int *)v15 = v16 )
852 {
853 v14 = v128;
854 stru_F8AD28._blv_lights_xs[j] += v126;
855 v15 = 4 * j + 16297672;
856 v16 = v14 - stru_F8AD28._blv_lights_ys[j++];
857 }
858 }
859 LABEL_24:
860 v135 = 1;
861 pGame->_44ED0A(v2, &v135, 31);
862 v104 = sr_sub_47C24C_get_palette(v2, v109, 0, 1);
863 v134 = stru_F8AD28.field_44;
864 v106 = stru_F8AD28.field_48;
865 v21 = stru_F8A590._viewport_space_y;
866 a2 = stru_F8A590._viewport_space_y;
867 v110 = v111 * stru_F8A590._viewport_space_y;
868 v97 = v5->pLevelOfDetail0;
869 v98 = v5->pLevelOfDetail1;
870 v99 = v5->pLevelOfDetail2;
871 v22 = v5->pLevelOfDetail3;
872 v23 = 640 * stru_F8A590._viewport_space_y;
873 v119 = 640 * stru_F8A590._viewport_space_y;
874 v100 = v22;
875 if ( stru_F8A590._viewport_space_y <= stru_F8A590._viewport_space_w )
876 {
877 v24 = 2 * stru_F8A590._viewport_space_y;
878 v120 = 2 * stru_F8A590._viewport_space_y;
879 while ( 1 )
880 {
881 a1 = *(__int16 *)((char *)stru_F8A590.array_18 + v24);
882 sub_4AE313(a1, v21, &stru_F81018.field_0);
883 if ( LOBYTE(viewparams->field_20) )
884 {
885 v27 = v111 * (v24 - pBLVRenderParams->uViewportY);
886 pZPixel = &pBLVRenderParams->pTargetZBuffer[2
887 * (*(__int16 *)((char *)stru_F8A590.array_18 + v24)
888 + 320 * (v24 - pBLVRenderParams->uViewportY))
889 - pBLVRenderParams->uViewportX];
890 pColorPixel = &pBLVRenderParams->pRenderTarget[v27
891 + 2 * *(__int16 *)((char *)stru_F8A590.array_18 + v24)
892 - pBLVRenderParams->uViewportX];
893 v26 = &pBLVRenderParams->pRenderTarget[v27
894 + 2 * *(__int16 *)((char *)stru_F8A590.array_3D8 + v24)
895 - pBLVRenderParams->uViewportX];
896 v23 = v119;
897 }
898 else
899 {
900 v25 = *(__int16 *)((char *)stru_F8A590.array_18 + v24);
901 pZPixel = &pBLVRenderParams->pTargetZBuffer[v25 + v23];
902 pColorPixel = &pBLVRenderParams->pRenderTarget[v25 + v110];
903 v26 = &pBLVRenderParams->pRenderTarget[v110 + *(__int16 *)((char *)stru_F8A590.array_3D8 + v24)];
904 }
905 v131 = (unsigned int)v26;
906 HIWORD(v28) = HIWORD(stru_F81018.field_0.field_0);
907 LOWORD(v28) = 0;
908 v105 = stru_F8AD28.field_0 | v28;
909 v123 = sub_4AE491(SHIWORD(stru_F81018.field_0.field_4), SHIWORD(stru_F81018.field_0.field_8));
910 if ( (unsigned int)pColorPixel < v131 )
911 {
912 v102 = v107 + v106;
913 v29 = (char *)&stru_F81018.field_34.field_8;
914 a1 += v134;
915 for ( k = &stru_F81018.field_34.field_8; ; v29 = (char *)k )
916 {
917 sub_4AE313(a1, a2, (stru337_stru0 *)(v29 - 8));
918 v30 = *((int *)v29 - 2);
919 LOWORD(v30) = 0;
920 v117 = v105;
921 v31 = stru_F8AD28.field_0 | v30;
922 if ( v105 <= (unsigned int)v31 )
923 v117 = v31;
924 v105 = v31;
925 v32 = *((int *)v29 - 14);
926 v122 = *((int *)v29 - 14) >> v107;
927 v33 = *((int *)v29 - 13);
928 v125 = *((int *)v29 - 13) >> v107;
929 v34 = *((int *)v29 - 1) - v32;
930 v113 = (*(int *)v29 - v33) >> v102;
931 v35 = *((int *)v29 - 11);
932 v114 = v34 >> v102;
933 v116 = (&v97)[4 * v35];
934 v36 = v35 + 16 - v5->uWidthLn2;
935 v133 = v35 + 16;
936 v127 = v35 + v36;
937 v37 = v5->uWidthMinus1 >> v35;
938 v38 = v5->uHeightMinus1 >> v35 << (v35 + 16);
939 v128 = v37;
940 v126 = v38;
941 v39 = (unsigned int)(LOBYTE(viewparams->field_20) ? &pColorPixel[2 * v134] : &pColorPixel[v134]);
942 if ( v39 > v131 )
943 v39 = v131;
944 v40 = *((short *)v29 + 1);
945 v41 = *((short *)v29 - 1);
946 v121 = v39;
947 v42 = sub_4AE491(v41, v40);
948 v101 = v42;
949 v124 = (signed int)(v39 - (int)pColorPixel) >> 1;
950 if ( v123 >> 16 == v42 >> 16 || v135 & 2 )
951 {
952 v123 = (int)sr_sub_47C24C_get_palette(v103, v109, v123 >> 16, 1);
953 if ( LOBYTE(viewparams->field_20) )
954 {
955 v86 = pColorPixel;
956 if ( (unsigned int)pColorPixel < v121 )
957 {
958 v87 = pZPixel;
959 v88 = v123;
960 v89 = v122;
961 v90 = v125;
962 v91 = v133;
963 v92 = v127;
964 if ( v124 & 2 )
965 {
966 *pZPixel = v117;
967 v87 -= 2;
968 v86 = pColorPixel + 2;
969 goto LABEL_69;
970 }
971 do
972 {
973 v86 += 4;
974 v93 = *(&v116[v128 & (v89 >> v91)] + ((v126 & v90) >> v92));
975 v94 = v117;
976 LOWORD(v93) = *(short *)(v88 + 2 * v93);
977 *v87 = v117;
978 v87[1] = v94;
979 v87[640] = v94;
980 v87[641] = v94;
981 *(v86 - 4) = v93;
982 *(v86 - 3) = v93;
983 v86[636] = v93;
984 v86[637] = v93;
985 v87[2] = v94;
986 v87[3] = v94;
987 v87[642] = v94;
988 v87[643] = v94;
989 v122 += v114;
990 v125 += v113;
991 v89 = v122;
992 v90 = v125;
993 LABEL_69:
994 v87 += 4;
995 v95 = *(short *)(v88 + 2 * *(&v116[v128 & (v89 >> v91)] + ((v126 & v90) >> v92)));
996 v96 = v114;
997 *(v86 - 2) = v95;
998 *(v86 - 1) = v95;
999 v86[638] = v95;
1000 v86[639] = v95;
1001 v122 += v96;
1002 v125 += v113;
1003 v89 = v122;
1004 v90 = v125;
1005 }
1006 while ( (unsigned int)v86 < v121 );
1007 pColorPixel = v86;
1008 pZPixel = v87;
1009 }
1010 }
1011 else
1012 {
1013 v75 = pColorPixel;
1014 if ( (unsigned int)pColorPixel < v121 )
1015 {
1016 v76 = pZPixel;
1017 v77 = v123;
1018 v78 = v122;
1019 v79 = v125;
1020 v80 = v133;
1021 v81 = v127;
1022 if ( v124 & 1 )
1023 {
1024 *pZPixel = v117;
1025 --v76;
1026 v75 = pColorPixel + 1;
1027 goto LABEL_62;
1028 }
1029 do
1030 {
1031 v75 += 2;
1032 v82 = *(&v116[v128 & (v78 >> v80)] + ((v126 & v79) >> v81));
1033 v83 = v117;
1034 LOWORD(v82) = *(short *)(v77 + 2 * v82);
1035 *v76 = v117;
1036 *(v75 - 2) = v82;
1037 v76[1] = v83;
1038 v122 += v114;
1039 v125 += v113;
1040 v78 = v122;
1041 v79 = v125;
1042 LABEL_62:
1043 v84 = (unsigned int)(&v116[v128 & (v78 >> v80)] + ((v126 & v79) >> v81));
1044 v76 += 2;
1045 v85 = v114;
1046 *(v75 - 1) = *(short *)(v77 + 2 * *(char *)v84);
1047 v122 += v85;
1048 v125 += v113;
1049 v78 = v122;
1050 v79 = v125;
1051 }
1052 while ( (unsigned int)v75 < v121 );
1053 pColorPixel = v75;
1054 pZPixel = v76;
1055 }
1056 }
1057 }
1058 else
1059 {
1060 v43 = (v42 - v123) >> v106;
1061 v44 = v123 - v43;
1062 v123 = v43;
1063 v115 = v44;
1064 if ( LOBYTE(viewparams->field_20) )
1065 {
1066 v60 = pColorPixel;
1067 if ( (unsigned int)pColorPixel < v121 )
1068 {
1069 v61 = pZPixel;
1070 v62 = v104;
1071 v63 = v122;
1072 v64 = v125;
1073 v65 = v133;
1074 v66 = v127;
1075 if ( v124 & 2 )
1076 {
1077 *pZPixel = v117;
1078 v61 += 2;
1079 v60 = pColorPixel + 2;
1080 goto LABEL_54;
1081 }
1082 do
1083 {
1084 v67 = (v128 & (v63 >> v65)) + ((v126 & v64) >> v66);
1085 v68 = v123 + v115;
1086 v60 += 4;
1087 v115 = v68;
1088 v69 = ((v68 & 0xFFFF0000u) >> 8) + v116[v67];
1089 v70 = v117;
1090 LOWORD(v69) = v62[v69];
1091 *v61 = v117;
1092 v61[1] = v70;
1093 v61[640] = v70;
1094 v61[641] = v70;
1095 *(v60 - 4) = v69;
1096 *(v60 - 3) = v69;
1097 v60[636] = v69;
1098 v60[637] = v69;
1099 v61[2] = v70;
1100 v61[3] = v70;
1101 v61[642] = v70;
1102 v61[643] = v70;
1103 v122 += v114;
1104 v125 += v113;
1105 v63 = v122;
1106 v64 = v125;
1107 v61 += 4;
1108 LABEL_54:
1109 v71 = (v128 & (v63 >> v65)) + ((v126 & v64) >> v66);
1110 v72 = v123 + v115;
1111 v73 = v116[v71];
1112 v115 = v72;
1113 LOWORD(v73) = v62[((v72 & 0xFFFF0000u) >> 8) + v73];
1114 v74 = v114;
1115 *(v60 - 2) = v73;
1116 *(v60 - 1) = v73;
1117 v60[638] = v73;
1118 v60[639] = v73;
1119 v122 += v74;
1120 v125 += v113;
1121 v63 = v122;
1122 v64 = v125;
1123 }
1124 while ( (unsigned int)v60 < v121 );
1125 pColorPixel = v60;
1126 pZPixel = v61;
1127 }
1128 }
1129 else
1130 {
1131 v45 = pColorPixel;
1132 if ( (unsigned int)pColorPixel < v121 )
1133 {
1134 v46 = pZPixel;
1135 v47 = v104;
1136 v48 = v122;
1137 v49 = v125;
1138 v50 = v133;
1139 v51 = v127;
1140 if ( v124 & 1 )
1141 {
1142 *pZPixel = v117;
1143 ++v46;
1144 v45 = pColorPixel + 1;
1145 goto LABEL_47;
1146 }
1147 do
1148 {
1149 v52 = (v128 & (v48 >> v50)) + ((v126 & v49) >> v51);
1150 v53 = v123 + v115;
1151 v45 += 2;
1152 v115 = v53;
1153 v54 = ((v53 & 0xFFFF0000u) >> 8) + v116[v52];
1154 v55 = v117;
1155 LOWORD(v54) = v47[v54];
1156 *v46 = v117;
1157 *(v45 - 2) = v54;
1158 v46[1] = v55;
1159 v122 += v114;
1160 v125 += v113;
1161 v48 = v122;
1162 v49 = v125;
1163 v46 += 2;
1164 LABEL_47:
1165 v56 = (v128 & (v48 >> v50)) + ((v126 & v49) >> v51);
1166 v57 = v123 + v115;
1167 v58 = v116[v56];
1168 v115 = v57;
1169 LOWORD(v58) = v47[((v57 & 0xFFFF0000u) >> 8) + v58];
1170 v59 = v114;
1171 *(v45 - 1) = v58;
1172 v122 += v59;
1173 v125 += v113;
1174 v48 = v122;
1175 v49 = v125;
1176 }
1177 while ( (unsigned int)v45 < v121 );
1178 pColorPixel = v45;
1179 pZPixel = v46;
1180 }
1181 }
1182 }
1183 k += 13;
1184 v5 = v108;
1185 v123 = v101;
1186 a1 += v134;
1187 if ( (unsigned int)pColorPixel >= v131 )
1188 break;
1189 }
1190 v23 = v119;
1191 v24 = v120;
1192 }
1193 ++a2;
1194 v110 += v111;
1195 v23 += 640;
1196 v24 += 2;
1197 v120 = v24;
1198 v119 = v23;
1199 if ( a2 > stru_F8A590._viewport_space_w )
1200 break;
1201 v21 = a2;
1202 }
1203 }
1204 return;
1205 }
1206 }
1207 }
1208 }
1209 }
1210 }
1211 }
1212 }
1213 // 4AE491: using guessed type int __fastcall sub_4AE491(int, int);
1214
1215
1216
1217
1218 //----- (004B0E07) --------------------------------------------------------
1219 unsigned int __fastcall sub_4B0E07(unsigned int uFaceID)
1220 {
1221 BLVFace *v1; // edi@1
1222 BLVFaceExtra *v2; // ecx@1
1223 Texture *v3; // esi@1
1224 unsigned int v4; // eax@1
1225 unsigned int v5; // ecx@1
1226 unsigned int result; // eax@1
1227 unsigned int v7; // ecx@5
1228
1229 v1 = &pIndoor->pFaces[uFaceID];
1230 v2 = &pIndoor->pFaceExtras[v1->uFaceExtraID];
1231 v3 = (Texture *)(v1->uBitmapID != -1 ? (int)&pBitmaps_LOD->pTextures[v1->uBitmapID] : 0);
1232 stru_F8AD28.pDeltaUV[0] = v2->sTextureDeltaU;
1233 stru_F8AD28.pDeltaUV[1] = v2->sTextureDeltaV;
1234 v4 = GetTickCount();
1235 v5 = v1->uAttributes;
1236 result = v4 >> 3;
1237 if ( v5 & 4 )
1238 {
1239 stru_F8AD28.pDeltaUV[1] -= result & v3->uHeightMinus1;
1240 }
1241 else
1242 {
1243 if ( v5 & 0x20 )
1244 stru_F8AD28.pDeltaUV[1] += result & v3->uHeightMinus1;
1245 }
1246 v7 = v1->uAttributes;
1247 if ( BYTE1(v7) & 8 )
1248 {
1249 stru_F8AD28.pDeltaUV[0] -= result & v3->uWidthMinus1;
1250 }
1251 else
1252 {
1253 if ( v7 & 0x40 )
1254 stru_F8AD28.pDeltaUV[0] += result & v3->uWidthMinus1;
1255 }
1256 return result;
1257 }
1258
1259
1260
1261 //----- (004B0EA8) --------------------------------------------------------
1262 void BspRenderer::PrepareFaceRenderList_d3d(int a2, unsigned int uFaceID)
1263 {
1264 //unsigned int v3; // edx@1
1265 //stru170 *v4; // ebx@1
1266 //BLVFace *v5; // eax@1
1267 //int v6; // ecx@2
1268 unsigned __int16 v7; // ax@11
1269 Vec3_short_ *v8; // esi@15
1270 int v9; // edx@15
1271 signed int v10; // eax@18
1272 signed int v11; // edi@19
1273 signed int v12; // ecx@19
1274 signed int v13; // esi@19
1275 signed int v14; // edx@20
1276 int v15; // edx@24
1277 //int v16; // esi@29
1278 //BLVFace *v17; // edi@34
1279 unsigned __int16 v18; // ax@34
1280 char *v19; // eax@38
1281 signed int v20; // ecx@38
1282 char *v21; // eax@42
1283 signed int v22; // ecx@42
1284 //signed int v23; // edx@45
1285 //char *v24; // ecx@46
1286 //int v25; // eax@47
1287 //Vec3_short_ *v26; // eax@47
1288 //double v27; // st7@47
1289 //signed int v28; // ST28_4@47
1290 char v29; // al@48
1291 signed int v30; // eax@51
1292 int v31; // eax@52
1293 //unsigned int v32; // eax@55
1294 //__int16 v33; // cx@56
1295 signed int v34; // [sp+Ch] [bp-14h]@18
1296 //int a0; // [sp+14h] [bp-Ch]@2
1297 //IndoorCameraD3D *a0a; // [sp+14h] [bp-Ch]@36
1298 signed int v37; // [sp+18h] [bp-8h]@19
1299 //stru10 *v38; // [sp+18h] [bp-8h]@36
1300 //BLVFace *v39; // [sp+1Ch] [bp-4h]@1
1301
1302 //v3 = uFaceID;
1303 //v4 = this;
1304 //v5 = &pIndoor->pFaces[uFaceID];
1305 field_FA8[std__vector_000FA8].std__vector_0007A8 = -1;
1306 //v39 = &pIndoor->pFaces[uFaceID];
1307
1308 auto pFace = &pIndoor->pFaces[uFaceID];
1309
1310 if (pFace->uAttributes & 1)
1311 {
1312 auto p = &field_FA8[a2];
1313 //v6 = (int)((char *)this + 2252 * a2);
1314 //a0 = v6;
1315 if (p->uFaceID == uFaceID)
1316 return;
1317 if (!a2 &&
1318 pBLVRenderParams->vPartyPos.x >= pFace->pBounding.x1 - 16 &&
1319 pBLVRenderParams->vPartyPos.x <= pFace->pBounding.x2 + 16 &&
1320 pBLVRenderParams->vPartyPos.y >= pFace->pBounding.y1 - 16 &&
1321 pBLVRenderParams->vPartyPos.y <= pFace->pBounding.y2 + 16 &&
1322 pBLVRenderParams->vPartyPos.z >= pFace->pBounding.z1 - 16 &&
1323 pBLVRenderParams->vPartyPos.z <= pFace->pBounding.z2 + 16 )
1324 {
1325 if ( abs(pFace->pFacePlane_old.dist + pBLVRenderParams->vPartyPos.x * pFace->pFacePlane_old.vNormal.x
1326 + pBLVRenderParams->vPartyPos.y * pFace->pFacePlane_old.vNormal.y
1327 + pBLVRenderParams->vPartyPos.z * pFace->pFacePlane_old.vNormal.z) <= 589824 )
1328 {
1329 v7 = pFace->uSectorID;
1330 if ( field_FA8[0].uSectorID == v7 )
1331 v7 = pFace->uBackSectorID;
1332 field_FA8[std__vector_000FA8].uSectorID = v7;
1333 field_FA8[std__vector_000FA8].uFaceID = uFaceID;
1334 field_FA8[std__vector_000FA8].uViewportX = pBLVRenderParams->uViewportX;
1335 field_FA8[std__vector_000FA8].uViewportZ = pBLVRenderParams->uViewportZ;
1336 field_FA8[std__vector_000FA8].uViewportY = pBLVRenderParams->uViewportY;
1337 field_FA8[std__vector_000FA8].uViewportW = pBLVRenderParams->uViewportW;
1338 field_FA8[std__vector_000FA8++].field_C._43F9E1(
1339 pBLVRenderParams->uViewportX,
1340 pBLVRenderParams->uViewportY,
1341 pBLVRenderParams->uViewportZ,
1342 pBLVRenderParams->uViewportW);
1343 sub_440639(std__vector_000FA8 - 1);
1344 return;
1345 }
1346 //v5 = v39;
1347 //v6 = a0;
1348 }
1349 v8 = &pIndoor->pVertices[pFace->pVertexIDs[0]];
1350 v9 = pFace->pFacePlane_old.vNormal.x * (v8->x - pBLVRenderParams->vPartyPos.x)
1351 + pFace->pFacePlane_old.vNormal.y * (v8->y - pBLVRenderParams->vPartyPos.y)
1352 + pFace->pFacePlane_old.vNormal.z * (v8->z - pBLVRenderParams->vPartyPos.z);
1353 if (p->uSectorID != pFace->uSectorID)
1354 v9 = -v9;
1355 if ( v9 < 0 )
1356 {
1357 v10 = sub_423B5D(uFaceID);
1358 v34 = v10;
1359 if ( v10 )
1360 {
1361 v11 = dword_50BAC8[0];
1362 v12 = dword_50B9D8_ys[0];
1363 a2 = dword_50BAC8[0];
1364 v13 = 1;
1365 v37 = dword_50B9D8_ys[0];
1366 if ( v10 > 1 )
1367 {
1368 do
1369 {
1370 v14 = dword_50BAC8[v13];
1371 if ( v14 < a2 )
1372 a2 = dword_50BAC8[v13];
1373 if ( v14 > v11 )
1374 v11 = v14;
1375 v15 = dword_50B9D8_ys[v13];
1376 if ( v15 < v37 )
1377 v37 = dword_50B9D8_ys[v13];
1378 if ( v15 > v12 )
1379 v12 = dword_50B9D8_ys[v13];
1380 v10 = v34;
1381 ++v13;
1382 }
1383 while ( v13 < v34 );
1384 }
1385 //v16 = a0;
1386 if (v11 >= p->uViewportX &&
1387 a2 <= p->uViewportZ &&
1388 v12 >= p->uViewportY &&
1389 v37 <= p->uViewportW &&
1390 sub_424829(v10, &field_FA8[std__vector_000FA8].field_C, &p->field_C, uFaceID))
1391 {
1392 //v17 = v39;
1393 v18 = pFace->uSectorID;
1394 if (p->uSectorID == v18 )
1395 v18 = pFace->uBackSectorID;
1396 field_FA8[std__vector_000FA8].uSectorID = v18;
1397 field_FA8[std__vector_000FA8].uFaceID = uFaceID;
1398 field_FA8[std__vector_000FA8].uViewportX = pBLVRenderParams->uViewportX;
1399 field_FA8[std__vector_000FA8].uViewportZ = pBLVRenderParams->uViewportZ;
1400 field_FA8[std__vector_000FA8].uViewportY = pBLVRenderParams->uViewportY;
1401 field_FA8[std__vector_000FA8].uViewportW = pBLVRenderParams->uViewportW;
1402 //v38 = pGame->pStru10Instance;
1403 //a0a = pGame->pIndoorCameraD3D;
1404 if (p->std__vector_0007A8 == -1 )
1405 {
1406 v29 = pGame->pStru10Instance->_49C681_DrawDebugStuff(
1407 pFace,
1408 field_FA8[std__vector_000FA8].std__vector_0007AC,
1409 field_FA8[std__vector_000FA8].pVertices);
1410 }
1411 else
1412 {
1413 static RenderVertexSoft static_subPrepareFaceRenderList_d3d_stru_F7AA08[64];
1414 static RenderVertexSoft static_subPrepareFaceRenderList_d3d_stru_F79E08[64];
1415
1416 //v23 = 0;
1417 a2 = pFace->uNumVertices;
1418 for (uint k = 0; k < pFace->uNumVertices; ++k)
1419 {
1420 //v24 = (char *)&static_subPrepareFaceRenderList_d3d_stru_F7AA08[0].vWorldPosition.z;
1421 //do
1422 //{
1423 //v25 = pFace->pVertexIDs[k];
1424 //v26 = &pIndoor->pVertices[pFace->pVertexIDs[k]];
1425 auto pVertex = &pIndoor->pVertices[pFace->pVertexIDs[k]];
1426 //v27 = (double)v26->z;
1427 //v28 = v26->y;
1428 //v17 = v39;
1429 static_subPrepareFaceRenderList_d3d_stru_F7AA08[k].vWorldPosition.x = pVertex->x;
1430 static_subPrepareFaceRenderList_d3d_stru_F7AA08[k].vWorldPosition.y = pVertex->y;
1431 static_subPrepareFaceRenderList_d3d_stru_F7AA08[k].vWorldPosition.z = pVertex->z;
1432 //v24 += 48;
1433 //}
1434 //while ( v23 < a2 );
1435 }
1436 pGame->pIndoorCameraD3D->_437285_prolly_colide_vertices_against_frustrum(
1437 static_subPrepareFaceRenderList_d3d_stru_F7AA08,
1438 (unsigned int *)&a2,
1439 static_subPrepareFaceRenderList_d3d_stru_F79E08,
1440 p->std__vector_0007AC,
1441 4,
1442 0,
1443 0);
1444 v29 = pGame->pStru10Instance->_49C5DA(
1445 pFace,
1446 static_subPrepareFaceRenderList_d3d_stru_F79E08,
1447 &a2,
1448 field_FA8[std__vector_000FA8].std__vector_0007AC,
1449 field_FA8[std__vector_000FA8].pVertices);
1450 }
1451 if ( v29 )
1452 {
1453 field_FA8[std__vector_000FA8].std__vector_0007A8 = uFaceID;
1454 v30 = std__vector_000FA8;
1455 if ( v30 < 150 )
1456 {
1457 v31 = v30 + 1;
1458 std__vector_000FA8 = v31;
1459 sub_440639(v31 - 1);
1460 }
1461 }
1462 if ( pBLVRenderParams->uFlags & 1 )
1463 pGame->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF);
1464 }
1465 }
1466 }
1467 }
1468 else
1469 {
1470 if (uNumFaceIDs < 1000 )
1471 {
1472 pFaceIDs[2 * uNumFaceIDs] = uFaceID;
1473 pFaceIDs[2 * uNumFaceIDs++ + 1] = a2;
1474 }
1475 }
1476 }
1477
1478
1479 //----- (004AFB86) --------------------------------------------------------
1480 void BspRenderer::PrepareFaceRenderList_sw(int a2, unsigned int uFaceID)
1481 {
1482 BspRenderer *v3; // ebx@1
1483 BLVFace *v4; // eax@1
1484 char *v5; // ecx@2
1485 unsigned __int16 v6; // ax@11
1486 int v7; // ecx@13
1487 Vec3_short_ *v8; // esi@16
1488 int v9; // edx@16
1489 signed int v10; // eax@19
1490 signed int v11; // edi@20
1491 signed int v12; // ecx@20
1492 signed int v13; // esi@20
1493 int v14; // edx@21
1494 int v15; // edx@25
1495 unsigned __int16 v16; // ax@35
1496 signed int v17; // eax@37
1497 int v18; // eax@38
1498 signed int v19; // [sp+Ch] [bp-14h]@19
1499 char *v20; // [sp+14h] [bp-Ch]@2
1500 BLVFace *v21; // [sp+18h] [bp-8h]@1
1501 signed int v22; // [sp+1Ch] [bp-4h]@20
1502 signed int v23; // [sp+28h] [bp+8h]@20
1503
1504 v3 = this;
1505 v4 = &pIndoor->pFaces[uFaceID];
1506 v21 = v4;
1507 if ( v4->uAttributes & 1 )
1508 {
1509 v5 = (char *)this + 2252 * a2;
1510 v20 = v5;
1511 if ( uFaceID == *((short *)v5 + 2982) )
1512 return;
1513 if ( !a2
1514 && pBLVRenderParams->vPartyPos.x >= v4->pBounding.x1 - 16
1515 && pBLVRenderParams->vPartyPos.x <= v4->pBounding.x2 + 16
1516 && pBLVRenderParams->vPartyPos.y >= v4->pBounding.y1 - 16
1517 && pBLVRenderParams->vPartyPos.y <= v4->pBounding.y2 + 16
1518 && pBLVRenderParams->vPartyPos.z >= v4->pBounding.z1 - 16
1519 && pBLVRenderParams->vPartyPos.z <= v4->pBounding.z2 + 16 )
1520 {
1521 if ( abs(v4->pFacePlane_old.dist + pBLVRenderParams->vPartyPos.x * v4->pFacePlane_old.vNormal.x
1522 + pBLVRenderParams->vPartyPos.y * v4->pFacePlane_old.vNormal.y
1523 + pBLVRenderParams->vPartyPos.z * v4->pFacePlane_old.vNormal.z) <= 589824 )
1524 {
1525 v6 = v21->uSectorID;
1526 if ( v3->field_FA8[0].uSectorID == v6 )
1527 v6 = v21->uBackSectorID;
1528 v3->field_FA8[v3->std__vector_000FA8].uSectorID = v6;
1529 v3->field_FA8[v3->std__vector_000FA8].uFaceID = uFaceID;
1530 v3->field_FA8[v3->std__vector_000FA8].uViewportX = LOWORD(pBLVRenderParams->uViewportX);
1531 v3->field_FA8[v3->std__vector_000FA8].uViewportZ = LOWORD(pBLVRenderParams->uViewportZ);
1532 v3->field_FA8[v3->std__vector_000FA8].uViewportY = LOWORD(pBLVRenderParams->uViewportY);
1533 v3->field_FA8[v3->std__vector_000FA8].uViewportW = LOWORD(pBLVRenderParams->uViewportW);
1534 v3->field_FA8[v3->std__vector_000FA8++].field_C._43F9E1(
1535 SLOWORD(pBLVRenderParams->uViewportX),
1536 pBLVRenderParams->uViewportY,
1537 SLOWORD(pBLVRenderParams->uViewportZ),
1538 pBLVRenderParams->uViewportW);
1539 v7 = v3->std__vector_000FA8 - 1;
1540 goto LABEL_14;
1541 }
1542 v4 = v21;
1543 v5 = v20;
1544 }
1545 v8 = &pIndoor->pVertices[*v4->pVertexIDs];
1546 v9 = v4->pFacePlane_old.vNormal.x * ((signed __int16)*(int *)&v8->x - pBLVRenderParams->vPartyPos.x)
1547 + v4->pFacePlane_old.vNormal.y * ((signed __int16)(*(int *)&v8->x >> 16) - pBLVRenderParams->vPartyPos.y)
1548 + v4->pFacePlane_old.vNormal.z * (v8->z - pBLVRenderParams->vPartyPos.z);
1549 if ( *((short *)v5 + 2004) != v4->uSectorID )
1550 v9 = -v9;
1551 if ( v9 < 0 )
1552 {
1553 v10 = sub_423B5D(uFaceID);
1554 v19 = v10;
1555 if ( v10 )
1556 {
1557 v11 = dword_50BAC8[0];
1558 v12 = dword_50B9D8_ys[0];
1559 v23 = dword_50BAC8[0];
1560 v13 = 1;
1561 v22 = dword_50B9D8_ys[0];
1562 if ( v10 > 1 )
1563 {
1564 do
1565 {
1566 v14 = dword_50BAC8[v13];
1567 if ( v14 < v23 )
1568 v23 = dword_50BAC8[v13];
1569 if ( v14 > v11 )
1570 v11 = dword_50BAC8[v13];
1571 v15 = dword_50B9D8_ys[v13];
1572 if ( v15 < v22 )
1573 v22 = dword_50B9D8_ys[v13];
1574 if ( v15 > v12 )
1575 v12 = dword_50B9D8_ys[v13];
1576 v10 = v19;
1577 ++v13;
1578 }
1579 while ( v13 < v19 );
1580 }
1581 if ( v11 >= *((short *)v20 + 2005)
1582 && v23 <= *((short *)v20 + 2007)
1583 && v12 >= *((short *)v20 + 2006)
1584 && v22 <= *((short *)v20 + 2008)
1585 && sub_424829(v10, &v3->field_FA8[v3->std__vector_000FA8].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) )
1586 {
1587 v16 = v21->uSectorID;
1588 if ( *((short *)v20 + 2004) == v16 )
1589 v16 = v21->uBackSectorID;
1590 v3->field_FA8[v3->std__vector_000FA8].uSectorID = v16;
1591 v3->field_FA8[v3->std__vector_000FA8].uFaceID = uFaceID;
1592 v3->field_FA8[v3->std__vector_000FA8].uViewportX = LOWORD(pBLVRenderParams->uViewportX);
1593 v3->field_FA8[v3->std__vector_000FA8].uViewportZ = LOWORD(pBLVRenderParams->uViewportZ);
1594 v3->field_FA8[v3->std__vector_000FA8].uViewportY = LOWORD(pBLVRenderParams->uViewportY);
1595 v3->field_FA8[v3->std__vector_000FA8].uViewportW = LOWORD(pBLVRenderParams->uViewportW);
1596 v17 = v3->std__vector_000FA8;
1597 if ( v17 < 150 )
1598 {
1599 v18 = v17 + 1;
1600 v3->std__vector_000FA8 = v18;
1601 v7 = v18 - 1;
1602 LABEL_14:
1603 sub_440639(v7);
1604 return;
1605 }
1606 }
1607 }
1608 }
1609 }
1610 else
1611 {
1612 if ( (signed int)this->uNumFaceIDs < 1000 )
1613 {
1614 this->pFaceIDs[2 * this->uNumFaceIDs] = uFaceID;
1615 this->pFaceIDs[2 * this->uNumFaceIDs++ + 1] = a2;
1616 }
1617 }
1618 }
1619
1620 //----- (004B0967) --------------------------------------------------------
1621 void __cdecl stru170_sub_4B0967()
1622 {
1623 signed int i; // edi@1
1624 int v1; // esi@2
1625 unsigned int v2; // ecx@4
1626 int v3; // eax@4
1627 int v4; // eax@6
1628 unsigned __int16 *v5; // edx@6
1629 int v6; // ecx@7
1630 int v7; // esi@8
1631
1632 for ( i = 0; i < (signed int)pBspRenderer->uNumFaceIDs; ++i )
1633 {
1634 v1 = pBspRenderer->pFaceIDs[2 * i];
1635 if ( v1 >= 0 )
1636 {
1637 if ( v1 < (signed int)pIndoor->uNumFaces )
1638 {
1639 v2 = pBspRenderer->pFaceIDs[2 * i];
1640 pBLVRenderParams->field_7C = &pBspRenderer->field_FA8[pBspRenderer->pFaceIDs[2 * i + 1]].field_C;
1641 v3 = sub_423B5D(v2);
1642 if ( v3 )
1643 {
1644 if ( sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1) )
1645 {
1646 v4 = stru_F8A590._viewport_space_y;
1647 v5 = pBLVRenderParams->pRenderTarget;
1648 if ( stru_F8A590._viewport_space_y <= stru_F8A590._viewport_space_w )
1649 {
1650 v6 = 640 * stru_F8A590._viewport_space_y;
1651 do
1652 {
1653 v5[v6 + stru_F8A590.array_18[v4]] = -1;
1654 v7 = v6 + stru_F8A590.array_3D8[v4];
1655 v6 += 640;
1656 v5[v7] = -1;
1657 ++v4;
1658 }
1659 while ( v4 <= stru_F8A590._viewport_space_w );
1660 }
1661 }
1662 }
1663 }
1664 }
1665 }
1666 }
1667
1668
1669 //----- (004AE5BA) --------------------------------------------------------
1670 Texture *BLVFace::GetTexture()
1671 {
1672 unsigned int v1; // ecx@2
1673
1674 if ( uAttributes & 0x4000 )
1675 v1 = pTextureFrameTable->GetFrameTexture(this->uBitmapID, pBLVRenderParams->field_0_timer_);
1676 else
1677 v1 = uBitmapID;
1678 return (Texture *)(v1 != -1 ? (int)&pBitmaps_LOD->pTextures[v1] : 0);
1679 }
1680
1681
1682 //----- (00498B15) --------------------------------------------------------
1683 void IndoorLocation::Release()
1684 {
1685 IndoorLocation *v1; // esi@1
1686 char *v2; // ebp@1
1687 void *v3; // ST00_4@1
1688
1689 v1 = this;
1690 v2 = (char *)&this->ptr_0002B4_doors_ddata;
1691 pAllocator->FreeChunk(this->ptr_0002B4_doors_ddata);
1692 *(int *)v2 = 0;
1693 pAllocator->FreeChunk(v1->ptr_0002B0_sector_rdata);
1694 v1->ptr_0002B0_sector_rdata = 0;
1695 pAllocator->FreeChunk(v1->ptr_0002B8_sector_lrdata);
1696 v1->ptr_0002B8_sector_lrdata = 0;
1697 pAllocator->FreeChunk(v1->ptr_2AC);
1698 v1->ptr_2AC = 0;
1699 pAllocator->FreeChunk(v1->pSpawnPoints);
1700 v3 = v1->pVertices;
1701 v1->pSpawnPoints = 0;
1702 v1->uNumSectors = 0;
1703 v1->uNumFaces = 0;
1704 v1->uNumVertices = 0;
1705 v1->uNumNodes = 0;
1706 v1->uNumDoors = 0;
1707 v1->uNumLights = 0;
1708 pAllocator->FreeChunk(v3);
1709 pAllocator->FreeChunk(v1->pFaces);
1710 pAllocator->FreeChunk(v1->pFaceExtras);
1711 pAllocator->FreeChunk(v1->pSectors);
1712 pAllocator->FreeChunk(v1->pLights);
1713 pAllocator->FreeChunk(v1->pDoors);
1714 pAllocator->FreeChunk(v1->pNodes);
1715 pAllocator->FreeChunk(v1->pMapOutlines);
1716 v1->pVertices = 0;
1717 v1->pFaces = 0;
1718 v1->pFaceExtras = 0;
1719 v1->pSectors = 0;
1720 v1->pLights = 0;
1721 v1->pDoors = 0;
1722 v1->pNodes = 0;
1723 v1->pMapOutlines = 0;
1724 v1->bLoaded = 0;
1725 }
1726
1727 //----- (00498C45) --------------------------------------------------------
1728 int IndoorLocation::Alloc()
1729 {
1730 IndoorLocation *v1; // esi@1
1731 void *v2; // eax@1
1732 const void *v3; // ST3C_4@1
1733 void *v4; // eax@1
1734 const void *v5; // ST3C_4@1
1735 void *v6; // eax@1
1736 const void *v7; // ST3C_4@1
1737 void *v8; // eax@1
1738 const void *v9; // ST3C_4@1
1739 void *v10; // eax@1
1740 const void *v11; // ST3C_4@1
1741 void *v12; // eax@1
1742 const void *v13; // ST3C_4@1
1743 void *v14; // eax@1
1744 const void *v15; // ST3C_4@1
1745 void *v16; // eax@1
1746 void *v17; // ecx@1
1747 signed int result; // eax@9
1748
1749 v1 = this;
1750 v2 = pAllocator->AllocNamedChunk(this->pVertices, 0x15F90u, "L.V");
1751 v3 = v1->pFaces;
1752 v1->pVertices = (Vec3_short_ *)v2;
1753 v4 = pAllocator->AllocNamedChunk(v3, 0xEA600u, "L.F");
1754 v5 = v1->pFaceExtras;
1755 v1->pFaces = (BLVFace *)v4;
1756 v6 = pAllocator->AllocNamedChunk(v5, 0x2BF20u, "L.FX");
1757 v7 = v1->pSectors;
1758 v1->pFaceExtras = (BLVFaceExtra *)v6;
1759 v8 = pAllocator->AllocNamedChunk(v7, 0xE800u, "L.R");
1760 v9 = v1->pLights;
1761 v1->pSectors = (BLVSector *)v8;
1762 v10 = pAllocator->AllocNamedChunk(v9, 0x1900u, "L.L");
1763 v11 = v1->pDoors;
1764 v1->pLights = (BLVLightMM7 *)v10;
1765 v12 = pAllocator->AllocNamedChunk(v11, 0x3E80u, "L.D");
1766 v13 = v1->pNodes;
1767 v1->pDoors = (BLVDoor *)v12;
1768 v14 = pAllocator->AllocNamedChunk(v13, 0x9C40u, "L.BSP");
1769 v15 = v1->pMapOutlines;
1770 v1->pNodes = (BSPNode *)v14;
1771 v16 = pAllocator->AllocNamedChunk(v15, 0x14824u, "L.Map");
1772 v17 = v1->pVertices;
1773 v1->pMapOutlines = (BLVMapOutlines *)v16;
1774 if ( v17 && v1->pFaces && v1->pFaceExtras && v1->pSectors && v1->pLights && v1->pDoors && v1->pNodes && v16 )
1775 {
1776 memset(v17, 90000, 0);
1777 memset(v1->pFaces, 960000, 0);
1778 memset(v1->pFaceExtras, 180000, 0);
1779 memset(v1->pSectors, 59392, 0);
1780 memset(v1->pLights, 6400, 0);
1781 memset(v1->pDoors, 16000, 0);
1782 memset(v1->pNodes, 40000, 0);
1783 memset(v1->pMapOutlines, 84004, 0);
1784 result = 1;
1785 }
1786 else
1787 {
1788 result = 0;
1789 }
1790 return result;
1791 }
1792
1793
1794
1795 //----- (00444810) --------------------------------------------------------
1796 unsigned int IndoorLocation::GetLocationIndex(const char *Str1)
1797 {
1798 const char *v1; // edi@1
1799 signed int v2; // esi@1
1800
1801 v1 = Str1;
1802 v2 = 0;
1803 while ( _strcmpi(v1, _4E6BDC_loc_names[v2]) )
1804 {
1805 ++v2;
1806 if ( v2 >= 11 )
1807 return 0;
1808 }
1809 return v2 + 1;
1810 }
1811
1812
1813
1814 //----- (004488F7) --------------------------------------------------------
1815 void IndoorLocation::ToggleLight(unsigned int uLightID, unsigned int bToggle)
1816 {
1817 char *v2; // eax@4
1818
1819 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && (signed int)uLightID <= pIndoor->uNumLights - 1 && (uLightID & 0x80000000u) == 0 )
1820 {
1821 v2 = (char *)&pIndoor->pLights[uLightID].uAtributes;
1822 if ( bToggle )
1823 *v2 &= 0xF7u;
1824 else
1825 *v2 |= 8u;
1826 pParty->uFlags |= 2u;
1827 }
1828 }
1829
1830
1831 //----- (00498E0A) --------------------------------------------------------
1832 bool IndoorLocation::Load(char *pFilename, int a3, size_t _i, char *pDest)
1833 {
1834 /*unsigned int v5; // ebx@1
1835 //IndoorLocation *v6; // esi@1
1836 FILE *v7; // edi@3
1837 bool result; // eax@3
1838 char *v9; // ecx@4
1839 void *v10; // eax@4
1840 //unsigned __int8 v11; // zf@4
1841 //unsigned __int8 v12; // sf@4
1842 int v13; // eax@5
1843 size_t v14; // ecx@6
1844 char *v15; // ecx@6
1845 int v16; // edx@6
1846 size_t v17; // ecx@6
1847 char *v18; // ecx@6
1848 int v19; // edx@6
1849 unsigned __int16 *v20; // edx@6
1850 unsigned __int16 *v21; // edx@6
1851 unsigned __int16 *v22; // edx@6
1852 __int16 v23; // ax@10
1853 char *v24; // ecx@10
1854 __int16 v25; // cx@10
1855 __int16 v26; // ax@11
1856 char *v27; // ecx@11
1857 unsigned __int16 v28; // ax@17
1858 BLVFaceExtra *v29; // ecx@17
1859 char *v30; // edx@17
1860 int v31; // ecx@20
1861 void *v32; // eax@25
1862 int v33; // eax@26
1863 unsigned __int16 *v34; // edx@27
1864 size_t v35; // ecx@27
1865 char *v36; // ecx@27
1866 int v37; // edx@27
1867 size_t v38; // ecx@27
1868 char *v39; // ecx@27
1869 int v40; // edx@27
1870 unsigned __int16 *v41; // edx@27
1871 unsigned __int16 *v42; // edx@27
1872 unsigned __int16 *v43; // edx@27
1873 unsigned __int16 *v44; // edx@27
1874 size_t v45; // ecx@27
1875 unsigned __int16 *v46; // edx@27
1876 void *v47; // eax@28
1877 BLVSector *v48; // eax@29
1878 size_t v49; // ecx@29
1879 unsigned __int16 *v50; // edx@31
1880 void *v51; // eax@32
1881 int v52; // eax@33
1882 unsigned __int16 *v53; // edx@34
1883 size_t v54; // ecx@34
1884 char *v55; // ecx@34
1885 int v56; // edx@34
1886 size_t v57; // ecx@34
1887 char *v58; // ecx@34
1888 int v59; // edx@34
1889 unsigned __int16 *v60; // edx@34
1890 unsigned __int16 *v61; // edx@34
1891 unsigned __int16 *v62; // edx@34
1892 unsigned __int16 *v63; // edx@34
1893 int v64; // ecx@34
1894 BLVDoor *v65; // ecx@36
1895 char *v66; // eax@37
1896 int v67; // edx@38
1897 int v68; // ecx@38
1898 BLVFace *v69; // edx@38
1899 int v70; // ecx@38
1900 int v71; // edx@38
1901 int v72; // eax@38
1902 unsigned __int16 v73; // ax@42
1903 char *v74; // ecx@42
1904 LayingItem *v75; // ecx@44
1905 size_t v76; // eax@45
1906 int j; // edx@46
1907 unsigned __int16 v78; // ax@50
1908 void *v79; // eax@52
1909 void **v80; // esi@52
1910 unsigned int v145; // eax@103
1911 void *v146; // eax@103
1912 unsigned int v147; // ecx@103
1913 int v148; // ebx@103
1914 unsigned int *v149; // ecx@103*/
1915 //size_t v150; // eax@103
1916 //unsigned int v151; // ebx@109
1917 //unsigned int v152; // ecx@116
1918 //unsigned int v153; // eax@117
1919 //size_t v154; // ebx@126
1920 //unsigned int v155; // ebx@134
1921 //size_t v156; // eax@140
1922 //signed int v157; // ebx@142
1923 //int v158; // ebx@148
1924 //BLVFace *v159; // eax@149
1925 // BLVFaceExtra *v160; // ecx@149
1926 //BLVFaceExtra *v161; // ecx@149
1927 //signed int v162; // ebx@154
1928 //unsigned int v163; // ebx@157
1929 //unsigned int v164; // ebx@157
1930 //unsigned int v165; // edx@158
1931 //char *v166; // ecx@158
1932 //unsigned __int16 v167; // ax@161
1933 //__int16 v168; // ax@165
1934 //unsigned int v169; // ebx@168
1935 //void *v170; // eax@168
1936 //size_t v171; // ebx@168
1937 //int v172; // edx@168
1938 //BLVDoor *v173; // ecx@169
1939 //int k; // eax@169
1940 //BLVDoor *v175; // ecx@172
1941 //int v176; // edx@172
1942 //BLVDoor *v177; // ecx@172
1943 //int v178; // edx@172
1944 //BLVDoor *v179; // ecx@172
1945 //int v180; // edx@172
1946 //BLVDoor *v181; // ecx@172
1947 //int v182; // edx@172
1948 //BLVDoor *v183; // ecx@172
1949 //int v184; // edx@172
1950 //BLVDoor *v185; // ecx@172
1951 //int v186; // edx@172
1952 //BLVDoor *v187; // ecx@172
1953 //int v188; // edx@172
1954 //unsigned __int16 *v189; // ebx@172
1955 //char *v190; // edx@173
1956 //BLVDoor *v191; // ecx@174
1957 //BLVDoor *l; // eax@175
1958 //signed int v193; // ebx@176
1959 //int v194; // ecx@176
1960 //BLVFaceExtra *v195; // ecx@176
1961 //BLVFace *v196; // ebx@178
1962 //std::string v197; // [sp-18h] [bp-680h]@66
1963 //void *v198; // [sp-14h] [bp-67Ch]@72
1964 //size_t v199; // [sp-10h] [bp-678h]@72
1965 //size_t v200; // [sp-Ch] [bp-674h]@72
1966 //const char *v201; // [sp-8h] [bp-670h]@4
1967 //int v202; // [sp-4h] [bp-66Ch]@4
1968 char v203[875]; // [sp+Ch] [bp-65Ch]@130
1969 char FileName[260]; // [sp+378h] [bp-2F0h]@1
1970 //char DstBuf; // [sp+47Ch] [bp-1ECh]@4
1971 __int32 Offset; // [sp+480h] [bp-1E8h]@4
1972 __int32 v207; // [sp+48Ch] [bp-1DCh]@4
1973 __int32 v208; // [sp+498h] [bp-1D0h]@4
1974 __int32 v209; // [sp+4A4h] [bp-1C4h]@4
1975 __int32 v210; // [sp+4B0h] [bp-1B8h]@4
1976 __int32 v211; // [sp+4BCh] [bp-1ACh]@15
1977 __int32 v212; // [sp+4C8h] [bp-1A0h]@15
1978 __int32 v213; // [sp+4D4h] [bp-194h]@25
1979 __int32 v214; // [sp+4E0h] [bp-188h]@25
1980 __int32 v215; // [sp+4ECh] [bp-17Ch]@32
1981 __int32 v216; // [sp+4F8h] [bp-170h]@32
1982 __int32 v217; // [sp+504h] [bp-164h]@40
1983 __int32 v218; // [sp+510h] [bp-158h]@40
1984 __int32 v219; // [sp+51Ch] [bp-14Ch]@43
1985 __int32 v220; // [sp+528h] [bp-140h]@43
1986 __int32 v221; // [sp+534h] [bp-134h]@52
1987 __int32 v222; // [sp+540h] [bp-128h]@52
1988 __int32 v223; // [sp+54Ch] [bp-11Ch]@52
1989 __int32 v224; // [sp+558h] [bp-110h]@52
1990 __int32 v225; // [sp+564h] [bp-104h]@52
1991 __int32 v226; // [sp+570h] [bp-F8h]@52
1992 __int32 v227; // [sp+57Ch] [bp-ECh]@52
1993 __int32 v228; // [sp+588h] [bp-E0h]@52
1994 __int32 v229; // [sp+594h] [bp-D4h]@52
1995 __int32 v230; // [sp+5A0h] [bp-C8h]@52
1996 __int32 v231; // [sp+5ACh] [bp-BCh]@52
1997 __int32 v232; // [sp+5B8h] [bp-B0h]@52
1998 __int32 v233; // [sp+5C4h] [bp-A4h]@52
1999 __int32 v234; // [sp+5D0h] [bp-98h]@52
2000 //char pName[40]; // [sp+5FCh] [bp-6Ch]@42
2001 //size_t pSource; // [sp+624h] [bp-44h]@67
2002 //char Dst[12]; // [sp+628h] [bp-40h]@9
2003 //char *v238; // [sp+634h] [bp-34h]@38
2004 ODMHeader header; // [sp+638h] [bp-30h]@61
2005 //void *ptr; // [sp+648h] [bp-20h]@66
2006 //size_t Count; // [sp+64Ch] [bp-1Ch]@109
2007 //int uSourceLen; // [sp+653h] [bp-15h]@66
2008 FILE *File; // [sp+658h] [bp-10h]@56
2009 //BLVSector *v244; // [sp+65Ch] [bp-Ch]@72
2010 //int v245; // [sp+660h] [bp-8h]@72
2011 //BLVFace *Src; // [sp+664h] [bp-4h]@73
2012 signed int Argsa; // [sp+670h] [bp+8h]@4
2013 signed int Argsb; // [sp+670h] [bp+8h]@7
2014 signed int Argsc; // [sp+670h] [bp+8h]@15
2015 signed int Argsd; // [sp+670h] [bp+8h]@18
2016 int Argse; // [sp+670h] [bp+8h]@25
2017 int Argsf; // [sp+670h] [bp+8h]@28
2018 int Argsg; // [sp+670h] [bp+8h]@32
2019 int Argsh; // [sp+670h] [bp+8h]@35
2020 signed int Argsi; // [sp+670h] [bp+8h]@40
2021 signed int Argsj; // [sp+670h] [bp+8h]@45
2022 //int Argsk; // [sp+670h] [bp+8h]@143
2023 //void *Argsl; // [sp+670h] [bp+8h]@155
2024 //signed int Argsm; // [sp+670h] [bp+8h]@161
2025 //signed int Argsn; // [sp+670h] [bp+8h]@175
2026
2027 //v5 = 0;
2028 //v6 = this;
2029 _6807E0_num_decorations_with_sounds_6807B8 = 0;
2030
2031 #pragma region "loading from txt"
2032 /*sprintf(FileName, "levels\\%s", pFilename);
2033 if ( GetFileAttributesA(FileName) != -1 )
2034 {
2035 Release();
2036 if ( Alloc() )
2037 {
2038 v7 = fopen(FileName, "rb");
2039 result = 1;
2040 if ( !v7 )
2041 return result;
2042 v9 = pDest;
2043 bLoaded = 1;
2044 v202 = (int)v7;
2045 v201 = (const char *)1;
2046 *(int *)v9 = 1;
2047 fread(&DstBuf, 0x180u, (size_t)v201, (FILE *)v202);
2048 fseek(v7, Offset, 0);
2049 fread(&blv, 0x88u, 1u, v7);
2050 fseek(v7, v207, 0);
2051 fread(&uNumVertices, 1u, 4u, v7);
2052 fseek(v7, v208, 0);
2053 fread(pVertices, 6u, uNumVertices, v7);
2054 fseek(v7, v209, 0);
2055 fread(&uNumFaces, 4u, 1u, v7);
2056 fseek(v7, v210, 0);
2057 fread(pFaces, 0x60u, uNumFaces, v7);
2058 v10 = pAllocator->AllocNamedChunk(ptr_2AC, blv.uFaces_fdata_Size, "L.FData");
2059 v202 = (int)v7;
2060 ptr_2AC = (unsigned __int16 *)v10;
2061 fread(v10, 1u, blv.uFaces_fdata_Size, (FILE *)v202);
2062 v11 = uNumFaces == 0;
2063 v12 = (uNumFaces & 0x80000000u) != 0;
2064 pDest = 0;
2065 Argsa = 0;
2066 if ( !(v12 | v11) )
2067 {
2068 v13 = 0;
2069 do
2070 {
2071 pFaces[v13].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)ptr_2AC];
2072 v14 = (size_t)&pFaces[v13];
2073 i = v14;
2074 v15 = &pDest[2 * *(char *)(v14 + 93) + 2];
2075 v16 = (int)&v15[(unsigned int)ptr_2AC];
2076 pDest = v15;
2077 *(int *)(i + 52) = v16;
2078 v17 = (size_t)&pFaces[v13];
2079 i = v17;
2080 v18 = &pDest[2 * *(char *)(v17 + 93) + 2];
2081 v19 = (int)&v18[(unsigned int)ptr_2AC];
2082 pDest = v18;
2083 *(int *)(i + 56) = v19;
2084 i = (size_t)&pFaces[v13];
2085 v20 = ptr_2AC;
2086 pDest += 2 * *(char *)(i + 93) + 2;
2087 *(int *)(i + 60) = (int)(char *)v20 + (int)pDest;
2088 i = (size_t)&pFaces[v13];
2089 v21 = ptr_2AC;
2090 pDest += 2 * *(char *)(i + 93) + 2;
2091 *(int *)(i + 64) = (int)(char *)v21 + (int)pDest;
2092 i = (size_t)&pFaces[v13];
2093 ++v13;
2094 v22 = ptr_2AC;
2095 pDest += 2 * *(char *)(i + 93) + 2;
2096 ++Argsa;
2097 *(int *)(i + 68) = (int)(char *)v22 + (int)pDest;
2098 pDest += 2 * *((char *)&pFaces[v13] - 3) + 2;
2099 }
2100 while ( Argsa < (signed int)uNumFaces );
2101 }
2102 Argsb = 0;
2103 if ( (signed int)uNumFaces > 0 )
2104 {
2105 pDest = 0;
2106 do
2107 {
2108 fread(Dst, 1u, 0xAu, v7);
2109 if ( pDest[(unsigned int)pFaces + 45] & 0x40 )
2110 {
2111 v23 = pTextureFrameTable->FindTextureByName(Dst);
2112 v24 = pDest;
2113 *(short *)&pDest[(unsigned int)pFaces + 74] = v23;
2114 v25 = *(short *)&v24[(unsigned int)pFaces + 74];
2115 if ( v25 )
2116 {
2117 pTextureFrameTable->LoadAnimationSequenceAndPalettes(v25);
2118 }
2119 else
2120 {
2121 v26 = pBitmaps_LOD->LoadTexture(Dst);
2122 v27 = pDest;
2123 *(short *)&pDest[(unsigned int)pFaces + 74] = v26;
2124 v27[(unsigned int)pFaces + 45] &= 0xBFu;
2125 }
2126 }
2127 else
2128 {
2129 *(short *)&pDest[(unsigned int)pFaces + 74] = pBitmaps_LOD->LoadTexture(Dst);
2130 }
2131 ++Argsb;
2132 pDest += 96;
2133 }
2134 while ( Argsb < (signed int)uNumFaces );
2135 }
2136 fseek(v7, v211, 0);
2137 fread(&uNumFaceExtras, 4u, 1u, v7);
2138 fseek(v7, v212, 0);
2139 fread(pFaceExtras, 0x24u, uNumFaceExtras, v7);
2140 Argsc = 0;
2141 if ( (signed int)uNumFaceExtras > 0 )
2142 {
2143 pDest = 0;
2144 do
2145 {
2146 fread(Dst, 1u, 0xAu, v7);
2147 v28 = pBitmaps_LOD->LoadTexture(Dst);
2148 v29 = pFaceExtras;
2149 v30 = pDest;
2150 ++Argsc;
2151 pDest += 36;
2152 *(unsigned __int16 *)((char *)&v29->uAdditionalBitmapID + (int)v30) = v28;
2153 }
2154 while ( Argsc < (signed int)uNumFaceExtras );
2155 }
2156 Argsd = 0;
2157 if ( (signed int)uNumFaces > 0 )
2158 {
2159 pDest = 0;
2160 do
2161 {
2162 v31 = (int)&pFaceExtras[*(short *)&pDest[(unsigned int)pFaces + 72]];
2163 if ( *(short *)(v31 + 26) )
2164 {
2165 if ( ((BLVFaceExtra *)v31)->HasEventint() )
2166 pDest[(unsigned int)pFaces + 46] |= 0x10u;
2167 else
2168 pDest[(unsigned int)pFaces + 46] &= 0xEFu;
2169 }
2170 ++Argsd;
2171 pDest += 96;
2172 }
2173 while ( Argsd < (signed int)uNumFaces );
2174 }
2175 fseek(v7, v213, 0);
2176 fread(&uNumSectors, 4u, 1u, v7);
2177 fseek(v7, v214, 0);
2178 fread(pSectors, 0x74u, uNumSectors, v7);
2179 v32 = pAllocator->AllocNamedChunk(ptr_0002B0_sector_rdata, blv.uSector_rdata_Size, "L.RData");
2180 v202 = (int)v7;
2181 ptr_0002B0_sector_rdata = (unsigned __int16 *)v32;
2182 fread(v32, 1u, blv.uSector_rdata_Size, (FILE *)v202);
2183 v11 = uNumSectors == 0;
2184 v12 = uNumSectors < 0;
2185 pDest = 0;
2186 Argse = 0;
2187 if ( !(v12 | v11) )
2188 {
2189 v33 = 0;
2190 do
2191 {
2192 pSectors[v33].pFloors = (unsigned __int16 *)&pDest[(unsigned int)ptr_0002B0_sector_rdata];
2193 i = (size_t)&pSectors[v33];
2194 v34 = ptr_0002B0_sector_rdata;
2195 pDest += 2 * *(short *)(i + 4);
2196 *(int *)(i + 16) = (int)(char *)v34 + (int)pDest;
2197 v35 = (size_t)&pSectors[v33];
2198 i = v35;
2199 v36 = &pDest[2 * *(short *)(v35 + 12)];
2200 v37 = (int)&v36[(unsigned int)ptr_0002B0_sector_rdata];
2201 pDest = v36;
2202 *(int *)(i + 24) = v37;
2203 v38 = (size_t)&pSectors[v33];
2204 i = v38;
2205 v39 = &pDest[2 * *(short *)(v38 + 20)];
2206 v40 = (int)&v39[(unsigned int)ptr_0002B0_sector_rdata];
2207 pDest = v39;
2208 *(int *)(i + 32) = v40;
2209 i = (size_t)&pSectors[v33];
2210 v41 = ptr_0002B0_sector_rdata;
2211 pDest += 2 * *(short *)(i + 28);
2212 *(int *)(i + 40) = (int)(char *)v41 + (int)pDest;
2213 i = (size_t)&pSectors[v33];
2214 v42 = ptr_0002B0_sector_rdata;
2215 pDest += 2 * *(short *)(i + 36);
2216 *(int *)(i + 48) = (int)(char *)v42 + (int)pDest;
2217 i = (size_t)&pSectors[v33];
2218 v43 = ptr_0002B0_sector_rdata;
2219 pDest += 2 * *(short *)(i + 44);
2220 *(int *)(i + 64) = (int)(char *)v43 + (int)pDest;
2221 i = (size_t)&pSectors[v33];
2222 v44 = ptr_0002B0_sector_rdata;
2223 pDest += 2 * *(short *)(i + 60);
2224 *(int *)(i + 72) = (int)(char *)v44 + (int)pDest;
2225 v45 = (size_t)&pSectors[v33];
2226 ++v33;
2227 i = v45;
2228 v46 = ptr_0002B0_sector_rdata;
2229 pDest += 2 * *(short *)(v45 + 68);
2230 ++Argse;
2231 *(int *)(v45 + 80) = (int)(char *)v46 + (int)pDest;
2232 pDest += 2 * *((short *)&pSectors[v33] - 20);
2233 }
2234 while ( Argse < uNumSectors );
2235 }
2236 v47 = pAllocator->AllocNamedChunk(
2237 ptr_0002B8_sector_lrdata,
2238 blv.uSector_lrdata_Size,
2239 "L.RLData");
2240 v202 = (int)v7;
2241 ptr_0002B8_sector_lrdata = (unsigned __int16 *)v47;
2242 fread(v47, 1u, blv.uSector_lrdata_Size, (FILE *)v202);
2243 v11 = uNumSectors == 0;
2244 v12 = uNumSectors < 0;
2245 pDest = 0;
2246 Argsf = 0;
2247 if ( !(v12 | v11) )
2248 {
2249 v48 = pSectors;
2250 v49 = 0;
2251 for ( i = 0; ; v49 = i )
2252 {
2253 v50 = ptr_0002B8_sector_lrdata;
2254 i += 116;
2255 ++Argsf;
2256 *(BLVLightMM7 **)((char *)&v48->pLights + v49) = (BLVLightMM7 *)((char *)v50 + (int)pDest);
2257 v48 = pSectors;
2258 pDest += 2 * *(__int16 *)((char *)&v48->uNumLights + v49);
2259 if ( Argsf >= uNumSectors )
2260 break;
2261 }
2262 }
2263 fseek(v7, v215, 0);
2264 fread(&uNumDoors, 4u, 1u, v7);
2265 fseek(v7, v216, 0);
2266 fread(pDoors, 0x50u, 0xC8u, v7);
2267 v51 = pAllocator->AllocNamedChunk(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
2268 v202 = (int)v7;
2269 ptr_0002B4_doors_ddata = (unsigned __int16 *)v51;
2270 fread(v51, 1u, blv.uDoors_ddata_Size, (FILE *)v202);
2271 v11 = uNumDoors == 0;
2272 v12 = uNumDoors < 0;
2273 pDest = 0;
2274 Argsg = 0;
2275 if ( !(v12 | v11) )
2276 {
2277 v52 = 0;
2278 do
2279 {
2280 pDoors[v52].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)ptr_0002B4_doors_ddata];
2281 i = (size_t)&pDoors[v52];
2282 v53 = ptr_0002B4_doors_ddata;
2283 pDest += 2 * *(short *)(i + 68);
2284 *(int *)(i + 40) = (int)(char *)v53 + (int)pDest;
2285 v54 = (size_t)&pDoors[v52];
2286 i = v54;
2287 v55 = &pDest[2 * *(short *)(v54 + 70)];
2288 v56 = (int)&v55[(unsigned int)ptr_0002B4_doors_ddata];
2289 pDest = v55;
2290 *(int *)(i + 44) = v56;
2291 v57 = (size_t)&pDoors[v52];
2292 i = v57;
2293 v58 = &pDest[2 * *(short *)(v57 + 72)];
2294 v59 = (int)&v58[(unsigned int)ptr_0002B4_doors_ddata];
2295 pDest = v58;
2296 *(int *)(i + 48) = v59;
2297 i = (size_t)&pDoors[v52];
2298 v60 = ptr_0002B4_doors_ddata;
2299 pDest += 2 * *(short *)(i + 70);
2300 *(int *)(i + 52) = (int)(char *)v60 + (int)pDest;
2301 i = (size_t)&pDoors[v52];
2302 v61 = ptr_0002B4_doors_ddata;
2303 pDest += 2 * *(short *)(i + 70);
2304 *(int *)(i + 56) = (int)(char *)v61 + (int)pDest;
2305 i = (size_t)&pDoors[v52];
2306 v62 = ptr_0002B4_doors_ddata;
2307 pDest += 2 * *(short *)(i + 74);
2308 *(int *)(i + 60) = (int)(char *)v62 + (int)pDest;
2309 i = (size_t)&pDoors[v52];
2310 v63 = ptr_0002B4_doors_ddata;
2311 pDest += 2 * *(short *)(i + 74);
2312 *(int *)(i + 64) = (int)(char *)v63 + (int)pDest;
2313 ++Argsg;
2314 v64 = pDoors[v52].uNumOffsets;
2315 ++v52;
2316 pDest += 2 * v64;
2317 }
2318 while ( Argsg < uNumDoors );
2319 }
2320 Argsh = 0;
2321 if ( uNumDoors > 0 )
2322 {
2323 v65 = pDoors;
2324 pDest = 0;
2325 do
2326 {
2327 i = 0;
2328 v66 = &pDest[(int)v65];
2329 if ( *(short *)&pDest[(int)v65 + 70] > 0 )
2330 {
2331 do
2332 {
2333 v67 = *((int *)v66 + 10);
2334 a3 = 2 * i;
2335 v68 = *(short *)(v67 + 2 * i);
2336 v69 = pFaces;
2337 ++i;
2338 v70 = (int)&pFaceExtras[v69[v68].uFaceExtraID];
2339 v71 = *((int *)v66 + 12);
2340 v72 = a3;
2341 v238 = (char *)v70;
2342 *(short *)(a3 + v71) = *(short *)(v70 + 20);
2343 *(__int16 *)(*(char **)((char *)&pDoors->pDeltaVs + (unsigned int)pDest) + v72) = *((short *)v238 + 11);
2344 v65 = pDoors;
2345 v66 = &pDest[(int)v65];
2346 }
2347 while ( (signed int)i < *(short *)&pDest[(int)v65 + 70] );
2348 }
2349 ++Argsh;
2350 pDest += 80;
2351 }
2352 while ( Argsh < uNumDoors );
2353 }
2354 fseek(v7, v217, 0);
2355 fread(&uNumLevelDecorations, 4u, 1u, v7);
2356 fseek(v7, v218, 0);
2357 fread(pLevelDecorations, 0x20u, uNumLevelDecorations, v7);
2358 Argsi = 0;
2359 if ( (signed int)uNumLevelDecorations > 0 )
2360 {
2361 pDest = (char *)pLevelDecorations;
2362 do
2363 {
2364 fread(pName, 1u, 0x20u, v7);
2365 v73 = pDecorationList->GetDecorIdByName(pName);
2366 v74 = pDest;
2367 ++Argsi;
2368 pDest += 32;
2369 *(short *)v74 = v73;
2370 }
2371 while ( Argsi < (signed int)uNumLevelDecorations );
2372 }
2373 fseek(v7, v219, 0);
2374 fread(&uNumLayingItems, 4u, 1u, v7);
2375 fseek(v7, v220, 0);
2376 fread(pLayingItems, 0x70u, uNumLayingItems, v7);
2377 if ( (signed int)uNumLayingItems > 0 )
2378 {
2379 v75 = pLayingItems;
2380 pDest = (char *)uNumLayingItems;
2381 do
2382 {
2383 Argsj = 0;
2384 v76 = 48 * v75->stru_24.uItemID;
2385 v11 = pObjectList->uNumObjects == 0;
2386 v12 = (pObjectList->uNumObjects & 0x80000000u) != 0;
2387 LOWORD(v76) = *(unsigned __int16 *)((char *)&pItemsTable->pItems[0].uSpriteID + v76);
2388 i = v76;
2389 v75->uItemType = v76;
2390 if ( v12 | v11 )
2391 {
2392 LABEL_50:
2393 v78 = 0;
2394 }
2395 else
2396 {
2397 for ( j = (int)&pObjectList->pObjects->uObjectID; (short)v76 != *(short *)j; j = a3 )
2398 {
2399 ++Argsj;
2400 a3 = j + 56;
2401 if ( Argsj >= (signed int)pObjectList->uNumObjects )
2402 goto LABEL_50;
2403 LOWORD(v76) = i;
2404 }
2405 v78 = Argsj;
2406 }
2407 v75->uObjectDescID = v78;
2408 ++v75;
2409 --pDest;
2410 }
2411 while ( pDest );
2412 }
2413 fseek(v7, v221, 0);
2414 fread(&uNumActors, 4u, 1u, v7);
2415 fseek(v7, v222, 0);
2416 fread(pActors, 0x344u, uNumActors, v7);
2417 fseek(v7, v228, 0);
2418 fread(&uNumChests, 4u, 1u, v7);
2419 fseek(v7, v229, 0);
2420 fread(pChests, 0x14CCu, uNumChests, v7);
2421 fseek(v7, v224, 0);
2422 fread(&uNumLights, 4u, 1u, v7);
2423 fseek(v7, v225, 0);
2424 fread(pLights, 0x10u, uNumLights, v7);
2425 fseek(v7, v226, 0);
2426 fread(&uNumNodes, 4u, 1u, v7);
2427 fseek(v7, v227, 0);
2428 fread(pNodes, 8u, uNumNodes, v7);
2429 fseek(v7, v230, 0);
2430 fread(&uNumSpawnPoints, 4u, 1u, v7);
2431 v79 = pAllocator->AllocNamedChunk(pSpawnPoints, 24 * uNumSpawnPoints, "Spawn");
2432 v202 = 0;
2433 pSpawnPoints = (SpawnPointMM7 *)v79;
2434 fseek(v7, v231, v202);
2435 fread(pSpawnPoints, 0x18u, uNumSpawnPoints, v7);
2436 fseek(v7, v232, 0);
2437 fread(&dlv, 0x28u, 1u, v7);
2438 fseek(v7, v233, 0);
2439 fread(&stru_5E4C90, 1u, 0xC8u, v7);
2440 fseek(v7, v234, 0);
2441 fread(&uLastVisitDay, 1u, 0x38u, v7);
2442 fseek(v7, v223, 0);
2443 v80 = (void **)&pMapOutlines;
2444 fread(*v80, 4u, 1u, v7);
2445 fread((char *)*v80 + 4, 0xCu, *(int *)*v80, v7);
2446 fclose(v7);
2447 goto LABEL_179;
2448 }
2449 return 4;
2450 }*/
2451 #pragma endregion
2452
2453 if (bLoaded)
2454 {
2455 Log::Warning(L"BLV is already loaded");
2456 return 3;
2457 }
2458
2459 if ( !pGames_LOD->DoesContainerExist(pFilename) )
2460 Abortf("Unable to find %s in Games.LOD", pFilename);
2461
2462 //v238 = pFilename - 4;
2463 //v81 = strlen(pFilename);
2464 strcpy(this->pFilename, pFilename);
2465 strcpy(&pFilename[strlen(pFilename) - 4], ".blv");
2466 File = pGames_LOD->FindContainer(pFilename, 1);
2467 //File = v82;
2468
2469 Release();
2470 if ( !Alloc() )
2471 return 4;
2472
2473 header.uVersion = 91969;
2474 header.pMagic[0] = 'm';
2475 header.pMagic[1] = 'v';
2476 header.pMagic[2] = 'i';
2477 header.pMagic[3] = 'i';
2478 header.uCompressedSize = 0;
2479 header.uDecompressedSize = 0;
2480 fread(&header, sizeof(ODMHeader), 1u, File);
2481 if (header.uVersion != 91969 ||
2482 header.pMagic[0] != 'm' ||
2483 header.pMagic[1] != 'v' ||
2484 header.pMagic[2] != 'i' ||
2485 header.pMagic[3] != 'i' )
2486 {
2487 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:792", 0);
2488 }
2489 //v83 = header.uCompressedSize;
2490 //pSource = header.uDecompressedSize;
2491 //v84 = malloc(header.uDecompressedSize);
2492 //v85 = v84;
2493 //ptr = v84;
2494 auto pRawBLV = malloc(header.uDecompressedSize);
2495 memset(pRawBLV, 0, header.uDecompressedSize);
2496
2497 if (header.uCompressedSize == header.uDecompressedSize)
2498 fread(pRawBLV, header.uDecompressedSize, 1, File);
2499 else if (header.uCompressedSize < header.uDecompressedSize)
2500 {
2501 auto pTmpMem = malloc(header.uCompressedSize);
2502 {
2503 fread(pTmpMem, header.uCompressedSize, 1, File);
2504
2505 uint uDecompressedSize = header.uDecompressedSize;
2506 zlib::MemUnzip(pRawBLV, &uDecompressedSize, pTmpMem, header.uCompressedSize);
2507
2508 if (uDecompressedSize != header.uDecompressedSize)
2509 Log::Warning(L"uDecompressedSize != header.uDecompressedSize in BLV");
2510 }
2511 free(pTmpMem);
2512 }
2513 else
2514 {
2515 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:803", 0);
2516 return 0;
2517 }
2518
2519 assert(sizeof(Vec3_short_) == 6);
2520 assert(sizeof(BLVFace) == 96);
2521 assert(sizeof(BLVFaceExtra) == 36);
2522 assert(sizeof(BLVSector) == 116);
2523 assert(sizeof(LevelDecoration) == 32);
2524 assert(sizeof(BLVLightMM7) == 16);
2525 assert(sizeof(BSPNode) == 8);
2526 assert(sizeof(SpawnPointMM7) == 24);
2527 assert(sizeof(DDM_DLV_Header) == 40);
2528 assert(sizeof(Actor) == 836);
2529 assert(sizeof(LayingItem) == 112);
2530 assert(sizeof(Chest) == 5324);
2531 assert(sizeof(stru123) == 0xC8);
2532 assert(sizeof(BLVMapOutline) == 12);
2533
2534 bLoaded = true;
2535
2536 auto pData = (char *)pRawBLV;
2537
2538 pGameLoadingUI_ProgressBar->Progress();
2539
2540 memcpy(&blv, pData, 136);
2541 memcpy(&uNumVertices, pData += 136, 4);
2542 memcpy(pVertices, pData += 4, uNumVertices * sizeof(Vec3_short_));
2543
2544 pGameLoadingUI_ProgressBar->Progress();
2545
2546 memcpy(&uNumFaces, pData += uNumVertices * sizeof(Vec3_short_), 4);
2547
2548 pGameLoadingUI_ProgressBar->Progress();
2549
2550 memcpy(pFaces, pData += 4, uNumFaces * sizeof (BLVFace));
2551 ptr_2AC = (unsigned __int16 *)pAllocator->AllocNamedChunk(ptr_2AC, blv.uFaces_fdata_Size, "L.FData");
2552
2553 memcpy(ptr_2AC, pData += uNumFaces * sizeof (BLVFace), blv.uFaces_fdata_Size);
2554
2555 for (uint i = 0, j = 0; i < uNumFaces; ++i)
2556 {
2557 auto pFace = pFaces + i;
2558
2559 pFace->pVertexIDs = ptr_2AC + j;
2560
2561 j += pFace->uNumVertices + 1;
2562 pFace->pXInterceptDisplacements = ptr_2AC + j;
2563
2564 j += pFace->uNumVertices + 1;
2565 pFace->pYInterceptDisplacements = ptr_2AC + j;
2566
2567 j += pFace->uNumVertices + 1;
2568 pFace->pZInterceptDisplacements = ptr_2AC + j;
2569
2570 j += pFace->uNumVertices + 1;
2571 pFace->pVertexUIDs = (__int16 *)(ptr_2AC + j);
2572
2573 j += pFace->uNumVertices + 1;
2574 pFace->pVertexVIDs = (__int16 *)(ptr_2AC + j);
2575
2576 j += pFace->uNumVertices + 1;
2577 /*v93 = &pFaces[v92];
2578 Src = v93;
2579 v94 = (BLVSector *)((char *)v244 + 2 * v93->uNumVertices + 2);
2580 v95 = (unsigned __int16 *)((char *)v94 + (unsigned int)ptr_2AC);
2581 v244 = v94;
2582 Src->pXInterceptDisplacements = v95;
2583 v96 = (int)&pFaces[v92];
2584 Src = (BLVFace *)v96;
2585 v97 = (BLVSector *)((char *)v244 + 2 * *(char *)(v96 + 93) + 2);
2586 v98 = (unsigned __int16 *)((char *)v97 + (unsigned int)ptr_2AC);
2587 v244 = v97;
2588 Src->pYInterceptDisplacements = v98;
2589 Src = &pFaces[v92];
2590 v99 = ptr_2AC;
2591 v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
2592 Src->pZInterceptDisplacements = (unsigned __int16 *)((char *)v99 + (int)v244);
2593 Src = &pFaces[v92];
2594 v100 = ptr_2AC;
2595 v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
2596 Src->pVertexUIDs = (unsigned __int16 *)((char *)v100 + (int)v244);
2597 Src = &pFaces[v92];
2598 ++v92;
2599 v101 = ptr_2AC;
2600 v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
2601 ++v245;
2602 Src->pVertexVIDs = (unsigned __int16 *)((char *)v101 + (int)v244);
2603 v244 = (BLVSector *)((char *)v244 + 2 * *((char *)&pFaces[v92] - 3) + 2);*/
2604 }
2605
2606 pGameLoadingUI_ProgressBar->Progress();
2607
2608 pData += blv.uFaces_fdata_Size;
2609
2610 for (uint i = 0; i < uNumFaces; ++i)
2611 {
2612 auto pFace = pFaces + i;
2613
2614 char pTexName[16];
2615 strncpy(pTexName, pData, 10);
2616 pData += 10;
2617
2618 if (pFace->uAttributes & 0x4000)
2619 {
2620 pFace->uBitmapID = pTextureFrameTable->FindTextureByName(pTexName);
2621 if (pFace->uBitmapID)
2622 pTextureFrameTable->LoadAnimationSequenceAndPalettes(pFace->uBitmapID);
2623 else
2624 {
2625 pFace->uBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
2626 pFace->uAttributes &= ~0x4000;
2627 }
2628 }
2629 else
2630 pFace->uBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
2631 }
2632
2633 pGameLoadingUI_ProgressBar->Progress();
2634
2635 memcpy(&uNumFaceExtras, pData, 4u);
2636 memcpy(pFaceExtras, pData += 4, uNumFaceExtras * sizeof(BLVFaceExtra));
2637 pData += uNumFaceExtras * sizeof(BLVFaceExtra);
2638
2639 pGameLoadingUI_ProgressBar->Progress();
2640
2641 //v108 = (char *)v107 + 36 * uNumFaceExtras;
2642 //v245 = 0;
2643 //*(int *)((char *)&uSourceLen + 1) = 0;
2644 for (uint i = 0; i < uNumFaceExtras; ++i)
2645 {
2646 char pTexName[32];
2647 strncpy(pTexName, pData, 10);
2648 pData += 10;
2649
2650 if (!strcmp(pTexName, ""))
2651 pFaceExtras[i].uAdditionalBitmapID = -1;
2652 else
2653 pFaceExtras[i].uAdditionalBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
2654 }
2655
2656
2657 for (uint i = 0; i < uNumFaces; ++i)
2658 {
2659 auto pFace = pFaces + i;
2660 auto pFaceExtra = pFaceExtras + pFace->uFaceExtraID;
2661
2662 if (pFaceExtra->uEventID)
2663 {
2664 if (pFaceExtra->HasEventint())
2665 pFace->uAttributes |= 0x100000;
2666 else
2667 pFace->uAttributes &= ~0x100000;
2668 }
2669 }
2670
2671 pGameLoadingUI_ProgressBar->Progress();
2672
2673 memcpy(&uNumSectors, pData, 4);
2674 memcpy(pSectors, pData + 4, uNumSectors * sizeof(BLVSector));
2675 pData += 4 + uNumSectors * sizeof(BLVSector);
2676
2677 pGameLoadingUI_ProgressBar->Progress();
2678
2679 ptr_0002B0_sector_rdata = (unsigned short *)pAllocator->AllocNamedChunk(ptr_0002B0_sector_rdata, blv.uSector_rdata_Size, "L.RData");
2680 memcpy(ptr_0002B0_sector_rdata, pData, blv.uSector_rdata_Size);
2681 pData += blv.uSector_rdata_Size;
2682
2683 for (uint i = 0, j = 0; i < uNumSectors; ++i)
2684 {
2685 auto pSector = pSectors + i;
2686
2687 pSector->pFloors = ptr_0002B0_sector_rdata + j;
2688 j += pSector->uNumFloors;
2689
2690 pSector->pWalls = ptr_0002B0_sector_rdata + j;
2691 j += pSector->field_C;
2692
2693 pSector->pCeilings = ptr_0002B0_sector_rdata + j;
2694 j += pSector->field_14;
2695
2696 pSector->pFluids = ptr_0002B0_sector_rdata + j;
2697 j += pSector->field_1C;
2698
2699 pSector->pPortals = ptr_0002B0_sector_rdata + j;
2700 j += pSector->uNumPortals;
2701
2702 pSector->pFaceIDs = ptr_0002B0_sector_rdata + j;
2703 j += pSector->field_2C;
2704
2705 pSector->pCogs = ptr_0002B0_sector_rdata + j;
2706 j += pSector->field_3C;
2707
2708 pSector->pDecorationIDs = ptr_0002B0_sector_rdata + j;
2709 j += pSector->uNumDecorations;
2710
2711 pSector->pMarkers = ptr_0002B0_sector_rdata + j;
2712 j += pSector->field_4C;
2713
2714
2715 //do
2716 //{
2717 /*pSectors[v118].pFloors = (unsigned __int16 *)((char *)Src + (unsigned int)ptr_0002B0_sector_rdata);
2718 v244 = &pSectors[v118];
2719 v119 = ptr_0002B0_sector_rdata;
2720 Src = (BLVFace *)((char *)Src + 2 * v244->field_4);
2721 v244->pWalls = (unsigned __int16 *)((char *)v119 + (int)Src);
2722 v120 = (int)&pSectors[v118];
2723 v244 = (BLVSector *)v120;
2724 v121 = (BLVFace *)((char *)Src + 2 * *(short *)(v120 + 12));
2725 v122 = (unsigned __int16 *)((char *)v121 + (unsigned int)ptr_0002B0_sector_rdata);
2726 Src = v121;
2727 v244->pCeilings = v122;
2728 v123 = (int)&pSectors[v118];
2729 v244 = (BLVSector *)v123;
2730 v124 = (BLVFace *)((char *)Src + 2 * *(short *)(v123 + 20));
2731 v125 = (unsigned __int16 *)((char *)v124 + (unsigned int)ptr_0002B0_sector_rdata);
2732 Src = v124;
2733 v244->pFluids = v125;
2734 v244 = &pSectors[v118];
2735 v126 = ptr_0002B0_sector_rdata;
2736 Src = (BLVFace *)((char *)Src + 2 * v244->field_1C);
2737 v244->pPortals = (unsigned __int16 *)((char *)v126 + (int)Src);
2738 v244 = &pSectors[v118];
2739 v127 = ptr_0002B0_sector_rdata;
2740 Src = (BLVFace *)((char *)Src + 2 * v244->uNumPortals);
2741 v244->pFaceIDs = (unsigned __int16 *)((char *)v127 + (int)Src);
2742 v244 = &pSectors[v118];
2743 v128 = ptr_0002B0_sector_rdata;
2744 Src = (BLVFace *)((char *)Src + 2 * v244->field_2C);
2745 v244->pCogs = (unsigned __int16 *)((char *)v128 + (int)Src);
2746 v244 = &pSectors[v118];
2747 v129 = ptr_0002B0_sector_rdata;
2748 Src = (BLVFace *)((char *)Src + 2 * v244->field_3C);
2749 v244->pDecorationIDs = (unsigned __int16 *)((char *)v129 + (int)Src);
2750 v130 = (int)&pSectors[v118];
2751 ++v118;
2752 v244 = (BLVSector *)v130;
2753 v131 = ptr_0002B0_sector_rdata;
2754 Src = (BLVFace *)((char *)Src + 2 * *(short *)(v130 + 68));
2755 ++v245;
2756 *(int *)(v130 + 80) = (int)(char *)v131 + (int)Src;
2757 Src = (BLVFace *)((char *)Src + 2 * *((short *)&pSectors[v118] - 20));*/
2758 //}
2759 //while ( v245 < uNumSectors );
2760 }
2761
2762 ptr_0002B8_sector_lrdata = (unsigned __int16 *)pAllocator->AllocNamedChunk(ptr_0002B8_sector_lrdata, blv.uSector_lrdata_Size, "L.RLData");
2763 memcpy(ptr_0002B8_sector_lrdata, pData, blv.uSector_lrdata_Size);
2764 pData += blv.uSector_lrdata_Size;
2765
2766 pGameLoadingUI_ProgressBar->Progress();
2767
2768 for (uint i = 0, j = 0; i < uNumSectors; ++i)
2769 {
2770 pSectors->pLights = (unsigned __int16 *)(ptr_0002B8_sector_lrdata + j);
2771 j += pSectors->uNumLights;
2772 }
2773
2774 pGameLoadingUI_ProgressBar->Progress();
2775
2776 memcpy(&uNumDoors, pData, 4);
2777 pData += 4;
2778
2779 pGameLoadingUI_ProgressBar->Progress();
2780 pGameLoadingUI_ProgressBar->Progress();
2781
2782 memcpy(&uNumLevelDecorations, pData, 4);
2783 memcpy(pLevelDecorations, pData + 4, uNumLevelDecorations * sizeof(LevelDecoration));
2784 pData += 4 + uNumLevelDecorations * sizeof(LevelDecoration);
2785
2786 for (uint i = 0; i < uNumLevelDecorations; ++i)
2787 {
2788 pLevelDecorations[i].uDecorationDescID = pDecorationList->GetDecorIdByName(pData);
2789
2790 pData += 32;
2791 }
2792
2793 pGameLoadingUI_ProgressBar->Progress();
2794
2795 memcpy(&uNumLights, pData, 4);
2796 memcpy(pLights, pData + 4, uNumLights * sizeof(BLVLightMM7));
2797 pData += 4 + uNumLights * sizeof(BLVLightMM7);
2798
2799 pGameLoadingUI_ProgressBar->Progress();
2800 pGameLoadingUI_ProgressBar->Progress();
2801
2802 memcpy(&uNumNodes, pData, 4);
2803 memcpy(pNodes, pData + 4, uNumNodes * sizeof(BSPNode));
2804 pData += 4 + uNumNodes * sizeof(BSPNode);
2805
2806 pGameLoadingUI_ProgressBar->Progress();
2807 pGameLoadingUI_ProgressBar->Progress();
2808
2809 memcpy(&uNumSpawnPoints, pData, 4);
2810 pSpawnPoints = (SpawnPointMM7 *)pAllocator->AllocNamedChunk(pSpawnPoints, uNumSpawnPoints * sizeof(SpawnPointMM7), "Spawn");
2811 memcpy(pSpawnPoints, pData + 4, uNumSpawnPoints * sizeof(SpawnPointMM7));
2812 pData += 4 + uNumSpawnPoints * sizeof(SpawnPointMM7);
2813
2814 pGameLoadingUI_ProgressBar->Progress();
2815 pGameLoadingUI_ProgressBar->Progress();
2816
2817 //v201 = (const char *)v148;
2818 //v200 = (size_t)pMapOutlines;
2819 memcpy(&pMapOutlines->uNumOutlines, pData, 4);
2820 memcpy(pMapOutlines->pOutlines, pData + 4, pMapOutlines->uNumOutlines * sizeof(BLVMapOutline));
2821 //v149 = pMapOutlines;
2822 //v199 = 12 * *v149;
2823 //memcpy(v149 + 1, (const void *)(v148 + 4), v199);
2824 free(pRawBLV);
2825 pRawBLV = nullptr;
2826
2827 void *pRawDLV = nullptr;
2828 strcpy(&pFilename[strlen(pFilename) - 4], ".dlv");
2829 File = pNew_LOD->FindContainer(pFilename, 1);
2830 fread(&header, 0x10u, 1u, File);//(FILE *)v245);
2831 bool _v244 = false;
2832 if (header.uVersion != 91969 ||
2833 header.pMagic[0] != 'm' ||
2834 header.pMagic[1] != 'v' ||
2835 header.pMagic[2] != 'i' ||
2836 header.pMagic[3] != 'i' )
2837 {
2838 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1090", 0);
2839 _v244 = true;
2840 }
2841 else
2842 {
2843 pRawDLV = malloc(header.uDecompressedSize);
2844 if (header.uCompressedSize == header.uDecompressedSize)
2845 fread(pRawDLV, 1, header.uCompressedSize, File);
2846 else if (header.uCompressedSize < header.uDecompressedSize)
2847 {
2848 auto pTmpMem = malloc(header.uCompressedSize);
2849 {
2850 fread(pTmpMem, header.uCompressedSize, 1, File);
2851
2852 uint uDecompressedSize = header.uDecompressedSize;
2853 zlib::MemUnzip(pRawDLV, &uDecompressedSize, pTmpMem, header.uCompressedSize);
2854
2855 if (uDecompressedSize != header.uDecompressedSize)
2856 Log::Warning(L"uDecompressedSize != header.uDecompressedSize in DLV");
2857 }
2858 free(pTmpMem);
2859 }
2860 else
2861 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1108", 0);
2862
2863 pData = (char *)pRawDLV;
2864 }
2865
2866 memcpy(&dlv, pData, 40);
2867 pData += 40;
2868
2869 //v152 = dlv.uNumFacesInBModels;
2870 if (dlv.uNumFacesInBModels)
2871 {
2872 //v153 = dlv.uNumDecorations;
2873 if (dlv.uNumDecorations)
2874 {
2875 if (dlv.uNumFacesInBModels != uNumFaces ||
2876 dlv.uNumDecorations != uNumLevelDecorations)
2877 _v244 = true;
2878 }
2879 }
2880
2881 if (dword_6BE364_game_settings_1 & 0x2000 )
2882 _i = 29030400;
2883 bool _a = false;
2884 if ( a3 - dlv.uLastRepawnDay >= _i && strcmpi(pCurrentMapName, "d29.dlv") )
2885 _a = true;
2886
2887 //v154 = 875;
2888 if (_v244)
2889 {
2890 memset(v203, 0, 0x36B);
2891 goto LABEL_132;
2892 }
2893 if (_a || !dlv.uLastRepawnDay )
2894 {
2895 memcpy(v203, pData, 0x36B);
2896 LABEL_132:
2897 free(File);
2898 dlv.uLastRepawnDay = a3;
2899 if (_v244)
2900 ++dlv.uNumRespawns;
2901 //v201 = pFilename;
2902 *(int *)pDest = 1;
2903 File = pGames_LOD->FindContainer(pFilename, 0);
2904 fread(&header, 0x10u, 1u, File);
2905 auto v155 = header.uCompressedSize;
2906 auto Count = header.uDecompressedSize;
2907 auto Src = (BLVFace *)malloc(header.uDecompressedSize);
2908 File = (FILE *)Src;
2909 if ( v155 <= Count )
2910 {
2911 if ( v155 == Count )
2912 {
2913 fread(Src, 1u, Count, File);
2914 }
2915 else
2916 {
2917 auto _uSourceLen = malloc(v155);
2918 fread(_uSourceLen, v155, 1u, File);
2919 zlib::MemUnzip(Src, &Count, _uSourceLen, v155);
2920 free(_uSourceLen);
2921 }
2922 }
2923 else
2924 {
2925 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1195", 0);
2926 }
2927 pData = ((char *)Src + 40);
2928 //v154 = 875;
2929 goto LABEL_140;
2930 }
2931 *(int *)pDest = 0;
2932 LABEL_140:
2933 //v202 = (int)".blv";
2934 //v156 = strlen(pFilename);
2935 strcpy(&pFilename[strlen(pFilename) - 4], ".blv");
2936 memcpy(_visible_outlines, pData, 875);
2937 pData += 875;
2938
2939 if ( *(int *)pDest )
2940 memcpy(_visible_outlines, v203, 875);
2941
2942 for (uint i = 0; i < pMapOutlines->uNumOutlines; ++i)
2943 {
2944 auto pVertex = pMapOutlines->pOutlines + i;
2945 if ((unsigned __int8)(1 << (7 - i % 8)) & _visible_outlines[i / 8])
2946 pVertex->uFlags |= 1;
2947 }
2948
2949
2950 for (uint i = 0; i < uNumFaces; ++i)
2951 {
2952 auto pFace = pFaces + i;
2953 auto pFaceExtra = pFaceExtras + pFace->uFaceExtraID;
2954
2955 memcpy(&pFace->uAttributes, pData, 4);
2956 pData += 4;
2957
2958 if (pFaceExtra->uEventID)
2959 {
2960 if (pFaceExtra->HasEventint())
2961 pFace->uAttributes |= 0x100000;
2962 else
2963 pFace->uAttributes &= ~0x100000;
2964 }
2965 }
2966
2967 pGameLoadingUI_ProgressBar->Progress();
2968
2969 for (uint i = 0; i < uNumLevelDecorations; ++i)
2970 {
2971 memcpy(&pLevelDecorations[i].field_2, pData, 2);
2972 pData += 2;
2973 }
2974
2975 pGameLoadingUI_ProgressBar->Progress();
2976
2977 memcpy(&uNumActors, pData, 4);
2978 memcpy(pActors, pData + 4, uNumActors * sizeof(Actor));
2979 pData += 4 + uNumActors * sizeof(Actor);
2980
2981 pGameLoadingUI_ProgressBar->Progress();
2982 pGameLoadingUI_ProgressBar->Progress();
2983
2984 memcpy(&uNumLayingItems, pData, 4);
2985 memcpy(pLayingItems, pData + 4, uNumLayingItems * sizeof(LayingItem));
2986 pData += 4 + uNumLayingItems * sizeof(LayingItem);
2987
2988 pGameLoadingUI_ProgressBar->Progress();
2989
2990 for (uint i = 0; i < uNumLayingItems; ++i)
2991 {
2992 auto pItem = pLayingItems + i;
2993
2994 if (pItem->stru_24.uItemID && !(pItem->uAttributes & 0x0100))
2995 {
2996 pItem->uItemType = pItemsTable->pItems[pItem->stru_24.uItemID - 1].uSpriteID;
2997
2998 uint uObjectID = 0;
2999 for (uint j = 0; j < pObjectList->uNumObjects; ++j)
3000 if (pItem->uItemType == pObjectList->pObjects[j].uObjectID)
3001 {
3002 pItem->uObjectDescID = j;
3003 break;
3004 }
3005 }
3006 }
3007
3008 pGameLoadingUI_ProgressBar->Progress();
3009
3010 memcpy(&uNumChests, pData, 4);
3011 memcpy(pChests, pData + 4, uNumChests * sizeof(Chest));
3012 pData += 4 + uNumChests * sizeof(Chest);
3013
3014 pGameLoadingUI_ProgressBar->Progress();
3015 pGameLoadingUI_ProgressBar->Progress();
3016
3017 memcpy(pDoors, pData, 0x3E80);
3018 pData += 0x3E80;
3019
3020 //v201 = (const char *)blv.uDoors_ddata_Size;
3021 //v200 = (size_t)ptr_0002B4_doors_ddata;
3022 //v170 = pAllocator->AllocNamedChunk(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
3023 //v171 = blv.uDoors_ddata_Size;
3024 ptr_0002B4_doors_ddata = (unsigned __int16 *)pAllocator->AllocNamedChunk(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
3025 memcpy(ptr_0002B4_doors_ddata, pData, blv.uDoors_ddata_Size);
3026 pData += blv.uDoors_ddata_Size;
3027
3028 //Src = (BLVFace *)((char *)Src + v171);
3029 //v172 = 0;
3030 //v245 = 0;
3031 //if (uNumDoors > 0)
3032 for (uint i = 0, j = 0; i < uNumDoors; ++i)
3033 {
3034 auto pDoor = pDoors + i;
3035
3036 pDoor->pVertexIDs = ptr_0002B4_doors_ddata + j;
3037 j += pDoor->uNumVertices;
3038
3039 pDoor->pFaceIDs = ptr_0002B4_doors_ddata + j;
3040 j += pDoor->uNumFaces;
3041
3042 pDoor->pSectorIDs = ptr_0002B4_doors_ddata + j;
3043 j += pDoor->field_48;
3044
3045 pDoor->pDeltaUs = (short *)(ptr_0002B4_doors_ddata + j);
3046 j += pDoor->uNumFaces;
3047
3048 pDoor->pDeltaVs = (short *)(ptr_0002B4_doors_ddata + j);
3049 j += pDoor->uNumFaces;
3050
3051 pDoor->pXOffsets = ptr_0002B4_doors_ddata + j;
3052 j += pDoor->uNumOffsets;
3053
3054 pDoor->pYOffsets = ptr_0002B4_doors_ddata + j;
3055 j += pDoor->uNumOffsets;
3056
3057 pDoor->pZOffsets = ptr_0002B4_doors_ddata + j;
3058 j += pDoor->uNumOffsets;
3059 /*v173 = pDoors;
3060 for ( k = 0; ; v172 = v188 + 2 * *((short *)&v173[k] - 3) )
3061 {
3062 v173[k].pVertexIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v172);
3063 v175 = &pDoors[k];
3064 v176 = v172 + 2 * v175->uNumVertices;
3065 v175->pFaceIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v176);
3066 v177 = &pDoors[k];
3067 v178 = v176 + 2 * v177->uNumFaces;
3068 v177->pSectorIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v178);
3069 v179 = &pDoors[k];
3070 v180 = v178 + 2 * v179->field_48;
3071 v179->pDeltaUs = (__int16 *)((char *)ptr_0002B4_doors_ddata + v180);
3072 v181 = &pDoors[k];
3073 v182 = v180 + 2 * v181->uNumFaces;
3074 v181->pDeltaVs = (__int16 *)((char *)ptr_0002B4_doors_ddata + v182);
3075 v183 = &pDoors[k];
3076 v184 = v182 + 2 * v183->uNumFaces;
3077 v183->pXOffsets = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v184);
3078 v185 = &pDoors[k];
3079 v186 = v184 + 2 * v185->uNumOffsets;
3080 v185->pYOffsets = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v186);
3081 v187 = &pDoors[k];
3082 ++k;
3083 v188 = v186 + 2 * v187->uNumOffsets;
3084 v189 = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v188);
3085 ++v245;
3086 v187->pZOffsets = v189;
3087 v173 = pDoors;
3088 if ( v245 >= uNumDoors )
3089 break;
3090 }*/
3091 }
3092 //v190 = 0;
3093 //v245 = 0;
3094 for (uint i = 0; i < uNumDoors; ++i)
3095 {
3096 auto pDoor = pDoors + i;
3097
3098 for (uint j = 0; j < pDoor->uNumFaces; ++j)
3099 {
3100 auto pFace = pFaces + pDoor->pFaceIDs[j];
3101 auto pFaceExtra = pFaceExtras + pFace->uFaceExtraID;
3102
3103 pDoor->pDeltaUs[j] = pFaceExtra->sTextureDeltaU;
3104 pDoor->pDeltaVs[j] = pFaceExtra->sTextureDeltaV;
3105 }
3106 //v191 = pDoors;
3107 //pDest = 0;
3108 //do
3109 // {
3110 /*Argsn = 0;
3111 for ( l = (BLVDoor *)&v190[(int)v191];
3112 Argsn < *(short *)&v190[(int)v191 + 70];
3113 l = (BLVDoor *)&v190[(int)v191] )
3114 {
3115 v193 = Argsn;
3116 v194 = l->pFaceIDs[Argsn++];
3117 v195 = &pFaceExtras[pFaces[v194].uFaceExtraID];
3118 l->pDeltaUs[v193] = v195->sTextureDeltaU;
3119 v190 = pDest;
3120 *(short *)(v193 * 2 + *(int *)&pDest[(unsigned int)pDoors + 52]) = v195->sTextureDeltaV;
3121 v191 = pDoors;
3122 }
3123 ++v245;
3124 v190 += 80;
3125 pDest = v190;*/
3126 //}
3127 //while ( v245 < uNumDoors );
3128 }
3129
3130
3131 pGameLoadingUI_ProgressBar->Progress();
3132
3133 memcpy(&stru_5E4C90, pData, 0xC8);
3134 pData += 0xC8;
3135
3136 pGameLoadingUI_ProgressBar->Progress();
3137
3138 memcpy(&stru1, pData, 0x38u);
3139 pData += 0x38;
3140
3141 free(pRawDLV);
3142 //v5 = 0;
3143
3144 pSoundList->LoadSound(64, 0);
3145 pSoundList->LoadSound(103, 0);
3146 pSoundList->LoadSound(63, 0);
3147 pSoundList->LoadSound(102, 0);
3148 pSoundList->LoadSound(50, 0);
3149 pSoundList->LoadSound(89, 0);
3150
3151 return 0;
3152 }
3153
3154
3155 //----- (0049AC17) --------------------------------------------------------
3156 int IndoorLocation::GetSector(int sX, int sY, int sZ)
3157 {
3158 int v4; // esi@1
3159 //unsigned __int8 v5; // zf@1
3160 //unsigned __int8 v6; // sf@1
3161 //unsigned __int8 v7; // of@1
3162 //BLVSector *v8; // eax@3
3163 //int v9; // edi@9
3164 //int v10; // eax@9
3165 //int v11; // edx@9
3166 //int v12; // eax@10
3167 //unsigned __int16 v13; // ax@12
3168 //int v14; // edi@14
3169 //BLVFace *v15; // eax@14
3170 //BLVFace *v16; // edi@14
3171 //PolygonType v17; // al@14
3172 //unsigned __int16 *pVertexIDs; // esi@16
3173 //Vec3_short_ *v19; // eax@16
3174 //int v20; // edx@16
3175 //unsigned __int16 *v21; // esi@17
3176 //int v22; // edi@19
3177 //int v23; // edi@20
3178 //Vec3_short_ *v24; // edx@20
3179 signed int v25; // edx@21
3180 int v26; // ebx@23
3181 //int v27; // edx@26
3182 //signed __int64 v28; // qtt@26
3183 ///Vec3_short_ *v29; // eax@26
3184 //Vec3_short_ *v30; // edx@26
3185 //int v31; // edx@26
3186 signed int v32; // edi@27
3187 signed __int64 v33; // qtt@27
3188 //Vec3_short_ *v34; // edx@27
3189 int v35; // edx@32
3190 int v37; // edi@38
3191 int v38; // ebx@40
3192 int v39; // eax@41
3193 BLVFace *v40; // esi@42
3194 PolygonType v41; // dl@42
3195 int v42; // edx@43
3196 int v43[50]; // [sp+Ch] [bp-108h]@1
3197 //int v44; // [sp+D4h] [bp-40h]@9
3198 //int v45; // [sp+D8h] [bp-3Ch]@14
3199 //int v46; // [sp+DCh] [bp-38h]@14
3200 //int v47; // [sp+E0h] [bp-34h]@19
3201 //int v48; // [sp+E4h] [bp-30h]@9
3202 //Vec3_short_ *v49; // [sp+E8h] [bp-2Ch]@19
3203 bool v50; // [sp+ECh] [bp-28h]@19
3204 int v51; // [sp+F0h] [bp-24h]@9
3205 //unsigned int v52; // [sp+F4h] [bp-20h]@2
3206 int v53; // [sp+F8h] [bp-1Ch]@10
3207 int v54; // [sp+FCh] [bp-18h]@16
3208 int v55; // [sp+100h] [bp-14h]@1
3209 int v56; // [sp+104h] [bp-10h]@1
3210 int v57; // [sp+108h] [bp-Ch]@16
3211 //Vec3_short_ *v58; // [sp+10Ch] [bp-8h]@20
3212 int v59; // [sp+110h] [bp-4h]@16
3213
3214 v4 = 0;
3215 //v7 = __OFSUB__(this->uNumSectors, 1);
3216 //v5 = this->uNumSectors == 1;
3217 //v6 = this->uNumSectors - 1 < 0;
3218 v55 = 0;
3219 v43[0] = 0;
3220 //v56 = 1;
3221 if (uNumSectors < 2)
3222 return 0;
3223
3224 for (uint i = 1; i < uNumSectors; ++i)
3225 {
3226 auto pSector = pSectors + i;
3227
3228 if (pSector->pBounding.x1 <= sX && pSector->pBounding.x2 >= sX)
3229 if (pSector->pBounding.y1 <= sY && pSector->pBounding.y2 >= sY)
3230 if (pSector->pBounding.z1 - 64 <= sZ && pSector->pBounding.z2 + 64 >= sZ)
3231 {
3232 Log::Warning(L"Sector[%u]", i);
3233 v51 = pSector->uNumFloors + pSector->uNumPortals;
3234 if (!v51)
3235 continue;
3236
3237 //v9 = pSector->uNumFloors;
3238 //v10 = v9 + pSector->uNumPortals;
3239 //v11 = 0;
3240 //v44 = v9;
3241 //v48 = 0;
3242
3243 //v12 = -2 * v9;
3244 //v53 = -2 * v9;
3245 for (uint j = 0; j < v51; ++j)
3246 {
3247 unsigned int uFaceID;
3248 if (j < pSector->uNumFloors)
3249 uFaceID = pSector->pFloors[j];
3250 else
3251 uFaceID = pSector->pPortals[j - pSector->uNumFloors];
3252
3253 auto pFace = pFaces + uFaceID;
3254 //v14 = (signed __int16)v13;
3255 //v15 = this->pFaces;
3256 //v46 = v13;
3257 //v14 *= 96;
3258 //v45 = v13 * sizeof(BLVFace);
3259 //v16 = pFaces + uFaceID;
3260 //v17 = v16->uPolygonType;
3261 if (pFace->uPolygonType == POLYGON_Floor ||
3262 pFace->uPolygonType == POLYGON_InBetweenFloorAndWall)
3263 {
3264 //pVertexIDs = pFace->pVertexIDs;
3265 //v19 = this->pVertices;
3266 //v20 = pVertices[pFace->pVertexIDs[0]].y;
3267 v54 = 0;
3268 //v57 = 0;
3269 //v5 = v16->uNumVertices == 0;
3270 v59 = pVertices[pFace->pVertexIDs[0]].y >= sY;
3271
3272 //v21 = pFace->pVertexIDs + 1;
3273 for (uint k = 1; k < pFace->uNumVertices; ++k)
3274 {
3275 if (v54 >= 2)
3276 break;
3277
3278 //v49 = &pVertices[pFace->pVertexIDs[k]];
3279 auto v2 = &pVertices[pFace->pVertexIDs[k]];
3280 //v22 = pVertex->y;
3281 //v47 = pVertex->y;
3282 v50 = v2->y >= sY;
3283 if ( v59 ^ v50 )
3284 {
3285 //v58 = &pVertices[pFace->pVertexIDs[k - 1]];
3286 auto v1 = &pVertices[pFace->pVertexIDs[k - 1]];
3287 //v23 = v58->x;
3288 //HIWORD(v24) = HIWORD(v49);
3289 //LOWORD(v24) = v49->x;
3290 //v49 = v24;
3291 //v59 = v49->x;
3292 v25 = v1->x >= sX ? 0 : 2; // BUG TODO TROLOLO
3293 v26 = v25 | v2->x < sX; // SWAP v1 and v2 till the result's correct
3294 if ( v26 != 3 )
3295 {
3296 if (!v26)
3297 ++v54;
3298 else
3299 {
3300 if (v1->x >= v2->x)
3301 {
3302 int _a58;
3303 int _a59;
3304
3305 v32 = v1->x - v2->x;
3306 LODWORD(v33) = v32 << 16;
3307 HIDWORD(v33) = v32 >> 16;
3308 _a58 = v33 / (v1->y - v2->y);
3309 _a59 = (unsigned __int64)(_a58 * (__int64)(sY - v2->y)) >> 16;
3310
3311 if (v59 + pVertices[k].x > sX)
3312 ++v54;
3313 }
3314 else
3315 {
3316 int _a58;
3317 int _a59;
3318 v32 = v2->x - v1->x;
3319 LODWORD(v33) = v32 << 16;
3320 HIDWORD(v33) = v32 >> 16;
3321 _a58 = v33 / (v2->y - v1->y);
3322 _a59 = (unsigned __int64)(_a58 * (signed __int64)(sY - v1->y)) >> 16;
3323
3324 if (_a59 + pVertices[k - 1].x > sX)
3325 ++v54;
3326 }
3327 }
3328 }
3329 }
3330
3331 v59 = v50;
3332 }
3333
3334 if (pFace->uNumVertices)
3335 {
3336 if (v54 == 1)
3337 {
3338 v35 = v55++;
3339 v43[v35] = uFaceID;
3340 }
3341 }
3342 }
3343 }
3344 v4 = v43[0];
3345 }
3346 }
3347
3348 if ( v55 == 1 )
3349 return this->pFaces[v4].uSectorID;
3350 v37 = 0;
3351 if ( !v55 )
3352 return 0;
3353 v38 = 0;
3354 v53 = 0xFFFFFFu;
3355 if ( v55 > 0 )
3356 {
3357 v39 = sY;
3358 while ( 1 )
3359 {
3360 v40 = &this->pFaces[v43[v37]];
3361 v41 = v40->uPolygonType;
3362 if ( v41 == 3 )
3363 break;
3364 if ( v41 == 4 )
3365 {
3366 v51 = v40->zCalc1;
3367 v57 = (unsigned __int64)(v51 * (signed __int64)(sX << 16)) >> 16;
3368 v56 = sY << 16;
3369 v51 = v40->zCalc2;
3370 v56 = (unsigned __int64)(v51 * (signed __int64)(sY << 16)) >> 16;
3371 v42 = (v56 + v40->zCalc3 + v57 + 32768) >> 16;
3372 goto LABEL_46;
3373 }
3374 LABEL_47:
3375 if ( v39 >= 0 )
3376 {
3377 if ( v39 < v53 )
3378 {
3379 v38 = v40->uSectorID;
3380 v53 = v39;
3381 }
3382 }
3383 ++v37;
3384 if ( v37 >= v55 )
3385 return v38;
3386 }
3387 v42 = this->pVertices[*v40->pVertexIDs].z;
3388 LABEL_46:
3389 v39 = sZ - v42;
3390 goto LABEL_47;
3391 }
3392 return v38;
3393 }
3394 // 49AC17: using guessed type int var_108[50];
3395
3396
3397 //----- (00498A41) --------------------------------------------------------
3398 char BLVFace::_get_normals(Vec3_int_ *a2, Vec3_int_ *a3)
3399 {
3400 BLVFace *v3; // ebx@1
3401 int v4; // eax@1
3402 signed __int64 v5; // qax@2
3403 double v6; // st7@8
3404 Vec3_float_ a1; // [sp+Ch] [bp-Ch]@8
3405
3406 v3 = this;
3407 LOBYTE(v4) = this->uPolygonType;
3408 if ( (char)v4 == POLYGON_VerticalWall )
3409 {
3410 a2->x = -this->pFacePlane_old.vNormal.y;
3411 LODWORD(v5) = this->pFacePlane_old.vNormal.x;
3412 LABEL_9:
3413 a2->y = v5;
3414 v4 = 0;
3415 a2->z = 0;
3416 a3->y = 0;
3417 a3->z = 0xFFFF0000u;
3418 LABEL_11:
3419 a3->x = v4;
3420 goto LABEL_12;
3421 }
3422 if ( (char)v4 == POLYGON_Floor || (char)v4 == POLYGON_Ceiling )
3423 {
3424 LABEL_10:
3425 v4 = 0;
3426 a2->x = 0x10000u;
3427 a2->z = 0;
3428 a2->y = 0;
3429 a3->y = 0xFFFF0000u;
3430 a3->z = 0;
3431 goto LABEL_11;
3432 }
3433 if ( (char)v4 == POLYGON_InBetweenFloorAndWall || (char)v4 == POLYGON_InBetweenCeilingAndWall )
3434 {
3435 if ( abs(this->pFacePlane_old.vNormal.z) < 46441 )
3436 {
3437 a1.x = (double)-v3->pFacePlane_old.vNormal.y;
3438 a1.y = (double)v3->pFacePlane_old.vNormal.x;
3439 a1.z = 0.0;
3440 a1.Normalize();
3441 v6 = a1.y * 65536.0;
3442 a2->x = (signed __int64)(a1.x * 65536.0);
3443 v5 = (signed __int64)v6;
3444 goto LABEL_9;
3445 }
3446 goto LABEL_10;
3447 }
3448 LABEL_12:
3449 if ( BYTE2(v3->uAttributes) & 0x80 )
3450 {
3451 a2->x = -a2->x;
3452 a2->y = -a2->y;
3453 a2->z = -a2->z;
3454 }
3455 if ( BYTE3(v3->uAttributes) & 1 )
3456 {
3457 a3->x = -a3->x;
3458 a3->y = -a3->y;
3459 a3->z = -a3->z;
3460 }
3461 return v4;
3462 }
3463
3464 //----- (0044C23B) --------------------------------------------------------
3465 int BLVFaceExtra::HasEventint()
3466 {
3467 signed int v1; // eax@1
3468 Event *v2; // esi@2
3469 signed int result; // eax@5
3470 signed int v4; // eax@6
3471
3472 v1 = 0;
3473 if ( (signed int)(uLevelEVT_NumEvents - 1) <= 0 )
3474 goto LABEL_5;
3475 v2 = pLevelEVT_Events;
3476 while ( v2->uEventID != this->uEventID )
3477 {
3478 ++v1;
3479 ++v2;
3480 if ( v1 >= (signed int)(uLevelEVT_NumEvents - 1) )
3481 goto LABEL_5;
3482 }
3483 v4 = v1;
3484 if ( pLevelEVT[pLevelEVT_Events[v4 + 1].uEventOffsetInEVT + 4] != 1
3485 || pLevelEVT[pLevelEVT_Events[v4].uEventOffsetInEVT + 4] != 4 )
3486 LABEL_5:
3487 result = 0;
3488 else
3489 result = 1;
3490 return result;
3491 }
3492
3493
3494
3495
3496 //----- (0046F228) --------------------------------------------------------
3497 void __cdecl BLV_UpdateDoors()
3498 {
3499 int v0; // ebx@1
3500 int v1; // edi@1
3501 BLVDoor *v2; // esi@3
3502 unsigned __int16 v3; // ax@3
3503 unsigned int v4; // ecx@5
3504 int v5; // eax@8
3505 int v6; // ecx@8
3506 int v7; // eax@12
3507 int v8; // eax@16
3508 unsigned __int8 v9; // zf@18
3509 char v10; // sf@18
3510 unsigned __int8 v11; // of@18
3511 int v12; // edi@19
3512 int v13; // ecx@19
3513 __int16 v14; // ax@19
3514 BLVFace *v15; // ebx@24
3515 unsigned __int16 *v16; // ecx@24
3516 Vec3_short_ *v17; // esi@24
3517 int v18; // eax@24
3518 int v19; // edx@24
3519 signed int v20; // eax@24
3520 Vec3_short_ *v21; // ecx@24
3521 double v22; // st7@24
3522 double v23; // st6@24
3523 int v24; // esi@25
3524 int v25; // eax@25
3525 BLVDoor *v26; // edi@25
3526 signed __int64 v27; // qtt@27
3527 BLVFaceExtra *v28; // esi@32
3528 int v29; // ecx@34
3529 int v30; // edx@34
3530 unsigned __int64 v31; // qax@34
3531 int v32; // eax@34
3532 unsigned __int16 *v33; // eax@35
3533 Vec3_short_ *v34; // eax@35
3534 int v35; // ecx@35
3535 int v36; // edx@35
3536 signed int v37; // eax@35
3537 signed int v38; // edx@35
3538 int v39; // eax@35
3539 int v40; // edx@35
3540 unsigned __int8 v41; // cf@35
3541 unsigned __int16 *v42; // edi@36
3542 Vec3_short_ *v43; // edi@36
3543 int v44; // ecx@36
3544 int v45; // edi@36
3545 int v46; // ecx@36
3546 __int16 *v47; // edx@44
3547 int v48; // ecx@44
3548 unsigned int v49; // ecx@46
3549 unsigned __int16 v50; // ax@48
3550 unsigned int v51; // eax@51
3551 unsigned __int16 v52; // ax@54
3552 int v53; // ecx@57
3553 int v54; // edx@57
3554 unsigned __int64 v55; // qax@57
3555 int v56; // ecx@58
3556 int v57; // eax@58
3557 int v58; // eax@59
3558 SoundID v59; // [sp-24h] [bp-88h]@12
3559 signed int v60; // [sp-20h] [bp-84h]@12
3560 unsigned int v61; // [sp-1Ch] [bp-80h]@12
3561 signed int v62; // [sp-18h] [bp-7Ch]@12
3562 signed int v63; // [sp-14h] [bp-78h]@12
3563 int v64; // [sp-10h] [bp-74h]@12
3564 unsigned int v65; // [sp-Ch] [bp-70h]@12
3565 int v66; // [sp-8h] [bp-6Ch]@12
3566 int v67; // [sp+8h] [bp-5Ch]@31
3567 int v68; // [sp+Ch] [bp-58h]@34
3568 int v69; // [sp+10h] [bp-54h]@34
3569 int v70; // [sp+14h] [bp-50h]@31
3570 int v71; // [sp+18h] [bp-4Ch]@34
3571 int v72; // [sp+1Ch] [bp-48h]@34
3572 int v73; // [sp+20h] [bp-44h]@24
3573 __int16 v74; // [sp+24h] [bp-40h]@24
3574 int v75; // [sp+28h] [bp-3Ch]@36
3575 int v76; // [sp+2Ch] [bp-38h]@36
3576 int v77; // [sp+30h] [bp-34h]@36
3577 int v78; // [sp+34h] [bp-30h]@36
3578 int v79; // [sp+38h] [bp-2Ch]@19
3579 unsigned int v80; // [sp+3Ch] [bp-28h]@2
3580 int v81; // [sp+40h] [bp-24h]@1
3581 int v82; // [sp+44h] [bp-20h]@35
3582 int v83; // [sp+48h] [bp-1Ch]@34
3583 int v84; // [sp+4Ch] [bp-18h]@34
3584 int v85; // [sp+50h] [bp-14h]@19
3585 SoundID eDoorSoundID; // [sp+54h] [bp-10h]@1
3586 BLVDoor *v87; // [sp+58h] [bp-Ch]@3
3587 int v88; // [sp+5Ch] [bp-8h]@18
3588 int v89; // [sp+60h] [bp-4h]@6
3589
3590 v0 = 0;
3591 v1 = 0;
3592 eDoorSoundID = (SoundID)pDoorSoundIDsByLocationID[dword_6BE13C_uCurrentlyLoadedLocationID];
3593 v81 = 0;
3594 if ( pIndoor->uNumDoors > 0 )
3595 {
3596 v80 = 0;
3597 do
3598 {
3599 v2 = &pIndoor->pDoors[v80 / 0x50];
3600 v87 = &pIndoor->pDoors[v80 / 0x50];
3601 v3 = pIndoor->pDoors[v80 / 0x50].uState;
3602 if ( v3 == (short)v0 || v3 == 2 )
3603 {
3604 v2->uAttributes &= 0xFFFFFFFDu;
3605 goto LABEL_62;
3606 }
3607 v2->uTimeSinceTriggered += pEventTimer->uTimeElapsed;
3608 v4 = v2->uTimeSinceTriggered;
3609 if ( v2->uState == 1 )
3610 {
3611 v89 = (signed int)(v4 * v2->uCloseSpeed) / 128;
3612 if ( v89 >= v2->uMoveLength )
3613 {
3614 v89 = v2->uMoveLength;
3615 v2->uState = BLVDoor::Open;
3616 LABEL_10:
3617 if ( !(v2->uAttributes & 6) && v2->uNumVertices != (short)v0 )
3618 {
3619 v66 = v0;
3620 v65 = v0;
3621 v64 = v0;
3622 v7 = 8 * v1;
3623 v63 = v0;
3624 v62 = -1;
3625 LOBYTE(v7) = 8 * v1 | 1;
3626 v61 = v0;
3627 v60 = v7;
3628 v59 = (SoundID)((int)eDoorSoundID + 1);
3629 LABEL_17:
3630 pAudioPlayer->PlaySound(v59, v60, v61, v62, v63, v64, v65, v66);
3631 goto LABEL_18;
3632 }
3633 goto LABEL_18;
3634 }
3635 }
3636 else
3637 {
3638 v5 = (signed int)(v4 * v2->uOpenSpeed) / 128;
3639 v6 = v2->uMoveLength;
3640 if ( v5 >= v6 )
3641 {
3642 v89 = v0;
3643 v2->uState = (BLVDoor::State)v0;
3644 goto LABEL_10;
3645 }
3646 v89 = v6 - v5;
3647 }
3648 if ( !(v2->uAttributes & 6) && v2->uNumVertices != (short)v0 )
3649 {
3650 v66 = v0;
3651 v65 = v0;
3652 v64 = v0;
3653 v8 = 8 * v1;
3654 v63 = v0;
3655 v62 = -1;
3656 LOBYTE(v8) = 8 * v1 | 1;
3657 v61 = 1;
3658 v60 = v8;
3659 v59 = eDoorSoundID;
3660 goto LABEL_17;
3661 }
3662 LABEL_18:
3663 v11 = __OFSUB__(v2->uNumVertices, (short)v0);
3664 v9 = v2->uNumVertices == (short)v0;
3665 v10 = (signed __int16)(v2->uNumVertices - v0) < 0;
3666 v88 = v0;
3667 if ( !((unsigned __int8)(v10 ^ v11) | v9) )
3668 {
3669 do
3670 {
3671 v12 = v88;
3672 v13 = v2->pVertexIDs[v88];
3673 v85 = v89;
3674 v79 = v2->vDirection.x;
3675 v85 = (unsigned __int64)(v79 * (signed __int64)v89) >> 16;
3676 v13 *= 6;
3677 *(__int16 *)((char *)&pIndoor->pVertices->x + v13) = ((unsigned int)(v79 * v89) >> 16) + v2->pXOffsets[v88];
3678 v85 = v89;
3679 v79 = v2->vDirection.y;
3680 v85 = (unsigned __int64)(v79 * (signed __int64)v89) >> 16;
3681 *(__int16 *)((char *)&pIndoor->pVertices->y + v13) = ((unsigned int)(v79 * v89) >> 16) + v2->pYOffsets[v12];
3682 v85 = v89;
3683 v79 = v2->vDirection.z;
3684 v85 = (unsigned __int64)(v79 * (signed __int64)v89) >> 16;
3685 v14 = ((unsigned int)(v79 * v89) >> 16) + v2->pZOffsets[v12];
3686 ++v88;
3687 *(__int16 *)((char *)&pIndoor->pVertices->z + v13) = v14;
3688 }
3689 while ( v88 < v2->uNumVertices );
3690 v1 = v81;
3691 }
3692 v11 = __OFSUB__(v2->uNumFaces, (short)v0);
3693 v9 = v2->uNumFaces == (short)v0;
3694 v10 = (signed __int16)(v2->uNumFaces - v0) < 0;
3695 v88 = v0;
3696 if ( !((unsigned __int8)(v10 ^ v11) | v9) )
3697 {
3698 while ( 1 )
3699 {
3700 v15 = &pIndoor->pFaces[v2->pFaceIDs[v88]];
3701 v16 = v15->pVertexIDs;
3702 v17 = &pIndoor->pVertices[*v16];
3703 v18 = v15->pFacePlane_old.vNormal.y;
3704 v73 = *(int *)&v17->x;
3705 v74 = v17->z;
3706 v19 = v15->pFacePlane_old.vNormal.z;
3707 v20 = -(v19 * v74 + (signed __int16)v73 * v15->pFacePlane_old.vNormal.x + SHIWORD(v73) * v18);
3708 v15->pFacePlane_old.dist = v20;
3709 v21 = &pIndoor->pVertices[*v16];
3710 v79 = v21->x;
3711 v22 = (double)v79;
3712 v23 = (double)v21->y;
3713 v79 = v21->z;
3714 v15->pFacePlane.dist = -((double)v79 * v15->pFacePlane.vNormal.z
3715 + v23 * v15->pFacePlane.vNormal.y
3716 + v22 * v15->pFacePlane.vNormal.x);
3717 if ( v19 )
3718 {
3719 v24 = abs(v20 >> 15);
3720 v25 = abs(v15->pFacePlane_old.vNormal.z);
3721 v26 = v87;
3722 if ( v24 > v25 )
3723 Abortf(
3724 "Door Error\ndoor id: %i\nfacet no: %i\n\nOverflow dividing facet->d [%i] by facet->nz [%i]",
3725 v87->uDoorID,
3726 v87->pFaceIDs[v88],
3727 v15->pFacePlane_old.dist,
3728 v15->pFacePlane_old.vNormal.z);
3729 v79 = v15->pFacePlane_old.vNormal.z;
3730 v85 = v15->pFacePlane_old.dist;
3731 LODWORD(v27) = v85 << 16;
3732 HIDWORD(v27) = v85 >> 16;
3733 v85 = v27 / v79;
3734 v15->zCalc3 = -(v27 / v79);
3735 }
3736 else
3737 {
3738 v26 = v87;
3739 }
3740 if ( BYTE2(v15->uAttributes) & 4 || pRenderer->pRenderD3D )
3741 v15->_get_normals((Vec3_int_ *)&v70, (Vec3_int_ *)&v67);
3742 v28 = &pIndoor->pFaceExtras[v15->uFaceExtraID];
3743 if ( !pRenderer->pRenderD3D )
3744 {
3745 if ( !(BYTE2(v15->uAttributes) & 4) )
3746 goto LABEL_59;
3747 v79 = v26->vDirection.x;
3748 v83 = (unsigned __int64)(v79 * (signed __int64)v70) >> 16;
3749 v85 = v71;
3750 v79 = v26->vDirection.y;
3751 v85 = (unsigned __int64)(v79 * (signed __int64)v71) >> 16;
3752 v84 = v72;
3753 v79 = v26->vDirection.z;
3754 v84 = (unsigned __int64)(v79 * (signed __int64)v72) >> 16;
3755 v79 = v83 + v85 + ((unsigned __int64)(v79 * (signed __int64)v72) >> 16);
3756 v29 = v89;
3757 v83 = (unsigned __int64)(v79 * (signed __int64)v89) >> 16;
3758 v28->sTextureDeltaU = -((unsigned int)(v79 * v89) >> 16);
3759 v79 = v26->vDirection.x;
3760 v85 = (unsigned __int64)(v79 * (signed __int64)v67) >> 16;
3761 v83 = v68;
3762 v79 = v26->vDirection.y;
3763 v83 = (unsigned __int64)(v79 * (signed __int64)v68) >> 16;
3764 v84 = v69;
3765 v79 = v26->vDirection.z;
3766 v84 = (unsigned __int64)(v79 * (signed __int64)v69) >> 16;
3767 v30 = v83 + ((unsigned __int64)(v79 * (signed __int64)v69) >> 16);
3768 v79 = v85 + v30;
3769 v31 = (v85 + v30) * (signed __int64)v29;
3770 v83 = v31 >> 16;
3771 v32 = v31 >> 16;
3772 goto LABEL_58;
3773 }
3774 v28->sTextureDeltaU = 0;
3775 v28->sTextureDeltaV = 0;
3776 v33 = v15->pVertexIDs;
3777 v85 = 1;
3778 v34 = &pIndoor->pVertices[*v33];
3779 v35 = v34->z;
3780 v36 = v34->y;
3781 v82 = v34->x;
3782 v79 = v36;
3783 v37 = v70 * v82 + v71 * v36 + v72 * v35;
3784 v38 = v67 * v82 + v68 * v36 + v35 * v69;
3785 v39 = v37 >> 16;
3786 *v15->pVertexUIDs = v39;
3787 v40 = v38 >> 16;
3788 *v15->pVertexVIDs = v40;
3789 v41 = v15->uNumVertices < 1u;
3790 v9 = v15->uNumVertices == 1;
3791 v83 = v40;
3792 v84 = v39;
3793 v82 = v40;
3794 if ( !(v41 | v9) )
3795 {
3796 do
3797 {
3798 v42 = v15->pVertexIDs;
3799 v75 = 2 * v85;
3800 v43 = &pIndoor->pVertices[v42[v85]];
3801 v79 = v43->z;
3802 v44 = v43->y;
3803 v45 = v43->x;
3804 v78 = v44;
3805 v76 = (v72 * v79 + v70 * v45 + v71 * v44) >> 16;
3806 v46 = (v67 * v45 + v68 * v44 + v79 * v69) >> 16;
3807 v77 = v46;
3808 if ( v76 < v39 )
3809 v39 = v76;
3810 if ( v46 < v40 )
3811 v83 = v46;
3812 if ( v76 > v84 )
3813 v84 = v76;
3814 if ( v46 > v82 )
3815 v82 = v46;
3816 v47 = v15->pVertexUIDs;
3817 v48 = v75;
3818 ++v85;
3819 *(unsigned __int16 *)((char *)v47 + v75) = v76;
3820 *(unsigned __int16 *)((char *)v15->pVertexVIDs + v48) = v77;
3821 v40 = v83;
3822 }
3823 while ( v85 < v15->uNumVertices );
3824 v26 = v87;
3825 }
3826 v49 = v15->uAttributes;
3827 if ( BYTE1(v49) & 0x10 )
3828 goto LABEL_50;
3829 if ( SBYTE1(v49) < 0 )
3830 {
3831 v50 = v15->uBitmapID;
3832 if ( v50 != -1 )
3833 break;
3834 }
3835 LABEL_51:
3836 v51 = v15->uAttributes;
3837 if ( v51 & 8 )
3838 {
3839 v28->sTextureDeltaV -= v40;
3840 }
3841 else
3842 {
3843 if ( v51 & 0x20000 )
3844 {
3845 v52 = v15->uBitmapID;
3846 if ( v52 != -1 )
3847 v28->sTextureDeltaV -= v82
3848 + *(short *)((signed __int16)v52 != -1 ? 72 * (signed __int16)v52 + 7278780 + 0x1A : 26);
3849 }
3850 }
3851 if ( BYTE2(v15->uAttributes) & 4 )
3852 {
3853 v75 = v26->vDirection.x;
3854 v84 = (unsigned __int64)(v75 * (signed __int64)v70) >> 16;
3855 v82 = v71;
3856 v75 = v26->vDirection.y;
3857 v82 = (unsigned __int64)(v75 * (signed __int64)v71) >> 16;
3858 v83 = v72;
3859 v75 = v26->vDirection.z;
3860 v83 = (unsigned __int64)(v75 * (signed __int64)v72) >> 16;
3861 v75 = v84 + v82 + ((unsigned __int64)(v75 * (signed __int64)v72) >> 16);
3862 v53 = v89;
3863 v82 = (unsigned __int64)(v75 * (signed __int64)v89) >> 16;
3864 v28->sTextureDeltaU = -((unsigned int)(v75 * v89) >> 16);
3865 v75 = v26->vDirection.x;
3866 v84 = (unsigned __int64)(v75 * (signed __int64)v67) >> 16;
3867 v82 = v68;
3868 v75 = v26->vDirection.y;
3869 v82 = (unsigned __int64)(v75 * (signed __int64)v68) >> 16;
3870 v83 = v69;
3871 v75 = v26->vDirection.z;
3872 v83 = (unsigned __int64)(v75 * (signed __int64)v69) >> 16;
3873 v54 = v82 + ((unsigned __int64)(v75 * (signed __int64)v69) >> 16);
3874 v75 = v84 + v54;
3875 v55 = (v84 + v54) * (signed __int64)v53;
3876 v82 = v55 >> 16;
3877 v32 = v55 >> 16;
3878 LABEL_58:
3879 v56 = v88;
3880 v57 = -v32;
3881 v28->sTextureDeltaV = v57;
3882 v28->sTextureDeltaU += v26->pDeltaUs[v56];
3883 v28->sTextureDeltaV = v57 + v26->pDeltaVs[v56];
3884 }
3885 LABEL_59:
3886 v58 = v26->uNumFaces;
3887 ++v88;
3888 if ( v88 >= v58 )
3889 {
3890 v1 = v81;
3891 v0 = 0;
3892 goto LABEL_62;
3893 }
3894 v2 = v87;
3895 }
3896 LOWORD(v39) = v84
3897 + ((signed __int16)v39 != -1 ? pBitmaps_LOD->pTextures[(signed __int16)v39].uTextureWidth : 24);
3898 LABEL_50:
3899 v28->sTextureDeltaU -= v39;
3900 goto LABEL_51;
3901 }
3902 LABEL_62:
3903 v80 += 80;
3904 ++v1;
3905 v81 = v1;
3906 }
3907 while ( v1 < pIndoor->uNumDoors );
3908 }
3909 }
3910 // 6BE13C: using guessed type int dword_6BE13C_uCurrentlyLoadedLocationID;
3911
3912 //----- (0046F90C) --------------------------------------------------------
3913 void __cdecl UpdateActors_BLV()
3914 {
3915 Actor *v0; // esi@2
3916 unsigned __int16 v1; // ax@2
3917 int v2; // edi@6
3918 int v3; // eax@6
3919 int v4; // eax@8
3920 __int16 v5; // ax@11
3921 signed int v6; // ebx@14
3922 unsigned __int8 v7; // zf@14
3923 unsigned __int8 v8; // sf@14
3924 signed __int16 v9; // ax@17
3925 signed __int64 v10; // qax@18
3926 unsigned __int16 v11; // ax@21
3927 int v12; // eax@29
3928 unsigned __int64 v13; // qax@29
3929 int v14; // eax@30
3930 unsigned __int64 v15; // qax@30
3931 int v16; // ecx@33
3932 BLVFace *v17; // edx@33
3933 int v18; // ecx@33
3934 BLVFace *v19; // eax@34
3935 int v20; // ecx@46
3936 int v21; // eax@46
3937 int v22; // edi@46
3938 int v23; // eax@48
3939 unsigned int v24; // eax@51
3940 int v25; // eax@52
3941 int v26; // ebx@54
3942 int v27; // ST08_4@54
3943 int v28; // edi@54
3944 int v29; // eax@54
3945 int v30; // ecx@62
3946 int v31; // ebx@62
3947 int v32; // eax@62
3948 int v33; // eax@64
3949 unsigned int v34; // ecx@64
3950 int v35; // ecx@64
3951 signed int v36; // edx@85
3952 signed int v37; // ebx@85
3953 BLVFace *v38; // edi@89
3954 int v39; // ecx@90
3955 int v40; // ebx@90
3956 PolygonType v41; // al@94
3957 int v42; // eax@96
3958 __int16 v43; // dx@96
3959 int v44; // ecx@96
3960 int v45; // edi@101
3961 int v46; // edi@101
3962 int v47; // eax@101
3963 unsigned __int64 v48; // qax@101
3964 unsigned __int8 v49; // zf@103
3965 unsigned __int8 v50; // sf@103
3966 unsigned __int8 v51; // of@103
3967 AIDirection v52; // [sp+0h] [bp-60h]@75
3968 AIDirection v53; // [sp+1Ch] [bp-44h]@116
3969 int v54; // [sp+38h] [bp-28h]@53
3970 unsigned int uSectorID; // [sp+3Ch] [bp-24h]@6
3971 int v56; // [sp+40h] [bp-20h]@6
3972 unsigned int _this; // [sp+44h] [bp-1Ch]@51
3973 int v58; // [sp+48h] [bp-18h]@51
3974 int v59; // [sp+4Ch] [bp-14h]@8
3975 unsigned int uFaceID; // [sp+50h] [bp-10h]@6
3976 int v61; // [sp+54h] [bp-Ch]@14
3977 int v62; // [sp+58h] [bp-8h]@6
3978 unsigned int v63; // [sp+5Ch] [bp-4h]@1
3979
3980 v63 = 0;
3981 if ( (signed int)uNumActors > 0 )
3982 {
3983 while ( 1 )
3984 {
3985 v0 = &pActors[v63];
3986 v1 = v0->uAIState;
3987 if ( v1 == 11 || v1 == 19 || v1 == 17 || !v0->uMovementSpeed )
3988 goto LABEL_123;
3989 uSectorID = v0->uSectorID;
3990 v2 = _46ED1B_collide_against_floor(v0->vPosition.x, v0->vPosition.y, v0->vPosition.z, &uSectorID, &uFaceID);
3991 v0->uSectorID = uSectorID;
3992 v3 = v0->pMonsterInfo.uFlying;
3993 v56 = v2;
3994 v62 = v3;
3995 if ( !v0->CanAct() )
3996 v62 = 0;
3997 v4 = v0->vPosition.z;
3998 v59 = 0;
3999 if ( v4 > v2 + 1 )
4000 v59 = 1;
4001 if ( v2 <= -30000 )
4002 {
4003 v5 = pIndoor->GetSector(v0->vPosition.x, v0->vPosition.y, v4);
4004 v0->uSectorID = v5;
4005 if ( !v5
4006 || (v56 = _46CEC3_get_floor_level(v0->vPosition.x, v0->vPosition.y, v0->vPosition.z, v5, &uFaceID), v56 == -30000) )
4007 goto LABEL_123;
4008 }
4009 if ( v0->uCurrentActionAnimation == 1 )
4010 {
4011 v6 = v0->uMovementSpeed;
4012 v7 = HIDWORD(v0->pActorBuffs[7].uExpireTime) == 0;
4013 v8 = SHIDWORD(v0->pActorBuffs[7].uExpireTime) < 0;
4014 v61 = v0->uMovementSpeed;
4015 if ( !v8 && (!(v8 | v7) || LODWORD(v0->pActorBuffs[7].uExpireTime)) )
4016 {
4017 v9 = v0->pActorBuffs[7].uPower;
4018 if ( v9 )
4019 LODWORD(v10) = v6 / (unsigned __int16)v9;
4020 else
4021 v10 = (signed __int64)((double)v61 * 0.5);
4022 v6 = v10;
4023 v61 = v10;
4024 }
4025 v11 = v0->uAIState;
4026 if ( v11 == 6 || v11 == 7 )
4027 {
4028 v6 *= 2;
4029 v61 = v6;
4030 }
4031 if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 1 )
4032 v6 = (signed __int64)((double)v61 * flt_6BE3AC_debug_recmod1_x_1_6);
4033 if ( v6 > 1000 )
4034 v6 = 1000;
4035 v12 = stru_5C6E00->SinCos(v0->uYawAngle);
4036 uSectorID = v12;
4037 v13 = v12 * (signed __int64)v6;
4038 v61 = v13 >> 16;
4039 v0->vVelocity.x = WORD1(v13);
4040 uSectorID = stru_5C6E00->SinCos(v0->uYawAngle - stru_5C6E00->uIntegerHalfPi);
4041 v61 = (unsigned __int64)(uSectorID * (signed __int64)v6) >> 16;
4042 v7 = v62 == 0;
4043 v0->vVelocity.y = (unsigned int)(uSectorID * v6) >> 16;
4044 if ( !v7 )
4045 {
4046 v14 = stru_5C6E00->SinCos(v0->uPitchAngle - stru_5C6E00->uIntegerHalfPi);
4047 uSectorID = v14;
4048 v15 = v14 * (signed __int64)v6;
4049 v61 = v15 >> 16;
4050 v0->vVelocity.z = WORD1(v15);
4051 }
4052 }
4053 else
4054 {
4055 v61 = v0->vVelocity.x;
4056 uSectorID = 55000;
4057 v61 = (unsigned __int64)(55000i64 * v61) >> 16;
4058 v0->vVelocity.x = v61;
4059 v61 = v0->vVelocity.y;
4060 v61 = (unsigned __int64)(uSectorID * (signed __int64)v61) >> 16;
4061 v7 = v62 == 0;
4062 v0->vVelocity.y = v61;
4063 if ( !v7 )
4064 {
4065 uSectorID = 55000;
4066 v61 = v0->vVelocity.z;
4067 v61 = (unsigned __int64)(55000i64 * v61) >> 16;
4068 v0->vVelocity.z = v61;
4069 }
4070 }
4071 v16 = v0->vPosition.z;
4072 v17 = pIndoor->pFaces;
4073 v51 = __OFSUB__(v16, v56);
4074 v8 = v16 - v56 < 0;
4075 v18 = uFaceID;
4076 if ( v8 ^ v51 )
4077 {
4078 v0->vPosition.z = v56 + 1;
4079 v19 = &v17[v18];
4080 if ( v19->uPolygonType == 3 )
4081 {
4082 if ( v0->vVelocity.z < 0 )
4083 v0->vVelocity.z = 0;
4084 }
4085 else
4086 {
4087 if ( v19->pFacePlane_old.vNormal.z < 45000 )
4088 v0->vVelocity.z -= LOWORD(pEventTimer->uTimeElapsed) * GetGravityStrength();
4089 }
4090 }
4091 else
4092 {
4093 if ( v59 && !v62 )
4094 v0->vVelocity.z += -8 * LOWORD(pEventTimer->uTimeElapsed) * GetGravityStrength();
4095 }
4096 if ( v0->vVelocity.x * v0->vVelocity.x + v0->vVelocity.y * v0->vVelocity.y + v0->vVelocity.z * v0->vVelocity.z >= 400 )
4097 break;
4098 v0->vVelocity.z = 0;
4099 v0->vVelocity.y = 0;
4100 v0->vVelocity.x = 0;
4101 if ( BYTE2(v17[v18].uAttributes) & 0x40 )
4102 {
4103 if (v0->uAIState == Dead)
4104 v0->uAIState = Removed;
4105 }
4106 LABEL_123:
4107 ++v63;
4108 if ( (signed int)v63 >= (signed int)uNumActors )
4109 return;
4110 }
4111 v20 = v0->uActorRadius;
4112 v21 = v0->uActorHeight;
4113 stru_721530.field_84 = -1;
4114 stru_721530.field_70 = 0;
4115 uSectorID = 0;
4116 stru_721530.field_0 = 1;
4117 stru_721530.field_8 = v20;
4118 stru_721530.prolly_normal_d = v20;
4119 stru_721530.field_C = v21;
4120 v22 = 0;
4121 while ( 1 )
4122 {
4123 stru_721530.field_34.x = v0->vPosition.x;
4124 stru_721530.normal.x = stru_721530.field_34.x;
4125 stru_721530.field_34.y = v0->vPosition.y;
4126 stru_721530.normal.y = stru_721530.field_34.y;
4127 v23 = v0->vPosition.z;
4128 stru_721530.normal.z = v23 + v20 + 1;
4129 stru_721530.field_34.z = v23 - v20 + stru_721530.field_C - 1;
4130 if ( stru_721530.field_34.z < stru_721530.normal.z )
4131 stru_721530.field_34.z = v23 + v20 + 1;
4132 stru_721530.field_1C = v0->vVelocity.x;
4133 stru_721530.field_20 = v0->vVelocity.y;
4134 stru_721530.field_24 = v0->vVelocity.z;
4135 stru_721530.uSectorID = v0->uSectorID;
4136 if ( !stru_721530._47050A(v22) )
4137 {
4138 v58 = v22;
4139 v24 = 8 * v63;
4140 LOBYTE(v24) = 8 * v63 | 3;
4141 v61 = v22;
4142 _this = v24;
4143 do
4144 {
4145 _46E44E_collide_against_faces_and_portals(1u);
4146 _46E0B2_collide_against_decorations();
4147 _46EF01_collision_chech_player(0);
4148 _46ED8A_collide_against_layingItems(_this);
4149 v25 = 0;
4150 v56 = 0;
4151 if ( ai_arrays_size > v22 )
4152 {
4153 do
4154 {
4155 v54 = ai_array_4F7DB0_actor_ids[v25];
4156 if ( v54 != v63 )
4157 {
4158 v26 = v54;
4159 v27 = abs(pActors[v54].vPosition.z - v0->vPosition.z);
4160 v28 = abs(pActors[v26].vPosition.y - v0->vPosition.y);
4161 v29 = abs(pActors[v26].vPosition.x - v0->vPosition.x);
4162 if ( sub_4621DA(v29, v28, v27) >= v0->uActorRadius + (signed int)pActors[v26].uActorRadius
4163 && _46DF1A_collide_against_actor(v54, 40) )
4164 ++v58;
4165 v22 = 0;
4166 }
4167 v25 = v56++ + 1;
4168 }
4169 while ( v56 < ai_arrays_size );
4170 }
4171 if ( _46F04E_collide_against_portals() )
4172 break;
4173 ++v61;
4174 }
4175 while ( v61 < 100 );
4176 v56 = v58 > 1;
4177 if ( stru_721530.field_7C >= stru_721530.field_6C )
4178 {
4179 v30 = stru_721530.normal2.x;
4180 v31 = stru_721530.normal2.y;
4181 v32 = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
4182 }
4183 else
4184 {
4185 v58 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.x) >> 16;
4186 v30 = v58 + v0->vPosition.x;
4187 v58 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.y) >> 16;
4188 v31 = v58 + v0->vPosition.y;
4189 v58 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16;
4190 v32 = v58 + v0->vPosition.z;
4191 }
4192 v33 = _46ED1B_collide_against_floor(v30, v31, v32, &stru_721530.uSectorID, &uFaceID);
4193 v34 = pIndoor->pFaces[uFaceID].uAttributes;
4194 v35 = v34 & 0x400000;
4195 if (v35 && v0->uAIState == Dead)
4196 {
4197 v0->uAIState = Removed;
4198 goto LABEL_120;
4199 }
4200 if ( v59 != v22 || v62 != v22 || v35 == v22 )
4201 {
4202 if ( v33 == -30000 )
4203 goto LABEL_120;
4204 if ( v0->uCurrentActionAnimation != 1 || v33 >= v0->vPosition.z - 100 || v59 != v22 || v62 != v22 )
4205 {
4206 if ( stru_721530.field_7C >= stru_721530.field_6C )
4207 {
4208 v0->vPosition.x = LOWORD(stru_721530.normal2.x);
4209 v0->vPosition.y = LOWORD(stru_721530.normal2.y);
4210 v0->vPosition.z = LOWORD(stru_721530.normal2.z) - LOWORD(stru_721530.prolly_normal_d) - 1;
4211 v0->uSectorID = LOWORD(stru_721530.uSectorID);
4212 goto LABEL_123;
4213 }
4214 v58 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.x) >> 16;
4215 v0->vPosition.x += (unsigned int)(stru_721530.field_7C * stru_721530.field_58.x) >> 16;
4216 v58 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.y) >> 16;
4217 v0->vPosition.y += (unsigned int)(stru_721530.field_7C * stru_721530.field_58.y) >> 16;
4218 v58 = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16;
4219 v36 = stru_721530.uFaceID;
4220 v0->vPosition.z += (unsigned int)(stru_721530.field_7C * stru_721530.field_58.z) >> 16;
4221 v0->uSectorID = LOWORD(stru_721530.uSectorID);
4222 stru_721530.field_70 += stru_721530.field_7C;
4223 v37 = v36 >> 3;
4224 if ( (v36 & 7) != 3 )
4225 {
4226 if ( (v36 & 7) != 4 )
4227 {
4228 if ( (v36 & 7) == 5 )
4229 {
4230 _this = sub_452A9E(v0->vVelocity.x * v0->vVelocity.x + v0->vVelocity.y * v0->vVelocity.y);
4231 v45 = stru_5C6E00->Atan2(
4232 v0->vPosition.x - pLevelDecorations[v37].vPosition.x,
4233 v0->vPosition.y - pLevelDecorations[v37].vPosition.y);
4234 v54 = stru_5C6E00->SinCos(v45);
4235 v56 = (unsigned __int64)(v54 * (signed __int64)(signed int)_this) >> 16;
4236 v46 = v45 - stru_5C6E00->uIntegerHalfPi;
4237 v0->vVelocity.x = v54 * _this >> 16;
4238 v47 = stru_5C6E00->SinCos(v46);
4239 v54 = v47;
4240 v48 = v47 * (signed __int64)(signed int)_this;
4241 v56 = v48 >> 16;
4242 v0->vVelocity.y = WORD1(v48);
4243 goto LABEL_119;
4244 }
4245 if ( (v36 & 7) == 6 )
4246 {
4247 stru_721530.field_84 = v36 >> 3;
4248 v38 = &pIndoor->pFaces[v37];
4249 if ( v38->uPolygonType == 3 )
4250 {
4251 v39 = v0->vVelocity.x;
4252 v40 = v0->vVelocity.y * v0->vVelocity.y;
4253 v0->vVelocity.z = 0;
4254 v0->vPosition.z = pIndoor->pVertices[*v38->pVertexIDs].z + 1;
4255 if ( v39 * v39 + v40 < 400 )
4256 {
4257 v0->vVelocity.y = 0;
4258 v0->vVelocity.x = 0;
4259 goto LABEL_119;
4260 }
4261 }
4262 else
4263 {
4264 v61 = abs(v38->pFacePlane_old.vNormal.x * v0->vVelocity.x + v38->pFacePlane_old.vNormal.y
4265 * v0->vVelocity.y
4266 + v38->pFacePlane_old.vNormal.z
4267 * v0->vVelocity.z) >> 16;
4268 if ( stru_721530.field_64 >> 3 > v61 )
4269 v61 = stru_721530.field_64 >> 3;
4270 v58 = v38->pFacePlane_old.vNormal.x;
4271 v58 = (unsigned __int64)(v61 * (signed __int64)v58) >> 16;
4272 _this = v38->pFacePlane_old.vNormal.y;
4273 _this = (unsigned __int64)(v61 * (signed __int64)(signed int)_this) >> 16;
4274 v56 = v38->pFacePlane_old.vNormal.z;
4275 v56 = (unsigned __int64)(v61 * (signed __int64)v56) >> 16;
4276 v0->vVelocity.x += v58;
4277 v0->vVelocity.y += _this;
4278 v0->vVelocity.z += v56;
4279 v41 = v38->uPolygonType;
4280 if ( v41 != 4 && v41 != 3 )
4281 {
4282 v42 = v38->pFacePlane_old.vNormal.x;
4283 v43 = v0->vPosition.z;
4284 v44 = stru_721530.prolly_normal_d
4285 - ((v38->pFacePlane_old.dist
4286 + v38->pFacePlane_old.vNormal.z * v0->vPosition.z
4287 + v38->pFacePlane_old.vNormal.y * v0->vPosition.y
4288 + v42 * v0->vPosition.x) >> 16);
4289 if ( v44 > 0 )
4290 {
4291 v0->vPosition.x += (unsigned int)(v44 * v42) >> 16;
4292 v0->vPosition.y += (unsigned int)(v44 * v38->pFacePlane_old.vNormal.y) >> 16;
4293 v0->vPosition.z = v43 + ((unsigned int)(v44 * v38->pFacePlane_old.vNormal.z) >> 16);
4294 }
4295 v0->uYawAngle = stru_5C6E00->Atan2(v0->vVelocity.x, v0->vVelocity.y);
4296 }
4297 }
4298 if ( BYTE3(v38->uAttributes) & 8 )
4299 EventProcessor(pIndoor->pFaceExtras[v38->uFaceExtraID].uEventID, 0, 1);
4300 }
4301 LABEL_119:
4302 v56 = v0->vVelocity.x;
4303 v54 = 58500;
4304 v56 = (unsigned __int64)(58500i64 * v56) >> 16;
4305 v0->vVelocity.x = v56;
4306 v56 = v0->vVelocity.y;
4307 v56 = (unsigned __int64)(v54 * (signed __int64)v56) >> 16;
4308 v54 = 58500;
4309 v0->vVelocity.y = v56;
4310 v56 = v0->vVelocity.z;
4311 v56 = (unsigned __int64)(v54 * (signed __int64)v56) >> 16;
4312 v22 = 0;
4313 v0->vVelocity.z = v56;
4314 goto LABEL_120;
4315 }
4316 if ( v0->GetActorsRelation(0) )
4317 {
4318 v51 = __OFSUB__(HIDWORD(pParty->pPartyBuffs[11].uExpireTime), v22);
4319 v49 = HIDWORD(pParty->pPartyBuffs[11].uExpireTime) == v22;
4320 v50 = HIDWORD(pParty->pPartyBuffs[11].uExpireTime) - v22 < 0;
4321 v0->vVelocity.y = v22;
4322 v0->vVelocity.x = v22;
4323 if ( !(v50 ^ v51)
4324 && (!((unsigned __int8)(v50 ^ v51) | v49) || LODWORD(pParty->pPartyBuffs[11].uExpireTime) > v22) )
4325 pParty->pPartyBuffs[11].Reset();
4326 viewparams->bRedrawGameUI = 1;
4327 goto LABEL_119;
4328 }
4329 v36 = stru_721530.uFaceID;
4330 LABEL_118:
4331 Actor::FaceObject(v63, v36, v22, (AIDirection *)v22);
4332 goto LABEL_119;
4333 }
4334 if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->field_4 == 2 || pTurnEngine->field_4 == 3) )
4335 goto LABEL_119;
4336 if ( v0->pMonsterInfo.uHostilityType )
4337 {
4338 if ( v56 == v22 )
4339 goto LABEL_114;
4340 }
4341 else
4342 {
4343 if ( v56 == v22 )
4344 {
4345 if ( !pActors[v37].pMonsterInfo.uHostilityType )
4346 goto LABEL_118;
4347 LABEL_114:
4348 Actor::_402968(v63, v36, v22, (AIDirection *)v22);
4349 goto LABEL_119;
4350 }
4351 }
4352 Actor::_403F58(v63, 4, v22, &v53);
4353 goto LABEL_119;
4354 }
4355 if ( v0->vPosition.x & 1 )
4356 v0->uYawAngle += 100;
4357 else
4358 v0->uYawAngle -= 100;
4359 }
4360 else
4361 {
4362 if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->field_4 == 2 || pTurnEngine->field_4 == 3) )
4363 goto LABEL_123;
4364 if ( !v0->pMonsterInfo.uHostilityType || v56 != v22 )
4365 {
4366 Actor::_403F58(v63, 4, v22, &v52);
4367 goto LABEL_123;
4368 }
4369 }
4370 }
4371 LABEL_120:
4372 ++uSectorID;
4373 if ( uSectorID >= 100 )
4374 goto LABEL_123;
4375 v20 = stru_721530.prolly_normal_d;
4376 }
4377 }
4378 }
4379 // 46DF1A: using guessed type int __fastcall 46DF1A_collide_against_actor(int, int);
4380 // 4F75D8: using guessed type int ai_arrays_size;
4381
4382
4383
4384
4385
4386
4387 //----- (00460A78) --------------------------------------------------------
4388 void __thiscall PrepareToLoadBLV(unsigned int bLoading)
4389 {
4390 unsigned int v1; // ebx@1
4391 unsigned int v2; // eax@8
4392 MapInfo *v3; // edi@9
4393 int v4; // eax@11
4394 int v5; // eax@12
4395 int v6; // eax@13
4396 int v7; // esi@27
4397 SpawnPointMM7 *v8; // edx@28
4398 //char v9; // bl@33
4399 //int v10; // eax@34
4400 //char *v11; // ecx@37
4401 //int v12; // edi@44
4402 //unsigned int v13; // edi@48
4403 char *v14; // esi@49
4404 __int16 v15; // ax@50
4405 int v16; // ecx@52
4406 DecorationDesc *v17; // eax@54
4407 int v18; // ecx@55
4408 //int *v19; // edi@58
4409 //unsigned char v20; // dl@58
4410 int v21; // eax@64
4411 char v22; // cl@64
4412 //signed int v23; // ebx@67
4413 //char *v24; // esi@68
4414 //int v25; // eax@70
4415 //char *v26; // esi@78
4416 //int v27; // eax@79
4417 char v28; // zf@81
4418 __int16 v29; // ax@85
4419 signed int v30; // edi@94
4420 int v31; // esi@94
4421 char Args; // [sp+350h] [bp-C4h]@16
4422 int v34[4]; // [sp+3E8h] [bp-2Ch]@96
4423 int v35; // [sp+3F8h] [bp-1Ch]@1
4424 //char b[4]; // [sp+3FCh] [bp-18h]@58
4425 MapInfo *v37; // [sp+400h] [bp-14h]@1
4426 int v38; // [sp+404h] [bp-10h]@1
4427 unsigned int v39; // [sp+408h] [bp-Ch]@8
4428 int pDest; // [sp+40Ch] [bp-8h]@1
4429 //int i; // [sp+410h] [bp-4h]@27
4430
4431 v37 = (MapInfo *)bLoading;
4432 v1 = 0;
4433 v35 = 0;
4434 pGameLoadingUI_ProgressBar->Reset(0x20u);
4435 bUnderwater = 0;
4436 bNoNPCHiring = 0;
4437 v38 = 0;
4438 pDest = 1;
4439 uCurrentlyLoadedLevelType = LEVEL_Indoor;
4440 pGame->uFlags2 &= 0xFFFFFFF7u;
4441 if ( Is_out15odm_underwater() )
4442 {
4443 bUnderwater = 1;
4444 pGame->uFlags2 |= 8u;
4445 }
4446 if ( !_strcmpi(pCurrentMapName, "out15.odm") || !_strcmpi(pCurrentMapName, "d23.blv") )
4447 bNoNPCHiring = 1;
4448 pPaletteManager->pPalette_tintColor[0] = 0;
4449 pPaletteManager->pPalette_tintColor[1] = 0;
4450 pPaletteManager->pPalette_tintColor[2] = 0;
4451 pPaletteManager->RecalculateAll();
4452 if ( qword_A750D8 )
4453 qword_A750D8 = 0i64;
4454 v2 = pMapStats->GetMapInfo(pCurrentMapName);
4455 v39 = v2;
4456 if ( v2 )
4457 {
4458 v3 = &pMapStats->pInfos[v2];
4459 v1 = v3->uRespawnIntervalDays;
4460 v38 = GetAlertStatus();
4461 }
4462 else
4463 {
4464 v3 = v37;
4465 }
4466 dword_6BE13C_uCurrentlyLoadedLocationID = v39;
4467 pAllocator->FreeChunk(ptr_6A0D08);
4468 ptr_6A0D08 = 0;
4469 _6A0D0C_txt_lod_loading = 0;
4470 TryLoadLevelFromLOD();
4471 pStationaryLightsStack->uNumLightsActive = 0;
4472 v4 = pIndoor->Load(
4473 pCurrentMapName,
4474 (unsigned int)(signed __int64)((double)pParty->uTimePlayed * 0.234375) / 60 / 60 / 24 + 1,
4475 v1,
4476 (char *)&pDest)
4477 - 1;
4478 if ( !v4 )
4479 {
4480 sprintf(&Args, "Unable to open %s", pCurrentMapName);
4481 Abortf(&Args);
4482 }
4483 v5 = v4 - 1;
4484 if ( !v5 )
4485 {
4486 sprintf(&Args, "File %s is not a BLV File", pCurrentMapName);
4487 Abortf(&Args);
4488 }
4489 v6 = v5 - 1;
4490 if ( !v6 )
4491 Abortf("Attempt to open new level before clearing old");
4492 if ( v6 == 1 )
4493 Abortf("Out of memory loading indoor level");
4494 if ( !(dword_6BE364_game_settings_1 & 0x2000) )
4495 {
4496 InitializeActors();
4497 InitializeLayingItems();
4498 }
4499 BYTE1(dword_6BE364_game_settings_1) &= 0xDFu;
4500 if ( !v39 )
4501 pDest = 0;
4502 if ( pDest == 1 )
4503 {
4504 v7 = 0;
4505 for (uint i = 0; i < pIndoor->uNumSpawnPoints; ++v7 )
4506 {
4507 v8 = &pIndoor->pSpawnPoints[v7];
4508 if ( pIndoor->pSpawnPoints[v7].uKind == 3 )
4509 SpawnEncounter(v3, v8, 0, 0, 0);
4510 else
4511 v3->SpawnRandomTreasure(v8);
4512 ++i;
4513 }
4514 RespawnGlobalDecorations();
4515 }
4516
4517 pSoundList->LoadSound(pDoorSoundIDsByLocationID[v39], 0);
4518 pSoundList->LoadSound(pDoorSoundIDsByLocationID[v39] + 1, 0);
4519
4520 for (uint i = 0; i < pIndoor->uNumDoors; ++i)
4521 {
4522 auto pDoor = pIndoor->pDoors + i;
4523
4524 if (pDoor->uAttributes & 0x01)
4525 {
4526 pDoor->uState = BLVDoor::Opening;
4527 pDoor->uTimeSinceTriggered = 15360;
4528 pDoor->uAttributes = 2;
4529 }
4530
4531 if (pDoor->uState == BLVDoor::Closed)
4532 {
4533 pDoor->uState = BLVDoor::Closing;
4534 pDoor->uTimeSinceTriggered = 15360;
4535 pDoor->uAttributes = 2;
4536 }
4537 else if (pDoor->uState == BLVDoor::Open)
4538 {
4539 pDoor->uState = BLVDoor::Opening;
4540 pDoor->uTimeSinceTriggered = 15360;
4541 pDoor->uAttributes = 2;
4542 }
4543 }
4544
4545 /*
4546 i = 0;
4547 v9 = 2;
4548 if ( pIndoor->uNumDoors > 0 )
4549 {
4550 v10 = 0;
4551 while ( 1 )
4552 {
4553 if ( pIndoor->pDoors[v10].uAttributes & 1 )
4554 {
4555 pIndoor->pDoors[v10].uState = 1;
4556 pIndoor->pDoors[v10].uTimeSinceTriggered = 15360;
4557 pIndoor->pDoors[v10].uAttributes = 2;
4558 }
4559 v11 = (char *)&pIndoor->pDoors[v10].uState;
4560 if ( !*(short *)v11 )
4561 break;
4562 if ( *(short *)v11 == 2 )
4563 {
4564 *(short *)v11 = 1;
4565 goto LABEL_41;
4566 }
4567 LABEL_42:
4568 ++i;
4569 ++v10;
4570 if ( i >= pIndoor->uNumDoors )
4571 goto LABEL_43;
4572 }
4573 *(short *)v11 = 3;
4574 LABEL_41:
4575 pIndoor->pDoors[v10].uTimeSinceTriggered = 15360;
4576 pIndoor->pDoors[v10].uAttributes = 2;
4577 goto LABEL_42;
4578 }
4579 LABEL_43:
4580 */
4581
4582 for (uint i = 0; i < pIndoor->uNumFaces; ++i)
4583 {
4584 auto pFace = pIndoor->pFaces + i;
4585 if (!pFace->uBitmapID != -1)
4586 pBitmaps_LOD->pTextures[pFace->uBitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[pFace->uBitmapID].palette_id1);
4587 }
4588
4589 /*i = 0;
4590 if ( (signed int)pIndoor->uNumFaces > 0 )
4591 {
4592 v12 = 0;
4593 do
4594 {
4595 if ( pIndoor->pFaces[v12].uBitmapID != -1 )
4596 pBitmaps_LOD->pTextures[pIndoor->pFaces[v12].uBitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[pIndoor->pFaces[v12].uBitmapID].palette_id1);
4597 ++i;
4598 ++v12;
4599 }
4600 while ( i < (signed int)pIndoor->uNumFaces );
4601 }*/
4602
4603
4604 pGameLoadingUI_ProgressBar->Progress();
4605
4606 for (uint i = 0; i < uNumLevelDecorations; ++i)
4607 {
4608 auto pDecortaion = pLevelDecorations + i;
4609
4610 pDecorationList->InitializeDecorationSprite(pDecortaion->uDecorationDescID);
4611
4612 v15 = pDecorationList->pDecorations[pDecortaion->uDecorationDescID].uSoundID;
4613 if (v15 && _6807E0_num_decorations_with_sounds_6807B8 < 9)
4614 {
4615 pSoundList->LoadSound(v15, 0);
4616 v16 = _6807E0_num_decorations_with_sounds_6807B8++;
4617 _6807B8_level_decorations_ids[v16] = i;
4618 }
4619
4620 if ( !(pDecortaion->field_2 & 0x20) )
4621 {
4622 v17 = &pDecorationList->pDecorations[pDecortaion->uDecorationDescID];
4623 if ( !((unsigned __int8)2 & v17->uFlags) )
4624 {
4625 v18 = v17->uLightRadius;
4626 if ( v18 )
4627 {
4628 unsigned char r = 255,
4629 g = 255,
4630 b = 255;
4631 if (pRenderer->pRenderD3D && pRenderer->bUseColoredLights)
4632 {
4633 r = v17->uColoredLightRed;
4634 g = v17->uColoredLightGreen;
4635 b = v17->uColoredLightBlue;
4636 }
4637 pStationaryLightsStack->AddLight(pDecortaion->vPosition.x,
4638 pDecortaion->vPosition.y,
4639 pDecortaion->vPosition.z + v17->uDecorationHeight,
4640 v18,
4641 r,
4642 g,
4643 b,
4644 byte_4E94D0);
4645 }
4646 }
4647 }
4648
4649 if (!pDecortaion->field_16_event_id)
4650 {
4651 if (pDecortaion->IsInteractive())
4652 {
4653 if ( v35 < 124 )
4654 {
4655 v21 = v35 + 1;
4656 pDecortaion->_idx_in_stru123 = v35 + 75;
4657 v22 = stru_5E4C90._decor_events[v21 + 74 - 75];
4658 v35 = v21;
4659 if ( !v22 )
4660 pDecortaion->field_2 |= 0x20;
4661 }
4662 }
4663 }
4664 }
4665
4666 pGameLoadingUI_ProgressBar->Progress();
4667
4668 for (uint i = 0; i < uNumLayingItems; ++i)
4669 {
4670 auto p = pLayingItems + i;
4671 if (p->uObjectDescID)
4672 {
4673 auto uItemID = p->stru_24.uItemID;
4674 if (uItemID)
4675 {
4676 if (uItemID != 220 && pItemsTable->pItems[uItemID].uEquipType == EQUIP_POTION &&
4677 !p->stru_24._bonus_type)
4678 p->stru_24._bonus_type = rand() % 15 + 5;
4679 pItemsTable->SetSpecialBonus(&p->stru_24);
4680 }
4681 }
4682 }
4683
4684 for (uint i = 0; i < uNumActors; ++i)
4685 //if ( (signed int)uNumActors > (signed int)v13 )
4686 {
4687 Actor *pActor = pActors + i;
4688 //v26 = (char *)&pActors[0].uAttributes;
4689 //do
4690 //{
4691 //v27 = *(int *)v26;
4692 if (pActor->uAttributes & 0x100000)
4693 {
4694 if ( !v39 )
4695 {
4696 pActor->pMonsterInfo.field_3E = 19;
4697 pActor->uAttributes |= 0x10000;
4698 continue;
4699 }
4700 v28 = v38 == 0;
4701 }
4702 else
4703 {
4704 v28 = v38 == 1;
4705 }
4706
4707 if ( !v28 )
4708 {
4709 pActor->PrepareSprites(0);
4710 v29 = pActor->pMonsterInfo.field_3E;
4711 pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
4712 if ( v29 != 11 && v29 != 19 && (!pActor->sCurrentHP || !pActor->pMonsterInfo.uHP) )
4713 {
4714 pActor->pMonsterInfo.field_3E = 5;
4715 pActor->UpdateAnimation();
4716 }
4717 }
4718 else
4719 {
4720 pActor->pMonsterInfo.field_3E = 19;
4721 pActor->uAttributes |= 0x10000;
4722 }
4723 //}
4724 //while ( i < (signed int)uNumActors );
4725 }
4726
4727 pGameLoadingUI_ProgressBar->Progress();
4728
4729 Actor this_;
4730 this_.pMonsterInfo.uID = 45;
4731 this_.PrepareSprites(0);
4732 if ( !v37 )
4733 {
4734 pParty->sRotationX = 0;
4735 pParty->sRotationY = 0;
4736 pParty->vPosition.z = 0;
4737 pParty->vPosition.y = 0;
4738 pParty->vPosition.x = 0;
4739 pParty->uFallStartY = 0;
4740 pParty->uFallSpeed = 0;
4741 TeleportToStartingPoint(uLevel_StartingPointType);
4742 }
4743 viewparams->_443365();
4744 PlayLevelMusic();
4745 if ( !v37 )
4746 {
4747 v30 = 0;
4748 v31 = 1;
4749 do
4750 {
4751 if ( pPlayers[v31]->CanAct() )
4752 v34[v30++] = v31;
4753 ++v31;
4754 }
4755 while ( v31 <= 4 );
4756 if ( v30 )
4757 {
4758 if ( pDest )
4759 {
4760 qword_A750D8 = 256i64;
4761 word_A750E0 = 46;
4762 word_A750E2 = LOWORD(v34[rand() % v30]);
4763 }
4764 }
4765 }
4766 }