changeset 437:0a1ea44b4a0a

ui mesages & spellcasting
author Nomad
date Sun, 24 Feb 2013 09:51:42 +0200
parents 4f451a616d3d
children 17c90e543e28
files GUIWindow.h Items.h NPC.h Player.cpp mm7_1.cpp mm7_2.cpp mm7_4.cpp mm7_5.cpp mm7_6.cpp mm7_data.cpp mm7_data.h
diffstat 11 files changed, 411 insertions(+), 218 deletions(-) [+]
line wrap: on
line diff
--- a/GUIWindow.h	Sun Feb 24 03:07:03 2013 +0200
+++ b/GUIWindow.h	Sun Feb 24 09:51:42 2013 +0200
@@ -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.h	Sun Feb 24 03:07:03 2013 +0200
+++ b/Items.h	Sun Feb 24 09:51:42 2013 +0200
@@ -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 03:07:03 2013 +0200
+++ b/NPC.h	Sun Feb 24 09:51:42 2013 +0200
@@ -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 03:07:03 2013 +0200
+++ b/Player.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -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 03:07:03 2013 +0200
+++ b/mm7_1.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -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;
 }
 
@@ -4542,13 +4545,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;
@@ -4576,11 +4580,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;
@@ -4667,14 +4672,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;
@@ -4703,13 +4709,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);
@@ -5394,13 +5401,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 )
@@ -5408,11 +5417,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
   {
@@ -5422,13 +5432,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 03:07:03 2013 +0200
+++ b/mm7_2.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -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;
@@ -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 03:07:03 2013 +0200
+++ b/mm7_4.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -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 03:07:03 2013 +0200
+++ b/mm7_5.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -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 03:07:03 2013 +0200
+++ b/mm7_6.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -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 03:07:03 2013 +0200
+++ b/mm7_data.cpp	Sun Feb 24 09:51:42 2013 +0200
@@ -1935,9 +1935,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 03:07:03 2013 +0200
+++ b/mm7_data.h	Sun Feb 24 09:51:42 2013 +0200
@@ -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;