changeset 568:6f7d936edc9b

SaveGame/LoadGame sorta works
author Nomad
date Tue, 05 Mar 2013 04:30:20 +0200
parents f51373466911
children f451efdb7c8b fdea951756f9
files LOD.cpp SaveLoad.cpp
diffstat 2 files changed, 29 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/LOD.cpp	Tue Mar 05 03:58:26 2013 +0200
+++ b/LOD.cpp	Tue Mar 05 04:30:20 2013 +0200
@@ -1691,7 +1691,7 @@
   if ( !this->pIOBuffer || !this->uIOBufferSize )
     return 3;
   v7 = this->uNumSubIndices == 0;
-  v8 = this->uNumSubIndices != 0; // v8 = (this->uNumSubIndices & 0x80000000u) != 0;
+  v8 = false;//this->uNumSubIndices != 0; // v8 = (this->uNumSubIndices & 0x80000000u) != 0;
   v36 = 0;
   v34 = 0;
   if ( v8 | v7 )
@@ -1703,7 +1703,7 @@
   while ( 1 )
   {
     v9 = pDir;
-    v10 = _strcmpi((const char *)v4->pSubIndices + v35, (const char *)pDir);
+    v10 = _strcmpi(v4->pSubIndices[v5].pFilename + v35, pDir->pFilename);
     if ( v10 )
     {
       if ( v10 > 0 )
@@ -1722,7 +1722,8 @@
     v11 = v5 >= v4->uNumSubIndices;
     v8 = (v5 - v4->uNumSubIndices) != 0;//v8 = ((v5 - v4->uNumSubIndices) & 0x80000000u) != 0;
     v34 = v5;
-    if ( !(v8 ^ v11) )
+    //if ( !(v8 ^ v11) )
+    if (v5 >= v4->uNumSubIndices)
       goto LABEL_22;
   }
   v12 = pDir->uNumSubIndices;
--- a/SaveLoad.cpp	Tue Mar 05 03:58:26 2013 +0200
+++ b/SaveLoad.cpp	Tue Mar 05 04:30:20 2013 +0200
@@ -301,10 +301,11 @@
   std::string *v71; // [sp+268h] [bp-8h]@8
   int a3; // [sp+26Fh] [bp-1h]@8
   
-  v66 = a2;
+  //v66 = a2;
   strcpy(byte_6BE3B0, pCurrentMapName);
-  if (!_strcmpi(pCurrentMapName, "d05.blv"))
+  if (!_strcmpi(pCurrentMapName, "d05.blv")) // arena
     return false;
+
   DstBuf = malloc(0xF4240);
   pDir.Reset();
   pPositionX = pParty->vPosition.x;
@@ -328,16 +329,17 @@
   free(pScreenshot);
   if (pCurrentScreen == SCREEN_SAVEGAME)
   {
-    pRenderer->DrawTextureIndexed(8, 8, (Texture *)(uTextureID_loadsave != -1 ? &pIcons_LOD->pTextures[uTextureID_loadsave] : 0));
-    pRenderer->DrawTextureIndexed(0x12, 0x8D, (Texture *)(uTextureID_save_up != -1 ? &pIcons_LOD->pTextures[uTextureID_save_up] : 0));
+    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, (const char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot);
-    pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, v5 + 25, 0x103u, 0, (const char *)(&pSavegameHeader + uLoadGameUI_SelectedSlot), 185, 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); //Пожалуйста, подождите
     pRenderer->Present();
-   }
+  }
+
   if (pNew_LOD->Write(&pDir, DstBuf, 0))
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 200); //Сохраненная игра повреждена! Code=%d
@@ -379,7 +381,8 @@
     MessageBoxA(nullptr, Str, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\LoadSave.cpp:811", 0);
   }
   strcpy(pDir.pFilename, "npcdata.bin");
-  pDir.uDataSize = 38076;
+  pDir.uDataSize = 501 * sizeof(NPCData);
+  assert(pDir.uDataSize == 38076);
   if ( pNew_LOD->Write(&pDir, pNPCStats->pNewNPCData, 0) )
   {
     sprintf(Str, pGlobalTXT_LocalizationStrings[612], 205);
@@ -535,7 +538,7 @@
       if ( (signed int)uNumLevelDecorations > 0 )
       {
         v66 = &pLevelDecorations[0].field_2;
-        for (int i =  0; i <= (signed int)uNumLevelDecorations; ++i)
+        for (int i = 0; i <= (signed int)uNumLevelDecorations; ++i)
         {
           memcpy(v22, v66, 2);
           v66 += 16;
@@ -609,29 +612,28 @@
 //----- (00460078) --------------------------------------------------------
 void __fastcall DoSavegame(unsigned int uSlot)
 {
-  unsigned int v1; // esi@1
-  int v2; // esi@2
+  //unsigned int v1; // esi@1
+  //int v2; // esi@2
   //RGBTexture *v3; // ebx@3
   int bNotArena; // [sp+2Ch] [bp-8h]@1
-  unsigned int v6; // [sp+30h] [bp-4h]@1
+  //unsigned int v6; // [sp+30h] [bp-4h]@1
 
   //__debugbreak();
 
-  v1 = uSlot;
-  v6 = uSlot;
+  //v1 = uSlot;
+  //v6 = uSlot;
   bNotArena = _strcmpi(pCurrentMapName, "d05.blv");
   if ( bNotArena )
   {
     LOD::Directory pDir; // [sp+Ch] [bp-28h]@2
     SaveGame(0, 0);
-    v2 = 100 * v1;
-    strcpy(&pSavegameHeader->pLocationName[v2], pCurrentMapName);
-    *(int *)((char *)&pSavegameHeader->uWordTime + v2) = LODWORD(pParty->uTimePlayed);
-    *(int *)((char *)&pSavegameHeader->uWordTime + v2 + 4) = HIDWORD(pParty->uTimePlayed);
-    strcpy((char *)&pDir, "header.bin");
+    //v2 = 100 * v1;
+    strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName);
+    pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed;
+    strcpy(pDir.pFilename, "header.bin");
     pDir.uDataSize = 100;
-    pNew_LOD->Write(&pDir, (char *)&pSavegameHeader + v2, 0);
-    sprintf(pTmpBuf, "saves\\save%03d.mm7", v6);
+    pNew_LOD->Write(&pDir, &pSavegameHeader[uSlot], 0);
+    sprintf(pTmpBuf, "saves\\save%03d.mm7", uSlot);
     pNew_LOD->CloseWriteFile();
     CopyFileA("data\\new.lod", pTmpBuf, 0);
   }
@@ -640,10 +642,8 @@
   pCurrentScreen = SCREEN_GAME;
   //v3 = pSavegameThumbnails;
   viewparams->bRedrawGameUI = 1;
-  for(int i=0;i<45;i++)
-  {
+  for (uint i = 0; i < 45; i++)
     pSavegameThumbnails[i].Release();
-  }
   //while ( (signed int)v3 < (signed int)&unk_6A0758 );
   if ( bNotArena )
     pNew_LOD->_4621A7();
@@ -652,7 +652,7 @@
   pIcons_LOD->_4355F7();
   pEventTimer->Resume();
   ShowStatusBarString(pGlobalTXT_LocalizationStrings[656], 2u);// "Game Saved!"
-  viewparams->bRedrawGameUI = 1;
+  viewparams->bRedrawGameUI = true;
 }
 // 4E28F8: using guessed type int pCurrentScreen;