diff mm7_2.cpp @ 982:08fd1436ef35

enums & lod
author Nomad
date Sat, 11 May 2013 13:19:55 +0200
parents 9334a8c59c8d
children 1462a5f12b65
line wrap: on
line diff
--- a/mm7_2.cpp	Sat May 11 01:28:06 2013 +0200
+++ b/mm7_2.cpp	Sat May 11 13:19:55 2013 +0200
@@ -6283,10 +6283,6 @@
 void SaveNewGame()
 {
   FILE *v3; // eax@7
-  LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3
-  LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4
-  LOD::Directory save_game_dir; // [sp+12Ch] [bp-4Ch]@9
-  LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3
   void *pSave; // [sp+170h] [bp-8h]@3
 
   if ( pVideoPlayer->AnyMovieLoaded() )
@@ -6294,21 +6290,24 @@
   pSave = pAllocator->AllocNamedChunk(0, 1000000, 0);
   pNew_LOD->CloseWriteFile();
   remove("data\\new.lod");
-  this_.Reset();
+
+  LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3
   strcpy(this_.LodVersion, "MMVII");
   strcpy(this_.LodDescription, "newmaps for MMVII");
   this_.LODSize = 100;
   this_.dword_0000A8 = 0;
+
+  LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3
   a3.dword_000018 = 0;
   a3.word_00001E = 0;
   strcpy(a3.pFilename, "current");
   pNew_LOD->CreateNewLod(&this_, &a3, "data\\new.lod");
-  if ( pNew_LOD->LoadFile("data\\new.lod", 0) )
+  if (pNew_LOD->LoadFile("data\\new.lod", false))
   {
     pNew_LOD->CreateTempFile();
     pNew_LOD->uNumSubDirs = 0;
-    pDir.Reset();
-
+
+    LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4
     for (int i = pGames_LOD->uNumSubDirs / 2; i < pGames_LOD->uNumSubDirs; ++i)
     {
       memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir));
@@ -6316,11 +6315,13 @@
       fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, v3);
       pNew_LOD->AppendDirectory(&pDir, pSave);
     }
-    save_game_dir.Reset();
+
+    LOD::Directory save_game_dir; // [sp+12Ch] [bp-4Ch]@9
     strcpy(pSavegameHeader[0].pLocationName, "out01.odm");
     strcpy(save_game_dir.pFilename, "header.bin");
-    save_game_dir.uDataSize = 100;
+    save_game_dir.uDataSize = sizeof(SavegameHeader);
     pNew_LOD->AppendDirectory(&save_game_dir, &pSavegameHeader[0]);
+
     pNew_LOD->FixDirectoryOffsets();
     pParty->vPrevPosition.y = 0;
     pParty->vPrevPosition.x = 12552;
@@ -9382,7 +9383,7 @@
   //bool v9; // edx@16
   //OtherOverlay *v10; // esi@44
   //signed int v11; // edi@44
-  unsigned int v12; // ecx@56
+  //unsigned int v12; // ecx@56
   HANDLE v13; // eax@68
   unsigned int startms; // [sp+8h] [bp-24h]@55
   RECT Rect; // [sp+Ch] [bp-20h]@15
@@ -9464,21 +9465,17 @@
     while ( 1 )
     {
       MainMenu_Loop();
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
 //LABEL_21:
       while ( 1 )
       {
-        switch (uGameState)
-        {
-          case GAME_FINISHED:
-            pGame->Deinitialize();
-            return true;
-        }
-        if (GetCurrentMenuID() == MENU_FINISHED)
-        {
-          uGameState = GAME_FINISHED;
-          continue;
-        }
+        if (uGameState == GAME_FINISHED ||
+            GetCurrentMenuID() == MENU_EXIT_GAME)
+        {
+          pGame->Deinitialize();
+          return true;
+        }
+
         if (GetCurrentMenuID() == MENU_NEWGAME)
         {
           if ( pAudioPlayer->hAILRedbook )
@@ -9499,13 +9496,17 @@
           pGame->pCShow->PlayMovie(MOVIE_Emerald, 0);
           SaveNewGame();
           pGame->Loop();
-          if ( uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU )
+
+          if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
           {
             SetCurrentMenuID(MENU_NEWGAME);
-            uGameState = GAME_STATE_0;
+            uGameState = GAME_STATE_PLAYING;
             continue;
           }
-          break;
+          else if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
+            break;
+
+          assert(false && "Invalid game state");
         }
         if (GetCurrentMenuID() == MENU_CREDITS)
         {
@@ -9517,7 +9518,7 @@
         }
         if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
         {
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
         }
         else
         {
@@ -9554,22 +9555,20 @@
 LABEL_49:
         if ( uGameState == GAME_STATE_3 )
         {
-          v12 = 5;
-          SetCurrentMenuID((MENU_STATE)v12);
-          //goto LABEL_21;
-          uGameState = GAME_STATE_0;
+          SetCurrentMenuID(MENU_5);
+          uGameState = GAME_STATE_PLAYING;
           continue;
         }
         if ( uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU )
         {
           SetCurrentMenuID(MENU_NEWGAME);
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
           continue;
         }
         if ( uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)// from the loaded game
         {
           pAudioPlayer->StopChannels(-1, -1);
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
           break;
         }
       }
@@ -9847,20 +9846,20 @@
 {
   switch (m)
   {
-    case -1:               return L"-1";
-    case MENU_MAIN:        return L"MENU_MAIN";
-    case MENU_NEWGAME:     return L"MENU_NEWGAME";
-    case MENU_CREDITS:     return L"MENU_CREDITS";
-    case MENU_SAVELOAD:    return L"MENU_SAVELOAD";
-    case MENU_FINISHED:    return L"MENU_FINISHED";
-    case MENU_5:           return L"MENU_5";
-    case MENU_CREATEPARTY: return L"MENU_CREATEPARTY";
+    case -1:                return L"-1";
+    case MENU_MAIN:         return L"MENU_MAIN";
+    case MENU_NEWGAME:      return L"MENU_NEWGAME";
+    case MENU_CREDITS:      return L"MENU_CREDITS";
+    case MENU_SAVELOAD:     return L"MENU_SAVELOAD";
+    case MENU_EXIT_GAME:    return L"MENU_EXIT_GAME";
+    case MENU_5:            return L"MENU_5";
+    case MENU_CREATEPARTY:  return L"MENU_CREATEPARTY";
     case MENU_NAMEPANELESC: return L"MENU_NAMEPANELESC";
-    case MENU_CREDITSPROC: return L"MENU_CREDITSPROC";
+    case MENU_CREDITSPROC:  return L"MENU_CREDITSPROC";
     case MENU_LoadingProcInMainMenu: return L"MENU_LoadingProcInMainMenu";
-    case MENU_10:          return L"MENU_10";
+    case MENU_10:           return L"MENU_10";
     case MENU_CREDITSCLOSE: return L"MENU_CREDITSCLOSE";
-    default:               return L"unk";
+    default:                return L"unk";
   };
 };
 void SetCurrentMenuID(MENU_STATE uMenu)