diff mm7_4.cpp @ 228:46ae2602aceb

Item generation doesn't crash (thou still generates weird stuff)
author Nomad
date Sun, 17 Feb 2013 15:45:46 +0200
parents 0c64754c7fd4
children c879446b4a22
line wrap: on
line diff
--- a/mm7_4.cpp	Sun Feb 17 15:09:31 2013 +0200
+++ b/mm7_4.cpp	Sun Feb 17 15:45:46 2013 +0200
@@ -5845,7 +5845,7 @@
 //----- (00497526) --------------------------------------------------------
 bool __cdecl PlayerCreationUI_Loop()
 {
-  RGBTexture *pTexture; // ebx@1
+  //RGBTexture *pTexture; // ebx@1
   UINT v1; // esi@1
   unsigned int v2; // ecx@3
   LONG uMouseX; // edi@6
@@ -5859,7 +5859,7 @@
   Player *v11; // esi@38
   signed int uSpellBookPageCount; // ecx@40
   int v13; // eax@40
-  signed int uSkillIdx; // eax@45
+  //signed int uSkillIdx; // eax@45
   int v15; // eax@70
   signed int v16; // ecx@70
   //unsigned int v18; // [sp-4h] [bp-84h]@48
@@ -5871,10 +5871,10 @@
   MSG Msg; // [sp+50h] [bp-30h]@17
   POINT v25; // [sp+6Ch] [bp-14h]@6
   bool v26; // [sp+74h] [bp-Ch]@1
-  POINT v24; // [sp+78h] [bp-8h]@6
-  Player *pPlayer;
-
-  pTexture = &pTexture_PCX;
+  //POINT v24; // [sp+78h] [bp-8h]@6
+  //Player *pPlayer;
+
+  //pTexture = &pTexture_PCX;
   v1 = 0;
   v26 = 0;
   pTexture_PCX.Release();
@@ -5889,7 +5889,7 @@
   {
     if ( pAsyncMouse != (void *)v1 )
       pAsyncMouse->_46B736_consume_click_lists(1);
-    uMouseX = pMouse->GetCursorPos(&v24)->x;
+    uMouseX = pMouse->GetCursorPos(&v25)->x;
     uMouseY = pMouse->GetCursorPos(&v25)->y;
     pControlsHead = pGUIWindow_CurrentMenu->pControlsHead;
     if ( pControlsHead != (GUIButton *)v1 )
@@ -5904,7 +5904,7 @@
           if ( (signed int)pNumMessage < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pNumMessage].eType = (UIMessageType)pControlsHead->field_1C;
-            pTexture = &pTexture_PCX;
+            //pTexture = &pTexture_PCX;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = pControlParam;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             pNumMessage = pMessageQueue_50CBD0->uNumMessages + 1;
@@ -5953,13 +5953,11 @@
       }
     }
   }
-  pTexture->Release();
+  pTexture_PCX.Release();
   pGUIWindow_CurrentMenu->Release();
   pIcons_LOD->_4114F2();
-  v20[0] = 0;
-  memset(&v20[1], 0, 0x1Cu);
-  *(_WORD*)&v20[29] = 0;
-  v20[31] = 0;
+
+  memset(v20, 0, 32);
   do
   {
     v8 = 0;
@@ -5985,112 +5983,107 @@
     v20[v9] = 1;
   }
   while ( (signed int)v1 < 32 );
+  //v10 = (char *)&pParty->pPlayers[0].sResMagicBase;
+  
   item.Reset();
-  //v10 = (char *)&pParty->pPlayers[0].sResMagicBase;
-  for ( pPlayer = &pParty->pPlayers[0];  pPlayer < &pParty->pPlayers[4]; pPlayer++)
-  {
+  //for ( pPlayer = &pParty->pPlayers[0];  pPlayer < &pParty->pPlayers[4]; pPlayer++)
+  for (uint i = 0; i < 4; ++i)
+  {
+    auto player = &pParty->pPlayers[i];
     //v11 = pPlayer;
-    if (pPlayer->classType == PLAYER_CLASS_KNIGHT)
-      pPlayer->sResMagicBase = 10;
+    if (player->classType == PLAYER_CLASS_KNIGHT)
+      player->sResMagicBase = 10;
     //*((short *)v10 + 400) = 0;
-    pPlayer->pPlayerBuffs[22].uExpireTime = 0;
+    player->pPlayerBuffs[22].uExpireTime = 0;
     uSpellBookPageCount = 0;
-    for ( int i = 0; i < 9; i++)
-    {
-      if ( pPlayer->pActiveSkills[12+i] )
+    for (uint j = 0; j < 9; j++)
+    {
+      if (player->pActiveSkills[PLAYER_SKILL_FIRE + j])
         ++uSpellBookPageCount;
     }
-    pPlayer->lastOpenedSpellbookPage = uSpellBookPageCount;
+    player->lastOpenedSpellbookPage = uSpellBookPageCount;
     pItemsTable->GenerateItem(2, 40, &item);
-    pPlayer->AddItem2(-1, &item);
-    uSkillIdx = 0;
-    v24.y = 0;
-    do
-    {
-      if ( pPlayer->pActiveSkills[uSkillIdx] )
-      {
-        switch ( uSkillIdx )
-        {
-          case PLAYER_SKILL_STAFF:   pPlayer->AddItem(-1, 61); break;
-          case PLAYER_SKILL_SWORD:   pPlayer->AddItem(-1, 1); break;
-          case PLAYER_SKILL_DAGGER:  pPlayer->AddItem(-1, 15); break;
-          case PLAYER_SKILL_AXE:     pPlayer->AddItem(-1, 23); break;
-          case PLAYER_SKILL_SPEAR:   pPlayer->AddItem(-1, 31); break;
-          case PLAYER_SKILL_BOW:     pPlayer->AddItem(-1, 47); break;
-          case PLAYER_SKILL_MACE:    pPlayer->AddItem(-1, 50); break;
-          case PLAYER_SKILL_BLASTER: assert(false); break;
-          case PLAYER_SKILL_SHIELD:  pPlayer->AddItem(-1, 84); break;
-          case PLAYER_SKILL_LEATHER: pPlayer->AddItem(-1, 66); break;
-          case PLAYER_SKILL_CHAIN:   pPlayer->AddItem(-1, 71); break;
-          case PLAYER_SKILL_PLATE:   pPlayer->AddItem(-1, 76); break;
-          case PLAYER_SKILL_FIRE:
-            pPlayer->AddItem(-1, 0x191);
-            pPlayer->spellbook.pFireSpellbook.bIsSpellAvailable[0] = true;
-          break;
-          case PLAYER_SKILL_AIR:
-            pPlayer->AddItem(-1, 0x19C);
-            pPlayer->spellbook.pAirSpellbook.bIsSpellAvailable[0] = true;
-          break;
-          case PLAYER_SKILL_WATER:
-            pPlayer->AddItem(-1, 0x1A7);
-			pPlayer->spellbook.pWaterSpellbook.bIsSpellAvailable[0] = true;
+    player->AddItem2(-1, &item);
+    //uSkillIdx = 0;
+    //v24.y = 0;
+
+    player->sHealth = player->GetMaxHealth();
+    player->sMana = player->GetMaxMana();
+    for (uint j = 0; j < 37; ++j)
+    {
+      if (!player->pActiveSkills[j])
+        continue;
+
+      switch (j)
+      {
+        case PLAYER_SKILL_STAFF:   player->AddItem(-1, 61); break;
+        case PLAYER_SKILL_SWORD:   player->AddItem(-1, 1); break;
+        case PLAYER_SKILL_DAGGER:  player->AddItem(-1, 15); break;
+        case PLAYER_SKILL_AXE:     player->AddItem(-1, 23); break;
+        case PLAYER_SKILL_SPEAR:   player->AddItem(-1, 31); break;
+        case PLAYER_SKILL_BOW:     player->AddItem(-1, 47); break;
+        case PLAYER_SKILL_MACE:    player->AddItem(-1, 50); break;
+        case PLAYER_SKILL_BLASTER: assert(false); break;
+        case PLAYER_SKILL_SHIELD:  player->AddItem(-1, 84); break;
+        case PLAYER_SKILL_LEATHER: player->AddItem(-1, 66); break;
+        case PLAYER_SKILL_CHAIN:   player->AddItem(-1, 71); break;
+        case PLAYER_SKILL_PLATE:   player->AddItem(-1, 76); break;
+        case PLAYER_SKILL_FIRE:
+          player->AddItem(-1, 0x191);
+          player->spellbook.pFireSpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_AIR:
+          player->AddItem(-1, 0x19C);
+          player->spellbook.pAirSpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_WATER:
+          player->AddItem(-1, 0x1A7);
+		  player->spellbook.pWaterSpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_EARTH:
+          player->AddItem(-1, 0x1B2);
+		  player->spellbook.pEarthSpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_SPIRIT:
+          player->AddItem(-1, 0x1BD);
+		  player->spellbook.pSpiritSpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_MIND:
+          player->AddItem(-1, 0x1C8);
+		  player->spellbook.pMindSpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_BODY:
+          player->AddItem(-1, 0x1D3);
+		  player->spellbook.pBodySpellbook.bIsSpellAvailable[0] = true;
+        break;
+        case PLAYER_SKILL_LIGHT:
+        case PLAYER_SKILL_DARK:
+        case PLAYER_SKILL_DIPLOMACY:
+          assert(false);
+        break;
+        case PLAYER_SKILL_ITEM_ID:
+        case PLAYER_SKILL_REPAIR:
+        case PLAYER_SKILL_MEDITATION:
+        case PLAYER_SKILL_PERCEPTION:
+        case PLAYER_SKILL_TRAP_DISARM:
+        case PLAYER_SKILL_LEARNING:
+          player->AddItem(-1, 0xDC);
+		  player->AddItem(-1, 5 * (rand() % 3 + 40));
+        break;
+        case PLAYER_SKILL_DODGE:   player->AddItem(-1, 115); break;
+        case PLAYER_SKILL_UNARMED: player->AddItem(-1, 110); break;
+        default:
           break;
-          case PLAYER_SKILL_EARTH:
-            pPlayer->AddItem(-1, 0x1B2);
-			pPlayer->spellbook.pEarthSpellbook.bIsSpellAvailable[0] = true;
-          break;
-          case PLAYER_SKILL_SPIRIT:
-            pPlayer->AddItem(-1, 0x1BD);
-			pPlayer->spellbook.pSpiritSpellbook.bIsSpellAvailable[0] = true;
-          break;
-          case PLAYER_SKILL_MIND:
-            pPlayer->AddItem(-1, 0x1C8);
-			pPlayer->spellbook.pMindSpellbook.bIsSpellAvailable[0] = true;
-          break;
-          case PLAYER_SKILL_BODY:
-            pPlayer->AddItem(-1, 0x1D3);
-			pPlayer->spellbook.pBodySpellbook.bIsSpellAvailable[0] = true;
-          break;
-          case PLAYER_SKILL_LIGHT:
-          case PLAYER_SKILL_DARK:
-          case PLAYER_SKILL_DIPLOMACY:
-            assert(false);
-          break;
-          case PLAYER_SKILL_ITEM_ID:
-          case PLAYER_SKILL_REPAIR:
-          case PLAYER_SKILL_MEDITATION:
-          case PLAYER_SKILL_PERCEPTION:
-          case PLAYER_SKILL_TRAP_DISARM:
-          case PLAYER_SKILL_LEARNING:
-            pPlayer->AddItem(-1, 0xDC);
-			pPlayer->AddItem(-1, 5 * (rand() % 3 + 40));
-          break;
-          case PLAYER_SKILL_DODGE:
-			pPlayer->AddItem(-1, 115);
-          break;
-          case PLAYER_SKILL_UNARMED:
-            pPlayer->AddItem(-1, 110);
-          break;
-          default:
-            break;
-        }
-		for ( int i = 0; i < 138; i++)
-        {
-          if ( &pPlayer->pInventoryItems[i] )
-            pPlayer->pInventoryItems[i].uAttributes |= 1;
-         }
-        pPlayer->sHealth = pPlayer->GetMaxHealth();
-        pPlayer->sMana = pPlayer->GetMaxMana();
-        uSkillIdx = v24.y;
-      }
-      ++uSkillIdx;
-      v24.y = uSkillIdx;
-    }
-    while ( uSkillIdx < 37 );
-    //v10 += 6972;
-	//pPlayer++;
-  }
-  //while ( (signed int)v10 < (signed int)((char *)&pParty->field_871C[455] + 2) );
+      }
+
+      for (uint k = 0; k < 138; k++)
+      {
+        if (&player->pInventoryItems[k])
+          player->pInventoryItems[k].uAttributes |= 1;
+      }
+    }
+  }
+
   pAudioPlayer->StopChannels(-1, -1);
   if (pAsyncMouse)
     pAsyncMouse->Suspend();