diff Indoor.cpp @ 28:18f7a1b94448

Indoor::Load
author Nomad
date Tue, 16 Oct 2012 19:31:34 +0200
parents 540178ef9b18
children e62134245ab0
line wrap: on
line diff
--- a/Indoor.cpp	Tue Oct 16 01:31:05 2012 +0200
+++ b/Indoor.cpp	Tue Oct 16 19:31:34 2012 +0200
@@ -1,3 +1,5 @@
+#include <assert.h>
+
 #include "Outdoor.h"
 #include "Render.h"
 #include "LayingItem.h"
@@ -16,6 +18,7 @@
 #include "GUIProgressBar.h"
 #include "stru123.h"
 #include "AudioPlayer.h"
+#include "Log.h"
 
 #include "mm7_data.h"
 
@@ -27,8 +30,8 @@
 
 
 
-IndoorLocation *pIndoor;
-BLVRenderParams *pBLVRenderParams;
+IndoorLocation *pIndoor = new IndoorLocation;
+BLVRenderParams *pBLVRenderParams = new BLVRenderParams;
 
 struct DecorationList *pDecorationList;
 
@@ -1816,7 +1819,7 @@
   v1->pNodes = (BSPNode *)v14;
   v16 = pAllocator->AllocNamedChunk(v15, 0x14824u, "L.Map");
   v17 = v1->pVertices;
-  v1->pMapVertices = (unsigned int *)v16;
+  v1->pMapVertices = (BLVMapVertices *)v16;
   if ( v17 && v1->pFaces && v1->pFaceExtras && v1->pSectors && v1->pLights && v1->pDoors && v1->pNodes && v16 )
   {
     memset(v17, 90000, 0);
@@ -1875,16 +1878,16 @@
 
 
 //----- (00498E0A) --------------------------------------------------------
-bool IndoorLocation::Load(char *pFilename, int a3, size_t i, char *pDest)
+bool IndoorLocation::Load(char *pFilename, int a3, size_t _i, char *pDest)
 {
-  unsigned int v5; // ebx@1
-  IndoorLocation *v6; // esi@1
+  /*unsigned int v5; // ebx@1
+  //IndoorLocation *v6; // esi@1
   FILE *v7; // edi@3
   bool result; // eax@3
   char *v9; // ecx@4
   void *v10; // eax@4
-  unsigned __int8 v11; // zf@4
-  unsigned __int8 v12; // sf@4
+  //unsigned __int8 v11; // zf@4
+  //unsigned __int8 v12; // sf@4
   int v13; // eax@5
   size_t v14; // ecx@6
   char *v15; // ecx@6
@@ -1953,131 +1956,67 @@
   unsigned __int16 v78; // ax@50
   void *v79; // eax@52
   void **v80; // esi@52
-  size_t v81; // eax@56
-  FILE *v82; // eax@56
-  unsigned int v83; // edi@67
-  void *v84; // eax@67
-  void *v85; // ebx@67
-  const void *v86; // ebx@72
-  const void *v87; // ebx@72
-  const void *v88; // ebx@72
-  void *v89; // eax@72
-  size_t v90; // ecx@72
-  const void *v91; // ebx@72
-  int v92; // eax@72
-  BLVFace *v93; // ecx@73
-  BLVSector *v94; // ecx@73
-  unsigned __int16 *v95; // edx@73
-  int v96; // ecx@73
-  BLVSector *v97; // ecx@73
-  unsigned __int16 *v98; // edx@73
-  unsigned __int16 *v99; // edx@73
-  unsigned __int16 *v100; // edx@73
-  unsigned __int16 *v101; // edx@73
-  __int16 v102; // ax@77
-  BLVSector *v103; // ecx@77
-  __int16 v104; // ax@77
-  __int16 v105; // ax@78
-  BLVSector *v106; // ecx@78
-  const void *v107; // ebx@82
-  const void *v108; // ebx@82
-  unsigned __int16 v109; // ax@86
-  BLVFaceExtra *v110; // ecx@86
-  int v111; // edx@86
-  BLVFaceExtra *v112; // ecx@89
-  const void *v113; // ebx@94
-  const void *v114; // ebx@94
-  void *v115; // eax@94
-  size_t v116; // ecx@94
-  const void *v117; // ebx@94
-  int v118; // eax@94
-  unsigned __int16 *v119; // edx@95
-  int v120; // ecx@95
-  BLVFace *v121; // ecx@95
-  unsigned __int16 *v122; // edx@95
-  int v123; // ecx@95
-  BLVFace *v124; // ecx@95
-  unsigned __int16 *v125; // edx@95
-  unsigned __int16 *v126; // edx@95
-  unsigned __int16 *v127; // edx@95
-  unsigned __int16 *v128; // edx@95
-  unsigned __int16 *v129; // edx@95
-  int v130; // ecx@95
-  unsigned __int16 *v131; // edx@95
-  void *v132; // eax@96
-  size_t v133; // ecx@96
-  const void *v134; // ebx@96
-  BLVSector *v135; // eax@97
-  FILE *v136; // ecx@97
-  unsigned __int16 *v137; // edx@99
-  const void *v138; // ebx@100
-  const void *v139; // ebx@100
-  unsigned __int16 v140; // ax@102
-  FILE *v141; // ecx@102
-  const void *v142; // ebx@103
-  const void *v143; // ebx@103
-  const void *v144; // ebx@103
   unsigned int v145; // eax@103
   void *v146; // eax@103
   unsigned int v147; // ecx@103
   int v148; // ebx@103
-  unsigned int *v149; // ecx@103
-  size_t v150; // eax@103
-  unsigned int v151; // ebx@109
-  unsigned int v152; // ecx@116
-  unsigned int v153; // eax@117
-  size_t v154; // ebx@126
-  unsigned int v155; // ebx@134
-  size_t v156; // eax@140
-  signed int v157; // ebx@142
-  int v158; // ebx@148
-  BLVFace *v159; // eax@149
-  BLVFaceExtra *v160; // ecx@149
-  BLVFaceExtra *v161; // ecx@149
-  signed int v162; // ebx@154
-  unsigned int v163; // ebx@157
-  unsigned int v164; // ebx@157
-  unsigned int v165; // edx@158
-  char *v166; // ecx@158
-  unsigned __int16 v167; // ax@161
-  __int16 v168; // ax@165
-  unsigned int v169; // ebx@168
-  void *v170; // eax@168
-  size_t v171; // ebx@168
-  int v172; // edx@168
-  BLVDoor *v173; // ecx@169
-  int k; // eax@169
-  BLVDoor *v175; // ecx@172
-  int v176; // edx@172
-  BLVDoor *v177; // ecx@172
-  int v178; // edx@172
-  BLVDoor *v179; // ecx@172
-  int v180; // edx@172
-  BLVDoor *v181; // ecx@172
-  int v182; // edx@172
-  BLVDoor *v183; // ecx@172
-  int v184; // edx@172
-  BLVDoor *v185; // ecx@172
-  int v186; // edx@172
-  BLVDoor *v187; // ecx@172
-  int v188; // edx@172
-  unsigned __int16 *v189; // ebx@172
-  char *v190; // edx@173
-  BLVDoor *v191; // ecx@174
-  BLVDoor *l; // eax@175
-  signed int v193; // ebx@176
-  int v194; // ecx@176
-  BLVFaceExtra *v195; // ecx@176
-  BLVFace *v196; // ebx@178
-  std::string v197; // [sp-18h] [bp-680h]@66
-  void *v198; // [sp-14h] [bp-67Ch]@72
-  size_t v199; // [sp-10h] [bp-678h]@72
-  size_t v200; // [sp-Ch] [bp-674h]@72
-  const char *v201; // [sp-8h] [bp-670h]@4
-  int v202; // [sp-4h] [bp-66Ch]@4
+  unsigned int *v149; // ecx@103*/
+  //size_t v150; // eax@103
+  //unsigned int v151; // ebx@109
+  //unsigned int v152; // ecx@116
+  //unsigned int v153; // eax@117
+  //size_t v154; // ebx@126
+  //unsigned int v155; // ebx@134
+  //size_t v156; // eax@140
+  //signed int v157; // ebx@142
+  //int v158; // ebx@148
+  //BLVFace *v159; // eax@149
+//  BLVFaceExtra *v160; // ecx@149
+  //BLVFaceExtra *v161; // ecx@149
+  //signed int v162; // ebx@154
+  //unsigned int v163; // ebx@157
+  //unsigned int v164; // ebx@157
+  //unsigned int v165; // edx@158
+  //char *v166; // ecx@158
+  //unsigned __int16 v167; // ax@161
+  //__int16 v168; // ax@165
+  //unsigned int v169; // ebx@168
+  //void *v170; // eax@168
+  //size_t v171; // ebx@168
+  //int v172; // edx@168
+  //BLVDoor *v173; // ecx@169
+  //int k; // eax@169
+  //BLVDoor *v175; // ecx@172
+  //int v176; // edx@172
+  //BLVDoor *v177; // ecx@172
+  //int v178; // edx@172
+  //BLVDoor *v179; // ecx@172
+  //int v180; // edx@172
+  //BLVDoor *v181; // ecx@172
+  //int v182; // edx@172
+  //BLVDoor *v183; // ecx@172
+  //int v184; // edx@172
+  //BLVDoor *v185; // ecx@172
+  //int v186; // edx@172
+  //BLVDoor *v187; // ecx@172
+  //int v188; // edx@172
+  //unsigned __int16 *v189; // ebx@172
+  //char *v190; // edx@173
+  //BLVDoor *v191; // ecx@174
+  //BLVDoor *l; // eax@175
+  //signed int v193; // ebx@176
+  //int v194; // ecx@176
+  //BLVFaceExtra *v195; // ecx@176
+  //BLVFace *v196; // ebx@178
+  //std::string v197; // [sp-18h] [bp-680h]@66
+  //void *v198; // [sp-14h] [bp-67Ch]@72
+  //size_t v199; // [sp-10h] [bp-678h]@72
+  //size_t v200; // [sp-Ch] [bp-674h]@72
+  //const char *v201; // [sp-8h] [bp-670h]@4
+  //int v202; // [sp-4h] [bp-66Ch]@4
   char v203[875]; // [sp+Ch] [bp-65Ch]@130
   char FileName[260]; // [sp+378h] [bp-2F0h]@1
-  char DstBuf; // [sp+47Ch] [bp-1ECh]@4
+  //char DstBuf; // [sp+47Ch] [bp-1ECh]@4
   __int32 Offset; // [sp+480h] [bp-1E8h]@4
   __int32 v207; // [sp+48Ch] [bp-1DCh]@4
   __int32 v208; // [sp+498h] [bp-1D0h]@4
@@ -2107,18 +2046,18 @@
   __int32 v232; // [sp+5B8h] [bp-B0h]@52
   __int32 v233; // [sp+5C4h] [bp-A4h]@52
   __int32 v234; // [sp+5D0h] [bp-98h]@52
-  char pName[40]; // [sp+5FCh] [bp-6Ch]@42
-  size_t pSource; // [sp+624h] [bp-44h]@67
-  char Dst[12]; // [sp+628h] [bp-40h]@9
-  char *v238; // [sp+634h] [bp-34h]@38
+  //char pName[40]; // [sp+5FCh] [bp-6Ch]@42
+  //size_t pSource; // [sp+624h] [bp-44h]@67
+  //char Dst[12]; // [sp+628h] [bp-40h]@9
+  //char *v238; // [sp+634h] [bp-34h]@38
   ODMHeader header; // [sp+638h] [bp-30h]@61
-  void *ptr; // [sp+648h] [bp-20h]@66
-  size_t Count; // [sp+64Ch] [bp-1Ch]@109
-  int uSourceLen; // [sp+653h] [bp-15h]@66
+  //void *ptr; // [sp+648h] [bp-20h]@66
+  //size_t Count; // [sp+64Ch] [bp-1Ch]@109
+  //int uSourceLen; // [sp+653h] [bp-15h]@66
   FILE *File; // [sp+658h] [bp-10h]@56
-  BLVSector *v244; // [sp+65Ch] [bp-Ch]@72
-  int v245; // [sp+660h] [bp-8h]@72
-  BLVFace *Src; // [sp+664h] [bp-4h]@73
+  //BLVSector *v244; // [sp+65Ch] [bp-Ch]@72
+  //int v245; // [sp+660h] [bp-8h]@72
+  //BLVFace *Src; // [sp+664h] [bp-4h]@73
   signed int Argsa; // [sp+670h] [bp+8h]@4
   signed int Argsb; // [sp+670h] [bp+8h]@7
   signed int Argsc; // [sp+670h] [bp+8h]@15
@@ -2129,46 +2068,48 @@
   int Argsh; // [sp+670h] [bp+8h]@35
   signed int Argsi; // [sp+670h] [bp+8h]@40
   signed int Argsj; // [sp+670h] [bp+8h]@45
-  int Argsk; // [sp+670h] [bp+8h]@143
-  void *Argsl; // [sp+670h] [bp+8h]@155
-  signed int Argsm; // [sp+670h] [bp+8h]@161
-  signed int Argsn; // [sp+670h] [bp+8h]@175
+  //int Argsk; // [sp+670h] [bp+8h]@143
+  //void *Argsl; // [sp+670h] [bp+8h]@155
+  //signed int Argsm; // [sp+670h] [bp+8h]@161
+  //signed int Argsn; // [sp+670h] [bp+8h]@175
 
-  v5 = 0;
-  v6 = this;
+  //v5 = 0;
+  //v6 = this;
   _6807E0_num_decorations_6807B8 = 0;
-  sprintfex(FileName, "levels\\%s", pFilename);
+
+  #pragma region "loading from txt"
+  /*sprintf(FileName, "levels\\%s", pFilename);
   if ( GetFileAttributesA(FileName) != -1 )
   {
-    v6->Release();
-    if ( v6->Alloc() )
+    Release();
+    if ( Alloc() )
     {
       v7 = fopen(FileName, "rb");
       result = 1;
       if ( !v7 )
         return result;
       v9 = pDest;
-      v6->bLoaded = 1;
+      bLoaded = 1;
       v202 = (int)v7;
       v201 = (const char *)1;
       *(int *)v9 = 1;
       fread(&DstBuf, 0x180u, (size_t)v201, (FILE *)v202);
       fseek(v7, Offset, 0);
-      fread(&v6->blv, 0x88u, 1u, v7);
+      fread(&blv, 0x88u, 1u, v7);
       fseek(v7, v207, 0);
-      fread(&v6->uNumVertices, 1u, 4u, v7);
+      fread(&uNumVertices, 1u, 4u, v7);
       fseek(v7, v208, 0);
-      fread(v6->pVertices, 6u, v6->uNumVertices, v7);
+      fread(pVertices, 6u, uNumVertices, v7);
       fseek(v7, v209, 0);
-      fread(&v6->uNumFaces, 4u, 1u, v7);
+      fread(&uNumFaces, 4u, 1u, v7);
       fseek(v7, v210, 0);
-      fread(v6->pFaces, 0x60u, v6->uNumFaces, v7);
-      v10 = pAllocator->AllocNamedChunk(v6->ptr_2AC, v6->blv.uFaces_fdata_Size, "L.FData");
+      fread(pFaces, 0x60u, uNumFaces, v7);
+      v10 = pAllocator->AllocNamedChunk(ptr_2AC, blv.uFaces_fdata_Size, "L.FData");
       v202 = (int)v7;
-      v6->ptr_2AC = (unsigned __int16 *)v10;
-      fread(v10, 1u, v6->blv.uFaces_fdata_Size, (FILE *)v202);
-      v11 = v6->uNumFaces == 0;
-      v12 = (v6->uNumFaces & 0x80000000u) != 0;
+      ptr_2AC = (unsigned __int16 *)v10;
+      fread(v10, 1u, blv.uFaces_fdata_Size, (FILE *)v202);
+      v11 = uNumFaces == 0;
+      v12 = (uNumFaces & 0x80000000u) != 0;
       pDest = 0;
       Argsa = 0;
       if ( !(v12 | v11) )
@@ -2176,50 +2117,50 @@
         v13 = 0;
         do
         {
-          v6->pFaces[v13].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)v6->ptr_2AC];
-          v14 = (size_t)&v6->pFaces[v13];
+          pFaces[v13].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)ptr_2AC];
+          v14 = (size_t)&pFaces[v13];
           i = v14;
           v15 = &pDest[2 * *(char *)(v14 + 93) + 2];
-          v16 = (int)&v15[(unsigned int)v6->ptr_2AC];
+          v16 = (int)&v15[(unsigned int)ptr_2AC];
           pDest = v15;
           *(int *)(i + 52) = v16;
-          v17 = (size_t)&v6->pFaces[v13];
+          v17 = (size_t)&pFaces[v13];
           i = v17;
           v18 = &pDest[2 * *(char *)(v17 + 93) + 2];
-          v19 = (int)&v18[(unsigned int)v6->ptr_2AC];
+          v19 = (int)&v18[(unsigned int)ptr_2AC];
           pDest = v18;
           *(int *)(i + 56) = v19;
-          i = (size_t)&v6->pFaces[v13];
-          v20 = v6->ptr_2AC;
+          i = (size_t)&pFaces[v13];
+          v20 = ptr_2AC;
           pDest += 2 * *(char *)(i + 93) + 2;
           *(int *)(i + 60) = (int)(char *)v20 + (int)pDest;
-          i = (size_t)&v6->pFaces[v13];
-          v21 = v6->ptr_2AC;
+          i = (size_t)&pFaces[v13];
+          v21 = ptr_2AC;
           pDest += 2 * *(char *)(i + 93) + 2;
           *(int *)(i + 64) = (int)(char *)v21 + (int)pDest;
-          i = (size_t)&v6->pFaces[v13];
+          i = (size_t)&pFaces[v13];
           ++v13;
-          v22 = v6->ptr_2AC;
+          v22 = ptr_2AC;
           pDest += 2 * *(char *)(i + 93) + 2;
           ++Argsa;
           *(int *)(i + 68) = (int)(char *)v22 + (int)pDest;
-          pDest += 2 * *((char *)&v6->pFaces[v13] - 3) + 2;
+          pDest += 2 * *((char *)&pFaces[v13] - 3) + 2;
         }
-        while ( Argsa < (signed int)v6->uNumFaces );
+        while ( Argsa < (signed int)uNumFaces );
       }
       Argsb = 0;
-      if ( (signed int)v6->uNumFaces > 0 )
+      if ( (signed int)uNumFaces > 0 )
       {
         pDest = 0;
         do
         {
           fread(Dst, 1u, 0xAu, v7);
-          if ( pDest[(unsigned int)v6->pFaces + 45] & 0x40 )
+          if ( pDest[(unsigned int)pFaces + 45] & 0x40 )
           {
             v23 = pTextureFrameTable->FindTextureByName(Dst);
             v24 = pDest;
-            *(short *)&pDest[(unsigned int)v6->pFaces + 74] = v23;
-            v25 = *(short *)&v24[(unsigned int)v6->pFaces + 74];
+            *(short *)&pDest[(unsigned int)pFaces + 74] = v23;
+            v25 = *(short *)&v24[(unsigned int)pFaces + 74];
             if ( v25 )
             {
               pTextureFrameTable->LoadAnimationSequenceAndPalettes(v25);
@@ -2228,68 +2169,68 @@
             {
               v26 = pBitmaps_LOD->LoadTexture(Dst);
               v27 = pDest;
-              *(short *)&pDest[(unsigned int)v6->pFaces + 74] = v26;
-              v27[(unsigned int)v6->pFaces + 45] &= 0xBFu;
+              *(short *)&pDest[(unsigned int)pFaces + 74] = v26;
+              v27[(unsigned int)pFaces + 45] &= 0xBFu;
             }
           }
           else
           {
-            *(short *)&pDest[(unsigned int)v6->pFaces + 74] = pBitmaps_LOD->LoadTexture(Dst);
+            *(short *)&pDest[(unsigned int)pFaces + 74] = pBitmaps_LOD->LoadTexture(Dst);
           }
           ++Argsb;
           pDest += 96;
         }
-        while ( Argsb < (signed int)v6->uNumFaces );
+        while ( Argsb < (signed int)uNumFaces );
       }
       fseek(v7, v211, 0);
-      fread(&v6->uNumFaceExtras, 4u, 1u, v7);
+      fread(&uNumFaceExtras, 4u, 1u, v7);
       fseek(v7, v212, 0);
-      fread(v6->pFaceExtras, 0x24u, v6->uNumFaceExtras, v7);
+      fread(pFaceExtras, 0x24u, uNumFaceExtras, v7);
       Argsc = 0;
-      if ( (signed int)v6->uNumFaceExtras > 0 )
+      if ( (signed int)uNumFaceExtras > 0 )
       {
         pDest = 0;
         do
         {
           fread(Dst, 1u, 0xAu, v7);
           v28 = pBitmaps_LOD->LoadTexture(Dst);
-          v29 = v6->pFaceExtras;
+          v29 = pFaceExtras;
           v30 = pDest;
           ++Argsc;
           pDest += 36;
           *(unsigned __int16 *)((char *)&v29->uAdditionalBitmapID + (int)v30) = v28;
         }
-        while ( Argsc < (signed int)v6->uNumFaceExtras );
+        while ( Argsc < (signed int)uNumFaceExtras );
       }
       Argsd = 0;
-      if ( (signed int)v6->uNumFaces > 0 )
+      if ( (signed int)uNumFaces > 0 )
       {
         pDest = 0;
         do
         {
-          v31 = (int)&v6->pFaceExtras[*(short *)&pDest[(unsigned int)v6->pFaces + 72]];
+          v31 = (int)&pFaceExtras[*(short *)&pDest[(unsigned int)pFaces + 72]];
           if ( *(short *)(v31 + 26) )
           {
             if ( ((BLVFaceExtra *)v31)->HasEventint() )
-              pDest[(unsigned int)v6->pFaces + 46] |= 0x10u;
+              pDest[(unsigned int)pFaces + 46] |= 0x10u;
             else
-              pDest[(unsigned int)v6->pFaces + 46] &= 0xEFu;
+              pDest[(unsigned int)pFaces + 46] &= 0xEFu;
           }
           ++Argsd;
           pDest += 96;
         }
-        while ( Argsd < (signed int)v6->uNumFaces );
+        while ( Argsd < (signed int)uNumFaces );
       }
       fseek(v7, v213, 0);
-      fread(&v6->uNumSectors, 4u, 1u, v7);
+      fread(&uNumSectors, 4u, 1u, v7);
       fseek(v7, v214, 0);
-      fread(v6->pSectors, 0x74u, v6->uNumSectors, v7);
-      v32 = pAllocator->AllocNamedChunk(v6->ptr_0002B0_sector_rdata, v6->blv.uSector_rdata_Size, "L.RData");
+      fread(pSectors, 0x74u, uNumSectors, v7);
+      v32 = pAllocator->AllocNamedChunk(ptr_0002B0_sector_rdata, blv.uSector_rdata_Size, "L.RData");
       v202 = (int)v7;
-      v6->ptr_0002B0_sector_rdata = (unsigned __int16 *)v32;
-      fread(v32, 1u, v6->blv.uSector_rdata_Size, (FILE *)v202);
-      v11 = v6->uNumSectors == 0;
-      v12 = v6->uNumSectors < 0;
+      ptr_0002B0_sector_rdata = (unsigned __int16 *)v32;
+      fread(v32, 1u, blv.uSector_rdata_Size, (FILE *)v202);
+      v11 = uNumSectors == 0;
+      v12 = uNumSectors < 0;
       pDest = 0;
       Argse = 0;
       if ( !(v12 | v11) )
@@ -2297,87 +2238,87 @@
         v33 = 0;
         do
         {
-          v6->pSectors[v33].pFloors = (unsigned __int16 *)&pDest[(unsigned int)v6->ptr_0002B0_sector_rdata];
-          i = (size_t)&v6->pSectors[v33];
-          v34 = v6->ptr_0002B0_sector_rdata;
+          pSectors[v33].pFloors = (unsigned __int16 *)&pDest[(unsigned int)ptr_0002B0_sector_rdata];
+          i = (size_t)&pSectors[v33];
+          v34 = ptr_0002B0_sector_rdata;
           pDest += 2 * *(short *)(i + 4);
           *(int *)(i + 16) = (int)(char *)v34 + (int)pDest;
-          v35 = (size_t)&v6->pSectors[v33];
+          v35 = (size_t)&pSectors[v33];
           i = v35;
           v36 = &pDest[2 * *(short *)(v35 + 12)];
-          v37 = (int)&v36[(unsigned int)v6->ptr_0002B0_sector_rdata];
+          v37 = (int)&v36[(unsigned int)ptr_0002B0_sector_rdata];
           pDest = v36;
           *(int *)(i + 24) = v37;
-          v38 = (size_t)&v6->pSectors[v33];
+          v38 = (size_t)&pSectors[v33];
           i = v38;
           v39 = &pDest[2 * *(short *)(v38 + 20)];
-          v40 = (int)&v39[(unsigned int)v6->ptr_0002B0_sector_rdata];
+          v40 = (int)&v39[(unsigned int)ptr_0002B0_sector_rdata];
           pDest = v39;
           *(int *)(i + 32) = v40;
-          i = (size_t)&v6->pSectors[v33];
-          v41 = v6->ptr_0002B0_sector_rdata;
+          i = (size_t)&pSectors[v33];
+          v41 = ptr_0002B0_sector_rdata;
           pDest += 2 * *(short *)(i + 28);
           *(int *)(i + 40) = (int)(char *)v41 + (int)pDest;
-          i = (size_t)&v6->pSectors[v33];
-          v42 = v6->ptr_0002B0_sector_rdata;
+          i = (size_t)&pSectors[v33];
+          v42 = ptr_0002B0_sector_rdata;
           pDest += 2 * *(short *)(i + 36);
           *(int *)(i + 48) = (int)(char *)v42 + (int)pDest;
-          i = (size_t)&v6->pSectors[v33];
-          v43 = v6->ptr_0002B0_sector_rdata;
+          i = (size_t)&pSectors[v33];
+          v43 = ptr_0002B0_sector_rdata;
           pDest += 2 * *(short *)(i + 44);
           *(int *)(i + 64) = (int)(char *)v43 + (int)pDest;
-          i = (size_t)&v6->pSectors[v33];
-          v44 = v6->ptr_0002B0_sector_rdata;
+          i = (size_t)&pSectors[v33];
+          v44 = ptr_0002B0_sector_rdata;
           pDest += 2 * *(short *)(i + 60);
           *(int *)(i + 72) = (int)(char *)v44 + (int)pDest;
-          v45 = (size_t)&v6->pSectors[v33];
+          v45 = (size_t)&pSectors[v33];
           ++v33;
           i = v45;
-          v46 = v6->ptr_0002B0_sector_rdata;
+          v46 = ptr_0002B0_sector_rdata;
           pDest += 2 * *(short *)(v45 + 68);
           ++Argse;
           *(int *)(v45 + 80) = (int)(char *)v46 + (int)pDest;
-          pDest += 2 * *((short *)&v6->pSectors[v33] - 20);
+          pDest += 2 * *((short *)&pSectors[v33] - 20);
         }
-        while ( Argse < v6->uNumSectors );
+        while ( Argse < uNumSectors );
       }
       v47 = pAllocator->AllocNamedChunk(
-              v6->ptr_0002B8_sector_lrdata,
-              v6->blv.uSector_lrdata_Size,
+              ptr_0002B8_sector_lrdata,
+              blv.uSector_lrdata_Size,
               "L.RLData");
       v202 = (int)v7;
-      v6->ptr_0002B8_sector_lrdata = (unsigned __int16 *)v47;
-      fread(v47, 1u, v6->blv.uSector_lrdata_Size, (FILE *)v202);
-      v11 = v6->uNumSectors == 0;
-      v12 = v6->uNumSectors < 0;
+      ptr_0002B8_sector_lrdata = (unsigned __int16 *)v47;
+      fread(v47, 1u, blv.uSector_lrdata_Size, (FILE *)v202);
+      v11 = uNumSectors == 0;
+      v12 = uNumSectors < 0;
       pDest = 0;
       Argsf = 0;
       if ( !(v12 | v11) )
       {
-        v48 = v6->pSectors;
+        v48 = pSectors;
         v49 = 0;
         for ( i = 0; ; v49 = i )
         {
-          v50 = v6->ptr_0002B8_sector_lrdata;
+          v50 = ptr_0002B8_sector_lrdata;
           i += 116;
           ++Argsf;
           *(BLVLightMM7 **)((char *)&v48->pLights + v49) = (BLVLightMM7 *)((char *)v50 + (int)pDest);
-          v48 = v6->pSectors;
+          v48 = pSectors;
           pDest += 2 * *(__int16 *)((char *)&v48->uNumLights + v49);
-          if ( Argsf >= v6->uNumSectors )
+          if ( Argsf >= uNumSectors )
             break;
         }
       }
       fseek(v7, v215, 0);
-      fread(&v6->uNumDoors, 4u, 1u, v7);
+      fread(&uNumDoors, 4u, 1u, v7);
       fseek(v7, v216, 0);
-      fread(v6->pDoors, 0x50u, 0xC8u, v7);
-      v51 = pAllocator->AllocNamedChunk(v6->ptr_0002B4_doors_ddata, v6->blv.uDoors_ddata_Size, "L.DData");
+      fread(pDoors, 0x50u, 0xC8u, v7);
+      v51 = pAllocator->AllocNamedChunk(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
       v202 = (int)v7;
-      v6->ptr_0002B4_doors_ddata = (unsigned __int16 *)v51;
-      fread(v51, 1u, v6->blv.uDoors_ddata_Size, (FILE *)v202);
-      v11 = v6->uNumDoors == 0;
-      v12 = v6->uNumDoors < 0;
+      ptr_0002B4_doors_ddata = (unsigned __int16 *)v51;
+      fread(v51, 1u, blv.uDoors_ddata_Size, (FILE *)v202);
+      v11 = uNumDoors == 0;
+      v12 = uNumDoors < 0;
       pDest = 0;
       Argsg = 0;
       if ( !(v12 | v11) )
@@ -2385,50 +2326,50 @@
         v52 = 0;
         do
         {
-          v6->pDoors[v52].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)v6->ptr_0002B4_doors_ddata];
-          i = (size_t)&v6->pDoors[v52];
-          v53 = v6->ptr_0002B4_doors_ddata;
+          pDoors[v52].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)ptr_0002B4_doors_ddata];
+          i = (size_t)&pDoors[v52];
+          v53 = ptr_0002B4_doors_ddata;
           pDest += 2 * *(short *)(i + 68);
           *(int *)(i + 40) = (int)(char *)v53 + (int)pDest;
-          v54 = (size_t)&v6->pDoors[v52];
+          v54 = (size_t)&pDoors[v52];
           i = v54;
           v55 = &pDest[2 * *(short *)(v54 + 70)];
-          v56 = (int)&v55[(unsigned int)v6->ptr_0002B4_doors_ddata];
+          v56 = (int)&v55[(unsigned int)ptr_0002B4_doors_ddata];
           pDest = v55;
           *(int *)(i + 44) = v56;
-          v57 = (size_t)&v6->pDoors[v52];
+          v57 = (size_t)&pDoors[v52];
           i = v57;
           v58 = &pDest[2 * *(short *)(v57 + 72)];
-          v59 = (int)&v58[(unsigned int)v6->ptr_0002B4_doors_ddata];
+          v59 = (int)&v58[(unsigned int)ptr_0002B4_doors_ddata];
           pDest = v58;
           *(int *)(i + 48) = v59;
-          i = (size_t)&v6->pDoors[v52];
-          v60 = v6->ptr_0002B4_doors_ddata;
+          i = (size_t)&pDoors[v52];
+          v60 = ptr_0002B4_doors_ddata;
           pDest += 2 * *(short *)(i + 70);
           *(int *)(i + 52) = (int)(char *)v60 + (int)pDest;
-          i = (size_t)&v6->pDoors[v52];
-          v61 = v6->ptr_0002B4_doors_ddata;
+          i = (size_t)&pDoors[v52];
+          v61 = ptr_0002B4_doors_ddata;
           pDest += 2 * *(short *)(i + 70);
           *(int *)(i + 56) = (int)(char *)v61 + (int)pDest;
-          i = (size_t)&v6->pDoors[v52];
-          v62 = v6->ptr_0002B4_doors_ddata;
+          i = (size_t)&pDoors[v52];
+          v62 = ptr_0002B4_doors_ddata;
           pDest += 2 * *(short *)(i + 74);
           *(int *)(i + 60) = (int)(char *)v62 + (int)pDest;
-          i = (size_t)&v6->pDoors[v52];
-          v63 = v6->ptr_0002B4_doors_ddata;
+          i = (size_t)&pDoors[v52];
+          v63 = ptr_0002B4_doors_ddata;
           pDest += 2 * *(short *)(i + 74);
           *(int *)(i + 64) = (int)(char *)v63 + (int)pDest;
           ++Argsg;
-          v64 = v6->pDoors[v52].uNumOffsets;
+          v64 = pDoors[v52].uNumOffsets;
           ++v52;
           pDest += 2 * v64;
         }
-        while ( Argsg < v6->uNumDoors );
+        while ( Argsg < uNumDoors );
       }
       Argsh = 0;
-      if ( v6->uNumDoors > 0 )
+      if ( uNumDoors > 0 )
       {
-        v65 = v6->pDoors;
+        v65 = pDoors;
         pDest = 0;
         do
         {
@@ -2441,15 +2382,15 @@
               v67 = *((int *)v66 + 10);
               a3 = 2 * i;
               v68 = *(short *)(v67 + 2 * i);
-              v69 = v6->pFaces;
+              v69 = pFaces;
               ++i;
-              v70 = (int)&v6->pFaceExtras[v69[v68].uFaceExtraID];
+              v70 = (int)&pFaceExtras[v69[v68].uFaceExtraID];
               v71 = *((int *)v66 + 12);
               v72 = a3;
               v238 = (char *)v70;
               *(short *)(a3 + v71) = *(short *)(v70 + 20);
-              *(__int16 *)(*(char **)((char *)&v6->pDoors->pDeltaVs + (unsigned int)pDest) + v72) = *((short *)v238 + 11);
-              v65 = v6->pDoors;
+              *(__int16 *)(*(char **)((char *)&pDoors->pDeltaVs + (unsigned int)pDest) + v72) = *((short *)v238 + 11);
+              v65 = pDoors;
               v66 = &pDest[(int)v65];
             }
             while ( (signed int)i < *(short *)&pDest[(int)v65 + 70] );
@@ -2457,7 +2398,7 @@
           ++Argsh;
           pDest += 80;
         }
-        while ( Argsh < v6->uNumDoors );
+        while ( Argsh < uNumDoors );
       }
       fseek(v7, v217, 0);
       fread(&uNumLevelDecorations, 4u, 1u, v7);
@@ -2527,741 +2468,734 @@
       fseek(v7, v229, 0);
       fread(pChests, 0x14CCu, uNumChests, v7);
       fseek(v7, v224, 0);
-      fread(&v6->uNumLights, 4u, 1u, v7);
+      fread(&uNumLights, 4u, 1u, v7);
       fseek(v7, v225, 0);
-      fread(v6->pLights, 0x10u, v6->uNumLights, v7);
+      fread(pLights, 0x10u, uNumLights, v7);
       fseek(v7, v226, 0);
-      fread(&v6->uNumNodes, 4u, 1u, v7);
+      fread(&uNumNodes, 4u, 1u, v7);
       fseek(v7, v227, 0);
-      fread(v6->pNodes, 8u, v6->uNumNodes, v7);
+      fread(pNodes, 8u, uNumNodes, v7);
       fseek(v7, v230, 0);
-      fread(&v6->uNumSpawnPoints, 4u, 1u, v7);
-      v79 = pAllocator->AllocNamedChunk(v6->pSpawnPoints, 24 * v6->uNumSpawnPoints, "Spawn");
+      fread(&uNumSpawnPoints, 4u, 1u, v7);
+      v79 = pAllocator->AllocNamedChunk(pSpawnPoints, 24 * uNumSpawnPoints, "Spawn");
       v202 = 0;
-      v6->pSpawnPoints = (SpawnPointMM7 *)v79;
+      pSpawnPoints = (SpawnPointMM7 *)v79;
       fseek(v7, v231, v202);
-      fread(v6->pSpawnPoints, 0x18u, v6->uNumSpawnPoints, v7);
+      fread(pSpawnPoints, 0x18u, uNumSpawnPoints, v7);
       fseek(v7, v232, 0);
-      fread(&v6->dlv, 0x28u, 1u, v7);
+      fread(&dlv, 0x28u, 1u, v7);
       fseek(v7, v233, 0);
       fread(&stru_5E4C90, 1u, 0xC8u, v7);
       fseek(v7, v234, 0);
-      fread(&v6->uLastVisitDay, 1u, 0x38u, v7);
+      fread(&uLastVisitDay, 1u, 0x38u, v7);
       fseek(v7, v223, 0);
-      v80 = (void **)&v6->pMapVertices;
+      v80 = (void **)&pMapVertices;
       fread(*v80, 4u, 1u, v7);
       fread((char *)*v80 + 4, 0xCu, *(int *)*v80, v7);
       fclose(v7);
       goto LABEL_179;
     }
     return 4;
+  }*/
+  #pragma endregion
+
+  if (bLoaded)
+  {
+    Log::Warning(L"BLV is already loaded");
+    return 3;
   }
+
   if ( !pGames_LOD->DoesContainerExist(pFilename) )
     Abortf("Unable to find %s in Games.LOD", pFilename);
-  v238 = pFilename - 4;
-  v81 = strlen(pFilename);
-  strcpy(&v238[v81], ".blv");
-  v82 = pGames_LOD->FindContainer(pFilename, 1);
-  v11 = v6->bLoaded == 0;
-  File = v82;
-  if ( !v11 )
-    return 3;
+
+  //v238 = pFilename - 4;
+  //v81 = strlen(pFilename);
+  strcpy(this->pFilename, pFilename);
+  strcpy(&pFilename[strlen(pFilename) - 4], ".blv");
+  File = pGames_LOD->FindContainer(pFilename, 1);
+  //File = v82;
 
   Release();
   if ( !Alloc() )
     return 4;
-
+  
+  header.uVersion = 91969;
   header.pMagic[0] = 'm';
-  header.uVersion = 91969;
   header.pMagic[1] = 'v';
   header.pMagic[2] = 'i';
   header.pMagic[3] = 'i';
   header.uCompressedSize = 0;
   header.uDecompressedSize = 0;
-  fread(&header, 0x10u, 1u, File);
-  if ( header.uVersion != 91969
-    || header.pMagic[0] != 'm'
-    || header.pMagic[1] != 'v'
-    || header.pMagic[2] != 'i'
-    || header.pMagic[3] != 'i' )
+  fread(&header, sizeof(ODMHeader), 1u, File);
+  if (header.uVersion != 91969 ||
+      header.pMagic[0] != 'm'  ||
+      header.pMagic[1] != 'v'  ||
+      header.pMagic[2] != 'i'  ||
+      header.pMagic[3] != 'i' )
   {
     MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:792", 0);
   }
-  v83 = header.uCompressedSize;
-  pSource = header.uDecompressedSize;
-  v84 = malloc(header.uDecompressedSize);
-  v85 = v84;
-  ptr = v84;
-  if ( v83 <= pSource )
+  //v83 = header.uCompressedSize;
+  //pSource = header.uDecompressedSize;
+  //v84 = malloc(header.uDecompressedSize);
+  //v85 = v84;
+  //ptr = v84;
+  auto pRawBLV = malloc(header.uDecompressedSize);
+  memset(pRawBLV, 0, header.uDecompressedSize);
+
+  if (header.uCompressedSize == header.uDecompressedSize)
+    fread(pRawBLV, header.uDecompressedSize, 1, File);
+  else if (header.uCompressedSize < header.uDecompressedSize)
   {
-    if ( v83 == pSource )
+    auto pTmpMem = malloc(header.uCompressedSize);
     {
-      fread(v84, pSource, 1u, File);
+      fread(pTmpMem, header.uCompressedSize, 1, File);
+
+      uint uDecompressedSize = header.uDecompressedSize;
+      zlib::MemUnzip(pRawBLV, &uDecompressedSize, pTmpMem, header.uCompressedSize);
+
+      if (uDecompressedSize != header.uDecompressedSize)
+        Log::Warning(L"uDecompressedSize != header.uDecompressedSize in BLV");
     }
-    else
-    {
-      *(int *)((char *)&uSourceLen + 1) = (int)malloc(v83);
-      fread(*(void **)((char *)&uSourceLen + 1), v83, 1u, File);
-      zlib::MemUnzip(v85, &pSource, *(const void **)((char *)&uSourceLen + 1), v83);
-      free(*(void **)((char *)&uSourceLen + 1));
-    }
+    free(pTmpMem);
   }
   else
   {
     MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:803", 0);
+    return 0;
   }
-  strcpy(v6->pFilename, pFilename);
-  v200 = 136;
-  v199 = (size_t)v85;
-  v198 = &v6->blv;
-  v6->bLoaded = 1;
-  memcpy(v198, (const void *)v199, v200);
-  v86 = (char *)v85 + 136;
+
+  assert(sizeof(Vec3_short_) == 6);
+  assert(sizeof(BLVFace) == 96);
+  assert(sizeof(BLVFaceExtra) == 36);
+  assert(sizeof(BLVSector) == 116);
+  assert(sizeof(LevelDecoration) == 32);
+  assert(sizeof(BLVLightMM7) == 16);
+  assert(sizeof(BSPNode) == 8);
+  assert(sizeof(SpawnPointMM7) == 24);
+  assert(sizeof(DDM_DLV_Header) == 40);
+  assert(sizeof(Actor) == 836);
+  assert(sizeof(LayingItem) == 112);
+  assert(sizeof(Chest) == 5324);
+  assert(sizeof(stru123) == 0xC8);
+  
+  bLoaded = true;
+
+  auto pData = (char *)pRawBLV;
+  
   pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumVertices, v86, 4u);
-  v86 = (char *)v86 + 4;
-  pGameLoadingUI_ProgressBar->Progress();
-  v202 = 6 * v6->uNumVertices;
-  v201 = (const char *)v86;
-  v200 = (size_t)v6->pVertices;
-  v245 = v202;
-  memcpy((void *)v200, v86, v202);
-  v87 = (char *)v86 + v245;
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumFaces, v87, 4u);
-  v87 = (char *)v87 + 4;
+
+  memcpy(&blv, pData, 136);
+  memcpy(&uNumVertices, pData += 136, 4);
+  memcpy(pVertices, pData += 4, uNumVertices * sizeof(Vec3_short_));
+  
   pGameLoadingUI_ProgressBar->Progress();
-  v202 = 96 * v6->uNumFaces;
-  v201 = (const char *)v87;
-  v200 = (size_t)v6->pFaces;
-  v245 = v202;
-  memcpy((void *)v200, v87, v202);
-  v88 = (char *)v87 + v245;
-  v202 = (int)"L.FData";
-  v201 = (const char *)v6->blv.uFaces_fdata_Size;
-  v200 = (size_t)v6->ptr_2AC;
-  v89 = pAllocator->AllocNamedChunk((const void *)v200, (unsigned int)v201, "L.FData");
-  v90 = v6->blv.uFaces_fdata_Size;
-  v6->ptr_2AC = (unsigned __int16 *)v89;
-  v245 = v90;
-  memcpy(v89, v88, v90);
-  v91 = (char *)v88 + v245;
-  v92 = 0;
-  v11 = v6->uNumFaces == 0;
-  v12 = (v6->uNumFaces & 0x80000000u) != 0;
-  v244 = 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+
+  memcpy(&uNumFaces, pData += uNumVertices * sizeof(Vec3_short_), 4);
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  memcpy(pFaces, pData += 4, uNumFaces * sizeof (BLVFace));
+  ptr_2AC = (unsigned __int16 *)pAllocator->AllocNamedChunk(ptr_2AC, blv.uFaces_fdata_Size, "L.FData");
+
+  memcpy(ptr_2AC, pData += uNumFaces * sizeof (BLVFace), blv.uFaces_fdata_Size);
+
+  for (uint i = 0, j = 0; i < uNumFaces; ++i)
   {
-    do
-    {
-      v6->pFaces[v92].pVertexIDs = (unsigned __int16 *)((char *)v244 + (unsigned int)v6->ptr_2AC);
-      v93 = &v6->pFaces[v92];
+    auto pFace = pFaces + i;
+
+    pFace->pVertexIDs = ptr_2AC + j;
+    
+    j += pFace->uNumVertices + 1;
+    pFace->pXInterceptDisplacements = ptr_2AC + j;
+
+    j += pFace->uNumVertices + 1;
+    pFace->pYInterceptDisplacements = ptr_2AC + j;
+
+    j += pFace->uNumVertices + 1;
+    pFace->pZInterceptDisplacements = ptr_2AC + j;
+
+    j += pFace->uNumVertices + 1;
+    pFace->pVertexUIDs = ptr_2AC + j;
+
+    j += pFace->uNumVertices + 1;
+    pFace->pVertexVIDs = ptr_2AC + j;
+
+    j += pFace->uNumVertices + 1;
+      /*v93 = &pFaces[v92];
       Src = v93;
       v94 = (BLVSector *)((char *)v244 + 2 * v93->uNumVertices + 2);
-      v95 = (unsigned __int16 *)((char *)v94 + (unsigned int)v6->ptr_2AC);
+      v95 = (unsigned __int16 *)((char *)v94 + (unsigned int)ptr_2AC);
       v244 = v94;
       Src->pXInterceptDisplacements = v95;
-      v96 = (int)&v6->pFaces[v92];
+      v96 = (int)&pFaces[v92];
       Src = (BLVFace *)v96;
       v97 = (BLVSector *)((char *)v244 + 2 * *(char *)(v96 + 93) + 2);
-      v98 = (unsigned __int16 *)((char *)v97 + (unsigned int)v6->ptr_2AC);
+      v98 = (unsigned __int16 *)((char *)v97 + (unsigned int)ptr_2AC);
       v244 = v97;
       Src->pYInterceptDisplacements = v98;
-      Src = &v6->pFaces[v92];
-      v99 = v6->ptr_2AC;
+      Src = &pFaces[v92];
+      v99 = ptr_2AC;
       v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
       Src->pZInterceptDisplacements = (unsigned __int16 *)((char *)v99 + (int)v244);
-      Src = &v6->pFaces[v92];
-      v100 = v6->ptr_2AC;
+      Src = &pFaces[v92];
+      v100 = ptr_2AC;
       v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
       Src->pVertexUIDs = (unsigned __int16 *)((char *)v100 + (int)v244);
-      Src = &v6->pFaces[v92];
+      Src = &pFaces[v92];
       ++v92;
-      v101 = v6->ptr_2AC;
+      v101 = ptr_2AC;
       v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
       ++v245;
       Src->pVertexVIDs = (unsigned __int16 *)((char *)v101 + (int)v244);
-      v244 = (BLVSector *)((char *)v244 + 2 * *((char *)&v6->pFaces[v92] - 3) + 2);
-    }
-    while ( v245 < (signed int)v6->uNumFaces );
+      v244 = (BLVSector *)((char *)v244 + 2 * *((char *)&pFaces[v92] - 3) + 2);*/
   }
-  v11 = v6->uNumFaces == 0;
-  v12 = (v6->uNumFaces & 0x80000000u) != 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  pData += blv.uFaces_fdata_Size;
+
+  for (uint i = 0; i < uNumFaces; ++i)
   {
-    v244 = 0;
-    do
+    auto pFace = pFaces + i;
+
+    char pTexName[16];
+    strncpy(pTexName, pData, 10);
+    pData += 10;
+
+    if (pFace->uAttributes & 0x4000)
     {
-      memcpy(Dst, v91, 0xAu);
-      v91 = (char *)v91 + 10;
-      if ( *((char *)&v244->field_2C + (unsigned int)v6->pFaces + 1) & 0x40 )
-      {
-        v102 = pTextureFrameTable->FindTextureByName(Dst);
-        v103 = v244;
-        *(short *)((char *)&v244->pDecorationIDs + (unsigned int)v6->pFaces + 2) = v102;
-        v104 = *(short *)((char *)&v103->pDecorationIDs + (unsigned int)v6->pFaces + 2);
-        if ( v104 )
-        {
-          pTextureFrameTable->LoadAnimationSequenceAndPalettes(v104);
-        }
-        else
-        {
-          v105 = pBitmaps_LOD->LoadTexture(Dst);
-          v106 = v244;
-          *(short *)((char *)&v244->pDecorationIDs + (unsigned int)v6->pFaces + 2) = v105;
-          *((char *)&v106->field_2C + (unsigned int)v6->pFaces + 1) &= 0xBFu;
-        }
-      }
+      pFace->uBitmapID = pTextureFrameTable->FindTextureByName(pTexName);
+      if (pFace->uBitmapID)
+        pTextureFrameTable->LoadAnimationSequenceAndPalettes(pFace->uBitmapID);
       else
       {
-        *(short *)((char *)&v244->pDecorationIDs + (unsigned int)v6->pFaces + 2) = pBitmaps_LOD->LoadTexture(Dst);
+        pFace->uBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
+        pFace->uAttributes &= ~0x4000;
       }
-      ++v245;
-      v244 = (BLVSector *)((char *)v244 + 96);
     }
-    while ( v245 < (signed int)v6->uNumFaces );
+    else
+      pFace->uBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
   }
+
   pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumFaceExtras, v91, 4u);
-  v107 = (char *)v91 + 4;
+
+  memcpy(&uNumFaceExtras, pData, 4u);
+  memcpy(pFaceExtras, pData += 4, uNumFaceExtras * sizeof(BLVFaceExtra));
+  pData += uNumFaceExtras * sizeof(BLVFaceExtra);
+
   pGameLoadingUI_ProgressBar->Progress();
-  v202 = 36 * v6->uNumFaceExtras;
-  v201 = (const char *)v107;
-  v200 = (size_t)v6->pFaceExtras;
-  v245 = v202;
-  memcpy((void *)v200, v107, v202);
-  v108 = (char *)v107 + v245;
-  v245 = 0;
-  if ( (signed int)v6->uNumFaceExtras > 0 )
+
+  //v108 = (char *)v107 + 36 * uNumFaceExtras;
+  //v245 = 0;
+  //*(int *)((char *)&uSourceLen + 1) = 0;
+  for (uint i = 0; i < uNumFaceExtras; ++i)
   {
-    *(int *)((char *)&uSourceLen + 1) = 0;
-    do
-    {
-      memcpy(Dst, v108, 0xAu);
-      v108 = (char *)v108 + 10;
-      if ( !_strcmpi(Dst, nullstring) )
-        *(unsigned __int16 *)((char *)&v6->pFaceExtras->uAdditionalBitmapID + *(int *)((char *)&uSourceLen + 1)) = -1;
-      v109 = pBitmaps_LOD->LoadTexture(Dst);
-      v110 = v6->pFaceExtras;
-      v111 = *(int *)((char *)&uSourceLen + 1);
-      ++v245;
-      *(int *)((char *)&uSourceLen + 1) += 36;
-      *(unsigned __int16 *)((char *)&v110->uAdditionalBitmapID + v111) = v109;
-    }
-    while ( v245 < (signed int)v6->uNumFaceExtras );
+    char pTexName[32];
+    strncpy(pTexName, pData, 10);
+    pData += 10;
+
+    if (!strcmp(pTexName, ""))
+      pFaceExtras[i].uAdditionalBitmapID = -1;
+    else
+      pFaceExtras[i].uAdditionalBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
   }
-  v11 = v6->uNumFaces == 0;
-  v12 = (v6->uNumFaces & 0x80000000u) != 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+
+
+  for (uint i = 0; i < uNumFaces; ++i)
   {
-    v244 = 0;
-    do
+    auto pFace = pFaces + i;
+    auto pFaceExtra = pFaceExtras + pFace->uFaceExtraID;
+
+    if (pFaceExtra->uEventID)
     {
-      v112 = &v6->pFaceExtras[*(short *)((char *)&v244->pDecorationIDs + (unsigned int)v6->pFaces)];
-      if ( v112->uEventID )
-      {
-        if ( v112->HasEventint() )
-          *((char *)&v244->uNumNonBSPFaces + (unsigned int)v6->pFaces) |= 0x10u;
-        else
-          *((char *)&v244->uNumNonBSPFaces + (unsigned int)v6->pFaces) &= 0xEFu;
-      }
-      ++v245;
-      v244 = (BLVSector *)((char *)v244 + 96);
+      if (pFaceExtra->HasEventint())
+        pFace->uAttributes |= 0x100000;
+      else
+        pFace->uAttributes &= ~0x100000;
     }
-    while ( v245 < (signed int)v6->uNumFaces );
   }
+
   pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumSectors, v108, 4u);
-  v113 = (char *)v108 + 4;
+
+  memcpy(&uNumSectors, pData, 4);
+  memcpy(pSectors, pData + 4, uNumSectors * sizeof(BLVSector));
+  pData += 4 + uNumSectors * sizeof(BLVSector);
+
   pGameLoadingUI_ProgressBar->Progress();
-  v202 = 116 * v6->uNumSectors;
-  v201 = (const char *)v113;
-  v200 = (size_t)v6->pSectors;
-  v245 = v202;
-  memcpy((void *)v200, v113, v202);
-  v114 = (char *)v113 + v245;
-  v202 = (int)"L.RData";
-  v201 = (const char *)v6->blv.uSector_rdata_Size;
-  v200 = (size_t)v6->ptr_0002B0_sector_rdata;
-  v115 = pAllocator->AllocNamedChunk((const void *)v200, (unsigned int)v201, "L.RData");
-  v116 = v6->blv.uSector_rdata_Size;
-  v6->ptr_0002B0_sector_rdata = (unsigned __int16 *)v115;
-  v245 = v116;
-  memcpy(v115, v114, v116);
-  v117 = (char *)v114 + v245;
-  v118 = 0;
-  v11 = v6->uNumSectors == 0;
-  v12 = v6->uNumSectors < 0;
-  Src = 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+
+  ptr_0002B0_sector_rdata = (unsigned short *)pAllocator->AllocNamedChunk(ptr_0002B0_sector_rdata, blv.uSector_rdata_Size, "L.RData");
+  memcpy(ptr_0002B0_sector_rdata, pData, blv.uSector_rdata_Size);
+  pData += blv.uSector_rdata_Size;
+
+  for (uint i = 0, j = 0; i < uNumSectors; ++i)
   {
-    do
-    {
-      v6->pSectors[v118].pFloors = (unsigned __int16 *)((char *)Src + (unsigned int)v6->ptr_0002B0_sector_rdata);
-      v244 = &v6->pSectors[v118];
-      v119 = v6->ptr_0002B0_sector_rdata;
+    auto pSector = pSectors + i;
+
+    pSector->pFloors = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_4;
+
+    pSector->pWalls = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_C;
+
+    pSector->pCeilings = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_14;
+
+    pSector->pFluids = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_1C;
+
+    pSector->pPortals = ptr_0002B0_sector_rdata + j;
+    j += pSector->uNumPortals;
+
+    pSector->pFaceIDs = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_2C;
+
+    pSector->pCogs = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_3C;
+
+    pSector->pDecorationIDs = ptr_0002B0_sector_rdata + j;
+    j += pSector->uNumDecorations;
+
+    pSector->pMarkers = ptr_0002B0_sector_rdata + j;
+    j += pSector->field_4C;
+
+
+    //do
+    //{
+      /*pSectors[v118].pFloors = (unsigned __int16 *)((char *)Src + (unsigned int)ptr_0002B0_sector_rdata);
+      v244 = &pSectors[v118];
+      v119 = ptr_0002B0_sector_rdata;
       Src = (BLVFace *)((char *)Src + 2 * v244->field_4);
       v244->pWalls = (unsigned __int16 *)((char *)v119 + (int)Src);
-      v120 = (int)&v6->pSectors[v118];
+      v120 = (int)&pSectors[v118];
       v244 = (BLVSector *)v120;
       v121 = (BLVFace *)((char *)Src + 2 * *(short *)(v120 + 12));
-      v122 = (unsigned __int16 *)((char *)v121 + (unsigned int)v6->ptr_0002B0_sector_rdata);
+      v122 = (unsigned __int16 *)((char *)v121 + (unsigned int)ptr_0002B0_sector_rdata);
       Src = v121;
       v244->pCeilings = v122;
-      v123 = (int)&v6->pSectors[v118];
+      v123 = (int)&pSectors[v118];
       v244 = (BLVSector *)v123;
       v124 = (BLVFace *)((char *)Src + 2 * *(short *)(v123 + 20));
-      v125 = (unsigned __int16 *)((char *)v124 + (unsigned int)v6->ptr_0002B0_sector_rdata);
+      v125 = (unsigned __int16 *)((char *)v124 + (unsigned int)ptr_0002B0_sector_rdata);
       Src = v124;
       v244->pFluids = v125;
-      v244 = &v6->pSectors[v118];
-      v126 = v6->ptr_0002B0_sector_rdata;
+      v244 = &pSectors[v118];
+      v126 = ptr_0002B0_sector_rdata;
       Src = (BLVFace *)((char *)Src + 2 * v244->field_1C);
       v244->pPortals = (unsigned __int16 *)((char *)v126 + (int)Src);
-      v244 = &v6->pSectors[v118];
-      v127 = v6->ptr_0002B0_sector_rdata;
+      v244 = &pSectors[v118];
+      v127 = ptr_0002B0_sector_rdata;
       Src = (BLVFace *)((char *)Src + 2 * v244->uNumPortals);
       v244->pFaceIDs = (unsigned __int16 *)((char *)v127 + (int)Src);
-      v244 = &v6->pSectors[v118];
-      v128 = v6->ptr_0002B0_sector_rdata;
+      v244 = &pSectors[v118];
+      v128 = ptr_0002B0_sector_rdata;
       Src = (BLVFace *)((char *)Src + 2 * v244->field_2C);
       v244->pCogs = (unsigned __int16 *)((char *)v128 + (int)Src);
-      v244 = &v6->pSectors[v118];
-      v129 = v6->ptr_0002B0_sector_rdata;
+      v244 = &pSectors[v118];
+      v129 = ptr_0002B0_sector_rdata;
       Src = (BLVFace *)((char *)Src + 2 * v244->field_3C);
       v244->pDecorationIDs = (unsigned __int16 *)((char *)v129 + (int)Src);
-      v130 = (int)&v6->pSectors[v118];
+      v130 = (int)&pSectors[v118];
       ++v118;
       v244 = (BLVSector *)v130;
-      v131 = v6->ptr_0002B0_sector_rdata;
+      v131 = ptr_0002B0_sector_rdata;
       Src = (BLVFace *)((char *)Src + 2 * *(short *)(v130 + 68));
       ++v245;
       *(int *)(v130 + 80) = (int)(char *)v131 + (int)Src;
-      Src = (BLVFace *)((char *)Src + 2 * *((short *)&v6->pSectors[v118] - 20));
-    }
-    while ( v245 < v6->uNumSectors );
+      Src = (BLVFace *)((char *)Src + 2 * *((short *)&pSectors[v118] - 20));*/
+    //}
+    //while ( v245 < uNumSectors );
+  }
+
+  ptr_0002B8_sector_lrdata = (unsigned __int16 *)pAllocator->AllocNamedChunk(ptr_0002B8_sector_lrdata, blv.uSector_lrdata_Size, "L.RLData");
+  memcpy(ptr_0002B8_sector_lrdata, pData, blv.uSector_lrdata_Size);
+  pData += blv.uSector_lrdata_Size;
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  for (uint i = 0, j = 0; i < uNumSectors; ++i)
+  {
+    pSectors->pLights = (BLVLightMM7 *)(ptr_0002B8_sector_lrdata + j);
+    j += pSectors->uNumLights;
   }
-  v202 = (int)"L.RLData";
-  v201 = (const char *)v6->blv.uSector_lrdata_Size;
-  v200 = (size_t)v6->ptr_0002B8_sector_lrdata;
-  v132 = pAllocator->AllocNamedChunk((const void *)v200, (unsigned int)v201, "L.RLData");
-  v133 = v6->blv.uSector_lrdata_Size;
-  v6->ptr_0002B8_sector_lrdata = (unsigned __int16 *)v132;
-  v245 = v133;
-  memcpy(v132, v117, v133);
-  v134 = (char *)v117 + v245;
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  memcpy(&uNumDoors, pData, 4);
+  pData += 4;
+
+  pGameLoadingUI_ProgressBar->Progress();
+  pGameLoadingUI_ProgressBar->Progress();
+  
+  memcpy(&uNumLevelDecorations, pData, 4);
+  memcpy(pLevelDecorations, pData + 4, uNumLevelDecorations * sizeof(LevelDecoration));
+  pData += 4 + uNumLevelDecorations * sizeof(LevelDecoration);
+
+  for (uint i = 0; i < uNumLevelDecorations; ++i)
+  {
+    pLevelDecorations[i].uDecorationDescID = pDecorationList->GetDecorIdByName(pData);
+
+    pData += 32;
+  }
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  memcpy(&uNumLights, pData, 4);
+  memcpy(pLights, pData + 4, uNumLights * sizeof(BLVLightMM7));
+  pData += 4 + uNumLights * sizeof(BLVLightMM7);
+
+  pGameLoadingUI_ProgressBar->Progress();
+  pGameLoadingUI_ProgressBar->Progress();
+
+  memcpy(&uNumNodes, pData, 4);
+  memcpy(pNodes, pData + 4, uNumNodes * sizeof(BSPNode));
+  pData += 4 + uNumNodes * sizeof(BSPNode);
+  
+  pGameLoadingUI_ProgressBar->Progress();
+  pGameLoadingUI_ProgressBar->Progress();
+
+  memcpy(&uNumSpawnPoints, pData, 4);
+  pSpawnPoints = (SpawnPointMM7 *)pAllocator->AllocNamedChunk(pSpawnPoints, uNumSpawnPoints * sizeof(SpawnPointMM7), "Spawn");
+  memcpy(pSpawnPoints, pData + 4, uNumSpawnPoints * sizeof(SpawnPointMM7));
+  pData += 4 + uNumSpawnPoints * sizeof(SpawnPointMM7);
+  
+  pGameLoadingUI_ProgressBar->Progress();
   pGameLoadingUI_ProgressBar->Progress();
-  v11 = v6->uNumSectors == 0;
-  v12 = v6->uNumSectors < 0;
-  Src = 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+
+  //v201 = (const char *)v148;
+  //v200 = (size_t)pMapVertices;
+  memcpy(&pMapVertices->uNumVertices, pData, 4);
+  memcpy(pMapVertices->pVertices, pData + 4, pMapVertices->uNumVertices * sizeof(Vec3_int_));
+  //v149 = pMapVertices;
+  //v199 = 12 * *v149;
+  //memcpy(v149 + 1, (const void *)(v148 + 4), v199);
+  free(pRawBLV);
+  pRawBLV = nullptr;
+
+  void *pRawDLV = nullptr;
+  strcpy(&pFilename[strlen(pFilename) - 4], ".dlv");
+  File = pNew_LOD->FindContainer(pFilename, 1);
+  fread(&header, 0x10u, 1u, File);//(FILE *)v245);
+  bool _v244 = false;
+  if (header.uVersion != 91969 ||
+      header.pMagic[0] != 'm'  ||
+      header.pMagic[1] != 'v'  ||
+      header.pMagic[2] != 'i'  ||
+      header.pMagic[3] != 'i' )
+  {
+    MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1090", 0);
+    _v244 = true;
+  }
+  else
   {
-    v135 = v6->pSectors;
-    v136 = 0;
-    for ( File = 0; ; v136 = File )
+    pRawDLV = malloc(header.uDecompressedSize);
+    if (header.uCompressedSize == header.uDecompressedSize)
+      fread(pRawDLV, 1, header.uCompressedSize, File);
+    else if (header.uCompressedSize < header.uDecompressedSize)
     {
-      v137 = v6->ptr_0002B8_sector_lrdata;
-      File = (FILE *)((char *)File + 116);
-      ++v245;
-      *(int *)((char *)&v136[2]._bufsiz + (int)v135) = (int)((char *)v137 + (int)Src);
-      v135 = v6->pSectors;
-      Src = (BLVFace *)((char *)Src + 2 * *(short *)((char *)&v136[2]._charbuf + (int)v135));
-      if ( v245 >= v6->uNumSectors )
-        break;
+      auto pTmpMem = malloc(header.uCompressedSize);
+      {
+        fread(pTmpMem, header.uCompressedSize, 1, File);
+
+        uint uDecompressedSize = header.uDecompressedSize;
+        zlib::MemUnzip(pRawDLV, &uDecompressedSize, pTmpMem, header.uCompressedSize);
+
+        if (uDecompressedSize != header.uDecompressedSize)
+          Log::Warning(L"uDecompressedSize != header.uDecompressedSize in DLV");
+      }
+      free(pTmpMem);
+    }
+    else
+      MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1108", 0);
+
+    pData = (char *)pRawDLV;
+  }
+  
+  memcpy(&dlv, pData, 40);
+  pData += 40;
+
+  //v152 = dlv.uNumFacesInBModels;
+  if (dlv.uNumFacesInBModels)
+  {
+    //v153 = dlv.uNumDecorations;
+    if (dlv.uNumDecorations)
+    {
+      if (dlv.uNumFacesInBModels != uNumFaces ||
+          dlv.uNumDecorations != uNumLevelDecorations)
+        _v244 = true;
     }
   }
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumDoors, v134, 4u);
-  v138 = (char *)v134 + 4;
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&uNumLevelDecorations, v138, 4u);
-  v138 = (char *)v138 + 4;
-  pGameLoadingUI_ProgressBar->Progress();
-  v245 = 32 * uNumLevelDecorations;
-  memcpy(pLevelDecorations, v138, 32 * uNumLevelDecorations);
-  v139 = (char *)v138 + v245;
-  v245 = 0;
-  if ( (signed int)uNumLevelDecorations > 0 )
+
+  if (dword_6BE364_game_settings_1 & 0x2000 )
+    _i = 29030400;
+  bool _a = false;
+  if ( a3 - dlv.uLastRepawnDay >= _i && strcmpi(pCurrentMapName, "d29.dlv") )
+    _a = true;
+
+  //v154 = 875;
+  if (_v244)
   {
-    File = (FILE *)pLevelDecorations;
-    do
-    {
-      memcpy(pName, v139, 0x20u);
-      v139 = (char *)v139 + 32;
-      v140 = pDecorationList->GetDecorIdByName(pName);
-      v141 = File;
-      ++v245;
-      ++File;
-      LOWORD(v141->_ptr) = v140;
-    }
-    while ( v245 < (signed int)uNumLevelDecorations );
-  }
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumLights, v139, 4u);
-  v142 = (char *)v139 + 4;
-  pGameLoadingUI_ProgressBar->Progress();
-  v202 = 16 * v6->uNumLights;
-  v201 = (const char *)v142;
-  v200 = (size_t)v6->pLights;
-  v245 = v202;
-  memcpy((void *)v200, v142, v202);
-  v143 = (char *)v142 + v245;
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumNodes, v143, 4u);
-  v143 = (char *)v143 + 4;
-  pGameLoadingUI_ProgressBar->Progress();
-  v202 = 8 * v6->uNumNodes;
-  v201 = (const char *)v143;
-  v200 = (size_t)v6->pNodes;
-  v245 = v202;
-  memcpy((void *)v200, v143, v202);
-  v144 = (char *)v143 + v245;
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uNumSpawnPoints, v144, 4u);
-  v144 = (char *)v144 + 4;
-  pGameLoadingUI_ProgressBar->Progress();
-  v145 = v6->uNumSpawnPoints;
-  v202 = (int)"Spawn";
-  v201 = (const char *)(24 * v145);
-  v200 = (size_t)v6->pSpawnPoints;
-  v146 = pAllocator->AllocNamedChunk((const void *)v200, 24 * v145, "Spawn");
-  v147 = v6->uNumSpawnPoints;
-  v6->pSpawnPoints = (SpawnPointMM7 *)v146;
-  v245 = 24 * v147;
-  memcpy(v146, v144, 24 * v147);
-  v148 = (int)((char *)v144 + v245);
-  pGameLoadingUI_ProgressBar->Progress();
-  v202 = 4;
-  v201 = (const char *)v148;
-  v200 = (size_t)v6->pMapVertices;
-  memcpy((void *)v200, (const void *)v148, 4u);
-  v149 = v6->pMapVertices;
-  v199 = 12 * *v149;
-  memcpy(v149 + 1, (const void *)(v148 + 4), v199);
-  free(ptr);
-  v202 = (int)".dlv";
-  v150 = strlen(pFilename);
-  strcpy(&v238[v150], (const char *)v202);
-  v245 = (int)pNew_LOD->FindContainer(pFilename, 1);
-  fread(&header, 0x10u, 1u, (FILE *)v245);
-  v244 = 0;
-  if ( header.uVersion != 91969
-    || header.pMagic[0] != 'm'
-    || header.pMagic[1] != 'v'
-    || header.pMagic[2] != 'i'
-    || header.pMagic[3] != 'i' )
-  {
-    MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1090", 0);
-    v244 = (BLVSector *)1;
-  }
-  v151 = header.uCompressedSize;
-  Count = header.uDecompressedSize;
-  Src = 0;
-  File = 0;
-  if ( !v244 )
-  {
-    Src = (BLVFace *)malloc(header.uDecompressedSize);
-    File = (FILE *)Src;
-    if ( v151 <= Count )
-    {
-      if ( v151 == Count )
-      {
-        fread(Src, 1u, Count, (FILE *)v245);
-      }
-      else
-      {
-        *(int *)((char *)&uSourceLen + 1) = (int)malloc(v151);
-        fread(*(void **)((char *)&uSourceLen + 1), v151, 1u, (FILE *)v245);
-        zlib::MemUnzip(Src, &Count, *(const void **)((char *)&uSourceLen + 1), v151);
-        free(*(void **)((char *)&uSourceLen + 1));
-      }
-    }
-    else
-    {
-    MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1108", 0);
-    }
-    memcpy(&v6->dlv, Src, 0x28u);
-    Src = (BLVFace *)((char *)Src + 40);
-  }
-  v152 = v6->dlv.uNumFacesInBModels;
-  if ( v152 )
-  {
-    v153 = v6->dlv.uNumDecorations;
-    if ( v153 )
-    {
-      if ( v152 != pIndoor->uNumFaces || v153 != uNumLevelDecorations )
-        v244 = (BLVSector *)1;
-    }
-  }
-  if ( BYTE1(dword_6BE364_game_settings_1) & 0x20 )
-    i = 29030400;
-  *(int *)((char *)&uSourceLen + 1) = 0;
-  if ( a3 - v6->dlv.uLastRepawnDay >= i && _strcmpi(pCurrentMapName, "d29.dlv") )
-    *(int *)((char *)&uSourceLen + 1) = 1;
-  v154 = 875;
-  if ( v244 )
-  {
-    memset(v203, 0, 0x36Bu);
+    memset(v203, 0, 0x36B);
     goto LABEL_132;
   }
-  if ( *(int *)((char *)&uSourceLen + 1) || !v6->dlv.uLastRepawnDay )
+  if (_a || !dlv.uLastRepawnDay )
   {
-    memcpy(v203, Src, 0x36Bu);
+    memcpy(v203, pData, 0x36B);
 LABEL_132:
     free(File);
-    v11 = v244 == (BLVSector *)1;
-    v6->dlv.uLastRepawnDay = a3;
-    if ( v11 )
-      ++v6->dlv.uNumRespawns;
-    v202 = 0;
-    v201 = pFilename;
+    dlv.uLastRepawnDay = a3;
+    if (_v244)
+      ++dlv.uNumRespawns;
+    //v201 = pFilename;
     *(int *)pDest = 1;
-    v245 = (int)pGames_LOD->FindContainer(v201, v202);
-    fread(&header, 0x10u, 1u, (FILE *)v245);
-    v155 = header.uCompressedSize;
-    Count = header.uDecompressedSize;
-    Src = (BLVFace *)malloc(header.uDecompressedSize);
+    File = pGames_LOD->FindContainer(pFilename, 0);
+    fread(&header, 0x10u, 1u, File);
+    auto v155 = header.uCompressedSize;
+    auto Count = header.uDecompressedSize;
+    auto Src = (BLVFace *)malloc(header.uDecompressedSize);
     File = (FILE *)Src;
     if ( v155 <= Count )
     {
       if ( v155 == Count )
       {
-        fread(Src, 1u, Count, (FILE *)v245);
+        fread(Src, 1u, Count, File);
       }
       else
       {
-        *(int *)((char *)&uSourceLen + 1) = (int)malloc(v155);
-        fread(*(void **)((char *)&uSourceLen + 1), v155, 1u, (FILE *)v245);
-        zlib::MemUnzip(Src, &Count, *(const void **)((char *)&uSourceLen + 1), v155);
-        free(*(void **)((char *)&uSourceLen + 1));
+        auto _uSourceLen = malloc(v155);
+        fread(_uSourceLen, v155, 1u, File);
+        zlib::MemUnzip(Src, &Count, _uSourceLen, v155);
+        free(_uSourceLen);
       }
     }
     else
     {
     MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1195", 0);
     }
-    Src = (BLVFace *)((char *)Src + 40);
-    v154 = 875;
+    pData = ((char *)Src + 40);
+    //v154 = 875;
     goto LABEL_140;
   }
   *(int *)pDest = 0;
 LABEL_140:
-  v202 = (int)".blv";
-  v156 = strlen(pFilename);
-  strcpy(&v238[v156], (const char *)v202);
-  memcpy(v6->_visible_outlines, Src, v154);
-  Src = (BLVFace *)((char *)Src + v154);
+  //v202 = (int)".blv";
+  //v156 = strlen(pFilename);
+  strcpy(&pFilename[strlen(pFilename) - 4], ".blv");
+  memcpy(_visible_outlines, pData, 875);
+  pData += 875;
+
   if ( *(int *)pDest )
-    memcpy(v6->_visible_outlines, v203, v154);
-  v157 = 0;
-  if ( (signed int)*pIndoor->pMapVertices > 0 )
+    memcpy(_visible_outlines, v203, 875);
+
+  for (uint i = 0; i < pMapVertices->uNumVertices; ++i)
   {
-    Argsk = 0;
-    do
-    {
-      if ( (unsigned __int8)(1 << (7 - v157 % 8)) & v6->_visible_outlines[v157 / 8] )
-        BYTE2(v6->pMapVertices[Argsk + 3]) |= 1u;
-      Argsk += 3;
-      ++v157;
-    }
-    while ( v157 < (signed int)*pIndoor->pMapVertices );
+    auto pVertex = pMapVertices->pVertices + i;
+    if ((unsigned __int8)(1 << (7 - i % 8)) & _visible_outlines[i / 8])
+      pVertex->uFlags |= 1;
   }
-  v245 = 0;
-  if ( (signed int)v6->uNumFaces > 0 )
+
+
+  for (uint i = 0; i < uNumFaces; ++i)
   {
-    v158 = 0;
-    do
+    auto pFace = pFaces + i;
+    auto pFaceExtra = pFaceExtras + pFace->uFaceExtraID;
+
+    memcpy(&pFace->uAttributes, pData, 4);
+    pData += 4;
+
+    if (pFaceExtra->uEventID)
     {
-      v200 = (size_t)&v6->pFaces[v158].uAttributes;
-      memcpy((void *)v200, Src, 4u);
-      v159 = v6->pFaces;
-      v160 = v6->pFaceExtras;
-      Src = (BLVFace *)((char *)Src + 4);
-      v161 = &v160[v159[v158].uFaceExtraID];
-      if ( v161->uEventID )
-      {
-        if ( v161->HasEventint() )
-          BYTE2(v6->pFaces[v158].uAttributes) |= 0x10u;
-        else
-          BYTE2(v6->pFaces[v158].uAttributes) &= 0xEFu;
-      }
-      ++v245;
-      ++v158;
+      if (pFaceExtra->HasEventint())
+        pFace->uAttributes |= 0x100000;
+      else
+        pFace->uAttributes &= ~0x100000;
     }
-    while ( v245 < (signed int)v6->uNumFaces );
   }
+
   pGameLoadingUI_ProgressBar->Progress();
-  v162 = 0;
-  if ( (signed int)uNumLevelDecorations > 0 )
+
+  for (uint i = 0; i < uNumLevelDecorations; ++i)
   {
-    Argsl = &pLevelDecorations[0].field_2;
-    do
-    {
-      memcpy(Argsl, Src, 2u);
-      Src = (BLVFace *)((char *)Src + 2);
-      Argsl = (char *)Argsl + 32;
-      ++v162;
-    }
-    while ( v162 < (signed int)uNumLevelDecorations );
+    memcpy(&pLevelDecorations[i].field_2, pData, 2);
+    pData += 2;
   }
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&uNumActors, Src, 4u);
-  Src = (BLVFace *)((char *)Src + 4);
+
   pGameLoadingUI_ProgressBar->Progress();
-  v163 = 836 * uNumActors;
-  memcpy(pActors, Src, 836 * uNumActors);
-  Src = (BLVFace *)((char *)Src + v163);
+
+  memcpy(&uNumActors, pData, 4);
+  memcpy(pActors, pData + 4, uNumActors * sizeof(Actor));
+  pData += 4 + uNumActors * sizeof(Actor);
+
+  pGameLoadingUI_ProgressBar->Progress();
+  pGameLoadingUI_ProgressBar->Progress();
+
+  memcpy(&uNumLayingItems, pData, 4);
+  memcpy(pLayingItems, pData + 4, uNumLayingItems * sizeof(LayingItem));
+  pData += 4 + uNumLayingItems * sizeof(LayingItem);
+
   pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&uNumLayingItems, Src, 4u);
-  Src = (BLVFace *)((char *)Src + 4);
-  pGameLoadingUI_ProgressBar->Progress();
-  v164 = 112 * uNumLayingItems;
-  memcpy(pLayingItems, Src, 112 * uNumLayingItems);
-  Src = (BLVFace *)((char *)Src + v164);
-  if ( (signed int)uNumLayingItems > 0 )
+
+  for (uint i = 0; i < uNumLayingItems; ++i)
   {
-    v165 = pObjectList->uNumObjects;
-    v166 = (char *)&pLayingItems[0].stru_24;
-    i = uNumLayingItems;
-    do
+    auto pItem = pLayingItems + i;
+ 
+    if (pItem->stru_24.uItemID && !(pItem->uAttributes & 0x0100))
     {
-      if ( *(int *)v166 && !(*(v166 - 9) & 1) )
-      {
-        Argsm = 0;
-        v167 = pItemsTable->pItems[*(int *)v166].uSpriteID;
-        *((short *)v166 - 18) = v167;
-        if ( (signed int)v165 <= 0 )
+      pItem->uItemType = pItemsTable->pItems[pItem->stru_24.uItemID - 1].uSpriteID;
+
+      uint uObjectID = 0;
+      for (uint j = 0; j < pObjectList->uNumObjects; ++j)
+        if (pItem->uItemType == pObjectList->pObjects[j].uObjectID)
         {
-LABEL_165:
-          v168 = 0;
-        }
-        else
-        {
-          pDest = (char *)&pObjectList->pObjects->uObjectID;
-          while ( v167 != *(short *)pDest )
-          {
-            ++Argsm;
-            pDest += 56;
-            if ( Argsm >= (signed int)v165 )
-              goto LABEL_165;
-          }
-          v168 = Argsm;
+          pItem->uObjectDescID = j;
+          break;
         }
-        *((short *)v166 - 17) = v168;
-      }
-      v166 += 112;
-      --i;
     }
-    while ( i );
   }
-  pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&uNumChests, Src, 4u);
-  Src = (BLVFace *)((char *)Src + 4);
+
   pGameLoadingUI_ProgressBar->Progress();
-  v169 = 5324 * uNumChests;
-  memcpy(pChests, Src, 5324 * uNumChests);
-  Src = (BLVFace *)((char *)Src + v169);
+
+  memcpy(&uNumChests, pData, 4);
+  memcpy(pChests, pData + 4, uNumChests * sizeof(Chest));
+  pData += 4 + uNumChests * sizeof(Chest);
+
+  pGameLoadingUI_ProgressBar->Progress();
   pGameLoadingUI_ProgressBar->Progress();
-  v202 = 16000;
-  v201 = (const char *)Src;
-  v200 = (size_t)v6->pDoors;
-  memcpy((void *)v200, Src, 0x3E80u);
-  Src = (BLVFace *)((char *)Src + 16000);
-  v202 = (int)"L.DData";
-  v201 = (const char *)v6->blv.uDoors_ddata_Size;
-  v200 = (size_t)v6->ptr_0002B4_doors_ddata;
-  v170 = pAllocator->AllocNamedChunk((const void *)v200, (unsigned int)v201, "L.DData");
-  v171 = v6->blv.uDoors_ddata_Size;
-  v6->ptr_0002B4_doors_ddata = (unsigned __int16 *)v170;
-  memcpy(v170, Src, v171);
-  Src = (BLVFace *)((char *)Src + v171);
-  v172 = 0;
-  v11 = v6->uNumDoors == 0;
-  v12 = v6->uNumDoors < 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+
+  memcpy(pDoors, pData, 0x3E80);
+  pData += 0x3E80;
+
+  //v201 = (const char *)blv.uDoors_ddata_Size;
+  //v200 = (size_t)ptr_0002B4_doors_ddata;
+  //v170 = pAllocator->AllocNamedChunk(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
+  //v171 = blv.uDoors_ddata_Size;
+  ptr_0002B4_doors_ddata = (unsigned __int16 *)pAllocator->AllocNamedChunk(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
+  memcpy(ptr_0002B4_doors_ddata, pData, blv.uDoors_ddata_Size);
+  pData += blv.uDoors_ddata_Size;
+
+  //Src = (BLVFace *)((char *)Src + v171);
+  //v172 = 0;
+  //v245 = 0;
+  //if (uNumDoors > 0)
+  for (uint i = 0, j = 0; i < uNumDoors; ++i)
   {
-    v173 = v6->pDoors;
+    auto pDoor = pDoors + i;
+
+    pDoor->pVertexIDs = ptr_0002B4_doors_ddata + j;
+    j += pDoor->uNumVertices;
+
+    pDoor->pFaceIDs = ptr_0002B4_doors_ddata + j;
+    j += pDoor->uNumFaces;
+
+    pDoor->pSectorIDs = ptr_0002B4_doors_ddata + j;
+    j += pDoor->field_48;
+
+    pDoor->pDeltaUs = (short *)(ptr_0002B4_doors_ddata + j);
+    j += pDoor->uNumFaces;
+
+    pDoor->pDeltaVs = (short *)(ptr_0002B4_doors_ddata + j);
+    j += pDoor->uNumFaces;
+
+    pDoor->pXOffsets = ptr_0002B4_doors_ddata + j;
+    j += pDoor->uNumOffsets;
+
+    pDoor->pYOffsets = ptr_0002B4_doors_ddata + j;
+    j += pDoor->uNumOffsets;
+
+    pDoor->pZOffsets = ptr_0002B4_doors_ddata + j;
+    j += pDoor->uNumOffsets;
+    /*v173 = pDoors;
     for ( k = 0; ; v172 = v188 + 2 * *((short *)&v173[k] - 3) )
     {
-      v173[k].pVertexIDs = (unsigned __int16 *)((char *)v6->ptr_0002B4_doors_ddata + v172);
-      v175 = &v6->pDoors[k];
+      v173[k].pVertexIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v172);
+      v175 = &pDoors[k];
       v176 = v172 + 2 * v175->uNumVertices;
-      v175->pFaceIDs = (unsigned __int16 *)((char *)v6->ptr_0002B4_doors_ddata + v176);
-      v177 = &v6->pDoors[k];
+      v175->pFaceIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v176);
+      v177 = &pDoors[k];
       v178 = v176 + 2 * v177->uNumFaces;
-      v177->pSectorIDs = (unsigned __int16 *)((char *)v6->ptr_0002B4_doors_ddata + v178);
-      v179 = &v6->pDoors[k];
+      v177->pSectorIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v178);
+      v179 = &pDoors[k];
       v180 = v178 + 2 * v179->field_48;
-      v179->pDeltaUs = (__int16 *)((char *)v6->ptr_0002B4_doors_ddata + v180);
-      v181 = &v6->pDoors[k];
+      v179->pDeltaUs = (__int16 *)((char *)ptr_0002B4_doors_ddata + v180);
+      v181 = &pDoors[k];
       v182 = v180 + 2 * v181->uNumFaces;
-      v181->pDeltaVs = (__int16 *)((char *)v6->ptr_0002B4_doors_ddata + v182);
-      v183 = &v6->pDoors[k];
+      v181->pDeltaVs = (__int16 *)((char *)ptr_0002B4_doors_ddata + v182);
+      v183 = &pDoors[k];
       v184 = v182 + 2 * v183->uNumFaces;
-      v183->pXOffsets = (unsigned __int16 *)((char *)v6->ptr_0002B4_doors_ddata + v184);
-      v185 = &v6->pDoors[k];
+      v183->pXOffsets = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v184);
+      v185 = &pDoors[k];
       v186 = v184 + 2 * v185->uNumOffsets;
-      v185->pYOffsets = (unsigned __int16 *)((char *)v6->ptr_0002B4_doors_ddata + v186);
-      v187 = &v6->pDoors[k];
+      v185->pYOffsets = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v186);
+      v187 = &pDoors[k];
       ++k;
       v188 = v186 + 2 * v187->uNumOffsets;
-      v189 = (unsigned __int16 *)((char *)v6->ptr_0002B4_doors_ddata + v188);
+      v189 = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v188);
       ++v245;
       v187->pZOffsets = v189;
-      v173 = v6->pDoors;
-      if ( v245 >= v6->uNumDoors )
+      v173 = pDoors;
+      if ( v245 >= uNumDoors )
         break;
-    }
+    }*/
   }
-  v190 = 0;
-  v11 = v6->uNumDoors == 0;
-  v12 = v6->uNumDoors < 0;
-  v245 = 0;
-  if ( !(v12 | v11) )
+  //v190 = 0;
+  //v245 = 0;
+  for (uint i = 0; i < uNumDoors; ++i)
   {
-    v191 = v6->pDoors;
-    pDest = 0;
-    do
+    auto pDoor = pDoors + i;
+
+    for (uint j = 0; j < pDoor->uNumFaces; ++j)
     {
-      Argsn = 0;
+      auto pFace = pFaces + pDoor->pFaceIDs[j];
+      auto pFaceExtra = pFaceExtras + pFace->uFaceExtraID;
+
+      pDoor->pDeltaUs[j] = pFaceExtra->sTextureDeltaU;
+      pDoor->pDeltaVs[j] = pFaceExtra->sTextureDeltaV;
+    }
+    //v191 = pDoors;
+    //pDest = 0;
+    //do
+   // {
+      /*Argsn = 0;
       for ( l = (BLVDoor *)&v190[(int)v191];
             Argsn < *(short *)&v190[(int)v191 + 70];
             l = (BLVDoor *)&v190[(int)v191] )
       {
         v193 = Argsn;
         v194 = l->pFaceIDs[Argsn++];
-        v195 = &v6->pFaceExtras[v6->pFaces[v194].uFaceExtraID];
+        v195 = &pFaceExtras[pFaces[v194].uFaceExtraID];
         l->pDeltaUs[v193] = v195->sTextureDeltaU;
         v190 = pDest;
-        *(short *)(v193 * 2 + *(int *)&pDest[(unsigned int)v6->pDoors + 52]) = v195->sTextureDeltaV;
-        v191 = v6->pDoors;
+        *(short *)(v193 * 2 + *(int *)&pDest[(unsigned int)pDoors + 52]) = v195->sTextureDeltaV;
+        v191 = pDoors;
       }
       ++v245;
       v190 += 80;
-      pDest = v190;
-    }
-    while ( v245 < v6->uNumDoors );
+      pDest = v190;*/
+    //}
+    //while ( v245 < uNumDoors );
   }
+
+
   pGameLoadingUI_ProgressBar->Progress();
-  v196 = Src;
-  memcpy(&stru_5E4C90, Src, 0xC8u);
+
+  memcpy(&stru_5E4C90, pData, 0xC8);
+  pData += 0xC8;
+
   pGameLoadingUI_ProgressBar->Progress();
-  memcpy(&v6->uLastVisitDay, &v196[2].pFacePlane.vNormal.z, 0x38u);
-  free(File);
-  v5 = 0;
-LABEL_179:
-  pSoundList->_4A9A67(64, v5);
-  pSoundList->_4A9A67(103, v5);
-  pSoundList->_4A9A67(63, v5);
-  pSoundList->_4A9A67(102, v5);
-  pSoundList->_4A9A67(50, v5);
-  pSoundList->_4A9A67(89, v5);
+
+  memcpy(&stru1, pData, 0x38u);
+  pData += 0x38;
+
+  free(pRawDLV);
+  //v5 = 0;
+
+  pSoundList->_4A9A67(64, 0);
+  pSoundList->_4A9A67(103, 0);
+  pSoundList->_4A9A67(63, 0);
+  pSoundList->_4A9A67(102, 0);
+  pSoundList->_4A9A67(50, 0);
+  pSoundList->_4A9A67(89, 0);
+
   return 0;
 }