changeset 992:3a3ab572eff5

Merge
author Nomad
date Mon, 13 May 2013 17:07:52 +0200
parents c5d8ea1e6ccb (current diff) 087a9af8e0ec (diff)
children ada1ed5f44a1
files GUIWindow.h Render.cpp Render.h UICharacter.cpp UiGame.cpp mm7_1.cpp mm7_5.cpp mm7_data.cpp mm7_data.h
diffstat 20 files changed, 518 insertions(+), 475 deletions(-) [+]
line wrap: on
line diff
--- a/Chest.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/Chest.cpp	Mon May 13 17:07:52 2013 +0200
@@ -242,7 +242,7 @@
   pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0);
 
   pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169,  35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId),   0);// Exit
-                    pChestWindow->CreateButton(  7,   8, 460, 343, 1, 0, UIMSG_C,      0, 0, "", 0);
+                    pChestWindow->CreateButton(  7,   8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem,      0, 0, "", 0);
 
   pCurrentScreen = SCREEN_CHEST;
   pEventTimer->Pause();
--- a/GUIWindow.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/GUIWindow.cpp	Mon May 13 17:07:52 2013 +0200
@@ -1160,7 +1160,7 @@
           GuildDialog();
           break;
         case BildingType_18:
-          __debugbreak; //What over the dialog?
+          __debugbreak(); //What over the dialog?
           sub_4B6478();
           break;
         case BildingType_TownHall:
@@ -1185,7 +1185,7 @@
           JailDialog();
           break;
         default:
-          __debugbreak;//New BildingType
+          __debugbreak();//New BildingType
           break;
       }
   }
@@ -1866,7 +1866,7 @@
         case WINDOW_ChangeLocation:
           pMainScreenNum = pCurrentScreen;
           pCurrentScreen = SCREEN_CHANGE_LOCATION;
-          pBtn_ExitCancel = pWindow->CreateButton(                  566,                   445,  75,  33, 1, 0, UIMSG_5B,             0, 'N', pGlobalTXT_LocalizationStrings[156], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);//Остаться в этой области
+          pBtn_ExitCancel = pWindow->CreateButton(                  566,                   445,  75,  33, 1, 0, UIMSG_CHANGE_LOCATION_ClickCencelBtn, 0, 'N', pGlobalTXT_LocalizationStrings[156], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);//Остаться в этой области
           pBtn_YES        = pWindow->CreateButton(                  486,                   445,  75,  33, 1, 0, UIMSG_OnTravelByFoot, 0, 'Y', pWindow->Hint, pIcons_LOD->GetTexture(uTextureID_BUTTYES2), 0);
                             pWindow->CreateButton(pNPCPortraits_x[0][0], pNPCPortraits_y[0][0],  63,  73, 1, 0, UIMSG_OnTravelByFoot, 1, ' ', pWindow->Hint, 0, 0, 0);
                             pWindow->CreateButton(                    8,                     8, 460, 344, 1, 0, UIMSG_OnTravelByFoot, 1,   0, pWindow->Hint, 0);
--- a/GUIWindow.h	Mon May 13 17:01:20 2013 +0200
+++ b/GUIWindow.h	Mon May 13 17:07:52 2013 +0200
@@ -14,9 +14,9 @@
 
   UIMSG_MouseLeftClickInGame = 10,
 
-  UIMSG_C = 12,
+  UIMSG_CHEST_ClickItem = 12,
 
-  UIMSG_E = 14,
+  UIMSG_MouseLeftClickInScreen = 14,
   UIMSG_F = 15,
 
   UIMSG_11 = 17,
@@ -70,7 +70,7 @@
   UIMSG_ClickInstallRemoveQuickSpellBtn = 88,
 
   UIMSG_OnTravelByFoot = 90,
-  UIMSG_5B = 91,
+  UIMSG_CHANGE_LOCATION_ClickCencelBtn = 91,
   UIMSG_ShowStatus_DateTime = 92,
   UIMSG_ShowStatus_ManaHP = 93,
   UIMSG_ShowStatus_Player = 94,
@@ -115,9 +115,9 @@
   UIMSG_SelectNPCDialogueOption = 136,
 
   UIMSG_CastSpell_GreatShot = 140,
-  UIMSG_CastSpell_8D = 141,
+  UIMSG_CastSpell_SPIRIT_Fate = 141,
   UIMSG_CastSpellFromBook = 142,
-  UIMSG_8F = 143,
+  UIMSG_CastSpell_8F = 143,
   UIMSG_PlayerCreation_VoicePrev = 144,
   UIMSG_PlayerCreation_VoiceNext = 145,
   UIMSG_92 = 146,
@@ -268,6 +268,7 @@
   WINDOW_SpellBook = 0x12,
   WINDOW_GreetingNPC = 19,
   WINDOW_Chest = 0x14,
+  WINDOW_22 = 0x16,
   WINDOW_SaveLoadButtons = 23,
   WINDOW_MainMenu_Load = 0x18,
   WINDOW_HouseInterior = 0x19,
@@ -386,7 +387,7 @@
   SCREEN_LOADGAME = 0xC,
   SCREEN_HOUSE = 0xD,
   SCREEN_E = 0xE,
-  SCREEN_F = 0xF,
+  SCREEN_CHEST_INVENTORY = 0xF,
   SCREEN_VIDEO = 0x10,
   SCREEN_CHANGE_LOCATION = 0x11,
   SCREEN_INPUT_BLV = 0x12,
--- a/Outdoor.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/Outdoor.cpp	Mon May 13 17:07:52 2013 +0200
@@ -127,19 +127,22 @@
 	{
 		pRenderer->DrawSkyD3D();
 		pRenderer->DrawBuildingsD3D();
-		pRenderer->RenderTerrainD3D();//pRenderer->DrawBezierTerrain();// Ritor1: temporarily lag
+		pRenderer->RenderTerrainD3D();
+		//pRenderer->DrawBezierTerrain();// Ritor1: temporarily lag
 	}
   }
   else if (pRenderer->pRenderD3D)
   {
     pRenderer->DrawSkyD3D();
     pRenderer->DrawBuildingsD3D();
-    pRenderer->RenderTerrainD3D();//pRenderer->DrawBezierTerrain();// Ritor1: temporarily lag
+    pRenderer->RenderTerrainD3D();
+    //pRenderer->DrawBezierTerrain();// Ritor1: temporarily lag
   }
   else
   {
 	pRenderer->DrawBuildingsSW();
-	pRenderer->RenderTerrainD3D();//pRenderer->DrawBezierTerrain();// Ritor1: temporarily lag
+	pRenderer->RenderTerrainD3D();
+	//pRenderer->DrawBezierTerrain();// Ritor1: temporarily lag
 	sr_sub_486F92_MessWithEdgesAndSpans();
 	pOutdoorCamera->_487355();
   }
--- a/Player.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/Player.cpp	Mon May 13 17:07:52 2013 +0200
@@ -7708,7 +7708,7 @@
                     goto LABEL_187;
                   /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                   {
-                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+                    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;
@@ -7797,7 +7797,7 @@
       && 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].eType = UIMSG_Escape;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;*/
--- a/Render.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/Render.cpp	Mon May 13 17:07:52 2013 +0200
@@ -874,8 +874,8 @@
   int v8; // eax@4
   unsigned int v9; // eax@6
   int v10; // eax@7
-  int v11; // ebx@9
-  int v12; // edi@9
+  //int v11; // ebx@9
+  //int v12; // edi@9
   int v13; // eax@21
   int v14; // eax@31
   int v15; // edi@33
@@ -885,9 +885,9 @@
   int v19; // eax@36
   int v20; // eax@39
   int v21; // ecx@43
-  char v22; // zf@44
+  //char v22; // zf@44
   int v23; // ecx@47
-  int v24; // edi@52
+  //int v24; // edi@52
   int v25; // eax@54
   int v26; // ecx@54
   int v27; // eax@56
@@ -932,34 +932,34 @@
   int v66; // edx@163
   int v67; // ecx@164
   int v68; // ecx@167
-  int v69; // eax@173
+  //int v69; // eax@173
   int v70; // edi@178
-  int v71; // eax@178
-  int v72; // ecx@178
-  int x; // ebx@180
-  int v74; // eax@182
+  //int v71; // eax@178
+  //int v72; // ecx@178
+  //int x; // ebx@180
+  //int v74; // eax@182
   int v75; // eax@184
   IndoorCameraD3D *pIndoorCameraD3D_3; // ecx@184
   int uStartZ; // ecx@184
   int v79; // ebx@185
   int v127; // esi@185
   int v86; // edi@196
-  int v87; // eax@196
-  int v88; // ecx@196
-  int v89; // eax@198
-  int v90; // ecx@200
+  //int v87; // eax@196
+  //int v88; // ecx@196
+  //int v89; // eax@198
+  //int v90; // ecx@200
   int v92; // ebx@203
-  int v93; // ST08_4@204
+  //int v93; // ST08_4@204
   int v97; // ST08_4@204
   float result; // eax@212
-  struct 
-  {
-  char v102[4]; // [sp+Ch] [bp-68h]@191
-  __int16 v103; // [sp+10h] [bp-64h]@190
-  __int16 v104; // [sp+12h] [bp-62h]@190
-  } v102;
+  //struct 
+  //{
+  int v106; // [sp+Ch] [bp-68h]@191
+  int v103; // [sp+10h] [bp-64h]@190
+  int v104; // [sp+12h] [bp-62h]@190
+  //} v102;
   int v105; // [sp+1Ch] [bp-58h]@1
-  int v106; // [sp+20h] [bp-54h]@3
+  int v107; // [sp+20h] [bp-54h]@3
   int uEndZ; // [sp+24h] [bp-50h]@3
   int v108; // [sp+28h] [bp-4Ch]@9
   int v109; // [sp+2Ch] [bp-48h]@9
@@ -970,7 +970,7 @@
   int v114; // [sp+40h] [bp-34h]@9
   int v115; // [sp+44h] [bp-30h]@9
   int v116; // [sp+48h] [bp-2Ch]@9
-  int v117; // [sp+4Ch] [bp-28h]@9
+  //int v117; // [sp+4Ch] [bp-28h]@9
   int v118; // [sp+50h] [bp-24h]@9
   int v119; // [sp+54h] [bp-20h]@1
   int v120; // [sp+58h] [bp-1Ch]@1
@@ -1014,8 +1014,8 @@
   else
     v10 = stru_5C6E00->pTanTable[v9];
   v108 = abs(v10);
-  v11 = v124;
-  v12 = v123;
+  //v11 = v124;
+  //v12 = v123;
   v114 = 0;
   v115 = 0;
   pIndoorCameraD3D_4 = 0;
@@ -1026,13 +1026,13 @@
   v109 = (uEndZ >= 0 ? 1: -1);//2 * (v107 >= 0) - 1;
   uEndZ = (v111 >= 0 ? 1: -1);//2 * (v111 >= 0) - 1;
   terrain_76E1C8[0] = 65535;
-  //v116 = 1;
+  uint _i = 1;
   v106 = (v6 >= 0 ? 1: -1);//2 * (v6 >= 0) - 1;
-  //v117 = 1;
+  uint j = 1;
   terrain_76E3C8[0] = 65535;
   terrain_76DDC8[0] = 65535;
   terrain_76DFC8[0] = 65535;
-  for( v116=1; v116 < 128; v116++)
+  for( _i = 1; _i < 128; _i++)
   {
     if ( v112 >= 0x10000 )
     {
@@ -1048,22 +1048,22 @@
     }
     else
     {
-      v11 += v110;
+      v124 += v110;
       v115 += v112;
       if ( v112 + v115 >= 65536 )
       {
-        v12 += v109;
+        v123 += v109;
         v115 = (unsigned __int16)v115;
       }
     }
-    if ( v11 < i || v11 > v120 || v12 < v122 || v12 > v119 )
+    if ( v124 < _i || v124 > v120 || v123 < v122 || v123 > v119 )
       break;
     //v13 = v116++;
-    terrain_76E3C8[v116] = v11;
-    terrain_76E1C8[v116] = v12;
-  }
-
-  for( v117=1; v117 < 128; v117++ )
+    terrain_76E3C8[_i] = v124;
+    terrain_76E1C8[_i] = v123;
+  }
+
+  for( j = 1; j < 128; j++ )
   {
     if ( v108 >= 65536 )
     {
@@ -1088,7 +1088,7 @@
     }
     //if ( v117 >= 128 )
       //break;
-    if ( v126 < i )
+    if ( v126 < _i )
       break;
     if ( v126 > v120 )
       break;
@@ -1097,27 +1097,27 @@
       break;
     if ( v118 > v119 )
       break;
-    terrain_76DFC8[v117] = v126;
-    terrain_76DDC8[v117] = v14;
+    terrain_76DFC8[j] = v126;
+    terrain_76DDC8[j] = v14;
   }
   v16 = 0;
   v126 = 0;
-  v17 = v117 - 1;
-  v18 = v116 - 1;
+  v17 = j - 1;
+  v18 = _i - 1;
   switch ( v105 )
   {
     case 0:
     case 7:
     {
-      v116 = terrain_76DFC8[v17];
-      if ( v120 > v116 )
+      //v116 = terrain_76DFC8[v17];
+      if ( v120 > terrain_76DFC8[v17] )
       {
         v125 = v120;
-        memset32(terrain_76D9C8, v119 + 1, 4 * (v120 - v116 + 1));
+        memset32(terrain_76D9C8, v119 + 1, 4 * (v120 - terrain_76DFC8[v17] + 1));
         v19 = v120;
         do
           terrain_76DBC8[v126++] = v19--;
-        while ( v19 >= v116 );
+        while ( v19 >= terrain_76DFC8[v17] );
         if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
         {
           do
@@ -1132,13 +1132,13 @@
       v21 = terrain_76DFC8[v17];
       while ( 1 )
       {
-        v125 = v21;
+        v125 = terrain_76DFC8[v17];
         if ( v21 < v124 )
           break;
         terrain_76DBC8[v16] = v21;
-        v22 = terrain_76DDC8[v17] == 65535;
+        //v22 = terrain_76DDC8[v17] == 65535;
         terrain_76D9C8[v16] = terrain_76DDC8[v17] + 1;
-        if ( v22 )
+        if ( terrain_76DDC8[v17] == 65535 )
         {
           terrain_76D9C8[v16] = v123 + 1;
           break;
@@ -1156,12 +1156,12 @@
         ++v16;
       }
       v16 = 0;
-      v24 = terrain_76E3C8[v18];
+      //v24 = terrain_76E3C8[v18];
       v126 = 0;
-      if ( v120 > v24 )
+      if ( v120 > terrain_76E3C8[v18] )
       {
         v125 = v120;
-        memset32(terrain_76D5C8, v122, 4 * (v120 - v24 + 1));
+        memset32(terrain_76D5C8, v122, 4 * (v120 - terrain_76E3C8[v18] + 1));
         do
         {
           v25 = v126;
@@ -1210,18 +1210,18 @@
     case 1:
     case 2:
     {
-      v116 = terrain_76DDC8[v17];
-      if ( v122 < v116 )
+      //v116 = terrain_76DDC8[v17];
+      if ( v122 < terrain_76DDC8[v17] )
       {
         v106 = v122;
-        memset32(terrain_76DBC8, v120 + 1, 4 * (v116 - v122 + 1));
+        memset32(terrain_76DBC8, v120 + 1, 4 * (terrain_76DDC8[v17] - v122 + 1));
         v32 = v122;
         do
         {
           v33 = v126++;
           terrain_76D9C8[v33] = v32++;
         }
-        while ( v32 <= v116 );
+        while ( v32 <= terrain_76DDC8[v17] );
         if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 -1] )
         {
           do
@@ -1237,10 +1237,10 @@
       v125 = terrain_76DDC8[v17];
       while ( v35 <= v123 )
       {
-        v22 = terrain_76DFC8[v17] == 65535;
+        //v22 = terrain_76DFC8[v17] == 65535;
         terrain_76DBC8[v16] = terrain_76DFC8[v17] + 1;
         terrain_76D9C8[v16] = v125;
-        if ( v22 )
+        if ( terrain_76DFC8[v17] == 65535 )
         {
           terrain_76DBC8[v16] = v124 + 1;
           break;
@@ -1313,15 +1313,15 @@
     case 5:
     case 6:
     {
-      v116 = terrain_76DDC8[v17];
-      if ( v119 > v116 )
+      //v116 = terrain_76DDC8[v17];
+      if ( v119 > terrain_76DDC8[v17] )
       {
         v106 = v119;
-        memset32(terrain_76DBC8, i, 4 * (v119 - v116 + 1));
+        memset32(terrain_76DBC8, i, 4 * (v119 - terrain_76DDC8[v17] + 1));
         v45 = v119;
         do
           terrain_76D9C8[v126++] = v45--;
-        while ( v45 >= v116 );
+        while ( v45 >= terrain_76DDC8[v17] );
         if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 -1] )
         {
           do
@@ -1337,10 +1337,10 @@
       v125 = terrain_76DDC8[v17];
       while ( v47 >= v123 )
       {
-        v22 = terrain_76DFC8[v17] == 65535;
+        //v22 = terrain_76DFC8[v17] == 65535;
         terrain_76DBC8[v16] = terrain_76DFC8[v17];
         terrain_76D9C8[v16] = v125;
-        if ( v22 )
+        if ( terrain_76DFC8[v17] == 65535 )
         {
           terrain_76DBC8[v16] = v124;
           break;
@@ -1412,18 +1412,18 @@
     case 3:
     case 4:
     {
-      v116 = terrain_76DFC8[v17];
-      if ( i < v116 )
+      //v116 = terrain_76DFC8[v17];
+      if ( i < terrain_76DFC8[v17] )
       {
         v106 = i;
-        memset32(terrain_76D9C8, v122, 4 * (v116 - i + 1));
+        memset32(terrain_76D9C8, v122, 4 * (terrain_76DFC8[v17] - i + 1));
         v56 = i;
         do
         {
           v57 = v126++;
           terrain_76DBC8[v57] = v56++;
         }
-        while ( v56 <= v116 );
+        while ( v56 <= terrain_76DFC8[v17] );
         if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 -1] )
         {
           do
@@ -1494,7 +1494,7 @@
         v67 = terrain_76E1C8[v18];
         terrain_76D7C8[v16] = v66;
         terrain_76D5C8[v16] = v67 + 1;
-        if ( v67 == 65535 )
+        if ( terrain_76E1C8[v18] == 65535 )
         {
           v31 = v123 + 1;
           terrain_76D5C8[v16] = v31;
@@ -1517,35 +1517,36 @@
     default:
       break;
   }
-  v69 = v16 - 1;
+  //v69 = v16 - 1;
   ptr_801A08 = pVerticesSR_806210;
   ptr_801A04 = pVerticesSR_801A10;
-  v126 = v69;
+  //v126 = v69;
+
   if ( v105 && v105 != 7 && v105 != 3 && v105 != 4 )//блок
   {
-    for ( i = v69; i >= 1; --i )
+    for ( i = v16 - 1; i >= 1; --i )
     {
       //v70 = i;
-      v71 = terrain_76D7C8[i];//88
-      v72 = terrain_76DBC8[i];//0
-      if ( v71 < v72 )//swap
-      {
-        terrain_76DBC8[i] = v71;
-        terrain_76D7C8[i] = v72;
-      }
-      x = terrain_76DBC8[i];//0
+      //v71 = terrain_76D7C8[i];//88
+      //v72 = terrain_76DBC8[i];//0
+      if ( terrain_76D7C8[i] < terrain_76DBC8[i] )//swap
+      {
+        terrain_76DBC8[i] = terrain_76D7C8[i];
+        terrain_76D7C8[i] = terrain_76DBC8[i];
+      }
+      //x = terrain_76DBC8[i];//0
       v111 = 0;
-      if ( x <= 0 )
-        x = -x;
-      v74 = terrain_76D7C8[i];
-      if ( v74 <= 0 )
-        v74 = -v74;
-      v75 = v74 + 2;
+      if ( terrain_76DBC8[i] <= 0 )
+        terrain_76DBC8[i] = -terrain_76DBC8[i];
+      //v74 = terrain_76D7C8[i];
+      if ( terrain_76D7C8[i] <= 0 )
+        terrain_76D7C8[i] = -terrain_76D7C8[i];
+      v75 = terrain_76D7C8[i] + 2;
       //pIndoorCameraD3D_3 = pGame->pIndoorCameraD3D;
       uEndZ = v75;
       //pIndoorCameraD3D_4 = pIndoorCameraD3D_3;
-      uStartZ = x - 2;
-      if ( x - 2 < v75 )
+      uStartZ = terrain_76DBC8[i] - 2;
+      if ( terrain_76DBC8[i] - 2 < v75 )
       {
         v127 = 0;
         //v79 = (v73 - 66) << 9;
@@ -1554,10 +1555,10 @@
         v111 = v75 - uStartZ;
         for (int z = uStartZ; z < uEndZ; ++z)
         {
-          ptr_801A08[v127].vWorldPosition.x = (-64 + x) * 512;//pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * 512;
+          ptr_801A08[v127].vWorldPosition.x = (-64 + terrain_76DBC8[i]) * 512;//pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * 512;
           ptr_801A08[v127].vWorldPosition.y = (64 - terrain_76D9C8[i]) * 512;
           ptr_801A08[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i]);
-          ptr_801A04[v127].vWorldPosition.x = (-64 + x) * 512;
+          ptr_801A04[v127].vWorldPosition.x = (-64 + terrain_76DBC8[i]) * 512;
           ptr_801A04[v127].vWorldPosition.y = (63 - terrain_76D9C8[i]) * 512;
           ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i] + 1);
           if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
@@ -1574,57 +1575,58 @@
        }
         //while ( v116 < v107 );
       }
-      v102.v103 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[i]);
-      v102.v104 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[i]);
+      v103 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[i]);
+      v104 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[i]);
       if ( pRenderer->pRenderD3D )//Ritor1: do comment to test
-        Render::RenderTerrainD3D();//Render::DrawTerrainD3D(v111, 0, (int)&v102);
+        Render::DrawTerrainD3D(v111, 0, v103, v104);//Render::RenderTerrainD3D();
       else
-        Render::DrawTerrainSW(v111, 0, (int)&v102);
-    }
-  }
-/*  else
-  {
-    for ( i = v69; i >= 1; --i )
-    {
-      v86 = i;
-      v87 = terrain_76D5C8[i];
-      v88 = terrain_76D9C8[i];
-      if ( v87 < v88 )
-      {
-        terrain_76D9C8[v86] = v87;
-        terrain_76D5C8[v86] = v88;
-      }
-      v89 = terrain_76D9C8[v86];
+        Render::DrawTerrainSW(v111, 0, v103, v104);
+    }
+  }
+  else
+  {
+    for ( i = v16 - 1; i >= 1; --i )
+    {
+      //v86 = i;
+      //v87 = terrain_76D5C8[i];
+      //v88 = terrain_76D9C8[i];
+      if ( terrain_76D5C8[i] < terrain_76D9C8[i] )
+      {
+        terrain_76D9C8[i] = terrain_76D5C8[i];
+        terrain_76D5C8[i] = terrain_76D9C8[i];
+      }
+      //v89 = terrain_76D9C8[i];
       v111 = 0;
-      if ( v89 <= 0 )
-        v89 = -v89;
-      v90 = terrain_76D5C8[v86];
-      if ( v90 <= 0 )
-        v90 = -v90;
+      if ( terrain_76D9C8[i] <= 0 )
+        terrain_76D9C8[i] = -terrain_76D9C8[i];
+      //v90 = terrain_76D5C8[i];
+      if ( terrain_76D5C8[i] <= 0 )
+        terrain_76D5C8[i] = -terrain_76D5C8[i];
       pIndoorCameraD3D_4 = pGame->pIndoorCameraD3D;
-      v107 = v90 + 2;
-      if ( v89 - 2 < v90 + 2 )
+      v107 = terrain_76D5C8[i] + 2;
+      if ( terrain_76D9C8[i] - 2 < terrain_76D5C8[i] + 2 )
       {
         v86 = 0;
-        v116 = v89 - 2;
-        v92 = (66 - v89) << 9;
-        pHeight = (66 - v89) << 9;
-        v111 = v90 + 2 - (v89 - 2);
-        do
-        {
-          v93 = v116;
-          v106 = (*(int *)((char *)terrain_76DBC8 + v86) - 64) << 9;
-          *(float *)((char *)&ptr_801A08->vWorldPosition.x + v86) = (double)v106;
-          *(float *)&pHeight = (double)pHeight;
-          *(float *)((char *)&ptr_801A08->vWorldPosition.y + v86) = *(float *)&pHeight;
-          v106 = pOutdoor->GetHeightOnTerrain(*(int *)((char *)terrain_76DBC8 + v86), v93);
-          v97 = v116;
-          *(float *)((char *)&ptr_801A08->vWorldPosition.z + v86) = (double)v106;
-          v106 = (*(int *)((char *)terrain_76DBC8 + v86) - 63) << 9;
-          *(float *)((char *)&ptr_801A04->vWorldPosition.x + v86) = (double)v106;
-          *(float *)((char *)&ptr_801A04->vWorldPosition.y + v86) = *(float *)&pHeight;
-          pHeight = pOutdoor->GetHeightOnTerrain(*(int *)((char *)terrain_76DBC8 + v86) + 1, v97);
-          *(float *)((char *)&ptr_801A04->vWorldPosition.z + v86) = (double)pHeight;
+        //v116 = terrain_76D9C8[i] - 2;
+        v92 = (66 - terrain_76D9C8[i]) << 9;
+        //pHeight = (66 - terrain_76D9C8[i]) << 9;
+        v111 = terrain_76D5C8[i] + 2 - (terrain_76D9C8[i] - 2);
+        //do
+        for ( v116 = terrain_76D9C8[i] - 2; v116 < v107; ++v116 )
+        {
+          //v93 = v116;
+          //v106 = (*(int *)((char *)terrain_76DBC8 + v86) - 64) << 9;
+          ptr_801A08[v86].vWorldPosition.x = terrain_76DBC8[v86] - 64 << 9;
+          //*(float *)&pHeight = (double)pHeight;
+          ptr_801A08[v86].vWorldPosition.y = v92;
+          //v106 = ;
+          //v97 = v116;
+          ptr_801A08[v86].vWorldPosition.z = pOutdoor->GetHeightOnTerrain(terrain_76DBC8[v86], v116);
+          //v106 = (*(int *)((char *)terrain_76DBC8 + v86) - 63) << 9;
+          ptr_801A04[v86].vWorldPosition.x = terrain_76DBC8[v86] - 63 << 9;
+          ptr_801A04[v86].vWorldPosition.y = v92;
+          //pHeight = pOutdoor->GetHeightOnTerrain(*(int *)((char *)terrain_76DBC8 + v86) + 1, v97);
+          ptr_801A04[v86].vWorldPosition.z = pOutdoor->GetHeightOnTerrain(terrain_76DBC8[v86] + 1, v116);
           if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
           {
            pIndoorCameraD3D_4->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1);
@@ -1634,19 +1636,19 @@
           }
           v92 -= 512;
           v86 += 48;
-          ++v116;
-          pHeight = v92;
-		}
-        while ( v116 < v107 );
+          //++v116;
+          //pHeight = v92;
+        }
+        //while ( v116 < v107 );
       }
       v103 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[v86]);
 	  v104 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[v86]);
 	  if ( pRenderer->pRenderD3D )
-        Render::DrawTerrainD3D(v111, 1, (int)&v102);
+        Render::DrawTerrainD3D(v111, 1, v103, v104);
       else
-        Render::DrawTerrainSW(v111, 1, (int)&v102);
-    }
-  }*/
+        Render::DrawTerrainSW(v111, 1, v103, v104);
+    }
+  }
   result = v126;
   pOutdoorCamera->field_40 = v126;
   return result;
@@ -1654,6 +1656,7 @@
 // 47FFC4: inconsistent fpu stack
 // 4D864C: using guessed type char byte_4D864C;
 
+
 void Render::RenderTerrainD3D() // New function. It's temporary
 {
   char result; // al@3
@@ -1838,9 +1841,9 @@
 }
 
 //----- (0048034E) --------------------------------------------------------
-void Render::DrawTerrainD3D(int a1, int a2, int a3)
-{
-  int v3; // esi@1
+void Render::DrawTerrainD3D(int a1, int a2, int a3, int unk4)
+{
+  //int v3; // esi@1
   int v4; // edi@1
   int v5; // ebx@2
   int v6; // eax@2
@@ -1914,10 +1917,10 @@
   unsigned int v73; // eax@150
   int v74; // eax@154
   unsigned int v75; // eax@158
-  unsigned int v76; // [sp-10h] [bp-E0h]@61
+  //unsigned int v76; // [sp-10h] [bp-E0h]@61
   int v77; // [sp-Ch] [bp-DCh]@61
   IDirect3DTexture2 *v78; // [sp-8h] [bp-D8h]@61
-  int v79; // [sp-4h] [bp-D4h]@61
+  //int v79; // [sp-4h] [bp-D4h]@61
   int v80; // [sp+0h] [bp-D0h]@59
   int v81; // [sp+0h] [bp-D0h]@109
   int v82; // [sp+54h] [bp-7Ch]@1
@@ -1961,24 +1964,24 @@
 
   static stru154 static_sub_0048034E_stru_154;
   static stru154 stru_76D5A8;
-  v3 = a1;
+  //v3 = a1;
   v82 = a2;
-  v83 = *(/*short **/_WORD *)(a3 + 4);
-  X = abs(*(/*short **/_WORD *)(a3 + 6));
+  v83 = a3;
+  X = abs(unk4);
   v4 = 0;
   v88 = 0;
-  v84 = v3 - 1;
+  v84 = a1 - 1;
   v90 = (float)pOutdoor->vSunlight.x / 65536.0;
   v91 = (float)pOutdoor->vSunlight.y / 65536.0;
   v92 = (float)pOutdoor->vSunlight.z / 65536.0;
-  if ( v3 - 1 > 0 )
+  if ( a1 - 1 > 0 )
   {
     while ( 1 )
     {
       v5 = abs(X);//v5 = 13108
       v6 = abs(v83);//v6 = 13108
       --X;
-      __debugbreak(); // uncoment & refactor following large if
+      //__debugbreak(); // uncoment & refactor following large if
       v93 = (int)&stru_76E5C8[(v5 << 7) + v6];
       /*if ( !v93->field_0 || ((v7 = 48 * v4, v8 = &pVerticesSR_806210[v4], a2 = v8, !v82) ? (v9 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7),
                                                                        v10 = &pVerticesSR_806210[1] + v7) : (v9 = &pVerticesSR_806210[1] + v7, v10 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7)),
@@ -2411,12 +2414,12 @@
               v80 = true;
             }
             //v79 = 0;
-            //v78 = pBitmaps_LOD->pHardwareTextures[v75];
+            v78 = pBitmaps_LOD->pHardwareTextures[v75];
             v71->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[v75];// Ritor1: It's temporary
             //v77 = (int)v71;
             //v76 = v71->uNumVertices;
             //goto LABEL_161;
-            pRenderer->DrawTerrainPolygon(v76, (stru148 *)v71, v78, v79, v80);
+            pRenderer->DrawTerrainPolygon(v71->uNumVertices, (stru148 *)v71, v78, 0, v80);
             goto LABEL_162;
           }
           v38 = (stru148 *)v71;
@@ -2435,7 +2438,7 @@
 // 76D5C0: using guessed type char static_sub_0048034E_byte_76D5C0__init_flag;
 
 //----- (00481212) --------------------------------------------------------
-void Render::DrawTerrainSW(int a1, int a2, int a3)
+void Render::DrawTerrainSW(int a1, int a2, int a3, int a4)
 {
   int v3; // esi@1
   int v4; // ecx@1
@@ -2549,8 +2552,8 @@
   //v4 = *(short *)(a3 + 4);
   //v5 = *(short *)(a3 + 6);
   v85 = a2;
-  v86 = *(_WORD *)(a3 + 4); //v4;
-  X = abs(*(_WORD *)(a3 + 6)); //v5
+  v86 = a3; //v4;
+  X = abs(a4); //v5
   v6 = 0;
   v90 = 0;
   v81 = v3 - 1;
--- a/Render.h	Mon May 13 17:01:20 2013 +0200
+++ b/Render.h	Mon May 13 17:07:52 2013 +0200
@@ -365,8 +365,8 @@
   void TransformBillboardsAndSetPalettesODM();
   float DrawBezierTerrain();
   void RenderTerrainD3D();
-  void DrawTerrainD3D(int a1, int edx0, int a3);
-  void DrawTerrainSW(int a1, int a2, int a3);
+  void DrawTerrainD3D(int a1, int edx0, int a3, int unk4);
+  void DrawTerrainSW(int a1, int a2, int a3, int a4);
   void ExecOutdoorDrawSW();
   void ChangeBetweenWinFullscreenModes();
   void DrawBillboardList_BLV();
--- a/UIBooks.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/UIBooks.cpp	Mon May 13 17:07:52 2013 +0200
@@ -396,7 +396,7 @@
   GUIWindow a1; // [sp+8h] [bp-54h]@10
 
   pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pSpellBookPagesTextr_11);
-  if ( dword_506548 || !dword_506528 )
+  if ( BtnUp_flag || !dword_506528 )
   {
     v13 = pTex_tab_an_6a__zoom_off;
     v11 = pViewport->uViewportTL_Y + 2;
@@ -409,7 +409,7 @@
     v0 = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(v0, v11, v13);
-  if ( dword_506544 || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
+  if ( BtnDown_flag || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
   {
     v14 = pTex_tab_an_7a__zoot_off;
     v12 = pViewport->uViewportTL_Y + 38;
@@ -443,14 +443,14 @@
   a1.uFrameZ = 407;
   a1.uFrameHeight = v4 * 264 / v4;
   a1.uFrameW = a1.uFrameHeight + 69;
-  if ( dword_506544 && dword_506528 + num_achieved_awards < num_achieved_awards_2 )
+  if ( BtnDown_flag && dword_506528 + num_achieved_awards < num_achieved_awards_2 )
   {
     pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     v5 = dword_50651C++;
     dword_506528 += num_achieved_awards;
     byte_506130[v5] = num_achieved_awards;
   }
-  if ( dword_506548 && dword_50651C )
+  if ( BtnUp_flag && dword_50651C )
   {
     pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     --dword_50651C;
@@ -461,9 +461,9 @@
     dword_506528 = 0;
     dword_50651C = 0;
   }
-  dword_506544 = 0;
+  BtnDown_flag = 0;
   v6 = achieved_awards[dword_506528];
-  dword_506548 = 0;
+  BtnUp_flag = 0;
   num_achieved_awards = 0;
   //v7 = *pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
   v7 = (int)pStorylineText->StoreLine[v6].pText;//*(&pStorylineText->field_0 + 3 * v6);
@@ -502,7 +502,7 @@
   GUIWindow a1; // [sp+Ch] [bp-54h]@9
 
   pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_CurrentBook);
-  if ( dword_506548 || !dword_506528 )
+  if ( BtnUp_flag || !dword_506528 )
   {
     v10 = pTex_tab_an_6a__zoom_off;
     v8 = pViewport->uViewportTL_Y + 2;
@@ -515,7 +515,7 @@
     v0 = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(v0, v8, v10);
-  if ( dword_506544 || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
+  if ( BtnDown_flag || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
   {
     v11 = pTex_tab_an_7a__zoot_off;
     v9 = pViewport->uViewportTL_Y + 38;
@@ -541,14 +541,14 @@
   a1.uFrameHeight = 264;
   a1.uFrameZ = 407;
   a1.uFrameW = 333;
-  if ( dword_506544 && dword_506528 + num_achieved_awards < num_achieved_awards_2 )
+  if ( BtnDown_flag && dword_506528 + num_achieved_awards < num_achieved_awards_2 )
   {
     pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     v2 = dword_50651C++;
     dword_506528 += num_achieved_awards;
     byte_506130[v2] = num_achieved_awards;
   }
-  if ( dword_506548 && dword_50651C )
+  if ( BtnUp_flag && dword_50651C )
   {
     pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
     --dword_50651C;
@@ -560,8 +560,8 @@
     dword_50651C = 0;
     dword_506528 = 0;
   }
-  dword_506544 = 0;
-  dword_506548 = 0;
+  BtnDown_flag = 0;
+  BtnUp_flag = 0;
   num_achieved_awards = 0;
   while ( v3 < num_achieved_awards_2 )
   {
@@ -620,7 +620,7 @@
 
   v31 = 0;
   pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_AutonotesBook);
-  if ( dword_506548 || !dword_506528 )
+  if ( BtnUp_flag || !dword_506528 )
   {
     v24 = pTex_tab_an_6a__zoom_off;
     v17 = pViewport->uViewportTL_Y + 2;
@@ -633,7 +633,7 @@
     v0 = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(v0, v17, v24);
-  if ( dword_506544 || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
+  if ( BtnDown_flag || dword_506528 + num_achieved_awards >= num_achieved_awards_2 )
   {
     v25 = pTex_tab_an_7a__zoot_off;
     v18 = pViewport->uViewportTL_Y + 38;
@@ -646,7 +646,7 @@
     v1 = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(v1, v18, v25);
-  if ( !dword_506540 )
+  if ( !Book_PageBtn3_flag )//Potions_page_flag
   {
     if (_506568_autonote_type != AUTONOTE_POTION_RECEPIE)
     {
@@ -672,7 +672,7 @@
   _506568_autonote_type = AUTONOTE_POTION_RECEPIE;
   pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTexture_506394);
 LABEL_16:
-  if ( dword_50653C )
+  if ( Book_PageBtn4_flag )//Fontains_page_flag
   {
     if ( _506568_autonote_type != v2 )
     {
@@ -696,7 +696,7 @@
   v3 = pViewport->uViewportTL_X + 399;
 LABEL_22:
   pRenderer->DrawTextureTransparent(v3, v19, v26);
-  if ( dword_506538 )
+  if ( Book_PageBtn5_flag )//Autonotes_Obelisks_page_flag
   {
     if ( _506568_autonote_type != AUTONOTE_OBELISK)
     {
@@ -720,7 +720,7 @@
   v4 = pViewport->uViewportTL_X + 397;
 LABEL_28:
   pRenderer->DrawTextureTransparent(v4, v20, v27);
-  if ( dword_506534 )
+  if ( Book_PageBtn6_flag )//Autonotes_Seer_page_flag
   {
     if ( _506568_autonote_type != AUTONOTE_SEER)
     {
@@ -744,7 +744,7 @@
   v5 = pViewport->uViewportTL_X + 397;
 LABEL_34:
   pRenderer->DrawTextureTransparent(v5, v21, v28);
-  if ( dword_506530 )
+  if ( Autonotes_Misc_page_flag )
   {
     if ( _506568_autonote_type != AUTONOTE_MISC)
     {
@@ -768,7 +768,7 @@
   v6 = pViewport->uViewportTL_X + 397;
 LABEL_40:
   pRenderer->DrawTextureTransparent(v6, v22, v29);
-  if ( dword_50652C )
+  if ( Autonotes_Instructors_page_flag )
   {
     if ( _506568_autonote_type != AUTONOTE_TEACHER)
     {
@@ -835,7 +835,7 @@
   }
   else
   {
-    if ( dword_506544 )
+    if ( BtnDown_flag )
     {
       v10 = num_achieved_awards + dword_506528;
       if ( num_achieved_awards + dword_506528 < num_achieved_awards_2 )
@@ -846,7 +846,7 @@
         pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
       }
     }
-    if ( dword_506548 && dword_50651C )
+    if ( BtnUp_flag && dword_50651C )
     {
       --dword_50651C;
       dword_506528 -= (unsigned __int8)byte_506130[dword_50651C];
@@ -859,15 +859,15 @@
     }
   }
   v12 = dword_506528;
-  dword_50652C = 0;
-  dword_506544 = 0;
-  dword_506548 = 0;
+  Autonotes_Instructors_page_flag = 0;
+  BtnDown_flag = 0;
+  BtnUp_flag = 0;
   num_achieved_awards = 0;
-  dword_506530 = 0;
-  dword_506534 = 0;
-  dword_506538 = 0;
-  dword_50653C = 0;
-  dword_506540 = 0;
+  Autonotes_Misc_page_flag = 0;
+  Book_PageBtn6_flag = 0;//Autonotes_Seer_page_flag
+  Book_PageBtn5_flag = 0;//Autonotes_Obelisks_page_flag
+  Book_PageBtn4_flag = 0;//Fontains_page_flag
+  Book_PageBtn3_flag = 0;//Potions_page_flag
   while ( v12 < num_achieved_awards_2 )
   {
     v13 = achieved_awards[v12];
@@ -899,7 +899,7 @@
   unsigned int textrX, textrY;
 
   pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pSpellBookPagesTextr_12);
-  if ( dword_506548 || viewparams->field_2C / 128 >= 12 )
+  if ( BtnUp_flag || viewparams->field_2C / 128 >= 12 )
   {
     buttnTxtr = pTex_tab_an_6a__zoom_off;
     textrY = pViewport->uViewportTL_Y + 2;
@@ -912,7 +912,7 @@
     textrX = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(textrX, textrY, buttnTxtr);
-  if ( dword_506544 || viewparams->field_2C / 128 <= 3 )
+  if ( BtnDown_flag || viewparams->field_2C / 128 <= 3 )
   {
     buttnTxtr = pTex_tab_an_7a__zoot_off;
     textrY = pViewport->uViewportTL_Y + 38;
@@ -925,7 +925,7 @@
     textrX = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(textrX, textrY, buttnTxtr);
-  if ( dword_506540 )
+  if ( Book_PageBtn3_flag )
   {
     buttnTxtr = pTexture_506390;
     textrY = pViewport->uViewportTL_Y + 113;
@@ -938,7 +938,7 @@
     textrX = pViewport->uViewportTL_X + 398;
   }
   pRenderer->DrawTextureTransparent(textrX, textrY, buttnTxtr);
-  if ( dword_50653C )
+  if ( Book_PageBtn4_flag )
   {
     buttnTxtr = pTexture_506388;
     textrY = pViewport->uViewportTL_X + 150;
@@ -951,7 +951,7 @@
     textrX = pViewport->uViewportTL_Y + 399;
   }
   pRenderer->DrawTextureTransparent(textrX, textrY, buttnTxtr);
-  if ( dword_506538 )
+  if ( Book_PageBtn5_flag )
   {
     buttnTxtr = pTexture_506380;
     textrY = pViewport->uViewportTL_Y + 188;
@@ -964,7 +964,7 @@
     textrX = pViewport->uViewportTL_X + 397;
   }
   pRenderer->DrawTextureTransparent(textrX, textrY, buttnTxtr);
-  if ( dword_506534 )
+  if ( Book_PageBtn6_flag )
   {
     buttnTxtr = pTexture_506378;
     textrY = pViewport->uViewportTL_Y + 226;
@@ -977,27 +977,27 @@
     textrX = pViewport->uViewportTL_X + 397;
   }
   pRenderer->DrawTextureTransparent(textrX, textrY, buttnTxtr);
-  if ( dword_506544 )
+  if ( BtnDown_flag )
     viewparams->CenterOnParty2();
-  if ( dword_506548 )
+  if ( BtnUp_flag )
     viewparams->CenterOnParty();
-  if ( dword_506540 )
+  if ( Book_PageBtn3_flag )
     viewparams->_443219();
-  if ( dword_50653C )
+  if ( Book_PageBtn4_flag )
     viewparams->_443231();
-  if ( dword_506538 )
+  if ( Book_PageBtn5_flag )
     viewparams->_44323D();
-  if ( dword_506534 )
+  if ( Book_PageBtn6_flag )
     viewparams->_443225();
 
-  if ( dword_506548 | dword_506544 | dword_506540 | dword_50653C | dword_506538 | dword_506534 )
+  if ( BtnUp_flag | BtnDown_flag | Book_PageBtn3_flag | Book_PageBtn4_flag | Book_PageBtn5_flag | Book_PageBtn6_flag )
     pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
-  dword_506548 = 0;
-  dword_506544 = 0;
-  dword_506534 = 0;
-  dword_506538 = 0;
-  dword_50653C = 0;
-  dword_506540 = 0;
+  BtnUp_flag = 0;
+  BtnDown_flag = 0;
+  Book_PageBtn6_flag = 0;
+  Book_PageBtn5_flag = 0;
+  Book_PageBtn4_flag = 0;
+  Book_PageBtn3_flag = 0;
   DrawBook_Map_sub(97, 49, 361, 313, 0);
   pRenderer->DrawTextureTransparent(75, 22, pTexture_mapbordr);
   map_window.uFrameWidth = game_viewport_width;
--- a/UICharacter.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/UICharacter.cpp	Mon May 13 17:07:52 2013 +0200
@@ -231,9 +231,9 @@
   a1.uFrameHeight = 290;
   a1.uFrameZ = 435;
   a1.uFrameW = 337;
-  if (dword_506544 && num_achieved_awards + dword_506528 < num_achieved_awards_2)
+  if (BtnDown_flag && num_achieved_awards + dword_506528 < num_achieved_awards_2)
     result = dword_506528++ + 1;
-  if (dword_506548 && result)
+  if (BtnUp_flag && result)
   {
     --result;
     dword_506528 = result;
@@ -260,8 +260,8 @@
             }
         }
     //LABEL_14:
-    dword_506544 = 0;
-    dword_506548 = 0;
+    BtnDown_flag = 0;
+    BtnUp_flag = 0;
     num_achieved_awards = 0;
     dword_50651C = 0;
 
@@ -2173,8 +2173,8 @@
         num_achieved_awards = 0;
 
         memset(pTmpBuf2, 0, 0x7D0u);
-        dword_506544 = 0;
-        dword_506548 = 0;
+        BtnDown_flag = 0;
+        BtnUp_flag = 0;
         dword_50651C = 0;
         dword_506528 = 0;
         for (int i = 0; i < 105; ++i)
--- a/UIHouses.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/UIHouses.cpp	Mon May 13 17:07:52 2013 +0200
@@ -1335,7 +1335,7 @@
     {
       /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
       {
-        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)29;
+        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_PlayArcomage;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v1;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = v1;
         ++pMessageQueue_50CBD0->uNumMessages;
@@ -2140,7 +2140,7 @@
 				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].eType = UIMSG_Escape;
 				pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
 				*(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
 				++pMessageQueue_50CBD0->uNumMessages;
@@ -2236,7 +2236,7 @@
 					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].eType = UIMSG_Escape;
 						pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
 						*(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
 						++pMessageQueue_50CBD0->uNumMessages;
@@ -5377,7 +5377,7 @@
           /*result = pMessageQueue_50CBD0->uNumMessages;
           if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
-            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
             *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
--- a/UIPopup.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/UIPopup.cpp	Mon May 13 17:07:52 2013 +0200
@@ -1735,7 +1735,7 @@
         sub_4179BC_draw_tooltip(pGlobalTXT_LocalizationStrings[207], pSkillPointsAttributeDescription);
       break;
     case 26:
-      __debugbreak;
+      __debugbreak();
       //_y = (Player *)(4 * pPlayers[uActiveCharacter]->classType);
       //v24 = *(char **)((char *)_y->pConditions + (int)pClassNames);
       //v7 = *(char **)((char *)_y->pConditions + (int)pClassDescriptions);
@@ -1848,7 +1848,7 @@
         ItemGen *v8; // ecx@70
         unsigned int v9; // eax@72
         unsigned int v10; // eax@76
-        char v11; // zf@83
+        //char v11; // zf@83
         GUIButton *pButton; // esi@84
         unsigned int v13; // ecx@85
         char *pStr; // edi@85
@@ -2079,7 +2079,7 @@
             }
         case SCREEN_CHARACTERS:
         case SCREEN_E:
-        case SCREEN_F:
+        case SCREEN_CHEST_INVENTORY:
             {
             if ( (signed int)pX > 467 && pCurrentScreen != SCREEN_E )
                 {
@@ -2096,11 +2096,10 @@
                 CharacterUI_SkillsTab_ShowHint();
                 }
             else
-                {
-                v11 = pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103;//2DEvent - CharacerScreenInventory
-                if ( v11 )
-                    identify_item();
-                }
+              {
+                if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103 )//2DEvent - CharacerScreenInventory
+                  identify_item();
+              }
             break;
             }
         case SCREEN_SPELL_BOOK:
--- a/UISaveLoad.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/UISaveLoad.cpp	Mon May 13 17:07:52 2013 +0200
@@ -184,7 +184,7 @@
     strcpy((char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot, (const char *)pKeyActionMap->pPressedKeysBuffer);
     /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)83;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_SaveGame;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
--- a/UiGame.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/UiGame.cpp	Mon May 13 17:07:52 2013 +0200
@@ -2061,7 +2061,7 @@
         || pCurrentScreen == SCREEN_CHEST
         || pCurrentScreen == SCREEN_SAVEGAME
         || pCurrentScreen == SCREEN_LOADGAME
-        || pCurrentScreen == SCREEN_F
+        || pCurrentScreen == SCREEN_CHEST_INVENTORY
         || pCurrentScreen == SCREEN_BOOKS
         || pCurrentScreen == SCREEN_BRANCHLESS_NPC_DIALOG )
         {
--- a/mm7_1.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_1.cpp	Mon May 13 17:07:52 2013 +0200
@@ -625,7 +625,7 @@
 }
 
 //----- (00420E01) --------------------------------------------------------
-void __cdecl sub_420E01()
+void __cdecl OnChestLeftClick()
 {
   int chest_id; // edi@1
   POINT *v1; // esi@2
@@ -850,7 +850,7 @@
     if ( uActiveCharacter == uPlayerID )
     {
       pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-      pCurrentScreen = SCREEN_F;
+      pCurrentScreen = SCREEN_CHEST_INVENTORY;
       //goto LABEL_28;
       uActiveCharacter = uPlayerID;
       return;
@@ -870,7 +870,7 @@
       uActiveCharacter = uPlayerID;
       return;
     }
-    if ( pCurrentScreen != SCREEN_F )
+    if ( pCurrentScreen != SCREEN_CHEST_INVENTORY )
     {
       viewparams->bRedrawGameUI = true;
       uActiveCharacter = uPlayerID;
@@ -883,7 +883,7 @@
     if ( uActiveCharacter == uPlayerID )
     {
       pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-      pCurrentScreen = SCREEN_F;
+      pCurrentScreen = SCREEN_CHEST_INVENTORY;
       //goto LABEL_28;
       uActiveCharacter = uPlayerID;
       return;
@@ -916,7 +916,7 @@
 // F8B19C: using guessed type int dword_F8B19C;
 
 //----- (00421EA6) --------------------------------------------------------
-void __cdecl sub_421EA6_OnInventoryLeftClick()
+void __cdecl OnInventoryLeftClick()
 {
   Player *v0; // ebx@1
   signed int v1; // eax@2
@@ -1254,7 +1254,7 @@
       }
       /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
         return;
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)161;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_StartNPCDialogue;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v18;
 LABEL_42:
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
@@ -1270,7 +1270,7 @@
     }
     /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)23;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Attack;
       goto LABEL_41;
     }*/
     pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
@@ -1287,7 +1287,7 @@
     {
       pMessageQueue_50CBD0->AddMessage(UIMSG_CastQuickSpell, 0, 0);
       /*&& (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)25;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_CastQuickSpell;
 LABEL_41:
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
       goto LABEL_42;*/
--- a/mm7_2.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_2.cpp	Mon May 13 17:07:52 2013 +0200
@@ -96,7 +96,7 @@
         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].eType = UIMSG_Escape;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
           ++pMessageQueue_50CBD0->uNumMessages;
@@ -595,7 +595,7 @@
   pParty->uFallSpeed = 0;
   /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
   {
-    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
     ++pMessageQueue_50CBD0->uNumMessages;
@@ -907,7 +907,7 @@
 
   if ( pCurrentScreen == SCREEN_E )
   {
-    sub_421EA6_OnInventoryLeftClick();
+    OnInventoryLeftClick();
     return;
   }
   if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
@@ -921,7 +921,7 @@
     case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
     {
       pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-      sub_421EA6_OnInventoryLeftClick();
+      OnInventoryLeftClick();
       break;
     }
     case HOUSE_DIALOGUE_GUILD_BUY_BOOKS:
@@ -7247,7 +7247,7 @@
           /*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].eType = UIMSG_Escape;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = !v12;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
@@ -10736,7 +10736,7 @@
             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].eType = UIMSG_StartNPCDialogue;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v12;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
--- a/mm7_4.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_4.cpp	Mon May 13 17:07:52 2013 +0200
@@ -6707,7 +6707,7 @@
           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].eType = UIMSG_Escape;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
@@ -6762,7 +6762,7 @@
           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].eType = UIMSG_Escape;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
@@ -6825,7 +6825,7 @@
   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].eType = UIMSG_Escape;
     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
     ++pMessageQueue_50CBD0->uNumMessages;
@@ -8461,7 +8461,7 @@
     /*result = pMessageQueue_50CBD0->uNumMessages;
     if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
       result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
       *(&pMessageQueue_50CBD0->uNumMessages + result) = v5;
--- a/mm7_5.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_5.cpp	Mon May 13 17:07:52 2013 +0200
@@ -438,6 +438,7 @@
           stru_506E40.Release();
           continue;
         case UIMSG_80:
+			__debugbreak();
           pIcons_LOD->_40F9C5();
           pIcons_LOD->_4114F2();
           pGUIWindow_CurrentMenu->Release();
@@ -731,6 +732,7 @@
           }
           continue;
         case UIMSG_1A9:
+			__debugbreak();
           if ( uMessageParam == 4 )
           {
             //--uGammaPos;
@@ -973,35 +975,31 @@
           back_to_game();
           if ( pMessageQueue_50CBD0->uNumMessages )
             pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen > SCREEN_F )
-          {
-            if ( pCurrentScreen >= SCREEN_CHANGE_LOCATION && (pCurrentScreen <= SCREEN_INPUT_BLV || pCurrentScreen == SCREEN_QUICK_REFERENCE) )
-            {
+          switch ( pCurrentScreen )
+          {
+            case SCREEN_E:
+				__debugbreak();
+            case SCREEN_NPC_DIALOGUE:
+            case SCREEN_CHEST:
+            case SCREEN_CHEST_INVENTORY:
+            case SCREEN_CHANGE_LOCATION:
+            case SCREEN_INPUT_BLV:
+            case SCREEN_QUICK_REFERENCE:
               if ( dword_50CDC8 )
-                goto LABEL_232;
+                break;
               CloseWindowBackground();
               uMessageParam = 1;
-              goto LABEL_232;
-            }
-          }
-          else
-          {
-            if ( pCurrentScreen >= SCREEN_E || pCurrentScreen == SCREEN_NPC_DIALOGUE || pCurrentScreen == SCREEN_CHEST )
-            {
-              if ( dword_50CDC8 )
-                goto LABEL_232;
-              CloseWindowBackground();
-              uMessageParam = 1;
-              goto LABEL_232;
-            }
-            if ( pCurrentScreen == SCREEN_HOUSE && !dword_50CDC8 && !dword_5C35C8 )
-            {
-              CloseWindowBackground();
-              dword_5C35C8 = 0;
-              uMessageParam = 1;
-            }
-          }
-LABEL_232:
+              break;
+            case SCREEN_HOUSE:
+              if ( !dword_50CDC8 && !dword_5C35C8 )
+              {
+                CloseWindowBackground();
+                dword_5C35C8 = 0;
+                uMessageParam = 1;
+                break;
+              }
+              break;
+          }
           if ( !ptr_507BDC )
           {
             pRenderer->ClearZBuffer(0, 479);
@@ -1012,7 +1010,36 @@
               if ( pCurrentScreen > SCREEN_67 )
               {
                 if ( pCurrentScreen == SCREEN_QUICK_REFERENCE )
-                  goto LABEL_321;
+                {
+                  pIcons_LOD->_4114F2();
+                  if ( pGUIWindow_Settings )
+                  {
+                    if ( pCurrentScreen == SCREEN_CHARACTERS )
+                    {
+                      pMouse->SetCursorBitmap("MICON2");
+                    }
+                    else
+                    {
+                      pGUIWindow_Settings->Release();
+                      pGUIWindow_Settings = 0;
+                      pMouse->SetCursorBitmap("MICON1");
+                      GameUI_Footer_TimeLeft = 0;
+                      unk_50C9A0 = 0;
+                      back_to_game();
+                    }
+                  }
+                  if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
+                    uActiveCharacter = pParty->GetNextActiveCharacter();
+                  pGUIWindow_CurrentMenu->Release();
+                  if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
+                    window_SpeakInHouse = 0;
+                  pGUIWindow_CurrentMenu = 0;
+                  pEventTimer->Resume();
+                  pCurrentScreen = SCREEN_GAME;
+                  viewparams->bRedrawGameUI = 1;
+                  pIcons_LOD->_4355F7();
+                  continue;
+                }
               }
               else
               {
@@ -1104,7 +1131,7 @@
                       //crt_deconstruct_ptr_6A0118();
                       stru_506E40.Release();
                       break;
-                    case SCREEN_F:
+                    case SCREEN_CHEST_INVENTORY:
                       pCurrentScreen = SCREEN_CHEST;
                       continue;
                     case SCREEN_CHEST:
@@ -1116,6 +1143,7 @@
                       pEventTimer->Resume();
                       continue;
                     case SCREEN_19:
+						__debugbreak();
                       pWindow2 = ptr_507BC8;
                       pWindow2->Release();
                       pIcons_LOD->_4114F2();
@@ -1125,7 +1153,6 @@
                       continue;
                     case SCREEN_OPTIONS://Close
                       options_menu_skin.Relaease();
-
                       pIcons_LOD->_40F9C5();
                       WriteWindowsRegistryInt("soundflag", (char)uSoundVolumeMultiplier);
                       WriteWindowsRegistryInt("musicflag", (char)uMusicVolimeMultiplier);
@@ -1137,18 +1164,12 @@
                       WriteWindowsRegistryInt("FlipOnExit", bFlipOnExit);
                       if ( !uTurnSpeed )
                       {
-                        //v171 = 3;
-                        //v30 = v171;
-                        //v31 = "TurnDelta";
                         WriteWindowsRegistryInt("TurnDelta", 3);
                         stru_506E40.Release();
                         break;
                       }
                       if ( uTurnSpeed == 64 )
                       {
-                        //v171 = 2;
-                        //v30 = v171;
-                        //v31 = "TurnDelta";
                         WriteWindowsRegistryInt("TurnDelta", 2);
                         stru_506E40.Release();
                         break;
@@ -1158,8 +1179,6 @@
                           stru_506E40.Release();
                           break;
                         }
-                      //v30 = v0;
-                      //v31 = "TurnDelta";
                       WriteWindowsRegistryInt("TurnDelta", 1);
                       stru_506E40.Release();
                       break;
@@ -1283,6 +1302,7 @@
                        pIcons_LOD->_4355F7();
                        continue;
                     case SCREEN_E:
+						__debugbreak();
                       pGUIWindow_CurrentMenu->Release();
                       pCurrentScreen = SCREEN_HOUSE;
                       pIcons_LOD->_4114F2();
@@ -1331,7 +1351,7 @@
                       viewparams->bRedrawGameUI = 1;
                       pIcons_LOD->_4355F7();
                       continue;
-                    case SCREEN_INPUT_BLV:
+                    case SCREEN_INPUT_BLV://click escape
                       if ( uCurrentHouse_Animation == 153 )
                         PlayHouseSound(0x99u, HouseSound_Greeting_2);
                       pVideoPlayer->Unload();
@@ -1343,8 +1363,11 @@
                         viewparams->bRedrawGameUI = 1;
                         dword_5B65CC = 0;
                       }
-                      goto LABEL_317;
-                    case SCREEN_NPC_DIALOGUE:
+                      DialogueEnding();
+                      pCurrentScreen = SCREEN_GAME;
+                      viewparams->bRedrawGameUI = 1;
+                      continue;
+                    case SCREEN_NPC_DIALOGUE://click escape
                       if ( dword_5B65CC )
                       {
                         pParty->field_709 = 0;
@@ -1353,12 +1376,19 @@
                         viewparams->bRedrawGameUI = 1;
                         dword_5B65CC = 0;
                       }
-                      goto LABEL_317;
-                    case SCREEN_BRANCHLESS_NPC_DIALOG:
+                      //goto LABEL_317;
+                      DialogueEnding();
+                      pCurrentScreen = SCREEN_GAME;
+                      viewparams->bRedrawGameUI = 1;
+                      continue;
+                    case SCREEN_BRANCHLESS_NPC_DIALOG://click escape
                       memset(GameUI_Footer_TimedString, 0, 0xC8u);
                       sub_4452BB();
-                      goto LABEL_317;
-                    case SCREEN_CHANGE_LOCATION:
+                      DialogueEnding();
+                      pCurrentScreen = SCREEN_GAME;
+                      viewparams->bRedrawGameUI = 1;
+                      continue;
+                    case SCREEN_CHANGE_LOCATION://click escape
                       if ( pParty->vPosition.x < -22528 )
                         pParty->vPosition.x = -22528;
                       if ( pParty->vPosition.x > 22528 )
@@ -1367,12 +1397,44 @@
                         pParty->vPosition.y = -22528;
                       if ( pParty->vPosition.y > 22528 )
                         pParty->vPosition.y = 22528;
-                      goto LABEL_317;
+                      DialogueEnding();
+                      pCurrentScreen = SCREEN_GAME;
+                      viewparams->bRedrawGameUI = 1;
+                      continue;
                     case SCREEN_VIDEO:
                       pVideoPlayer->Unload();
                       continue;
                     case SCREEN_CHARACTERS:
-                      goto LABEL_319;
+                      CharacterUI_ReleaseButtons();
+                      sub_419379();
+                      pIcons_LOD->_4114F2();
+                      if ( pGUIWindow_Settings )
+                      {
+                        if ( pCurrentScreen == SCREEN_CHARACTERS )
+                        {
+                          pMouse->SetCursorBitmap("MICON2");
+                        }
+                        else
+                        {
+                          pGUIWindow_Settings->Release();
+                          pGUIWindow_Settings = 0;
+                          pMouse->SetCursorBitmap("MICON1");
+                          GameUI_Footer_TimeLeft = 0;
+                          unk_50C9A0 = 0;
+                          back_to_game();
+                        }
+                      }
+                      if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
+                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                      pGUIWindow_CurrentMenu->Release();
+                      if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
+                        window_SpeakInHouse = 0;
+                      pGUIWindow_CurrentMenu = 0;
+                      pEventTimer->Resume();
+                      pCurrentScreen = SCREEN_GAME;
+                      viewparams->bRedrawGameUI = 1;
+                      pIcons_LOD->_4355F7();
+                      continue;
                     default:
                       if ( pGUIWindow_Settings )
                       {
@@ -1433,7 +1495,6 @@
 LABEL_319:
                 CharacterUI_ReleaseButtons();
                 sub_419379();
-LABEL_321:
                 pIcons_LOD->_4114F2();
               }
               if ( pGUIWindow_Settings )
@@ -1628,7 +1689,6 @@
             || pOutdoor->GetTravelDestination(pParty->vPosition.x, pParty->vPosition.y, pOut, 20) != 1 )
           {
             viewparams->bRedrawGameUI = 1;
-LABEL_387:
             CloseWindowBackground();
             if ( pParty->vPosition.x < -22528 )
               pParty->vPosition.x = -22528;
@@ -1638,7 +1698,6 @@
               pParty->vPosition.y = -22528;
             if ( pParty->vPosition.y > 22528 )
               pParty->vPosition.y = 22528;
-LABEL_317:
             DialogueEnding();
             pCurrentScreen = SCREEN_GAME;
           }
@@ -1701,7 +1760,6 @@
             }
             if ( !_strcmpi(pCurrentMapName, "out15.odm") || !_strcmpi(pCurrentMapName, "d47.blv") )
               bNoNPCHiring = 1;
-            //v0 = 1;
             PrepareToLoadODM(1u, (OutdoorCamera *)1);
             pAudioPlayer->SetMapEAX();
             bDialogueUI_InitializeActor_NPC_ID = 0;
@@ -1718,9 +1776,22 @@
           }
           viewparams->bRedrawGameUI = 1;
           continue;
-        case UIMSG_5B:
-          goto LABEL_387;
-        case UIMSG_CastSpell_BE:
+        case UIMSG_CHANGE_LOCATION_ClickCencelBtn:
+          CloseWindowBackground();
+          if ( pParty->vPosition.x < -22528 )
+            pParty->vPosition.x = -22528;
+          if ( pParty->vPosition.x > 22528 )
+            pParty->vPosition.x = 22528;
+          if ( pParty->vPosition.y < -22528 )
+            pParty->vPosition.y = -22528;
+          if ( pParty->vPosition.y > 22528 )
+            pParty->vPosition.y = 22528;
+          DialogueEnding();
+          pCurrentScreen = SCREEN_GAME;
+          viewparams->bRedrawGameUI = 1;
+          continue;
+        case UIMSG_CastSpell_BE://???
+          __debugbreak();
           if ( pRenderer->pRenderD3D )
           {
             LOWORD(v42) = pGame->pVisInstance->get_picked_object_zbuf_val();
@@ -1741,10 +1812,10 @@
             if ( !v47 )
               continue;
             v51 = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-            *((char *)v51 + 8) &= 0xBFu;
-            *((short *)v51 + 2) = uMessageParam;
-            *((int *)v51 + 3) = v44;
-            pParty->pPlayers[*((short *)v51 + 1)].SetRecoveryTime(300);
+            LOBYTE(v51->field_8) &= 0xBFu;
+            v51->uPlayerID_2 = uMessageParam;
+            v51->spell_target_pid = v44;
+            pParty->pPlayers[v51->uPlayerID].SetRecoveryTime(300);
             pWindow3 = pGUIWindow_Settings;
             pWindow3->Release();
             pGUIWindow_Settings = 0;
@@ -1760,10 +1831,10 @@
             if ( !v47 )
               continue;
             v51 = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-            *((char *)v51 + 8) &= 0xBFu;
-            *((short *)v51 + 2) = uMessageParam;
-            *((int *)v51 + 3) = v44;
-            pParty->pPlayers[*((short *)v51 + 1)].SetRecoveryTime(300);
+            LOBYTE(v51->field_8) &= 0xBFu;
+            v51->uPlayerID_2 = uMessageParam;
+            v51->spell_target_pid = v44;
+            pParty->pPlayers[v51->uPlayerID].SetRecoveryTime(300);
             pWindow3 = pGUIWindow_Settings;
             pWindow3->Release();
             pGUIWindow_Settings = 0;
@@ -1787,12 +1858,11 @@
               if ( !(pODMFace->uAttributes & 0x02000000) || !pODMFace->sCogTriggeredID )
                 continue;
               v44 = uNumSeconds;
-              //goto LABEL_415;
               v51 = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
               *((char *)v51 + 8) &= 0xBFu;
-              *((short *)v51 + 2) = uMessageParam;
-              *((int *)v51 + 3) = v44;
-              pParty->pPlayers[*((short *)v51 + 1)].SetRecoveryTime(300);
+              v51->uPlayerID_2 = uMessageParam;
+              v51->spell_target_pid = v44;
+              pParty->pPlayers[v51->uPlayerID].SetRecoveryTime(300);
               pWindow3 = pGUIWindow_Settings;
               pWindow3->Release();
               pGUIWindow_Settings = 0;
@@ -1809,15 +1879,12 @@
           }
           if ( v48 )
             continue;
-//LABEL_415:
           v51 = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-          *((char *)v51 + 8) &= 0xBFu;
-//LABEL_416:
-          *((short *)v51 + 2) = uMessageParam;
-          *((int *)v51 + 3) = v44;
-          pParty->pPlayers[*((short *)v51 + 1)].SetRecoveryTime(300);
+          LOBYTE(v51->field_8) &= 0xBFu;
+          v51->uPlayerID_2 = uMessageParam;
+          v51->spell_target_pid = v44;
+          pParty->pPlayers[v51->uPlayerID].SetRecoveryTime(300);
           pWindow3 = pGUIWindow_Settings;
-//LABEL_333:
           pWindow3->Release();
           pGUIWindow_Settings = 0;
           pMouse->SetCursorBitmap("MICON1");
@@ -1825,9 +1892,10 @@
           unk_50C9A0 = 0;
           back_to_game();
           continue;
-        case UIMSG_CastSpell_SPIRIT_Preservation:
-        case UIMSG_CastSpell_8D:
-        case UIMSG_8F:
+        case UIMSG_CastSpell_8F:
+			__debugbreak();
+        case UIMSG_CastSpell_SPIRIT_Preservation://and blessing, treatment paralysis, hand hammers(individual upgrade)
+        case UIMSG_CastSpell_SPIRIT_Fate:
           if ( pMessageQueue_50CBD0->uNumMessages )
             pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
           if ( unk_50C9A0 )
@@ -1839,21 +1907,21 @@
           {
             if ( pGUIWindow_Settings )
             {
-              v52 = pGUIWindow_Settings->ptr_1C;
+              v51 = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
               switch ( uMessage )
               {
-                case 69:
-                  *((char *)v52 + 8) &= 0xFDu;
+                case UIMSG_CastSpell_SPIRIT_Preservation:
+                  LOBYTE(v51->field_8) &= 0xFDu;
                   break;
-                case 141:
-                  *((char *)v52 + 9) &= 0xFEu;
+                case UIMSG_CastSpell_SPIRIT_Fate:
+                  HIBYTE(v51->field_8) &= 0xFEu;
                   break;
-                case 143:
-                  *((char *)v52 + 9) &= 0xFDu;
+                case UIMSG_CastSpell_8F:
+                  HIBYTE(v51->field_8) &= 0xFDu;
                   break;
               }
-              *((short *)v52 + 2) = uMessageParam;
-              pParty->pPlayers[*((short *)v52 + 1)].SetRecoveryTime(300);
+              v51->uPlayerID_2 = uMessageParam;
+              pParty->pPlayers[v51->uPlayerID].SetRecoveryTime(300);
               pGUIWindow_Settings->Release();
               pGUIWindow_Settings = 0;
               pEventTimer->Resume();
@@ -1864,6 +1932,7 @@
           }
           continue;
         case UIMSG_BF:
+			__debugbreak();
           dword_50CDC8 = 1;
           sub_42FBDD();
           SaveGame(1, 0);
@@ -1890,7 +1959,7 @@
           //goto LABEL_434;
           /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
           {
-            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+            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;
@@ -1944,11 +2013,10 @@
           continue;
         case UIMSG_CloseAfterInstallBeacon:
           dword_50CDC8 = 1;
-          //goto LABEL_453;
           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].eType = UIMSG_Escape;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
           ++pMessageQueue_50CBD0->uNumMessages;*/
@@ -2094,12 +2162,10 @@
                     *((int *)v67 + 17) = 1;
                   else
                     pParty->pPlayers[(unsigned __int8)town_portal_caster_id].CanCastSpell(0x14u);
-//LABEL_434:
                   /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                   {
-                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
                     pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
-//LABEL_771:
                     *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                     ++pMessageQueue_50CBD0->uNumMessages;
                   }*/
@@ -2230,12 +2296,11 @@
           uGameState = GAME_STATE_FINAL_WINDOW;
           continue;
         case UIMSG_C4:
-			__debugbreak;
+			__debugbreak();
           uGameState = GAME_STATE_PLAYING;
           strcpy((char *)pKeyActionMap->pPressedKeysBuffer, "2");
-          goto LABEL_524;
         case UIMSG_DD:
-LABEL_524:
+			__debugbreak();
           sprintf(pTmpBuf, "%s", pKeyActionMap->pPressedKeysBuffer);
           memcpy(&v216, txt_file_frametable_parser((const char *)pKeyActionMap->pPressedKeysBuffer, &v218), sizeof(v216));
           if ( v216.uPropCount == 1 )
@@ -2244,10 +2309,7 @@
             v70 = atoi(v216.pProperties[0]);
             if ( v70 <= 0 || v70 >= 77 )
             {
-//LABEL_90:
               v1 = "";
-//LABEL_91:
-              //v0 = 1;
               continue;
             }
             v71 = v70;
@@ -2270,9 +2332,7 @@
                 dword_6BE364_game_settings_1 |= 1u;
                 uGameState = GAME_STATE_2;
                 OnMapLeave();
-                //goto LABEL_90;
                 v1 = "";
-                //v0 = 1;
                 continue;
               }
             }
@@ -2282,10 +2342,8 @@
           else
           {
             if ( v216.uPropCount != 3 )
-              //goto LABEL_90;
             {
               v1 = "";
-              //v0 = 1;
               continue;
             }
             v74 = atoi(v216.pProperties[0]);
@@ -2297,14 +2355,11 @@
               if ( pIndoor->GetSector(v74, thisi, v75) )
               {
                 v77 = thisi;
-//LABEL_544:
                 pParty->vPosition.x = v74;
                 pParty->vPosition.y = v77;
                 pParty->vPosition.z = v76;
                 pParty->uFallStartY = v76;
-                //goto LABEL_90;
                 v1 = "";
-                //v0 = 1;
                 continue;
               }
             }
@@ -2318,15 +2373,12 @@
                   if ( thisi > -32768 )
                   {
                     if ( thisi < 32768 && v76 >= 0 && v76 < 10000 )
-                      //goto LABEL_544;
                     {
                       pParty->vPosition.x = v74;
                       pParty->vPosition.y = v77;
                       pParty->vPosition.z = v76;
                       pParty->uFallStartY = v76;
-                      //goto LABEL_90;
                       v1 = "";
-                      //v0 = 1;
                       continue;
                     }
                   }
@@ -2337,9 +2389,7 @@
             v73 = "Can't jump to that location!";
           }
           ShowStatusBarString(v73, 6u);
-          //goto LABEL_90;
           v1 = "";
-          //v0 = 1;
           continue;
         case UIMSG_CastQuickSpell:
           if ( bUnderwater == 1 )
@@ -2349,16 +2399,15 @@
             continue;
           }
           if ( !uActiveCharacter || (pPlayer2 = pPlayers[uActiveCharacter], pPlayer2->uTimeToRecovery) )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           _42777D_CastSpell_UseWand_ShootArrow(pPlayer2->uQuickSpell, uActiveCharacter - 1, 0, 0, uActiveCharacter);
           continue;
+        case UIMSG_CastSpell_GreatShot://???
+			__debugbreak();
         case UIMSG_CastSpell_SmallShot://FireBlow, Lightning, Ice Lightning, Swarm, 
-        case UIMSG_CastSpell_GreatShot://Fireball, Spraying poison and other
           if ( pRenderer->pRenderD3D )
           {
             v81 = pGame->pVisInstance->get_picked_object_zbuf_val();
@@ -2373,27 +2422,24 @@
           v44 = (unsigned __int16)v81;
           v84 = v83 >> 16;
           if ( PID_TYPE(v44) != 3 || v84 >= 5120 )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           v51 = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-          if ( uMessage == 70 )
-          {
-            *((char *)v51 + 8) &= 247;
+          if ( uMessage == UIMSG_CastSpell_SmallShot )
+          {
+            LOBYTE(v51->field_8) &= 0xF7;
           }
           else
           {
-            if ( uMessage == 140 )
-              *((char *)v51 + 9) &= 0xFEu;
+            if ( uMessage == UIMSG_CastSpell_GreatShot )
+              HIBYTE(v51->field_8) &= 0xFEu;
             else
-              *((char *)v51 + 9) &= 0xFDu;
-          }
-          //goto LABEL_416;
-          *((short *)v51 + 2) = uMessageParam;
-          *((int *)v51 + 3) = v44;
+              HIBYTE(v51->field_8) &= 0xFDu;
+          }
+          v51->uPlayerID_2 = uMessageParam;
+          v51->spell_target_pid = v44;
           pParty->pPlayers[v51->uPlayerID].SetRecoveryTime(300);
           pWindow3 = pGUIWindow_Settings;
           pWindow3->Release();
@@ -2404,11 +2450,10 @@
           back_to_game();
           continue;
         case UIMSG_1C:
+			__debugbreak();
           if ( !uActiveCharacter || pCurrentScreen )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           ptr_507BC8 = GUIWindow::Create(0, 0, 640, 480, WINDOW_68, uMessageParam, 0);
@@ -2416,15 +2461,13 @@
           pEventTimer->Pause();
           continue;
         case UIMSG_1B:
+			__debugbreak();
           if ( !uActiveCharacter )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           if ( pParty->bTurnBasedModeOn != 1 )
-            //goto LABEL_569;
           {
             if ( pActors[uMessageParam].uAIState == 5 )
               stru_50C198.LootActor(&pActors[uMessageParam]);
@@ -2433,15 +2476,12 @@
             continue;
           }
           if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3 )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           if ( !(pTurnEngine->field_18 & 2) )
           {
-//LABEL_569:
             if ( pActors[uMessageParam].uAIState == 5 )
               stru_50C198.LootActor(&pActors[uMessageParam]);
             else
@@ -2451,27 +2491,21 @@
 
         case UIMSG_Attack:
           if ( !uActiveCharacter )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           if ( pParty->bTurnBasedModeOn != 1 )
-            //goto LABEL_577;
           {
             _42ECB5_PlayerAttacksActor();
             continue;
           }
           if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3 )
-            //goto LABEL_90;
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           if ( !(pTurnEngine->field_18 & 2) )
-//LABEL_577:
             _42ECB5_PlayerAttacksActor();
           continue;
         case UIMSG_ExitRest:
@@ -2535,7 +2569,6 @@
             if ( !uActiveCharacter )
             {
               v1 = "";
-              //v0 = 1;
               continue;
             }
             pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)13, 0);
@@ -2563,7 +2596,6 @@
           if ( !uActiveCharacter )
           {
             v1 = "";
-            //v0 = 1;
             continue;
           }
           pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)13, 0);
@@ -2613,7 +2645,7 @@
                 dword_506F14 = 0;
                 /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
                 {
-                  pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+                  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;
@@ -2683,7 +2715,6 @@
           }
           sprintfex(pTmpBuf, v161, v178);
           sub_41C0B8_set_status_string(pTmpBuf);
-          //v0 = 1;
           continue;
         case UIMSG_ClickInstallRemoveQuickSpellBtn:
           GUIWindow::Create(pBtn_InstallRemoveSpell->uX, pBtn_InstallRemoveSpell->uY, 0, 0, WINDOW_PressedButton2, (int)pBtn_InstallRemoveSpell, 0);
@@ -2705,6 +2736,7 @@
           byte_506550 = 0;
           continue;
         case UIMSG_33:
+			__debugbreak();
           if ( !uActiveCharacter )
             continue;
           pPlayer3 = pPlayers[uActiveCharacter];
@@ -2802,6 +2834,7 @@
         continue;
 
         case UIMSG_92:
+			__debugbreak();
           if ( pTurnEngine->field_4 != 3 )
             _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 133, 1, 0);
           continue;
@@ -2820,7 +2853,6 @@
             if ( uActiveCharacter && !pPlayers[uActiveCharacter]->uTimeToRecovery )
             {
               if ( !pCurrentScreen )
-                //goto LABEL_693;
               {
                 GUIWindow::Create(0x1DCu, 0x1C2u, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
                 pCurrentScreen = SCREEN_SPELL_BOOK;
@@ -2883,7 +2915,7 @@
 //LABEL_453:
           /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
             continue;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
           //goto LABEL_770;
           pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
           *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
@@ -2891,17 +2923,18 @@
           pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
           continue;
         case UIMSG_C0:
+			__debugbreak();
           dword_50651C = 1;
           if ( pMouse->GetCursorPos(&v211)->y > 178 )
             dword_50651C = -1;
           continue;
         case UIMSG_ClickAwardsUpBtn:
           GUIWindow::Create(pBtn_Up->uX, pBtn_Up->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Up, 0);
-          dword_506548 = 1;
+          BtnUp_flag = 1;
           continue;
         case UIMSG_ClickAwardsDownBtn:
           GUIWindow::Create(pBtn_Down->uX, pBtn_Down->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Down, 0);
-          dword_506544 = 1;
+          BtnDown_flag = 1;
           continue;
         case UIMSG_ChangeDetaliz:
           bRingsShownInCharScreen ^= 1;
@@ -2983,57 +3016,59 @@
           GUIWindow::Create(pCharacterScreen_AwardsBtn->uX, pCharacterScreen_AwardsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_AwardsBtn, 0);
           FillAwardsData();
           continue;
-        case UIMSG_AutonotesBook:
+        case UIMSG_AutonotesBook://не только Автозаметки (в процессе)
           switch ( uMessageParam )
           {
-            default:
-              continue;
-            case 11:
-              dword_506548 = 1;
-              continue;
-            case 10:
-              dword_506544 = 1;
-              continue;
+            case 11://Page UP
+              BtnUp_flag = 1;
+              pButton = pBtn_Book_2;
+              break;
+            case 10://Page DOWN
+              BtnDown_flag = 1;
+              pButton = pBtn_Book_1;
+              break;
             case 0:
               pButton = pBtn_Book_1;
-              dword_506544 = 1;
+              BtnDown_flag = 1;
               break;
             case 1:
-              pButton = pBtn_Book_2;
-              dword_506548 = 1;
+              pButton = pBtn_Book_2;//увеличить в MapsBook
+              BtnUp_flag = 1;
               break;
-            case 2:
-              dword_506540 = 1;
+            case 2://Potions
+              Book_PageBtn3_flag = 1;
               if ( dword_506364 )
                 continue;
               pButton = pBtn_Book_3;
               break;
-            case 3:
-              dword_50653C = 1;
+            case 3://fountains
+              Book_PageBtn4_flag = 1;
               if ( dword_506364 )
                 continue;
               pButton = pBtn_Book_4;
               break;
-            case 4:
-              dword_506538 = 1;
+            case 4://obelisks
+              Book_PageBtn5_flag = 1;//Autonotes_Obelisks_page_flag
               if ( dword_506364 )
                 continue;
               pButton = pBtn_Book_5;
               break;
-            case 5:
-              dword_506534 = 1;
+            case 5://seer
+              Book_PageBtn6_flag = 1;//Autonotes_Seer_page_flag
               if ( dword_506364 )
                 continue;
               pButton = pBtn_Book_6;
               break;
-            case 6:
+            case 6://misc
               pButton = pBtn_Autonotes_Misc;
-              dword_506530 = 1;
+              Autonotes_Misc_page_flag = 1;
               break;
-            case 7:
+            case 7://Instructors
               pButton = pBtn_Autonotes_Instructors;
-              dword_50652C = 1;
+              Autonotes_Instructors_page_flag = 1;
               break;
+            default:
+              continue;
           }
           GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, 1);
           continue;
@@ -3090,16 +3125,16 @@
           sprintf(pTmpBuf, "%d / %d %s    %d / %d %s", v110->sHealth, v114, v113, v112, v111, v109);
           sub_41C0B8_set_status_string(pTmpBuf);
           continue;
-        case UIMSG_C:
-          if ( pCurrentScreen == SCREEN_F )
-          {
-            sub_421EA6_OnInventoryLeftClick();
+        case UIMSG_CHEST_ClickItem:
+          if ( pCurrentScreen == SCREEN_CHEST_INVENTORY )
+          {
+            OnInventoryLeftClick();
             continue;
           }
-          sub_420E01();
+          OnChestLeftClick();
           continue;
         case UIMSG_InventoryLeftClick:
-          sub_421EA6_OnInventoryLeftClick();
+          OnInventoryLeftClick();
           continue;
         case UIMSG_MouseLeftClickInGame:
           if ( !pRenderer->pRenderD3D )
@@ -3113,11 +3148,11 @@
           if ( !pMessageQueue_50CBD0->uNumMessages )
             //goto LABEL_768;
           {
-            pMessageQueue_50CBD0->AddMessage(UIMSG_E, 0, 0);
+            pMessageQueue_50CBD0->AddMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
             /*if ( (signed int)v115 < 40 )
             //goto LABEL_769;
             {
-              pMessageQueue_50CBD0->pMessages[v115].eType = (UIMessageType)14;
+              pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
               pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
               *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
               ++pMessageQueue_50CBD0->uNumMessages;
@@ -3128,10 +3163,10 @@
           if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
           {
             pMessageQueue_50CBD0->uNumMessages = 1;
-            pMessageQueue_50CBD0->AddMessage(UIMSG_E, 0, 0);
+            pMessageQueue_50CBD0->AddMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
             /*v115 = v0;
             pMessageQueue_50CBD0->uNumMessages = v0;
-            pMessageQueue_50CBD0->pMessages[v115].eType = (UIMessageType)14;
+            pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
             //goto LABEL_771;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
@@ -3140,23 +3175,24 @@
           }
           v115 = 0;
           pMessageQueue_50CBD0->uNumMessages = 0;
-          pMessageQueue_50CBD0->AddMessage(UIMSG_E, 0, 0);
+          pMessageQueue_50CBD0->AddMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
           /*if ( (signed int)v115 < 40 )
             //goto LABEL_769;
           {
-            pMessageQueue_50CBD0->pMessages[v115].eType = (UIMessageType)14;
+            pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
             pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
             *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
             ++pMessageQueue_50CBD0->uNumMessages;
             continue;
           }*/
           continue;
-        case UIMSG_E://срабатывает при нажатии на правую кнопку мыши после UIMSG_MouseLeftClickInGame
+        case UIMSG_MouseLeftClickInScreen://срабатывает при нажатии на правую кнопку мыши после UIMSG_MouseLeftClickInGame
           if ( pMessageQueue_50CBD0->uNumMessages )
             pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
           OnGameViewportClick();
           continue;
         case UIMSG_F:
+			__debugbreak();
           if ( pRenderer->pRenderD3D )
           {
             LOWORD(v116) = pGame->pVisInstance->get_picked_object_zbuf_val();
@@ -3171,8 +3207,9 @@
           GUIWindow::Create(0, 0, 0, 0, WINDOW_F, (int)pButton2, 0);
           continue;
         case UIMSG_54:
+			__debugbreak();
           pButton2 = (GUIButton *)uMessageParam;
-          GUIWindow::Create(0, 0, 0, 0, (WindowType)22, (int)pButton2, 0);
+          GUIWindow::Create(0, 0, 0, 0, WINDOW_22, (int)pButton2, 0);
           continue;
         case UIMSG_Game_Action:
           if ( pMessageQueue_50CBD0->uNumMessages )
@@ -10278,7 +10315,7 @@
         {
           Chest::DrawChestUI((unsigned int)pWindow->ptr_1C);
         }
-        else if ( pCurrentScreen == SCREEN_F )
+        else if ( pCurrentScreen == SCREEN_CHEST_INVENTORY )
         {
           pRenderer->ClearZBuffer(0, 479);
           draw_leather();
@@ -10894,7 +10931,7 @@
       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].eType = UIMSG_Escape;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
         ++pMessageQueue_50CBD0->uNumMessages;
@@ -10970,7 +11007,7 @@
       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].eType = UIMSG_Escape;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
         ++pMessageQueue_50CBD0->uNumMessages;
@@ -11286,7 +11323,7 @@
   {
     /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
     {
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)27;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_1B;
       pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v6 >> 3;
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
--- a/mm7_6.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_6.cpp	Mon May 13 17:07:52 2013 +0200
@@ -2320,10 +2320,10 @@
         if ( pGUIWindow_Settings )
           return;
         pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
-        pGUIWindow_Settings->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_8D, 0, 0x31u, "", 0);
-        pGUIWindow_Settings->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_8D, 1, 0x32u, "", 0);
-        pGUIWindow_Settings->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_8D, 2, 0x33u, "", 0);
-        pGUIWindow_Settings->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_8D, 3, 0x34u, "", 0);
+        pGUIWindow_Settings->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_SPIRIT_Fate, 0, 0x31u, "", 0);
+        pGUIWindow_Settings->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_SPIRIT_Fate, 1, 0x32u, "", 0);
+        pGUIWindow_Settings->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_SPIRIT_Fate, 2, 0x33u, "", 0);
+        pGUIWindow_Settings->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_SPIRIT_Fate, 3, 0x34u, "", 0);
         pGUIWindow_Settings->CreateButton(8, 8, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_GreatShot, 0, 0, "", NULL);
         sub_421B2C_PlaceInInventory_or_DropPickedItem();
       }
@@ -2340,8 +2340,8 @@
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight)->uTextureHeight,
                        1, 0, UIMSG_ScrollNPCPanel, 1, 0, "",
                        pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight), 0);
-        pGUIWindow_Settings->CreateButton(0x1EBu, 149, 64, 74, 1, 0, UIMSG_8F, 4, 0x35u, "", 0);
-        pGUIWindow_Settings->CreateButton(0x231u, 149, 64, 74, 1, 0, UIMSG_8F, 5, 0x36u, "", 0);
+        pGUIWindow_Settings->CreateButton(0x1EBu, 149, 64, 74, 1, 0, UIMSG_CastSpell_8F, 4, 0x35u, "", 0);
+        pGUIWindow_Settings->CreateButton(0x231u, 149, 64, 74, 1, 0, UIMSG_CastSpell_8F, 5, 0x36u, "", 0);
       }
     }
 }
@@ -9020,7 +9020,7 @@
       {
         /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
           goto LABEL_175;
-        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)404;
+        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Game_Action;
         //goto LABEL_174;
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
@@ -9051,7 +9051,7 @@
         /*if ( (signed int)v15 >= 40 )
           goto LABEL_175;
 //LABEL_173:
-        pMessageQueue_50CBD0->pMessages[v15].eType = (UIMessageType)113;
+        pMessageQueue_50CBD0->pMessages[v15].eType = UIMSG_Escape;
 //LABEL_174:
         pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
         *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
--- a/mm7_data.cpp	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_data.cpp	Mon May 13 17:07:52 2013 +0200
@@ -1488,14 +1488,14 @@
 unsigned int uExitCancelTextureId;
 int dword_50651C; // weak
 int dword_506528; // weak
-int dword_50652C; // weak
-int dword_506530; // weak
-int dword_506534; // weak
-int dword_506538; // weak
-int dword_50653C; // weak
-int dword_506540; // weak
-int dword_506544; // weak
-int dword_506548; // weak
+int Autonotes_Instructors_page_flag; // dword_50652C
+int Autonotes_Misc_page_flag; //dword_506530
+int Book_PageBtn6_flag; //dword_506534
+int Book_PageBtn5_flag; //dword_506538
+int Book_PageBtn4_flag; // dword_50653C
+int Book_PageBtn3_flag; //dword_506540
+int BtnDown_flag; //BtnDown_flag
+int BtnUp_flag; //BtnUp_flag
 int quick_spell_at_page; // weak
 char byte_506550; // weak
 char *aMoonPhaseNames[5];
--- a/mm7_data.h	Mon May 13 17:01:20 2013 +0200
+++ b/mm7_data.h	Mon May 13 17:07:52 2013 +0200
@@ -916,14 +916,14 @@
 extern unsigned int uExitCancelTextureId;
 extern int dword_50651C; // weak
 extern int dword_506528; // weak
-extern int dword_50652C; // weak
-extern int dword_506530; // weak
-extern int dword_506534; // weak
-extern int dword_506538; // weak
-extern int dword_50653C; // weak
-extern int dword_506540; // weak
-extern int dword_506544; // weak
-extern int dword_506548; // weak
+extern int Autonotes_Instructors_page_flag; // dword_50652C
+extern int Autonotes_Misc_page_flag; //dword_506530
+extern int Book_PageBtn6_flag; //dword_506534
+extern int Book_PageBtn5_flag; //dword_506538
+extern int Book_PageBtn4_flag; //dword_50653C
+extern int Book_PageBtn3_flag; //dword_506540
+extern int BtnDown_flag; //BtnDown_flag
+extern int BtnUp_flag; //BtnUp_flag
 extern int quick_spell_at_page; // weak
 extern char byte_506550; // weak
 extern char *aMoonPhaseNames[5];
@@ -1619,14 +1619,14 @@
 void __cdecl sub_42038D();
 
 void __fastcall party_finds_gold(unsigned int uNumGold, int _1_dont_share_with_followers___2_the_same_but_without_a_message__else_normal); // idb
-void __cdecl sub_420E01();
+void OnChestLeftClick();
 void __cdecl GameUI_WritePointedObjectStatusString();
 struct GUIWindow *__thiscall GameUI_InitializeCharacterWindow(unsigned int _this);
 struct GUIWindow *__thiscall sub_4219BE(void *a4);
 bool __cdecl sub_421B2C_PlaceInInventory_or_DropPickedItem();
 void __fastcall GameUI_OnPlayerPortraitLeftClick(unsigned int uPlayerID); // idb
-void __cdecl sub_421EA6_OnInventoryLeftClick();
-void __cdecl OnGameViewportClick();
+void OnInventoryLeftClick();
+void OnGameViewportClick();
 bool PauseGameDrawing();
 void SetUserInterface(enum PartyAlignment alignment, bool bReplace);
 void __cdecl reset_some_strus_flt_2Cs();