changeset 986:b584c743cb47

Слияние
author Ritor1
date Sun, 12 May 2013 09:38:30 +0600
parents 062788391c88 (current diff) d982fffb8b96 (diff)
children 9e132060ada3
files
diffstat 28 files changed, 596 insertions(+), 1132 deletions(-) [+]
line wrap: on
line diff
--- a/Autonotes.h	Sun May 12 09:38:20 2013 +0600
+++ b/Autonotes.h	Sun May 12 09:38:30 2013 +0600
@@ -6,21 +6,20 @@
 /*  351 */
 enum AUTONOTE_TYPE : __int32
 {
-  AUTONOTE_POTION_RECEPIE = 0x0,
-  AUTONOTE_STAT_HINT = 0x1,
-  AUTONOTE_OBELISK = 0x2,
-  AUTONOTE_SEER = 0x3,
-  AUTONOTE_MISC = 0x4,
-  AUTONOTE_TEACHER = 0x5,
+  AUTONOTE_POTION_RECEPIE = 0,
+  AUTONOTE_STAT_HINT = 1,
+  AUTONOTE_OBELISK = 2,
+  AUTONOTE_SEER = 3,
+  AUTONOTE_MISC = 4,
+  AUTONOTE_TEACHER = 5,
 };
 
 /*  350 */
 #pragma pack(push, 1)
 struct Autonote
 {
-  const char *pText;
-  enum AUTONOTE_TYPE eType;
+  const char    *pText;
+  AUTONOTE_TYPE  eType;
 };
 #pragma pack(pop)
 extern Autonote pAutonoteTxt[195]; // weak
-
--- a/GUIWindow.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/GUIWindow.cpp	Sun May 12 09:38:30 2013 +0600
@@ -577,6 +577,8 @@
       num_achieved_awards_2 = v12;
       }
       break;
+
+
   case WINDOW_AutonotesBook:
       {
       pTexture_AutonotesBook   = pIcons_LOD->LoadTexturePtr("sbautnot", TEXTURE_16BIT_PALETTE);
@@ -612,7 +614,7 @@
       num_achieved_awards = 0;
       while ( v10 < 196 )
           {
-          if ( dword_506568 == pAutonoteTxt[v10-1].eType)//dword_72371C[2 * v10] )
+          if ( _506568_autonote_type == pAutonoteTxt[v10-1].eType)//dword_72371C[2 * v10] )
               {
               //v25 = (&dword_723718_autonote_related)[8 * (signed __int16)v10];
               v25 = (char *)pAutonoteTxt[v10-1].pText;
@@ -1110,7 +1112,7 @@
   pRenderer->DrawTextureIndexed(pNPCPortraits_x[0][0], pNPCPortraits_y[0][0], pDialogueNPCPortraits[(signed int)v4]);
   if ( pCurrentScreen == SCREEN_E )
   {
-    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
     if ( pDialogueNPCCount == uNumDialogueNPCPortraits && uHouse_ExitPic )
     {
       pRenderer->DrawTextureIndexed(556, 451, &pIcons_LOD->pTextures[uTextureID_x_x_u]);
--- a/GUIWindow.h	Sun May 12 09:38:20 2013 +0600
+++ b/GUIWindow.h	Sun May 12 09:38:30 2013 +0600
@@ -212,18 +212,18 @@
 /*  251 */
 enum MENU_STATE : __int32
 {
-  MENU_MAIN = 0x0,
-  MENU_NEWGAME = 0x1,
-  MENU_CREDITS = 0x2,
-  MENU_SAVELOAD = 0x3,
-  MENU_FINISHED = 0x4,
-  MENU_5 = 0x5,
-  MENU_CREATEPARTY = 0x6,
-  MENU_NAMEPANELESC = 0x7,
-  MENU_CREDITSPROC = 0x8,
-  MENU_LoadingProcInMainMenu = 0x9,
-  MENU_10 = 0xA,
-  MENU_CREDITSCLOSE = 0xB,
+  MENU_MAIN = 0,
+  MENU_NEWGAME = 1,
+  MENU_CREDITS = 2,
+  MENU_SAVELOAD = 3,
+  MENU_EXIT_GAME = 4,
+  MENU_5 = 5,
+  MENU_CREATEPARTY = 6,
+  MENU_NAMEPANELESC = 7,
+  MENU_CREDITSPROC = 8,
+  MENU_LoadingProcInMainMenu = 9,
+  MENU_10 = 10,
+  MENU_CREDITSCLOSE = 11,
 };
 
 
@@ -472,11 +472,15 @@
 
 
 //character ui
-unsigned int __fastcall GetSkillColor(unsigned int uPlayerClass, PLAYER_SKILL_TYPE uPlayerSkillType, signed int skill_level);
-const char *__fastcall CharacterUI_GetSkillDescText(unsigned int uPlayerID, PLAYER_SKILL_TYPE uPlayerSkillType);
-char __cdecl CharacterUI_SkillsTab_ShowHint();
-void __cdecl CharacterUI_StatsTab_ShowHint();
-char __fastcall CharacterUI_StatsTab_Draw(unsigned int uPlayerID); // idb
+unsigned int GetSkillColor(unsigned int uPlayerClass, PLAYER_SKILL_TYPE uPlayerSkillType, signed int skill_level);
+const char *CharacterUI_GetSkillDescText(unsigned int uPlayerID, PLAYER_SKILL_TYPE uPlayerSkillType);
+char CharacterUI_SkillsTab_ShowHint();
+void CharacterUI_StatsTab_ShowHint();
+char CharacterUI_StatsTab_Draw(unsigned int uPlayerID); // idb
+void CharacterUI_SkillsTab_Draw(Player *player);
+void CharacterUI_AwardsTab_Draw(unsigned int uPlayerID); // idb
+void CharacterUI_InventoryTab_Draw(Player *player, bool a2);
+void CharacterUI_CharacterScreen_Draw(unsigned int uPlayerIdx); // idb
 
 
 
@@ -638,4 +642,13 @@
 extern GUIButton *pCreationUI_BtnPressRight2[4];
 extern GUIButton *pCreationUI_BtnPressLeft2[4];
 extern GUIButton *pCreationUI_BtnPressLeft[4];
-extern GUIButton *pCreationUI_BtnPressRight[4];
\ No newline at end of file
+extern GUIButton *pCreationUI_BtnPressRight[4];
+
+
+extern unsigned int ui_color_text_default;
+extern unsigned int ui_color_text_highlight;
+extern unsigned int ui_color_text_header;
+extern unsigned int ui_color_text_bonus;
+extern unsigned int ui_color_text_bonus_neg;
+extern unsigned int ui_color_text_skill_upgradeable;
+extern unsigned int ui_color_text_skill_not_upgradeable;
\ No newline at end of file
--- a/Game.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/Game.cpp	Sun May 12 09:38:30 2013 +0600
@@ -256,17 +256,17 @@
   signed int pNewNPCsCount; // ecx@58
   char *pFlags; // eax@59
   Player *pPlayer; // esi@65
-  OtherOverlay *pOtherOverlay; // esi@67
-  signed int v8; // edi@67
-  int pPlayerNum; // edi@69
+  //OtherOverlay *pOtherOverlay; // esi@67
+  //signed int v8; // edi@67
+  //int pPlayerNum; // edi@69
   int *pHealth; // esi@71
-  signed int v11; // esi@78
-  int v12; // eax@83
+  //signed int v11; // esi@78
+  //int v12; // eax@83
   const char *pLocationName; // [sp-4h] [bp-68h]@74
   bool bLoading; // [sp+10h] [bp-54h]@1
-  signed int bLoadinga; // [sp+10h] [bp-54h]@19
+  //signed int bLoadinga; // [sp+10h] [bp-54h]@19
   signed int v16; // [sp+14h] [bp-50h]@8
-  int v17[4]; // [sp+18h] [bp-4Ch]@80
+  //int v17[4]; // [sp+18h] [bp-4Ch]@80
   MSG Msg; // [sp+28h] [bp-3Ch]@20
   char Source[64]; // [sp+44h] [bp-20h]@76
 
@@ -276,7 +276,7 @@
   {
     pParty->Reset();
     dword_6BE340 = 0;
-    uGameState = GAME_STATE_0;
+    uGameState = GAME_STATE_PLAYING;
     LoadGame(uLoadGameUI_SelectedSlot);
   }
 
@@ -314,7 +314,8 @@
       pAsyncKeyboard->Resume();
     if ( pRenderer->pRenderD3D )
       pGame->pVisInstance->_4C1A02();
-    bLoadinga = 0;
+
+    bool game_finished = false;
     do
     {
       while ( PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE) )
@@ -349,7 +350,7 @@
         pMouse->_469EA4();
         pRenderer->EndScene();
       }
-      if ( pVideoPlayer->pBinkMovie && !BinkWait(pVideoPlayer->pBinkMovie) )
+      else if ( pVideoPlayer->pBinkMovie && !BinkWait(pVideoPlayer->pBinkMovie) )
       {
         pRenderer->BeginScene();
         pMouse->DrawCursorToTarget();
@@ -357,13 +358,12 @@
         pMouse->_469EA4();
         pRenderer->EndScene();
       }
+      
+      pEventTimer->Update();
+      pMiscTimer->Update();
 
       static int gtc_old = GetTickCount();
       int gtc = GetTickCount();
-      auto evt_old = pEventTimer->uStartTime,
-           msc_old = pMiscTimer->uStartTime;
-      pEventTimer->Update();
-      pMiscTimer->Update();
       Log::Warning(L"Evt/Msc/GTC dt: %u/%u/%u", pEventTimer->uTimeElapsed, pMiscTimer->uTimeElapsed, gtc - gtc_old);
       gtc_old = gtc;
 
@@ -373,7 +373,7 @@
         pMiscTimer->Resume();
       if ( pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn )
         pEventTimer->bTackGameTime = 0;
-      if ( !pEventTimer->bPaused && !uGameState )
+      if ( !pEventTimer->bPaused && uGameState == GAME_STATE_PLAYING)
       {
         if ( !pEventTimer->bTackGameTime )
           _494035_timed_effects__water_walking_damage__etc();
@@ -396,14 +396,14 @@
       if (uGameState == GAME_FINISHED)
         //goto LABEL_96;
       {
-        bLoadinga = 1;
+        game_finished = true;
         continue;
       }
       if (uGameState == GAME_STATE_2)
       {
         pAudioPlayer->StopChannels(-1, -1);
         PrepareWorld(0);
-        uGameState = GAME_STATE_0;
+        uGameState = GAME_STATE_PLAYING;
         continue;
       }
       if ( (signed int)uGameState <= GAME_STATE_2 )
@@ -415,22 +415,24 @@
       if ( (signed int)uGameState <= GAME_STATE_5 || uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU )
       {
 //LABEL_96:
-        bLoadinga = 1;
+        game_finished = true;
         continue;
       }
-      if ( uGameState != GAME_STATE_8 )
+      if ( uGameState != GAME_STATE_PARTY_DIED )
       {
         if ( uGameState != GAME_STATE_FINAL_WINDOW )
         {
 //LABEL_85:
           pGame->Draw();
-          continue;
         }
-        pRenderer->BeginScene();
-        GUI_UpdateWindows();
-        pRenderer->EndScene();
-        //goto LABEL_89;
-        pRenderer->Present();
+        else
+        {
+          pRenderer->BeginScene();
+          GUI_UpdateWindows();
+          pRenderer->EndScene();
+          //goto LABEL_89;
+          pRenderer->Present();
+        }
         continue;
       }
       pAudioPlayer->StopChannels(-1, -1);//    
@@ -465,17 +467,9 @@
       pParty->uTimePlayed += 0x276000ui64;
       LOWORD(pParty->uFlags) &= ~0x204;
       pParty->SetGold(0);
-      pOtherOverlay = pOtherOverlayList->pOverlays;
-      v8 = 50;
-      do
-      {
-        pOtherOverlay->Reset();
-        ++pOtherOverlay;
-        --v8;
-      }
-      while ( v8 );
+      pOtherOverlayList->Reset();
       memset(pParty->pPartyBuffs, 0, 0x140u);
-      pPlayerNum = 1;
+
       if ( pParty->bTurnBasedModeOn == 1 )
       {
         pTurnEngine->End(1);
@@ -493,7 +487,7 @@
         uActiveCharacter = 1;
       }
     //  while ( (signed int)pHealth < (signed int)&pParty->field_871C[567] );
-      if ( (unsigned __int16)_449B57_test_bit(pParty->_quest_bits, 136) )
+      if (_449B57_test_bit(pParty->_quest_bits, PARTY_QUEST_FINISHED_EMERALD_ISLE))
       {
         pParty->vPosition.x = -17331;            // respawn in harmondale
         pParty->vPosition.y = 12547;
@@ -527,23 +521,27 @@
         PrepareWorld(1);
       }
       InitializeActors();
-      v11 = 0;
-      do
+
+
+      int num_conscious_players = 0;
+      int conscious_players_ids[4] = {-1, -1, -1, -1};
+      for (int v11 = 0; v11 < 4; ++v11)
       {
-        if ( pPlayers[pPlayerNum]->CanAct() )
-          v17[v11++] = pPlayerNum;
-        ++pPlayerNum;
+        if (pPlayers[v11 + 1]->CanAct())
+          conscious_players_ids[num_conscious_players++] = v11;
       }
-      while ( pPlayerNum <= 4 );
-      if ( v11 )
+      if (num_conscious_players)
       {
-        v12 = rand();
-        pPlayers[v17[v12 % v11]]->PlaySound(SPEECH_99, 0);
+        int idx = conscious_players_ids[rand() % num_conscious_players];
+        assert(idx >= 0);
+        pPlayers[idx + 1]->PlaySound(SPEECH_99, 0);
       }
+
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2u);// "Once again you've cheated death!.." "   ! "
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
     }
-    while ( !bLoadinga );
+    while (!game_finished);
+
     dword_6BE340 = 0;
     pEventTimer->Pause();
     ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
@@ -551,7 +549,7 @@
     {
       sub_491E3A();
       LoadPlayerPortraintsAndVoices();
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
       pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
       bLoading = true;
       continue;
--- a/Game.h	Sun May 12 09:38:20 2013 +0600
+++ b/Game.h	Sun May 12 09:38:30 2013 +0600
@@ -27,17 +27,17 @@
 /*  320 */
 enum GAME_STATE
 {
-  GAME_STATE_0 = 0x0,
-  GAME_FINISHED = 0x1,
-  GAME_STATE_2 = 0x2,
-  GAME_STATE_3 = 0x3,
-  GAME_STATE_NEWGAME_OUT_GAMEMENU = 0x4,
-  GAME_STATE_5 = 0x5,
-  GAME_STATE_6 = 0x6,
+  GAME_STATE_PLAYING = 0,
+  GAME_FINISHED = 1,
+  GAME_STATE_2 = 2,
+  GAME_STATE_3 = 3,
+  GAME_STATE_NEWGAME_OUT_GAMEMENU = 4,
+  GAME_STATE_5 = 5,
+  GAME_STATE_STARTING_NEW_GAME = 6,
   GAME_STATE_GAME_QUITTING_TO_MAIN_MENU = 7,
-  GAME_STATE_8 = 0x8,
-  GAME_STATE_FINAL_WINDOW = 0x9,
-  GAME_STATE_A = 0xA
+  GAME_STATE_PARTY_DIED = 8,
+  GAME_STATE_FINAL_WINDOW = 9,
+  GAME_STATE_A = 10
 };
 
 
--- a/Items.h	Sun May 12 09:38:20 2013 +0600
+++ b/Items.h	Sun May 12 09:38:30 2013 +0600
@@ -10,6 +10,10 @@
   ITEM_IDENTIFIED = 0x1,
   ITEM_BROKEN = 0x2,
   ITEM_TEMP_BONUS = 0x8,
+  ITEM_AURA_EFFECT_RED = 0x10,
+  ITEM_AURA_EFFECT_BLUE = 0x20,
+  ITEM_AURA_EFFECT_GREEN = 0x40,
+  ITEM_AURA_EFFECT_PURPLE = 0x80,
   ITEM_STOLEN = 0x100,
   ITEM_ENCHANTED = 0x200,
 };
--- a/LOD.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/LOD.cpp	Sun May 12 09:38:30 2013 +0600
@@ -1001,7 +1001,7 @@
   strcpy(pHeader->pSignature, "LOD");
   pHeader->LODSize = 100;
   pHeader->uNumIndices = 1;
-  pDir->pFilename[15] = 0;
+  pDir->field_F = 0;
   pDir->uDataSize = 0;
   pDir->uOfsetFromSubindicesStart = 288;
   strcpy(pLODName, lod_name);
@@ -1430,8 +1430,7 @@
 
 //----- (00461FD4) ---LODFile_sub_461FD4---text:004632EA  --------------------------------------------------
 int LODWriteableFile::FixDirectoryOffsets()
-    {
-     LOD::Directory Lindx; 
+{
     int total_size; // edi@1
     int temp_offset; // ecx@5
     FILE *tmp_file; // eax@9
@@ -1455,9 +1454,10 @@
     tmp_file = fopen(Filename, "wb+");
 
     if ( tmp_file )
-        {
+    {
         fwrite((const void *)&header, sizeof(LOD::FileHeader), 1, tmp_file);
-        Lindx.Reset();
+
+        LOD::Directory Lindx;
         strcpy(Lindx.pFilename, "chapter");
         Lindx.uOfsetFromSubindicesStart=uOffsetToSubIndex; //10h 16
         Lindx.uDataSize=sizeof(LOD::Directory) * uNumSubDirs + total_size;		   //14h 20
@@ -1501,47 +1501,29 @@
 //----- (00461F71) --------------------------------------------------------
 bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData)
 {
-  if ( uNumSubDirs < 299 )
-  {
-    memcpy(&pSubIndices[uNumSubDirs], pDir, sizeof(LOD::Directory));
-    ++uNumSubDirs;
-    fwrite(pData, 1u, pDir->uDataSize, pOutputFileHandle);
-    return true;
-  }
-  else
-  {
-    MessageBoxA(0, "Unable to append item!", "LOD::File", 0x30u);
-    return false;
-  }
+  assert(uNumSubDirs < 299);
+
+  memcpy(&pSubIndices[uNumSubDirs++], pDir, sizeof(LOD::Directory));
+  fwrite(pData, 1, pDir->uDataSize, pOutputFileHandle);
+  return true;
 }
 
 
 //----- (00461F1E) --------------------------------------------------------
 int LODWriteableFile::CreateTempFile()
 {
-  int result; // eax@2
-  FILE *pFile; // eax@5;
-  if ( isFileOpened )
+  if (!isFileOpened)
+    return 1;
+
+  if (pIOBuffer && uIOBufferSize )
   {
-    if (pIOBuffer && uIOBufferSize )
-    {
-      uCurrentIndexDir = 0;
-      uNumSubDirs = 0;
-      pFile = fopen("lodapp.tmp", "wb+");
-      pOutputFileHandle = pFile;
-      result =pFile? 1:7;
-      
-    }
-    else
-    {
-      result = 5;
-    }
+    uCurrentIndexDir = 0;
+    uNumSubDirs = 0;
+    pOutputFileHandle = fopen("lodapp.tmp", "wb+");
+    return pOutputFileHandle ? 1 : 7;  
   }
   else
-  {
-    result = 1;
-  }
-  return result;
+    return 5;
 }
 
 
@@ -1566,8 +1548,7 @@
 
 //----- (00461B48) --------------------------------------------------------
 unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4)
-    {
-     LOD::Directory Lindx;
+{
     char Filename[256]; 
     char NewFilename[256];
     FILE *tmp_file; 
@@ -1631,8 +1612,9 @@
         size_correction=0;
     else
         size_correction=pSubIndices[insert_index].uDataSize;
+
     //create chapter index
-    Lindx.Reset();
+    LOD::Directory Lindx;
     strcpy(Lindx.pFilename, "chapter");
     Lindx.dword_000018=0;
     Lindx.word_00001E=0;
@@ -1723,39 +1705,34 @@
 
 //----- (00461A43) --------------------------------------------------------
 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting)
-    {
-    LOD::Directory lod_indx ;
+{
+  if (bWriting & 1)
+    pFile = fopen(pFilename, "rb");
+  else
+    pFile = fopen(pFilename, "rb+");
+  if (!pFile)
+    return false;
 
-    if (bWriting & 1)
-        pFile = fopen(pFilename, "rb");
-    else
-        pFile = fopen(pFilename, "rb+");
-    if (!pFile)
-        return false;
+  strcpy(pLODName, pFilename);
+  fread(&header, sizeof(LOD::FileHeader), 1, pFile);
+  
+  LOD::Directory lod_indx;
+  fread( &lod_indx,sizeof(LOD::Directory), 1, pFile);
 
-    strcpy(pLODName, pFilename);
-    fread(&header, sizeof(LOD::FileHeader), 1, pFile);
-    lod_indx.Reset();
-    fread( &lod_indx,sizeof(LOD::Directory), 1, pFile);
-    fseek(pFile, 0, SEEK_SET);
-    isFileOpened = true;
-    strcpy(pContainerName, "chapter");
-    uCurrentIndexDir = 0;
-    uLODDataSize = lod_indx.uDataSize;
-    uNumSubDirs = lod_indx.uNumSubIndices;
-    uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart;
-    fseek(pFile, uOffsetToSubIndex, SEEK_SET);
+  fseek(pFile, 0, SEEK_SET);
+  isFileOpened = true;
+  strcpy(pContainerName, "chapter");
+  uCurrentIndexDir = 0;
+  uLODDataSize = lod_indx.uDataSize;
+  uNumSubDirs = lod_indx.uNumSubIndices;
+  assert(uNumSubDirs <= 300);
 
-    if (uNumSubDirs > 300)
-        {
-        MessageBoxW(0, L"LODchapterPages exceed 300", L"LODFile", MB_ICONEXCLAMATION);
-        fclose(pFile);
-        return false;
-        }
+  uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart;
+  fseek(pFile, uOffsetToSubIndex, SEEK_SET);
 
-    fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile);
-    return true;
-    }
+  fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile);
+  return true;
+}
 
 
 //----- (00461A11) --------------------------------------------------------
@@ -1859,17 +1836,6 @@
 }
 
 
-//----- (004617B6) --------------------------------------------------------
-void LOD::FileHeader::Reset()
-{
-  this->pSignature[0] = 0;
-  this->LodVersion[0] = 0;
-  this->LodDescription[0] = 0;
-  this->LODSize = 0;
-  this->dword_0000A8 = 0;
-  this->uNumIndices = 0;
-}
-
 //----- (00461790) --------------------------------------------------------
 LOD::File::~File()
 {
@@ -1903,22 +1869,6 @@
 }
 
 
-//----- (00461743) --------------------------------------------------------
-LOD::Directory *LOD::Directory::Reset()
-{
-  LOD::Directory *result; // eax@1
-
-  result = this;
-  this->pFilename[0] = 0;
-  this->uOfsetFromSubindicesStart = 0;
-  this->uDataSize = 0;
-  this->dword_000018 = 0;
-  this->uNumSubIndices = 0;
-  this->word_00001E = 0;
-  return result;
-}
-
-
 //----- (0046172B) --------------------------------------------------------
 LOD::Directory::Directory()
 {
--- a/LOD.h	Sun May 12 09:38:20 2013 +0600
+++ b/LOD.h	Sun May 12 09:38:30 2013 +0600
@@ -19,6 +19,7 @@
   #pragma pack(push, 1)
   struct FileHeader
   {
+    //----- (004617B6) --------------------------------------------------------
     inline FileHeader()
     {
       memset(pSignature, 0, 4);
@@ -26,10 +27,15 @@
       memset(LodDescription, 0, 80);
       memset(array_0000B0, 0, 28);
       memset(array_0000CC, 0, 52);
+
+      pSignature[0] = 0;
+      LodVersion[0] = 0;
+      LodDescription[0] = 0;
+      LODSize = 0;
+      dword_0000A8 = 0;
+      uNumIndices = 0;
     }
 
-    void Reset();
-
     char pSignature[4];
     char LodVersion[80];
     //char field_C[32];
@@ -48,10 +54,9 @@
   struct Directory
   {
     Directory();
-    Directory *Reset();
 
-
-    char pFilename[16];
+    char pFilename[15];
+    char field_F;
     unsigned int uOfsetFromSubindicesStart;
     unsigned int uDataSize;
     int dword_000018;
--- a/Party.h	Sun May 12 09:38:20 2013 +0600
+++ b/Party.h	Sun May 12 09:38:30 2013 +0600
@@ -11,6 +11,7 @@
 enum PARTY_QUEST_BITS: unsigned __int32
 {
   PARTY_QUEST_EVENMORN_MAP_FOUND = 64,
+  PARTY_QUEST_FINISHED_EMERALD_ISLE = 136,
   PARTY_QUEST_FOUNTAIN_HARMONDALE = 206,
   PARTY_QUEST_FOUNTAIN_NIGHON = 207,
   PARTY_QUEST_FOUNTAIN_PIERPONT = 208,
--- a/Player.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/Player.cpp	Sun May 12 09:38:30 2013 +0600
@@ -2167,7 +2167,7 @@
   signed int v8; // [sp-4h] [bp-10h]@4
 
   v1 = this;
-  LOBYTE(v2) = GetActualSkillLevel(PLAYER_SKILL_PERCEPTION);
+  v2 = (char)GetActualSkillLevel(PLAYER_SKILL_PERCEPTION);
   v3 = v1->pActiveSkills[26];
   v4 = v2 & 0x3F;
   v5 = v1->pActiveSkills[26] & 0x3F;
@@ -8473,7 +8473,7 @@
       v20->PlaySound(SPEECH_96, 0);
 	  v21 = pAutonoteTxt[var_value-1].eType;// dword_72371C[2 * a3];
       bFlashAutonotesBook = 1;
-      dword_506568 = v21;
+      _506568_autonote_type = v21;
     }
     _449B7E_toggle_bit(pParty->_autonote_bits, var_value, 1u);
     v31 = 1;
@@ -9272,7 +9272,7 @@
       v23->PlaySound(SPEECH_96, 0);
 	  v24 = pAutonoteTxt[val-1].eType;//dword_72371C[2 * val];
       bFlashAutonotesBook = 1;
-      dword_506568 = v24;
+      _506568_autonote_type = v24;
     }
     _449B7E_toggle_bit(pParty->_autonote_bits, val, 1u);
     v3 = 1;
--- a/SaveLoad.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/SaveLoad.cpp	Sun May 12 09:38:30 2013 +0600
@@ -229,7 +229,7 @@
 
 //----- (0045F469) --------------------------------------------------------
 void SaveGame( bool IsAutoSAve, bool NotSaveWorld )
-    {
+{
   unsigned short *pScreenshot; // edi@5
   int text_pos; // eax@6
   FILE *pLLoidFile; // edi@24
@@ -250,7 +250,6 @@
   ODMHeader odm_data; // [sp+218h] [bp-58h]@30
   int res; // [sp+224h] [bp-4Ch]@30
   int pPositionZ; // [sp+228h] [bp-48h]@2
-  LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2
   size_t Size; // [sp+250h] [bp-20h]@26
   char *uncompressed_buff; // [sp+258h] [bp-18h]@2
   unsigned int compressed_block_size; // [sp+260h] [bp-10h]@23
@@ -261,7 +260,8 @@
     return;
 
   uncompressed_buff = (char*)malloc(1000000);
-  pLodDirectory.Reset();
+
+  LOD::Directory pLodDirectory; // [sp+22Ch] [bp-44h]@2
   pPositionX = pParty->vPosition.x;
   pPositionY = pParty->vPosition.y;
   pPositionZ = pParty->vPosition.z;
--- a/Spells.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/Spells.cpp	Sun May 12 09:38:30 2013 +0600
@@ -232,79 +232,57 @@
 //----- (00458585) --------------------------------------------------------
 void SpellBuff::Reset()
 {
-
-  this->uSkill = 0;
-  this->uPower = 0;
-  this->uExpireTime = 0i64;
-  this->uCaster = 0;
-  this->uFlags = 0;
-  if ( this->uOverlayID )
+  uSkill = 0;
+  uPower = 0;
+  uExpireTime = 0i64;
+  uCaster = 0;
+  uFlags = 0;
+  if (uOverlayID)
   {
-    ((OtherOverlay *)&stru_5E4C90._decor_events[20 * this->uOverlayID + 105])->Reset();
+    pOtherOverlayList->pOverlays[uOverlayID - 1].Reset();
     pOtherOverlayList->bRedraw = true;
-    this->uOverlayID = 0;
+    uOverlayID = 0;
   }
 }
 
 //----- (004585CA) --------------------------------------------------------
 signed int SpellBuff::_4585CA(__int64 a2)
 {
-  signed int result; // eax@3
-
-  if ( this->uExpireTime && (signed __int64)this->uExpireTime < a2 )
+  if (uExpireTime && uExpireTime < a2)
   {
-    this->uExpireTime = 0i64;
-    this->uPower = 0;
-    this->uSkill = 0;
-    this->uOverlayID = 0;
-    result = 1;
+    uExpireTime = 0;
+    uPower = 0;
+    uSkill = 0;
+    uOverlayID = 0;
+    return true;
   }
-  else
-  {
-    result = 0;
-  }
-  return result;
+  return false;
 }
 
 //----- (004584E0) --------------------------------------------------------
-signed int SpellBuff::Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int a5, unsigned __int8 a6)
+bool SpellBuff::Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int uOverlayID, unsigned __int8 caster)
 {
-  SpellBuff *v6; // esi@1
-  signed int result; // eax@3
-  int v8; // eax@4
+  if (this->uExpireTime && uExpireTime < this->uExpireTime)
+    return false;
 
-  v6 = this;
-  if ( this->uExpireTime && (signed __int64)uExpireTime < (signed __int64)this->uExpireTime )
-  {
-    result = 0;
-  }
-  else
+  this->uSkill = uSkillLevel;
+  this->uPower = uPower;
+  this->uExpireTime = uExpireTime;
+  if (this->uOverlayID && this->uOverlayID != uOverlayID)
   {
-    this->uSkill = uSkillLevel;
-    this->uPower = uPower;
-    LOWORD(v8) = this->uOverlayID;
-    this->uExpireTime = uExpireTime;
-    if ( (short)v8 )
-    {
-      v8 = (unsigned __int16)v8;
-      if ( (unsigned __int16)v8 != a5 )
-      {
-        ((OtherOverlay *)&stru_5E4C90._decor_events[20 * v8 + 105])->Reset();
-        pOtherOverlayList->bRedraw = true;
-        v6->uOverlayID = 0;
-      }
-    }
-    v6->uOverlayID = a5;
-    v6->uCaster = a6;
-    result = 1;
+    pOtherOverlayList->pOverlays[this->uOverlayID - 1].Reset();
+    pOtherOverlayList->bRedraw = true;
+    this->uOverlayID = 0;
   }
-  return result;
+  this->uOverlayID = uOverlayID;
+  this->uCaster = caster;
+
+  return true;
 }
 
 //----- (0045384A) --------------------------------------------------------
 void SpellStats::Initialize()
-	{
-
+{
 	int decode_step;
 	char* test_string;
 	bool break_loop;
--- a/Spells.h	Sun May 12 09:38:20 2013 +0600
+++ b/Spells.h	Sun May 12 09:38:30 2013 +0600
@@ -155,7 +155,7 @@
     uFlags = 0;
   }
 
-  signed int Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int a5, unsigned __int8 a6);
+  bool Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int uOverlayID, unsigned __int8 caster);
   void Reset();
   signed int _4585CA(__int64 a2);
   bool NotExpired();
--- a/Texture.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/Texture.cpp	Sun May 12 09:38:30 2013 +0600
@@ -128,7 +128,7 @@
 unsigned int uTextureID_ib_td5_A;
 unsigned int uTextureID_ib_td2_A; // weak
 unsigned int uTextureID_ib_td1_A;
-int uTextureID_507958; // weak
+int uTextureID_CharacterUI_InventoryBackground; // weak
 int uTextureID_50795C; // weak
 
 
--- a/Texture.h	Sun May 12 09:38:20 2013 +0600
+++ b/Texture.h	Sun May 12 09:38:30 2013 +0600
@@ -231,7 +231,7 @@
 extern unsigned int uTextureID_ib_td5_A;
 extern unsigned int uTextureID_ib_td2_A; // weak
 extern unsigned int uTextureID_ib_td1_A;
-extern int uTextureID_507958; // weak
+extern int uTextureID_CharacterUI_InventoryBackground; // weak
 extern int uTextureID_50795C; // weak
 
 
--- a/UIBooks.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/UIBooks.cpp	Sun May 12 09:38:30 2013 +0600
@@ -648,7 +648,7 @@
   pRenderer->DrawTextureTransparent(v1, v18, v25);
   if ( !dword_506540 )
   {
-    if ( dword_506568 )
+    if (_506568_autonote_type != AUTONOTE_POTION_RECEPIE)
     {
       pRenderer->DrawTextureTransparent(
         pViewport->uViewportTL_X + 408,
@@ -659,7 +659,7 @@
     }
     goto LABEL_14;
   }
-  if ( !dword_506568 )
+  if (_506568_autonote_type == AUTONOTE_POTION_RECEPIE)
   {
 LABEL_14:
     v2 = 1;
@@ -669,12 +669,12 @@
   v31 = 1;
   pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
 LABEL_15:
-  dword_506568 = 0;
+  _506568_autonote_type = AUTONOTE_POTION_RECEPIE;
   pRenderer->DrawTextureTransparent(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTexture_506394);
 LABEL_16:
   if ( dword_50653C )
   {
-    if ( dword_506568 != v2 )
+    if ( _506568_autonote_type != v2 )
     {
       v31 = v2;
       pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
@@ -682,7 +682,7 @@
   }
   else
   {
-    if ( dword_506568 != v2 )
+    if ( _506568_autonote_type != v2 )
     {
       v26 = pTexture_506388;
       v19 = pViewport->uViewportTL_Y + 150;
@@ -691,14 +691,14 @@
     }
   }
   v26 = pTexture_50638C;
-  dword_506568 = v2;
+  _506568_autonote_type = v2;
   v19 = pViewport->uViewportTL_Y + 150;
   v3 = pViewport->uViewportTL_X + 399;
 LABEL_22:
   pRenderer->DrawTextureTransparent(v3, v19, v26);
   if ( dword_506538 )
   {
-    if ( dword_506568 != 2 )
+    if ( _506568_autonote_type != AUTONOTE_OBELISK)
     {
       v31 = v2;
       pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
@@ -706,7 +706,7 @@
   }
   else
   {
-    if ( dword_506568 != 2 )
+    if ( _506568_autonote_type != AUTONOTE_OBELISK)
     {
       v27 = pTexture_506380;
       v20 = pViewport->uViewportTL_Y + 188;
@@ -715,14 +715,14 @@
     }
   }
   v27 = pTexture_506384;
-  dword_506568 = 2;
+  _506568_autonote_type = AUTONOTE_OBELISK;
   v20 = pViewport->uViewportTL_Y + 188;
   v4 = pViewport->uViewportTL_X + 397;
 LABEL_28:
   pRenderer->DrawTextureTransparent(v4, v20, v27);
   if ( dword_506534 )
   {
-    if ( dword_506568 != 3 )
+    if ( _506568_autonote_type != AUTONOTE_SEER)
     {
       v31 = v2;
       pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
@@ -730,7 +730,7 @@
   }
   else
   {
-    if ( dword_506568 != 3 )
+    if ( _506568_autonote_type != AUTONOTE_SEER)
     {
       v28 = pTexture_506378;
       v21 = pViewport->uViewportTL_Y + 226;
@@ -739,14 +739,14 @@
     }
   }
   v28 = pTexture_50637C;
-  dword_506568 = 3;
+  _506568_autonote_type = AUTONOTE_SEER;
   v21 = pViewport->uViewportTL_Y + 226;
   v5 = pViewport->uViewportTL_X + 397;
 LABEL_34:
   pRenderer->DrawTextureTransparent(v5, v21, v28);
   if ( dword_506530 )
   {
-    if ( dword_506568 != 4 )
+    if ( _506568_autonote_type != AUTONOTE_MISC)
     {
       v31 = v2;
       pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
@@ -754,7 +754,7 @@
   }
   else
   {
-    if ( dword_506568 != 4 )
+    if ( _506568_autonote_type != AUTONOTE_MISC)
     {
       v29 = pTexture_506370;
       v22 = pViewport->uViewportTL_Y + 263;
@@ -763,14 +763,14 @@
     }
   }
   v29 = pTexture_506374;
-  dword_506568 = 4;
+  _506568_autonote_type = AUTONOTE_MISC;
   v22 = pViewport->uViewportTL_Y + 264;
   v6 = pViewport->uViewportTL_X + 397;
 LABEL_40:
   pRenderer->DrawTextureTransparent(v6, v22, v29);
   if ( dword_50652C )
   {
-    if ( dword_506568 != 5 )
+    if ( _506568_autonote_type != AUTONOTE_TEACHER)
     {
       v31 = v2;
       pAudioPlayer->PlaySound(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
@@ -778,7 +778,7 @@
   }
   else
   {
-    if ( dword_506568 != 5 )
+    if ( _506568_autonote_type != AUTONOTE_TEACHER)
     {
       v30 = pTexture_506368;
       v23 = pViewport->uViewportTL_Y + 302;
@@ -787,7 +787,7 @@
     }
   }
   v30 = pTexture_50636C;
-  dword_506568 = 5;
+  _506568_autonote_type = AUTONOTE_TEACHER;
   v23 = pViewport->uViewportTL_Y + 302;
   v7 = pViewport->uViewportTL_X + 397;
 LABEL_46:
@@ -815,7 +815,7 @@
     do
     {
       //if ( dword_72371C[2 * v8] == dword_506568 )
-	  if ( pAutonoteTxt[v8-1].eType == dword_506568 )
+	  if ( pAutonoteTxt[v8-1].eType == _506568_autonote_type )
       {
         //v32 = (&dword_723718_autonote_related)[8 * (signed __int16)v8];
 		v32 = (char *)pAutonoteTxt[v8-1].pText;
--- a/UICharacter.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/UICharacter.cpp	Sun May 12 09:38:30 2013 +0600
@@ -45,514 +45,143 @@
 
 
 
+unsigned int ui_color_text_default;
+unsigned int ui_color_text_highlight;
+unsigned int ui_color_text_header;
+unsigned int ui_color_text_bonus;
+unsigned int ui_color_text_bonus_neg;
+unsigned int ui_color_text_skill_upgradeable;
+unsigned int ui_color_text_skill_not_upgradeable;
+void set_default_ui_skin()
+{
+  ui_color_text_default = TargetColor(255, 255, 255);
+  ui_color_text_highlight = TargetColor(255, 0, 0);
+  ui_color_text_header = TargetColor(255, 255, 155);
+  ui_color_text_bonus = TargetColor(0, 255, 0);
+  ui_color_text_bonus_neg = TargetColor(255, 0, 0);
+
+  ui_color_text_skill_upgradeable = TargetColor(0, 175, 255);
+  ui_color_text_skill_not_upgradeable = TargetColor(255, 0, 0);
+}
+
+
+
+static int CharacterUI_SkillsTab_Draw__DrawSkillTable(Player *player, int x, int y, int *skill_list, int skill_list_size, int right_margin, const char *skill_group_name)
+{
+  int y_offset = y;
+  
+  sprintf(pTmpBuf, "%s\r%03d%s", skill_group_name, right_margin, pGlobalTXT_LocalizationStrings[131]); //"Level"
+  pGUIWindow_CurrentMenu->DrawText(pFontArrus, x, y, ui_color_text_header, pTmpBuf, 0, 0, 0);
+
+  int num_skills_drawn = 0;
+  for (uint i = 0; i < skill_list_size; ++i)
+  {
+    auto skill = (PLAYER_SKILL_TYPE)skill_list[i];
+    for (uint j = 0; j < pGUIWindow_CurrentMenu->uNumControls; ++j)
+    {
+      auto v8 = pGUIWindow_CurrentMenu->pControlsHead;
+
+      for (int v7 = j; v7 > 0; --v7)
+        v8 = v8->pNext;
+
+      auto v9 = v8->field_1C;
+      if ((short)(v8->field_1C) >= 0)
+        continue;
+      if ( (v9 & 0x7FFF) != skill )
+        continue;
+
+      ++num_skills_drawn;
+      y_offset = v8->uY;
+
+      auto skill_value = player->pActiveSkills[skill];
+      auto skill_level = skill_value & 0x3F;
+
+      uint skill_color = 0;
+      uint skill_mastery_color = 0;
+      if (player->uSkillPoints > skill_level)
+        skill_color = ui_color_text_skill_upgradeable;
+
+      if (pGUIWindow_CurrentMenu->pCurrentPosActiveItem == j)
+      {
+        if (player->uSkillPoints > skill_level)
+          skill_mastery_color = ui_color_text_bonus;
+        else
+          skill_mastery_color = ui_color_text_skill_not_upgradeable;
+        skill_color = skill_mastery_color;
+      }
+
+      if (SkillToMastery(skill_value) == 1)
+      {
+        sprintfex(pTmpBuf, "%s\r%03d%2d", pSkillNames[skill], right_margin, skill_level);
+        pGUIWindow_CurrentMenu->DrawText(pFontLucida, x, v8->uY, skill_color, pTmpBuf, 0, 0, 0);
+      }
+      else
+      {
+        const char *v46 = nullptr;
+
+        switch (SkillToMastery(skill_value))
+        {
+          case 4: v46 = pGlobalTXT_LocalizationStrings[96];  break; // "Grand"
+          case 3: v46 = pGlobalTXT_LocalizationStrings[432]; break; // Master
+          case 2: v46 = pGlobalTXT_LocalizationStrings[433]; break; // Expert
+        }
+
+        if (!skill_mastery_color)
+          skill_mastery_color = ui_color_text_header;
+
+        
+        sprintfex(pTmpBuf, "%s \f%05d%s\f%05d\r%03d%2d", pSkillNames[skill], skill_mastery_color, v46, skill_color, right_margin, skill_level);
+        pGUIWindow_CurrentMenu->DrawText(pFontLucida, x, v8->uY, skill_color, pTmpBuf, 0, 0, 0);
+      }
+    }
+  }
+
+  if (!num_skills_drawn)
+  {
+    y_offset += LOBYTE(pFontLucida->uFontHeight) - 3;
+    pGUIWindow_CurrentMenu->DrawText(pFontLucida, x, y_offset, 0, pGlobalTXT_LocalizationStrings[153], 0, 0, 0); //"None"
+  }
+
+  return y_offset;
+}
+
 
 
 //----- (00419719) --------------------------------------------------------
-char __fastcall CharacterUI_SkillsTab_Draw(unsigned int uPlayerID)
-    {
-    unsigned int v1; // esi@1
-    Player *pPlayer; // ebp@1
-    unsigned int v3; // eax@1
-    signed int v4; // ecx@1
-    int v5; // edi@3
-    GUIWindow *v6; // ecx@3
-    int v7; // eax@4
-    GUIButton *v8; // edx@5
-    int v9; // eax@7
-    unsigned int v10; // ecx@9
-    unsigned __int16 v11; // ax@9
-    int v12; // eax@9
-    unsigned __int8 v13; // cf@12
-    unsigned __int8 v14; // zf@12
-    unsigned int v15; // eax@12
-    char *v16; // ecx@22
-    GUIWindow *v17; // ecx@33
-    int v18; // edx@34
-    GUIButton *v19; // eax@35
-    int v20; // edx@37
-    unsigned __int16 v21; // cx@39
-    unsigned int v22; // eax@39
-    int v23; // edi@39
-    unsigned int v24; // eax@42
-    char v25; // sf@52
-    char *v26; // ecx@52
-    int v27; // edi@63
-    GUIWindow *v28; // ecx@63
-    int v29; // edx@64
-    GUIButton *v30; // eax@65
-    int v31; // edx@67
-    unsigned int v32; // ecx@69
-    int v33; // eax@69
-    unsigned int v34; // eax@72
-    char *v35; // ecx@82
-    GUIWindow *v36; // ecx@93
-    int v37; // edx@94
-    GUIButton *v38; // eax@94
-    int v39; // edx@97
-    unsigned __int16 v40; // cx@99
-    unsigned int v41; // eax@99
-    int v42; // edi@99
-    unsigned int v43; // eax@102
-    char *v44; // ecx@112
-    char *v46; // [sp-Ch] [bp-4Ch]@19
-    char *v47; // [sp-Ch] [bp-4Ch]@49
-    char *v48; // [sp-Ch] [bp-4Ch]@79
-    char *v49; // [sp-Ch] [bp-4Ch]@109
-    unsigned int v50; // [sp-8h] [bp-48h]@19
-    unsigned int v51; // [sp-8h] [bp-48h]@49
-    unsigned int v52; // [sp-8h] [bp-48h]@79
-    unsigned int v53; // [sp-8h] [bp-48h]@109
-    int v54; // [sp-4h] [bp-44h]@19
-    int v55; // [sp-4h] [bp-44h]@49
-    int v56; // [sp-4h] [bp-44h]@79
-    int v57; // [sp-4h] [bp-44h]@109
-    unsigned int v58; // [sp+10h] [bp-30h]@9
-    unsigned int v59; // [sp+10h] [bp-30h]@39
-    unsigned int v60; // [sp+10h] [bp-30h]@69
-    unsigned int v61; // [sp+10h] [bp-30h]@99
-    int v62; // [sp+14h] [bp-2Ch]@4
-    int v63; // [sp+14h] [bp-2Ch]@34
-    int v64; // [sp+14h] [bp-2Ch]@64
-    int v65; // [sp+14h] [bp-2Ch]@94
-    signed int i; // [sp+18h] [bp-28h]@4
-    signed int v67; // [sp+18h] [bp-28h]@34
-    signed int v68; // [sp+18h] [bp-28h]@64
-    signed int v69; // [sp+18h] [bp-28h]@94
-    int v70; // [sp+1Ch] [bp-24h]@3
-    int v71; // [sp+1Ch] [bp-24h]@33
-    int v72; // [sp+1Ch] [bp-24h]@63
-    int v73; // [sp+1Ch] [bp-24h]@93
-    int uY; // [sp+20h] [bp-20h]@9
-    int uYa; // [sp+20h] [bp-20h]@33
-    int uYb; // [sp+20h] [bp-20h]@69
-    int uYc; // [sp+20h] [bp-20h]@93
-    unsigned int a5; // [sp+24h] [bp-1Ch]@1
-    unsigned int v79; // [sp+28h] [bp-18h]@1
-    int *v80; // [sp+2Ch] [bp-14h]@3
-    int *v81; // [sp+2Ch] [bp-14h]@33
-    int *v82; // [sp+2Ch] [bp-14h]@63
-    int *v83; // [sp+2Ch] [bp-14h]@93
-    unsigned int v84; // [sp+30h] [bp-10h]@1
-    int v85; // [sp+34h] [bp-Ch]@1
-    unsigned int v86; // [sp+38h] [bp-8h]@1
-    unsigned __int16 v87; // [sp+3Ch] [bp-4h]@9
-    char *v88; // [sp+3Ch] [bp-4h]@24
-    char *v89; // [sp+3Ch] [bp-4h]@54
-    unsigned __int16 v90; // [sp+3Ch] [bp-4h]@69
-    char *v91; // [sp+3Ch] [bp-4h]@84
-    char *v92; // [sp+3Ch] [bp-4h]@114
+void CharacterUI_SkillsTab_Draw(Player *player)
+{
+  pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->LoadTexturePtr("fr_skill", TEXTURE_16BIT_PALETTE));
+
+  sprintfex(pTmpBuf, "%s \f%05d^Pv[%s]\f00000\r177%s: \f%05d%d\f00000",
+            pGlobalTXT_LocalizationStrings[206],        // Skills for
+            ui_color_text_header,
+            player->pName,
+            pGlobalTXT_LocalizationStrings[207],        // Skill Points
+            player->uSkillPoints ? ui_color_text_bonus : ui_color_text_default,
+            player->uSkillPoints);
+  pGUIWindow_CurrentMenu->DrawText(pFontArrus, 24, 18, 0, pTmpBuf, 0, 0, 0);
 
-    v1 = uPlayerID;
-    a5 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-    v84 = TargetColor(0, 0xAFu, 0xFFu);
-    v85 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem;
-    v86 = TargetColor(0xFFu, 0, 0);
-    v79 = TargetColor(0, 0xFFu, 0);
-    pPlayer = &pParty->pPlayers[v1-1];
-    v3 = pIcons_LOD->LoadTexture("fr_skill", TEXTURE_16BIT_PALETTE);
-    pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(v3));
-    v4 = v79;
-    if ( !pPlayer->uSkillPoints )
-        v4 = 65535;
-    sprintf(
-        pTmpBuf,
-        "%s \f%05d%s\f00000\r177%s: \f%05d%d\f00000",
-        pGlobalTXT_LocalizationStrings[206],        // Skills for
-        a5,
-        pPlayer->pName,
-        pGlobalTXT_LocalizationStrings[207],        // Skill Points
-        v4,
-        pPlayer->uSkillPoints);
-    pGUIWindow_CurrentMenu->DrawText(pFontArrus, 24, 18, 0, pTmpBuf, 0, 0, 0);
-    v5 = 2 * LOBYTE(pFontLucida->uFontHeight) + 13;// Weapons,   Level
-    sprintf(pTmpBuf, "%s\r400%s", pGlobalTXT_LocalizationStrings[242], pGlobalTXT_LocalizationStrings[131]);
-    pGUIWindow_CurrentMenu->DrawText(pFontArrus, 24, v5, a5, pTmpBuf, 0, 0, 0);
-    v6 = pGUIWindow_CurrentMenu;
-    v70 = 0;
-    v80 = pWeaponSkills;
-    do
-        {
-        v62 = *v80;
-        v7 = 0;
-        for ( i = 0; i < (signed int)v6->uNumControls; v7 = i++ + 1 )
-            {
-            v8 = v6->pControlsHead;
-            if ( v7 > 0 )
-                {
-                do
-                    {
-                    v8 = v8->pNext;
-                    --v7;
-                    }
-                    while ( v7 );
-                }
-            v9 = v8->field_1C;
-            if ( SBYTE1(v9) >= 0 )
-                continue;
-            BYTE1(v9) &= 0x7Fu;
-            if ( v9 != v62 )
-                continue;
-            v5 = v8->uY;
-            v10 = pPlayer->uSkillPoints;
-            ++v70;
-            v11 = pPlayer->pActiveSkills[v62];
-            v87 = pPlayer->pActiveSkills[v62];
-            v12 = v11 & 0x3F;
-            v58 = 0;
-            uY = v12;
-            if ( v10 >= v12 + 1 )
-                v58 = v84;
-            if ( v85 == i )
-                {
-                v13 = v10 < v12;
-                v14 = v10 == v12;
-                v15 = v86;
-                if ( !(v13 | v14) )
-                    v15 = v79;
-                v58 = v15;
-                }
-            else
-                {
-                v15 = v58;
-                }
-            if ( HIBYTE(v87) & 1 )
-                {
-                if ( !v15 )
-                    v15 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                v54 = uY;
-                v50 = v58;
-                v46 = pGlobalTXT_LocalizationStrings[96];
-                }
-            else
-                {
-                if ( !(v87 & 0xC0) )
-                    {
-                    sprintf(pTmpBuf, "%s\r400%2d", pSkillNames[v62], uY);
-                    pGUIWindow_CurrentMenu->DrawText(pFontLucida, 24, v5, v58, pTmpBuf, 0, 0, 0);
-                    v6 = pGUIWindow_CurrentMenu;
-                    continue;
-                    }
-                v16 = pGlobalTXT_LocalizationStrings[432];
-                if ( (v87 & 0x80u) == 0 )
-                    v16 = pGlobalTXT_LocalizationStrings[433];
-                v88 = v16;
-                if ( !v15 )
-                    v15 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                v54 = uY;
-                v50 = v58;
-                v46 = v88;
-                }
-            sprintf(pTmpBuf, "%s ", pSkillNames[v62], v15, v46, v50, v54);
-            pGUIWindow_CurrentMenu->DrawText(pFontLucida, 24, v5, v58, pTmpBuf, 0, 0, 0);
-            v6 = pGUIWindow_CurrentMenu;
-            }
-        ++v80;
-        }
-        while ( v80 <= &pWeaponSkills[8]);
-        if ( !v70 )
-            {
-            v5 = v5 + LOBYTE(pFontLucida->uFontHeight) - 3;
-            v6->DrawText(pFontLucida, 24, v5, 0, pGlobalTXT_LocalizationStrings[153], 0, 0, 0);
-            }
-        uYa = v5 + 2 * LOBYTE(pFontLucida->uFontHeight) - 10;
-        sprintf(pTmpBuf, "%s\r400%s", pGlobalTXT_LocalizationStrings[138], pGlobalTXT_LocalizationStrings[131]);
-        pGUIWindow_CurrentMenu->DrawText(pFontArrus, 24, uYa, a5, pTmpBuf, 0, 0, 0);
-        v17 = pGUIWindow_CurrentMenu;
-        v71 = 0;
-        v81 = pMagicSkills;
-        do
-            {
-            v18 = 0;
-            v67 = 0;
-            v63 = *v81;
-            while ( v67 < (signed int)v17->uNumControls )
-                {
-                v19 = v17->pControlsHead;
-                if ( v18 > 0 )
-                    {
-                    do
-                        {
-                        v19 = v19->pNext;
-                        --v18;
-                        }
-                        while ( v18 );
-                    }
-                v20 = v19->field_1C;
-                if ( SBYTE1(v20) >= 0 || (BYTE1(v20) &= 0x7Fu, v20 != v63) )
-                    {
-                    v18 = v67++ + 1;
-                    continue;
-                    }
-                ++v71;
-                uYa = v19->uY;
-                v21 = pPlayer->pActiveSkills[v63];
-                v22 = pPlayer->uSkillPoints;
-                v23 = pPlayer->pActiveSkills[v63] & 0x3F;
-                v59 = 0;
-                if ( v22 >= v23 + 1 )
-                    v59 = v84;
-                if ( v85 == v67 )
-                    {
-                    v13 = v22 < v23;
-                    v14 = v22 == v23;
-                    v24 = v86;
-                    if ( !(v13 | v14) )
-                        v24 = v79;
-                    v59 = v24;
-                    }
-                else
-                    {
-                    v24 = v59;
-                    }
-                if ( HIBYTE(v21) & 1 )
-                    {
-                    if ( !v24 )
-                        v24 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                    v55 = v23;
-                    v51 = v59;
-                    v47 = pGlobalTXT_LocalizationStrings[96];
-                    }
-                else
-                    {
-                    if ( !(v21 & 0xC0) )
-                        {
-                        sprintf(pTmpBuf, "%s\r400%2d", pSkillNames[v63], v23);
-                        pGUIWindow_CurrentMenu->DrawText(pFontLucida, 24, uYa, v59, pTmpBuf, 0, 0, 0);
-                        v17 = pGUIWindow_CurrentMenu;
-                        v18 = v67++ + 1;
-                        continue;
-                        }
-                    v25 = (v21 & 0x80u) != 0;
-                    v26 = pGlobalTXT_LocalizationStrings[432];
-                    if ( !v25 )
-                        v26 = pGlobalTXT_LocalizationStrings[433];
-                    v89 = v26;
-                    if ( !v24 )
-                        v24 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                    v55 = v23;
-                    v51 = v59;
-                    v47 = v89;
-                    }
-                sprintf(pTmpBuf, "%s ", pSkillNames[v63], v24, v47, v51, v55);
-                //LABEL_58:
-                pGUIWindow_CurrentMenu->DrawText(pFontLucida, 24, uYa, v59, pTmpBuf, 0, 0, 0);
-                v17 = pGUIWindow_CurrentMenu;
-                //LABEL_59:
-                v18 = v67++ + 1;
-                }
-            ++v81;
-            }
-            while ( v81 <= &pMagicSkills[8]);
-            if ( !v71 )
-                v17->DrawText(
-                pFontLucida,
-                24,
-                LOBYTE(pFontLucida->uFontHeight) + uYa - 3,
-                0,
-                pGlobalTXT_LocalizationStrings[153],
-                0,
-                0,
-                0);
-            v27 = 2 * LOBYTE(pFontLucida->uFontHeight) + 13;
-            sprintf(pTmpBuf, "%s\r177%s", pGlobalTXT_LocalizationStrings[11], pGlobalTXT_LocalizationStrings[131]);
-            pGUIWindow_CurrentMenu->DrawText(pFontArrus, 248, v27, a5, pTmpBuf, 0, 0, 0);
-            v28 = pGUIWindow_CurrentMenu;
-            v72 = 0;
-            v82 = pArmorSkills;
-            do
-                {
-                v29 = 0;
-                v68 = 0;
-                v64 = *v82;
-                while ( v68 < (signed int)v28->uNumControls )
-                    {
-                    v30 = v28->pControlsHead;
-                    if ( v29 > 0 )
-                        {
-                        do
-                            {
-                            v30 = v30->pNext;
-                            --v29;
-                            }
-                            while ( v29 );
-                        }
-                    v31 = v30->field_1C;
-                    if ( SBYTE1(v31) >= 0 || (BYTE1(v31) &= 0x7Fu, v31 != v64) )
-                        {
-                        v29 = v68++ + 1;
-                        continue;
-                        }
-                    v27 = v30->uY;
-                    ++v72;
-                    v60 = 0;
-                    v90 = pPlayer->pActiveSkills[v64];
-                    v32 = pPlayer->uSkillPoints;
-                    v33 = pPlayer->pActiveSkills[v64] & 0x3F;
-                    uYb = v33;
-                    if ( v32 >= v33 + 1 )
-                        v60 = v84;
-                    if ( v85 == v68 )
-                        {
-                        v13 = v32 < v33;
-                        v14 = v32 == v33;
-                        v34 = v86;
-                        if ( !(v13 | v14) )
-                            v34 = v79;
-                        v60 = v34;
-                        }
-                    else
-                        {
-                        v34 = v60;
-                        }
-                    if ( (pPlayer->pActiveSkills[v64] >> 8) & 1 )
-                        {
-                        if ( !v34 )
-                            v34 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                        v56 = uYb;
-                        v52 = v60;
-                        v48 = pGlobalTXT_LocalizationStrings[96];
-                        }
-                    else
-                        {
-                        if ( !(v90 & 0xC0) )
-                            {
-                            sprintf(pTmpBuf, "%s\r177%2d", pSkillNames[v64], uYb);
-                            pGUIWindow_CurrentMenu->DrawText(pFontLucida, 248, v27, v60, pTmpBuf, 0, 0, 0);
-                            v28 = pGUIWindow_CurrentMenu;
-                            v29 = v68++ + 1;
-                            continue;
-                            }
-                        v35 = pGlobalTXT_LocalizationStrings[432];
-                        if ( (v90 & 0x80u) == 0 )
-                            v35 = pGlobalTXT_LocalizationStrings[433];
-                        v91 = v35;
-                        if ( !v34 )
-                            v34 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                        v56 = uYb;
-                        v52 = v60;
-                        v48 = v91;
-                        }
-                    sprintf(pTmpBuf, "%s ", pSkillNames[v64], v34, v48, v52, v56);
-                    //LABEL_88:
-                    pGUIWindow_CurrentMenu->DrawText(pFontLucida, 248, v27, v60, pTmpBuf, 0, 0, 0);
-                    v28 = pGUIWindow_CurrentMenu;
-                    //LABEL_89:
-                    v29 = v68++ + 1;
-                    }
-                ++v82;
-                }
-                while ( v82 <= &pArmorSkills[4]);
-                if ( !v72 )
-                    {
-                    v27 = v27 + LOBYTE(pFontLucida->uFontHeight) - 3;
-                    v28->DrawText(pFontLucida, 248, v27, 0, pGlobalTXT_LocalizationStrings[153], 0, 0, 0);
-                    }
-                uYc = v27 + 2 * LOBYTE(pFontLucida->uFontHeight) - 10;
-                sprintf(pTmpBuf, "%s\r177%s", pGlobalTXT_LocalizationStrings[143], pGlobalTXT_LocalizationStrings[131]);
-                pGUIWindow_CurrentMenu->DrawText(pFontArrus, 248, uYc, a5, pTmpBuf, 0, 0, 0);
-                v36 = pGUIWindow_CurrentMenu;
-                v73 = 0;
-                v83 = pMiscSkills;
-                do
-                    {
-                    v37 = 0;
-                    v69 = 0;
-                    v38 = (GUIButton *)*v83;
-                    v65 = *v83;
-                    while ( v69 < (signed int)v36->uNumControls )
-                        {
-                        v38 = v36->pControlsHead;
-                        if ( v37 > 0 )
-                            {
-                            do
-                                {
-                                v38 = v38->pNext;
-                                --v37;
-                                }
-                                while ( v37 );
-                            }
-                        v39 = v38->field_1C;
-                        if ( SBYTE1(v39) >= 0 || (BYTE1(v39) &= 0x7Fu, v39 != v65) )
-                            {
-                            //goto LABEL_119;
-                            v37 = v69++ + 1;
-                            continue;
-                            }
-                        ++v73;
-                        uYc = v38->uY;
-                        v40 = pPlayer->pActiveSkills[v65];
-                        v41 = pPlayer->uSkillPoints;
-                        v42 = pPlayer->pActiveSkills[v65] & 0x3F;
-                        v61 = 0;
-                        if ( v41 >= v42 + 1 )
-                            v61 = v84;
-                        if ( v85 == v69 )
-                            {
-                            v13 = v41 < v42;
-                            v14 = v41 == v42;
-                            v43 = v86;
-                            if ( !(v13 | v14) )
-                                v43 = v79;
-                            v61 = v43;
-                            }
-                        else
-                            {
-                            v43 = v61;
-                            }
-                        if ( HIBYTE(v40) & 1 )
-                            {
-                            if ( !v43 )
-                                v43 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                            v57 = v42;
-                            v53 = v61;
-                            v49 = pGlobalTXT_LocalizationStrings[96];
-                            }
-                        else
-                            {
-                            if ( !(v40 & 0xC0) )
-                                {
-                                sprintf(pTmpBuf, "%s\r177%2d", pSkillNames[v65], v42);
-                                LOBYTE(v38) = pGUIWindow_CurrentMenu->DrawText(pFontLucida, 248, uYc, v61, pTmpBuf, 0, 0, 0);
-                                v36 = pGUIWindow_CurrentMenu;
-                                v37 = v69++ + 1;
-                                continue;
-                                }
-                            v25 = (v40 & 0x80u) != 0;
-                            v44 = pGlobalTXT_LocalizationStrings[432];
-                            if ( !v25 )
-                                v44 = pGlobalTXT_LocalizationStrings[433];
-                            v92 = v44;
-                            if ( !v43 )
-                                v43 = TargetColor(0xFFu, 0xFFu, 0x9Bu);
-                            v57 = v42;
-                            v53 = v61;
-                            v49 = v92;
-                            }
-                        sprintf(pTmpBuf, "%s ", pSkillNames[v65], v43, v49, v53, v57);
-                        LOBYTE(v38) = pGUIWindow_CurrentMenu->DrawText(pFontLucida, 248, uYc, v61, pTmpBuf, 0, 0, 0);
-                        v36 = pGUIWindow_CurrentMenu;
-                        v37 = v69++ + 1;
-                        }
-                    ++v83;
-                    }
-                    while ( v83 <= &pMiscSkills[11]);
-                    if ( !v73 )
-                        LOBYTE(v38) = v36->DrawText(
-                        pFontLucida,
-                        248,
-                        LOBYTE(pFontLucida->uFontHeight) + uYc - 3,
-                        0,
-                        pGlobalTXT_LocalizationStrings[153],
-                        0,
-                        0,
-                        0);
-                    return (char)v38;
+  int y = 2 * LOBYTE(pFontLucida->uFontHeight) + 13;
+  y = CharacterUI_SkillsTab_Draw__DrawSkillTable(player, 24, y, pWeaponSkills, 9, 400, pGlobalTXT_LocalizationStrings[242]); // "Weapons"
+
+  y += 2 * LOBYTE(pFontLucida->uFontHeight) - 10;
+  CharacterUI_SkillsTab_Draw__DrawSkillTable(player, 24, y, pMagicSkills, 9, 400, pGlobalTXT_LocalizationStrings[138]); // "Magic"
+
+  y = 2 * LOBYTE(pFontLucida->uFontHeight) + 13;
+  y = CharacterUI_SkillsTab_Draw__DrawSkillTable(player, 248, y, pArmorSkills, 5, 177, pGlobalTXT_LocalizationStrings[11]); // "Armor"
+ 
+  y += 2 * LOBYTE(pFontLucida->uFontHeight) - 10;
+  y = CharacterUI_SkillsTab_Draw__DrawSkillTable(player, 248, y, pMiscSkills, 12, 177, pGlobalTXT_LocalizationStrings[143]); //"Misc"
 }
 
 
 
 
 
+
+
+
+
     
 unsigned int GetAwardColor(unsigned int priority)
 {
@@ -685,201 +314,109 @@
 
 
 
-    //----- (0041A2C1) --------------------------------------------------------
-    unsigned int __fastcall GetSizeInInventorySlots(unsigned int uNumPixels)
-        {
-        if ( (signed int)uNumPixels < 14 )
-            uNumPixels = 14;
-        return ((signed int)(uNumPixels - 14) >> 5) + 1;
-        }
+//----- (0041A2C1) --------------------------------------------------------
+unsigned int __fastcall GetSizeInInventorySlots(unsigned int uNumPixels)
+{
+  if ( (signed int)uNumPixels < 14 )
+    uNumPixels = 14;
+  return ((signed int)(uNumPixels - 14) >> 5) + 1;
+}
 
-    //----- (0041A2D1) --------------------------------------------------------
-    void __fastcall CharacterUI_InventoryTab_Draw(unsigned int uPlayerID, char a2)
-        {
-        Player *pPlayer; // esi@1
-        char v3; // bl@1
-        unsigned int v4; // eax@2
-        ItemGen *pItem; // ebx@5
-        unsigned int v6; // eax@6
+//----- (0041A2D1) --------------------------------------------------------
+void CharacterUI_InventoryTab_Draw(Player *player, bool a2)
+{
         Texture *v7; // esi@6
-        __int16 v8; // ax@6
-        signed int v9; // edi@6
-        signed int v10; // ecx@6
         signed int v11; // edx@6
-        signed int v12; // eax@11
         int v13; // eax@13
         signed int v14; // edx@13
         int v15; // eax@13
-        unsigned int v16; // ebx@15
         unsigned int v17; // edi@15
         Texture *pTexture; // ebx@24
-        double v19; // st7@26
-        const char *v20; // [sp-8h] [bp-40h]@20
-        Player *pPlayer2; // [sp+14h] [bp-24h]@1
-        int uTextureId; // [sp+18h] [bp-20h]@6
-        int *v23; // [sp+1Ch] [bp-1Ch]@1
-        int v24; // [sp+20h] [bp-18h]@5
-        ItemGen *pItem2; // [sp+24h] [bp-14h]@5
-        int v26; // [sp+28h] [bp-10h]@3
-        unsigned int uCellID; // [sp+2Ch] [bp-Ch]@3
         unsigned int uCellX; // [sp+30h] [bp-8h]@5
         unsigned int uCellY; // [sp+34h] [bp-4h]@5
 
-        v23 = pRenderer->pActiveZBuffer;
-        pPlayer = pPlayers[uPlayerID];
-        v3 = a2;
-        pPlayer2 = pPlayers[uPlayerID];
-        pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_507958));
-        if ( v3 )
-            {
-            v4 = pIcons_LOD->LoadTexture("fr_strip", TEXTURE_16BIT_PALETTE);
-            pRenderer->DrawTextureIndexed(8u, 0x131u, pIcons_LOD->GetTexture(v4));
-            }
-        uCellID = 0;
-        v26 = (int)pPlayer->pInventoryIndices;
-        do
-            {
-            if ( *(int *)v26 > 0 )
-                {
-                v24 = *(int *)v26 - 1;
-                uCellY = 32 * (uCellID / 14) + 17;
-                pItem = &pPlayer->pInventoryItems[v24];
-                uCellX = 32 * (uCellID % 14) + 14;
-                pItem2 = pItem;
-                if ( pItem->uItemID )
-                    {
-                    v6 = pIcons_LOD->LoadTexture(pItemsTable->pItems[pItem->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-                    uTextureId = v6;
-                    v7 = pIcons_LOD->GetTexture(v6);
-                    v8 = v7->uTextureWidth;
-                    v9 = v7->uTextureHeight;
-                    v10 = v7->uTextureWidth;
+  pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_CharacterUI_InventoryBackground));
+  if (a2)
+    pRenderer->DrawTextureIndexed(8, 305, pIcons_LOD->LoadTexturePtr("fr_strip", TEXTURE_16BIT_PALETTE));
+
+  int i = 0;
+  for (uint i = 0; i < 126; ++i)
+  {
+    int v26 = (int)(player->pInventoryIndices + i);
+
+    if (player->pInventoryIndices[i] <= 0)
+      continue;
+
+    int item_idx = player->pInventoryIndices[i];
+    auto item = &player->pInventoryItems[item_idx - 1];
+    if (!item->uItemID)
+      continue;
+
+    uCellY = 32 * (i / 14) + 17;
+    uCellX = 32 * (i % 14) + 14;
+
+    uint item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+    v7 = pIcons_LOD->GetTexture(item_texture_id);
+
                     v11 = v7->uTextureWidth;
-                    if ( v10 < 14 )
+                    if (v11 < 14)
                         v11 = 14;
-                    if ( (v11 - 14) >> 5 == 0 && v8 < 32 )
-                        uCellX += (32 - v10) / 2;
-                    v12 = v7->uTextureWidth;
-                    if ( v10 < 14 )
-                        v12 = 14;
-                    v13 = v12 - 14;
-                    v14 = v7->uTextureHeight;
+
+                    if ( (v11 - 14) / 32 == 0 && v7->uTextureWidth < 32)
+                        uCellX += (32 - v7->uTextureWidth) / 2;
+                    v13 = v11 - 14;
                     LOBYTE(v13) = v13 & 0xE0;
                     v15 = v13 + 32;
-                    if ( v9 < 14 )
+                    v14 = v7->uTextureHeight;
+                    if (v14 < 14 )
                         v14 = 14;
-                    v16 = pItem->uAttributes;
-                    v17 = uCellX + ((v15 - v10) >> 1) + pSRZBufferLineOffsets[uCellY + ((((v14 - 14) & 0xFFFFFFE0) - v9 + 32) >> 1)];
-                    if ( !(v16 & 0xF0) )
-                        {
-                        if (pItem->Identified() || pCurrentScreen != SCREEN_HOUSE )
-                            {
-                            if (pItem->Broken())
-                                pRenderer->DrawTransparentRedShade(uCellX, uCellY, v7);
-                            else
-                                pRenderer->DrawTextureTransparent(uCellX, uCellY, v7);
-                            }
-                        else
-                            {
-                            pRenderer->DrawTransparentGreenShade(uCellX, uCellY, v7);
-                            }
-                        ZBuffer_Fill(&v23[v17], uTextureId, v24 + 1);
-                        pPlayer = pPlayer2;
-                        //goto LABEL_34;
-                        ++uCellID;
-                        v26 += 4;
-                        continue;
-                        }
-                    if ( (unsigned __int8)(v16 & 0xF0) != 16 )
-                        {
-                        if ( (unsigned __int8)(v16 & 0xF0) == 32 )
-                            {
-                            v20 = "sp28a";
-                            pTexture = pIcons_LOD->LoadTexturePtr(v20, TEXTURE_16BIT_PALETTE);
-                            dword_50C9A8 -= pEventTimer->uTimeElapsed;
-                            if ( dword_50C9A8 <= 0 )
-                                {
-                                dword_50C9A8 = 0;
-                                LOBYTE(pItem2->uAttributes) &= 0xFu;
-                                ptr_50C9A4 = 0;
-                                }
-                            v19 = (double)GetTickCount() * 0.1;
-                            pRenderer->_4A63E6(uCellX, uCellY, v7, pTexture, (signed __int64)v19, 0, 255);
-                            ZBuffer_Fill(&v23[v17], uTextureId, v24 + 1);
-                            pPlayer = pPlayer2;
-                            //goto LABEL_34;
-                            ++uCellID;
-                            v26 += 4;
-                            continue;
-                            }
-                        if ( (unsigned __int8)(v16 & 0xF0) == 64 )
-                            {
-                            v20 = "sp30a";
-                            pTexture = pIcons_LOD->LoadTexturePtr(v20, TEXTURE_16BIT_PALETTE);
-                            dword_50C9A8 -= pEventTimer->uTimeElapsed;
-                            if ( dword_50C9A8 <= 0 )
-                                {
-                                dword_50C9A8 = 0;
-                                LOBYTE(pItem2->uAttributes) &= 0xFu;
-                                ptr_50C9A4 = 0;
-                                }
-                            v19 = (double)GetTickCount() * 0.1;
-                            pRenderer->_4A63E6(uCellX, uCellY, v7, pTexture, (signed __int64)v19, 0, 255);
-                            ZBuffer_Fill(&v23[v17], uTextureId, v24 + 1);
-                            pPlayer = pPlayer2;
-                            //goto LABEL_34;
-                            ++uCellID;
-                            v26 += 4;
-                            continue;
-                            }
-                        if ( (unsigned __int8)(v16 & 0xF0) == 128 )
-                            {
-                            v20 = "sp91a";
-                            pTexture = pIcons_LOD->LoadTexturePtr(v20, TEXTURE_16BIT_PALETTE);
-                            dword_50C9A8 -= pEventTimer->uTimeElapsed;
-                            if ( dword_50C9A8 <= 0 )
-                                {
-                                dword_50C9A8 = 0;
-                                LOBYTE(pItem2->uAttributes) &= 0xFu;
-                                ptr_50C9A4 = 0;
-                                }
-                            v19 = (double)GetTickCount() * 0.1;
-                            pRenderer->_4A63E6(uCellX, uCellY, v7, pTexture, (signed __int64)v19, 0, 255);
-                            ZBuffer_Fill(&v23[v17], uTextureId, v24 + 1);
-                            pPlayer = pPlayer2;
-                            //goto LABEL_34;
-                            ++uCellID;
-                            v26 += 4;
-                            continue;
-                            }
-                        }
-                    v20 = "sptext01";
-                    pTexture = pIcons_LOD->LoadTexturePtr(v20, TEXTURE_16BIT_PALETTE);
-                    dword_50C9A8 -= pEventTimer->uTimeElapsed;
-                    if ( dword_50C9A8 <= 0 )
-                        {
-                        dword_50C9A8 = 0;
-                        LOBYTE(pItem2->uAttributes) &= 0xFu;
-                        ptr_50C9A4 = 0;
-                        }
-                    v19 = (double)GetTickCount() * 0.1;
-                    pRenderer->_4A63E6(uCellX, uCellY, v7, pTexture, (signed __int64)v19, 0, 255);
-                    ZBuffer_Fill(&v23[v17], uTextureId, v24 + 1);
-                    pPlayer = pPlayer2;
-                    }
-                }
-            //LABEL_34:
-            ++uCellID;
-            v26 += 4;
-            }
-            while ( uCellID < 126 );
-        }
+                    v17 = uCellX + ((v15 - v7->uTextureWidth) >> 1) + pSRZBufferLineOffsets[uCellY + ((((v14 - 14) & 0xFFFFFFE0) - v7->uTextureHeight + 32) >> 1)];
+
+
+    if (!(item->uAttributes & 0xF0))
+    {
+      if (item->Identified() || pCurrentScreen != SCREEN_HOUSE)
+      {
+        if (item->Broken())
+          pRenderer->DrawTransparentRedShade(uCellX, uCellY, v7);
+        else
+          pRenderer->DrawTextureTransparent(uCellX, uCellY, v7);
+      }
+      else
+        pRenderer->DrawTransparentGreenShade(uCellX, uCellY, v7);
 
-    //----- (0041A556) --------------------------------------------------------
-    void __cdecl draw_leather()
-        {
-        pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_Leather));
-        }
+      ZBuffer_Fill(&pRenderer->pActiveZBuffer[v17], item_texture_id, item_idx);
+      continue;
+    }
+    else
+    {
+      switch (item->uAttributes & 0xF0)
+      {
+        case ITEM_AURA_EFFECT_RED:    pTexture = pIcons_LOD->LoadTexturePtr("sptext01", TEXTURE_16BIT_PALETTE); break;
+        case ITEM_AURA_EFFECT_BLUE:   pTexture = pIcons_LOD->LoadTexturePtr("sp28a", TEXTURE_16BIT_PALETTE);    break;
+        case ITEM_AURA_EFFECT_GREEN:  pTexture = pIcons_LOD->LoadTexturePtr("sp30a", TEXTURE_16BIT_PALETTE);    break;
+        case ITEM_AURA_EFFECT_PURPLE: pTexture = pIcons_LOD->LoadTexturePtr("sp91a", TEXTURE_16BIT_PALETTE);    break;
+      }
+
+      _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+      if (_50C9A8_item_enchantment_timer <= 0)
+      {
+        _50C9A8_item_enchantment_timer = 0;
+        LOBYTE(item->uAttributes) &= 0xF;
+        ptr_50C9A4 = 0;
+      }
+
+      pRenderer->_4A63E6(uCellX, uCellY, v7, pTexture, GetTickCount() * 0.1, 0, 255);
+      ZBuffer_Fill(&pRenderer->pActiveZBuffer[v17], item_texture_id, item_idx);
+    }
+  }
+}
+
+//----- (0041A556) --------------------------------------------------------
+void draw_leather()
+{
+  pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_Leather));
+}
 
     //----- (0041A57E) --------------------------------------------------------
     void QuickRefDraw()
@@ -1101,7 +638,7 @@
           CharacterUI_SkillScreen_Draw();
         }
         sub_419379();
-        CharacterUI_SkillsTab_Draw(uPlayerIdx);
+        CharacterUI_SkillsTab_Draw(pPlayers[uPlayerIdx]);
         v6 = pIcons_LOD->LoadTexture("ib-cd2-d", TEXTURE_16BIT_PALETTE);
         pTexture = pIcons_LOD->GetTexture(v6);
         pButton = pCharacterScreen_SkillsBtn;
@@ -1120,7 +657,7 @@
       case WINDOW_CharacterWindow_Inventory:                                                        // inventory and other
         sub_4196A0();
         sub_419379();
-        CharacterUI_InventoryTab_Draw(uPlayerIdx, 0);
+        CharacterUI_InventoryTab_Draw(pPlayers[uPlayerIdx], false);
         v2 = pIcons_LOD->LoadTexture("ib-cd3-d", TEXTURE_16BIT_PALETTE);
         pTexture = pIcons_LOD->GetTexture(v2);
         pButton = pCharacterScreen_InventoryBtn;
@@ -1349,10 +886,10 @@
         if ( (item_MainHand4->uAttributes & 0xF0) == 128 )
           v167 = "sp91a";
         v16 = pIcons_LOD->LoadTexturePtr(v167, TEXTURE_16BIT_PALETTE);
-        dword_50C9A8 -= pEventTimer->uTimeElapsed;
-        if ( dword_50C9A8 <= 0 )
+        _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+        if ( _50C9A8_item_enchantment_timer <= 0 )
         {
-          dword_50C9A8 = 0;
+          _50C9A8_item_enchantment_timer = 0;
           item_MainHand4->uAttributes &= 0xFu;
           ptr_50C9A4 = 0;
         }
@@ -1396,10 +933,10 @@
         if ( (itemBow->uAttributes & 0xF0) == 128 )
           v168 = "sp91a";
         a2b = pIcons_LOD->LoadTexturePtr(v168, TEXTURE_16BIT_PALETTE);
-        dword_50C9A8 -= pEventTimer->uTimeElapsed;
-        if ( dword_50C9A8 <= 0 )
+        _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+        if ( _50C9A8_item_enchantment_timer <= 0 )
         {
-          dword_50C9A8 = 0;
+          _50C9A8_item_enchantment_timer = 0;
           itemBow->uAttributes &= 0xFu;
           ptr_50C9A4 = 0;
         }
@@ -1458,10 +995,10 @@
           if ( (item_Cloak->uAttributes & 0xF0) == 128 )
             v169 = "sp91a";
           v39 = pIcons_LOD->LoadTexturePtr(v169, TEXTURE_16BIT_PALETTE);
-          dword_50C9A8 -= pEventTimer->uTimeElapsed;
-          if ( dword_50C9A8 <= 0 )
+          _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+          if ( _50C9A8_item_enchantment_timer <= 0 )
           {
-            dword_50C9A8 = 0;
+            _50C9A8_item_enchantment_timer = 0;
             item_Cloak->uAttributes &= 0xFu;
             ptr_50C9A4 = 0;
           }
@@ -1526,10 +1063,10 @@
           if ( (item_Armor->uAttributes & 0xF0) == 128 )
             v170 = "sp91a";
           v51 = pIcons_LOD->LoadTexturePtr(v170, TEXTURE_16BIT_PALETTE);
-          dword_50C9A8 -= pEventTimer->uTimeElapsed;
-          if ( dword_50C9A8 <= 0 )
+          _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+          if ( _50C9A8_item_enchantment_timer <= 0 )
           {
-            dword_50C9A8 = 0;
+            _50C9A8_item_enchantment_timer = 0;
             item_Armor->uAttributes &= 0xFu;
             ptr_50C9A4 = 0;
           }
@@ -1582,10 +1119,10 @@
                 if ( (item_Armor->uAttributes & 0xF0) == 128 )
                   v173 = "sp91a";
                 v96 = (char *)pIcons_LOD->LoadTexturePtr(v173, TEXTURE_16BIT_PALETTE);
-                dword_50C9A8 -= pEventTimer->uTimeElapsed;
-                if ( dword_50C9A8 <= 0 )
+                _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+                if ( _50C9A8_item_enchantment_timer <= 0 )
                 {
-                  dword_50C9A8 = 0;
+                  _50C9A8_item_enchantment_timer = 0;
                   item_Armor->uAttributes &= 0xFu;
                   ptr_50C9A4 = 0;
                 }
@@ -1627,10 +1164,10 @@
               if ( (item_Armor->uAttributes & 0xF0) == 128 )
                 v178 = "sp91a";
               v96 = (char *)pIcons_LOD->LoadTexturePtr(v178, TEXTURE_16BIT_PALETTE);
-              dword_50C9A8 -= pEventTimer->uTimeElapsed;
-              if ( dword_50C9A8 <= 0 )
+              _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+              if ( _50C9A8_item_enchantment_timer <= 0 )
               {
-                dword_50C9A8 = 0;
+                _50C9A8_item_enchantment_timer = 0;
                 item_Armor->uAttributes &= 0xFu;
                 ptr_50C9A4 = 0;
               }
@@ -1691,10 +1228,10 @@
           if ( (item_Boot->uAttributes & 0xF0) == 128 )
             v171 = "sp91a";
           v63 = pIcons_LOD->LoadTexturePtr(v171, TEXTURE_16BIT_PALETTE);
-          dword_50C9A8 -= pEventTimer->uTimeElapsed;
-          if ( dword_50C9A8 <= 0 )
+          _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+          if ( _50C9A8_item_enchantment_timer <= 0 )
           {
-            dword_50C9A8 = 0;
+            _50C9A8_item_enchantment_timer = 0;
             item_Boot->uAttributes &= 0xFu;
             ptr_50C9A4 = 0;
           }
@@ -1762,10 +1299,10 @@
             if ( (item_Belt->uAttributes & 0xF0) == 128 )
               v172 = "sp91a";
             v77 = pIcons_LOD->LoadTexturePtr(v172, TEXTURE_16BIT_PALETTE);
-            dword_50C9A8 -= pEventTimer->uTimeElapsed;
-            if ( dword_50C9A8 <= 0 )
+            _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+            if ( _50C9A8_item_enchantment_timer <= 0 )
             {
-              dword_50C9A8 = 0;
+              _50C9A8_item_enchantment_timer = 0;
               item_Belt->uAttributes &= 0xFu;
               ptr_50C9A4 = 0;
             }
@@ -1837,10 +1374,10 @@
               if ( (item_CloakCollar->uAttributes & 0xF0) == 128 )
                 v179 = "sp91a";
               a2i = pIcons_LOD->LoadTexturePtr(v179, TEXTURE_16BIT_PALETTE);
-              dword_50C9A8 -= pEventTimer->uTimeElapsed;
-              if ( dword_50C9A8 <= 0 )
+              _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+              if ( _50C9A8_item_enchantment_timer <= 0 )
               {
-                dword_50C9A8 = 0;
+                _50C9A8_item_enchantment_timer = 0;
                 item_CloakCollar->uAttributes &= 0xFu;
                 ptr_50C9A4 = 0;
               }
@@ -1901,10 +1438,10 @@
           if ( (item_Helm->uAttributes & 0xF0) == 128 )
             v180 = "sp91a";
           v129 = pIcons_LOD->LoadTexturePtr(v180, TEXTURE_16BIT_PALETTE);
-          dword_50C9A8 -= pEventTimer->uTimeElapsed;
-          if ( dword_50C9A8 <= 0 )
+          _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+          if ( _50C9A8_item_enchantment_timer <= 0 )
           {
-            dword_50C9A8 = 0;
+            _50C9A8_item_enchantment_timer = 0;
             item_Helm->uAttributes &= 0xFu;
             ptr_50C9A4 = 0;
           }
@@ -1965,10 +1502,10 @@
         if ( (item_MainHand3->uAttributes & 0xF0) == 128 )
           v182 = "sp91a";
         v140 = pIcons_LOD->LoadTexturePtr(v182, TEXTURE_16BIT_PALETTE);
-        dword_50C9A8 -= pEventTimer->uTimeElapsed;
-        if ( dword_50C9A8 <= 0 )
+        _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+        if ( _50C9A8_item_enchantment_timer <= 0 )
         {
-          dword_50C9A8 = 0;
+          _50C9A8_item_enchantment_timer = 0;
           item_MainHand3->uAttributes &= 0xFu;
           ptr_50C9A4 = 0;
         }
@@ -2037,10 +1574,10 @@
         if ( (item_Shield->uAttributes & 0xF0) == 128 )
           v183 = "sp91a";
         v157 = pIcons_LOD->LoadTexturePtr(v183, TEXTURE_16BIT_PALETTE);
-        dword_50C9A8 -= pEventTimer->uTimeElapsed;
-        if ( dword_50C9A8 <= 0 )
+        _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+        if ( _50C9A8_item_enchantment_timer <= 0 )
         {
-          dword_50C9A8 = 0;
+          _50C9A8_item_enchantment_timer = 0;
           item_Shield->uAttributes &= 0xFu;
           ptr_50C9A4 = 0;
         }
@@ -2114,10 +1651,10 @@
         if ( (item->uAttributes & 0xF0) == 128 )
           spell_texture_name = "sp91a";
         spell_texture = pIcons_LOD->LoadTexturePtr(spell_texture_name, TEXTURE_16BIT_PALETTE);
-        dword_50C9A8 -= pEventTimer->uTimeElapsed;
-        if ( dword_50C9A8 <= 0 )
+        _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+        if ( _50C9A8_item_enchantment_timer <= 0 )
         {
-          dword_50C9A8 = 0;
+          _50C9A8_item_enchantment_timer = 0;
           item->uAttributes &= 0xFu;
           ptr_50C9A4 = 0;
         }
@@ -2159,10 +1696,10 @@
       if ( (item->uAttributes & 0xF0) == 128 )
         spell_texture_name = "sp91a";
       spell_texture = pIcons_LOD->LoadTexturePtr(spell_texture_name, TEXTURE_16BIT_PALETTE);
-      dword_50C9A8 -= pEventTimer->uTimeElapsed;
-      if ( dword_50C9A8 <= 0 )
+      _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+      if ( _50C9A8_item_enchantment_timer <= 0 )
       {
-        dword_50C9A8 = 0;
+        _50C9A8_item_enchantment_timer = 0;
         item->uAttributes &= 0xFu;
         ptr_50C9A4 = 0;
       }
@@ -2207,10 +1744,10 @@
     if ( (item->uAttributes & 0xF0) == 128 )
       spell_texture_name = "sp91a";
     spell_texture = pIcons_LOD->LoadTexturePtr(spell_texture_name, TEXTURE_16BIT_PALETTE);
-    dword_50C9A8 -= pEventTimer->uTimeElapsed;
-    if ( dword_50C9A8 <= 0 )
+    _50C9A8_item_enchantment_timer -= pEventTimer->uTimeElapsed;
+    if ( _50C9A8_item_enchantment_timer <= 0 )
     {
-      dword_50C9A8 = 0;
+      _50C9A8_item_enchantment_timer = 0;
       item->uAttributes &= 0xFu;
       ptr_50C9A4 = 0;
     }
@@ -2593,7 +2130,7 @@
     }
 
 //----- (00418511) --------------------------------------------------------
-char __fastcall CharacterUI_StatsTab_Draw(unsigned int uPlayerID)
+char CharacterUI_StatsTab_Draw(unsigned int uPlayerID)
 {
         Player *pPlayer; // edi@1
         unsigned int v4; // eax@2
--- a/UIHouses.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/UIHouses.cpp	Sun May 12 09:38:30 2013 +0600
@@ -3017,7 +3017,7 @@
     case HOUSE_DIALOGUE_SHOP_SELL:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[199], 0);
       if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
         return;
@@ -3036,7 +3036,7 @@
     case HOUSE_DIALOGUE_SHOP_IDENTIFY:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[197], 0);
       if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
         return;
@@ -3064,7 +3064,7 @@
     case HOUSE_DIALOGUE_SHOP_REPAIR:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[198], 0);
       if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win())
             return;
@@ -3085,7 +3085,7 @@
     case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];//sell
       pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];//identify
       pShopOptions[2] = pGlobalTXT_LocalizationStrings[179];//repair
@@ -3575,7 +3575,7 @@
     case HOUSE_DIALOGUE_SHOP_SELL:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[199], 0);
       if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
         return;
@@ -3593,7 +3593,7 @@
     case HOUSE_DIALOGUE_SHOP_IDENTIFY:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[197], 0);
       if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
         return;
@@ -3619,7 +3619,7 @@
     case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];
       pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];
       all_text_height = 0;
@@ -4173,7 +4173,7 @@
     case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       pShopOptions[0] = pGlobalTXT_LocalizationStrings[200]; //"Sell"
       pShopOptions[1] = pGlobalTXT_LocalizationStrings[113]; //"Identify"
       pShopOptions[2] = pGlobalTXT_LocalizationStrings[179]; //"Repair"
@@ -4211,7 +4211,7 @@
     case HOUSE_DIALOGUE_SHOP_SELL:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[199], 0);//"Select the Item to Sell"
       if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win())
         return;
@@ -4231,7 +4231,7 @@
     case HOUSE_DIALOGUE_SHOP_IDENTIFY:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[197], 0); //"Select the Item to Identify"	
       if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
       {
@@ -4265,7 +4265,7 @@
     case HOUSE_DIALOGUE_SHOP_REPAIR:
     {
       draw_leather();
-      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
       DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[198], 0);
       if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win())
         return;
@@ -5903,7 +5903,7 @@
   if ( dialog_menu_id == HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT )
   {
     draw_leather();
-    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
     pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];// "Sell"
     pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];// "Identify"
     pShopOptions[2] = pGlobalTXT_LocalizationStrings[179];// "Repair"
@@ -5942,7 +5942,7 @@
   if ( dialog_menu_id == HOUSE_DIALOGUE_SHOP_SELL)
   {
     draw_leather();
-    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
     DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[199], 0);// "Select the Item to Sell"
     if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()
       || (v11 = pMouse->GetCursorPos(&v107)->x - 14,
@@ -5962,7 +5962,7 @@
   if ( dialog_menu_id == HOUSE_DIALOGUE_SHOP_IDENTIFY)
   {
     draw_leather();
-    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
     DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[197], 0);// "Select the Item to Identify"
     if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
     {
@@ -5999,7 +5999,7 @@
   if ( dialog_menu_id == HOUSE_DIALOGUE_SHOP_REPAIR)
   {
     draw_leather();
-    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
     DrawTextAtStatusBar(pGlobalTXT_LocalizationStrings[198], 0);// "Select the Item to Repair"
     if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()
       || (pTextHeight = pMouse->GetCursorPos(&v110)->x - 14,
--- a/UIPartyCreation.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/UIPartyCreation.cpp	Sun May 12 09:38:30 2013 +0600
@@ -653,16 +653,16 @@
 // 4E28F8: using guessed type int pCurrentScreen;
 
 //----- (0049750E) --------------------------------------------------------
-void __cdecl DeleteCCharFont()
+void DeleteCCharFont()
 {
   pAllocator->FreeChunk(pFontCChar);
   pFontCChar = 0;
 }
 //----- (00497526) --------------------------------------------------------
-bool __cdecl PlayerCreationUI_Loop()
+bool PlayerCreationUI_Loop()
 {
   //RGBTexture *pTexture; // ebx@1
-  UINT v1; // esi@1
+  //UINT v1; // esi@1
   unsigned int v2; // ecx@3
   LONG uMouseX; // edi@6
   LONG uMouseY; // eax@6
@@ -691,7 +691,6 @@
   //Player *pPlayer;
 
   //pTexture = &pTexture_PCX;
-  v1 = 0;
   v26 = 0;
   pTexture_PCX.Release();
   pTexture_PCX.Load("makeme.pcx", 0);
@@ -703,7 +702,7 @@
   SetCurrentMenuID((MENU_STATE)v2);
   while ( GetCurrentMenuID() == MENU_CREATEPARTY )
   {
-    if ( pAsyncMouse != (void *)v1 )
+    if (pAsyncMouse)
       pAsyncMouse->_46B736_consume_click_lists(1);
     uMouseX = pMouse->GetCursorPos(&v25)->x;
     uMouseY = pMouse->GetCursorPos(&v25)->y;
@@ -727,7 +726,7 @@
       while ( pControlsHead != (GUIButton *)v1 );
     }*/
 
-    while ( PeekMessageA(&Msg, (HWND)v1, v1, v1, PM_REMOVE) )
+    while ( PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE) )
     {
       if ( Msg.message == WM_QUIT )
         Game_DeinitializeAndTerminate(0);
@@ -751,15 +750,15 @@
         v26 = 1;
         //v2 = 0;
         //goto LABEL_27;
-        SetCurrentMenuID((MENU_STATE)MENU_MAIN);
+        SetCurrentMenuID(MENU_MAIN);
         continue;
       }
-      if ( uGameState == GAME_STATE_6 )//if click OK in PlayerCreation Window
+      if ( uGameState == GAME_STATE_STARTING_NEW_GAME )//if click OK in PlayerCreation Window
       {
-        uGameState = v1;
+        uGameState = GAME_STATE_PLAYING;
         //v2 = 1;
         //goto LABEL_27;
-        SetCurrentMenuID((MENU_STATE)MENU_NEWGAME);
+        SetCurrentMenuID(MENU_NEWGAME);
         continue;
       }
     }
@@ -768,6 +767,7 @@
   pGUIWindow_CurrentMenu->Release();
   pIcons_LOD->_4114F2();
 
+  int v1 = 0;
   memset(v20, 0, 32);
   do
   {
@@ -890,7 +890,7 @@
 
       for (uint k = 0; k < 138; k++)
       {
-        if (&player->pInventoryItems[k])
+        if (player->pInventoryItems[k].uItemID)
           player->pInventoryItems[k].SetIdentified();
       }
     }
--- a/UIPopup.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/UIPopup.cpp	Sun May 12 09:38:30 2013 +0600
@@ -1395,7 +1395,7 @@
 
 
 //----- (00417BB5) --------------------------------------------------------
-const char *__fastcall CharacterUI_GetSkillDescText(unsigned int uPlayerID, PLAYER_SKILL_TYPE uPlayerSkillType)
+const char *CharacterUI_GetSkillDescText(unsigned int uPlayerID, PLAYER_SKILL_TYPE uPlayerSkillType)
 {
     //enum PLAYER_SKILL_TYPE v2; // esi@1
     //unsigned int v3; // ebx@1
--- a/mm7_1.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_1.cpp	Sun May 12 09:38:30 2013 +0600
@@ -1320,6 +1320,9 @@
   unsigned __int16 v6; // [sp-4h] [bp-14h]@7
 
 
+  extern void set_default_ui_skin();
+  set_default_ui_skin();
+
     if (align == PartyAlignment_Evil)
     {
       if ( bReplace )
@@ -1357,7 +1360,7 @@
 
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uExitCancelTextureId], "ib-bcu-c", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50795C], "evtnpc-c", 2);
-        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507958], "fr_inven-c", 2);
+        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_CharacterUI_InventoryBackground], "fr_inven-c", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Parchment], "parchment", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B4], "cornr_ll-c", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B0], "cornr_lr-c", 2);
@@ -1397,7 +1400,7 @@
         uTextureID_PlayerBuff_Hammerhands = pIcons_LOD->LoadTexture("isg-03-c", TEXTURE_16BIT_PALETTE);
         uTextureID_PlayerBuff_PainReflection = pIcons_LOD->LoadTexture("isg-04-c", TEXTURE_16BIT_PALETTE);
         uTextureID_50795C = pIcons_LOD->LoadTexture("evtnpc-c", TEXTURE_16BIT_PALETTE);
-        uTextureID_507958 = pIcons_LOD->LoadTexture("fr_inven", TEXTURE_16BIT_PALETTE);
+        uTextureID_CharacterUI_InventoryBackground = pIcons_LOD->LoadTexture("fr_inven", TEXTURE_16BIT_PALETTE);
         pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeC");
         pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnim_WizardEye->uIconID);
         pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchC");
@@ -1442,7 +1445,7 @@
         pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnum_Torchlight->uIconID);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uExitCancelTextureId], "ib-bcu-a", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50795C], "evtnpc", 2);
-        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507958], "fr_inven", 2);
+        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_CharacterUI_InventoryBackground], "fr_inven", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Parchment], "parchment", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B4], "cornr_ll", 2);
         pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B0], "cornr_lr", 2);
@@ -1482,7 +1485,7 @@
         uTextureID_PlayerBuff_Hammerhands = pIcons_LOD->LoadTexture("isg-03-a", TEXTURE_16BIT_PALETTE);
         uTextureID_PlayerBuff_PainReflection = pIcons_LOD->LoadTexture("isg-04-a", TEXTURE_16BIT_PALETTE);
         uTextureID_50795C = pIcons_LOD->LoadTexture("evtnpc", TEXTURE_16BIT_PALETTE);
-        uTextureID_507958 = pIcons_LOD->LoadTexture("fr_inven", TEXTURE_16BIT_PALETTE);
+        uTextureID_CharacterUI_InventoryBackground = pIcons_LOD->LoadTexture("fr_inven", TEXTURE_16BIT_PALETTE);
         pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeA");
         pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnim_WizardEye->uIconID);
         pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchA");
@@ -1538,7 +1541,7 @@
       pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnum_Torchlight->uIconID);
       pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uExitCancelTextureId], "ib-bcu-b", 2);
       pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50795C], "evtnpc-b", 2);
-      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507958], "fr_inven-b", 2);
+      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_CharacterUI_InventoryBackground], "fr_inven-b", 2);
       pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Parchment], "parchment", 2);
       pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B4], "cornr_ll-b", 2);
       pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B0], "cornr_lr-b", 2);
--- a/mm7_2.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_2.cpp	Sun May 12 09:38:30 2013 +0600
@@ -5440,28 +5440,17 @@
 }
 
 //----- (00458244) --------------------------------------------------------
-unsigned int __fastcall SkillToMastery(unsigned __int16 a1)
-{
-  unsigned int result; // eax@1
-
-  result = 1;                                   // Normal
-  if ( HIBYTE(a1) & 1 )
-  {
-    result = 4;                                 // Grandmaster
-  }
-  else
-  {
-    if ( (a1 & 0x80u) == 0 )
-    {
-      if ( a1 & 0x40 )
-        result = 2;                             // Expert
-    }
-    else
-    {
-      result = 3;                               // Master
-    }
-  }
-  return result;
+unsigned int SkillToMastery(unsigned int value)
+{
+  switch (value & 0x1C0)
+  {
+    case 0x100: return 4;     // Grandmaster
+    case 0x80:  return 3;     // Master
+    case 0x40:  return 2;     // Expert
+    case 0x00:  return 1;     // Normal
+    default:
+      assert(false);
+  }
 }
 
 //----- (0045828B) --------------------------------------------------------
@@ -6283,10 +6272,6 @@
 void SaveNewGame()
 {
   FILE *v3; // eax@7
-  LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3
-  LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4
-  LOD::Directory save_game_dir; // [sp+12Ch] [bp-4Ch]@9
-  LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3
   void *pSave; // [sp+170h] [bp-8h]@3
 
   if ( pVideoPlayer->AnyMovieLoaded() )
@@ -6294,21 +6279,24 @@
   pSave = pAllocator->AllocNamedChunk(0, 1000000, 0);
   pNew_LOD->CloseWriteFile();
   remove("data\\new.lod");
-  this_.Reset();
+
+  LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3
   strcpy(this_.LodVersion, "MMVII");
   strcpy(this_.LodDescription, "newmaps for MMVII");
   this_.LODSize = 100;
   this_.dword_0000A8 = 0;
+
+  LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3
   a3.dword_000018 = 0;
   a3.word_00001E = 0;
   strcpy(a3.pFilename, "current");
   pNew_LOD->CreateNewLod(&this_, &a3, "data\\new.lod");
-  if ( pNew_LOD->LoadFile("data\\new.lod", 0) )
+  if (pNew_LOD->LoadFile("data\\new.lod", false))
   {
     pNew_LOD->CreateTempFile();
     pNew_LOD->uNumSubDirs = 0;
-    pDir.Reset();
-
+
+    LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4
     for (int i = pGames_LOD->uNumSubDirs / 2; i < pGames_LOD->uNumSubDirs; ++i)
     {
       memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir));
@@ -6316,11 +6304,13 @@
       fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, v3);
       pNew_LOD->AppendDirectory(&pDir, pSave);
     }
-    save_game_dir.Reset();
+
+    LOD::Directory save_game_dir; // [sp+12Ch] [bp-4Ch]@9
     strcpy(pSavegameHeader[0].pLocationName, "out01.odm");
     strcpy(save_game_dir.pFilename, "header.bin");
-    save_game_dir.uDataSize = 100;
+    save_game_dir.uDataSize = sizeof(SavegameHeader);
     pNew_LOD->AppendDirectory(&save_game_dir, &pSavegameHeader[0]);
+
     pNew_LOD->FixDirectoryOffsets();
     pParty->vPrevPosition.y = 0;
     pParty->vPrevPosition.x = 12552;
@@ -9382,7 +9372,7 @@
   //bool v9; // edx@16
   //OtherOverlay *v10; // esi@44
   //signed int v11; // edi@44
-  unsigned int v12; // ecx@56
+  //unsigned int v12; // ecx@56
   HANDLE v13; // eax@68
   unsigned int startms; // [sp+8h] [bp-24h]@55
   RECT Rect; // [sp+Ch] [bp-20h]@15
@@ -9464,21 +9454,17 @@
     while ( 1 )
     {
       MainMenu_Loop();
-      uGameState = GAME_STATE_0;
+      uGameState = GAME_STATE_PLAYING;
 //LABEL_21:
       while ( 1 )
       {
-        switch (uGameState)
-        {
-          case GAME_FINISHED:
-            pGame->Deinitialize();
-            return true;
-        }
-        if (GetCurrentMenuID() == MENU_FINISHED)
-        {
-          uGameState = GAME_FINISHED;
-          continue;
-        }
+        if (uGameState == GAME_FINISHED ||
+            GetCurrentMenuID() == MENU_EXIT_GAME)
+        {
+          pGame->Deinitialize();
+          return true;
+        }
+
         if (GetCurrentMenuID() == MENU_NEWGAME)
         {
           if ( pAudioPlayer->hAILRedbook )
@@ -9499,13 +9485,17 @@
           pGame->pCShow->PlayMovie(MOVIE_Emerald, 0);
           SaveNewGame();
           pGame->Loop();
-          if ( uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU )
+
+          if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
           {
             SetCurrentMenuID(MENU_NEWGAME);
-            uGameState = GAME_STATE_0;
+            uGameState = GAME_STATE_PLAYING;
             continue;
           }
-          break;
+          else if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
+            break;
+
+          assert(false && "Invalid game state");
         }
         if (GetCurrentMenuID() == MENU_CREDITS)
         {
@@ -9517,7 +9507,7 @@
         }
         if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
         {
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
         }
         else
         {
@@ -9554,22 +9544,20 @@
 LABEL_49:
         if ( uGameState == GAME_STATE_3 )
         {
-          v12 = 5;
-          SetCurrentMenuID((MENU_STATE)v12);
-          //goto LABEL_21;
-          uGameState = GAME_STATE_0;
+          SetCurrentMenuID(MENU_5);
+          uGameState = GAME_STATE_PLAYING;
           continue;
         }
         if ( uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU )
         {
           SetCurrentMenuID(MENU_NEWGAME);
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
           continue;
         }
         if ( uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)// from the loaded game
         {
           pAudioPlayer->StopChannels(-1, -1);
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
           break;
         }
       }
@@ -9847,20 +9835,20 @@
 {
   switch (m)
   {
-    case -1:               return L"-1";
-    case MENU_MAIN:        return L"MENU_MAIN";
-    case MENU_NEWGAME:     return L"MENU_NEWGAME";
-    case MENU_CREDITS:     return L"MENU_CREDITS";
-    case MENU_SAVELOAD:    return L"MENU_SAVELOAD";
-    case MENU_FINISHED:    return L"MENU_FINISHED";
-    case MENU_5:           return L"MENU_5";
-    case MENU_CREATEPARTY: return L"MENU_CREATEPARTY";
+    case -1:                return L"-1";
+    case MENU_MAIN:         return L"MENU_MAIN";
+    case MENU_NEWGAME:      return L"MENU_NEWGAME";
+    case MENU_CREDITS:      return L"MENU_CREDITS";
+    case MENU_SAVELOAD:     return L"MENU_SAVELOAD";
+    case MENU_EXIT_GAME:    return L"MENU_EXIT_GAME";
+    case MENU_5:            return L"MENU_5";
+    case MENU_CREATEPARTY:  return L"MENU_CREATEPARTY";
     case MENU_NAMEPANELESC: return L"MENU_NAMEPANELESC";
-    case MENU_CREDITSPROC: return L"MENU_CREDITSPROC";
+    case MENU_CREDITSPROC:  return L"MENU_CREDITSPROC";
     case MENU_LoadingProcInMainMenu: return L"MENU_LoadingProcInMainMenu";
-    case MENU_10:          return L"MENU_10";
+    case MENU_10:           return L"MENU_10";
     case MENU_CREDITSCLOSE: return L"MENU_CREDITSCLOSE";
-    default:               return L"unk";
+    default:                return L"unk";
   };
 };
 void SetCurrentMenuID(MENU_STATE uMenu)
--- a/mm7_4.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_4.cpp	Sun May 12 09:38:30 2013 +0600
@@ -2794,7 +2794,7 @@
 LABEL_135:
     if ( pCurrentScreen != SCREEN_REST
       && (!v51 || dword_5C35C0) )
-      uGameState = GAME_STATE_8;
+      uGameState = GAME_STATE_PARTY_DIED;
   }
   if ( uActiveCharacter )
   {
--- a/mm7_5.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_5.cpp	Sun May 12 09:38:30 2013 +0600
@@ -1036,7 +1036,7 @@
                       if ( ptr_50C9A4 && ptr_50C9A4->uItemID )
                       {
                         LOBYTE(ptr_50C9A4->uAttributes) &= 0xFu;
-                        dword_50C9A8 = 0;
+                        _50C9A8_item_enchantment_timer = 0;
                         ptr_50C9A4 = 0;
                       }
                       if ( pGUIWindow_Settings )
@@ -2231,7 +2231,7 @@
           continue;
         case UIMSG_C4:
 			__debugbreak;
-          uGameState = GAME_STATE_0;
+          uGameState = GAME_STATE_PLAYING;
           strcpy((char *)pKeyActionMap->pPressedKeysBuffer, "2");
           goto LABEL_524;
         case UIMSG_DD:
@@ -3341,7 +3341,7 @@
           break;
         case UIMSG_ExitToWindows:
           GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
-          SetCurrentMenuID(MENU_FINISHED);
+          SetCurrentMenuID(MENU_EXIT_GAME);
           break;
         case UIMSG_PlayerCreation_SelectAttribute:
           pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
@@ -3435,7 +3435,7 @@
           if ( PlayerCreation_ComputeAttributeBonus() || !PlayerCreation_Chose4Skills() )
             GameUI_Footer_TimeLeft = GetTickCount() + 4000;
           else
-            uGameState = GAME_STATE_6;
+            uGameState = GAME_STATE_STARTING_NEW_GAME;
           break;
         case UIMSG_PlayerCreationClickReset:
           GUIWindow::Create(527, 431, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnReset, 0);
@@ -9223,7 +9223,7 @@
 
 //----- (0040DEF3) --------------------------------------------------------
 unsigned short TargetColor( unsigned __int16 r, unsigned __int16 g, unsigned __int16 b )
-    {
+{
   return ((unsigned int)b >> (8 - LOBYTE(pRenderer->uTargetBBits))) | pRenderer->uTargetGMask & (g << (LOBYTE(pRenderer->uTargetGBits) + 
                            LOBYTE(pRenderer->uTargetBBits) - 8)) | pRenderer->uTargetRMask & (r << (LOBYTE(pRenderer->uTargetGBits) + 
                            LOBYTE(pRenderer->uTargetRBits) + LOBYTE(pRenderer->uTargetBBits) - 8));
@@ -10282,7 +10282,7 @@
         {
           pRenderer->ClearZBuffer(0, 479);
           draw_leather();
-          CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+          CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
           pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
         }
         continue;
@@ -10330,7 +10330,7 @@
       {
         pRenderer->ClearZBuffer(0, 479);
         draw_leather();
-        CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+        CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
         CharacterUI_DrawPaperdoll(uActiveCharacter);
         pRenderer->DrawTextureTransparent(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uTextureID_x_x_u));
         continue;
@@ -10781,7 +10781,7 @@
           HIDWORD(v27->uExpireTime) = HIDWORD(v32);
           v27->uAttributes = v32;
         }
-        dword_50C9A8 = 256;
+        _50C9A8_item_enchantment_timer = 256;
         goto LABEL_92;
       }
       v36 = (70.0 - (double)pParty->pPickedItem.uEnchantmentType) * 0.01;
@@ -11459,7 +11459,7 @@
 }
 
 //----- (00417AD4) --------------------------------------------------------
-unsigned int __fastcall GetSkillColor(unsigned int uPlayerClass, PLAYER_SKILL_TYPE uPlayerSkillType, signed int skill_level)
+unsigned int GetSkillColor(unsigned int uPlayerClass, PLAYER_SKILL_TYPE uPlayerSkillType, signed int skill_level)
 {
   int v8; // eax@10
   int v12; // eax@14
--- a/mm7_6.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_6.cpp	Sun May 12 09:38:30 2013 +0600
@@ -3874,7 +3874,7 @@
 					v69->uAttributes |= 8u;
 				}
 				v69->uAttributes |= 0x10u;
-				dword_50C9A8 = 256;
+				_50C9A8_item_enchantment_timer = 256;
 				LODWORD(v727) = 1;
 				break;
 			}
@@ -4964,7 +4964,7 @@
 			continue;
 		}
 		*((int *)v243 + 5) |= 0x40u;
-					dword_50C9A8 = 256;
+					_50C9A8_item_enchantment_timer = 256;
 					LODWORD(v727) = 1;
 					break;
 			}
@@ -5034,7 +5034,7 @@
 LABEL_612:
 								_this->uItemID |= 0x20u;
 
-								dword_50C9A8 = 256;
+								_50C9A8_item_enchantment_timer = 256;
 								LODWORD(v727) = 1;
 								break;
 							}
@@ -5386,7 +5386,7 @@
 								+ rand() % 10;//(pItemsTable->field_116D8[19] - pItemsTable->field_116D8[18] + 1);
 		}
 		v294->uAttributes |= 0x20u;
-		dword_50C9A8 = 256;
+		_50C9A8_item_enchantment_timer = 256;
 		LODWORD(v727) = 1;
 		break;
 		}
@@ -7131,7 +7131,7 @@
 			*(int *)(v592 + 20) |= 8u;
 		}
 		*(char *)(v592 + 20) |= 0x80u;
-		dword_50C9A8 = 256;
+		_50C9A8_item_enchantment_timer = 256;
 		LODWORD(v727) = 1;
 		break;
 			}
--- a/mm7_data.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_data.cpp	Sun May 12 09:38:30 2013 +0600
@@ -507,10 +507,10 @@
 __int16 RightClickPortraitXmin[4]={0x14, 0x83, 0xF2, 0x165};
 __int16 RightClickPortraitXmax[4]={0x53, 0xC6, 0x138, 0x1A7};
 void *off_4E2A12; // stat_string_control_button_count
-int pArmorSkills[5]={ 9, 10, 11, 8, 30};
-int pWeaponSkills[9]={3, 5, 2, 6, 4, 0, 1, 31, 7};
-int pMiscSkills[12]={35, 33, 24, 21, 32, 36, 29, 25, 22, 26, 23, 34};
-int pMagicSkills[9]={12, 13, 14, 15, 16, 17, 18, 19, 20};
+int pArmorSkills[5]  = {PLAYER_SKILL_LEATHER, PLAYER_SKILL_CHAIN,      PLAYER_SKILL_PLATE,        PLAYER_SKILL_SHIELD,  PLAYER_SKILL_DODGE};
+int pWeaponSkills[9] = {PLAYER_SKILL_AXE,     PLAYER_SKILL_BOW,        PLAYER_SKILL_DAGGER,       PLAYER_SKILL_MACE,    PLAYER_SKILL_SPEAR,      PLAYER_SKILL_STAFF,    PLAYER_SKILL_SWORD,       PLAYER_SKILL_UNARMED,    PLAYER_SKILL_BLASTER};
+int pMiscSkills[12]  = {PLAYER_SKILL_ALCHEMY, PLAYER_SKILL_ARMSMASTER, PLAYER_SKILL_BODYBUILDING, PLAYER_SKILL_ITEM_ID, PLAYER_SKILL_MONSTER_ID, PLAYER_SKILL_LEARNING, PLAYER_SKILL_TRAP_DISARM, PLAYER_SKILL_MEDITATION, PLAYER_SKILL_MERCHANT, PLAYER_SKILL_PERCEPTION, PLAYER_SKILL_REPAIR, PLAYER_SKILL_STEALING};
+int pMagicSkills[9]  = {PLAYER_SKILL_FIRE,    PLAYER_SKILL_AIR,        PLAYER_SKILL_WATER,        PLAYER_SKILL_EARTH,   PLAYER_SKILL_SPIRIT,     PLAYER_SKILL_MIND,     PLAYER_SKILL_BODY,        PLAYER_SKILL_LIGHT,      PLAYER_SKILL_DARK};
 unsigned int pHealthBarPos[4] = {22, 137, 251, 366};
 unsigned int pManaBarPos[4] = {102, 217, 331, 447};
 char _4E2AD8_ui_colors[72];
@@ -1502,7 +1502,7 @@
 int quick_spell_at_page; // weak
 char byte_506550; // weak
 char *aMoonPhaseNames[5];
-int dword_506568; // weak
+int _506568_autonote_type; // weak
 char bRecallingBeacon; // weak
 int uLastPointedObjectID; // weak
 //unsigned __int8 bMonsterInfoUI_bDollInitialized;
@@ -1604,7 +1604,7 @@
 int dword_50C998_turnbased_icon_1A; // weak
 int uSpriteID_Spell11; // idb
 _UNKNOWN unk_50C9A0; // weak
-int dword_50C9A8; // weak
+int _50C9A8_item_enchantment_timer; // weak
 int dword_50C9AC; // weak
 int dword_50C9D0; // weak
 int dword_50C9D4; // weak
--- a/mm7_data.h	Sun May 12 09:38:20 2013 +0600
+++ b/mm7_data.h	Sun May 12 09:38:30 2013 +0600
@@ -930,7 +930,7 @@
 extern int quick_spell_at_page; // weak
 extern char byte_506550; // weak
 extern char *aMoonPhaseNames[5];
-extern int dword_506568; // weak
+extern int _506568_autonote_type; // 506568
 extern char bRecallingBeacon; // weak
 extern int uLastPointedObjectID; // weak
 //extern unsigned __int8 bMonsterInfoUI_bDollInitialized;
@@ -1032,7 +1032,7 @@
 extern int dword_50C998_turnbased_icon_1A; // weak
 extern int uSpriteID_Spell11; // idb
 extern _UNKNOWN unk_50C9A0; // weak
-extern int dword_50C9A8; // weak
+extern int _50C9A8_item_enchantment_timer; // weak
 extern int dword_50C9AC; // weak
 extern int dword_50C9D0; // weak
 extern int dword_50C9D4; // weak
@@ -1594,16 +1594,12 @@
 signed int __thiscall GetConditionDrawColor(unsigned int uConditionIdx); // idb
 char __fastcall sub_4179BC_draw_tooltip(const char *a1, const char *a2); // idb
 void FillAwardsData();
-void __cdecl sub_419220();
-void __cdecl sub_419379();
-void __cdecl CharacterUI_SkillScreen_Draw();
-void __cdecl sub_4196A0();
-char __fastcall CharacterUI_SkillsTab_Draw(unsigned int uPlayerID); // idb
-void CharacterUI_AwardsTab_Draw(unsigned int uPlayerID); // idb
+void sub_419220();
+void sub_419379();
+void CharacterUI_SkillScreen_Draw();
+void sub_4196A0();
 unsigned int __fastcall GetSizeInInventorySlots(unsigned int uNumPixels);
-void __fastcall CharacterUI_InventoryTab_Draw(unsigned int uPlayerID, char a2);
 void __cdecl draw_leather();
-void __thiscall CharacterUI_CharacterScreen_Draw(unsigned int uPlayerIdx); // idb
 void __cdecl GameUI_DrawRightPanelItems();
 void __cdecl GameUI_DrawFoodAndGold();
 void __cdecl GameUI_DrawLifeManaBars();
@@ -1793,7 +1789,7 @@
 int __cdecl j_SetSomeItemsNames();
 
 
-unsigned int __fastcall SkillToMastery(unsigned __int16 a1);
+unsigned int SkillToMastery(unsigned int skill_value);
 unsigned int __fastcall GetSpellColor(signed int a1);
 void *__thiscall unknown_vdtor_6(void *_this, bool a2);
 unsigned short * MakeScreenshot(signed int width, signed int height);
--- a/stru6.cpp	Sun May 12 09:38:20 2013 +0600
+++ b/stru6.cpp	Sun May 12 09:38:30 2013 +0600
@@ -1286,11 +1286,6 @@
   PlayerBuffAnim *v4; // esi@1
   const char *v6; // [sp-4h] [bp-10h]@2
 
-  //v3 = this;
-  //v4 = &array_0[uPlayerID];
-  //v4[32].uSpellIconID_ = 0;    pPlayerBuffs[]::field_4
-  //v4[32].uSpellID = uSpellID;  pPlayerBuffs[]::bRender
-
   v4 = &pPlayerBuffs[uPlayerID];
   v4->uSpellAnimTimeElapsed = 0;
   v4->bRender = uSpellID != 0;
@@ -1298,7 +1293,6 @@
   switch (uSpellID)
   {
     case SPELL_DISEASE:
-      //__debugbreak(); // spell id == 153 wtf , curse probably ? happening when attacked by harpies /disease(Ritor1)/
       v6 = "zapp";
     break;
       
@@ -1367,16 +1361,12 @@
     case SPELL_BODY_PROTECTION_FROM_MAGIC:  v6 = "spell75"; break;
 
     default:
-      //v4[32].uSpellID = 0;
       v4->bRender = false;
       return;
   }
   
-  //v4[33].uSpellIconID = pIconsFrameTable->FindIcon(v6);
   v4->uSpellIconID = pIconsFrameTable->FindIcon(v6);
-  //if ( v4[32].uSpellID )
   if (v4->bRender)
-    //v3->array_0[(signed __int16)uPlayerID + 33].uSpellAnimLength = 8 * pIconsFrameTable->pIcons[v4[33].uSpellIconID].uAnimLength;
     v4->uSpellAnimTime = 8 * pIconsFrameTable->pIcons[v4->uSpellIconID].uAnimLength;
 }