changeset 456:20d96ec810c8

Слияние
author Ritor1
date Sun, 24 Feb 2013 13:53:18 +0600
parents 4c4584219da3 (current diff) 17c90e543e28 (diff)
children e5cf03a3d98e
files mm7_1.cpp mm7_4.cpp mm7_data.h
diffstat 13 files changed, 433 insertions(+), 233 deletions(-) [+]
line wrap: on
line diff
--- a/GUIWindow.h	Sun Feb 24 13:52:57 2013 +0600
+++ b/GUIWindow.h	Sun Feb 24 13:53:18 2013 +0600
@@ -196,7 +196,7 @@
   UIMSG_SaveGame = 0x53,
   UIMSG_54 = 0x54,
   UIMSG_55 = 0x55,
-  UIMSG_56 = 0x56,
+  UIMSG_SelectSpell = 0x56,
   UIMSG_57 = 0x57,
   UIMSG_58 = 0x58,
   UIMSG_5A = 0x5A,
@@ -373,7 +373,7 @@
 
 
 
-
+#define AddMessage(msg, param, a4) AddMessageImpl((msg), (param), (a4), __FILE__, __LINE__)
 /*  250 */
 #pragma pack(push, 1)
 struct GUIMessageQueue
@@ -383,10 +383,13 @@
   {}
 
   void PopMessage(UIMessageType *pMsg, int *pParam, int *a4);
-  void SendMessage(UIMessageType msg, int param, unsigned int a4);
+  void AddMessageImpl(UIMessageType msg, int param, unsigned int a4, const char *file = nullptr, int line = 0);
 
   unsigned int uNumMessages;
   GUIMessage pMessages[40];
+
+  const char *files[40];
+  int          lines[40];
 };
 #pragma pack(pop)
 
--- a/Items.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/Items.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -1647,11 +1647,11 @@
   if ( v20 <= EQUIP_BOW )
   {
     v37 = v5->uBonusChanceWpSpecial[v54];
-    if ( !*(unsigned int *)v37 )
+    if ( !v37 )
       return;
     v38 = rand() % 100;
-    v36 = __OFSUB__(v38, *(unsigned int *)v37);
-    v35 = v38 - *(unsigned int *)v37 < 0;
+    v36 = __OFSUB__(v38, v37);
+    v35 = v38 - v37 < 0;
   }
   else
   {
@@ -1665,10 +1665,10 @@
       }
       return;
     }
-    v22 = (int)&uBonusChanceStandart[v6];
-    if ( !*(unsigned int *)v22 )
+    v22 = uBonusChanceStandart[v6];
+    if ( !v22 )
       return;
-    v24 = *(unsigned int *)v22;
+    v24 = v22;
     v25 = rand() % 100;
     if ( !uBonusChanceSpecial[v6] && !(v25 < v24))
         return;
--- a/Items.h	Sun Feb 24 13:52:57 2013 +0600
+++ b/Items.h	Sun Feb 24 13:53:18 2013 +0600
@@ -17,12 +17,12 @@
 
 
 enum ITEM_MATERIAL
-	{
+{
 	MATERIAL_COMMON  =0,
 	MATERIAL_ARTEFACT = 1,
 	MATERIAL_RELIC    = 2,
 	MATERIAL_SPECIAL  = 3 
-	};
+};
 
 /*  330 */
 enum ITEM_TYPE
@@ -125,7 +125,7 @@
   unsigned int uItemID;
   int uEncantmentType;
   int _bonus_strength;
-  int uSpecEnchantmentType;
+  int uSpecEnchantmentType; // 25: +5 levels
   int uNumCharges;
   unsigned int uAttributes;
   unsigned __int8 uBodyAnchor;
--- a/NPC.h	Sun Feb 24 13:52:57 2013 +0600
+++ b/NPC.h	Sun Feb 24 13:53:18 2013 +0600
@@ -91,6 +91,17 @@
   unsigned int uProfession; //18      CheckHiredNPCSpeciality(uProfession)
                                   /*   
 
+      v0 = uDefaultTravelTime_ByFoot;
+  if ( CheckHiredNPCSpeciality(5u) )
+    --v0;
+  if ( CheckHiredNPCSpeciality(6u) )
+    v0 -= 2;
+  if ( CheckHiredNPCSpeciality(7u) )
+    v0 -= 3;
+  if ( CheckHiredNPCSpeciality(0x2Cu) )
+    --v0;
+
+
       case PLAYER_SKILL_MONSTER_ID:
       if ( CheckHiredNPCSpeciality(58) )
         skill += 6;
--- a/Player.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/Player.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -1784,7 +1784,7 @@
 }
 // 506128: using guessed type int areWeLoadingTexture;
 
-
+//identf
 //----- (00490EEE) --------------------------------------------------------
 int Player::_490EEE(ItemGen *pItem, int a3, int a4, int a5)
 {
@@ -7598,13 +7598,14 @@
                 {
                   if ( !v73 )
                     goto LABEL_187;
-                  if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                   {
                     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
                     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
                     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                     ++pMessageQueue_50CBD0->uNumMessages;
-                  }
+                  }*/
+                  pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
                 }
                 if ( v73 )
                 {
@@ -7679,27 +7680,23 @@
     if ( dword_50C9E8 < 40 )
     {
       dword_50C9EC[3 * dword_50C9E8] = 146;
-      dword_50C9F0[3 * dword_50C9E8] = v24;
-      *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = a2 - 1;
+      dword_50C9EC[3 * dword_50C9E8 + 1] = v24;
+      dword_50C9EC[3 * dword_50C9E8 + 2] = a2 - 1;
       ++dword_50C9E8;
     }
     if ( pCurrentScreen
       && pGUIWindow_CurrentMenu
-      && pGUIWindow_CurrentMenu->eWindowType != WINDOW_null
-      && (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-    {
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+      && pGUIWindow_CurrentMenu->eWindowType != WINDOW_null)
+      //&& (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+    {
+      /*pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-      ++pMessageQueue_50CBD0->uNumMessages;
-    }
-  }
-}
-// 4E28F8: using guessed type int pCurrentScreen;
-// 50C9AC: using guessed type int dword_50C9AC;
-// 50C9EC: using guessed type int dword_50C9EC[];
-// 6BE3C4: using guessed type char bUnderwater;
-// 720984: using guessed type int 720984_unused;
+      ++pMessageQueue_50CBD0->uNumMessages;*/
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+    }
+  }
+}
 
 
 
--- a/mm7_1.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_1.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -1520,13 +1520,14 @@
         if ( result->uHotkey == v3 )
         {
           v6 = result->uControlParam;
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          pMessageQueue_50CBD0->AddMessage((UIMessageType)result->uControlID, v6, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)result->uControlID;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v6;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
           return result;
         }
       }
@@ -2025,14 +2026,15 @@
     }
 LABEL_26:
     v11 = v9->uControlParam;
-    if ( (signed int)v2 < 40 )
+    /*if ( (signed int)v2 < 40 )
     {
       pMessageQueue_50CBD0->pMessages[v2].eType = (UIMessageType)v9->uControlID;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v11;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = v1;
       v2 = pMessageQueue_50CBD0->uNumMessages + 1;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage((UIMessageType)v9->uControlID, v11, v1);
     goto LABEL_47;
   }
   if ( v26 != 38 )
@@ -2150,13 +2152,14 @@
   }
 LABEL_56:
   v21 = v19->uControlParam;
-  if ( (signed int)v2 < 40 )
+  /*if ( (signed int)v2 < 40 )
   {
     pMessageQueue_50CBD0->pMessages[v2].eType = (UIMessageType)v19->uControlID;
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v21;
     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = v1;
     ++pMessageQueue_50CBD0->uNumMessages;
-  }
+  }*/
+  pMessageQueue_50CBD0->AddMessage((UIMessageType)v19->uControlID, v21, v1);
   return 1;
 }
 
@@ -4540,13 +4543,14 @@
               return;
             }
             v38 = pButton->uControlParam;
-            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
             {
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = pMessageType3;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v38;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
-            }
+            }*/
+            pMessageQueue_50CBD0->AddMessage(pMessageType3, v38, 0);
             //goto LABEL_131;
             uLastPointedObjectID = 1;
             return;
@@ -4574,11 +4578,12 @@
                     v36 = pButton->uControlParam;
                     if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                     {
-                      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = pMessageType2;
+                      pMessageQueue_50CBD0->AddMessage(pMessageType2, v36, 0);
+                      /*pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = pMessageType2;
                       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v36;
                       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                       //goto LABEL_27;
-                      ++pMessageQueue_50CBD0->uNumMessages;
+                      ++pMessageQueue_50CBD0->uNumMessages;*/
                       v13 = pButton->pButtonName;
                       sub_41C0B8_set_status_string(v13);
                       uLastPointedObjectID = 1;
@@ -4665,14 +4670,15 @@
             if ( pMessageType1 )
             {
               v12 = pButton->uControlParam;
-              if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+              pMessageQueue_50CBD0->AddMessage(pMessageType1, v12, 0);
+              /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
               {
                 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = pMessageType1;
                 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v12;
                 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
 //LABEL_27:
                 ++pMessageQueue_50CBD0->uNumMessages;
-              }
+              }*/
             }
 //LABEL_28:
             v13 = pButton->pButtonName;
@@ -4701,13 +4707,14 @@
                   if ( pMessageType1 )
                   {
                     v12 = pButton->uControlParam;
-                    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                    pMessageQueue_50CBD0->AddMessage(pMessageType1, v12, 0);
+                    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                     {
                       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = pMessageType1;
                       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v12;
                       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                       ++pMessageQueue_50CBD0->uNumMessages;
-                    }
+                    }*/
                   }
                   v13 = pButton->pButtonName;
                   sub_41C0B8_set_status_string(v13);
@@ -5392,13 +5399,15 @@
         }
         return;
       }
-      if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
         return;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)161;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v18;
 LABEL_42:
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
+      return;*/
+      pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v18, 0);
       return;
     }
     if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
@@ -5406,11 +5415,12 @@
       pTurnEngine->field_18 |= 8u;
       return;
     }
-    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)23;
       goto LABEL_41;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
   }
   else
   {
@@ -5420,13 +5430,14 @@
       return;
     }
     if ( uActiveCharacter
-      && sub_427769_spell(pPlayers[uActiveCharacter]->uQuickSpell)
-      && (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+      && sub_427769_spell(pPlayers[uActiveCharacter]->uQuickSpell))
     {
+      pMessageQueue_50CBD0->AddMessage(UIMSG_19, 0, 0);
+      /*&& (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)25;
 LABEL_41:
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-      goto LABEL_42;
+      goto LABEL_42;*/
     }
   }
 }
--- a/mm7_2.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_2.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -222,13 +222,14 @@
         if ( v1 <= 0 )
         {
 LABEL_8:
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
           return;
         }
         if ( v1 > pParty->uNumGold )
@@ -328,13 +329,14 @@
           if ( !v6 )
           {
 LABEL_17:
-            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
             {
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
-            }
+            }*/
             return;
           }
           if ( v6 > pParty->uNumGold )
@@ -638,12 +640,13 @@
           pVideoPlayer->Unload();
           window_SpeakInHouse->Release();
           window_SpeakInHouse = 0;
+
           if ( pMessageQueue_50CBD0->uNumMessages )
             pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          pMessageQueue_50CBD0->pMessages[0].eType = (UIMessageType)409;
+          pMessageQueue_50CBD0->pMessages[0].eType = UIMSG_OpenRestUI;
           pMessageQueue_50CBD0->pMessages[0].param = v27;
           pMessageQueue_50CBD0->pMessages[0].field_8 = 1;
-LABEL_51:
+//LABEL_51:
           ++pMessageQueue_50CBD0->uNumMessages;
           return;
         }
@@ -754,12 +757,9 @@
           HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 3);
           v5 = 1;
 LABEL_43:
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
-            return;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v5;
-          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          goto LABEL_51;
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v5, 0);
+          return;
+          //goto LABEL_51;
         }
       }
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
@@ -2966,13 +2966,14 @@
     {
       if ( a1 == 41 )
       {
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
           ++pMessageQueue_50CBD0->uNumMessages;
-        }
+        }*/
         dword_50C9DC = 195;
         ptr_50C9E0 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
         return 0;
@@ -3467,13 +3468,14 @@
   pParty->sRotationY = 512;
   pParty->sRotationX = 0;
   pParty->uFallSpeed = 0;
-  if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
   {
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
     ++pMessageQueue_50CBD0->uNumMessages;
-  }
+  }*/
+  pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
   v2 = pParty->pPlayers;
   do
   {
@@ -4097,13 +4099,14 @@
         dword_F8B19C = 103;
         break;
       case 104:
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)29;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v1;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = v1;
           ++pMessageQueue_50CBD0->uNumMessages;
-        }
+        }*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_PlayArcomage, v1, v1);
         dword_F8B19C = 104;
         break;
     }
@@ -5198,24 +5201,28 @@
   }
   if ( v15 )
   {
-    if ( (signed int)result < 40 )
-    {
-      pMessageQueue_50CBD0->pMessages[result].eType = (UIMessageType)132;
+    /*if ( (signed int)result < 40 )
+    {
+      pMessageQueue_50CBD0->pMessages[result].eType = UIMSG_Quit;
       goto LABEL_42;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_Quit, 1, 0);
+    goto LABEL_43;
   }
   else
   {
-    if ( (signed int)result < 40 )
-    {
-      pMessageQueue_50CBD0->pMessages[result].eType = (UIMessageType)197;
+    pMessageQueue_50CBD0->AddMessage(UIMSG_ShowFinalWindow, 1, 0);
+    goto LABEL_43;
+    /*if ( (signed int)result < 40 )
+    {
+      pMessageQueue_50CBD0->pMessages[result].eType = UIMSG_C5;
 LABEL_42:
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
       result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
       *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
       goto LABEL_43;
-    }
+    }*/
   }
 LABEL_43:
   bGameoverLoop = 0;
@@ -7911,9 +7918,9 @@
   v4 = rand();
   v34 = 0;
   v5 = v4 % 100;
-  v6 = 2 * (v2->Treasure_prob + 7 * v3->uIndex) - 14;
-  v7 = (unsigned __int8)byte_4E8168[v6 + 16];
-  v8 = (unsigned __int8)byte_4E8168[v6 + 17];
+ // v6 = 2 * (v2->Treasure_prob + 7 * v3->uIndex) - 14;
+  v7 = (unsigned __int8)byte_4E8168[v3->uIndex-1][2*v2->Treasure_prob];
+  v8 = (unsigned __int8)byte_4E8168[v3->uIndex-1][2*v2->Treasure_prob+1];
   v32 = v5;
   v33 = v7;
   v9 = rand();
@@ -8089,8 +8096,8 @@
       if ( (v3->uItemID & 0x80000000u) == 0 )
         goto LABEL_56;
       v4 = rand() % 5 + 1;
-      v5 = (unsigned __int8)byte_4E8168[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 2];
-      v6 = (unsigned __int8)byte_4E8168[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 3];
+      v5 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob];//[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 2];
+      v6 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob+1];//[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 3];
       v7 = rand();
       v8 = v6 - v5 + 1;
       v9 = v5 + v7 % v8;
@@ -11004,13 +11011,14 @@
   {
     pGUIWindow_CurrentMenu->field_40 = 0;
     strcpy((char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot, (const char *)pKeyActionMap->pPressedKeysBuffer);
-    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)83;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_SaveGame, 0, 0);
   }
   else
   {
@@ -11949,14 +11957,15 @@
         }
         if ( wParam == 27 )
         {
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, !v12, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             v12 = window_SpeakInHouse == 0;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = !v12;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
           return 0;
         }
         if ( wParam <= 0x24 )
@@ -15206,13 +15215,14 @@
           Actor::FaceObject(v12, 4u, 0, 0);
           if ( v13->uNPC_ID )
           {
-            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v12, 0);
+            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
             {
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)161;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v12;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
-            }
+            }*/
           }
           else
           {
--- a/mm7_4.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_4.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -5866,7 +5866,7 @@
   LONG uMouseX; // edi@6
   LONG uMouseY; // eax@6
   GUIButton *pControlsHead; // edx@6
-  unsigned int pNumMessage; // ecx@7
+  //unsigned int pNumMessage; // ecx@7
   int pControlParam; // esi@12
   signed int v8; // edi@30
   int v9; // edx@31
@@ -5907,7 +5907,9 @@
     uMouseX = pMouse->GetCursorPos(&v25)->x;
     uMouseY = pMouse->GetCursorPos(&v25)->y;
     pControlsHead = pGUIWindow_CurrentMenu->pControlsHead;
-    if ( pControlsHead != (GUIButton *)v1 )
+
+    //does nothing actually
+    /*if ( pControlsHead != (GUIButton *)v1 )
     {
       pNumMessage = pMessageQueue_50CBD0->uNumMessages;
       do
@@ -5916,13 +5918,14 @@
             && uMouseY >= (signed int)pControlsHead->uY && uMouseY <= (signed int)pControlsHead->uW )//mouse movement
         {
           pControlParam = pControlsHead->uControlParam;
-          pMessageQueue_50CBD0->SendMessage((UIMessageType)pControlsHead->field_1C, pControlParam, 0);
+          pMessageQueue_50CBD0->AddMessage((UIMessageType)pControlsHead->field_1C, pControlParam, 0);
           v1 = 0;
         }
         pControlsHead = pControlsHead->pNext;
       }
       while ( pControlsHead != (GUIButton *)v1 );
-    }
+    }*/
+
     while ( PeekMessageA(&Msg, (HWND)v1, v1, v1, PM_REMOVE) )
     {
       if ( Msg.message == WM_QUIT )
@@ -9520,13 +9523,14 @@
             }
             pPlayers[uActiveCharacter]->PlaySound(SPEECH_85, 0);
           }
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
         }
       }
       else
@@ -9577,13 +9581,14 @@
               }
               break;
           }
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
           v11 = uActiveCharacter;
           if ( uActiveCharacter )
           {
@@ -9644,13 +9649,15 @@
   sub_44A56A();
   PrepareHouse((HOUSE_TYPE)(int)window_SpeakInHouse->ptr_1C);
   dword_F8B19C = 1;
-  if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+
+  pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
   {
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
     ++pMessageQueue_50CBD0->uNumMessages;
-  }
+  }*/
   v11 = uActiveCharacter;
   if ( uActiveCharacter )
   {
@@ -11604,7 +11611,7 @@
 LABEL_55:
           HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, v63);
 LABEL_56:
-          result = pMessageQueue_50CBD0->uNumMessages;
+          /*result = pMessageQueue_50CBD0->uNumMessages;
           if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
@@ -11613,7 +11620,9 @@
             *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
           }
-          return result;
+          return result;*/
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+          return 1; // void function actually
         }
         sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[538], v5 - LODWORD(v0->uExperience), v34 + 1);// 
                                                 // "You need %d more experience to train to level %d"
@@ -12484,13 +12493,14 @@
           pParty->field_709 = 0;
           sub_44A56A();
           dword_591084 = 0;
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
           goto LABEL_89;
         }
         v14 = 76;
@@ -12545,13 +12555,15 @@
     strcpy(v13, v15);
     pParty->field_709 = 0;
     sub_44A56A();
-    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+
+    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
+    }*/
     if ( (uDialogue_SpeakingActorNPC_ID & 0x80000000u) == 0 )
       pDialogue_SpeakingActor->uAIState = Removed;
     if ( uActiveCharacter )
@@ -12569,13 +12581,14 @@
     {
       if ( v2->uProfession != 41 )
         v2->bHasUsedTheAbility = 1;
-      if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
       {
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
         ++pMessageQueue_50CBD0->uNumMessages;
-      }
+      }*/
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
       goto LABEL_87;
     }
     v7 = pGlobalTXT_LocalizationStrings[140];
@@ -12844,7 +12857,7 @@
           }
         }
       }
-      result = pMessageQueue_50CBD0->uNumMessages;
+      /*result = pMessageQueue_50CBD0->uNumMessages;
       if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
       {
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
@@ -12852,8 +12865,9 @@
         result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
         *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
         ++pMessageQueue_50CBD0->uNumMessages;
-      }
-      return result;
+      }*/
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+      return 1; // void function actually
     }
     pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
     v5 = 0;
@@ -13388,7 +13402,7 @@
     v1->PlaySound(SPEECH_82, 0);
     pOtherOverlayList->_4418B1(20, uActiveCharacter + 99, 0, 65536);
 LABEL_46:
-    result = pMessageQueue_50CBD0->uNumMessages;
+    /*result = pMessageQueue_50CBD0->uNumMessages;
     if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
@@ -13396,8 +13410,9 @@
       result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
       *(&pMessageQueue_50CBD0->uNumMessages + result) = v25;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
-    return result;
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v25);
+    return result; // void func
   }
   v63 = 1;
   v41 = pDialogueWindow->GetControl(pDialogueWindow->pStartingPosActiveItem);
@@ -13650,7 +13665,7 @@
     {
       v5 = 0;
     }
-    result = pMessageQueue_50CBD0->uNumMessages;
+    /*result = pMessageQueue_50CBD0->uNumMessages;
     if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
@@ -13658,8 +13673,9 @@
       result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
       *(&pMessageQueue_50CBD0->uNumMessages + result) = v5;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
-    return result;
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, v5);
+    return result; // void func
   }
   if ( !(unsigned __int16)_449B57_test_bit(
                             (unsigned __int8 *)v1->field_152,
@@ -14000,11 +14016,12 @@
       {
         ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
         HousePlaySomeSound((unsigned int)window_SpeakInHouse->ptr_1C, 3);
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
           return;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
-        goto LABEL_33;
+        goto LABEL_33;*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
       }
       Party::TakeGold(s1);
       v47[1] = (const char *)7;
@@ -14076,7 +14093,8 @@
           sqrt(3.1415926);
         while ( sub_4BD8B5() )
           ;
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
@@ -14084,7 +14102,7 @@
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
           ++pMessageQueue_50CBD0->uNumMessages;
           return;
-        }
+        }*/
       }
       else
       {
--- a/mm7_5.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_5.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -77,7 +77,7 @@
   unsigned int v8; // edx@59
   unsigned int v9; // ecx@60
   unsigned int v10; // ecx@73
-  unsigned int v11; // eax@75
+  //unsigned int v11; // eax@75
   unsigned __int8 v12; // sf@75
   unsigned __int8 v13; // of@75
   int v14; // eax@98
@@ -489,23 +489,25 @@
             v10 = pSaveListPosition + uMessageParam;
             if ( dword_6BE138 == pSaveListPosition + uMessageParam )
             {
-              if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+              pMessageQueue_50CBD0->AddMessage(UIMSG_LoadSlot, 0, 0);
+              pMessageQueue_50CBD0->AddMessage(UIMSG_LoadGame, 0, 0);
+              /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
               {
-                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)164;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_LoadSlot;
                 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
                 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-                v11 = pMessageQueue_50CBD0->uNumMessages + 1;
-                v13 = pMessageQueue_50CBD0->uNumMessages + 1 > 40;
-                v12 = (signed int)pMessageQueue_50CBD0->uNumMessages - 39 < 0;
+                //v11 = pMessageQueue_50CBD0->uNumMessages + 1;
+                //v13 = pMessageQueue_50CBD0->uNumMessages + 1 > 40;
+                //v12 = (signed int)pMessageQueue_50CBD0->uNumMessages - 39 < 0;
                 ++pMessageQueue_50CBD0->uNumMessages;
                 if ( v12 ^ v13 )
                 {
-                  pMessageQueue_50CBD0->pMessages[v11].eType = (UIMessageType)82;
+                  pMessageQueue_50CBD0->pMessages[v11].eType = UIMSG_LoadGame;
                   pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
                   *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                   ++pMessageQueue_50CBD0->uNumMessages;
                 }
-              }
+              }*/
             }
             uLoadGameUI_SelectedSlot = v10;
             dword_6BE138 = v10;
@@ -1918,13 +1920,14 @@
           }
           sub_4BD8B5();
           //goto LABEL_434;
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v0, 0);
           continue;
         case UIMSG_C3:
           pAudioPlayer->StopChannels(-1, -1);
@@ -1987,12 +1990,13 @@
         case UIMSG_B5:
           dword_50CDC8 = v0;
           //goto LABEL_453;
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
             continue;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;
+          ++pMessageQueue_50CBD0->uNumMessages;*/
           continue;
         case UIMSG_B3:
           pPlayer9 = pPlayers[_506348_current_lloyd_playerid + 1];
@@ -2038,13 +2042,14 @@
               pParty->sRotationY = LOWORD(pNPCData4->Location2D);
               pParty->sRotationX = HIWORD(pNPCData4->Location2D);
             }
-            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v0, 0);
+            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
             {
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
-            }
+            }*/
             //crt_deconstruct_ptr_6A0118();
             pBooksWindow->Release();
             pGUIWindow_CurrentMenu->Release();
@@ -2135,14 +2140,15 @@
                   else
                     pParty->pPlayers[(unsigned __int8)byte_50C0C0].CanCastSpell(0x14u);
 //LABEL_434:
-                  if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                   {
                     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
                     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
 //LABEL_771:
                     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                     ++pMessageQueue_50CBD0->uNumMessages;
-                  }
+                  }*/
+                  pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, v0, 0);
                   continue;
                 }
                 v63 = 210;
@@ -2688,13 +2694,14 @@
                 Rest(v95 % 6 + 60);
                 _506F18_num_hours_to_sleep = 0;
                 dword_506F14 = 0;
-                if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                 {
                   pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
                   pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
                   *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                   ++pMessageQueue_50CBD0->uNumMessages;
-                }
+                }*/
+                pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
                 ShowStatusBarString(pGlobalTXT_LocalizationStrings[481], 2u);// "Encounter!"
                 v165 = 0;
                 v151 = 0;
@@ -2874,14 +2881,18 @@
           v130 = 0;
           v127 = rand() % 2 + 204;
           goto _play_sound_and_continue;
-        case UIMSG_56:
-          if ( pTurnEngine->field_4 != 3 )
-          {
-            if ( uActiveCharacter )
-            {
-              uNumSeconds = (unsigned int)pPlayers[uActiveCharacter];
-              if ( *(char *)(uNumSeconds + 11 * *(char *)(uNumSeconds + 6734) + uMessageParam + 402) )
-              {
+        case UIMSG_SelectSpell:
+        {
+          if (pTurnEngine->field_4 == 3)
+            continue;
+          if (!uActiveCharacter)
+            continue;
+
+            //  uNumSeconds = (unsigned int)pPlayers[uActiveCharacter];
+          auto player = pPlayers[uActiveCharacter];
+          if (player->spellbook.pChapters[player->lastOpenedSpellbookPage].bIsSpellAvailable[uMessageParam])
+              //if ( *(char *)(uNumSeconds + 11 * *(char *)(uNumSeconds + &lastOpenedSpellbookPage) + uMessageParam + 402) )
+          {
                 if ( dword_50654C - 1 == uMessageParam )
                 {
                   pGUIWindow_CurrentMenu->Release();
@@ -2889,12 +2900,12 @@
                   viewparams->bRedrawGameUI = v0;
                   pCurrentScreen = SCREEN_GAME;
                   pIcons_LOD->_4114F2();
-                  v103 = dword_50654C + 11 * *(char *)(uNumSeconds + 6734);
+                  v103 = dword_50654C + 11 * player->lastOpenedSpellbookPage;
                   if ( dword_50C9E8 < 40 )
                   {
-                    dword_50C9EC[3 * dword_50C9E8] = 142;
-                    dword_50C9F0[3 * dword_50C9E8] = v103;
-                    *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = uActiveCharacter - 1;
+                    dword_50C9EC[3 * dword_50C9E8] = UIMSG_CastSpellFromBook;
+                    dword_50C9EC[3 * dword_50C9E8 + 1] = v103;
+                    dword_50C9EC[3 * dword_50C9E8 + 2] = uActiveCharacter - 1;
                     ++dword_50C9E8;
                   }
                 }
@@ -2903,10 +2914,9 @@
                   byte_506550 = 1;
                   dword_50654C = uMessageParam + 1;
                 }
-              }
-            }
-          }
-          continue;
+          }
+        }
+        continue;
 
         case UIMSG_CastSpellFromBook:
           if ( pTurnEngine->field_4 != 3 )
@@ -3013,13 +3023,14 @@
           GUIWindow::Create(0x25Au, 0x1C2u, 0, 0, WINDOW_VoiceSwitcherButton, (int)pBtn_GameSettings, 0);
           uNumVisibleWindows = uNumVisibleWindows - 1; //Ritor1: Insert
 //LABEL_453:
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
             continue;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
           //goto LABEL_770;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;
+          ++pMessageQueue_50CBD0->uNumMessages;*/
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
           continue;
         case UIMSG_C0:
           dword_50651C = v0;
@@ -3309,7 +3320,8 @@
           if ( !pMessageQueue_50CBD0->uNumMessages )
             //goto LABEL_768;
           {
-            if ( (signed int)v115 < 40 )
+            pMessageQueue_50CBD0->AddMessage(UIMSG_E, 0, 0);
+            /*if ( (signed int)v115 < 40 )
             //goto LABEL_769;
             {
               pMessageQueue_50CBD0->pMessages[v115].eType = (UIMessageType)14;
@@ -3317,12 +3329,14 @@
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
               continue;
-            }
+            }*/
             continue;
           }
           if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
           {
-            v115 = v0;
+            pMessageQueue_50CBD0->uNumMessages = v0;
+            pMessageQueue_50CBD0->AddMessage(UIMSG_E, 0, 0);
+            /*v115 = v0;
             pMessageQueue_50CBD0->uNumMessages = v0;
 //LABEL_769:
             pMessageQueue_50CBD0->pMessages[v115].eType = (UIMessageType)14;
@@ -3330,13 +3344,14 @@
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
             //goto LABEL_771;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-            ++pMessageQueue_50CBD0->uNumMessages;
+            ++pMessageQueue_50CBD0->uNumMessages;*/
             continue;
           }
           v115 = 0;
           pMessageQueue_50CBD0->uNumMessages = 0;
 //LABEL_768:
-          if ( (signed int)v115 < 40 )
+          pMessageQueue_50CBD0->AddMessage(UIMSG_E, 0, 0);
+          /*if ( (signed int)v115 < 40 )
             //goto LABEL_769;
           {
             pMessageQueue_50CBD0->pMessages[v115].eType = (UIMessageType)14;
@@ -3344,7 +3359,7 @@
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
             continue;
-          }
+          }*/
           continue;
         case UIMSG_E:
 //LABEL_772:
@@ -3455,13 +3470,14 @@
   dword_50C9E8 = 0;
   if ( dword_50C9DC )
   {
-    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)dword_50C9DC;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = (int)ptr_50C9E0;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage((UIMessageType)dword_50C9DC, (int)ptr_50C9E0, 0);
     dword_50C9DC = 0;
   }
   else
@@ -3471,13 +3487,14 @@
       dword_50C9D8 -= pEventTimer->uTimeElapsed;
       if ( dword_50C9D8 <= 0 )
       {
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)dword_50C9D0;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = dword_50C9D4;
           *(&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;
@@ -3699,8 +3716,8 @@
               v26 = uNum + pSaveListPosition;
               if ( dword_6BE138 == uNum + pSaveListPosition )
               {
-                pMessageQueue_50CBD0->SendMessage(UIMSG_LoadSlot, 0, 0);
-                pMessageQueue_50CBD0->SendMessage(UIMSG_LoadGame, 0, 0);
+                pMessageQueue_50CBD0->AddMessage(UIMSG_LoadSlot, 0, 0);
+                pMessageQueue_50CBD0->AddMessage(UIMSG_LoadGame, 0, 0);
               }
               uLoadGameUI_SelectedSlot = v26;
               dword_6BE138 = v26;
@@ -3777,12 +3794,13 @@
             viewparams->bRedrawGameUI = 1;
           }
           GUIWindow::Create(602, 450, 0, 0, WINDOW_VoiceSwitcherButton, (int)pBtn_GameSettings, 0);
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
             continue;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;
+          ++pMessageQueue_50CBD0->uNumMessages;*/
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
           continue;
         }
         if ( pUIMessageType == UIMSG_Escape )
@@ -3813,7 +3831,7 @@
               SetCurrentMenuID(MENU_CREDITSCLOSE);
               continue;
             }
-            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
             {
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)5;
 //LABEL_93:
@@ -3821,7 +3839,8 @@
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
               continue;
-            }
+            }*/
+            pMessageQueue_50CBD0->AddMessage(UIMSG_ChangeGameState, 0, 0);
             continue;
           }
           v16 = GetCurrentMenuID() == 8;
@@ -13107,7 +13126,7 @@
 LABEL_30:
   if ( byte_506360 )
   {
-    result = pMessageQueue_50CBD0->uNumMessages;
+    /*result = pMessageQueue_50CBD0->uNumMessages;
     if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)181;
@@ -13115,7 +13134,8 @@
       result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
       *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_B5, 0, 0);
   }
   return result;
 }
@@ -14476,13 +14496,14 @@
   GUIWindow *v0; // ecx@1
 
   v0 = ptr_507BDC;
-  if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+  pMessageQueue_50CBD0->AddMessage((UIMessageType)(int)ptr_507BDC->ptr_1C, 0, 0);
+  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
   {
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)(int)ptr_507BDC->ptr_1C;
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
     ++pMessageQueue_50CBD0->uNumMessages;
-  }
+  }*/
   v0->Release();
   ptr_507BDC = 0;
   pCurrentScreen = dword_506F0C[0];
@@ -15091,9 +15112,9 @@
           pGUIButton3->DrawLabel(pHint, pFontCreate, 0, 0);
         pWindow->Release();
         if (pCurrentScreen == SCREEN_SAVEGAME)
-          pMessageQueue_50CBD0->SendMessage(UIMSG_SaveGame, 0, 0);
+          pMessageQueue_50CBD0->AddMessage(UIMSG_SaveGame, 0, 0);
         else
-          pMessageQueue_50CBD0->SendMessage(UIMSG_LoadGame, 0, 0);
+          pMessageQueue_50CBD0->AddMessage(UIMSG_LoadGame, 0, 0);
       }
       continue;
     }
@@ -15113,7 +15134,7 @@
           if ( pHint && pHint != (char *)1 )
             pGUIButton->DrawLabel(pHint, pFontCreate, 0, 0);
           pWindow->Release();
-          if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
             continue;
           pNumMessages = pMessageQueue_50CBD0->uNumMessages;
 //LABEL_151:
@@ -15121,7 +15142,8 @@
 //LABEL_152:
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;
+          ++pMessageQueue_50CBD0->uNumMessages;*/
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
           continue;
         }
         v34 = v33 - 1;
@@ -15208,14 +15230,15 @@
           ((GUIButton *)v32)->DrawLabel(pHint, pFontCreate, 0, 0);
         pWindow->Release();
         pNumMessages = pMessageQueue_50CBD0->uNumMessages;
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
          pMessageQueue_50CBD0->pMessages[pNumMessages].eType = (UIMessageType)113;
          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
          ++pMessageQueue_50CBD0->uNumMessages;
          continue;
-        }
+        }*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
         continue;
       }
 
@@ -15233,7 +15256,7 @@
         pWindow->Release();
 //LABEL_142:
         pNumMessages = pMessageQueue_50CBD0->uNumMessages;
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           //goto LABEL_151;
         {
          pMessageQueue_50CBD0->pMessages[pNumMessages].eType = (UIMessageType)113; //0x71
@@ -15241,7 +15264,8 @@
          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
          ++pMessageQueue_50CBD0->uNumMessages;
          continue;
-        }
+        }*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
         continue;
       }
       v14 = pWindowType - 80;
@@ -15410,13 +15434,14 @@
         {
           v29 = pMessageQueue_50CBD0->uNumMessages;
           pWindow->field_40 = 0;
-          if ( (signed int)v29 < 40 )
+          /*if ( (signed int)v29 < 40 )
           {
             pMessageQueue_50CBD0->pMessages[v29].eType = (UIMessageType)(int)ptr_507BD0->ptr_1C;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
-          }
+          }*/
+          pMessageQueue_50CBD0->AddMessage((UIMessageType)(int)ptr_507BD0->ptr_1C, 0, 0);
           pEventTimer->Resume();
           ptr_507BD0->Release();
           pCurrentScreen = SCREEN_GAME;
@@ -15538,14 +15563,15 @@
         }
         //goto LABEL_142;
         pNumMessages = pMessageQueue_50CBD0->uNumMessages;
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
         {
          pMessageQueue_50CBD0->pMessages[pNumMessages].eType = (UIMessageType)113;
          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
          ++pMessageQueue_50CBD0->uNumMessages;
          continue;
-        }
+        }*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
         continue;
       }
       if ( pWindowType == WINDOW_SpellBook )
@@ -15906,13 +15932,15 @@
       v26 = rand();
       v0->ReceiveDamage(v26 % 11 + 10, 0);
       pAudioPlayer->PlaySound(SOUND_8, 0, 0, -1, 0, 0, 0, 0);
-      if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
       {
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
         ++pMessageQueue_50CBD0->uNumMessages;
-      }
+      }*/
       v42 = (int *)&a2.y;
       v41 = (int *)&y.y;
       v40 = (int *)&pOut;
@@ -15980,13 +16008,15 @@
       }
       v0->_4160CA(v23);
       pAudioPlayer->PlaySound(SOUND_8, 0, 0, -1, 0, 0, 0, 0);
-      if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
+      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
       {
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
         ++pMessageQueue_50CBD0->uNumMessages;
-      }
+      }*/
       v42 = (int *)&a2.y;
       v41 = (int *)&y.y;
       v40 = (int *)&pOut;
@@ -16636,7 +16666,7 @@
         pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
       }
       //v11 = i->uControlParam;
-      pMessageQueue_50CBD0->SendMessage((UIMessageType)i->uControlID, i->uControlParam, 0);
+      pMessageQueue_50CBD0->AddMessage((UIMessageType)i->uControlID, i->uControlParam, 0);
       return;
     }
     goto LABEL_45;
@@ -16655,13 +16685,15 @@
     && pPlayers[uActiveCharacter]->CanAct()
     && pPlayers[uActiveCharacter]->CanSteal() )
   {
-    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)27;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v6 >> 3;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
-    }
+    }*/
+    pMessageQueue_50CBD0->AddMessage(UIMSG_1B, v6 >> 3, 0);
+
     if ( pParty->bTurnBasedModeOn == 1 )
     {
       if ( pTurnEngine->field_4 == 3 )
--- a/mm7_6.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_6.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -2175,7 +2175,7 @@
 {
   //bool result; // eax@2
   __int16 v6; // bx@4
-  Player *v7; // eax@4
+  //Player *v7; // eax@4
   char v8; // zf@12
   unsigned __int16 v9; // cx@16
   unsigned int v10; // eax@18
@@ -2214,7 +2214,9 @@
 
 
     v6 = a5;
-    v7 = &pParty->pPlayers[uPlayerID];
+    //v7 = &pParty->pPlayers[uPlayerID];
+  assert(uPlayerID < 4);
+  auto player = &pParty->pPlayers[uPlayerID];
     if ( !(a5 & 0x10) )
     {
       switch ( a1 )
@@ -2275,19 +2277,19 @@
           if ( a4 )
             v8 = (a4 & 0x1C0) == 0;
           else
-            v8 = (v7->pActiveSkills[16] & 0x1C0) == 0;
+            v8 = (player->pActiveSkills[PLAYER_SKILL_SPIRIT] & 0x1C0) == 0;
           if ( v8 )
             goto LABEL_25;
           break;
         case 50:
           v9 = a4;
           if ( !a4 )
-            v9 = v7->pActiveSkills[16];
+            v9 = player->pActiveSkills[PLAYER_SKILL_SPIRIT];
           goto LABEL_18;
         case 95:
           v9 = a4;
           if ( !a4 )
-            v9 = v7->pActiveSkills[20];
+            v9 = player->pActiveSkills[PLAYER_SKILL_DARK];
 LABEL_18:
           v10 = SkillToMastery(v9);
           v12 = __OFSUB__(v10, 3);
@@ -2296,7 +2298,7 @@
         case 73:
           v13 = a4;
           if ( !a4 )
-            v13 = v7->pActiveSkills[18];
+            v13 = player->pActiveSkills[PLAYER_SKILL_BODY];
           v14 = SkillToMastery(v13);
           v12 = __OFSUB__(v14, 4);
           v11 = ((v14 - 4) & 0x80000000u) != 0;
@@ -5613,7 +5615,7 @@
         if ( pParty->uFlags & 0x30 && v12 != 4 || rand() % 100 >= amount && v731 != 4 )
           goto LABEL_200;
         byte_50C0C0 = LOBYTE(v3->uPlayerID);
-        pMessageQueue_50CBD0->SendMessage((UIMessageType)195, v1, v1);
+        pMessageQueue_50CBD0->AddMessage(UIMSG_C3, v1, v1);
         goto LABEL_1056;
       case 33:
         LODWORD(v733) = 604800 * v2;
@@ -5623,7 +5625,7 @@
         if ( pPlayer->sMana >= (signed int)uRequiredMana )
         {
           pEventTimer->Pause();
-          pMessageQueue_50CBD0->SendMessage((UIMessageType)177, v1, v1);
+          pMessageQueue_50CBD0->AddMessage(UIMSG_B1, v1, v1);
           qword_506350 = (signed int)v733;
           _506348_current_lloyd_playerid = v3->uPlayerID;
           ::uRequiredMana = v319;
@@ -7795,11 +7797,115 @@
   return 8 * this->pIcons[uIconID].uAnimLength;
 }
 
+
+const wchar_t *UIMessage2String(UIMessageType msg)
+{
+  #define CASE(xxx) case xxx: _swprintf(b, L"%03X/%s", msg, L#xxx); return b;
+  static wchar_t b[256]; // bad for threads
+  switch (msg)
+  {
+    CASE(UIMSG_SelectSpell)
+    CASE(UIMSG_ChangeGameState)
+    CASE(UIMSG_Attack)
+    CASE(UIMSG_PlayArcomage)
+    CASE(UIMSG_MainMenu_ShowPartyCreationWnd)
+    CASE(UIMSG_MainMenu_ShowLoadWindow)
+    CASE(UIMSG_ShowCredits)
+    CASE(UIMSG_ExitToWindows)
+    CASE(UIMSG_PlayerCreationChangeName)
+    CASE(UIMSG_PlayerCreationClickPlus)
+    CASE(UIMSG_PlayerCreationClickMinus)
+    CASE(UIMSG_PlayerCreationSelectActiveSkill)
+    CASE(UIMSG_PlayerCreationSelectClass)
+    CASE(UIMSG_PlayerCreationClickOK)
+    CASE(UIMSG_PlayerCreationClickReset)
+    CASE(UIMSG_AutonotesBook)
+    CASE(UIMSG_PlayerCreationRemoveUpSkill)
+    CASE(UIMSG_PlayerCreationRemoveDownSkill)
+    CASE(UIMSG_SPellbook_ShowHightlightedSpellInfo)
+    CASE(UIMSG_LoadGame)
+    CASE(UIMSG_SaveGame)
+    CASE(UIMSG_ShowStatus_DateTime)
+    CASE(UIMSG_ShowStatus_ManaHP)
+    CASE(UIMSG_ShowStatus_Player)
+    CASE(UIMSG_Wait5Minutes)
+    CASE(UIMSG_Wait1Hour)
+    CASE(UIMSG_ShowStatus_Food)
+    CASE(UIMSG_ShowStatus_Funds)
+    CASE(UIMSG_QuickReference)
+    CASE(UIMSG_GameMenuButton)
+    CASE(UIMSG_AlreadyResting)
+    CASE(UIMSG_SelectCharacter)
+    CASE(UIMSG_ChangeSoundVolume)
+    CASE(UIMSG_ChangeMusicVolume)
+    CASE(UIMSG_Escape)
+    CASE(UIMSG_PlayerCreation_SelectAttribute)
+    CASE(UIMSG_InventoryLeftClick)
+    CASE(UIMSG_SkillUp)
+    CASE(UIMSG_GameMenu_ReturnToGame)
+    CASE(UIMSG_StartNewGame)
+    CASE(UIMSG_Game_OpenLoadGameDialog)
+    CASE(UIMSG_Game_OpenSaveGameDialog)
+    CASE(UIMSG_Game_OpenOptionsDialog)
+    CASE(UIMSG_SetGraphicsMode)
+    CASE(UIMSG_Quit)
+    CASE(UIMSG_StartHireling1Dialogue)
+    CASE(UIMSG_StartHireling2Dialogue)
+    CASE(UIMSG_SelectDialogueOption)
+    CASE(UIMSG_CastSpellFromBook)
+    CASE(UIMSG_PlayerCreation_VoicePrev)
+    CASE(UIMSG_PlayerCreation_VoiceNext)
+    CASE(UIMSG_StartNPCDialogue)
+    CASE(UIMSG_ArrowUp)
+    CASE(UIMSG_DownArrow)
+    CASE(UIMSG_LoadSlot)
+    CASE(UIMSG_SelectLoadSlot)
+    CASE(UIMSG_Cancel)
+    CASE(UIMSG_ExitRest)
+    CASE(UIMSG_PlayerCreation_FacePrev)
+    CASE(UIMSG_PlayerCreation_FaceNext)
+    CASE(UIMSG_CycleCharacters)
+    CASE(UIMSG_SetTurnSpeed)
+    CASE(UIMSG_ToggleWalkSound)
+    CASE(UIMSG_ChangeVoiceVolume)
+    CASE(UIMSG_ToggleShowDamage)
+    CASE(UIMSG_ScrollNPCPanel)
+    CASE(UIMSG_ShowFinalWindow)
+    CASE(UIMSG_OpenQuestBook)
+    CASE(UIMSG_OpenAutonotes)
+    CASE(UIMSG_OpenMapBook)
+    CASE(UIMSG_OpenCalendar)
+    CASE(UIMSG_OpenHistoryBook)
+    CASE(UIMSG_ToggleAlwaysRun)
+    CASE(UIMSG_ToggleFlipOnExit)
+    CASE(UIMSG_Game_Action)
+    CASE(UIMSG_OpenRestUI)
+    CASE(UIMSG_TransitionUI_Confirm)
+    CASE(UIMSG_OpenKeyMappingOptions)
+    CASE(UIMSG_SelectKeyPage1)
+    CASE(UIMSG_SelectKeyPage2)
+    CASE(UIMSG_ResetKeyMapping)
+    CASE(UIMSG_ChangeKeyButton)
+    CASE(UIMSG_OpenVideoOptions)
+    CASE(UIMSG_ToggleBloodsplats)
+    CASE(UIMSG_ToggleColoredLights)
+    CASE(UIMSG_ToggleTint)
+    default:
+      _swprintf(b, L"UIMSG_%03X", msg); return b;
+  };
+  #undef CASE
+}
+
+
 //----- (0042EB8D) --------------------------------------------------------
-void GUIMessageQueue::SendMessage(UIMessageType msg, int param, unsigned int a4)
+void GUIMessageQueue::AddMessageImpl(UIMessageType msg, int param, unsigned int a4, const char *file, int line)
 {
+  Log::Warning(L"%s @ (%S %u)", UIMessage2String(msg), file, line);
   if (uNumMessages < 40)
   {
+    files[uNumMessages] = file;
+    lines[uNumMessages] = line;
+
     pMessages[uNumMessages].eType = msg;
     pMessages[uNumMessages].param = param;
     pMessages[uNumMessages++].field_8 = a4;
@@ -9084,8 +9190,9 @@
             {
               pActionQueue = pPartyActionQueue;
 LABEL_120:
-
-              if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+              pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
+              break;
+              /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
               {
                 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Attack;
                 //goto _send_message;
@@ -9093,7 +9200,7 @@
                 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                 ++pMessageQueue_50CBD0->uNumMessages;
                 break;
-              }
+              }*/
             }
             else
             {
@@ -9101,8 +9208,8 @@
               if ( dword_50C9E8 < 40 )
               {
                 dword_50C9EC[3 * dword_50C9E8] = 25;
-                dword_50C9F0[3 * dword_50C9E8] = 0;
-                *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = 0;
+                dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
+                dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
                 ++dword_50C9E8;
               }
             }
@@ -9119,13 +9226,15 @@
           case INPUT_EventTrigger:
             if (pCurrentScreen == SCREEN_GAME)
             {
-              if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+              /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
                 break;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Game_Action;
               //goto _send_message;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
+              break;*/
+              pMessageQueue_50CBD0->AddMessage(UIMSG_Game_Action, 0, 0);
               break;
             }
             if ( pCurrentScreen == SCREEN_NPC_DIALOGUE )
@@ -9133,6 +9242,8 @@
               v11 = pMessageQueue_50CBD0->uNumMessages;
               if ( pMessageQueue_50CBD0->uNumMessages )
               {
+                v11 = 0;
+                pMessageQueue_50CBD0->uNumMessages = 0;
                 if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
                 {
                   v11 = 1;
@@ -9145,10 +9256,9 @@
                   ++pMessageQueue_50CBD0->uNumMessages;
                   break;
                 }
-                v11 = 0;
-                pMessageQueue_50CBD0->uNumMessages = 0;
+                break;
               }
-              if ( (signed int)v11 < 40 )
+              /*if ( (signed int)v11 < 40 )
                 //goto LABEL_132;
               {
                 pMessageQueue_50CBD0->pMessages[v11].eType = UIMSG_Escape;
@@ -9156,7 +9266,8 @@
                 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                 ++pMessageQueue_50CBD0->uNumMessages;
                 break;
-              }
+              }*/
+              pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
             }
             break;
           case INPUT_CharCycle:
@@ -9166,8 +9277,8 @@
               break;
             dword_50C9EC[3 * dword_50C9E8] = 176;
             //goto LABEL_155;
-            dword_50C9F0[3 * dword_50C9E8] = 0;
-            *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = 0;
+            dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
+            dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
             ++dword_50C9E8;
             break;
           case INPUT_LookUp:
@@ -9235,8 +9346,8 @@
               break;
             dword_50C9EC[3 * dword_50C9E8] = 367;
             //goto LABEL_155;
-            dword_50C9F0[3 * dword_50C9E8] = 0;
-            *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = 0;
+            dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
+            dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
             ++dword_50C9E8;
             break;
           case INPUT_ZoomOut:
@@ -9245,8 +9356,8 @@
             {
               dword_50C9EC[3 * dword_50C9E8] = 368;
 //LABEL_155:
-              dword_50C9F0[3 * dword_50C9E8] = 0;
-              *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = 0;
+              dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
+              dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
               ++dword_50C9E8;
             }
             break;
@@ -9276,13 +9387,14 @@
     {
       if ( !pCurrentScreen )
       {
-        if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
           goto LABEL_175;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)404;
         //goto LABEL_174;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-        ++pMessageQueue_50CBD0->uNumMessages;
+        ++pMessageQueue_50CBD0->uNumMessages;*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Game_Action, 0, 0);
         goto LABEL_175;
       }
       if ( pCurrentScreen == SCREEN_NPC_DIALOGUE
@@ -9295,9 +9407,9 @@
           if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
           {
             v15 = 1;
-            pMessageQueue_50CBD0->uNumMessages = 1;
+            pMessageQueue_50CBD0->uNumMessages = 0;
             //goto LABEL_173;
-            pMessageQueue_50CBD0->pMessages[v15].eType = (UIMessageType)113;
+            pMessageQueue_50CBD0->pMessages[v15].eType = UIMSG_Escape;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
@@ -9305,14 +9417,15 @@
           }
           pMessageQueue_50CBD0->uNumMessages = 0;
         }
-        if ( (signed int)v15 >= 40 )
+        /*if ( (signed int)v15 >= 40 )
           goto LABEL_175;
 //LABEL_173:
         pMessageQueue_50CBD0->pMessages[v15].eType = (UIMessageType)113;
 //LABEL_174:
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-        ++pMessageQueue_50CBD0->uNumMessages;
+        ++pMessageQueue_50CBD0->uNumMessages;*/
+        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
         goto LABEL_175;
       }
     }
--- a/mm7_data.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_data.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -1104,7 +1104,14 @@
 char aEWorkMsdevMm_7[777]; // idb
 char aGammaControlNo[777]; // idb
 __int16 word_4E8152[11] = {0, 0, 0, 90, 8, 2, 70, 20, 10, 50, 30};
-char byte_4E8168[116];
+char byte_4E8168[7][14]={  //byte_4E8178
+	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
+	{ 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
+	{ 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3},
+	{ 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4},
+	{ 2, 2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5},
+	{ 2, 2, 2, 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6},
+	{ 2, 2, 2, 2, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}};
 char aD3dTextureName[777]; // idb
 char aLogd3d_txt[777]; // idb
 char byte_4E8394[204] =
@@ -1935,9 +1942,8 @@
 int dword_50C9DC; // weak
 struct NPCData *ptr_50C9E0;
 int dword_50C9E8; // idb
-int dword_50C9EC[777]; // weak
-int dword_50C9F0[120]; // idb
-int dword_50CDC8; // weak
+int dword_50C9EC[120]; // weak
+int dword_50CDC8;
 int dword_50CDCC; // weak
 int bProcessorIsNotIntel; // weak
 Vec3_int_ layingitem_vel_50FDFC;
--- a/mm7_data.h	Sun Feb 24 13:52:57 2013 +0600
+++ b/mm7_data.h	Sun Feb 24 13:53:18 2013 +0600
@@ -786,7 +786,7 @@
 extern char aEWorkMsdevMm_7[]; // idb
 extern char aGammaControlNo[]; // idb
 extern __int16 word_4E8152[11];
-extern char byte_4E8168[116];
+extern char byte_4E8168[7][14];
 extern char aD3dTextureName[]; // idb
 extern char aLogd3d_txt[]; // idb
 extern char byte_4E8394[]; // weak
@@ -1277,9 +1277,8 @@
 extern int dword_50C9DC; // weak
 extern struct NPCData *ptr_50C9E0;
 extern int dword_50C9E8; // idb
-extern int dword_50C9EC[]; // weak
-extern int dword_50C9F0[120]; // idb
-extern int dword_50CDC8; // weak
+extern int dword_50C9EC[]; // 50C9EC
+extern int dword_50CDC8;
 extern int dword_50CDCC; // weak
 extern int bProcessorIsNotIntel; // weak
 extern Vec3_int_ layingitem_vel_50FDFC;
--- a/stru9.cpp	Sun Feb 24 13:52:57 2013 +0600
+++ b/stru9.cpp	Sun Feb 24 13:53:18 2013 +0600
@@ -227,7 +227,7 @@
 //----- (00498737) --------------------------------------------------------
 void stru9::AddVertex(struct VertexBuffer *pVertexBuffer, struct RenderVertexSoft *pVertex)
 {
-  __debugbreak();
+//  __debugbreak();
   RenderVertexSoft *v3; // eax@1
 
   v3 = &pVertexBuffer->pVertices[pVertexBuffer->uNumVertices];