changeset 1682:3c451fd02fcf

OnInventoryLeftClick cleanup
author Grumpy7
date Fri, 20 Sep 2013 10:23:54 +0200
parents 406872881eb6
children 96d567a7d15f
files CastSpellInfo.cpp Items.cpp Items.h Player.cpp UI/UICharacter.cpp mm7_5.cpp mm7_data.cpp mm7_data.h
diffstat 8 files changed, 153 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
--- a/CastSpellInfo.cpp	Thu Sep 19 08:26:28 2013 +0200
+++ b/CastSpellInfo.cpp	Fri Sep 20 10:23:54 2013 +0200
@@ -1020,9 +1020,9 @@
 				break;
 			}
 
-			dword_50C9D0 = 113;
-			dword_50C9D4 = 0;
-			dword_50C9D8 = 1;
+			_50C9D0_AfterEnchClickEventId = 113;
+			_50C9D4_AfterEnchClickEventSecondParam = 0;
+			_50C9D8_AfterEnchClickEventTimeout = 1;
 
 			ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
 			pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
@@ -1886,9 +1886,9 @@
 			
 			if ( pItemsTable->pItems[v240->uItemID].uEquipType != 12 || v240->uAttributes & 2 )
 			{
-				dword_50C9D0 = 113;
-				dword_50C9D4 = 0;
-				dword_50C9D8 = 1;
+				_50C9D0_AfterEnchClickEventId = 113;
+				_50C9D4_AfterEnchClickEventSecondParam = 0;
+				_50C9D8_AfterEnchClickEventTimeout = 1;
 
 				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2);  // Spell failed
 				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
@@ -1919,9 +1919,9 @@
 			if ( uNewCharges <= 0 )
 			{
 				v240 = 0;
-				dword_50C9D0 = 113;
-				dword_50C9D4 = 0;
-				dword_50C9D8 = 1;
+				_50C9D0_AfterEnchClickEventId = 113;
+				_50C9D4_AfterEnchClickEventSecondParam = 0;
+				_50C9D8_AfterEnchClickEventTimeout = 1;
 				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u);
 				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
 				pCastSpell->uSpellID = 0;
@@ -1936,7 +1936,7 @@
 		case SPELL_WATER_ENCHANT_ITEM:
 		{
 			if ( !pPlayer->CanCastSpell(uRequiredMana) )
-				break;
+        break;
 			uRequiredMana = 0;
 			amount = 10 * v2;
 			v730 = 1;
@@ -3650,9 +3650,9 @@
 				|| (v591 = _v732->uEquipType) != 0 && v591 != 1 && v591 != 2
 				|| pItemsTable->IsMaterialNonCommon(_v733) )
 			{
-				dword_50C9D0 = 113;
-				dword_50C9D4 = 0;
-				dword_50C9D8 = 1;
+				_50C9D0_AfterEnchClickEventId = 113;
+				_50C9D4_AfterEnchClickEventSecondParam = 0;
+				_50C9D8_AfterEnchClickEventTimeout = 1;
 
 				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
 				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
@@ -4102,7 +4102,7 @@
       pGUIWindow_Settings = 0;
       pMouse->SetCursorBitmap("MICON1");
       GameUI_Footer_TimeLeft = 0;
-      unk_50C9A0 = 0;
+      _50C9A0_IsEnchantingInProgress = 0;
       back_to_game();
     }
   }
@@ -4329,7 +4329,7 @@
         pGUIWindow_Settings = nullptr;
         pMouse->SetCursorBitmap("MICON1");
         GameUI_Footer_TimeLeft = 0;
-        unk_50C9A0 = 0;
+        _50C9A0_IsEnchantingInProgress = 0;
         back_to_game();
       }
     }
@@ -4377,7 +4377,7 @@
         if ( !pIcons_LOD->uNumPrevLoadedFiles )
           pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
         pGUIWindow_Settings = pCastSpellInfo[result].GetCastSpellInInventoryWindow();
-        unk_50C9A0 = 1;
+        _50C9A0_IsEnchantingInProgress = 1;
         some_active_character = uActiveCharacter;
         sub_421B2C_PlaceInInventory_or_DropPickedItem();
         return;
--- a/Items.cpp	Thu Sep 19 08:26:28 2013 +0200
+++ b/Items.cpp	Fri Sep 20 10:23:54 2013 +0200
@@ -143,7 +143,7 @@
 
 int  sub_4BE571(int a1, int *a2, int a3, int a4);
 
-ItemGen *ptr_50C9A4;
+ItemGen *ptr_50C9A4_ItemToEnchant;
 
 struct ItemsTable *pItemsTable; // 005D29E0
 
--- a/Items.h	Thu Sep 19 08:26:28 2013 +0200
+++ b/Items.h	Fri Sep 20 10:23:54 2013 +0200
@@ -414,7 +414,7 @@
 void GenerateItemsInChest();
 
 extern std::array<const char, 5> uItemsAmountPerShopType; // weak
-extern ItemGen *ptr_50C9A4;
+extern ItemGen *ptr_50C9A4_ItemToEnchant;
 
 extern struct ItemsTable *pItemsTable;
 
--- a/Player.cpp	Thu Sep 19 08:26:28 2013 +0200
+++ b/Player.cpp	Fri Sep 20 10:23:54 2013 +0200
@@ -7472,7 +7472,6 @@
   Player *playerPtr; // ebx@3
   Actor *actorPtr; // esi@3
   unsigned int v8; // eax@4
-  signed int v22; // edi@36
   int spellId; // eax@38
   signed int recvdMagicDmg; // eax@139
   int v72[4]; // [sp+30h] [bp-24h]@164
@@ -7525,39 +7524,40 @@
       if ( spellPower )
         dmgToReceive /= (signed int)spellPower;
     }
+    int damageType;
     switch (element)
     {
-      case 0: v22 = actorPtr->pMonsterInfo.uAttack1Type; 
+      case 0: damageType = actorPtr->pMonsterInfo.uAttack1Type; 
         break;
-      case 1: v22 = actorPtr->pMonsterInfo.uAttack2Type; 
+      case 1: damageType = actorPtr->pMonsterInfo.uAttack2Type; 
         break;
       case 2: spellId = actorPtr->pMonsterInfo.uSpell1ID;
-        v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
+        damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
         break;
       case 3: spellId = actorPtr->pMonsterInfo.uSpell2ID;
-        v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
+        damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
         break;
-      case 4: v22 = actorPtr->pMonsterInfo.field_3C_some_special_attack; 
+      case 4: damageType = actorPtr->pMonsterInfo.field_3C_some_special_attack; 
         break;
       default:
-      case 5: v22 = 4; //yes, the original just assigned the value 4
+      case 5: damageType = 4; //yes, the original just assigned the value 4
         break;   
     }
     if ( !(dword_6BE368_debug_settings_2 & 0x10) )
     {
-      dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22);
+      dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)damageType);
       if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 )
       {
         int actorState = actorPtr->uAIState;
         if ( actorState != Dying && actorState != Dead)
         {
-          int reflectedDamage = stru_50C198.CalcMagicalDamageToActor(actorPtr, v22, dmgToReceive);
+          int reflectedDamage = stru_50C198.CalcMagicalDamageToActor(actorPtr, damageType, dmgToReceive);
           actorPtr->sCurrentHP -= reflectedDamage;
           if ( reflectedDamage >= 0 )
           {
             if ( actorPtr->sCurrentHP >= 1 )
             {
-              Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);
+              Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);     //todo extract this branch to a function once Actor::functions are changed to nonstatic actor functions
               Actor::AggroSurroundingPeasants(uActorID, 1);
             }
             else
@@ -7797,102 +7797,108 @@
 void  OnInventoryLeftClick()
 {
   Player *v0; // ebx@1
-  signed int v1; // eax@2
   signed int v2; // ecx@2
   int v3; // eax@2
-  char v4; // sf@2
-  int v5; // eax@2
+  int invMatrixIndex; // eax@2
   unsigned int v6; // eax@7
-  unsigned int v7; // esi@12
-  unsigned int v8; // eax@12
+  unsigned int pickedItemId; // esi@12
+  unsigned int invItemIndex; // eax@12
   unsigned int v9; // eax@16
   unsigned int v10; // eax@18
-  ItemGen this_; // [sp+Ch] [bp-3Ch]@1
+  ItemGen tmpItem; // [sp+Ch] [bp-3Ch]@1
   POINT a2; // [sp+30h] [bp-18h]@4
-  unsigned int v13; // [sp+38h] [bp-10h]@13
   unsigned int pY; // [sp+3Ch] [bp-Ch]@2
   unsigned int pX; // [sp+40h] [bp-8h]@2
-  int a4; // [sp+44h] [bp-4h]@2
 
   v0 = pPlayers[uActiveCharacter];
   if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103 )
   {
     pMouse->GetClickPos(&pX, &pY);
-    pY = pY - 17;
-    v2 =pX - 14;
-    pX = v2;
-    v3 = 14 * (pY >> 5);
-    v2 >>= 5;
-    v4 = v2 + v3 < 0;
-    v5 = v2 + v3;
-    a4 = v5;
-    if ( !v4 )
-    {
-      if ( v5 <= 126 && pMouse->GetCursorPos(&a2)->x < 462
+    v3 = Player::INVETORYSLOTSWIDTH * ((pY - 17) / 32);
+    v2 = (pX - 14) / 32;
+    invMatrixIndex = v2 + v3;
+    if ( v2 + v3 >= 0 )
+    {
+      if ( invMatrixIndex <= 126 && pMouse->GetCursorPos(&a2)->x < 462
             && pMouse->GetCursorPos(&a2)->x >= 14 )
       {
-        if ( unk_50C9A0 )
+        if ( _50C9A0_IsEnchantingInProgress )
         {
-          v6 = v0->GetItemIDAtInventoryIndex(&a4);
+          v6 = v0->GetItemIDAtInventoryIndex(&invMatrixIndex);
           if ( v6 )
           {
             *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;
             *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
             *((int *)pGUIWindow_Settings->ptr_1C + 3) = v6 - 1;
-            *((short *)pGUIWindow_Settings->ptr_1C + 3) = a4;
-            ptr_50C9A4 = (ItemGen *)&v0->pInventoryItemList[v6-1];
-            unk_50C9A0 = 0;
+            *((short *)pGUIWindow_Settings->ptr_1C + 3) = invMatrixIndex;
+            ptr_50C9A4_ItemToEnchant = &v0->pInventoryItemList[v6-1];
+            _50C9A0_IsEnchantingInProgress = 0;
             if ( pMessageQueue_50CBD0->uNumMessages )
               pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
             pMouse->SetCursorBitmap("MICON1");
-            dword_50C9D0 = 113;
-            dword_50C9D4 = 0;
-            dword_50C9D8 = 256;
+            _50C9D0_AfterEnchClickEventId = 113;
+            _50C9D4_AfterEnchClickEventSecondParam = 0;
+            _50C9D8_AfterEnchClickEventTimeout = 256;
           }
           return;
         }
-        if ( ptr_50C9A4 )
+        if ( ptr_50C9A4_ItemToEnchant )
           return;
-        v7 = pParty->pPickedItem.uItemID;
-        v8 = v0->GetItemIDAtInventoryIndex(&a4);
-        if ( !v7 )
+        pickedItemId = pParty->pPickedItem.uItemID;
+        invItemIndex = v0->GetItemIDAtInventoryIndex(&invMatrixIndex);
+        if (!pickedItemId)
         {
-          if ( !v8 )
+          if ( !invItemIndex )
             return;
-          memcpy(&pParty->pPickedItem, &v0->pInventoryItemList[v8-1], sizeof(pParty->pPickedItem));
-          v0->RemoveItemAtInventoryIndex(a4);
-          v9 = pParty->pPickedItem.uItemID;
-          pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
-          return;
+          else
+          {
+            memcpy(&pParty->pPickedItem, &v0->pInventoryItemList[invItemIndex-1], sizeof(pParty->pPickedItem));
+            v0->RemoveItemAtInventoryIndex(invMatrixIndex);
+            v9 = pParty->pPickedItem.uItemID;
+            pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
+            return;
+          }
         }
-        v13 = v8;
-        if ( v8 )
+        else
         {
-          a2.y = (LONG)&v0->pInventoryItemList[v8-1];
-          memcpy(&this_, (const void *)a2.y, sizeof(this_));
-          v0->RemoveItemAtInventoryIndex(a4);
-          pX = v0->AddItem2(a4, &pParty->pPickedItem);
-          if ( !pX )
+          if ( invItemIndex )
           {
-            pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem);
-            if ( !pX )
+            ItemGen* invItemPtr = &v0->pInventoryItemList[invItemIndex-1];
+            memcpy(&tmpItem, invItemPtr, sizeof(tmpItem));
+            v0->RemoveItemAtInventoryIndex(invMatrixIndex);
+            int emptyIndex = v0->AddItem2(invMatrixIndex, &pParty->pPickedItem);
+            if ( !emptyIndex )
             {
-              v0->PutItemArInventoryIndex(this_.uItemID, v13 - 1, a4);
-              memcpy((void *)a2.y, &this_, sizeof(ItemGen));
+              emptyIndex = v0->AddItem2(-1, &pParty->pPickedItem);
+              if ( !emptyIndex )
+              {
+                v0->PutItemArInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex);
+                memcpy(invItemPtr, &tmpItem, sizeof(ItemGen));
+                return;
+              }
+            }
+            v9 = tmpItem.uItemID;
+            memcpy(&pParty->pPickedItem, &tmpItem, sizeof(ItemGen));
+            pMouse->SetCursorBitmap(pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName);
+            return;
+          }
+          else
+          {
+            v10 = v0->AddItem(invMatrixIndex, pickedItemId);
+            if ( v10 )
+            {
+              memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, sizeof(ItemGen));
+              pMouse->RemoveHoldingItem();
+              return;
+            }
+            v10 = v0->AddItem(-1, pickedItemId);
+            if ( v10 )
+            {
+              memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, sizeof(ItemGen));
+              pMouse->RemoveHoldingItem();
               return;
             }
           }
-          v9 = this_.uItemID;
-          memcpy(&pParty->pPickedItem, &this_, sizeof(pParty->pPickedItem));
-          pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
-          return;
-        }
-        v10 = v0->AddItem(a4, v7);
-        pX = v10;
-        if ( v10 || (v10 = v0->AddItem(-1, pParty->pPickedItem.uItemID), (pX = v10) != 0) )
-        {
-          memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, 0x24u);
-          pMouse->RemoveHoldingItem();
         }
       }
     }
--- a/UI/UICharacter.cpp	Thu Sep 19 08:26:28 2013 +0200
+++ b/UI/UICharacter.cpp	Fri Sep 20 10:23:54 2013 +0200
@@ -819,7 +819,7 @@
         {
           _50C9A8_item_enchantment_timer = 0;
           item->uAttributes &= 0xFFFFFF0Fu;
-          ptr_50C9A4 = 0;
+          ptr_50C9A4_ItemToEnchant = 0;
         }
         pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(pIcons_LOD->LoadTexture(v166, TEXTURE_16BIT_PALETTE)),
                            pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE), GetTickCount() * 0.1, 0, 255);
@@ -863,7 +863,7 @@
         {
           _50C9A8_item_enchantment_timer = 0;
           item->uAttributes &= 0xFFFFFF0Fu;
-          ptr_50C9A4 = 0;
+          ptr_50C9A4_ItemToEnchant = 0;
         }
         pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(pIcons_LOD->LoadTexture(pItemsTable->pItems[item->uItemID].pIconName, TEXTURE_16BIT_PALETTE)),
                   pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE),
@@ -924,7 +924,7 @@
           {
             _50C9A8_item_enchantment_timer = 0;
             item->uAttributes &= 0xFFFFFF0Fu;
-            ptr_50C9A4 = 0;
+            ptr_50C9A4_ItemToEnchant = 0;
           }
           pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(paperdoll_cloak_texture[pBodyComplection][index]),
                            pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE), GetTickCount() * 0.1, 0, 255);
@@ -989,7 +989,7 @@
           {
             _50C9A8_item_enchantment_timer = 0;
             item->uAttributes &= 0xFFFFFF0Fu;
-            ptr_50C9A4 = 0;
+            ptr_50C9A4_ItemToEnchant = 0;
           }
           pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(paperdoll_armor_texture[pBodyComplection][index][0]),
                           pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE), GetTickCount() * 0.1, 0, 255);
@@ -1051,7 +1051,7 @@
           {
             _50C9A8_item_enchantment_timer = 0;
             item->uAttributes &= 0xFFFFFF0Fu;
-            ptr_50C9A4 = 0;
+            ptr_50C9A4_ItemToEnchant = 0;
           }
           pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(v59), pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE),
                   GetTickCount() * 0.1, 0, 255);
@@ -1120,7 +1120,7 @@
             {
               _50C9A8_item_enchantment_timer = 0;
               item->uAttributes &= 0xFFFFFF0Fu;
-              ptr_50C9A4 = 0;
+              ptr_50C9A4_ItemToEnchant = 0;
             }
             pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(v75), pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE),
                         GetTickCount() * 0.1, 0, 255);
@@ -1208,7 +1208,7 @@
                   {
                     _50C9A8_item_enchantment_timer = 0;
                     item->uAttributes &= 0xFFFFFF0Fu;
-                    ptr_50C9A4 = 0;
+                    ptr_50C9A4_ItemToEnchant = 0;
                   }
                   pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(v94), pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE),
                                 GetTickCount() * 0.1, 0, 255);
@@ -1251,7 +1251,7 @@
               {
                 _50C9A8_item_enchantment_timer = 0;
                 item->uAttributes &= 0xFFFFFF0Fu;
-                ptr_50C9A4 = 0;
+                ptr_50C9A4_ItemToEnchant = 0;
               }
               pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(paperdoll_armor_texture[pBodyComplection][index][1]),
                     pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE), GetTickCount() * 0.1, 0, 255);
@@ -1314,7 +1314,7 @@
               {
                 _50C9A8_item_enchantment_timer = 0;
                 item->uAttributes &= 0xFFFFFF0Fu;
-                ptr_50C9A4 = 0;
+                ptr_50C9A4_ItemToEnchant = 0;
               }
               pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(paperdoll_cloak_collar_texture[pBodyComplection][index]),
                             pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE), GetTickCount() * 0.1, 0, 255);
@@ -1377,7 +1377,7 @@
           {
             _50C9A8_item_enchantment_timer = 0;
             item->uAttributes &= 0xFFFFFF0Fu;
-            ptr_50C9A4 = 0;
+            ptr_50C9A4_ItemToEnchant = 0;
           }
           pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(v127), pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE),
                         GetTickCount() * 0.1, 0, 255);
@@ -1435,7 +1435,7 @@
         {
           _50C9A8_item_enchantment_timer = 0;
           item->uAttributes &= 0xFFFFFF0Fu;
-          ptr_50C9A4 = 0;
+          ptr_50C9A4_ItemToEnchant = 0;
         }
         pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(pIcons_LOD->LoadTexture(v181, TEXTURE_16BIT_PALETTE)),
                    pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE), GetTickCount() * 0.1, 0, 255);
@@ -1507,7 +1507,7 @@
         {
           _50C9A8_item_enchantment_timer = 0;
           item->uAttributes &= 0xFFFFFF0Fu;
-          ptr_50C9A4 = 0;
+          ptr_50C9A4_ItemToEnchant = 0;
         }
         pRenderer->DrawAura(item_X, item_Y, pIcons_LOD->GetTexture(v153), pIcons_LOD->LoadTexturePtr(container, TEXTURE_16BIT_PALETTE),
                      GetTickCount() * 0.1, 0, 255);
@@ -1584,7 +1584,7 @@
       {
         _50C9A8_item_enchantment_timer = 0;
         LOBYTE(player->pInventoryItemList[player->pInventoryMatrix[i] - 1].uAttributes) &= 0xF;
-        ptr_50C9A4 = 0;
+        ptr_50C9A4_ItemToEnchant = 0;
       }
       pRenderer->DrawAura(uCellX, uCellY, pTexture, pTexture, GetTickCount() * 0.1, 0, 255);
       ZBuffer_Fill(&pRenderer->pActiveZBuffer[v17], item_texture_id, player->pInventoryMatrix[i]);
@@ -1626,7 +1626,7 @@
     {
       _50C9A8_item_enchantment_timer = 0;
       item->uAttributes &= 0xFFFFFF0F;
-      ptr_50C9A4 = 0;
+      ptr_50C9A4_ItemToEnchant = 0;
     }
     pRenderer->DrawAura(x, y, item_texture, enchantment_texture, GetTickCount() * 0.1, 0, 255);
   }
@@ -2682,27 +2682,27 @@
       }
       WetsuitOff(uActiveCharacter);
     }
-    if ( unk_50C9A0 )//наложить закл на экипировку
+    if ( _50C9A0_IsEnchantingInProgress )//наложить закл на экипировку
     {
       *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;//CastSpellInfo
       *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
       *((int *)pGUIWindow_Settings->ptr_1C + 3) = v36;
       *((short *)pGUIWindow_Settings->ptr_1C + 3) = pEquipType;
-      ptr_50C9A4 = v38;
-      unk_50C9A0 = 0;
+      ptr_50C9A4_ItemToEnchant = v38;
+      _50C9A0_IsEnchantingInProgress = 0;
       if ( pMessageQueue_50CBD0->uNumMessages )
         pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
       pMouse->SetCursorBitmap("MICON1");
-      dword_50C9D4 = 0;
-      dword_50C9D0 = 113;
-      dword_50C9D8 = 256;
+      _50C9D4_AfterEnchClickEventSecondParam = 0;
+      _50C9D0_AfterEnchClickEventId = 113;
+      _50C9D8_AfterEnchClickEventTimeout = 256;
     }
     else
     {
-      if ( !ptr_50C9A4 )//снять вещь
+      if ( !ptr_50C9A4_ItemToEnchant )//снять вещь
       {
         pParty->SetHoldingItem(v38);
-        *(&pPlayers[uActiveCharacter]->uBirthYear + pPlayers[uActiveCharacter]->pInventoryItemList[v36].uBodyAnchor) = 0;// это pPlayers[uActiveCharacter]->pEquipment[pPlayers[uActiveCharacter]->pInventoryItemList[v36].uBodyAnchor]
+        pPlayers[uActiveCharacter]->pEquipment.pIndices[pPlayers[uActiveCharacter]->pInventoryItemList[v36].uBodyAnchor] = 0;
         v38->Reset();
       }
     }
--- a/mm7_5.cpp	Thu Sep 19 08:26:28 2013 +0200
+++ b/mm7_5.cpp	Fri Sep 20 10:23:54 2013 +0200
@@ -1004,7 +1004,7 @@
                       pGUIWindow_Settings = 0;
                       pMouse->SetCursorBitmap("MICON1");
                       GameUI_Footer_TimeLeft = 0;
-                      unk_50C9A0 = 0;
+                      _50C9A0_IsEnchantingInProgress = 0;
                       back_to_game();
                     }
                   }
@@ -1036,15 +1036,15 @@
                         some_active_character = 0;
                         if ( pParty->bTurnBasedModeOn )
                           pTurnEngine->ApplyPlayerAction();
-                        dword_50C9D0 = 0;
-                        dword_50C9D4 = 0;
-                        dword_50C9D8 = 0;
+                        _50C9D0_AfterEnchClickEventId = 0;
+                        _50C9D4_AfterEnchClickEventSecondParam = 0;
+                        _50C9D8_AfterEnchClickEventTimeout = 0;
                       }
-                      if ( ptr_50C9A4 && ptr_50C9A4->uItemID )
+                      if ( ptr_50C9A4_ItemToEnchant && ptr_50C9A4_ItemToEnchant->uItemID )
                       {
-                        LOBYTE(ptr_50C9A4->uAttributes) &= 0xFu;
+                        LOBYTE(ptr_50C9A4_ItemToEnchant->uAttributes) &= 0xFu;
                         _50C9A8_item_enchantment_timer = 0;
-                        ptr_50C9A4 = 0;
+                        ptr_50C9A4_ItemToEnchant = 0;
                       }
                       if ( pGUIWindow_Settings )
                       {
@@ -1058,7 +1058,7 @@
                          pGUIWindow_Settings = 0;
                          pMouse->SetCursorBitmap("MICON1");
                          GameUI_Footer_TimeLeft = 0;
-                         unk_50C9A0 = 0;
+                         _50C9A0_IsEnchantingInProgress = 0;
                          back_to_game();
                         }
                        }
@@ -1090,7 +1090,7 @@
                          pGUIWindow_Settings = 0;
                          pMouse->SetCursorBitmap("MICON1");
                          GameUI_Footer_TimeLeft = 0;
-                         unk_50C9A0 = 0;
+                         _50C9A0_IsEnchantingInProgress = 0;
                          back_to_game();
                         }
                       }
@@ -1274,7 +1274,7 @@
                           pGUIWindow_Settings = 0;
                           pMouse->SetCursorBitmap("MICON1");
                           GameUI_Footer_TimeLeft = 0;
-                          unk_50C9A0 = 0;
+                          _50C9A0_IsEnchantingInProgress = 0;
                           back_to_game();
                          }
                       }
@@ -1324,7 +1324,7 @@
                           pGUIWindow_Settings = 0;
                           pMouse->SetCursorBitmap("MICON1");
                           GameUI_Footer_TimeLeft = 0;
-                          unk_50C9A0 = 0;
+                          _50C9A0_IsEnchantingInProgress = 0;
                           back_to_game();
                         }
                       }
@@ -1408,7 +1408,7 @@
                           pGUIWindow_Settings = 0;
                           pMouse->SetCursorBitmap("MICON1");
                           GameUI_Footer_TimeLeft = 0;
-                          unk_50C9A0 = 0;
+                          _50C9A0_IsEnchantingInProgress = 0;
                           back_to_game();
                         }
                       }
@@ -1436,7 +1436,7 @@
                           pGUIWindow_Settings = 0;
                           pMouse->SetCursorBitmap("MICON1");
                           GameUI_Footer_TimeLeft = 0;
-                          unk_50C9A0 = 0;
+                          _50C9A0_IsEnchantingInProgress = 0;
                           back_to_game();
                         }
                       }
@@ -1464,7 +1464,7 @@
                       pGUIWindow_Settings = 0;
                       pMouse->SetCursorBitmap("MICON1");
                       GameUI_Footer_TimeLeft = 0;
-                      unk_50C9A0 = 0;
+                      _50C9A0_IsEnchantingInProgress = 0;
                       back_to_game();
                     }
                   }
@@ -1496,7 +1496,7 @@
                   pGUIWindow_Settings = 0;
                   pMouse->SetCursorBitmap("MICON1");
                   GameUI_Footer_TimeLeft = 0;
-                  unk_50C9A0 = 0;
+                  _50C9A0_IsEnchantingInProgress = 0;
                   back_to_game();
                 }
               }
@@ -1563,7 +1563,7 @@
             pGUIWindow_Settings = 0;
             pMouse->SetCursorBitmap("MICON1");
             GameUI_Footer_TimeLeft = 0;
-            unk_50C9A0 = 0;
+            _50C9A0_IsEnchantingInProgress = 0;
             back_to_game();
             continue;
           }
@@ -1802,7 +1802,7 @@
             pGUIWindow_Settings = 0;
             pMouse->SetCursorBitmap("MICON1");
             GameUI_Footer_TimeLeft = 0;
-            unk_50C9A0 = 0;
+            _50C9A0_IsEnchantingInProgress = 0;
             back_to_game();
             continue;
           }
@@ -1820,7 +1820,7 @@
             pGUIWindow_Settings = 0;
             pMouse->SetCursorBitmap("MICON1");
             GameUI_Footer_TimeLeft = 0;
-            unk_50C9A0 = 0;
+            _50C9A0_IsEnchantingInProgress = 0;
             back_to_game();
             continue;
           }
@@ -1847,7 +1847,7 @@
               pGUIWindow_Settings = 0;
               pMouse->SetCursorBitmap("MICON1");
               GameUI_Footer_TimeLeft = 0;
-              unk_50C9A0 = 0;
+              _50C9A0_IsEnchantingInProgress = 0;
               back_to_game();
               continue;
             }
@@ -1867,7 +1867,7 @@
           pGUIWindow_Settings = 0;
           pMouse->SetCursorBitmap("MICON1");
           GameUI_Footer_TimeLeft = 0;
-          unk_50C9A0 = 0;
+          _50C9A0_IsEnchantingInProgress = 0;
           back_to_game();
           continue;
         case UIMSG_CastSpell_Character_Big_Improvement://Preservation and blessing, treatment paralysis, hand hammers(individual upgrade)
@@ -1875,7 +1875,7 @@
         case UIMSG_HiredNPC_CastSpell:
           if ( pMessageQueue_50CBD0->uNumMessages )
             pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( unk_50C9A0 )
+          if ( _50C9A0_IsEnchantingInProgress )
           {
             uActiveCharacter = uMessageParam;
             viewparams->bRedrawGameUI = 1;
@@ -1904,7 +1904,7 @@
               pEventTimer->Resume();
               pMouse->SetCursorBitmap("MICON1");
               GameUI_Footer_TimeLeft = 0;
-              unk_50C9A0 = 0;
+              _50C9A0_IsEnchantingInProgress = 0;
             }
           }
           continue;
@@ -2388,7 +2388,7 @@
           pGUIWindow_Settings = 0;
           pMouse->SetCursorBitmap("MICON1");
           GameUI_Footer_TimeLeft = 0;
-          unk_50C9A0 = 0;
+          _50C9A0_IsEnchantingInProgress = 0;
           back_to_game();
           continue;
         case UIMSG_1C:
@@ -3218,10 +3218,10 @@
   }
   else
   {
-    if ( dword_50C9D0 > 0 )
+    if ( _50C9D0_AfterEnchClickEventId > 0 )
     {
-      dword_50C9D8 -= pEventTimer->uTimeElapsed;
-      if ( dword_50C9D8 <= 0 )
+      _50C9D8_AfterEnchClickEventTimeout -= pEventTimer->uTimeElapsed;
+      if ( _50C9D8_AfterEnchClickEventTimeout <= 0 )
       {
         /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
@@ -3230,10 +3230,10 @@
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
           ++pMessageQueue_50CBD0->uNumMessages;
         }*/
-        pMessageQueue_50CBD0->AddMessage((UIMessageType)dword_50C9D0, dword_50C9D4, 0);
-        dword_50C9D0 = 0;
-        dword_50C9D4 = 0;
-        dword_50C9D8 = 0;
+        pMessageQueue_50CBD0->AddMessage((UIMessageType)_50C9D0_AfterEnchClickEventId, _50C9D4_AfterEnchClickEventSecondParam, 0);
+        _50C9D0_AfterEnchClickEventId = 0;
+        _50C9D4_AfterEnchClickEventSecondParam = 0;
+        _50C9D8_AfterEnchClickEventTimeout = 0;
       }
     }
   }
--- a/mm7_data.cpp	Thu Sep 19 08:26:28 2013 +0200
+++ b/mm7_data.cpp	Fri Sep 20 10:23:54 2013 +0200
@@ -995,12 +995,12 @@
 int dword_50C994 = 0; // weak
 int dword_50C998_turnbased_icon_1A = 0; // weak
 int uSpriteID_Spell11; // idb
-_UNKNOWN unk_50C9A0; // weak
+bool _50C9A0_IsEnchantingInProgress; // weak
 int _50C9A8_item_enchantment_timer = 0; // weak
 int dword_50C9AC; // weak
-int dword_50C9D0; // weak
-int dword_50C9D4; // weak
-int dword_50C9D8; // weak
+int _50C9D0_AfterEnchClickEventId; // weak
+int _50C9D4_AfterEnchClickEventSecondParam; // weak
+int _50C9D8_AfterEnchClickEventTimeout; // weak
 int dword_50C9DC; // weak
 struct NPCData *ptr_50C9E0;
 //int dword_50C9E8; // idb
--- a/mm7_data.h	Thu Sep 19 08:26:28 2013 +0200
+++ b/mm7_data.h	Fri Sep 20 10:23:54 2013 +0200
@@ -677,12 +677,12 @@
 extern int dword_50C994; // weak
 extern int dword_50C998_turnbased_icon_1A; // weak
 extern int uSpriteID_Spell11; // idb
-extern _UNKNOWN unk_50C9A0; // weak
+extern bool _50C9A0_IsEnchantingInProgress; // weak
 extern int _50C9A8_item_enchantment_timer; // weak
 extern int dword_50C9AC; // weak
-extern int dword_50C9D0; // weak
-extern int dword_50C9D4; // weak
-extern int dword_50C9D8; // weak
+extern int _50C9D0_AfterEnchClickEventId; // weak
+extern int _50C9D4_AfterEnchClickEventSecondParam; // weak
+extern int _50C9D8_AfterEnchClickEventTimeout; // weak
 extern int dword_50C9DC; // weak
 extern struct NPCData *ptr_50C9E0;
 //extern int dword_50C9E8; // idb