diff SaveLoad.cpp @ 810:f5156b8c61ad

savegame refactoring
author Gloval
date Tue, 26 Mar 2013 00:57:54 +0400
parents 90bcfb56c8f9
children 35122475edd7 cfc65feef029
line wrap: on
line diff
--- a/SaveLoad.cpp	Mon Mar 25 14:56:50 2013 +0200
+++ b/SaveLoad.cpp	Tue Mar 26 00:57:54 2013 +0400
@@ -24,6 +24,15 @@
 
 
 
+struct SaveDataHeader
+    {
+    int Signature;
+    char txt_ver[4];
+    int compressed_size;
+    int uncompressed_size;
+    };
+
+
 
 
 struct SavegameList *pSavegameList = new SavegameList;
@@ -228,16 +237,16 @@
 
 
 //----- (0045F469) --------------------------------------------------------
-int __fastcall SaveGame(int a1, __int16 *a2)
-{
+void SaveGame( bool IsAutoSAve, bool NotSaveWorld )
+    {
   int result; // eax@1
-  void *pScreenshot; // edi@5
-  int v4; // eax@6
+  unsigned short *pScreenshot; // edi@5
+  int text_pos; // eax@6
   int v5; // eax@6
   int v6; // eax@6
   const char *v7; // edi@8
   FILE *v8; // edi@24
-  int v9; // edi@30
+  char* compressed_buf; // edi@30
   void *v10; // esi@31
   void *v11; // esi@31
   void *v12; // esi@37
@@ -249,7 +258,7 @@
   unsigned int v18; // ecx@38
   unsigned int v19; // esi@39
   BSPModel *v20; // edx@39
-  void *v21; // esi@41
+  char *data_write_pos; // esi@41
   void *v22; // esi@41
   BSPModel *v23; // eax@42
   signed int v24; // edi@42
@@ -283,7 +292,7 @@
   int pPositionX; // [sp+20Ch] [bp-64h]@2
   int v53; // [sp+210h] [bp-60h]@2
   int v54; // [sp+214h] [bp-5Ch]@2
-  int Src; // [sp+218h] [bp-58h]@30
+  SaveDataHeader Src; // [sp+218h] [bp-58h]@30
   char v56; // [sp+21Ch] [bp-54h]@30
   char v57; // [sp+21Dh] [bp-53h]@30
   char v58; // [sp+21Eh] [bp-52h]@30
@@ -291,12 +300,12 @@
   int v60; // [sp+220h] [bp-50h]@30
   int v61; // [sp+224h] [bp-4Ch]@30
   int v62; // [sp+228h] [bp-48h]@2
-  LOD::Directory pDir; // [sp+22Ch] [bp-44h]@2
+  LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2
   size_t Size; // [sp+250h] [bp-20h]@26
   __int16 *v66; // [sp+254h] [bp-1Ch]@1
-  void *DstBuf; // [sp+258h] [bp-18h]@2
+  char *uncompressed_buff; // [sp+258h] [bp-18h]@2
   __int16 *v68; // [sp+25Ch] [bp-14h]@32
-  unsigned int v69; // [sp+260h] [bp-10h]@23
+  unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23
   int v70; // [sp+264h] [bp-Ch]@22
   std::string *v71; // [sp+268h] [bp-8h]@8
   int a3; // [sp+26Fh] [bp-1h]@8
@@ -304,10 +313,10 @@
   //v66 = a2;
   strcpy(byte_6BE3B0, pCurrentMapName);
   if (!_strcmpi(pCurrentMapName, "d05.blv")) // arena
-    return false;
+    return;
 
-  DstBuf = malloc(0xF4240);
-  pDir.Reset();
+  uncompressed_buff = (char*)malloc(1000000);
+  pLodDirectory.Reset();
   pPositionX = pParty->vPosition.x;
   v51 = pParty->vPosition.y;
   v62 = pParty->vPosition.z;
@@ -322,25 +331,25 @@
   if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
     pIndoor->stru1.uLastVisitDay = pParty->uTimePlayed;
   else
-    pOutdoor->uLastVisitDay = pParty->uTimePlayed;
+    pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed;
   pScreenshot = MakeScreenshot(150, 112);
-  strcpy(pDir.pFilename, "image.pcx");
-  pRenderer->_49F5A2((int)pScreenshot, 150, 112, DstBuf, 1000000, (int)&pDir.uDataSize);
+  strcpy(pLodDirectory.pFilename, "image.pcx");
+  pRenderer->PackPCXpicture(pScreenshot, 150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize);
   free(pScreenshot);
   if (pCurrentScreen == SCREEN_SAVEGAME)
   {
     pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
     pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
-    v4 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[190]);
-    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v4 + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Сохранение
-    v5 = pFontSmallnum->AlignText_Center(0xBA, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
-    pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, v5 + 25, 0x103u, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0);
-    v6 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[165]);
-    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v6 + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Пожалуйста, подождите
+    text_pos = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[190]);
+    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos + 25, 219, 0, pGlobalTXT_LocalizationStrings[190], 0, 0, 0); //Сохранение
+    text_pos  = pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
+    pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, text_pos  + 25, 259, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0);
+    text_pos  = pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]);
+    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, text_pos  + 25, 299, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0); //Пожалуйста, подождите
     pRenderer->Present();
   }
 
-  if (pNew_LOD->Write(&pDir, DstBuf, 0))
+  if (pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0))
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 200); //Сохраненная игра повреждена! Code=%d
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:773", 0);
@@ -352,45 +361,45 @@
   memset(header.field_30, 0, 52);
   strcpy(header.pLocationName, pCurrentMapName);
   header.uWordTime = pParty->uTimePlayed;
-  strcpy(pDir.pFilename, "header.bin");
-  pDir.uDataSize = sizeof(SavegameHeader);
-  if (pNew_LOD->Write(&pDir, &header, 0))
+  strcpy(pLodDirectory.pFilename, "header.bin");
+  pLodDirectory.uDataSize = sizeof(SavegameHeader);
+  if (pNew_LOD->Write(&pLodDirectory, &header, 0))
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 201);
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:784", 0);
   }
-  strcpy(pDir.pFilename, "party.bin");
-  pDir.uDataSize = 90680;
-  if ( pNew_LOD->Write(&pDir, pParty, 0) )
+  strcpy(pLodDirectory.pFilename, "party.bin");
+  pLodDirectory.uDataSize = sizeof(Party); //90680;
+  if ( pNew_LOD->Write(&pLodDirectory, pParty, 0) )
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 202);
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:793", 0);
   }
-  strcpy(pDir.pFilename, "clock.bin");
-  pDir.uDataSize = 40;
-  if ( pNew_LOD->Write(&pDir, pEventTimer, 0) )
+  strcpy(pLodDirectory.pFilename, "clock.bin");
+  pLodDirectory.uDataSize =sizeof(Timer);// 40;
+  if ( pNew_LOD->Write(&pLodDirectory, pEventTimer, 0) )
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 203);
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:802", 0);
   }
-  strcpy(pDir.pFilename, "overlay.bin");
-  pDir.uDataSize = 1008;
-  if ( pNew_LOD->Write(&pDir, pOtherOverlayList, 0) )
+  strcpy(pLodDirectory.pFilename, "overlay.bin");
+  pLodDirectory.uDataSize =sizeof(OtherOverlayList);// 1008;
+  if ( pNew_LOD->Write(&pLodDirectory, pOtherOverlayList, 0) )
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 204);
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0);
   }
-  strcpy(pDir.pFilename, "npcdata.bin");
-  pDir.uDataSize = 501 * sizeof(NPCData);
-  assert(pDir.uDataSize == 38076);
-  if ( pNew_LOD->Write(&pDir, pNPCStats->pNewNPCData, 0) )
+  strcpy(pLodDirectory.pFilename, "npcdata.bin");
+  pLodDirectory.uDataSize = 501 * sizeof(NPCData);
+  assert(pLodDirectory.uDataSize == 38076);
+  if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pNewNPCData, 0) )
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 205);
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:820", 0);
   }
-  strcpy(pDir.pFilename, "npcgroup.bin");
-  pDir.uDataSize = 102;
-  if ( pNew_LOD->Write(&pDir, pNPCStats->pGroups_copy, 0) )
+  strcpy(pLodDirectory.pFilename, "npcgroup.bin");
+  pLodDirectory.uDataSize = 102;
+  if ( pNew_LOD->Write(&pLodDirectory, pNPCStats->pGroups_copy, 0) )
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 206);
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:829", 0);
@@ -406,13 +415,13 @@
         __debugbreak();
         sprintf(Str, "lloyd%d%d.pcx", i, j);
         fseek(v8, 0, 2);
-        pDir.uDataSize = ftell(v8);
+        pLodDirectory.uDataSize = ftell(v8);
         rewind(v8);
-        fread(DstBuf, pDir.uDataSize, 1, v8);
-        strcpy((char *)&pDir, Str);
+        fread(uncompressed_buff, pLodDirectory.uDataSize, 1, v8);
+        strcpy((char *)&pLodDirectory, Str);
         fclose(v8);
         remove(Str);
-        if ( pNew_LOD->Write(&pDir, DstBuf, 0) )
+        if ( pNew_LOD->Write(&pLodDirectory, uncompressed_buff, 0) )
         {
           sprintf(Str, pGlobalTXT_LocalizationStrings[612], 207);
           MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:857", 0);
@@ -421,114 +430,100 @@
       }
 	}
   }
-  if ( !a2 )
+  if ( !NotSaveWorld )
   {
     //__debugbreak();
-    sub_42FA22_mess_with_laying_item_list();
-    v9 = (int)malloc(0xF4240);
-    v71 = (std::string *)v9;
-    Src = 91969;
-    v56 = 109;
-    v57 = 118;
-    v58 = 105;
-    v59 = 105;
-    v60 = 0;
-    v61 = 0;
-    memcpy((void *)v9, &Src, 0x10);
+    CompactLayingItemsList();
+    compressed_buf = (char*)malloc(1000000);
+  //  v71 = (std::string *)compressed_buf;
+    Src.Signature = 91969;
+    Src.txt_ver[0] = 'm';
+    Src.txt_ver[1] = 'v';
+    Src.txt_ver[2] = 'i';
+    Src.txt_ver[3] = 'i';
+    Src.compressed_size = 0;
+    Src.uncompressed_size = 0;
+    data_write_pos = uncompressed_buff;
+    memcpy((void *)compressed_buf, &Src, 0x10);
     if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
     {
       pIndoor->dlv.uNumFacesInBModels = pIndoor->uNumFaces;
       pIndoor->dlv.uNumBModels = 0;
       pIndoor->dlv.uNumDecorations = uNumLevelDecorations;
-      memcpy(DstBuf, &pIndoor->dlv, 0x28);
-      v10 = (char *)DstBuf + 40;
-      memcpy(v10, pIndoor->_visible_outlines, 0x36B);
-      v11 = (char *)v10 + 875;
-      if ( (signed int)pIndoor->uNumFaces > 0 )
-      {
-        v68 = 0;
-        for (int i =  0; i <= (signed int)pIndoor->uNumFaces; ++i)
+      memcpy(data_write_pos, &pIndoor->dlv, 0x28);
+      data_write_pos += 40;
+      memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B);
+      data_write_pos += 875;
+    
+        for (int i =  0; i <(signed int)pIndoor->uNumFaces; ++i)
         {
-		  v38 = &pIndoor->pFaces[i].uAttributes;//(char *)v68 + (unsigned int)pIndoor->pFaces + 44;
-          memcpy(v11, v38, 4);
-          v68 += 48;
-          v11 = (char *)v11 + 4;
+          memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4);
+          data_write_pos += 4;
         }
-      }
-      if ( (signed int)uNumLevelDecorations > 0 )
-      {
-        v68 = &pLevelDecorations[0].field_2;
-        for (int i =  0; i <= (signed int)uNumLevelDecorations; ++i)
+
+        for (int i =  0; i <(signed int)uNumLevelDecorations; ++i)
         {
-          memcpy(v11, v68, 2);
-          v68 += 16;
-          v11 = (char *)v11 + 2;
+          memcpy(data_write_pos, &pLevelDecorations[i].field_2, 2);
+     
+          data_write_pos+= 2;
         }
-      }
-      memcpy(v11, &uNumActors, 4);
-      v12 = (char *)v11 + 4;
-      memcpy(v12, pActors, 836 * uNumActors);
-      v13 = (char *)v12 + 836 * uNumActors;
-      memcpy(v13, &uNumSpriteObjects, 4);
-      v13 = (char *)v13 + 4;
-      memcpy(v13, pSpriteObjects, 112 * uNumSpriteObjects);
-      v14 = (char *)v13 + 112 * uNumSpriteObjects;
-      memcpy(v14, &uNumChests, 4);
-      v14 = (char *)v14 + 4;
-      memcpy(v14, pChests, 5324 * uNumChests);
-      v15 = (char *)v14 + 5324 * uNumChests;
-      memcpy(v15, pIndoor->pDoors, 0x3E80);
-      v15 = (char *)v15 + 16000;
-      memcpy(v15, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size);
-      v16 = (char *)v15 + pIndoor->blv.uDoors_ddata_Size;
-      memcpy(v16, &stru_5E4C90, 0xC8);
-      v17 = (int)((char *)v16 + 200);
-      memcpy((void *)v17, &pIndoor->stru1, 0x38);
+      memcpy(data_write_pos, &uNumActors, 4);
+      data_write_pos += 4;
+      memcpy(data_write_pos, pActors, 836 * uNumActors);
+      data_write_pos += 836 * uNumActors;
+      memcpy(data_write_pos, &uNumSpriteObjects, 4);
+      data_write_pos += 4;
+      memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects);
+      data_write_pos += 112 * uNumSpriteObjects;
+      memcpy(data_write_pos, &uNumChests, 4);
+      data_write_pos += 4;
+      memcpy(data_write_pos, pChests, 5324 * uNumChests);
+      data_write_pos += 5324 * uNumChests;
+      memcpy(data_write_pos, pIndoor->pDoors, 0x3E80);
+      data_write_pos += 16000;
+      memcpy(data_write_pos, pIndoor->ptr_0002B4_doors_ddata, pIndoor->blv.uDoors_ddata_Size);
+      data_write_pos += pIndoor->blv.uDoors_ddata_Size;
+      memcpy(data_write_pos, &stru_5E4C90, 0xC8);
+      data_write_pos += 200;
+      memcpy(data_write_pos, &pIndoor->stru1, 0x38);
+      data_write_pos += 56;
+
     }
     else
     {
       v18 = 0;
       pOutdoor->ddm.uNumFacesInBModels = 0;
-      if ( (signed int)pOutdoor->uNumBModels > 0 )
-      {
-        v19 = pOutdoor->uNumBModels;
-		v20 = &pOutdoor->pBModels[0];
-        do
-        {
-		  v18 += v20->uNumFaces;
-          ++v20;
-          --v19;
-          pOutdoor->ddm.uNumFacesInBModels = v18;
-        }
-        while ( v19 );
-      }
-      v21 = DstBuf;
+      for (int i=0; i<pOutdoor->uNumBModels;++i)
+          {
+          v18 +=pOutdoor->pBModels[i].uNumFaces;
+          }
+      pOutdoor->ddm.uNumFacesInBModels = v18;
       pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels;
       pOutdoor->ddm.uNumDecorations = uNumLevelDecorations;
-      memcpy(DstBuf, &pOutdoor->ddm, 0x28);
-      v21 = (char *)v21 + 40;
-      memcpy(v21, pOutdoor->uUndiscoveredArea, 0x3C8);
-      v21 = (char *)v21 + 968;
-      memcpy(v21, pOutdoor->uDicovered_area, 0x3C8);
-      v22 = (char *)v21 + 968;
+      memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28
+      data_write_pos += sizeof(DDM_DLV_Header);
+      memcpy(data_write_pos, pOutdoor->uUndiscoveredArea, 0x3C8);
+      data_write_pos += 968;
+      memcpy(data_write_pos, pOutdoor->uDicovered_area, 0x3C8);
+      data_write_pos += 968;
       if ( (signed int)pOutdoor->uNumBModels > 0 )
       {
         v23 = pOutdoor->pBModels;
         v24 = 76;
 		for (int i =  0; i < (signed int)pOutdoor->uNumBModels ; ++i)
         {
-		  v25 = v23[i].uNumFaces == 0;//*(int *)&v23->pModelName[v24] == 0;
-		  v26 = v23[i].uNumFaces < 0;//*(int *)&v23->pModelName[v24] < 0;
-          if ( !(v26 | v25) )
+		  //v25 = v23[i].uNumFaces == 0;//*(int *)&v23->pModelName[v24] == 0;
+		 // v26 = v23[i].uNumFaces < 0;//*(int *)&v23->pModelName[v24] < 0;
+          if ( pOutdoor->pBModels[i].uNumFaces>0)
           {
             v68 = 0;
 			for (int j =  0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j)
             {
 			  v38 = &(v23[i].pFaces[j].uAttributes); //(char *)v68 + *(int *)&v23->pModelName[v24 + 8] + 28;				 
-              memcpy(v22, v38, 4);
+              memcpy(data_write_pos, v38, 4);
               v23 = pOutdoor->pBModels;
               v68 += 154;
-              v22 = (char *)v22 + 4;
+              data_write_pos += 4;
             }
            }
           v24 += 188;
@@ -539,55 +534,56 @@
         v66 = &pLevelDecorations[0].field_2;
         for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i)
         {
-          memcpy(v22, v66, 2);
+          memcpy(data_write_pos, v66, 2);
           v66 += 16;
-          v22 = (char *)v22 + 2;
+          data_write_pos += 2;
         }
       }
-      memcpy(v22, &uNumActors, 4);
-      v28 = (char *)v22 + 4;
-      memcpy(v28, pActors, 836 * uNumActors);
-      v29 = (char *)v28 + 836 * uNumActors;
-      memcpy(v29, &uNumSpriteObjects, 4);
-      v29 = (char *)v29 + 4;
-      memcpy(v29, pSpriteObjects, 112 * uNumSpriteObjects);
-      v30 = (char *)v29 + 112 * uNumSpriteObjects;
-      memcpy(v30, &uNumChests, 4);
-      v30 = (char *)v30 + 4;
-      memcpy(v30, pChests, 5324 * uNumChests);
-      v31 = (char *)v30 + 5324 * uNumChests;
-      memcpy(v31, &stru_5E4C90, 0xC8);
-      v17 = (int)((char *)v31 + 200);
-      memcpy((void *)v17, &pOutdoor->uLastVisitDay, 0x38);
-      v9 = (int)v71;
+      memcpy(data_write_pos, &uNumActors, 4);
+      data_write_pos += 4;
+      memcpy(data_write_pos, pActors, 836 * uNumActors);
+      data_write_pos +=  836 * uNumActors;
+      memcpy(data_write_pos, &uNumSpriteObjects, 4);
+      data_write_pos += 4;
+      memcpy(data_write_pos, pSpriteObjects, 112 * uNumSpriteObjects);
+      data_write_pos += 112 * uNumSpriteObjects;
+      memcpy(data_write_pos, &uNumChests, 4);
+      data_write_pos += 4;
+      memcpy(data_write_pos, pChests, 5324 * uNumChests);
+      data_write_pos += 5324 * uNumChests;
+      memcpy(data_write_pos, &stru_5E4C90, 0xC8);
+      data_write_pos += 200;
+      memcpy(data_write_pos, &pOutdoor->loc_time, 0x38);
+      data_write_pos += 56;
+
+      //compressed_buf = (int)v71;
     }
-    v32 = v17 + 56;
     strcpy(Source, pCurrentMapName);
     _splitpath(Source, Drive, Dir, Filename, Ext);
     v48 = 100;
-    Size = v32 - (int)DstBuf;
-    v69 = 999984;
-    LOBYTE(v33) = zlib::MemZip((char *)v9 + 16, (unsigned int *)&v69, DstBuf, v32 - (int)DstBuf);
-    if ( v33 || (signed int)v69 > (signed int)Size )
+    Size = (int)data_write_pos - (int)uncompressed_buff;
+    compressed_block_size = 999984;
+    LOBYTE(v33) = zlib::MemZip((char *)compressed_buf + 16, (unsigned int *)&compressed_block_size, uncompressed_buff,Size);
+    if ( v33 || (signed int)compressed_block_size > (signed int)Size )
     {
-      memcpy((void *)(v9 + 16), DstBuf, Size);
-      v69 = Size;
+      memcpy((void *)(compressed_buf + 16), uncompressed_buff, Size);
+      compressed_block_size = Size;
     }
-    v69 += 16;
-    memcpy((void *)(v9 + 8), &v69, 4);
-    memcpy((void *)(v9 + 12), &Size, 4);
+    compressed_block_size += 16;
+    memcpy(&((SaveDataHeader *)compressed_buf)->compressed_size, &compressed_block_size, 4);
+    memcpy(&((SaveDataHeader *)compressed_buf)->uncompressed_size, &Size, 4);
     sprintf(Source, "%s%s", &Filename, &Ext);
-    strcpy((char *)&pDir, Source);
-    pDir.uDataSize = v69;
-    if ( pNew_LOD->Write(&pDir, (const void *)v9, 0) )
+    strcpy((char *)&pLodDirectory, Source);
+    pLodDirectory.uDataSize = compressed_block_size;
+    if ( pNew_LOD->Write(&pLodDirectory, (const void *)compressed_buf, 0) )
     {
       sprintf(Str, pGlobalTXT_LocalizationStrings[612], 208);
       MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:1071", 0);
     }
-    free((void *)v9);
+    free((void *)compressed_buf);
   }
-  free(DstBuf);
-  if ( a1 )
+  free(uncompressed_buff);
+  if ( IsAutoSAve )
   {
     if ( !CopyFileA("data\\new.lod", "saves\\autosave.mm7", 0) )
     {
@@ -602,9 +598,7 @@
   pParty->vPosition.z = v62;
   pParty->uFallStartY = v62;
   pParty->sRotationY = v53;
-  result = v54;
   pParty->sRotationX = v54;
-  return result;
 }