diff mm7_2.cpp @ 0:9c0607679772

init
author Ritor1
date Sat, 12 Jan 2013 09:45:18 +0600
parents
children 89240115d392
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mm7_2.cpp	Sat Jan 12 09:45:18 2013 +0600
@@ -0,0 +1,17436 @@
+#include <io.h>
+#include <direct.h>
+#include <assert.h>
+
+#include "MapInfo.h"
+#include "Game.h"
+#include "GUIWindow.h"
+#include "GUIButton.h"
+#include "GUIFont.h"
+#include "Party.h"
+#include "AudioPlayer.h"
+#include "Outdoor.h"
+#include "IndoorCamera.h"
+#include "Overlays.h"
+#include "Monsters.h"
+#include "Arcomage.h"
+#include "LOD.h"
+#include "Actor.h"
+#include "Allocator.h"
+#include "Events.h"
+#include "Viewport.h"
+#include "FrameTableInc.h"
+#include "Math.h"
+#include "LayingItem.h"
+#include "ObjectList.h"
+#include "Chest.h"
+#include "PaletteManager.h"
+#include "DecorationList.h"
+#include "SaveLoad.h"
+#include "stru123.h"
+#include "stru287.h"
+#include "Time.h"
+#include "IconFrameTable.h"
+#include "GUIProgressBar.h"
+#include "stru157.h"
+#include "Bink_Smacker.h"
+#include "TileFrameTable.h"
+#include "PlayerFrameTable.h"
+#include "Awards.h"
+#include "Autonotes.h"
+#include "stru160.h"
+#include "stru279.h"
+#include "TurnEngine.h"
+#include "FactionTable.h"
+#include "StorylineTextTable.h"
+#include "Random.h"
+#include "stru277.h"
+#include "stru298.h"
+#include "stru12.h"
+#include "stru351.h"
+#include "Events2D.h"
+#include "stru159.h"
+#include "Log.h"
+
+#include "mm7_data.h"
+
+
+//----- (004B4F4F) --------------------------------------------------------
+char *__cdecl sub_4B4F4F()
+{
+  const char *v0; // esi@1
+  const char *v1; // ST10_4@1
+  unsigned __int16 v2; // ST0C_2@1
+  int v3; // eax@1
+  GUIWindow v5; // [sp+8h] [bp-54h]@1
+
+  memcpy(&v5, ptr_507BC0, sizeof(v5));
+  v0 = pGlobalTXT_LocalizationStrings[672];
+  v1 = pGlobalTXT_LocalizationStrings[672];
+  v5.uFrameX = 483;
+  v5.uFrameWidth = 148;
+  v5.uFrameZ = 334;
+  v2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
+  v3 = pFontArrus->CalcTextHeight(v0, &v5, 0, 0);
+  return v5.DrawTitleText(pFontArrus, 0, (310 - v3) / 2 + 18, v2, v1, 3u);
+}
+
+
+
+//----- (004B68EA) --------------------------------------------------------
+bool __fastcall sub_4B68EA(int a1)
+{
+  signed int v1; // edi@1
+  int *v2; // esi@1
+  int v3; // ecx@2
+
+  v1 = 0;
+  v2 = &dword_4F0E10[a1];
+  while ( 1 )
+  {
+    v3 = 8 * *((char *)v2 + v1);
+    if ( *(&byte_4F09B1[pParty->uDaysPlayed % 7] + v3 * 4) )
+    {
+      if ( !dword_4F09CC[v3] || (unsigned __int16)_449B57_test_bit(pParty->_award_bits, LOWORD(dword_4F09CC[v3])) )
+        break;
+    }
+    ++v1;
+    if ( v1 >= 4 )
+      return 0;
+  }
+  return 1;
+}
+
+
+
+//----- (004B7911) --------------------------------------------------------
+void __cdecl sub_4B7911()
+{
+  GUIWindow *v0; // eax@4
+  int v1; // eax@10
+  int v2; // esi@10
+  GUIFont *v3; // ST20_4@20
+  int v4; // eax@20
+  MonsterInfo *v5; // edi@21
+  unsigned int v6; // ST20_4@21
+  char *v7; // ST1C_4@21
+  unsigned int v8; // eax@21
+  int v9; // esi@21
+  char *v10; // eax@23
+  signed int v11; // ebx@24
+  signed int i; // esi@26
+  int v13; // eax@27
+  GUIWindow *v14; // ecx@28
+  __int64 v15; // qax@28
+  signed int v16; // ebx@28
+  int v17; // ebx@28
+  unsigned __int8 v18; // sf@28
+  char **v19; // edi@29
+  GUIButton *v20; // eax@30
+  GUIButton *v21; // esi@30
+  int v22; // eax@30
+  unsigned int v23; // ecx@30
+  unsigned __int16 v24; // ax@30
+  GUIWindow a1; // [sp+Ch] [bp-110h]@21
+  GUIWindow w; // [sp+60h] [bp-BCh]@21
+  GUIWindow _this; // [sp+B4h] [bp-68h]@1
+  int v28; // [sp+108h] [bp-14h]@1
+  int v29; // [sp+10Ch] [bp-10h]@28
+  int v30; // [sp+110h] [bp-Ch]@1
+  int v31; // [sp+114h] [bp-8h]@29
+  GUIFont *pOutString; // [sp+118h] [bp-4h]@21
+
+  memcpy(&_this, ptr_507BC0, sizeof(_this));
+  _this.uFrameX = 483;
+  _this.uFrameWidth = 148;
+  _this.uFrameZ = 334;
+  v28 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+  v30 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
+  sprintf(pTmpBuf, "%s: %d", pGlobalTXT_LocalizationStrings[605], pParty->uFine);
+  _this.DrawTitleText(pFontArrus, 0, 0x104u, v30, pTmpBuf, 3u);
+  if ( dword_F8B19C == 1 )
+  {
+    v11 = 1;
+    pOutString = 0;
+    pShopOptions[0] = pGlobalTXT_LocalizationStrings[604];
+    if ( pParty->uFine )
+    {
+      pShopOptions[1] = pGlobalTXT_LocalizationStrings[603];
+      v11 = 2;
+    }
+    for ( i = 0; i < v11; ++i )
+    {
+      v13 = pFontArrus->CalcTextHeight(pShopOptions[i], &_this, 0, 0);
+      pOutString = (GUIFont *)((char *)pOutString + v13);
+    }
+    v29 = (100 - (signed int)pOutString) / v11;
+    v14 = pDialogueWindow;
+    v15 = 80 - v11 * (100 - (signed int)pOutString) / v11 - (signed int)pOutString;
+    v16 = v15 - HIDWORD(v15);
+    LODWORD(v15) = pDialogueWindow->pStartingPosActiveItem;
+    HIDWORD(v15) = v15 + pDialogueWindow->pNumPresenceButton;
+    v17 = (v16 >> 1) - v29 / 2 + 158;
+    v18 = -pDialogueWindow->pNumPresenceButton < 0;
+    pOutString = (GUIFont *)pDialogueWindow->pStartingPosActiveItem;
+    if ( v18 ^ __OFSUB__((int)v15, HIDWORD(v15)) )
+    {
+      v31 = 2;
+      v19 = pShopOptions;
+      do
+      {
+        v20 = v14->GetControl((unsigned int)pOutString);
+        v21 = v20;
+        v20->uY = v29 + v17;
+        v22 = pFontArrus->CalcTextHeight(*v19, &_this, 0, 0);
+        v23 = v21->uY;
+        v21->uHeight = v22;
+        v17 = v23 + v22 - 1;
+        v21->uW = v17;
+        v24 = v30;
+        if ( pDialogueWindow->pCurrentPosActiveItem != v31 )
+          v24 = v28;
+        _this.DrawTitleText(pFontArrus, 0, v23, v24, *v19, 3u);
+        v14 = pDialogueWindow;
+        ++v31;
+        ++v19;
+        pOutString = (GUIFont *)((char *)pOutString + 1);
+      }
+      while ( (signed int)pOutString < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
+    }
+  }
+  else
+  {
+    if ( dword_F8B19C != 99 )
+    {
+      if ( dword_F8B19C != 100 )
+        return;
+      v0 = ptr_507BC0;
+      if ( ptr_507BC0->field_40 == 1 )
+      {
+        sprintf(pTmpBuf, "%s\n%s", pGlobalTXT_LocalizationStrings[606], pGlobalTXT_LocalizationStrings[112]);
+        _this.DrawTitleText(pFontArrus, 0, 0x92u, v30, pTmpBuf, 3u);
+        _this.DrawTitleText(pFontArrus, 0, 0xBAu, v28, (const char *)pKeyActionMap->pPressedKeysBuffer, 3u);
+        v3 = pFontArrus;
+        v4 = pFontArrus->GetLineWidth((const char *)pKeyActionMap->pPressedKeysBuffer);
+        _this.DrawFlashingInputCursor(v4 / 2 + 80, 185, v3);
+        return;
+      }
+      if ( ptr_507BC0->field_40 == 2 )
+      {
+        v1 = atoi((const char *)pKeyActionMap->pPressedKeysBuffer);
+        v2 = v1;
+        if ( v1 <= 0 )
+        {
+LABEL_8:
+          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          {
+            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
+            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+            ++pMessageQueue_50CBD0->uNumMessages;
+          }
+          return;
+        }
+        if ( v1 > pParty->uNumGold )
+        {
+          HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
+          v2 = pParty->uNumGold;
+        }
+        if ( v2 > pParty->uFine )
+          v2 = pParty->uFine;
+        Party::TakeGold(v2);
+        pParty->uFine -= v2;
+        if ( pParty->uFine < 0 )
+          pParty->uFine = 0;
+        if ( uActiveCharacter )
+          pPlayers[uActiveCharacter]->PlaySound(81, 0);
+        v0 = ptr_507BC0;
+      }
+      else
+      {
+        if ( ptr_507BC0->field_40 != 3 )
+          return;
+      }
+      v0->field_40 = 0;
+      goto LABEL_8;
+    }
+    v5 = &pMonsterStats->pInfos[word_F8B1A0];
+    v6 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+    v7 = v5->pName;
+    v8 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
+    sprintf(pTmpBuf, &byte_4F0F98, v8, v7, v6);
+    sprintf(pTmpBuf2, dword_F8B1A4, pTmpBuf, 100 * v5->uLevel);
+    ptr_F8B1E8 = pTmpBuf2;
+    memcpy(&a1, pDialogueWindow, sizeof(a1));
+    w.uFrameWidth = 458;
+    w.uFrameZ = 457;
+    pOutString = pFontArrus;
+    v9 = pFontArrus->CalcTextHeight(pTmpBuf2, &w, 13, 0) + 7;
+    if ( 352 - v9 < 8 )
+    {
+      pOutString = pFontCreate;
+      v9 = pFontCreate->CalcTextHeight(ptr_F8B1E8, &w, 13, 0) + 7;
+    }
+
+    auto pTex = (uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0);
+    pRenderer->_4A6A68(
+      8u,
+      352 - v9,
+      pTex,
+      (pTex ? pTex->uTextureHeight : 26) - v9);
+    pRenderer->DrawTextureIndexed(8u, 347 - v9, pTexture_591428);
+    v10 = FitTextInAWindow(ptr_F8B1E8, pOutString, &w, 0xDu, 0);
+    a1.DrawText(pOutString, 13, 354 - v9, 0, v10, 0, 0, 0);
+  }
+}
+// F8B19C: using guessed type int dword_F8B19C;
+// F8B1A0: using guessed type __int16 word_F8B1A0;
+
+//----- (004B7D7E) --------------------------------------------------------
+void __cdecl _4B7D7E_bank()
+{
+  GUIWindow *v0; // eax@4
+  int v1; // ecx@5
+  int v2; // eax@6
+  unsigned int v3; // esi@6
+  GUIFont *v4; // ST10_4@12
+  int v5; // eax@12
+  int v6; // eax@19
+  unsigned int v7; // esi@19
+  unsigned __int16 v8; // ax@27
+  unsigned __int16 v9; // ax@29
+  char *v10; // [sp-8h] [bp-70h]@11
+  char *v11; // [sp-4h] [bp-6Ch]@11
+  GUIWindow _this; // [sp+Ch] [bp-5Ch]@1
+  __int16 v13[2]; // [sp+60h] [bp-8h]@1
+  __int16 v14[2]; // [sp+64h] [bp-4h]@1
+
+  memcpy(&_this, ptr_507BC0, sizeof(_this));
+  _this.uFrameX = 483;
+  _this.uFrameWidth = 148;
+  _this.uFrameZ = 334;
+  *(int *)v13 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+  *(int *)v14 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
+  sprintf(pTmpBuf, "%s: %d", pGlobalTXT_LocalizationStrings[25], pParty->uNumGoldInBank);
+  _this.DrawTitleText(pFontArrus, 0, 0xDCu, v14[0], pTmpBuf, 3u);
+  if ( dword_F8B19C != 1 )
+  {
+    if ( dword_F8B19C == 7 )
+    {
+      v0 = ptr_507BC0;
+      if ( ptr_507BC0->field_40 != 1 )
+      {
+        v1 = ptr_507BC0->field_40 - 2;
+        if ( ptr_507BC0->field_40 == 2 )
+        {
+          v6 = atoi((const char *)pKeyActionMap->pPressedKeysBuffer);
+          v7 = v6;
+          if ( !v6 )
+          {
+LABEL_17:
+            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            {
+              pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+              pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
+              *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+              ++pMessageQueue_50CBD0->uNumMessages;
+            }
+            return;
+          }
+          if ( v6 > pParty->uNumGold )
+          {
+            HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
+            v7 = pParty->uNumGold;
+          }
+          if ( v7 )
+          {
+            Party::TakeGold(v7);
+            pParty->uNumGoldInBank += v7;
+            if ( uActiveCharacter )
+              pPlayers[uActiveCharacter]->PlaySound(81, 0);
+          }
+          v0 = ptr_507BC0;
+LABEL_16:
+          v0->field_40 = 0;
+          goto LABEL_17;
+        }
+LABEL_15:
+        if ( v1 != 1 )
+          return;
+        goto LABEL_16;
+      }
+      v11 = pGlobalTXT_LocalizationStrings[112];
+      v10 = pGlobalTXT_LocalizationStrings[60];
+    }
+    else
+    {
+      if ( dword_F8B19C != 8 )
+        return;
+      v0 = ptr_507BC0;
+      if ( ptr_507BC0->field_40 != 1 )
+      {
+        v1 = ptr_507BC0->field_40 - 2;
+        if ( ptr_507BC0->field_40 == 2 )
+        {
+          ptr_507BC0->field_40 = 0;
+          v2 = atoi((const char *)pKeyActionMap->pPressedKeysBuffer);
+          v3 = v2;
+          if ( v2 )
+          {
+            if ( v2 > pParty->uNumGoldInBank )
+            {
+              HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
+              v3 = pParty->uNumGoldInBank;
+            }
+            if ( v3 )
+            {
+              Party::SetGold(pParty->uNumGold + v3);
+              pParty->uNumGoldInBank -= v3;
+            }
+          }
+          goto LABEL_17;
+        }
+        goto LABEL_15;
+      }
+      v11 = pGlobalTXT_LocalizationStrings[112];
+      v10 = pGlobalTXT_LocalizationStrings[244];
+    }
+    sprintf(pTmpBuf, "%s\n%s", v10, v11);
+    _this.DrawTitleText(pFontArrus, 0, 0x92u, v14[0], pTmpBuf, 3u);
+    _this.DrawTitleText(pFontArrus, 0, 0xBAu, v13[0], (const char *)pKeyActionMap->pPressedKeysBuffer, 3u);
+    v4 = pFontArrus;
+    v5 = pFontArrus->GetLineWidth((const char *)pKeyActionMap->pPressedKeysBuffer);
+    _this.DrawFlashingInputCursor(v5 / 2 + 80, 185, v4);
+    return;
+  }
+  v8 = v14[0];
+  if ( pDialogueWindow->pCurrentPosActiveItem != 2 )
+    v8 = v13[0];
+  _this.DrawTitleText(pFontArrus, 0, 0x92u, v8, pGlobalTXT_LocalizationStrings[60], 3u);
+  v9 = v14[0];
+  if ( pDialogueWindow->pCurrentPosActiveItem != 3 )
+    v9 = v13[0];
+  _this.DrawTitleText(pFontArrus, 0, 0xB0u, v9, pGlobalTXT_LocalizationStrings[244], 3u);
+}
+// F8B19C: using guessed type int dword_F8B19C;
+
+//----- (004B8285) --------------------------------------------------------
+void __cdecl sub_4B8285_prolly_draw_arcomage_result()
+{
+  GUIWindow *v0; // ebx@1
+  Player *v1; // edi@1
+  double v2; // st7@1
+  signed int v3; // ebx@1
+  int v4; // ecx@1
+  int v5; // esi@3
+  signed int v6; // edi@5
+  int v7; // ecx@5
+  GUIWindow *v8; // edi@16
+  signed int v9; // esi@16
+  unsigned int v10; // esi@18
+  int v11; // eax@18
+  unsigned int v12; // eax@19
+  int v13; // eax@21
+  int v14; // ecx@26
+  GUIButton *v15; // eax@28
+  GUIButton *v16; // esi@28
+  int v17; // eax@28
+  char *v18; // eax@30
+  int v19; // eax@30
+  unsigned int v20; // ecx@30
+  int v21; // edx@30
+  int v22; // eax@30
+  unsigned __int16 v23; // ax@30
+  int v24; // eax@34
+  int v25; // eax@34
+  char *v26; // esi@36
+  int v27; // edi@46
+  unsigned int v28; // eax@53
+  unsigned int v29; // eax@55
+  unsigned int v30; // eax@57
+  signed int v31; // eax@59
+  unsigned int v32; // eax@61
+  GUIWindow *v33; // edi@64
+  int v34; // eax@64
+  int v35; // ecx@64
+  int v36; // esi@64
+  char v37; // sf@64
+  GUIButton *v38; // eax@65
+  int v39; // edx@69
+  int v40; // ecx@69
+  int v41; // ecx@69
+  int v42; // ecx@70
+  unsigned int v43; // edx@70
+  int v44; // edx@71
+  int v45; // ecx@71
+  int v46; // ecx@72
+  int v47; // eax@74
+  signed int v48; // edi@77
+  signed int i; // esi@79
+  int v50; // eax@80
+  GUIWindow *v51; // ecx@81
+  _QWORD v52; // qax@81
+  signed int v53; // edi@81
+  int v54; // edi@81
+  GUIButton *v55; // esi@83
+  const char **v56; // eax@83
+  int v57; // eax@83
+  unsigned int v58; // ecx@83
+  Player *v59; // edx@83
+  unsigned __int16 v60; // ax@83
+  int v61; // eax@99
+  int v62; // edi@99
+  char *v63; // eax@99
+  GUIFont *v64; // edx@99
+  GUIFont *v65; // edi@100
+  unsigned int v66; // [sp-10h] [bp-284h]@75
+  unsigned __int16 v67; // [sp-Ch] [bp-280h]@75
+  int v68; // [sp-Ch] [bp-280h]@99
+  char *v69; // [sp-8h] [bp-27Ch]@75
+  int v70; // [sp-8h] [bp-27Ch]@99
+  unsigned int v71; // [sp-4h] [bp-278h]@75
+  const char *v72; // [sp-4h] [bp-278h]@93
+  unsigned int v73; // [sp-4h] [bp-278h]@99
+  char Dest; // [sp+Ch] [bp-268h]@55
+  char v75; // [sp+70h] [bp-204h]@59
+  char a1; // [sp+D4h] [bp-1A0h]@57
+  char v77; // [sp+138h] [bp-13Ch]@59
+  GUIWindow v78; // [sp+19Ch] [bp-D8h]@99
+  GUIWindow v79; // [sp+1F0h] [bp-84h]@1
+  char *Str[2]; // [sp+244h] [bp-30h]@30
+  unsigned int v81; // [sp+24Ch] [bp-28h]@1
+  unsigned __int8 v82; // [sp+253h] [bp-21h]@59
+  int v83; // [sp+254h] [bp-20h]@1
+  __int16 v84[2]; // [sp+258h] [bp-1Ch]@1
+  Player *v85; // [sp+25Ch] [bp-18h]@1
+  int v86; // [sp+260h] [bp-14h]@18
+  unsigned __int8 v87; // [sp+266h] [bp-Eh]@59
+  unsigned __int8 v88; // [sp+267h] [bp-Dh]@57
+  int v89; // [sp+268h] [bp-Ch]@1
+  unsigned __int8 v90; // [sp+26Fh] [bp-5h]@55
+  GUIFont *pOutString; // [sp+270h] [bp-4h]@3
+
+  v0 = ptr_507BC0;
+  memcpy(&v79, ptr_507BC0, sizeof(v79));
+  v85 = pPlayers[uActiveCharacter];
+  v1 = v85;
+  v79.uFrameX = 483;
+  v79.uFrameWidth = 148;
+  v79.uFrameZ = 334;
+  v81 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+  *(int *)v84 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
+  //v2 = p2DEvents_minus1__20[13 * (unsigned int)v0->ptr_1C];
+  v2 = p2DEvents[(unsigned int)v0->ptr_1C - 1].fPriceMultiplier;
+  *(float *)&v83 = v2;
+  *(float *)&v89 = v2 * v2;
+  v3 = (signed __int64)(*(float *)&v89 * 0.1);
+  v4 = v3 * (100 - v1->GetMerchant()) / 100;
+  if ( v4 < v3 / 3 )
+    v4 = v3 / 3;
+  v5 = 1;
+  pOutString = (GUIFont *)v4;
+  if ( v4 <= 0 )
+    pOutString = (GUIFont *)1;
+  v6 = (signed __int64)(*(float *)&v89 * *(float *)&v83 * 0.0099999998);
+  v7 = v6 * (100 - v85->GetMerchant()) / 100;
+  if ( v7 < v6 / 3 )
+    v7 = v6 / 3;
+  v83 = v7;
+  if ( v7 <= 0 )
+  {
+    v7 = 1;
+    v83 = 1;
+  }
+  if ( dword_F8B19C > 101 )
+  {
+    if ( dword_F8B19C == 102 )
+    {
+      v65 = pFontArrus;
+      pOutString = pFontArrus;
+      strcpy(pTmpBuf, pNPCTopics[354].pText);
+      v78.uFrameWidth = 460;
+      v78.uFrameZ = 452;
+      v62 = v65->CalcTextHeight(pTmpBuf, &v78, 12, 0) + 7;
+      if ( 352 - v62 < 8 )
+      {
+        pOutString = pFontCreate;
+        v62 = pFontCreate->CalcTextHeight(pTmpBuf, &v78, 12, 0) + 7;
+      }
+
+      auto pTex = (uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0);
+      pRenderer->_4A6A68(
+        8u,
+        352 - v62,
+        pTex,
+        (pTex ? pTex->uTextureHeight : 26) - v62);
+
+      pRenderer->DrawTextureIndexed(8u, 347 - v62, pTexture_591428);
+      v73 = 0;
+      v70 = 0;
+      v68 = 0;
+      v63 = FitTextInAWindow(pTmpBuf, pOutString, &v78, 0xCu, 0);
+      v64 = pOutString;
+    }
+    else
+    {
+      if ( dword_F8B19C != 103 )
+      {
+        if ( dword_F8B19C != 104 || pArcomageGame->bGameInProgress == 1 )
+          return;
+        v26 = pTmpBuf;
+        if ( pArcomageGame->uGameResult )
+        {
+          if ( pArcomageGame->uGameResult == 1 )
+            v72 = pGlobalTXT_LocalizationStrings[640];// You won!
+          else
+            v72 = pGlobalTXT_LocalizationStrings[641];// You lost!
+        }
+        else
+        {
+          v72 = pGlobalTXT_LocalizationStrings[639];// A tie!
+        }
+        strcpy(pTmpBuf, v72);
+LABEL_97:
+        v71 = 3;
+        v69 = v26;
+        v67 = v84[0];
+        v66 = (174 - pFontArrus->CalcTextHeight(v26, &v79, 0, 0)) / 2 + 138;
+        goto LABEL_98;
+      }
+      strcpy(pTmpBuf, pNPCTopics[(uint)ptr_507BC0->ptr_1C + 247].pText);
+      v78.uFrameWidth = 460;
+      v78.uFrameZ = 452;
+      v61 = pFontArrus->CalcTextHeight(pTmpBuf, &v78, 12, 0);
+      v62 = v61 + 7;
+
+      auto pTex = (uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : nullptr);
+      pRenderer->_4A6A68(
+        8u,
+        352 - (v61 + 7),
+        pTex,
+        (pTex ? pTex->uTextureHeight : 26) - (v61 + 7));
+
+      pRenderer->DrawTextureIndexed(8u, 347 - v62, pTexture_591428);
+      v73 = 0;
+      v70 = 0;
+      v68 = 0;
+      v63 = FitTextInAWindow(pTmpBuf, pFontArrus, &v78, 0xCu, 0);
+      v64 = pFontArrus;
+    }
+    ptr_507BC0->DrawText(v64, 12, 354 - v62, 0, v63, v68, v70, v73);
+    return;
+  }
+  if ( dword_F8B19C != 101 )
+  {
+    if ( dword_F8B19C != 1 )
+    {
+      if ( dword_F8B19C == 15 )
+      {
+        if ( pParty->uNumGold >= (unsigned int)pOutString )
+        {
+          Party::TakeGold((unsigned int)pOutString);
+          v27 = (int)ptr_507BC0->ptr_1C;
+          HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 2);
+          dword_F8B19C = 0;
+          while ( sub_4BD8B5() )
+            ;
+          sub_4B1D27();
+          pVideoPlayer->Unload();
+          ptr_507BC0->Release();
+          ptr_507BC0 = 0;
+          if ( pMessageQueue_50CBD0->uNumMessages )
+            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+          pMessageQueue_50CBD0->pMessages[0].eType = (UIMessageType)409;
+          pMessageQueue_50CBD0->pMessages[0].param = v27;
+          pMessageQueue_50CBD0->pMessages[0].field_8 = 1;
+LABEL_51:
+          ++pMessageQueue_50CBD0->uNumMessages;
+          return;
+        }
+      }
+      else
+      {
+        if ( dword_F8B19C != 16 )
+        {
+          if ( dword_F8B19C != 96 || !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+            return;
+          v8 = pDialogueWindow;
+          *(float *)&v89 = 0.0;
+
+          //v9 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)ptr_507BC0->ptr_1C] * 500.0);
+          v9 = (signed __int64)(p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].flt_24 * 500.0);
+
+          pOutString = (GUIFont *)(v9 * (100 - v85->GetMerchant()) / 100);
+          if ( (signed int)pOutString < v9 / 3 )
+            pOutString = (GUIFont *)(v9 / 3);
+          v10 = v8->pStartingPosActiveItem;
+          v11 = v10 + v8->pNumPresenceButton;
+          v86 = 0;
+          if ( (signed int)v10 < v11 )
+          {
+            do
+            {
+              v12 = v8->GetControl(v10)->uControlParam - 36;
+              if ( byte_4ED970_skill_learn_ability_by_class_table[v85->uClass][v12] && !v85->pActiveSkills[v12] )
+              {
+                v13 = pFontArrus->CalcTextHeight(pSkillNames[v12], &v79, 0, 0);
+                v89 += v13;
+                ++v86;
+              }
+              ++v10;
+            }
+            while ( (signed int)v10 < v8->pStartingPosActiveItem + v8->pNumPresenceButton );
+            if ( v86 )
+            {
+              sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], pOutString);
+              v79.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
+              pOutString = (GUIFont *)((149 - v89) / v86);
+              if ( (149 - v89) / v86 > 32 )
+                pOutString = (GUIFont *)32;
+              v14 = (149 - v86 * (signed int)pOutString - v89) / 2 - (signed int)pOutString / 2 + 162;
+              v89 = v8->pStartingPosActiveItem;
+              v83 = v14;
+              if ( v89 < v89 + v8->pNumPresenceButton )
+              {
+                v86 = 2;
+                do
+                {
+                  v15 = v8->GetControl(v89);
+                  v16 = v15;
+                  v17 = v15->uControlParam - 36;
+                  if ( !byte_4ED970_skill_learn_ability_by_class_table[v85->uClass][v17] || v85->pActiveSkills[v17] )
+                  {
+                    v16->uW = 0;
+                    v16->uHeight = 0;
+                    v16->uY = 0;
+                  }
+                  else
+                  {
+                    v18 = pSkillNames[v17];
+                    v16->uY = (unsigned int)((char *)pOutString + v83);
+                    Str[1] = v18;
+                    v19 = pFontArrus->CalcTextHeight(v18, &v79, 0, 0);
+                    v20 = v16->uY;
+                    v21 = v86;
+                    v16->uHeight = v19;
+                    v22 = v19 + v20 - 1;
+                    v16->uW = v22;
+                    v83 = v22;
+                    v23 = v84[0];
+                    if ( pDialogueWindow->pCurrentPosActiveItem != v21 )
+                      v23 = v81;
+                    v79.DrawTitleText(pFontArrus, 0, v20, v23, Str[1], 3u);
+                  }
+                  v24 = v8->pNumPresenceButton;
+                  ++v89;
+                  v25 = v8->pStartingPosActiveItem + v24;
+                  ++v86;
+                }
+                while ( v89 < v25 );
+              }
+              return;
+            }
+          }
+          v26 = pTmpBuf;
+          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v85->pName, pClassNames[v85->uClass]);
+          strcat(pTmpBuf, "\n \n");
+          strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
+          goto LABEL_97;
+        }
+        *(_QWORD *)Str = pParty->uNumFoodRations;
+        //if ( (double)pParty->uNumFoodRations >= p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C] )
+        if ( (double)pParty->uNumFoodRations >= p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].fPriceMultiplier )
+        {
+          ShowStatusBarString(pGlobalTXT_LocalizationStrings[140], 2u);
+          if ( uActiveCharacter )
+            pPlayers[uActiveCharacter]->PlaySound(67, 0);
+          goto LABEL_43;
+        }
+        if ( pParty->uNumGold >= v7 )
+        {
+          Party::TakeGold(v7);
+          //pParty->uNumFoodRations = (signed __int64)p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C];
+          pParty->uNumFoodRations = (signed __int64)p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].fPriceMultiplier;
+          HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 3);
+          v5 = 1;
+LABEL_43:
+          if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+            return;
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v5;
+          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+          goto LABEL_51;
+        }
+      }
+      ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
+      HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, 4);
+      goto LABEL_43;
+    }
+    if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+      return;
+    v28 = *(int *)v84;
+    if ( pDialogueWindow->pCurrentPosActiveItem != 2 )
+      v28 = v81;
+    sprintf(&Dest, format_4E2DC8, v28);
+    sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[178], pOutString);
+    strcat(&Dest, pTmpBuf2);
+    v90 = pFontArrus->CalcTextHeight(&Dest, &v79, 0, 0);
+    strcat(&Dest, "\n \n");
+    v29 = *(int *)v84;
+    if ( pDialogueWindow->pCurrentPosActiveItem != 3 )
+      v29 = v81;
+    sprintf(&a1, format_4E2DC8, v29);
+    sprintf(pTmpBuf2,
+      pGlobalTXT_LocalizationStrings[86],
+      //(signed __int64)p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C],
+      (signed __int64)p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].fPriceMultiplier,
+      v83);
+    strcat(&a1, pTmpBuf2);
+    v88 = pFontArrus->CalcTextHeight(&a1, &v79, 0, 0);
+    strcat(&a1, "\n \n");
+    v30 = *(int *)v84;
+    if ( pDialogueWindow->pCurrentPosActiveItem != 4 )
+      v30 = v81;
+    sprintf(&v77, format_4E2DC8, v30);
+    strcat(&v77, pGlobalTXT_LocalizationStrings[160]);
+    v82 = pFontArrus->CalcTextHeight(&v77, &v79, 0, 0);
+    strcat(&v77, "\n \n");
+    v75 = 0;
+    v87 = 0;
+    v31 = (signed int)ptr_507BC0->ptr_1C;
+    if ( v31 >= 108 && v31 <= 120 )
+    {
+      v32 = *(int *)v84;
+      if ( pDialogueWindow->pCurrentPosActiveItem != 5 )
+        v32 = v81;
+      sprintf(&v75, format_4E2DC8, v32);
+      strcat(&v75, pGlobalTXT_LocalizationStrings[611]);
+      v87 = pFontArrus->CalcTextHeight(&v75, &v79, 0, 0);
+    }
+    v33 = pDialogueWindow;
+    Str[1] = (char *)pDialogueWindow;
+    v34 = pDialogueWindow->pStartingPosActiveItem;
+    v35 = v34 + pDialogueWindow->pNumPresenceButton;
+    v36 = LOBYTE(pFontArrus->uFontHeight) - 3;
+    v37 = -pDialogueWindow->pNumPresenceButton < 0;
+    pOutString = (GUIFont *)pDialogueWindow->pStartingPosActiveItem;
+    if ( !(v37 ^ __OFSUB__(v34, v35)) )
+    {
+LABEL_75:
+      sprintf(pTmpBuf, "%s%s%s%s", &Dest, &a1, &v77, &v75);
+      v71 = 3;
+      v69 = pTmpBuf;
+      v67 = 0;
+      v66 = 146;
+LABEL_98:
+      v79.DrawTitleText(pFontArrus, 0, v66, v67, v69, v71);
+      return;
+    }
+    while ( 1 )
+    {
+      v38 = v33->GetControl((unsigned int)pOutString);
+      if ( v38->uControlParam == 15 )
+      {
+        v46 = v90;
+        v38->uHeight = v90;
+        v38->uY = 146;
+        v41 = v46 + 145;
+        goto LABEL_73;
+      }
+      if ( v38->uControlParam == 16 )
+      {
+        v44 = v88;
+        v45 = v90 + v36 + 146;
+        v38->uHeight = v88;
+        v38->uY = v45;
+        v41 = v45 + v44 - 1;
+        goto LABEL_73;
+      }
+      if ( v38->uControlParam == 96 )
+        break;
+      if ( v38->uControlParam == 101 )
+      {
+        v39 = v90 + 3 * v36 + v87 + v88 + 146;
+        v33 = (GUIWindow *)Str[1];
+        v40 = v87;
+        v38->uHeight = v87;
+        v38->uY = v39;
+        v41 = v39 + v40 - 1;
+LABEL_73:
+        v38->uW = v41;
+      }
+      v47 = v33->pStartingPosActiveItem;
+      pOutString = (GUIFont *)((char *)pOutString + 1);
+      if ( (signed int)pOutString >= v33->pNumPresenceButton + v47 )
+        goto LABEL_75;
+    }
+    v42 = v90 + v88 + 2 * v36 + 146;
+    v43 = v82;
+    v38->uY = v42;
+    v38->uHeight = v43;
+    v41 = v43 + v42 - 1;
+    goto LABEL_73;
+  }
+  if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+  {
+    v48 = 2;
+    pShopOptions[0] = pGlobalTXT_LocalizationStrings[620];
+    pOutString = 0;
+    pShopOptions[1] = pGlobalTXT_LocalizationStrings[622];
+    if ( pParty->HasItem(0x28Bu) )
+    {
+      pShopOptions[2] = pGlobalTXT_LocalizationStrings[621];
+      v48 = 3;
+    }
+    for ( i = 0; i < v48; ++i )
+    {
+      v50 = pFontArrus->CalcTextHeight(pShopOptions[i], &v79, 0, 0);
+      pOutString = (GUIFont *)((char *)pOutString + v50);
+    }
+    v86 = (174 - (signed int)pOutString) / v48;
+    v51 = pDialogueWindow;
+    v52 = 174 - v48 * (174 - (signed int)pOutString) / v48 - (signed int)pOutString;
+    v53 = v52 - HIDWORD(v52);
+    LODWORD(v52) = pDialogueWindow->pStartingPosActiveItem;
+    HIDWORD(v52) = v52 + pDialogueWindow->pNumPresenceButton;
+    v54 = (v53 >> 1) - v86 / 2 + 138;
+    v37 = -pDialogueWindow->pNumPresenceButton < 0;
+    v89 = pDialogueWindow->pStartingPosActiveItem;
+    if ( v37 ^ __OFSUB__((int)v52, HIDWORD(v52)) )
+    {
+      v85 = (Player *)2;
+      pOutString = (GUIFont *)pShopOptions;
+      do
+      {
+        v55 = v51->GetControl(v89);
+        v56 = (const char **)pOutString;
+        v55->uY = v86 + v54;
+        v57 = pFontArrus->CalcTextHeight(*v56, &v79, 0, 0);
+        v58 = v55->uY;
+        v59 = v85;
+        v55->uHeight = v57;
+        v54 = v57 + v58 - 1;
+        v55->uW = v54;
+        v60 = v84[0];
+        if ( (Player *)pDialogueWindow->pCurrentPosActiveItem != v59 )
+          v60 = v81;
+        v79.DrawTitleText(pFontArrus, 0, v58, v60, *(const char **)&pOutString->cFirstChar, 3u);
+        v51 = pDialogueWindow;
+        v85 = (Player *)((char *)v85 + 1);
+        pOutString = (GUIFont *)((char *)pOutString + 4);
+        ++v89;
+      }
+      while ( v89 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
+    }
+  }
+}
+
+//----- (004B8E3D) --------------------------------------------------------
+void *__cdecl GenerateShopItems()
+{
+  GUIWindow *v0; // eax@1
+  signed int v1; // edi@1
+  signed int v2; // esi@1
+  int v3; // ecx@3
+  int v4; // ebx@3
+  int v5; // ecx@3
+  bool v6; // ebp@5
+  int v7; // ecx@5
+  void *result; // eax@15
+  signed int v9; // [sp-Ch] [bp-14h]@7
+
+  v0 = ptr_507BC0;
+  v1 = 0;
+  v2 = (signed int)ptr_507BC0->ptr_1C;
+  //if ( _4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)ptr_507BC0->ptr_1C]] )
+  if ( _4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].uType] )
+  {
+    while ( v2 > 14 )
+    {
+      if ( v2 <= 28 )
+      {
+        v6 = v1 > 3;
+        v7 = v6 + 2 * v2 - 30;
+        v2 = (signed int)v0->ptr_1C;
+        v4 = word_4F0498[5 * v7];
+        __debugbreak();
+        //things happen around word_4F0400 actually
+        //v5 = *(short *)&aTooManyStation[2 * (5 * (v6 + 2 * v2) + rand() % 4) + 10];
+        goto LABEL_13;
+      }
+      if ( v2 <= 41 )
+      {
+        v4 = word_4F0576[v2];
+        v9 = 22;
+        goto LABEL_12;
+      }
+      if ( v2 <= 53 )
+      {
+        if ( v1 >= 6 )
+        {
+          v4 = word_4F0578[v2];
+          v9 = 45;
+LABEL_12:
+          v5 = v9;
+LABEL_13:
+          pItemsTable->GenerateItem(v4, v5, (ItemGen *)&pParty->field_777C[9 * (v1 + 12 * v2)]);
+          v0 = ptr_507BC0;
+          pParty->field_777C[9 * (v1 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 5] = 1;
+          goto LABEL_14;
+        }
+        auto _t = (ItemGen *)&pParty->field_777C[9 * (v1 + 12 * v2)];
+        _t->Reset();
+        v0 = ptr_507BC0;
+        pParty->field_777C[9 * (v1 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] = 220;
+      }
+LABEL_14:
+      v2 = (signed int)v0->ptr_1C;
+      ++v1;
+      //if ( v1 >= (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v0->ptr_1C]] )
+      if ( v1 >= (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v0->ptr_1C - 1].uType] )
+        goto LABEL_15;
+    }
+    v3 = 5 * v2;
+    v2 = (signed int)v0->ptr_1C;
+    v4 = word_4F03FE[v3];
+    v5 = word_4F0400[5 * v2 + rand() % 4];
+    goto LABEL_13;
+  }
+LABEL_15:
+  result = v0->ptr_1C;
+  *(int *)&pParty->field_16154[4 * (int)result] = 0;
+  return result;
+}
+
+
+
+//----- (004B910F) --------------------------------------------------------
+char *__cdecl sub_4B910F()
+{
+  Player *v0; // ebx@1
+  char *result; // eax@6
+  signed int v2; // esi@8
+  unsigned int v3; // ebx@10
+  ItemGen *v4; // eax@11
+  char *v5; // ecx@12
+  unsigned __int8 v6; // dl@13
+  char *v7; // edx@14
+  int v8; // eax@15
+  int v9; // ST08_4@16
+  int v10; // eax@16
+  signed int v11; // esi@18
+  int v12; // ST08_4@21
+  int v13; // eax@21
+  int v14; // edi@23
+  char **v15; // esi@23
+  int v16; // eax@24
+  GUIWindow *v17; // ecx@25
+  int v18; // edx@25
+  int v19; // edi@25
+  unsigned __int8 v20; // sf@25
+  GUIButton *v21; // esi@27
+  const char **v22; // eax@27
+  int v23; // eax@27
+  unsigned int v24; // ecx@27
+  int v25; // edx@27
+  unsigned __int16 v26; // ax@27
+  signed int v27; // esi@32
+  int v28; // ST08_4@36
+  int v29; // eax@36
+  GUIWindow *v30; // edi@41
+  void *v31; // eax@41
+  signed int v32; // esi@41
+  unsigned int v33; // esi@43
+  int v34; // eax@43
+  unsigned int v35; // eax@44
+  int v36; // eax@46
+  __int32 v37; // ecx@51
+  GUIButton *v38; // eax@53
+  GUIButton *v39; // esi@53
+  int v40; // eax@53
+  char *v41; // eax@55
+  int v42; // eax@55
+  unsigned int v43; // ecx@55
+  const char **v44; // edx@55
+  int v45; // eax@55
+  unsigned __int16 v46; // ax@55
+  int v47; // eax@59
+  const char **v48; // eax@63
+  unsigned int v49; // esi@65
+  Texture *v50; // eax@65
+  int v51; // edi@65
+  int v52; // esi@70
+  Texture *v53; // ST1C_4@70
+  int v54; // edi@70
+  signed int v55; // ecx@73
+  SHORT v56; // di@82
+  bool v57; // eax@82
+  const char *v58; // ecx@84
+  POINT *v59; // esi@89
+  LONG v60; // ecx@90
+  int v61; // eax@90
+  int v62; // ecx@90
+  ItemGen *v63; // esi@90
+  int v64; // eax@95
+  int v65; // esi@96
+  char **v66; // edi@96
+  int v67; // eax@97
+  GUIWindow *v68; // ecx@98
+  int v69; // edx@98
+  int v70; // edi@98
+  GUIButton *v71; // esi@100
+  const char **v72; // eax@100
+  int v73; // eax@100
+  unsigned int v74; // ecx@100
+  Player *v75; // edx@100
+  unsigned __int16 v76; // ax@100
+  GUIWindow *v77; // [sp-18h] [bp-110h]@14
+  int v78; // [sp-14h] [bp-10Ch]@14
+  ItemGen *v79; // [sp-10h] [bp-108h]@12
+  int v80; // [sp-10h] [bp-108h]@14
+  void *v81; // [sp-Ch] [bp-104h]@12
+  unsigned __int16 v82; // [sp-Ch] [bp-104h]@14
+  int v83; // [sp-8h] [bp-100h]@11
+  char *v84; // [sp-8h] [bp-100h]@14
+  __int64 *v85; // [sp-4h] [bp-FCh]@11
+  unsigned int v86; // [sp-4h] [bp-FCh]@14
+  POINT v87; // [sp+Ch] [bp-ECh]@8
+  POINT v88; // [sp+14h] [bp-E4h]@18
+  POINT v89; // [sp+1Ch] [bp-DCh]@89
+  POINT v90; // [sp+24h] [bp-D4h]@19
+  POINT v91; // [sp+2Ch] [bp-CCh]@89
+  POINT v92; // [sp+34h] [bp-C4h]@9
+  POINT v93; // [sp+3Ch] [bp-BCh]@33
+  POINT v94; // [sp+44h] [bp-B4h]@18
+  POINT v95; // [sp+4Ch] [bp-ACh]@32
+  POINT v96; // [sp+54h] [bp-A4h]@18
+  POINT v97; // [sp+5Ch] [bp-9Ch]@32
+  POINT a2; // [sp+64h] [bp-94h]@8
+  POINT v99; // [sp+6Ch] [bp-8Ch]@32
+  POINT v100; // [sp+74h] [bp-84h]@8
+  GUIWindow v101; // [sp+7Ch] [bp-7Ch]@1
+  char *Str; // [sp+D0h] [bp-28h]@55
+  __int32 v103; // [sp+D4h] [bp-24h]@25
+  int v104; // [sp+D8h] [bp-20h]@1
+  int v105; // [sp+DCh] [bp-1Ch]@1
+  POINT v106; // [sp+E0h] [bp-18h]@8
+  Player *_this; // [sp+E8h] [bp-10h]@1
+  int v108; // [sp+ECh] [bp-Ch]@26
+  const char **v109; // [sp+F0h] [bp-8h]@26
+  unsigned __int8 v110; // [sp+F7h] [bp-1h]@16
+
+  v0 = pPlayers[uActiveCharacter];
+  _this = pPlayers[uActiveCharacter];
+  memcpy(&v101, ptr_507BC0, sizeof(v101));
+  v101.uFrameX = 483;
+  v101.uFrameWidth = 148;
+  v101.uFrameZ = 334;
+  v105 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+  v104 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
+  if ( dword_F8B19C > 5 )
+  {
+    if ( dword_F8B19C == 94 )
+    {
+      draw_leather();
+      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];
+      pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];
+      pShopOptions[2] = pGlobalTXT_LocalizationStrings[179];
+      v65 = 0;
+      v66 = pShopOptions;
+      do
+      {
+        v67 = pFontArrus->CalcTextHeight(*v66, &v101, 0, 0);
+        ++v66;
+        v65 += v67;
+      }
+      while ( (signed int)v66 < (signed int)&pShopOptions[3] );
+      v68 = pDialogueWindow;
+      v109 = (const char **)((174 - v65) / 3);
+      result = (char *)pDialogueWindow->pStartingPosActiveItem;
+      v69 = (int)&result[pDialogueWindow->pNumPresenceButton];
+      v70 = (3 * (58 - (signed int)v109) - v65) / 2 - (174 - v65) / 3 / 2 + 138;
+      v20 = -pDialogueWindow->pNumPresenceButton < 0;
+      v106.y = pDialogueWindow->pStartingPosActiveItem;
+      if ( v20 ^ __OFSUB__((int)result, (int)v69) )
+      {
+        _this = (Player *)2;
+        v108 = (int)pShopOptions;
+        do
+        {
+          v71 = v68->GetControl(v106.y);
+          v72 = (const char **)v108;
+          v71->uY = (unsigned int)((char *)v109 + v70);
+          v73 = pFontArrus->CalcTextHeight(*v72, &v101, 0, 0);
+          v74 = v71->uY;
+          v75 = _this;
+          v71->uHeight = v73;
+          v70 = v73 + v74 - 1;
+          v71->uW = v70;
+          v76 = v104;
+          if ( (Player *)pDialogueWindow->pCurrentPosActiveItem != v75 )
+            v76 = v105;
+          v101.DrawTitleText(pFontArrus, 0, v74, v76, *(const char **)v108, 3u);
+          v68 = pDialogueWindow;
+          _this = (Player *)((char *)_this + 1);
+          v108 += 4;
+          ++v106.y;
+          result = (char *)(pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem);
+        }
+        while ( v106.y < (signed int)result );
+      }
+      return result;
+    }
+    if ( dword_F8B19C != 95 )
+    {
+      result = (char *)(dword_F8B19C - 96);
+      if ( dword_F8B19C == 96 )
+      {
+        result = (char *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+        if ( result )
+        {
+          v30 = pDialogueWindow;
+          v3 = 0;
+          v31 = ptr_507BC0->ptr_1C;
+          v106.y = 0;
+          //v32 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (signed int)v31] * 500.0);
+          v32 = (signed __int64)(p2DEvents[(signed int)v31 - 1].flt_24 * 500.0);
+          v108 = v32 * (100 - _this->GetMerchant()) / 100;
+          if ( v108 < v32 / 3 )
+            v108 = v32 / 3;
+          v33 = v30->pStartingPosActiveItem;
+          v34 = v33 + v30->pNumPresenceButton;
+          v109 = 0;
+          if ( (signed int)v33 >= v34 )
+            goto LABEL_105;
+          do
+          {
+            v35 = v30->GetControl(v33)->uControlParam - 36;
+            if ( byte_4ED970_skill_learn_ability_by_class_table[_this->uClass][v35] && !_this->pActiveSkills[v35] )
+            {
+              v36 = pFontArrus->CalcTextHeight(pSkillNames[v35], &v101, 0, 0);
+              v106.y += v36;
+              v109 = (const char **)((char *)v109 + 1);
+            }
+            ++v33;
+          }
+          while ( (signed int)v33 < v30->pNumPresenceButton + v30->pStartingPosActiveItem );
+          if ( !v109 )
+          {
+LABEL_105:
+            sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], _this->pName, pClassNames[_this->uClass]);
+            strcat(pTmpBuf, "\n \n");
+            strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
+            v7 = pTmpBuf;
+            v86 = 3;
+            v84 = pTmpBuf;
+            v82 = v104;
+            v80 = 0;
+            v78 = 0;
+            v77 = &v101;
+            goto LABEL_15;
+          }
+          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v108);
+          v101.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
+          v108 = (149 - v106.y) / (signed int)v109;
+          if ( (149 - v106.y) / (signed int)v109 > 32 )
+            v108 = 32;
+          result = (char *)v30->pStartingPosActiveItem;
+          v37 = (149 - (signed int)v109 * v108 - v106.y) / 2 - v108 / 2 + 162;
+          v106.y = (LONG)result;
+          v103 = v37;
+          if ( (signed int)result < (signed int)&result[v30->pNumPresenceButton] )
+          {
+            v109 = (const char **)2;
+            do
+            {
+              v38 = v30->GetControl(v106.y);
+              v39 = v38;
+              v40 = v38->uControlParam - 36;
+              if ( !byte_4ED970_skill_learn_ability_by_class_table[_this->uClass][v40] || _this->pActiveSkills[v40] )
+              {
+                v39->uW = 0;
+                v39->uHeight = 0;
+                v39->uY = 0;
+              }
+              else
+              {
+                v41 = pSkillNames[v40];
+                v39->uY = v108 + v103;
+                Str = v41;
+                v42 = pFontArrus->CalcTextHeight(v41, &v101, 0, 0);
+                v43 = v39->uY;
+                v44 = v109;
+                v39->uHeight = v42;
+                v45 = v43 + v42 - 1;
+                v39->uW = v45;
+                v103 = v45;
+                v46 = v104;
+                if ( (const char **)pDialogueWindow->pCurrentPosActiveItem != v44 )
+                  v46 = v105;
+                v101.DrawTitleText(pFontArrus, 0, v43, v46, Str, 3u);
+              }
+              v47 = v30->pStartingPosActiveItem;
+              ++v106.y;
+              result = (char *)(v30->pNumPresenceButton + v47);
+              v109 = (const char **)((char *)v109 + 1);
+            }
+            while ( v106.y < (signed int)result );
+          }
+        }
+      }
+      return result;
+    }
+  }
+  else
+  {
+    if ( dword_F8B19C == 5 )
+    {
+      draw_leather();
+      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      sub_4B46A5(pGlobalTXT_LocalizationStrings[198], 0);
+      result = (char *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+      if ( result )
+      {
+        v27 = pMouse->GetCursorPos(&v99)->x - 14;
+        v106.x = (v27 >> 5) + 14 * ((pMouse->GetCursorPos(&v97)->y - 17) >> 5);
+        result = (char *)pMouse->GetCursorPos(&v95);
+        if ( *(int *)result > 13 )
+        {
+          result = (char *)pMouse->GetCursorPos(&v93);
+          if ( *(int *)result < 462 )
+          {
+            result = (char *)v0->GetItemIDAtInventoryIndex((int *)&v106.x);
+            v3 = 0;
+            if ( result )
+            {
+              result = (char *)(9 * (int)result);
+              if ( _this->field_1F5[4 * (int)result + 15] & 2 )
+              {
+                v85 = 0;
+                v83 = 5;
+                v81 = ptr_507BC0->ptr_1C;
+                v79 = (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * (int)result + 5];
+                v28 = (int)ptr_507BC0->ptr_1C;
+                v110 = uActiveCharacter - 1;
+                v29 = _this->_490EEE(
+                        (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * (int)result + 5],
+                        1,
+                        v28,
+                        5);
+                v6 = v110;
+                v5 = (char *)pMerchantsRepairPhrases[v29];
+                goto LABEL_14;
+              }
+            }
+          }
+        }
+      }
+      return result;
+    }
+    if ( dword_F8B19C == 1 )
+    {
+      result = (char *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+      if ( result )
+      {
+        pShopOptions[0] = pGlobalTXT_LocalizationStrings[134];
+        pShopOptions[1] = pGlobalTXT_LocalizationStrings[152];
+        pShopOptions[2] = pGlobalTXT_LocalizationStrings[159];
+        v14 = 0;
+        pShopOptions[3] = pGlobalTXT_LocalizationStrings[160];
+        v15 = pShopOptions;
+        do
+        {
+          v16 = pFontArrus->CalcTextHeight(*v15, &v101, 0, 0);
+          ++v15;
+          v14 += v16;
+        }
+        while ( (signed int)v15 < (signed int)&unk_F8B1C8 );
+        v17 = pDialogueWindow;
+        v103 = (174 - v14) / 4;
+        result = (char *)pDialogueWindow->pStartingPosActiveItem;
+        v18 = (int)&result[pDialogueWindow->pNumPresenceButton];
+        v19 = (174 - 4 * (174 - v14) / 4 - v14) / 2 - (174 - v14) / 4 / 2 + 138;
+        v20 = -pDialogueWindow->pNumPresenceButton < 0;
+        _this = (Player *)pDialogueWindow->pStartingPosActiveItem;
+        if ( v20 ^ __OFSUB__((int)result, v18) )
+        {
+          v108 = 2;
+          v109 = (const char **)pShopOptions;
+          do
+          {
+            v21 = v17->GetControl((unsigned int)_this);
+            v22 = v109;
+            v21->uY = v103 + v19;
+            v23 = pFontArrus->CalcTextHeight(*v22, &v101, 0, 0);
+            v24 = v21->uY;
+            v25 = v108;
+            v21->uHeight = v23;
+            v19 = v24 + v23 - 1;
+            v21->uW = v19;
+            v26 = v104;
+            if ( pDialogueWindow->pCurrentPosActiveItem != v25 )
+              v26 = v105;
+            v101.DrawTitleText(pFontArrus, 0, v24, v26, *v109, 3u);
+            v17 = pDialogueWindow;
+            ++v108;
+            ++v109;
+            _this = (Player *)((char *)_this + 1);
+            result = (char *)(pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem);
+          }
+          while ( (signed int)_this < (signed int)result );
+        }
+      }
+      return result;
+    }
+    if ( dword_F8B19C != 2 )
+    {
+      if ( dword_F8B19C == 3 )
+      {
+        draw_leather();
+        CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+        sub_4B46A5(pGlobalTXT_LocalizationStrings[199], 0);
+        result = (char *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+        if ( result )
+        {
+          v11 = pMouse->GetCursorPos(&v96)->x - 14;
+          v106.x = (v11 >> 5) + 14 * ((pMouse->GetCursorPos(&v88)->y - 17) >> 5);
+          result = (char *)pMouse->GetCursorPos(&v94);
+          if ( *(int *)result > 13 )
+          {
+            result = (char *)pMouse->GetCursorPos(&v90);
+            if ( *(int *)result < 462 )
+            {
+              result = (char *)v0->GetItemIDAtInventoryIndex((int *)&v106.x);
+              v3 = 0;
+              if ( result )
+              {
+                v85 = 0;
+                v83 = 3;
+                v81 = ptr_507BC0->ptr_1C;
+                v79 = (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * (int)result + 5];
+                v12 = (int)ptr_507BC0->ptr_1C;
+                v110 = uActiveCharacter - 1;
+                v13 = _this->_490EEE(v79, 1, v12, 3);
+                v6 = v110;
+                v5 = (char *)pMerchantsSellPhrases[v13];
+                goto LABEL_14;
+              }
+            }
+          }
+        }
+      }
+      else
+      {
+        result = (char *)(dword_F8B19C - 4);
+        if ( dword_F8B19C == 4 )
+        {
+          draw_leather();
+          CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+          sub_4B46A5(pGlobalTXT_LocalizationStrings[197], 0);
+          result = (char *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+          if ( result )
+          {
+            v2 = pMouse->GetCursorPos(&a2)->x - 14;
+            v106.x = (v2 >> 5) + 14 * ((pMouse->GetCursorPos(&v87)->y - 17) >> 5);
+            result = (char *)pMouse->GetCursorPos(&v100);
+            if ( *(int *)result > 13 )
+            {
+              result = (char *)pMouse->GetCursorPos(&v92);
+              if ( *(int *)result < 462 )
+              {
+                result = (char *)v0->GetItemIDAtInventoryIndex((int *)&v106.x);
+                v3 = 0;
+                if ( result )
+                {
+                  v85 = 0;
+                  v83 = 4;
+                  v4 = (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * (int)result + 5];
+                  if ( !(v4->uAttributes & 1) )
+                  {
+                    v81 = ptr_507BC0->ptr_1C;
+                    v79 = v4;
+                    v9 = (int)ptr_507BC0->ptr_1C;
+                    v110 = uActiveCharacter - 1;
+                    v10 = _this->_490EEE(v4, 1, v9, 4);
+                    v6 = v110;
+                    v5 = (char *)pMerchantsIdentifyPhrases[v10];
+                    goto LABEL_14;
+                  }
+                  v81 = ptr_507BC0->ptr_1C;
+                  v5 = "%24";
+                  v79 = v4;
+LABEL_13:
+                  v6 = uActiveCharacter - 1;
+LABEL_14:
+                  v7 = sub_495461(v5, v6, v79, (char *)v81, v83, v85);
+                  v86 = 3;
+                  v84 = v7;
+                  v82 = v105;
+                  v80 = v3;
+                  v78 = v3;
+                  v77 = &v101;
+LABEL_15:
+                  v8 = pFontArrus->CalcTextHeight(v7, v77, v78, v80);
+                  return v101.DrawTitleText(pFontArrus, v3, (174 - v8) / 2 + 138, v82, v84, v86);
+                }
+              }
+            }
+          }
+        }
+      }
+      return result;
+    }
+  }
+  pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
+  v3 = 0;
+  if ( dword_F8B19C == 2 )
+  {
+    v48 = 0;
+    v108 = 0;
+    v109 = 0;
+    do
+    {
+      if ( pParty->field_777C[9 * (int)&v48[3 * (unsigned int)ptr_507BC0->ptr_1C]] )
+      {
+        v49 = word_F8B158[(signed int)v48];
+        v50 = dword_F8B168[(signed int)v48];
+        v49 += 30;
+        v51 = 60 - ((signed int)v50->uTextureWidth >> 1);
+        pRenderer->DrawTextureTransparent(v51 + v108, v49, v50);
+        sub_40F92A(
+          &pRenderer->pActiveZBuffer[v51 + v108 + 640 * v49],
+          dword_F8B168[(signed int)v109],
+          (int)((char *)v109 + 1));
+        v48 = v109;
+      }
+      v108 += 70;
+      v48 = (const char **)((char *)v48 + 1);
+      v109 = v48;
+    }
+    while ( (signed int)v48 < 6 );
+  }
+  else
+  {
+    v109 = 0;
+    v108 = 0;
+    do
+    {
+      if ( pParty->field_C59C[9 * (int)&v109[3 * (unsigned int)ptr_507BC0->ptr_1C] + 724] )
+      {
+        v52 = word_F8B158[(signed int)v109] + 30;
+        v53 = dword_F8B168[(signed int)v109];
+        v54 = 60 - ((signed int)v53->uTextureWidth >> 1);
+        pRenderer->DrawTextureTransparent(v54 + v108, word_F8B158[(signed int)v109] + 30, v53);
+        sub_40F92A(
+          &pRenderer->pActiveZBuffer[v54 + v108 + 640 * v52],
+          dword_F8B168[(signed int)v109],
+          (int)((char *)v109 + 1));
+      }
+      v109 = (const char **)((char *)v109 + 1);
+      v108 += 70;
+    }
+    while ( (signed int)v109 < 6 );
+  }
+  result = (char *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+  if ( result )
+  {
+    v55 = 0;
+    v106.x = 0;
+    if ( dword_F8B19C == 2 )
+    {
+      v106.x = 0;
+      do
+      {
+        if ( pParty->field_777C[9 * (v55 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] )
+          ++v106.x;
+        ++v55;
+      }
+      while ( v55 < 6 );
+    }
+    else
+    {
+      do
+      {
+        if ( pParty->field_C59C[9 * (v55 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
+          ++v106.x;
+        ++v55;
+      }
+      while ( v55 < 6 );
+    }
+    v56 = GetAsyncKeyState(17);
+    v57 = _this->CanSteal();
+    Str = (char *)v57;
+    if ( v56 && v57 )
+    {
+      v58 = pGlobalTXT_LocalizationStrings[185];
+    }
+    else
+    {
+      v58 = pGlobalTXT_LocalizationStrings[195];
+      if ( dword_F8B19C != 2 )
+        v58 = pGlobalTXT_LocalizationStrings[196];
+    }
+    sub_4B46A5(v58, 0);
+    if ( v106.x )
+    {
+      v59 = pMouse->GetCursorPos(&v91);
+      result = (char *)(v59->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v89)->y]);
+      if ( pRenderer->pActiveZBuffer[(int)result] & 0xFFFF )
+      {
+        v60 = (pRenderer->pActiveZBuffer[(int)result] & 0xFFFF) - 1;
+        v106.x = v60;
+        v61 = (int)ptr_507BC0->ptr_1C;
+        v62 = 9 * (v60 + 12 * v61);
+        v63 = (ItemGen *)&pParty->field_777C[v62];
+        if ( dword_F8B19C != 2 )
+          v63 = (ItemGen *)&pParty->field_C59C[v62 + 724];
+        if ( !v56 || !Str )
+        {
+          v85 = 0;
+          v83 = 2;
+          v81 = ptr_507BC0->ptr_1C;
+          v79 = v63;
+          v110 = uActiveCharacter - 1;
+          v64 = _this->_490EEE(v63, 1, v61, 2);
+          v6 = v110;
+          v5 = (char *)pMerchantsBuyPhrases[v64];
+          goto LABEL_14;
+        }
+        v5 = pGlobalTXT_LocalizationStrings[181];
+        v85 = 0;
+        v83 = 2;
+        v81 = ptr_507BC0->ptr_1C;
+        v79 = v63;
+        goto LABEL_13;
+      }
+    }
+    else
+    {
+      result = v101._4B1854(
+                 __PAIR__(
+                   pParty->field_3C.field_50[2 * (unsigned int)ptr_507BC0->ptr_1C + 1],
+                   pParty->field_3C.field_50[2 * (unsigned int)ptr_507BC0->ptr_1C])
+               - pParty->uTimePlayed);
+    }
+  }
+  return result;
+}
+
+
+//----- (004B9CC6) --------------------------------------------------------
+POINT *__cdecl sub_4B9CC6()
+{
+  Player *v0; // ebx@1
+  POINT *result; // eax@7
+  GUIWindow *v2; // edi@9
+  unsigned int v3; // ebx@9
+  void *v4; // eax@9
+  signed int v5; // esi@9
+  unsigned int v6; // esi@11
+  int v7; // eax@11
+  unsigned int v8; // eax@12
+  int v9; // eax@14
+  int v10; // ecx@19
+  GUIButton *v11; // eax@21
+  GUIButton *v12; // esi@21
+  int v13; // eax@21
+  char *v14; // eax@23
+  int v15; // eax@23
+  unsigned int v16; // ecx@23
+  int v17; // edx@23
+  int v18; // eax@23
+  unsigned __int16 v19; // ax@23
+  int v20; // eax@27
+  char *v21; // edx@29
+  int v22; // esi@30
+  char **v23; // edi@30
+  int v24; // eax@31
+  GUIWindow *v25; // ecx@32
+  int v26; // edx@32
+  int v27; // edi@32
+  unsigned __int8 v28; // sf@32
+  GUIButton *v29; // esi@34
+  const char **v30; // eax@34
+  int v31; // eax@34
+  unsigned int v32; // ecx@34
+  Player *v33; // edx@34
+  int v34; // eax@34
+  unsigned __int16 v35; // ax@34
+  signed int v36; // esi@39
+  ItemGen *v37; // eax@42
+  char *v38; // ecx@43
+  unsigned __int8 v39; // dl@44
+  int v40; // eax@46
+  int v41; // ST08_4@47
+  int v42; // eax@47
+  signed int v43; // esi@49
+  int v44; // ST08_4@52
+  int v45; // eax@52
+  Texture *v46; // ecx@55
+  unsigned int v47; // edi@55
+  unsigned int v48; // esi@57
+  int v49; // edx@61
+  Texture *v50; // ecx@67
+  unsigned int v51; // edi@67
+  unsigned int v52; // esi@69
+  int v53; // edx@73
+  Texture *v54; // ecx@79
+  unsigned int v55; // edi@79
+  unsigned int v56; // esi@81
+  int v57; // edx@85
+  Texture *v58; // ecx@91
+  unsigned int v59; // edi@91
+  unsigned int v60; // esi@93
+  int v61; // edx@97
+  signed int v62; // ecx@102
+  SHORT v63; // di@110
+  bool v64; // eax@110
+  const char *v65; // ecx@112
+  POINT *v66; // esi@117
+  int v67; // ecx@118
+  int v68; // eax@118
+  int v69; // ecx@118
+  ItemGen *v70; // esi@118
+  int v71; // eax@123
+  int v72; // edi@125
+  char **v73; // esi@125
+  int v74; // eax@126
+  GUIWindow *v75; // ecx@127
+  int v76; // edx@127
+  int v77; // edi@127
+  GUIButton *v78; // esi@129
+  const char **v79; // eax@129
+  int v80; // eax@129
+  unsigned int v81; // ecx@129
+  Player *v82; // edx@129
+  unsigned __int16 v83; // ax@129
+  GUIWindow *v84; // [sp-18h] [bp-F0h]@29
+  int v85; // [sp-14h] [bp-ECh]@29
+  int v86; // [sp-10h] [bp-E8h]@29
+  ItemGen *v87; // [sp-10h] [bp-E8h]@43
+  unsigned __int16 v88; // [sp-Ch] [bp-E4h]@29
+  void *v89; // [sp-Ch] [bp-E4h]@43
+  char *v90; // [sp-8h] [bp-E0h]@29
+  int v91; // [sp-8h] [bp-E0h]@42
+  unsigned int v92; // [sp-4h] [bp-DCh]@29
+  __int64 *v93; // [sp-4h] [bp-DCh]@42
+  POINT v94; // [sp+Ch] [bp-CCh]@39
+  POINT v95; // [sp+14h] [bp-C4h]@49
+  POINT v96; // [sp+1Ch] [bp-BCh]@117
+  POINT v97; // [sp+24h] [bp-B4h]@40
+  POINT v98; // [sp+2Ch] [bp-ACh]@117
+  POINT v99; // [sp+34h] [bp-A4h]@49
+  POINT v100; // [sp+3Ch] [bp-9Ch]@50
+  POINT v101; // [sp+44h] [bp-94h]@39
+  POINT v102; // [sp+4Ch] [bp-8Ch]@49
+  POINT a2; // [sp+54h] [bp-84h]@39
+  GUIWindow v104; // [sp+5Ch] [bp-7Ch]@1
+  int v105; // [sp+B0h] [bp-28h]@19
+  int v106; // [sp+B4h] [bp-24h]@1
+  char *Str; // [sp+B8h] [bp-20h]@23
+  int v108; // [sp+BCh] [bp-1Ch]@1
+  __int32 v109; // [sp+C0h] [bp-18h]@39
+  Player *_this; // [sp+C4h] [bp-14h]@1
+  const char **v111; // [sp+C8h] [bp-10h]@9
+  unsigned int v112; // [sp+CCh] [bp-Ch]@9
+  unsigned __int8 v113; // [sp+D3h] [bp-5h]@47
+  int v114; // [sp+D4h] [bp-4h]@11
+
+  v0 = pPlayers[uActiveCharacter];
+  _this = pPlayers[uActiveCharacter];
+  memcpy(&v104, ptr_507BC0, sizeof(v104));
+  v104.uFrameX = 483;
+  v104.uFrameWidth = 148;
+  v104.uFrameZ = 334;
+  v108 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+  v106 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
+  if ( dword_F8B19C == 1 )
+  {
+    result = (POINT *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+    if ( result )
+    {
+      pShopOptions[0] = pGlobalTXT_LocalizationStrings[134];
+      pShopOptions[1] = pGlobalTXT_LocalizationStrings[152];
+      pShopOptions[2] = pGlobalTXT_LocalizationStrings[159];
+      v72 = 0;
+      pShopOptions[3] = pGlobalTXT_LocalizationStrings[160];
+      v73 = pShopOptions;
+      do
+      {
+        v74 = pFontArrus->CalcTextHeight(*v73, &v104, 0, 0);
+        ++v73;
+        v72 += v74;
+      }
+      while ( (signed int)v73 < (signed int)&unk_F8B1C8 );
+      v75 = pDialogueWindow;
+      Str = (char *)((174 - v72) / 4);
+      result = (POINT *)pDialogueWindow->pStartingPosActiveItem;
+      v76 = (int)((char *)result + pDialogueWindow->pNumPresenceButton);
+      v77 = (174 - 4 * (174 - v72) / 4 - v72) / 2 - (174 - v72) / 4 / 2 + 138;
+      v28 = -pDialogueWindow->pNumPresenceButton < 0;
+      v112 = pDialogueWindow->pStartingPosActiveItem;
+      if ( v28 ^ __OFSUB__((int)result, v76) )
+      {
+        _this = (Player *)2;
+        v111 = (const char **)pShopOptions;
+        do
+        {
+          v78 = v75->GetControl(v112);
+          v79 = v111;
+          v78->uY = (unsigned int)&Str[v77];
+          v80 = pFontArrus->CalcTextHeight(*v79, &v104, 0, 0);
+          v81 = v78->uY;
+          v82 = _this;
+          v78->uHeight = v80;
+          v77 = v81 + v80 - 1;
+          v78->uW = v77;
+          v83 = v106;
+          if ( (Player *)pDialogueWindow->pCurrentPosActiveItem != v82 )
+            v83 = v108;
+          v104.DrawTitleText(pFontArrus, 0, v81, v83, *v111, 3u);
+          v75 = pDialogueWindow;
+          _this = (Player *)((char *)_this + 1);
+          ++v111;
+          ++v112;
+          result = (POINT *)(pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem);
+        }
+        while ( (signed int)v112 < (signed int)result );
+      }
+    }
+  }
+  else
+  {
+    if ( dword_F8B19C != 2 )
+    {
+      if ( dword_F8B19C == 3 )
+      {
+        draw_leather();
+        CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+        sub_4B46A5(pGlobalTXT_LocalizationStrings[199], 0);
+        result = (POINT *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+        if ( !result
+          || (v43 = pMouse->GetCursorPos(&v99)->x - 14,
+              v109 = (v43 >> 5) + 14 * ((pMouse->GetCursorPos(&v95)->y - 17) >> 5),
+              result = pMouse->GetCursorPos(&v102),
+              result->x <= 13)
+          || (result = pMouse->GetCursorPos(&v100), result->x >= 462)
+          || (result = (POINT *)v0->GetItemIDAtInventoryIndex((int *)&v109), v3 = 0, !result) )
+          return result;
+        v93 = 0;
+        v91 = 3;
+        v89 = ptr_507BC0->ptr_1C;
+        v87 = (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * (int)result + 5];
+        v44 = (int)ptr_507BC0->ptr_1C;
+        v113 = uActiveCharacter - 1;
+        v45 = _this->_490EEE(v87, 4, v44, 3);
+        v39 = v113;
+        v38 = (char *)pMerchantsSellPhrases[v45];
+        goto LABEL_45;
+      }
+      if ( dword_F8B19C == 4 )
+      {
+        draw_leather();
+        CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+        sub_4B46A5(pGlobalTXT_LocalizationStrings[197], 0);
+        result = (POINT *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+        if ( !result
+          || (v36 = pMouse->GetCursorPos(&a2)->x - 14,
+              v109 = (v36 >> 5) + 14 * ((pMouse->GetCursorPos(&v94)->y - 17) >> 5),
+              result = pMouse->GetCursorPos(&v101),
+              result->x <= 13)
+          || (result = pMouse->GetCursorPos(&v97), result->x >= 462)
+          || (result = (POINT *)v0->GetItemIDAtInventoryIndex((int *)&v109), v3 = 0, !result) )
+          return result;
+        v93 = 0;
+        v91 = 4;
+        v37 = (ItemGen *)&_this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * (int)result + 5];
+        if ( !(v37->uAttributes & 1) )
+        {
+          v89 = ptr_507BC0->ptr_1C;
+          v87 = v37;
+          v41 = (int)ptr_507BC0->ptr_1C;
+          v113 = uActiveCharacter - 1;
+          v42 = _this->_490EEE(v37, 4, v41, 4);
+          v39 = v113;
+          v38 = (char *)pMerchantsIdentifyPhrases[v42];
+          goto LABEL_45;
+        }
+        v89 = ptr_507BC0->ptr_1C;
+        v38 = "%24";
+        v87 = v37;
+LABEL_44:
+        v39 = uActiveCharacter - 1;
+LABEL_45:
+        v21 = sub_495461(v38, v39, v87, (char *)v89, v91, v93);
+        v92 = 3;
+        v90 = v21;
+        v88 = v108;
+        v86 = v3;
+        v85 = v3;
+        v84 = &v104;
+        goto LABEL_46;
+      }
+      if ( dword_F8B19C == 94 )
+      {
+        draw_leather();
+        CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+        pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];
+        pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];
+        v22 = 0;
+        v23 = pShopOptions;
+        do
+        {
+          v24 = pFontArrus->CalcTextHeight(*v23, &v104, 0, 0);
+          ++v23;
+          v22 += v24;
+        }
+        while ( (signed int)v23 < (signed int)&pShopOptions[2] );
+        Str = (char *)((174 - v22) / 2);
+        v25 = pDialogueWindow;
+        result = (POINT *)pDialogueWindow->pStartingPosActiveItem;
+        v26 = (int)((char *)result + pDialogueWindow->pNumPresenceButton);
+        v27 = (2 * (87 - (174 - v22) / 2) - v22) / 2 - (174 - v22) / 2 / 2 + 138;
+        v28 = -pDialogueWindow->pNumPresenceButton < 0;
+        v112 = pDialogueWindow->pStartingPosActiveItem;
+        if ( v28 ^ __OFSUB__((int)result, v26) )
+        {
+          _this = (Player *)2;
+          v111 = (const char **)pShopOptions;
+          do
+          {
+            v29 = v25->GetControl(v112);
+            v30 = v111;
+            v29->uY = (unsigned int)&Str[v27];
+            v31 = pFontArrus->CalcTextHeight(*v30, &v104, 0, 0);
+            v32 = v29->uY;
+            v33 = _this;
+            v29->uHeight = v31;
+            v34 = v31 + v32 - 1;
+            v29->uW = v34;
+            v27 = v34;
+            v35 = v106;
+            if ( (Player *)pDialogueWindow->pCurrentPosActiveItem != v33 )
+              v35 = v108;
+            v104.DrawTitleText(pFontArrus, 0, v32, v35, *v111, 3u);
+            v25 = pDialogueWindow;
+            _this = (Player *)((char *)_this + 1);
+            ++v111;
+            ++v112;
+            result = (POINT *)(pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem);
+          }
+          while ( (signed int)v112 < (signed int)result );
+        }
+        return result;
+      }
+      if ( dword_F8B19C != 95 )
+      {
+        result = (POINT *)(dword_F8B19C - 96);
+        if ( dword_F8B19C != 96
+          || (result = (POINT *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()) == 0 )
+          return result;
+        v2 = pDialogueWindow;
+        v3 = 0;
+        v4 = ptr_507BC0->ptr_1C;
+        v112 = 0;
+        //v5 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (signed int)v4] * 500.0);
+        v5 = (signed __int64)(p2DEvents[(signed int)v4 - 1].flt_24 * 500.0);
+        v111 = (const char **)(v5 * (100 - _this->GetMerchant()) / 100);
+        if ( (signed int)v111 < v5 / 3 )
+          v111 = (const char **)(v5 / 3);
+        v6 = v2->pStartingPosActiveItem;
+        v7 = v6 + v2->pNumPresenceButton;
+        v114 = 0;
+        if ( (signed int)v6 < v7 )
+        {
+          do
+          {
+            v8 = v2->GetControl(v6)->uControlParam - 36;
+            if ( byte_4ED970_skill_learn_ability_by_class_table[_this->uClass][v8] && !_this->pActiveSkills[v8] )
+            {
+              v9 = pFontArrus->CalcTextHeight(pSkillNames[v8], &v104, 0, 0);
+              v112 += v9;
+              ++v114;
+            }
+            ++v6;
+          }
+          while ( (signed int)v6 < v2->pNumPresenceButton + v2->pStartingPosActiveItem );
+          if ( v114 )
+          {
+            sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], v111);
+            v104.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
+            v111 = (const char **)((signed int)(149 - v112) / v114);
+            if ( (signed int)(149 - v112) / v114 > 32 )
+              v111 = (const char **)32;
+            result = (POINT *)v2->pStartingPosActiveItem;
+            v10 = (signed int)(149 - v114 * (int)v111 - v112) / 2 - (signed int)v111 / 2 + 162;
+            v112 = (unsigned int)result;
+            v105 = v10;
+            if ( (signed int)result < (signed int)((char *)result + v2->pNumPresenceButton) )
+            {
+              v114 = 2;
+              do
+              {
+                v11 = v2->GetControl(v112);
+                v12 = v11;
+                v13 = v11->uControlParam - 36;
+                if ( !byte_4ED970_skill_learn_ability_by_class_table[_this->uClass][v13] || _this->pActiveSkills[v13] )
+                {
+                  v12->uW = 0;
+                  v12->uHeight = 0;
+                  v12->uY = 0;
+                }
+                else
+                {
+                  v14 = pSkillNames[v13];
+                  v12->uY = (unsigned int)((char *)v111 + v105);
+                  Str = v14;
+                  v15 = pFontArrus->CalcTextHeight(v14, &v104, 0, 0);
+                  v16 = v12->uY;
+                  v17 = v114;
+                  v12->uHeight = v15;
+                  v18 = v16 + v15 - 1;
+                  v12->uW = v18;
+                  v105 = v18;
+                  v19 = v106;
+                  if ( pDialogueWindow->pCurrentPosActiveItem != v17 )
+                    v19 = v108;
+                  v104.DrawTitleText(pFontArrus, 0, v16, v19, Str, 3u);
+                }
+                v20 = v2->pStartingPosActiveItem;
+                ++v112;
+                result = (POINT *)(v2->pNumPresenceButton + v20);
+                ++v114;
+              }
+              while ( (signed int)v112 < (signed int)result );
+            }
+            return result;
+          }
+        }
+        sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], _this->pName, pClassNames[_this->uClass]);
+        strcat(pTmpBuf, "\n \n");
+        strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
+        v21 = pTmpBuf;
+        v92 = 3;
+        v90 = pTmpBuf;
+        v88 = v106;
+        v86 = 0;
+        v85 = 0;
+        v84 = &v104;
+LABEL_46:
+        v40 = pFontArrus->CalcTextHeight(v21, v84, v85, v86);
+        return (POINT *)v104.DrawTitleText(pFontArrus, v3, (174 - v40) / 2 + 138, v88, v90, v92);
+      }
+    }
+    pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
+    v3 = 0;
+    v114 = 0;
+    if ( dword_F8B19C == 2 )
+    {
+      do
+      {
+        if ( pParty->field_777C[9 * (v114 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] )
+        {
+          v46 = dword_F8B168[v114];
+          v47 = 152 - v46->uTextureHeight;
+          if ( (signed int)v47 < 1 )
+            v47 = 0;
+          v48 = 75 * v114 - v46->uTextureWidth / 2 + 40;
+          if ( v114 )
+          {
+            if ( v114 == 5 )
+            {
+              v49 = dword_F8B168[5]->uTextureWidth;
+              if ( (signed int)v48 > 457 - v49 )
+                v48 = 457 - v49;
+            }
+          }
+          else
+          {
+            if ( (signed int)v48 < 18 )
+              v48 = 18;
+          }
+          pRenderer->DrawTextureTransparent(v48, v47, v46);
+          sub_40F92A(&pRenderer->pActiveZBuffer[v48 + 640 * v47], dword_F8B168[v114], v114 + 1);
+        }
+        ++v114;
+      }
+      while ( v114 < 6 );
+      v114 = 0;
+      do
+      {
+        if ( pParty->field_777C[9 * (v114 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 54] )
+        {
+          v50 = dword_F8B168[v114 + 6];
+          v51 = 308 - v50->uTextureHeight;
+          if ( (signed int)v51 < 1 )
+            v51 = 0;
+          v52 = 75 * v114 - v50->uTextureWidth / 2 + 40;
+          if ( v114 )
+          {
+            if ( v114 == 5 )
+            {
+              v53 = dword_F8B168[11]->uTextureWidth;
+              if ( (signed int)v52 > 457 - v53 )
+                v52 = 457 - v53;
+            }
+          }
+          else
+          {
+            if ( (signed int)v52 < 18 )
+              v52 = 18;
+          }
+          pRenderer->DrawTextureTransparent(v52, v51, v50);
+          sub_40F92A(&pRenderer->pActiveZBuffer[v52 + 640 * v51], dword_F8B168[v114 + 6], v114 + 7);
+        }
+        ++v114;
+      }
+      while ( v114 < 6 );
+    }
+    else
+    {
+      do
+      {
+        if ( pParty->field_C59C[9 * (v114 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
+        {
+          v54 = dword_F8B168[v114];
+          v55 = 152 - v54->uTextureHeight;
+          if ( (signed int)v55 < 1 )
+            v55 = 0;
+          v56 = 75 * v114 - v54->uTextureWidth / 2 + 40;
+          if ( v114 )
+          {
+            if ( v114 == 5 )
+            {
+              v57 = dword_F8B168[5]->uTextureWidth;
+              if ( (signed int)v56 > 457 - v57 )
+                v56 = 457 - v57;
+            }
+          }
+          else
+          {
+            if ( (signed int)v56 < 18 )
+              v56 = 18;
+          }
+          pRenderer->DrawTextureTransparent(v56, v55, v54);
+          sub_40F92A(&pRenderer->pActiveZBuffer[v56 + 640 * v55], dword_F8B168[v114], v114 + 1);
+        }
+        ++v114;
+      }
+      while ( v114 < 6 );
+      v114 = 0;
+      do
+      {
+        if ( pParty->field_C59C[9 * (v114 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 778] )
+        {
+          v58 = dword_F8B168[v114 + 6];
+          v59 = 308 - v58->uTextureHeight;
+          if ( (signed int)v59 < 1 )
+            v59 = 0;
+          v60 = 75 * v114 - v58->uTextureWidth / 2 + 40;
+          if ( v114 )
+          {
+            if ( v114 == 5 )
+            {
+              v61 = dword_F8B168[11]->uTextureWidth;
+              if ( (signed int)v60 > 457 - v61 )
+                v60 = 457 - v61;
+            }
+          }
+          else
+          {
+            if ( (signed int)v60 < 18 )
+              v60 = 18;
+          }
+          pRenderer->DrawTextureTransparent(v60, v59, v58);
+          sub_40F92A(&pRenderer->pActiveZBuffer[v60 + 640 * v59], dword_F8B168[v114 + 6], v114 + 7);
+        }
+        ++v114;
+      }
+      while ( v114 < 6 );
+    }
+    result = (POINT *)sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
+    if ( result )
+    {
+      v62 = 0;
+      v109 = 0;
+      if ( dword_F8B19C == 2 )
+      {
+        do
+        {
+          if ( pParty->field_777C[9 * (v62 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] )
+            ++v109;
+          ++v62;
+        }
+        while ( v62 < 12 );
+      }
+      else
+      {
+        do
+        {
+          if ( pParty->field_C59C[9 * (v62 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
+            ++v109;
+          ++v62;
+        }
+        while ( v62 < 12 );
+      }
+      v63 = GetAsyncKeyState(17);
+      v64 = _this->CanSteal();
+      Str = (char *)v64;
+      if ( v63 && v64 )
+      {
+        v65 = pGlobalTXT_LocalizationStrings[185];
+      }
+      else
+      {
+        v65 = pGlobalTXT_LocalizationStrings[195];
+        if ( dword_F8B19C != 2 )
+          v65 = pGlobalTXT_LocalizationStrings[196];
+      }
+      sub_4B46A5(v65, 0);
+      if ( !v109 )
+        return (POINT *)v104._4B1854(
+                          __PAIR__(
+                            pParty->field_3C.field_50[2 * (unsigned int)ptr_507BC0->ptr_1C + 1],
+                            pParty->field_3C.field_50[2 * (unsigned int)ptr_507BC0->ptr_1C])
+                        - pParty->uTimePlayed);
+      v66 = pMouse->GetCursorPos(&v98);
+      result = (POINT *)(v66->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v96)->y]);
+      if ( pRenderer->pActiveZBuffer[(int)result] & 0xFFFF )
+      {
+        v67 = (pRenderer->pActiveZBuffer[(int)result] & 0xFFFF) - 1;
+        v109 = v67;
+        v68 = (int)ptr_507BC0->ptr_1C;
+        v69 = 9 * (v67 + 12 * v68);
+        v70 = (ItemGen *)&pParty->field_777C[v69];
+        if ( dword_F8B19C != 2 )
+          v70 = (ItemGen *)&pParty->field_C59C[v69 + 724];
+        if ( !v63 || !Str )
+        {
+          v93 = 0;
+          v91 = 2;
+          v89 = ptr_507BC0->ptr_1C;
+          v87 = v70;
+          v113 = uActiveCharacter - 1;
+          v71 = _this->_490EEE(v70, 4, v68, 2);
+          v39 = v113;
+          v38 = (char *)pMerchantsBuyPhrases[v71];
+          goto LABEL_45;
+        }
+        v38 = pGlobalTXT_LocalizationStrings[181];
+        v93 = 0;
+        v91 = 2;
+        v89 = ptr_507BC0->ptr_1C;
+        v87 = v70;
+        goto LABEL_44;
+      }
+    }
+  }
+  return result;
+}
+
+
+//----- (004BA928) --------------------------------------------------------
+void __cdecl sub_4BA928()
+{
+  Player *v0; // ebx@1
+  signed int v1; // esi@8
+  unsigned int v2; // eax@10
+  ItemGen *v3; // eax@11
+  unsigned __int8 v4; // dl@12
+  char *v5; // ecx@12
+  char *v6; // eax@13
+  int v7; // ST08_4@15
+  int v8; // eax@15
+  signed int v9; // esi@17
+  unsigned int v10; // eax@19
+  char *v11; // edi@19
+  int v12; // ST08_4@20
+  int v13; // eax@20
+  unsigned __int8 v14; // dl@20
+  char *v15; // ecx@20
+  char **v16; // edi@22
+  int v17; // ebx@22
+  char **v18; // esi@22
+  int v19; // eax@23
+  GUIWindow *v20; // ecx@24
+  int v21; // eax@24
+  int v22; // edx@24
+  int v23; // ebx@24
+  unsigned __int8 v24; // sf@24
+  GUIButton *v25; // eax@26
+  GUIButton *v26; // esi@26
+  int v27; // eax@26
+  unsigned int v28; // ecx@26
+  Player *v29; // edx@26
+  unsigned __int16 v30; // ax@26
+  signed int v31; // esi@31
+  unsigned int v32; // eax@33
+  int v33; // eax@34
+  int v34; // ST08_4@35
+  int v35; // eax@35
+  char *v36; // edx@36
+  GUIWindow *v37; // edi@42
+  signed int v38; // esi@42
+  unsigned int v39; // esi@44
+  int v40; // eax@44
+  unsigned int v41; // eax@45
+  int v42; // eax@47
+  int v43; // ecx@52
+  GUIButton *v44; // eax@54
+  GUIButton *v45; // esi@54
+  int v46; // eax@54
+  char *v47; // eax@56
+  int v48; // eax@56
+  unsigned int v49; // ecx@56
+  int v50; // edx@56
+  int v51; // eax@56
+  unsigned __int16 v52; // ax@56
+  int v53; // eax@60
+  int v54; // eax@60
+  signed int v55; // ebx@65
+  Texture *v56; // eax@67
+  unsigned int v57; // edi@68
+  Texture *v58; // ST1C_4@68
+  int v59; // eax@68
+  int v60; // edi@69
+  signed int v61; // ebx@73
+  Texture *v62; // eax@75
+  int v63; // edi@76
+  Texture *v64; // ST1C_4@76
+  unsigned int v65; // ST18_4@76
+  int v66; // eax@76
+  int v67; // edi@77
+  signed int v68; // ecx@81
+  SHORT v69; // bx@89
+  bool v70; // eax@89
+  const char *v71; // ecx@91
+  void *v72; // eax@95
+  POINT *v73; // esi@97
+  int v74; // ecx@97
+  int v75; // eax@98
+  int v76; // ecx@98
+  ItemGen *v77; // ecx@99
+  unsigned __int8 v78; // bl@104
+  char **v79; // edi@105
+  int v80; // ebx@105
+  char **v81; // esi@105
+  int v82; // eax@106
+  GUIWindow *v83; // ecx@107
+  int v84; // eax@107
+  int v85; // edx@107
+  int v86; // ebx@107
+  GUIButton *v87; // eax@109
+  GUIButton *v88; // esi@109
+  int v89; // eax@109
+  unsigned int v90; // ecx@109
+  int v91; // edx@109
+  unsigned __int16 v92; // ax@109
+  signed int v93; // edx@114
+  POINT *v94; // edi@120
+  __int32 v95; // ecx@120
+  void *v96; // ST14_4@122
+  unsigned __int8 v97; // bl@122
+  ItemGen *v98; // ST10_4@122
+  int v99; // eax@122
+  char *v100; // eax@122
+  const char *v101; // ST18_4@122
+  unsigned __int16 v102; // ST14_2@122
+  int v103; // eax@122
+  signed int v104; // edi@123
+  Texture *v105; // eax@125
+  int v106; // ebx@126
+  Texture *v107; // ST1C_4@126
+  unsigned int v108; // ST18_4@126
+  int v109; // eax@126
+  int v110; // ebx@127
+  GUIWindow *v111; // [sp-18h] [bp-11Ch]@36
+  unsigned int v112; // [sp-14h] [bp-118h]@13
+  int v113; // [sp-14h] [bp-118h]@36
+  ItemGen *v114; // [sp-10h] [bp-114h]@12
+  unsigned int v115; // [sp-10h] [bp-114h]@13
+  ItemGen *v116; // [sp-10h] [bp-114h]@20
+  int v117; // [sp-10h] [bp-114h]@36
+  void *v118; // [sp-Ch] [bp-110h]@12
+  unsigned __int16 v119; // [sp-Ch] [bp-110h]@13
+  void *v120; // [sp-Ch] [bp-110h]@20
+  char *v121; // [sp-8h] [bp-10Ch]@13
+  int v122; // [sp-8h] [bp-10Ch]@20
+  unsigned int v123; // [sp-4h] [bp-108h]@13
+  __int64 *v124; // [sp-4h] [bp-108h]@20
+  int v125; // [sp-4h] [bp-108h]@68
+  int v126; // [sp-4h] [bp-108h]@76
+  int v127; // [sp-4h] [bp-108h]@126
+  POINT v128; // [sp+Ch] [bp-F8h]@8
+  POINT v129; // [sp+14h] [bp-F0h]@18
+  char v130; // [sp+1Ch] [bp-E8h]@120
+  POINT a2; // [sp+24h] [bp-E0h]@8
+  POINT v132; // [sp+2Ch] [bp-D8h]@120
+  POINT v133; // [sp+34h] [bp-D0h]@17
+  char v134; // [sp+3Ch] [bp-C8h]@97
+  POINT v135; // [sp+44h] [bp-C0h]@31
+  POINT v136; // [sp+4Ch] [bp-B8h]@97
+  POINT v137; // [sp+54h] [bp-B0h]@17
+  POINT v138; // [sp+5Ch] [bp-A8h]@32
+  POINT v139; // [sp+64h] [bp-A0h]@17
+  POINT v140; // [sp+6Ch] [bp-98h]@31
+  POINT v141; // [sp+74h] [bp-90h]@8
+  POINT v142; // [sp+7Ch] [bp-88h]@31
+  POINT v143; // [sp+84h] [bp-80h]@9
+  GUIWindow v144; // [sp+8Ch] [bp-78h]@1
+  char *Str; // [sp+E0h] [bp-24h]@56
+  int v146; // [sp+E4h] [bp-20h]@24
+  int v147; // [sp+E8h] [bp-1Ch]@1
+  int v148; // [sp+ECh] [bp-18h]@1
+  __int32 v149; // [sp+F0h] [bp-14h]@8
+  Player *_this; // [sp+F4h] [bp-10h]@1
+  unsigned __int8 uPlayerID; // [sp+FBh] [bp-9h]@15
+  int v152; // [sp+FCh] [bp-8h]@24
+  int v153; // [sp+100h] [bp-4h]@44
+
+  v0 = pPlayers[uActiveCharacter];
+  _this = pPlayers[uActiveCharacter];
+  memcpy(&v144, ptr_507BC0, sizeof(v144));
+  v144.uFrameX = 483;
+  v144.uFrameWidth = 148;
+  v144.uFrameZ = 334;
+  v148 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
+  v147 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xE1u, 0xCDu, 0x23u);
+  if ( dword_F8B19C > 5 )
+  {
+    if ( dword_F8B19C == 6 )
+    {
+      pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
+      sub_4B46A5(pGlobalTXT_LocalizationStrings[195], 0);
+      if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+        return;
+      v149 = 0;
+      v93 = 0;
+      do
+      {
+        if ( pParty->field_C59C[9 * (v93 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
+          ++v149;
+        ++v93;
+      }
+      while ( v93 < 8 );
+      if ( v149 )
+      {
+        v94 = pMouse->GetCursorPos(&v132);
+        v149 = pRenderer->pActiveZBuffer[v94->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v130)->y]];
+        v95 = v149;
+        if ( v149 && v149 != -65536 )
+        {
+          --v149;
+          v96 = ptr_507BC0->ptr_1C;
+          v97 = uActiveCharacter - 1;
+          v98 = (ItemGen *)&pParty->field_C59C[9 * (v95 - 1 + 12 * (int)v96) + 724];
+          v99 = _this->_490EEE(
+                  (ItemGen *)&pParty->field_C59C[9 * (v95 - 1 + 12 * (int)v96) + 724],
+                  2,
+                  (int)ptr_507BC0->ptr_1C,
+                  2);
+          v100 = sub_495461((char *)pMerchantsBuyPhrases[v99], v97, v98, (char *)v96, 2, 0);
+          v101 = v100;
+          v102 = v148;
+          v103 = pFontArrus->CalcTextHeight(v100, &v144, 0, 0);
+          v144.DrawTitleText(pFontArrus, 0, (174 - v103) / 2 + 138, v102, v101, 3u);
+        }
+        v104 = 0;
+        v153 = 0;
+        do
+        {
+          if ( pParty->field_C59C[9 * (v104 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] )
+          {
+            v105 = dword_F8B168[v104];
+            if ( v104 >= 4 )
+            {
+              v110 = 90 - ((signed int)v105->uTextureWidth >> 1);
+              pRenderer->DrawTextureTransparent(v153 + v110 - 420, 0x7Eu, dword_F8B168[v104]);
+              v127 = v104 + 1;
+              v109 = v153 + v110 + 80220;
+            }
+            else
+            {
+              v106 = 98 - v105->uTextureHeight;
+              v107 = dword_F8B168[v104];
+              v108 = 98 - v105->uTextureHeight;
+              v152 = 86 - ((signed int)v105->uTextureWidth >> 1);
+              pRenderer->DrawTextureTransparent(v152 + v153, v108, v107);
+              v127 = v104 + 1;
+              v109 = v152 + v153 + 640 * v106;
+            }
+            ZBuffer_DoFill(&pRenderer->pActiveZBuffer[v109], dword_F8B168[v104], v127);
+          }
+          v153 += 105;
+          ++v104;
+        }
+        while ( v104 < 8 );
+        return;
+      }
+      v72 = ptr_507BC0->ptr_1C;
+      goto LABEL_96;
+    }
+    if ( dword_F8B19C == 94 )
+    {
+      draw_leather();
+      CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+      v79 = pShopOptions;
+      pShopOptions[0] = pGlobalTXT_LocalizationStrings[200];
+      pShopOptions[1] = pGlobalTXT_LocalizationStrings[113];
+      pShopOptions[2] = pGlobalTXT_LocalizationStrings[179];
+      v80 = 0;
+      v81 = pShopOptions;
+      do
+      {
+        v82 = pFontArrus->CalcTextHeight(*v81, &v144, 0, 0);
+        ++v81;
+        v80 += v82;
+      }
+      while ( (signed int)v81 < (signed int)&pShopOptions[3] );
+      v83 = pDialogueWindow;
+      v152 = (174 - v80) / 3;
+      v84 = pDialogueWindow->pStartingPosActiveItem;
+      v85 = v84 + pDialogueWindow->pNumPresenceButton;
+      v86 = (3 * (58 - v152) - v80) / 2 - v152 / 2 + 138;
+      v24 = -pDialogueWindow->pNumPresenceButton < 0;
+      _this = (Player *)pDialogueWindow->pStartingPosActiveItem;
+      if ( v24 ^ __OFSUB__(v84, v85) )
+      {
+        v153 = 2;
+        do
+        {
+          v87 = v83->GetControl((unsigned int)_this);
+          v88 = v87;
+          v87->uY = v152 + v86;
+          v89 = pFontArrus->CalcTextHeight(*v79, &v144, 0, 0);
+          v90 = v88->uY;
+          v91 = v153;
+          v88->uHeight = v89;
+          v86 = v90 + v89 - 1;
+          v88->uW = v86;
+          v92 = v147;
+          if ( pDialogueWindow->pCurrentPosActiveItem != v91 )
+            v92 = v148;
+          v144.DrawTitleText(pFontArrus, 0, v90, v92, *v79, 3u);
+          v83 = pDialogueWindow;
+          ++v153;
+          ++v79;
+          _this = (Player *)((char *)_this + 1);
+        }
+        while ( (signed int)_this < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
+      }
+      return;
+    }
+    if ( dword_F8B19C != 95 )
+    {
+      if ( dword_F8B19C != 96 || !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+        return;
+      v152 = 0;
+      v37 = pDialogueWindow;
+      //v38 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)ptr_507BC0->ptr_1C] * 500.0);
+      v38 = (signed __int64)(p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].flt_24 * 500.0);
+      _this = (Player *)(v38 * (100 - v0->GetMerchant()) / 100);
+      if ( (signed int)_this < v38 / 3 )
+        _this = (Player *)(v38 / 3);
+      v39 = v37->pStartingPosActiveItem;
+      v40 = v37->pNumPresenceButton;
+      v153 = 0;
+      if ( (signed int)v39 < (signed int)(v39 + v40) )
+      {
+        do
+        {
+          v41 = v37->GetControl(v39)->uControlParam - 36;
+          if ( byte_4ED970_skill_learn_ability_by_class_table[v0->uClass][v41] && !v0->pActiveSkills[v41] )
+          {
+            v42 = pFontArrus->CalcTextHeight(pSkillNames[v41], &v144, 0, 0);
+            v152 += v42;
+            ++v153;
+          }
+          ++v39;
+        }
+        while ( (signed int)v39 < v37->pNumPresenceButton + v37->pStartingPosActiveItem );
+        if ( v153 )
+        {
+          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[401], _this);
+          v144.DrawTitleText(pFontArrus, 0, 0x92u, 0, pTmpBuf, 3u);
+          _this = (Player *)((149 - v152) / v153);
+          if ( (149 - v152) / v153 > 32 )
+            _this = (Player *)32;
+          v43 = (149 - v153 * (signed int)_this - v152) / 2 - (signed int)_this / 2 + 162;
+          v152 = v37->pStartingPosActiveItem;
+          v146 = v43;
+          if ( v152 < v152 + v37->pNumPresenceButton )
+          {
+            v153 = 2;
+            do
+            {
+              v44 = v37->GetControl(v152);
+              v45 = v44;
+              v46 = v44->uControlParam - 36;
+              if ( !byte_4ED970_skill_learn_ability_by_class_table[v0->uClass][v46] || v0->pActiveSkills[v46] )
+              {
+                v45->uW = 0;
+                v45->uHeight = 0;
+                v45->uY = 0;
+              }
+              else
+              {
+                v47 = pSkillNames[v46];
+                v45->uY = (unsigned int)((char *)_this + v146);
+                Str = v47;
+                v48 = pFontArrus->CalcTextHeight(v47, &v144, 0, 0);
+                v49 = v45->uY;
+                v50 = v153;
+                v45->uHeight = v48;
+                v51 = v49 + v48 - 1;
+                v45->uW = v51;
+                v146 = v51;
+                v52 = v147;
+                if ( pDialogueWindow->pCurrentPosActiveItem != v50 )
+                  v52 = v148;
+                v144.DrawTitleText(pFontArrus, 0, v49, v52, Str, 3u);
+              }
+              v53 = v37->pStartingPosActiveItem;
+              ++v152;
+              v54 = v37->pNumPresenceButton + v53;
+              ++v153;
+            }
+            while ( v152 < v54 );
+          }
+          return;
+        }
+      }
+      sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[544], v0->pName, pClassNames[v0->uClass]);
+      strcat(pTmpBuf, "\n \n");
+      strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
+      v11 = 0;
+      v36 = pTmpBuf;
+      v123 = 3;
+      v121 = pTmpBuf;
+      v119 = v147;
+      v117 = 0;
+      v113 = 0;
+      v111 = &v144;
+LABEL_63:
+      v115 = (174 - pFontArrus->CalcTextHeight(v36, v111, v113, v117)) / 2 + 138;
+      v112 = (unsigned int)v11;
+LABEL_14:
+      v144.DrawTitleText(pFontArrus, v112, v115, v119, v121, v123);
+      return;
+    }
+LABEL_64:
+    pRenderer->DrawTextureIndexed(8u, 8u, dword_F8B164);
+    if ( dword_F8B19C == 2 )
+    {
+      v55 = 0;
+      v153 = 0;
+      do
+      {
+        if ( pParty->field_777C[9 * (v55 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] )
+        {
+          v56 = dword_F8B168[v55];
+          if ( v55 >= 4 )
+          {
+            v60 = 90 - ((signed int)v56->uTextureWidth >> 1);
+            pRenderer->DrawTextureTransparent(v60 + v153 - 420, 0x7Eu, dword_F8B168[v55]);
+            v125 = v55 + 1;
+            v59 = v60 + v153 + 80220;
+          }
+          else
+          {
+            v57 = 98 - v56->uTextureHeight;
+            v58 = dword_F8B168[v55];
+            v152 = 86 - ((signed int)v56->uTextureWidth >> 1);
+            pRenderer->DrawTextureTransparent(v153 + v152, v57, v58);
+            v125 = v55 + 1;
+            v59 = v153 + v152 + 640 * v57;
+          }
+          ZBuffer_DoFill(&pRenderer->pActiveZBuffer[v59], dword_F8B168[v55], v125);
+        }
+        v153 += 105;
+        ++v55;
+      }
+      while ( v55 < 8 );
+      v11 = 0;
+    }
+    else
+    {
+      v11 = 0;
+      v61 = 0;
+      v153 = 0;
+      do
+      {
+        if ( (char *)pParty->field_C59C[9 * (v61 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] != v11 )
+        {
+          v62 = dword_F8B168[v61];
+          if ( v61 >= 4 )
+          {
+            v67 = 90 - ((signed int)v62->uTextureWidth >> 1);
+            pRenderer->DrawTextureTransparent(v153 + v67 - 420, 0x7Eu, dword_F8B168[v61]);
+            v126 = v61 + 1;
+            v66 = v153 + v67 + 80220;
+          }
+          else
+          {
+            v63 = 98 - v62->uTextureHeight;
+            v64 = dword_F8B168[v61];
+            v65 = 98 - v62->uTextureHeight;
+            v152 = 86 - ((signed int)v62->uTextureWidth >> 1);
+            pRenderer->DrawTextureTransparent(v152 + v153, v65, v64);
+            v126 = v61 + 1;
+            v66 = v152 + v153 + 640 * v63;
+          }
+          ZBuffer_DoFill(&pRenderer->pActiveZBuffer[v66], dword_F8B168[v61], v126);
+          v11 = 0;
+        }
+        v153 += 105;
+        ++v61;
+      }
+      while ( v61 < 8 );
+    }
+    if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+      return;
+    v68 = 0;
+    v149 = (__int32)v11;
+    if ( dword_F8B19C == 2 )
+    {
+      do
+      {
+        if ( (char *)pParty->field_777C[9 * (v68 + 12 * (unsigned int)ptr_507BC0->ptr_1C)] != v11 )
+          ++v149;
+        ++v68;
+      }
+      while ( v68 < 6 );
+    }
+    else
+    {
+      do
+      {
+        if ( (char *)pParty->field_C59C[9 * (v68 + 12 * (unsigned int)ptr_507BC0->ptr_1C) + 724] != v11 )
+          ++v149;
+        ++v68;
+      }
+      while ( v68 < 6 );
+    }
+    v69 = GetAsyncKeyState(17);
+    v70 = _this->CanSteal();
+    Str = (char *)v70;
+    if ( v69 == (short)v11 || (char *)v70 == v11 )
+    {
+      v71 = pGlobalTXT_LocalizationStrings[195];
+      if ( dword_F8B19C != 2 )
+        v71 = pGlobalTXT_LocalizationStrings[196];
+    }
+    else
+    {
+      v71 = pGlobalTXT_LocalizationStrings[185];
+    }
+    sub_4B46A5(v71, 0);
+    if ( (char *)v149 != v11 )
+    {
+      v73 = pMouse->GetCursorPos(&v136);
+      v74 = pRenderer->pActiveZBuffer[v73->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v134)->y]] & 0xFFFF;
+      if ( !v74 )
+        return;
+      v149 = v74 - 1;
+      v75 = (int)ptr_507BC0->ptr_1C;
+      v76 = 9 * (v74 - 1 + 12 * v75);
+      if ( dword_F8B19C == 2 )
+        v77 = (ItemGen *)&pParty->field_777C[v76];
+      else
+        v77 = (ItemGen *)&pParty->field_C59C[v76 + 724];
+      if ( v69 == (short)v11 || Str == v11 )
+      {
+        v124 = (__int64 *)v11;
+        v122 = 2;
+        v120 = ptr_507BC0->ptr_1C;
+        v116 = v77;
+        v78 = uActiveCharacter - 1;
+        v15 = (char *)pMerchantsBuyPhrases[_this->_490EEE(v77, 2, v75, 2)];
+        v14 = v78;
+      }
+      else
+      {
+        v124 = (__int64 *)v11;
+        v122 = 2;
+        v120 = ptr_507BC0->ptr_1C;
+        v116 = v77;
+        v15 = pGlobalTXT_LocalizationStrings[181];
+        v14 = uActiveCharacter - 1;
+      }
+LABEL_36:
+      v36 = sub_495461(v15, v14, v116, (char *)v120, v122, v124);
+      v123 = 3;
+      v121 = v36;
+      v119 = v148;
+      v117 = (int)v11;
+      v113 = (int)v11;
+      v111 = &v144;
+      goto LABEL_63;
+    }
+    v72 = ptr_507BC0->ptr_1C;
+LABEL_96:
+    v144._4B1854(
+      __PAIR__(pParty->field_3C.field_50[2 * (int)v72 + 1], pParty->field_3C.field_50[2 * (int)v72])
+    - pParty->uTimePlayed);
+    return;
+  }
+  if ( dword_F8B19C == 5 )
+  {
+    draw_leather();
+    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    sub_4B46A5(pGlobalTXT_LocalizationStrings[198], 0);
+    if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()
+      || (v31 = pMouse->GetCursorPos(&v135)->x - 14,
+          v149 = (v31 >> 5) + 14 * ((pMouse->GetCursorPos(&v142)->y - 17) >> 5),
+          pMouse->GetCursorPos(&v140)->x <= 13)
+      || pMouse->GetCursorPos(&v138)->x >= 462
+      || (v32 = v0->GetItemIDAtInventoryIndex((int *)&v149), v11 = 0, !v32)
+      || (v33 = 9 * v32, !(v0->field_1F5[4 * v33 + 15] & 2)) )
+      return;
+    v124 = 0;
+    v122 = 5;
+    v120 = ptr_507BC0->ptr_1C;
+    v116 = (ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * v33 + 5];
+    v34 = (int)ptr_507BC0->ptr_1C;
+    uPlayerID = uActiveCharacter - 1;
+    v35 = v0->_490EEE((ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[4 * v33 + 5], 2, v34, 5);
+    v14 = uPlayerID;
+    v15 = (char *)pMerchantsRepairPhrases[v35];
+    goto LABEL_36;
+  }
+  if ( dword_F8B19C == 1 )
+  {
+    if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+    {
+      v16 = pShopOptions;
+      pShopOptions[0] = pGlobalTXT_LocalizationStrings[134];
+      pShopOptions[1] = pGlobalTXT_LocalizationStrings[152];
+      pShopOptions[2] = pGlobalTXT_LocalizationStrings[159];
+      v17 = 0;
+      pShopOptions[3] = pGlobalTXT_LocalizationStrings[160];
+      v18 = pShopOptions;
+      do
+      {
+        v19 = pFontArrus->CalcTextHeight(*v18, &v144, 0, 0);
+        ++v18;
+        v17 += v19;
+      }
+      while ( (signed int)v18 < (signed int)&unk_F8B1C8 );
+      v20 = pDialogueWindow;
+      v146 = (174 - v17) / 4;
+      v21 = pDialogueWindow->pStartingPosActiveItem;
+      v22 = v21 + pDialogueWindow->pNumPresenceButton;
+      v23 = (174 - 4 * (174 - v17) / 4 - v17) / 2 - (174 - v17) / 4 / 2 + 138;
+      v24 = -pDialogueWindow->pNumPresenceButton < 0;
+      v152 = pDialogueWindow->pStartingPosActiveItem;
+      if ( v24 ^ __OFSUB__(v21, v22) )
+      {
+        _this = (Player *)2;
+        do
+        {
+          v25 = v20->GetControl(v152);
+          v26 = v25;
+          v25->uY = v146 + v23;
+          v27 = pFontArrus->CalcTextHeight(*v16, &v144, 0, 0);
+          v28 = v26->uY;
+          v29 = _this;
+          v26->uHeight = v27;
+          v23 = v28 + v27 - 1;
+          v26->uW = v23;
+          v30 = v147;
+          if ( (Player *)pDialogueWindow->pCurrentPosActiveItem != v29 )
+            v30 = v148;
+          v144.DrawTitleText(pFontArrus, 0, v28, v30, *v16, 3u);
+          v20 = pDialogueWindow;
+          _this = (Player *)((char *)_this + 1);
+          ++v16;
+          ++v152;
+        }
+        while ( v152 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
+      }
+    }
+    return;
+  }
+  if ( dword_F8B19C == 2 )
+    goto LABEL_64;
+  if ( dword_F8B19C == 3 )
+  {
+    draw_leather();
+    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    sub_4B46A5(pGlobalTXT_LocalizationStrings[199], 0);
+    if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win()
+      || (v9 = pMouse->GetCursorPos(&v139)->x - 14,
+          v149 = (v9 >> 5) + 14 * ((pMouse->GetCursorPos(&v133)->y - 17) >> 5),
+          pMouse->GetCursorPos(&v137)->x <= 13)
+      || pMouse->GetCursorPos(&v129)->x >= 462
+      || (v10 = v0->GetItemIDAtInventoryIndex((int *)&v149), v11 = 0, !v10) )
+      return;
+    v124 = 0;
+    v122 = 3;
+    v120 = ptr_507BC0->ptr_1C;
+    v116 = (ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v10 + 5];
+    v12 = (int)ptr_507BC0->ptr_1C;
+    uPlayerID = uActiveCharacter - 1;
+    v13 = v0->_490EEE(v116, 2, v12, 3);
+    v14 = uPlayerID;
+    v15 = (char *)pMerchantsSellPhrases[v13];
+    goto LABEL_36;
+  }
+  if ( dword_F8B19C == 4 )
+  {
+    draw_leather();
+    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
+    sub_4B46A5(pGlobalTXT_LocalizationStrings[197], 0);
+    if ( sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+    {
+      v1 = pMouse->GetCursorPos(&a2)->x - 14;
+      v149 = (v1 >> 5) + 14 * ((pMouse->GetCursorPos(&v128)->y - 17) >> 5);
+      if ( pMouse->GetCursorPos(&v141)->x > 13 )
+      {
+        if ( pMouse->GetCursorPos(&v143)->x < 462 )
+        {
+          v2 = v0->GetItemIDAtInventoryIndex((int *)&v149);
+          if ( v2 )
+          {
+            v3 = (ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v2 + 5];
+            if ( v3->uAttributes & 1 )
+            {
+              v118 = ptr_507BC0->ptr_1C;
+              v4 = uActiveCharacter - 1;
+              v5 = "%24";
+              v114 = v3;
+            }
+            else
+            {
+              v118 = ptr_507BC0->ptr_1C;
+              v114 = v3;
+              v7 = (int)ptr_507BC0->ptr_1C;
+              uPlayerID = uActiveCharacter - 1;
+              v8 = v0->_490EEE(v3, 2, v7, 4);
+              v4 = uPlayerID;
+              v5 = (char *)pMerchantsIdentifyPhrases[v8];
+            }
+            v6 = sub_495461(v5, v4, v114, (char *)v118, 4, 0);
+            v123 = 3;
+            v121 = v6;
+            v119 = v148;
+            v115 = (174 - pFontArrus->CalcTextHeight(v6, &v144, 0, 0)) / 2 + 138;
+            v112 = 0;
+            goto LABEL_14;
+          }
+        }
+      }
+    }
+  }
+}
+
+//----- (004BB756) --------------------------------------------------------
+signed int __fastcall sub_4BB756(signed int a1)
+{
+  unsigned int v1; // esi@8
+  unsigned int v3; // ecx@10
+  char *v4; // esi@15
+  int v5; // ebx@16
+  int v6; // ST38_4@16
+  char *v7; // esi@18
+  int v8; // ebx@19
+  int v9; // ST30_4@19
+  int v10; // ST44_4@19
+  int v11; // ST48_4@19
+  int v12; // ST4C_4@19
+  int v13; // ST50_4@19
+  int v14; // ST3C_4@19
+  int v15; // ST40_4@19
+  int v16; // ST34_4@19
+  int v17; // ST38_4@19
+  Player *v18; // esi@21
+  int v19; // eax@26
+  int v20; // eax@39
+  SoundID v21; // [sp-20h] [bp-54h]@25
+  signed int v22; // [sp-1Ch] [bp-50h]@25
+  unsigned int v23; // [sp-18h] [bp-4Ch]@25
+  signed int v24; // [sp-14h] [bp-48h]@25
+  signed int v25; // [sp-10h] [bp-44h]@25
+  int v26; // [sp-10h] [bp-44h]@32
+  int v27; // [sp-Ch] [bp-40h]@25
+  unsigned int v28; // [sp-Ch] [bp-40h]@32
+  unsigned int v29; // [sp-8h] [bp-3Ch]@25
+  __int16 v30; // [sp-8h] [bp-3Ch]@32
+  int v31; // [sp-4h] [bp-38h]@25
+  int v32; // [sp-4h] [bp-38h]@32
+
+  if ( a1 > 39 )
+  {
+    if ( a1 != 40 )
+    {
+      if ( a1 == 41 )
+      {
+        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        {
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+          ++pMessageQueue_50CBD0->uNumMessages;
+        }
+        dword_50C9DC = 195;
+        ptr_50C9E0 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
+        return 0;
+      }
+      if ( a1 == 42 )
+      {
+        v32 = 0;
+        v30 = 0;
+        v28 = 133;
+        v26 = 46;
+      }
+      else
+      {
+        if ( a1 == 43 )
+        {
+          v32 = 0;
+          v30 = 0;
+          v28 = 133;
+          v26 = 51;
+        }
+        else
+        {
+          if ( a1 != 52 )
+            return 0;
+          v32 = 0;
+          v30 = 0;
+          v28 = 133;
+          v26 = 86;
+        }
+      }
+      _42777D_CastSpell_UseWand_ShootArrow(v26, 0, v28, v30, v32);
+      return 0;
+    }
+    v20 = pOtherOverlayList->_4418B1(10005, 201, 0, 65536);
+    pParty->pPartyBuffs[18].Apply(pParty->uTimePlayed + 46080, 3u, 0, v20, 0);
+    pParty->pPartyBuffs[18].uFlags |= 1u;
+    v31 = 0;
+    v29 = 0;
+    v27 = 0;
+    v25 = 0;
+    v24 = -1;
+    v23 = 0;
+    v22 = 0;
+    v21 = (SoundID)12040;
+LABEL_40:
+    pAudioPlayer->PlaySound(v21, v22, v23, v24, v25, v27, v29, v31);
+    return 0;
+  }
+  if ( a1 == 39 )
+  {
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    {
+      ShowStatusBarString(pGlobalTXT_LocalizationStrings[494], 2u);
+      v31 = 0;
+      v29 = 0;
+      v27 = 0;
+      v25 = 0;
+      v24 = -1;
+      v23 = 0;
+      v22 = 0;
+      v21 = (SoundID)203;
+    }
+    else
+    {
+      v19 = pOtherOverlayList->_4418B1(10008, 203, 0, 65536);
+      pParty->pPartyBuffs[7].Apply(pParty->uTimePlayed + 30720, 3u, 1u, v19, 0);
+      pParty->pPartyBuffs[7].uFlags |= 1u;
+      v31 = 0;
+      v29 = 0;
+      v27 = 0;
+      v25 = 0;
+      v24 = -1;
+      v23 = 0;
+      v22 = 0;
+      v21 = (SoundID)11090;
+    }
+    goto LABEL_40;
+  }
+  if ( a1 == 10 )
+  {
+    v18 = pParty->pPlayers;
+    do
+    {
+      v18->sHealth = v18->GetMaxHealth();
+      ++v18;
+    }
+    while ( (signed int)v18 < (signed int)pParty->pHirelings );
+    return 0;
+  }
+  if ( a1 == 11 )
+  {
+    v7 = (char *)&pParty->pPlayers[0].pConditions[15];
+    do
+    {
+      v8 = *((int *)v7 - 2);
+      v9 = *((int *)v7 - 1);
+      v10 = *(int *)v7;
+      v11 = *((int *)v7 + 1);
+      v12 = *((int *)v7 + 2);
+      v13 = *((int *)v7 + 3);
+      v14 = *((int *)v7 + 8);
+      v15 = *((int *)v7 + 9);
+      v16 = *((int *)v7 + 4);
+      v17 = *((int *)v7 + 5);
+      memset(v7 - 120, 0, 0xA0u);
+      *((int *)v7 + 2) = v12;
+      *((int *)v7 + 3) = v13;
+      *(int *)v7 = v10;
+      *((int *)v7 + 1) = v11;
+      *((int *)v7 - 1) = v9;
+      *((int *)v7 + 8) = v14;
+      *((int *)v7 + 9) = v15;
+      *((int *)v7 + 4) = v16;
+      *((int *)v7 - 2) = v8;
+      *((int *)v7 + 5) = v17;
+      *((int *)v7 + 1585) = ((Player *)(v7 - 120))->GetMaxHealth();
+      v7 += 6972;
+    }
+    while ( (signed int)v7 < (signed int)&pParty->pHirelings[1].evtb );
+    return 0;
+  }
+  if ( a1 == 12 )
+  {
+    v4 = (char *)&pParty->pPlayers[0].pActiveSkills[8];
+    do
+    {
+      v5 = *((int *)v4 - 32);
+      v6 = *((int *)v4 - 31);
+      memset(v4 - 280, 0, 0xA0u);
+      *(int *)v4 = v5;
+      *((int *)v4 + 1) = v6;
+      *((int *)v4 + 1545) = ((Player *)(v4 - 280))->GetMaxHealth();
+      v4 += 6972;
+    }
+    while ( (signed int)v4 < (signed int)&pParty->field_777C[22] );
+    return 0;
+  }
+  if ( a1 == 33 )
+  {
+    v1 = 14;
+    if ( pParty->uNumFoodRations >= 0xE )
+      return 1;
+    v3 = 1;
+LABEL_13:
+    Party::GiveFood(v3);
+    if ( pParty->uNumFoodRations > v1 )
+      pParty->uNumFoodRations = v1;
+    return 0;
+  }
+  if ( a1 == 34 )
+  {
+    v1 = 14;
+    if ( pParty->uNumFoodRations >= 0xE )
+      return 1;
+    v3 = 2;
+    goto LABEL_13;
+  }
+  return 0;
+}
+// 50C9DC: using guessed type int dword_50C9DC;
+
+//----- (004BBA85) --------------------------------------------------------
+const char *sub_4BBA85_bounties()
+{
+  int v0; // edi@1
+  signed __int64 v1; // qax@2
+  int i; // eax@2
+  int v3; // edx@3
+  int v4; // edi@14
+  __int16 v5; // ax@14
+  char v6; // zf@14
+  Player *v7; // ebx@16
+  const char *result; // eax@19
+
+  uDialogueType = 83;
+  pDialogueWindow->Release();
+  pDialogueWindow = GUIWindow::Create(0, 0, 640, 350, WINDOW_MainMenu, 0, 0);
+  pBtn_ExitCancel = pDialogueWindow->CreateButton(
+                 471u,
+                 445u,
+                 169u,
+                 35u,
+                 1,
+                 0,
+                 0x71u,
+                 0,
+                 0,
+                 pGlobalTXT_LocalizationStrings[34],// "Cancel"
+                 (Texture *)(uTextureID_506438 != -1 ? &pIcons_LOD->pTextures[uTextureID_506438] : 0),
+                 0);
+  pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, 0x51u, 0, 0, "", 0);
+  pDialogueWindow->CreateButton(480u, 160u, 140u, 30u, 1, 0, 0, 0x53u, 0, "", 0);
+  pDialogueWindow->_41D08F(1, 1, 0, 2);
+  dword_F8B19C = -1;
+  v0 = (int)((char *)ptr_507BC0->ptr_1C - 102);
+  if ( (signed __int64)__PAIR__(pParty->field_3C.field_0[2 * v0 + 1], pParty->field_3C.field_0[2 * v0]) < (signed __int64)pParty->uTimePlayed )
+  {
+    pParty->field_75A[v0] = 0;
+    v1 = (signed __int64)((double)(0x12750000 * (pParty->uCurrentMonth + 12i64 * pParty->uCurrentYear - 14015))
+                        * 0.033333335);
+    pParty->field_3C.field_0[2 * v0] = v1;
+    pParty->field_3C.field_0[2 * v0 + 1] = HIDWORD(v1);
+    for ( i = rand(); ; i = rand() )
+    {
+      v3 = i % 258 + 1;
+      pParty->field_750[v0] = v3;
+      if ( (unsigned __int16)v3 < 0x73u || (unsigned __int16)v3 > 0x84u )
+      {
+        if ( ((unsigned __int16)v3 < 0xEBu || (unsigned __int16)v3 > 0xFCu)
+          && ((unsigned __int16)v3 < 0x85u || (unsigned __int16)v3 > 0x96u)
+          && ((unsigned __int16)v3 < 0x97u || (unsigned __int16)v3 > 0xBAu)
+          && ((unsigned __int16)v3 < 0xC4u || (unsigned __int16)v3 > 0xC6u) )
+          break;
+      }
+    }
+  }
+  v4 = v0;
+  v5 = pParty->field_750[v4];
+  v6 = pParty->field_75A[v4] == 0;
+  word_F8B1A0 = pParty->field_750[v4];
+  if ( v6 )
+  {
+    v6 = v5 == 0;
+    result = pNPCTopics[351].pText;
+    if ( v6 )
+      result = pNPCTopics[353].pText;
+  }
+  else
+  {
+    if ( v5 )
+    {
+      party_finds_gold(100 * pMonsterStats->pInfos[(unsigned __int16)v5].uLevel, 0);
+      v7 = pParty->pPlayers;
+      do
+      {
+        v7->SetVariable(VAR_Award, 86);
+        ++v7;
+      }
+      while ( (signed int)v7 < (signed int)pParty->pHirelings );
+      pParty->uNumBountiesCollected += 100 * pMonsterStats->pInfos[pParty->field_750[v4]].uLevel;
+      pParty->field_750[v4] = 0;
+      pParty->field_75A[v4] = 0;
+    }
+    result = pNPCTopics[352].pText;
+  }
+  dword_F8B1A4 = (char *)result;
+  return result;
+}
+
+//----- (004BBCDD) --------------------------------------------------------
+void __cdecl sub_4BBCDD()
+{
+  signed int v0; // ebp@3
+  char *v1; // eax@4
+  __int16 v2; // cx@5
+  int v3; // esi@8
+  Player *v4; // esi@14
+  GUIButton *v5; // eax@18
+  GUIButton *v6; // esi@19
+  size_t v7; // [sp+10h] [bp-4h]@4
+
+  if ( pParty->field_7B5_in_arena_quest )
+  {
+    if ( pParty->field_7B5_in_arena_quest == -1 )
+    {
+      uDialogueType = 92;
+    }
+    else
+    {
+      v0 = 0;
+      if ( (signed int)uNumActors <= 0 )
+        goto LABEL_23;
+      v1 = (char *)&pActors[0].uAIState;
+      v7 = uNumActors;
+      do
+      {
+        v2 = *(short *)v1;
+        if ( *(short *)v1 == 5 || v2 == 11 || v2 == 19 || (v3 = *((int *)v1 + 159)) != 0 && (v3 & 7) == 4 )
+          ++v0;
+        v1 += 836;
+        --v7;
+      }
+      while ( v7 );
+      if ( v0 >= (signed int)uNumActors )
+      {
+LABEL_23:
+        uDialogueType = 91;
+        v4 = pParty->pPlayers;
+        ++*((char *)&pParty->field_75A[3] + (unsigned __int8)pParty->field_7B5_in_arena_quest + 1);
+        do
+        {
+          v4->SetVariable(VAR_Award, (unsigned __int8)pParty->field_7B5_in_arena_quest + 3);
+          ++v4;
+        }
+        while ( (signed int)v4 < (signed int)pParty->pHirelings );
+        party_finds_gold(dword_F8B1B4, 0);
+        pAudioPlayer->PlaySound((SoundID)14060, 0, 0, -1, 0, 0, 0, 0);
+        pParty->field_7B5_in_arena_quest = -1;
+      }
+      else
+      {
+        uDialogueType = 90;
+        pParty->vPosition.x = 3849;
+        pParty->vPosition.y = 5770;
+        pParty->vPosition.z = 1;
+        pParty->uFallStartY = 1;
+        pParty->sRotationY = 512;
+        pParty->sRotationX = 0;
+        pParty->uFallSpeed = 0;
+        pAudioPlayer->PlaySound((SoundID)14060, 0, 0, -1, 0, 0, 0, 0);
+      }
+    }
+  }
+  else
+  {
+    uDialogueType = 89;
+    v5 = pDialogueWindow->pControlsHead;
+    if ( v5 )
+    {
+      do
+      {
+        v6 = v5->pNext;
+        pAllocator->FreeChunk(v5);
+        v5 = v6;
+      }
+      while ( v6 );
+    }
+    pDialogueWindow->pControlsHead = 0;
+    pDialogueWindow->pControlsTail = 0;
+    pDialogueWindow->uNumControls = 0;
+    pBtn_ExitCancel = pDialogueWindow->CreateButton(
+                   0x1D7u,
+                   0x1BDu,
+                   0xA9u,
+                   0x23u,
+                   1,
+                   0,
+                   0x71u,
+                   0,
+                   0,
+                   pGlobalTXT_LocalizationStrings[79],
+                   (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
+                   0);
+    pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, 0x88u, 0x55u, 0, "", 0);
+    pDialogueWindow->CreateButton(0x1E0u, 0xBEu, 0x8Cu, 0x1Eu, 1, 0, 0x88u, 0x56u, 0, "", 0);
+    pDialogueWindow->CreateButton(0x1E0u, 0xDCu, 0x8Cu, 0x1Eu, 1, 0, 0x88u, 0x57u, 0, "", 0);
+    pDialogueWindow->CreateButton(0x1E0u, 0xFAu, 0x8Cu, 0x1Eu, 1, 0, 0x88u, 0x58u, 0, "", 0);
+    pDialogueWindow->_41D08F(4, 1, 0, 1);
+  }
+}
+// F8B1B4: using guessed type int dword_F8B1B4;
+
+//----- (004BBF61) --------------------------------------------------------
+void __fastcall _4BBF61_summon_actor(int a1, __int16 x, int y, int z)
+{
+  size_t v4; // esi@1
+  int monster_id; // edi@1
+  __int16 v6; // ax@4
+  Actor *v7; // esi@5
+  int v8; // eax@5
+  MonsterInfo *v9; // edi@5
+  MonsterDesc *v10; // ebx@5
+  unsigned __int16 *v11; // ebx@5
+  int v12; // ebx@7
+  int v13; // eax@8
+  __int16 x_; // [sp+8h] [bp-Ch]@1
+  __int16 v15; // [sp+Ch] [bp-8h]@1
+  __int16 v16; // [sp+10h] [bp-4h]@3
+  signed int ya; // [sp+1Ch] [bp+8h]@5
+
+  v4 = uNumActors;
+  monster_id = a1;
+  x_ = x;
+  v15 = a1;
+  if ( (signed int)uNumActors < 500
+    && ((signed int)pAllocator->uBigBufferSizeAligned >> 10) - ((signed int)pAllocator->uNextFreeOffsetInBigBuffer >> 10) >= 2000 )
+  {
+    v16 = 0;
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    {
+      v6 = pIndoor->GetSector(x, y, z);
+      v4 = uNumActors;
+      v16 = v6;
+    }
+    v7 = &pActors[v4];
+    v7->Reset();
+    v8 = monster_id;
+    v9 = &pMonsterStats->pInfos[monster_id];
+    v10 = &pMonsterList->pMonsters[v8 - 1];
+    strcpy(v7->pActorName, v9->pName);
+    v7->sCurrentHP = LOWORD(v9->uHP);
+    memcpy(&v7->pMonsterInfo, v9, 0x58u);
+    v7->word_000086_some_monster_id = v15;
+    v7->uActorRadius = v10->uMonsterRadius;
+    v7->uActorHeight = v10->uMonsterHeight;
+    v7->uMovementSpeed = v10->uMovementSpeed;
+    v7->vInitialPosition.x = x_;
+    v7->vPosition.x = x_;
+    BYTE2(v7->uAttributes) |= 8u;
+    v7->pMonsterInfo.uTreasureType = 0;
+    v7->pMonsterInfo.uTreasureLevel = 0;
+    v7->pMonsterInfo.uTreasureDiceSides = 0;
+    v7->pMonsterInfo.uTreasureDiceRolls = 0;
+    v7->pMonsterInfo.uTreasureDropChance = 0;
+    v7->vInitialPosition.y = y;
+    v7->vPosition.y = y;
+    v7->vInitialPosition.z = z;
+    v7->vPosition.z = z;
+    v7->uTetherDistance = 256;
+    v7->uSectorID = v16;
+    v7->uGroup = 1;
+    v7->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
+    v7->PrepareSprites(0);
+    v11 = v10->pSoundSampleIDs;
+    ya = 4;
+    do
+    {
+      pSoundList->LoadSound((signed __int16)*v11, 0);
+      ++v11;
+      --ya;
+    }
+    while ( ya );
+    v12 = 0;
+    do
+      LOWORD(v13) = pSoundList->LoadSound(v12++ + word_4EE088_sound_ids[v9->uSpell1ID], 1u);
+    while ( v13 );
+    ++uNumActors;
+  }
+}
+// 4EE088: using guessed type __int16 word_4EE088_sound_ids[];
+
+//----- (004BC109) --------------------------------------------------------
+void __cdecl ArenaFight()
+{
+  int v0; // edi@1
+  char *v1; // eax@7
+  Player *v2; // edi@9
+  int v3; // eax@10
+  signed int v4; // esi@10
+  signed __int64 v5; // qax@18
+  signed int v6; // ebx@34
+  char *v7; // edi@34
+  int v8; // eax@37
+  int v9; // esi@43
+  int v10; // eax@44
+  unsigned __int8 v11; // sf@44
+  unsigned __int8 v12; // of@44
+  signed int v13; // eax@49
+  int v14; // esi@49
+  int v15; // edx@50
+  int v16; // eax@51
+  signed int v17; // ecx@51
+  int v18; // edx@53
+  int i; // edi@55
+  int monster_y; // ST18_4@56
+  int v21; // eax@56
+  signed int v22; // [sp-4h] [bp-144h]@51
+  __int16 v23[100]; // [sp+Ch] [bp-134h]@39
+  GUIWindow window; // [sp+D4h] [bp-6Ch]@1
+  __int16 monster_ids[6]; // [sp+128h] [bp-18h]@56
+  int v26; // [sp+134h] [bp-Ch]@1
+  int v27; // [sp+138h] [bp-8h]@23
+  int num_monsters; // [sp+13Ch] [bp-4h]@17
+
+  v26 = 0;
+  pParty->field_7B5_in_arena_quest = uDialogueType;
+  memcpy(&window, pDialogueWindow, sizeof(window));
+  window.uFrameWidth = 460;
+  window.uFrameZ = 452;
+  v0 = pFontArrus->CalcTextHeight(pGlobalTXT_LocalizationStrings[575], &window, 13, 0) + 7;
+  pRenderer->BeginSceneD3D();
+
+  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    pIndoor->Draw();
+  else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+      pOutdoor->Draw();
+
+  pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
+  pRenderer->BeginScene();
+  if ( pRenderer->pRenderD3D )
+    pRenderer->FillRectFast(
+      pViewport->uViewportX,
+      pViewport->uViewportY,
+      pViewport->uViewportZ - pViewport->uViewportX,
+      pViewport->uViewportW - pViewport->uViewportY + 1,
+      pRenderer->uTargetGMask | pRenderer->uTargetBMask);
+
+  auto pTex = (uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : nullptr);
+  pRenderer->_4A6A68(
+    8u,
+    352 - v0,
+    pTex,
+    (pTex ? pTex->uTextureHeight : 26) - v0);
+
+  pRenderer->DrawTextureIndexed(8u, 347 - v0, pTexture_591428);
+  v1 = FitTextInAWindow(pGlobalTXT_LocalizationStrings[575], pFontArrus, &window, 0xDu, 0);
+  pDialogueWindow->DrawText(pFontArrus, 13, 354 - v0, 0, v1, 0, 0, 0);
+  pRenderer->EndScene();
+  pRenderer->Present();
+  pParty->vPosition.x = 3849;
+  pParty->vPosition.y = 5770;
+  pParty->vPosition.z = 1;
+  pParty->uFallStartY = 1;
+  pParty->sRotationY = 512;
+  pParty->sRotationX = 0;
+  pParty->uFallSpeed = 0;
+  if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+  {
+    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
+    *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+    ++pMessageQueue_50CBD0->uNumMessages;
+  }
+  v2 = pParty->pPlayers;
+  do
+  {
+    v3 = v2->GetActualLevel();
+    v4 = v26;
+    if ( v3 > v26 )
+    {
+      v26 = v2->GetActualLevel();
+      v4 = v26;
+    }
+    ++v2;
+  }
+  while ( (signed int)v2 < (signed int)pParty->pHirelings );
+  if ( uDialogueType == 85 )
+  {
+    num_monsters = v4;
+    goto LABEL_22;
+  }
+  if ( uDialogueType == 86 )
+  {
+    v5 = (signed __int64)((double)v26 * 1.5);
+    goto LABEL_20;
+  }
+  if ( uDialogueType == 87 )
+  {
+    LODWORD(v5) = 2 * v4;
+LABEL_20:
+    num_monsters = v5;
+LABEL_22:
+    v4 /= 2;
+    goto LABEL_24;
+  }
+  if ( uDialogueType == 88 )
+    num_monsters = 2 * v4;
+  else
+    v4 = v27;
+LABEL_24:
+  if ( v4 < 1 )
+    v4 = 1;
+  if ( v4 > 100 )
+    v4 = 100;
+  if ( num_monsters > 100 )
+    num_monsters = 100;
+  if ( v4 < 2 )
+    v4 = 2;
+  if ( num_monsters < 2 )
+    num_monsters = 2;
+  v6 = 0;
+  v27 = 1;
+  v7 = (char *)&pMonsterStats->pInfos[1].uLevel;
+  do
+  {
+    if ( v7[8] != 1 )
+    {
+      if ( !MonsterStats::BelongsToSupertype(*((short *)v7 + 22), MONSTER_SUPERTYPE_8) )
+      {
+        v8 = (unsigned __int8)*v7;
+        if ( v8 >= v4 )
+        {
+          if ( v8 <= num_monsters )
+            v23[v6++] = v27;
+        }
+      }
+    }
+    ++v27;
+    v7 += 88;
+  }
+  while ( (signed int)v7 <= (signed int)&pMonsterStats->pInfos[258].uLevel );
+  num_monsters = 6;
+  if ( v6 < 6 )
+    num_monsters = v6;
+  v9 = 0;
+  if ( num_monsters > 0 )
+  {
+    do
+    {
+      v10 = rand();
+      ++v9;
+      v12 = __OFSUB__(v9, num_monsters);
+      v11 = v9 - num_monsters < 0;
+      *((short *)&window.pControlsTail + v9 + 1) = v23[v10 % v6];
+    }
+    while ( v11 ^ v12 );
+  }
+  if ( uDialogueType == 85 )
+  {
+    v16 = rand();
+    v17 = 3;
+    v22 = 50;
+    goto LABEL_53;
+  }
+  if ( uDialogueType == 86 )
+  {
+    v16 = rand();
+    v17 = 7;
+    v22 = 100;
+LABEL_53:
+    v18 = v16 % v17;
+    v13 = v22;
+    v14 = v18 + 6;
+    goto LABEL_55;
+  }
+  if ( uDialogueType == 87 )
+  {
+    v15 = rand() % 11;
+    v13 = 200;
+    v14 = v15 + 10;
+  }
+  else
+  {
+    if ( uDialogueType == 88 )
+    {
+      v13 = 500;
+      v14 = 20;
+    }
+    else
+    {
+      v14 = v27;
+      v13 = dword_F8B1B4;
+    }
+  }
+LABEL_55:
+  i = 0;
+  for ( dword_F8B1B4 = v26 * v13; i < v14; ++i )
+  {
+    monster_y = pMonsterArenaPlacements[i].y;
+    v21 = rand();
+    _4BBF61_summon_actor((unsigned __int16)monster_ids[v21 % num_monsters], pMonsterArenaPlacements[i].x, monster_y, 1);
+  }
+  pAudioPlayer->PlaySound((SoundID)14060, 0, 0, -1, 0, 0, 0, 0);
+}
+
+
+
+
+
+//----- (004BC8D5) --------------------------------------------------------
+Texture *__cdecl sub_4BC8D5()
+{
+  int v0; // esi@1
+  char *v1; // ebx@1
+  signed int v2; // edi@1
+  signed int v3; // eax@2
+  int v4; // esi@7
+  GUIWindow *v5; // ebp@15
+  Texture *result; // eax@15
+  int v7; // [sp+10h] [bp-4h]@0
+
+  v0 = v7;
+  v1 = (char *)ptr_507BC0->ptr_1C - 139;
+  v2 = 0;
+  do
+  {
+    //v3 = p2DEvents_minus1___00[26 * (unsigned int)ptr_507BC0->ptr_1C];
+    v3 = p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].uType;
+    if ( v3 < 5 )
+      goto LABEL_12;
+    if ( v3 <= 13 )
+    {
+      v0 = rand() % word_4F0F30[(signed int)v1]
+         //+ 11 * p2DEvents_minus1___00[26 * (unsigned int)ptr_507BC0->ptr_1C]
+         + 11 * p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].uType
+         + 345;
+    }
+    else
+    {
+      if ( v3 == 14 )
+      {
+        v4 = rand() % 4;
+      }
+      else
+      {
+        if ( v3 == 15 )
+        {
+          v4 = rand() % 3 + 4;
+        }
+        else
+        {
+          if ( v3 != 16 )
+            goto LABEL_12;
+          v4 = rand() % 2 + 7;
+        }
+      }
+      v0 = rand() % word_4F0F30[(signed int)v1] + 11 * v4 + 400;
+    }
+LABEL_12:
+    if ( v0 == 487 )
+    {
+      if ( !(unsigned __int16)_449B57_test_bit(pParty->_award_bits, 239) )
+        v0 = 486;
+    }
+    v5 = ptr_507BC0;
+
+    auto _u = (ItemGen *)&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + v2 + 12 * (unsigned int)ptr_507BC0->ptr_1C;
+    _u->Reset();
+    *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v2 + 12 * (unsigned int)v5->ptr_1C)) = v0;
+    *(&pParty->pPlayers[1].pInstalledBeacons[1].field_10 + 9 * (v2++ + 12 * (unsigned int)v5->ptr_1C)) = 1;
+    result = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(pItemsTable->pItems[v0].pIconName, TEXTURE_16BIT_PALETTE)];
+    *(&dword_F8B164 + v2) = result;
+  }
+  while ( v2 < 12 );
+  return result;
+}
+
+
+//----- (004BCA33) --------------------------------------------------------
+GUIButton *__cdecl sub_4BCA33()
+{
+  pDialogueWindow->Release();
+  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, 0, 0);
+  pBtn_ExitCancel = pDialogueWindow->CreateButton(
+                 0x1D7u,
+                 0x1BDu,
+                 0xA9u,
+                 0x23u,
+                 1,
+                 0,
+                 0x71u,
+                 0,
+                 0,
+                 pGlobalTXT_LocalizationStrings[74],
+                 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
+                 0);
+  return pDialogueWindow->CreateButton(8u, 8u, 0x1C2u, 0x140u, 1, 0, 0x51u, 0, 0, "", 0);
+}
+
+//----- (004BCACC) --------------------------------------------------------
+void __fastcall sub_4BCACC_bounties(signed int a1)
+{
+  unsigned int v1; // edi@1
+  signed int v2; // ebx@1
+  signed int v3; // ecx@2
+  int v4; // eax@5
+  signed int v5; // esi@5
+  Player *v6; // ecx@5
+  signed int v7; // edx@5
+  GUIWindow *v8; // esi@10
+  unsigned int v9; // eax@12
+  int v10; // esi@31
+  int v11; // edi@31
+  int v12; // esi@32
+  __int16 v13; // bp@32
+  int v14; // edx@32
+  GUIWindow *v15; // eax@32
+  int v16; // eax@32
+  int v17; // eax@33
+  int v18; // eax@34
+  int v19; // eax@35
+  __int16 v20; // ax@37
+  __int16 v21; // ax@76
+  __int16 v22; // ax@107
+  __int16 v23; // ax@132
+  __int16 v24; // ax@163
+  int v25; // esi@190
+  __int16 v26; // ax@190
+  char v27; // zf@190
+  Player *v28; // edi@192
+  int v29; // eax@204
+  void *v30; // esi@208
+  unsigned __int64 v31; // qax@208
+  signed int v32; // edi@209
+  int v33; // eax@210
+  unsigned int v34; // eax@211
+  Player *v35; // edi@227
+  signed int v36; // esi@227
+  int v37; // ecx@227
+  int v38; // esi@230
+  int v39; // edx@235
+  void *v40; // edi@243
+  unsigned __int64 v41; // qax@243
+  void *v42; // eax@244
+  signed int v43; // edi@244
+  int v44; // edx@244
+  int v45; // eax@246
+  unsigned int v46; // eax@247
+  void *v47; // eax@250
+  signed int v48; // edi@250
+  int v49; // eax@252
+  int v50; // eax@256
+  unsigned int v51; // eax@257
+  void *v52; // eax@260
+  signed int v53; // edi@260
+  int v54; // eax@262
+  signed int v55; // [sp+10h] [bp-10h]@1
+  int v56; // [sp+14h] [bp-Ch]@31
+
+  v1 = 0;
+  v2 = a1;
+  v55 = a1;
+  if ( !pDialogueWindow->pNumPresenceButton )
+    return;
+  pRenderer->ClearZBuffer(0, 479);
+  v3 = dword_F8B198;
+  if ( dword_F8B19C != 1 )
+    goto LABEL_13;
+  if ( dword_F8B198 == 30 )
+  {
+    if ( v2 == 17 )
+    {
+      v4 = 0;
+      v5 = 0;
+      v6 = pPlayers[uActiveCharacter];
+      v7 = v6->uLevel;
+      if ( v7 > 0 )
+      {
+        do
+          v4 += v5++ + 1;
+        while ( v5 < v7 );
+      }
+      if ( v7 < (unsigned __int16)word_4F0866[(unsigned int)ptr_507BC0->ptr_1C]
+        && (signed __int64)v6->uExperience < 1000 * v4 )
+        return;
+    }
+    goto LABEL_9;
+  }
+  v8 = ptr_507BC0;
+  if ( (dword_F8B198 == 27 || dword_F8B198 == 28)
+    && (v1 = 0,
+        *(&byte_4F09B1[32 * (unsigned __int8)*(&byte_4F0CCF[4 * (unsigned int)ptr_507BC0->ptr_1C] + v2)]
+        + pParty->uDaysPlayed % 7))
+    || dword_F8B198 != 23
+    || v55 != 10 )
+  {
+LABEL_9:
+    pDialogueWindow->Release();
+    pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x159u, WINDOW_MainMenu, v1, v1);
+    pBtn_ExitCancel = pDialogueWindow->CreateButton(
+                   526,
+                   445,
+                   75,
+                   33,
+                   1,
+                   v1,
+                   0x71u,
+                   v1,
+                   v1,
+                   pGlobalTXT_LocalizationStrings[74],// "End Conversation"
+                   (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0),
+                   v1);
+    pDialogueWindow->CreateButton(8u, 8u, 0x1C2u, 0x140u, 1, v1, 0x51u, v1, v1, "", (Texture *)v1);
+LABEL_10:
+    v3 = dword_F8B198;
+    v8 = ptr_507BC0;
+    goto LABEL_11;
+  }
+  if ( uActiveCharacter != v1 )
+  {
+    if ( !pPlayers[uActiveCharacter]->_4B6FF9() )
+      return;
+    goto LABEL_10;
+  }
+LABEL_11:
+  dword_F8B19C = v55;
+  if ( v3 < 19 )
+  {
+    v9 = pIcons_LOD->LoadTexture(off_4F03B8[v3], TEXTURE_16BIT_PALETTE);
+    v3 = dword_F8B198;
+    dword_F8B164 = &pIcons_LOD->pTextures[v9];
+LABEL_13:
+    v8 = ptr_507BC0;
+  }
+  if ( v3 > 21 )
+  {
+    if ( v3 == 22 )
+    {
+      if ( dword_F8B19C >= 7 && dword_F8B19C <= 8 )
+        pKeyActionMap->_459E5A(1, 10, v8);
+      return;
+    }
+    if ( v3 != 23 && v3 != 30 )
+      return;
+  }
+  else
+  {
+    if ( v3 != 21 )
+    {
+      if ( v3 <= (signed int)v1 )
+        return;
+      if ( v3 > 4 )
+      {
+        if ( v3 <= 16 )
+        {
+          if ( (signed __int64)__PAIR__(
+                                 *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)v8->ptr_1C + 44472],
+                                 *(int *)&stru_AA1058[3].pSounds[8 * (unsigned int)v8->ptr_1C + 44468]) >= (signed __int64)pParty->uTimePlayed )
+          {
+            v32 = 0;
+            do
+            {
+              v33 = *(&pParty->pPlayers[1].pInstalledBeacons[0].field_18 + 9 * (v32 + 12 * (unsigned int)v8->ptr_1C));
+              if ( v33 )
+              {
+                v34 = pIcons_LOD->LoadTexture(
+                        pItemsTable->pItems[v33].pIconName,
+                        TEXTURE_16BIT_PALETTE);
+                v8 = ptr_507BC0;
+                dword_F8B168[v32] = &pIcons_LOD->pTextures[v34];
+              }
+              ++v32;
+            }
+            while ( v32 < 12 );
+          }
+          else
+          {
+            sub_4BC8D5();
+            v30 = ptr_507BC0->ptr_1C;
+            v31 = pParty->uTimePlayed
+                + (signed __int64)((double)(0xA8C000
+                                          //* (signed int)p2DEvents_minus1[26 * (unsigned int)ptr_507BC0->ptr_1C])
+                                          * (signed int)p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].field_1C)
+                                 * 0.033333335);
+            *(int *)&stru_AA1058[3].pSounds[8 * (int)v30 + 44468] = v31;
+            *(int *)&stru_AA1058[3].pSounds[8 * (int)v30 + 44472] = HIDWORD(v31);
+          }
+          return;
+        }
+        if ( v3 != 17 )
+          return;
+        if ( v55 == 99 )
+        {
+          v10 = (int)((char *)v8->ptr_1C - 102);
+          v56 = v10;
+          v11 = 8 * v10 + 11325428;
+          if ( (signed __int64)__PAIR__(pParty->field_3C.field_0[2 * v10 + 1], pParty->field_3C.field_0[2 * v10]) >= (signed __int64)pParty->uTimePlayed )
+          {
+            v13 = 0;
+          }
+          else
+          {
+            v12 = v10;
+            v13 = 0;
+            pParty->field_75A[v12] = 0;
+            *(_QWORD *)v11 = (signed __int64)((double)(309657600
+                                                     * (pParty->uCurrentMonth + 12i64 * pParty->uCurrentYear - 14015))
+                                            * 0.033333335);
+            v14 = rand() % 258;
+            v15 = ptr_507BC0;
+            pParty->field_750[v12] = v14 + 1;
+            v16 = (int)((char *)v15->ptr_1C - 102);
+            if ( v16 )
+            {
+              v17 = v16 - 1;
+              if ( v17 )
+              {
+                v18 = v17 - 1;
+                if ( v18 )
+                {
+                  v19 = v18 - 1;
+                  if ( v19 )
+                  {
+                    if ( v19 == 1 )
+                    {
+                      while ( 1 )
+                      {
+                        v20 = pParty->field_750[v12];
+                        if ( (unsigned __int16)v20 < 0x73u || (unsigned __int16)v20 > 0x84u )
+                        {
+                          if ( ((unsigned __int16)v20 < 0xE8u || (unsigned __int16)v20 > 0xF9u)
+                            && ((unsigned __int16)v20 < 0x85u || (unsigned __int16)v20 > 0x96u)
+                            && ((unsigned __int16)v20 < 0x97u || (unsigned __int16)v20 > 0xBAu)
+                            && ((unsigned __int16)v20 < 0xBEu || (unsigned __int16)v20 > 0xC0u)
+                            && ((unsigned __int16)v20 < 0xC4u || (unsigned __int16)v20 > 0xC6u)
+                            && ((unsigned __int16)v20 < 0x2Bu || (unsigned __int16)v20 > 0x2Du)
+                            && ((unsigned __int16)v20 < 0x6Du || (unsigned __int16)v20 > 0x6Fu)
+                            && ((unsigned __int16)v20 < 0x46u || (unsigned __int16)v20 > 0x48u)
+                            && ((unsigned __int16)v20 < 0x100u || (unsigned __int16)v20 > 0x102u)
+                            && ((unsigned __int16)v20 < 0xD9u || (unsigned __int16)v20 > 0xDBu)
+                            && ((unsigned __int16)v20 < 0xC7u || (unsigned __int16)v20 > 0xC9u)
+                            && ((unsigned __int16)v20 < 0xE5u || (unsigned __int16)v20 > 0xE7u)
+                            && ((unsigned __int16)v20 < 0xDFu || (unsigned __int16)v20 > 0xE1u)
+                            && ((unsigned __int16)v20 < 0x5Bu || (unsigned __int16)v20 > 0x5Du)
+                            && ((unsigned __int16)v20 < 0x49u || (unsigned __int16)v20 > 0x4Bu)
+                            && ((unsigned __int16)v20 < 0xFDu || (unsigned __int16)v20 > 0xFFu)
+                            && ((unsigned __int16)v20 < 0x61u || (unsigned __int16)v20 > 0x63u)
+                            && ((unsigned __int16)v20 < 0x10u || (unsigned __int16)v20 > 0x12u) )
+                            break;
+                        }
+                        pParty->field_750[v12] = rand() % 258 + 1;
+                      }
+                    }
+                  }
+                  else
+                  {
+                    while ( 1 )
+                    {
+                      v21 = pParty->field_750[v12];
+                      if ( (unsigned __int16)v21 < 0x73u || (unsigned __int16)v21 > 0x84u )
+                      {
+                        if ( ((unsigned __int16)v21 < 0xE8u || (unsigned __int16)v21 > 0xF9u)
+                          && ((unsigned __int16)v21 < 0x85u || (unsigned __int16)v21 > 0x96u)
+                          && ((unsigned __int16)v21 < 0x97u || (unsigned __int16)v21 > 0xBAu)
+                          && ((unsigned __int16)v21 < 0xBEu || (unsigned __int16)v21 > 0xC0u)
+                          && ((unsigned __int16)v21 < 0xC4u || (unsigned __int16)v21 > 0xC6u)
+                          && ((unsigned __int16)v21 < 0x2Bu || (unsigned __int16)v21 > 0x2Du)
+                          && ((unsigned __int16)v21 < 0x5Eu || (unsigned __int16)v21 > 0x60u)
+                          && ((unsigned __int16)v21 < 0x43u || (unsigned __int16)v21 > 0x45u)
+                          && ((unsigned __int16)v21 < 0x4Fu || (unsigned __int16)v21 > 0x51u)
+                          && ((unsigned __int16)v21 < 0xC1u || (unsigned __int16)v21 > 0xC3u)
+                          && ((unsigned __int16)v21 < 0x13u || (unsigned __int16)v21 > 0x15u)
+                          && ((unsigned __int16)v21 < 0xFDu || (unsigned __int16)v21 > 0xFFu)
+                          && ((unsigned __int16)v21 < 0x61u || (unsigned __int16)v21 > 0x63u)
+                          && ((unsigned __int16)v21 < 0x6Au || (unsigned __int16)v21 > 0x6Cu) )
+                          break;
+                      }
+                      pParty->field_750[v12] = rand() % 258 + 1;
+                    }
+                  }
+                }
+                else
+                {
+                  while ( 1 )
+                  {
+                    v22 = pParty->field_750[v12];
+                    if ( (unsigned __int16)v22 < 0x73u || (unsigned __int16)v22 > 0x84u )
+                    {
+                      if ( ((unsigned __int16)v22 < 0xE8u || (unsigned __int16)v22 > 0xF9u)
+                        && ((unsigned __int16)v22 < 0x85u || (unsigned __int16)v22 > 0x96u)
+                        && ((unsigned __int16)v22 < 0x97u || (unsigned __int16)v22 > 0xBAu)
+                        && ((unsigned __int16)v22 < 0xBEu || (unsigned __int16)v22 > 0xC0u)
+                        && ((unsigned __int16)v22 < 0xC4u || (unsigned __int16)v22 > 0xC6u)
+                        && ((unsigned __int16)v22 < 0x2Bu || (unsigned __int16)v22 > 0x2Du)
+                        && ((unsigned __int16)v22 < 0x31u || (unsigned __int16)v22 > 0x33u)
+                        && ((unsigned __int16)v22 < 0x34u || (unsigned __int16)v22 > 0x36u)
+                        && ((unsigned __int16)v22 < 0xFDu || (unsigned __int16)v22 > 0xFFu)
+                        && ((unsigned __int16)v22 < 0x61u || (unsigned __int16)v22 > 0x63u)
+                        && ((unsigned __int16)v22 < 0x1Cu || (unsigned __int16)v22 > 0x1Eu) )
+                        break;
+                    }
+                    pParty->field_750[v12] = rand() % 258 + 1;
+                  }
+                }
+              }
+              else
+              {
+                while ( 1 )
+                {
+                  v23 = pParty->field_750[v12];
+                  if ( (unsigned __int16)v23 < 0x73u || (unsigned __int16)v23 > 0x84u )
+                  {
+                    if ( ((unsigned __int16)v23 < 0xE8u || (unsigned __int16)v23 > 0xF9u)
+                      && ((unsigned __int16)v23 < 0x85u || (unsigned __int16)v23 > 0x96u)
+                      && ((unsigned __int16)v23 < 0x97u || (unsigned __int16)v23 > 0xBAu)
+                      && ((unsigned __int16)v23 < 0xBEu || (unsigned __int16)v23 > 0xC0u)
+                      && ((unsigned __int16)v23 < 0xC4u || (unsigned __int16)v23 > 0xC6u)
+                      && ((unsigned __int16)v23 < 0x2Bu || (unsigned __int16)v23 > 0x2Du)
+                      && ((unsigned __int16)v23 < 0x52u || (unsigned __int16)v23 > 0x54u)
+                      && ((unsigned __int16)v23 < 4u || (unsigned __int16)v23 > 6u)
+                      && ((unsigned __int16)v23 < 0x37u || (unsigned __int16)v23 > 0x39u)
+                      && ((unsigned __int16)v23 < 0x3Au || (unsigned __int16)v23 > 0x3Cu)
+                      && ((unsigned __int16)v23 < 0x3Du || (unsigned __int16)v23 > 0x3Fu)
+                      && ((unsigned __int16)v23 < 0xFDu || (unsigned __int16)v23 > 0xFFu)
+                      && ((unsigned __int16)v23 < 0x61u || (unsigned __int16)v23 > 0x63u)
+                      && ((unsigned __int16)v23 < 0xCDu || (unsigned __int16)v23 > 0xCFu) )
+                      break;
+                  }
+                  pParty->field_750[v12] = rand() % 258 + 1;
+                }
+              }
+            }
+            else
+            {
+              while ( 1 )
+              {
+                v24 = pParty->field_750[v12];
+                if ( (unsigned __int16)v24 < 0x73u || (unsigned __int16)v24 > 0x84u )
+                {
+                  if ( ((unsigned __int16)v24 < 0xEBu || (unsigned __int16)v24 > 0xFCu)
+                    && ((unsigned __int16)v24 < 0x85u || (unsigned __int16)v24 > 0x96u)
+                    && ((unsigned __int16)v24 < 0x97u || (unsigned __int16)v24 > 0xBAu)
+                    && ((unsigned __int16)v24 < 0xBEu || (unsigned __int16)v24 > 0xC0u)
+                    && ((unsigned __int16)v24 < 0xC4u || (unsigned __int16)v24 > 0xC6u)
+                    && ((unsigned __int16)v24 < 0x2Bu || (unsigned __int16)v24 > 0x2Du)
+                    && ((unsigned __int16)v24 < 0xCDu || (unsigned __int16)v24 > 0xCFu)
+                    && ((unsigned __int16)v24 < 0x5Eu || (unsigned __int16)v24 > 0x60u)
+                    && ((unsigned __int16)v24 < 0xFDu || (unsigned __int16)v24 > 0xFFu)
+                    && ((unsigned __int16)v24 < 0x6Du || (unsigned __int16)v24 > 0x6Fu)
+                    && ((unsigned __int16)v24 < 0x61u || (unsigned __int16)v24 > 0x63u) )
+                    break;
+                }
+                pParty->field_750[v12] = rand() % 258 + 1;
+              }
+            }
+            v10 = v56;
+          }
+          v25 = v10;
+          v26 = pParty->field_750[v25];
+          v27 = pParty->field_75A[v25] == v13;
+          word_F8B1A0 = pParty->field_750[v25];
+          if ( v27 )
+          {
+            v1 = 0;
+            v27 = v26 == v13;
+            v29 = (int)pNPCTopics[351].pText;
+            if ( v27 )
+              v29 = (int)pNPCTopics[353].pText;
+            dword_F8B1A4 = (char *)v29;
+          }
+          else
+          {
+            if ( v26 != v13 )
+            {
+              party_finds_gold(100 * pMonsterStats->pInfos[(unsigned __int16)v26].uLevel, 0);
+              v28 = pParty->pPlayers;
+              do
+              {
+                v28->SetVariable(VAR_Award, 86);
+                ++v28;
+              }
+              while ( (signed int)v28 < (signed int)pParty->pHirelings );
+              pParty->uNumBountiesCollected += 100 * pMonsterStats->pInfos[pParty->field_750[v25]].uLevel;
+              pParty->field_750[v25] = v13;
+              pParty->field_75A[v25] = v13;
+            }
+            v1 = 0;
+            dword_F8B1A4 = pNPCTopics[352].pText;
+          }
+          goto LABEL_196;
+        }
+        if ( v55 == 100 )
+        {
+          pKeyActionMap->_459E5A(1, 10, v8);
+          goto LABEL_196;
+        }
+      }
+    }
+  }
+  if ( v55 > 95 )
+  {
+LABEL_196:
+    switch ( v55 )
+    {
+      case 96:
+        pDialogueWindow->eWindowType = WINDOW_MainMenu;
+        sub_4BCA33();
+        sub_4B3703((void *)dword_F8B198);
+        break;
+      case 101:
+        pDialogueWindow->eWindowType = WINDOW_MainMenu;
+        sub_4BCA33();
+        sub_4B3A72(dword_F8B198);
+        break;
+      case 102:
+        dword_F8B19C = 102;
+        break;
+      case 103:
+        dword_F8B19C = 103;
+        break;
+      case 104:
+        if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        {
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)29;
+          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v1;
+          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = v1;
+          ++pMessageQueue_50CBD0->uNumMessages;
+        }
+        dword_F8B19C = 104;
+        break;
+    }
+    return;
+  }
+  if ( v55 != 95 && v55 != 2 )
+  {
+    if ( v55 == 3 )
+    {
+      dword_F8B19C = 3;
+    }
+    else
+    {
+      if ( v55 == 4 )
+      {
+        dword_F8B19C = 4;
+      }
+      else
+      {
+        if ( v55 != 5 )
+        {
+          if ( v55 > 35 )
+          {
+            if ( v55 <= 72 )
+            {
+              v35 = pPlayers[uActiveCharacter];
+              //v36 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)v8->ptr_1C] * 500.0);
+              v36 = (signed __int64)(p2DEvents[(unsigned int)v8->ptr_1C - 1].flt_24 * 500.0);
+              v37 = v36 * (100 - pPlayers[uActiveCharacter]->GetMerchant()) / 100;
+              if ( v37 < v36 / 3 )
+                v37 = v36 / 3;
+              
+              __debugbreak();
+              //pSkillAvailabilityPerClass[8 + v58->uClass][4 + v23]
+              // or
+              //byte_4ED970_skill_learn_ability_by_class_table[v58->uClass][v23 - 36]
+              // or
+              //byte_4ED970_skill_learn_ability_by_class_table[v58->uClass - 1][v23 + 1]
+
+              if (false)
+              //if ( *(&byte_4ED94C[37 * v35->uClass] + v55) )
+              {
+                v38 = (int)(&v35->uIntelligence + v55);
+                if ( !*(short *)v38 )
+                {
+                  if ( pParty->uNumGold < v37 )
+                  {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
+                    if ( dword_F8B198 == 30 || dword_F8B198 == 21 )
+                      v39 = 4;
+                    else
+                      v39 = 2;
+                    HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, v39);
+                  }
+                  else
+                  {
+                    Party::TakeGold(v37);
+                    dword_F8B1E4 = 1;
+                    *(short *)v38 = 1;
+                    v35->PlaySound(78, 0);
+                  }
+                }
+              }
+            }
+            else
+            {
+              if ( v55 == 94 )
+              {
+                pDialogueWindow->eWindowType = WINDOW_MainMenu;
+                sub_4BCA33();
+                sub_4B3AD4(dword_F8B198);
+              }
+            }
+          }
+          return;
+        }
+        dword_F8B19C = 5;
+      }
+    }
+    sub_421B2C_PlaceInInventory_or_DropPickedItem();
+    return;
+  }
+  if ( (signed __int64)__PAIR__(
+                         pParty->field_3C.field_50[2 * (unsigned int)v8->ptr_1C + 1],
+                         pParty->field_3C.field_50[2 * (unsigned int)v8->ptr_1C]) < (signed __int64)pParty->uTimePlayed )
+  {
+    GenerateShopItems();
+    sub_4B8F94();
+    v8 = ptr_507BC0;
+    v40 = ptr_507BC0->ptr_1C;
+    v3 = dword_F8B198;
+    v41 = pParty->uTimePlayed
+        //+ (signed __int64)((double)(11059200 * (signed int)p2DEvents_minus1[26 * (unsigned int)ptr_507BC0->ptr_1C])
+        + (signed __int64)((double)(11059200 * (signed int)p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].field_1C)
+                         * 0.033333335);
+    pParty->field_3C.field_50[2 * (int)v40] = v41;
+    pParty->field_3C.field_50[2 * (int)v40 + 1] = HIDWORD(v41);
+  }
+  v42 = v8->ptr_1C;
+  v43 = 0;
+  //v44 = p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C];
+  v44 = p2DEvents[(unsigned int)v8->ptr_1C - 1].uType;
+  if ( v55 == 2 )
+  {
+    if ( _4F063C_smthn_by_2da_uType[v44] )
+    {
+      do
+      {
+        v45 = pParty->field_777C[9 * (v43 + 12 * (int)v42)];
+        if ( v45 )
+        {
+          v46 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v45].pIconName, TEXTURE_16BIT_PALETTE);
+          v3 = dword_F8B198;
+          v8 = ptr_507BC0;
+          dword_F8B168[v43] = &pIcons_LOD->pTextures[v46];
+        }
+        v42 = v8->ptr_1C;
+        ++v43;
+      }
+      //while ( v43 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
+      while ( v43 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] );
+    }
+    if ( v3 == 1 )
+    {
+      v47 = v8->ptr_1C;
+      v48 = 0;
+      //if ( _4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] )
+      if ( _4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] )
+      {
+        do
+        {
+          if ( pParty->field_777C[9 * (v48 + 12 * (int)v47)] )
+          {
+            v49 = rand();
+            v8 = ptr_507BC0;
+            word_F8B158[v48] = v49 % (300 - dword_F8B168[v48]->uTextureHeight);
+          }
+          v47 = v8->ptr_1C;
+          ++v48;
+        }
+        //while ( v48 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
+        while ( v48 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] );
+      }
+    }
+  }
+  else
+  {
+    if ( _4F063C_smthn_by_2da_uType[v44] )
+    {
+      do
+      {
+        v50 = pParty->field_C59C[9 * (v43 + 12 * (int)v42) + 724];
+        if ( v50 )
+        {
+          v51 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v50].pIconName, TEXTURE_16BIT_PALETTE);
+          v3 = dword_F8B198;
+          v8 = ptr_507BC0;
+          dword_F8B168[v43] = &pIcons_LOD->pTextures[v51];
+        }
+        v42 = v8->ptr_1C;
+        ++v43;
+      }
+      //while ( v43 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
+      while ( v43 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] );
+    }
+    if ( v3 == 1 )
+    {
+      v52 = v8->ptr_1C;
+      v53 = 0;
+      //if ( _4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] )
+      if ( _4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType] )
+      {
+        do
+        {
+          if ( pParty->field_C59C[9 * (v53 + 12 * (int)v52) + 724] )
+          {
+            v54 = rand();
+            v8 = ptr_507BC0;
+            word_F8B158[v53] = v54 % (300 - dword_F8B168[v53]->uTextureHeight);
+          }
+          v52 = v8->ptr_1C;
+          ++v53;
+        }
+        //while ( v53 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents_minus1___00[26 * (unsigned int)v8->ptr_1C]] );
+        while ( v53 < (unsigned __int8)_4F063C_smthn_by_2da_uType[p2DEvents[(unsigned int)v8->ptr_1C - 1].uType ] );
+      }
+    }
+  }
+}
+
+//----- (004BD8B5) --------------------------------------------------------
+signed int __cdecl sub_4BD8B5()
+{
+  int v0; // eax@4
+  int v1; // eax@29
+  unsigned int v2; // esi@30
+  const char *v3; // ebx@31
+
+  if ( pMessageQueue_50CBD0->uNumMessages )
+    pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+  pKeyActionMap->_459ED1(3);
+  pKeyActionMap->ResetKeys();
+  _5C3420_pDecoration = 0;
+  ptr_F8B1E8 = 0;
+  if ( array_5913D8[6] )
+  {
+    v0 = dword_F8B19C;
+    if ( dword_F8B19C != 2
+      && dword_F8B19C != 3
+      && dword_F8B19C != 97
+      && dword_F8B19C != 5
+      && dword_F8B19C != 4
+      && dword_F8B164 )
+    {
+      dword_F8B164->Release();
+      v0 = dword_F8B19C;
+      dword_F8B164 = 0;
+    }
+    if ( v0 && v0 != 1 )
+    {
+      if ( v0 == -1 )
+      {
+        _4B4224_UpdateNPCTopics((int)((char *)array_5913D8[6] - 1));
+LABEL_33:
+        pVideoPlayer->_4BF5B2();
+        return 1;
+      }
+      if ( v0 != 94 && v0 != 96 && v0 != 101 )
+      {
+        if ( v0 == 3 || v0 == 5 || v0 == 4 )
+        {
+          sub_4BCA33();
+          dword_F8B19C = 94;
+          sub_4B3AD4(dword_F8B198);
+        }
+        else
+        {
+          if ( v0 != 102 && v0 != 103 && v0 != 104 )
+          {
+            pVideoPlayer->_4BF5B2();
+LABEL_28:
+            dword_F8B19C = 1;
+            sub_4B3B42(dword_F8B198);
+            return 1;
+          }
+          pVideoPlayer->_4BF5B2();
+          sub_4BCA33();
+          dword_F8B19C = 101;
+          sub_4B3A72(dword_F8B198);
+        }
+        return 1;
+      }
+      pVideoPlayer->_4BF5B2();
+      sub_4BCA33();
+      goto LABEL_28;
+    }
+    array_5913D8[6] = 0;
+    pDialogueWindow->Release();
+    dword_F8B19C = 0;
+    pDialogueWindow = 0;
+    pIcons_LOD->_40F9C5();
+    v1 = uNumDialogueNPCPortraits;
+    if ( uNumDialogueNPCPortraits != 1 )
+    {
+      v2 = 0;
+      pBtn_ExitCancel = ptr_507BC0->pControlsHead;
+      if ( uNumDialogueNPCPortraits > 0 )
+      {
+        v3 = byte_591180;
+        do
+        {
+          array_5913D8[v2 + 7] = (NPCData *)ptr_507BC0->CreateButton(
+                                              *(&_4E5E50_transui_x + v2 + 6 * v1 - 6),
+                                              *(&_4E5EE0_transui_y + v2 + 6 * v1 - 6),
+                                              0x3Fu,
+                                              0x49u,
+                                              1,
+                                              0,
+                                              0x19Au,
+                                              v2,
+                                              0,
+                                              v3,
+                                              0,
+                                              0,
+                                              0);
+          v1 = uNumDialogueNPCPortraits;
+          ++v2;
+          v3 += 100;
+        }
+        while ( (signed int)v2 < uNumDialogueNPCPortraits );
+      }
+      goto LABEL_33;
+    }
+  }
+  return 0;
+}
+
+
+
+
+
+//----- (004BDB56) --------------------------------------------------------
+void __cdecl sub_4BDB56_buy_skill____()
+{
+  Player *v0; // edi@1
+  signed int v1; // esi@9
+  unsigned int v2; // eax@11
+  int v3; // esi@12
+  float v4; // ST1C_4@12
+  signed int v5; // eax@12
+  signed int v6; // eax@12
+  char v7; // zf@12
+  int v8; // eax@15
+  const char *v9; // ecx@15
+  signed int v10; // esi@18
+  unsigned int v11; // esi@20
+  int v12; // esi@21
+  void *v13; // ecx@26
+  signed int v14; // esi@31
+  unsigned int v15; // eax@33
+  GUIWindow *v16; // esi@34
+  POINT *v17; // esi@37
+  int v18; // ecx@37
+  void *v19; // eax@38
+  ItemGen *v20; // esi@38
+  float v21; // ST1C_4@38
+  signed int v22; // eax@38
+  int v23; // ebx@38
+  int v24; // edx@39
+  int v25; // eax@40
+  int v26; // ebx@41
+  Player *v27; // ecx@43
+  POINT *v28; // esi@49
+  int v29; // ecx@49
+  void *v30; // eax@50
+  int v31; // ecx@50
+  ItemGen *v32; // esi@51
+  float v33; // ST1C_4@53
+  signed int v34; // eax@53
+  int v35; // eax@53
+  bool v36; // eax@53
+  unsigned int v37; // eax@53
+  int v38; // eax@55
+  int v39; // eax@63
+  int v40; // eax@64
+  int v41; // edx@66
+  int v42; // esi@74
+  signed int v43; // ebx@74
+  int v44; // ecx@74
+  unsigned __int16 *pSkill; // esi@77
+  signed int v46; // [sp-18h] [bp-CCh]@36
+  unsigned int v47; // [sp-14h] [bp-C8h]@36
+  signed int v48; // [sp-10h] [bp-C4h]@36
+  signed int v49; // [sp-Ch] [bp-C0h]@36
+  int v50; // [sp-8h] [bp-BCh]@36
+  int v51; // [sp-4h] [bp-B8h]@28
+  unsigned int v52; // [sp-4h] [bp-B8h]@36
+  int v53; // [sp+0h] [bp-B4h]@16
+  unsigned int v54; // [sp+0h] [bp-B4h]@25
+  int v55; // [sp+0h] [bp-B4h]@26
+  int v56; // [sp+0h] [bp-B4h]@36
+  POINT v57; // [sp+10h] [bp-A4h]@49
+  POINT v58; // [sp+18h] [bp-9Ch]@18
+  POINT v59; // [sp+20h] [bp-94h]@49
+  POINT v60; // [sp+28h] [bp-8Ch]@9
+  POINT v61; // [sp+30h] [bp-84h]@37
+  POINT v62; // [sp+38h] [bp-7Ch]@18
+  POINT v63; // [sp+40h] [bp-74h]@37
+  POINT v64; // [sp+48h] [bp-6Ch]@19
+  POINT v65; // [sp+50h] [bp-64h]@32
+  POINT v66; // [sp+58h] [bp-5Ch]@18
+  POINT v67; // [sp+60h] [bp-54h]@31
+  POINT a2; // [sp+68h] [bp-4Ch]@9
+  POINT v69; // [sp+70h] [bp-44h]@31
+  POINT v70; // [sp+78h] [bp-3Ch]@9
+  POINT v71; // [sp+80h] [bp-34h]@31
+  POINT v72; // [sp+88h] [bp-2Ch]@10
+  bool v73; // [sp+90h] [bp-24h]@53
+  int v74; // [sp+94h] [bp-20h]@53
+  int a6; // [sp+98h] [bp-1Ch]@57
+  int a3; // [sp+9Ch] [bp-18h]@53
+  Player *v77; // [sp+A0h] [bp-14h]@1
+  unsigned int uNumSeconds; // [sp+A4h] [bp-10h]@53
+  unsigned int v79; // [sp+A8h] [bp-Ch]@9
+  int v80; // [sp+ACh] [bp-8h]@12
+  ItemGen *_this; // [sp+B0h] [bp-4h]@13
+
+  v0 = pPlayers[uActiveCharacter];
+  v77 = pPlayers[uActiveCharacter];
+  if ( pCurrentScreen == 14 )
+    goto LABEL_73;
+  if ( !sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win() )
+  {
+    v56 = 0;
+    v52 = 0;
+    v50 = 0;
+    v49 = 0;
+    v48 = -1;
+    v47 = 0;
+    v46 = 0;
+    goto LABEL_87;
+  }
+  if ( dword_F8B19C > 18 )
+  {
+    if ( dword_F8B19C < 36 )
+      return;
+    if ( dword_F8B19C <= 72 )
+    {
+      v42 = dword_F8B19C - 36;
+      //v43 = (signed __int64)(*(float *)&p2DEvents_minus1__24[13 * (unsigned int)ptr_507BC0->ptr_1C] * 500.0);
+      v43 = (signed __int64)(p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].flt_24 * 500.0);
+      v44 = v43 * (100 - v0->GetMerchant()) / 100;
+      if ( v44 < v43 / 3 )
+        v44 = v43 / 3;
+      if ( byte_4ED970_skill_learn_ability_by_class_table[v0->uClass][v42] )
+      {
+        pSkill = &v0->pActiveSkills[v42];
+        if ( !*pSkill )
+        {
+          if ( pParty->uNumGold < v44 )
+          {
+            ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);// "You don't have enough gold"
+            v13 = ptr_507BC0->ptr_1C;
+            if ( dword_F8B198 == 30 )
+              v55 = 4;
+            else
+              v55 = 2;
+            goto LABEL_84;
+          }
+          Party::TakeGold(v44);
+          v53 = 0;
+          dword_F8B1E4 = 1;
+          *pSkill = 1;
+          v51 = 78;
+          goto LABEL_80;
+        }
+      }
+      return;
+    }
+    if ( dword_F8B19C != 94 )
+    {
+      if ( dword_F8B19C != 95 )
+        return;
+      goto LABEL_49;
+    }
+    pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
+LABEL_73:
+    sub_421EA6_OnInventoryLeftClick();
+    return;
+  }
+  if ( dword_F8B19C == 18 )
+  {
+    v17 = pMouse->GetCursorPos(&v63);
+    v18 = pRenderer->pActiveZBuffer[v17->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v61)->y]] & 0xFFFF;
+    if ( !v18 )
+      return;
+    v19 = ptr_507BC0->ptr_1C;
+    v20 = (ItemGen *)(&pParty->pPlayers[1].uExpressionTimeLength + 18 * (v18 + 12 * (int)v19));
+    //v21 = p2DEvents_minus1__20[13 * (signed int)v19];
+    v21 = p2DEvents[(signed int)v19 - 1].fPriceMultiplier;
+    _this = v20;
+    v22 = v20->GetValue();
+    v23 = v0->_4B8142(v22, v21);
+    v80 = v23;
+    GetAsyncKeyState(VK_CONTROL);
+    if ( pParty->uNumGold < v23 )
+    {
+      v24 = 2;
+LABEL_62:
+      HousePlaySomeSound((unsigned int)ptr_507BC0->ptr_1C, v24);
+      v9 = pGlobalTXT_LocalizationStrings[155];
+      v54 = 2;
+      goto LABEL_71;
+    }
+    v25 = v0->AddItem(0xFFFFFFFFu, v20->uItemID);
+    if ( v25 )
+    {
+      v26 = 1;
+      v20->uAttributes |= 1u;
+      memcpy(&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v25 + 5], v20, 0x24u);
+      goto LABEL_42;
+    }
+    v0->PlaySound(15, 0);
+    v54 = 5;
+LABEL_70:
+    v9 = pGlobalTXT_LocalizationStrings[563];   // "Pack is Full!"
+    goto LABEL_71;
+  }
+  if ( dword_F8B19C == 2 )
+  {
+LABEL_49:
+    v28 = pMouse->GetCursorPos(&v59);
+    v29 = pRenderer->pActiveZBuffer[v28->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v57)->y]] & 0xFFFF;
+    if ( !v29 )
+      return;
+    v30 = ptr_507BC0->ptr_1C;
+    v31 = 9 * (v29 - 1 + 12 * (int)v30);
+    if ( dword_F8B19C == 2 )
+    {
+      v32 = (ItemGen *)&pParty->field_777C[v31];
+      _this = (ItemGen *)&pParty->field_777C[v31];
+    }
+    else
+    {
+      _this = (ItemGen *)&pParty->field_C59C[v31 + 724];
+      v32 = (ItemGen *)&pParty->field_C59C[v31 + 724];
+    }
+    //v33 = p2DEvents_minus1__20[13 * (signed int)v30];
+    v33 = p2DEvents[(signed int)v30 - 1].fPriceMultiplier;
+    v34 = v32->GetValue();
+    v80 = v0->_4B8142(v34, v33);
+    LOWORD(v35) = GetAsyncKeyState(VK_CONTROL);
+    v74 = v35;
+    v36 = v0->CanSteal();
+    uNumSeconds = 0;
+    a3 = 0;
+    v73 = v36;
+    v37 = pMapStats->GetMapInfo(pCurrentMapName);
+    if ( v37 )
+      a3 = pMapStats->pInfos[v37]._steal_perm;
+    v38 = GetPartyReputation();
+    v26 = 1;
+    if ( v73 == 1 )
+    {
+      if ( (short)v74 )
+      {
+        uNumSeconds = v0->StealFromShop(v32, a3, v38, 0, &a6);
+        if ( !uNumSeconds )
+        {
+          sub_4B1447_party_fine((int)ptr_507BC0->ptr_1C, 0, a6);
+          return;
+        }
+      }
+    }
+    if ( pParty->uNumGold < v80 )
+    {
+      v24 = 2;
+      if ( uNumSeconds != 2 )
+      {
+        if ( uNumSeconds != 1 )
+          goto LABEL_62;
+      }
+    }
+    v39 = v0->AddItem(0xFFFFFFFFu, v32->uItemID);
+    if ( v39 )
+    {
+      v32->uAttributes |= 1u;
+      v7 = v73 == 1;
+      v40 = (int)((char *)v0 + 36 * v39);
+      memcpy((void *)(v40 + 496), v32, 0x24u);
+      if ( v7 )
+      {
+        if ( (short)v74 )
+        {
+          v41 = uNumSeconds;
+          if ( uNumSeconds == 1 || uNumSeconds == 2 )
+          {
+            *(char *)(v40 + 517) |= 1u;
+            sub_4B1447_party_fine((int)ptr_507BC0->ptr_1C, v41, a6);
+            goto LABEL_43;
+          }
+        }
+      }
+LABEL_42:
+      dword_F8B1E4 = v26;
+      Party::TakeGold(v80);
+LABEL_43:
+      viewparams->bRedrawGameUI = v26;
+      _this->Reset();
+      pRenderer->ClearZBuffer(0, 479);
+      v27 = v77;
+      v53 = 0;
+      v51 = 75;
+LABEL_81:
+      v27->PlaySound(v51, v53);
+      return;
+    }
+    v0->PlaySound(15, 0);
+    v54 = 2;
+    goto LABEL_70;
+  }
+  if ( dword_F8B19C == 3 )
+  {
+    v14 = pMouse->GetCursorPos(&v71)->x - 14;
+    v79 = (v14 >> 5) + 14 * ((pMouse->GetCursorPos(&v69)->y - 17) >> 5);
+    if ( pMouse->GetCursorPos(&v67)->x <= 13
+      || pMouse->GetCursorPos(&v65)->x >= 462
+      || (v15 = v0->GetItemIDAtInventoryIndex((int *)&v79), (v77 = (Player *)v15) == 0) )
+      return;
+    v16 = ptr_507BC0;
+    if ( sub_4BDAAF((ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v15 + 5], (int)ptr_507BC0->ptr_1C) )
+    {
+      dword_F8B1E4 = 1;
+      v0->_4BE2DD(v79, (int)((char *)v77 - 1), (int)v16->ptr_1C);
+      viewparams->bRedrawGameUI = 1;
+      pRenderer->ClearZBuffer(0, 479);
+      v53 = 0;
+      v51 = 77;
+      goto LABEL_80;
+    }
+    v0->PlaySound(79, 0);
+    v56 = 0;
+    v52 = 0;
+    v50 = 0;
+    v49 = 0;
+    v48 = -1;
+    v47 = 0;
+    v46 = 0;
+LABEL_87:
+    pAudioPlayer->PlaySound(SOUND_27, v46, v47, v48, v49, v50, v52, v56);
+    return;
+  }
+  if ( dword_F8B19C == 4 )
+  {
+    v10 = pMouse->GetCursorPos(&v62)->x - 14;
+    v79 = (v10 >> 5) + 14 * ((pMouse->GetCursorPos(&v66)->y - 17) >> 5);
+    if ( pMouse->GetCursorPos(&v58)->x > 13 )
+    {
+      if ( pMouse->GetCursorPos(&v64)->x < 462 )
+      {
+        v11 = v0->GetItemIDAtInventoryIndex((int *)&v79);
+        if ( v11 )
+        {
+          //v80 = v0->_4B8179(p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C]);
+          v80 = v0->_4B8179(p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].fPriceMultiplier);
+          v12 = (int)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v11 + 5];
+          if ( !(*(char *)(v12 + 20) & 1) )
+          {
+            _this = (ItemGen *)ptr_507BC0->ptr_1C;
+            if ( sub_4BDAAF((ItemGen *)v12, (int)_this) )
+            {
+              if ( pParty->uNumGold >= v80 )
+              {
+                dword_F8B1E4 = 1;
+                Party::TakeGold(v80);
+                *(int *)(v12 + 20) |= 1u;
+                v0->PlaySound(73, 0);
+                v9 = pGlobalTXT_LocalizationStrings[569];
+                goto LABEL_25;
+              }
+              goto LABEL_26;
+            }
+            pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
+            v53 = 0;
+            goto LABEL_28;
+          }
+          v53 = 0;
+LABEL_30:
+          v51 = 76;
+          goto LABEL_80;
+        }
+      }
+    }
+  }
+  else
+  {
+    if ( dword_F8B19C == 5 )
+    {
+      v1 = pMouse->GetCursorPos(&a2)->x - 14;
+      v79 = (v1 >> 5) + 14 * ((pMouse->GetCursorPos(&v70)->y - 17) >> 5);
+      if ( pMouse->GetCursorPos(&v60)->x > 13 )
+      {
+        if ( pMouse->GetCursorPos(&v72)->x < 462 )
+        {
+          v2 = v0->GetItemIDAtInventoryIndex((int *)&v79);
+          if ( v2 )
+          {
+            v3 = (int)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v2 + 5];
+            //v4 = p2DEvents_minus1__20[13 * (unsigned int)ptr_507BC0->ptr_1C];
+            v4 = p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].fPriceMultiplier;
+
+            auto _v = (ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v2 + 5];
+            v5 = _v->GetValue();
+
+            v6 = v0->_4B81C3(v5, v4);
+            v7 = (*(char *)(v3 + 20) & 2) == 0;
+            v80 = v6;
+            if ( !v7 )
+            {
+              _this = (ItemGen *)ptr_507BC0->ptr_1C;
+              if ( sub_4BDAAF((ItemGen *)v3, (int)_this) )
+              {
+                if ( pParty->uNumGold >= v80 )
+                {
+                  dword_F8B1E4 = 1;
+                  Party::TakeGold(v80);
+                  v8 = *(int *)(v3 + 20);
+                  LOBYTE(v8) = v8 & 0xFD;
+                  *(int *)(v3 + 20) = v8 | 1;
+                  v0->PlaySound(74, 0);
+                  v9 = pGlobalTXT_LocalizationStrings[570];
+LABEL_25:
+                  v54 = 2;
+LABEL_71:
+                  ShowStatusBarString(v9, v54);
+                  return;
+                }
+LABEL_26:
+                v13 = _this;
+                v55 = 2;
+LABEL_84:
+                HousePlaySomeSound((unsigned int)v13, v55);
+                return;
+              }
+              pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
+              v53 = 0;
+LABEL_28:
+              v51 = 79;
+LABEL_80:
+              v27 = v0;
+              goto LABEL_81;
+            }
+            v53 = 0;
+            goto LABEL_30;
+          }
+        }
+      }
+    }
+  }
+}
+
+
+
+//----- (004BE386) --------------------------------------------------------
+void __fastcall log_error(const char *pMessage)
+{
+  const char *v1; // edi@1
+  FILE *f; // eax@1
+  FILE *v3; // esi@1
+
+  v1 = pMessage;
+  f = fopen("errorlog.txt", "a");
+  v3 = f;
+  if ( f )
+  {
+    fprintf(f, "%s\n", v1);
+    fclose(v3);
+    fflush(v3);
+  }
+}
+
+//----- (004BE3BF) --------------------------------------------------------
+FrameTableTxtLine *texture_frame_table_txt_parser(const char *_this, FrameTableTxtLine *a2)
+{
+  char *v2; // eax@3
+  signed int v3; // edx@3
+  unsigned int v4; // edi@3
+  char v5; // cl@4
+  FrameTableTxtLine *result; // eax@21
+  signed int v7; // [sp+Ch] [bp-4h]@3
+
+  static struct FrameTableTxtLine static_stru_F8BA58; // weak
+  static_stru_F8BA58.field_0 = 0;
+  if ( _this && *_this )
+  {
+    v2 = (char *)&unk_F8B668;
+    v3 = 1;
+    v7 = 0;
+    v4 = _this - (char *)&unk_F8B668;
+    do
+    {
+      v5 = v2[v4];
+      *v2 = v5;
+      if ( !v5 )
+        break;
+      if ( v5 != 32 && v5 != 44 && v5 != 9 || v7 )
+      {
+        if ( v5 == 34 )
+        {
+          *v2 = 0;
+          v3 = 1;
+          if ( v7 )
+          {
+            v7 = 0;
+          }
+          else
+          {
+            v7 = 1;
+            if ( v2[v4 + 1] == 34 )
+            {
+              static_stru_F8BA58.pProperties[static_stru_F8BA58.field_0] = v2;
+              ++static_stru_F8BA58.field_0;
+            }
+          }
+        }
+        else
+        {
+          if ( v3 )
+          {
+            static_stru_F8BA58.pProperties[static_stru_F8BA58.field_0] = v2;
+            ++static_stru_F8BA58.field_0;
+          }
+          v3 = 0;
+        }
+      }
+      else
+      {
+        *v2 = 0;
+        v3 = 1;
+      }
+      if ( static_stru_F8BA58.field_0 >= 30 )
+        break;
+      ++v2;
+    }
+    while ( (unsigned int)v2 < (unsigned int)&unk_F8BA50 );
+    *v2 = 0;
+  }
+  result = a2;
+  memcpy(a2, &static_stru_F8BA58, 0x7Cu);
+  return result;
+}
+// F8BA58: using guessed type FrameTableTxtLine static_stru_F8BA58;
+
+//----- (004BE485) --------------------------------------------------------
+FrameTableTxtLine *__thiscall frame_table_txt_parser(const char *pString, FrameTableTxtLine *a2)
+{
+  char *v2; // eax@3
+  signed int v3; // edi@3
+  signed int v4; // edx@3
+  char v5; // cl@4
+  FrameTableTxtLine *result; // eax@24
+  unsigned int v7; // [sp+Ch] [bp-4h]@3
+
+  stru_F8B5E8.field_0 = 0;
+  if ( pString && *pString )
+  {
+    v2 = (char *)&unk_F8B1F8;
+    v3 = 0;
+    v7 = pString - (const char *)&unk_F8B1F8;
+    v4 = 1;
+    while ( 1 )
+    {
+      v5 = v2[v7];
+      *v2 = v5;
+      if ( !v5 )
+      {
+LABEL_23:
+        *v2 = 0;
+        break;
+      }
+      if ( v5 == ',' )
+      {
+        if ( v3 )
+          goto LABEL_18;
+        *v2 = 0;
+      }
+      else
+      {
+        if ( v5 != '\t' )
+        {
+          if ( v5 == '"' )
+          {
+            *v2 = 0;
+            v4 = 1;
+            if ( v3 )
+            {
+              v3 = 0;
+            }
+            else
+            {
+              v3 = 1;
+              if ( v2[v7 + 1] == 34 )
+              {
+                stru_F8B5E8.pProperties[stru_F8B5E8.field_0] = v2;
+                ++stru_F8B5E8.field_0;
+              }
+            }
+            goto LABEL_21;
+          }
+LABEL_18:
+          if ( v4 )
+          {
+            stru_F8B5E8.pProperties[stru_F8B5E8.field_0] = v2;
+            ++stru_F8B5E8.field_0;
+          }
+          v4 = 0;
+          goto LABEL_21;
+        }
+        if ( v3 )
+          goto LABEL_18;
+        *v2 = 0;
+        if ( v4 )
+        {
+          stru_F8B5E8.pProperties[stru_F8B5E8.field_0] = v2;
+          ++stru_F8B5E8.field_0;
+        }
+      }
+      v4 = 1;
+LABEL_21:
+      if ( stru_F8B5E8.field_0 < 30 )
+      {
+        ++v2;
+        if ( (unsigned int)v2 < (unsigned int)&unk_F8B5E0 )
+          continue;
+      }
+      goto LABEL_23;
+    }
+  }
+  result = a2;
+  memcpy(a2, &stru_F8B5E8, 0x7Cu);
+  return result;
+}
+// F8B5E8: using guessed type FrameTableTxtLine stru_F8B5E8;
+
+//----- (004BE571) --------------------------------------------------------
+int __fastcall sub_4BE571(int a1, int *a2, int a3, int a4)
+{
+  int result; // eax@1
+  int i; // esi@3
+
+  result = a3;
+  if ( a3 < a4 )
+  {
+    for ( i = 0; i < a3; ++i )
+    {
+      if ( a1 == a2[i] )
+        break;
+    }
+    if ( i == a3 )
+    {
+      a2[a3] = a1;
+      result = a3 + 1;
+    }
+  }
+  else
+  {
+    result = a4;
+  }
+  return result;
+}
+
+
+
+//----- (004BF91E) --------------------------------------------------------
+unsigned int __thiscall GameOverMenu(void *ecx0)
+{
+  char *v1; // eax@2
+  unsigned int result; // eax@3
+  char *v3; // eax@7
+  char *v4; // ST24_4@9
+  int v5; // eax@9
+  char *v6; // eax@10
+  char *v7; // edx@10
+  char *v8; // ecx@12
+  char *v9; // eax@14
+  unsigned int v10; // eax@25
+  GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1
+  MSG Msg; // [sp+88h] [bp-48h]@22
+  unsigned int v14; // [sp+A4h] [bp-2Ch]@5
+  void *v15; // [sp+A8h] [bp-28h]@1
+  char *pInString; // [sp+ACh] [bp-24h]@5
+  unsigned int v17; // [sp+B0h] [bp-20h]@5
+  unsigned int v18; // [sp+B4h] [bp-1Ch]@5
+  unsigned int v19; // [sp+B8h] [bp-18h]@5
+  int v20; // [sp+BCh] [bp-14h]@7
+  int i; // [sp+C0h] [bp-10h]@7
+  GUIFont *pFont; // [sp+C4h] [bp-Ch]@1
+  unsigned __int64 v23; // [sp+C8h] [bp-8h]@5
+
+  v15 = ecx0;
+
+  RGBTexture _this; // [sp+Ch] [bp-C4h]@1
+  //RGBTexture::RGBTexture(&this);
+
+  BYTE1(dword_6BE364_game_settings_1) &= 0xBFu;
+  bGameoverLoop = 1;
+  pVideoPlayer->bStopBeforeSchedule = 0;
+  pAudioPlayer->StopChannels(-1, -1);
+  pRenderer->BeginScene();
+  pRenderer->ClearBlack();
+  pRenderer->EndScene();
+  pRenderer->Present();
+  pVideoPlayer->field_40 = 0;
+  _449B57_test_bit(pParty->_award_bits, 99);
+  _this.Load("winbg.pcx", 2);
+  pRenderer->BeginScene();
+  pRenderer->DrawTextureRGB(0, 0, &_this);
+  pRenderer->EndScene();
+  free(_this.pPixels);
+  _this.pPixels = 0;
+  ptr_507BC0 = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+  pWindow.uFrameX = 75;
+  pWindow.uFrameY = 60;
+  pWindow.uFrameWidth = 469;
+  pWindow.uFrameHeight = 338;
+  pWindow.uFrameZ = 543;
+  pWindow.uFrameW = 397;
+  pFont = LoadFont("endgame.fnt", "FONTPAL", 0);
+  if ( (unsigned __int16)_449B57_test_bit(pParty->_award_bits, 99) )
+  {
+    v1 = pGlobalTXT_LocalizationStrings[675];
+  }
+  else
+  {
+    result = _449B57_test_bit(pParty->_award_bits, 100);
+    if ( !(short)result )
+      return result;
+    v1 = pGlobalTXT_LocalizationStrings[676];
+  }
+  pInString = v1;
+  v23 = pParty->uTimePlayed - 138240;
+  v19 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 0x18;
+  v14 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 0x18 / 0x1C / 0xC;
+  v18 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 0x18 / 0x1C % 0xC;
+  v17 = v19 % 0x1C;
+  if ( !v19 )
+    v19 = 1;
+  pRenderer->BeginScene();
+  pWindow.DrawTitleText(pFont, 1u, 0x23u, 1u, pGlobalTXT_LocalizationStrings[9], 3u);
+  v3 = pParty->pPlayers[0].pName;
+  v23 = 0i64;
+  v20 = 0;
+  for ( i = (int)pParty->pPlayers[0].pName; ; v3 = (char *)i )
+  {
+    v4 = pClassNames[(unsigned __int8)v3[17]];
+    v5 = ((Player *)(v3 - 168))->GetBaseLevel();
+    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[129], i, v5, v4);
+    pWindow.DrawTitleText(
+      pFont,
+      1u,
+      v20 * (LOBYTE(pFont->uFontHeight) - 2) + LOBYTE(pFont->uFontHeight) + 46,
+      1u,
+      pTmpBuf,
+      3u);
+    v23 += __PAIR__(*(int *)(i - 4), *(int *)(i - 8));
+    ++v20;
+    i += 6972;
+    if ( i >= (signed int)&pParty->pPickedItem.uNumCharges )
+      break;
+  }
+  v23 = (signed __int64)v23 / v19;
+  v6 = FitTextInAWindow(pInString, pFont, &pWindow, 0xCu, 0);
+  pWindow.DrawTitleText(pFont, 1u, 5 * (LOBYTE(pFont->uFontHeight) + 11), 1u, v6, 0);
+  strcpy(pTmpBuf, pGlobalTXT_LocalizationStrings[37]);
+  v7 = pGlobalTXT_LocalizationStrings[56];
+  if ( v17 != 1 )
+    v7 = pGlobalTXT_LocalizationStrings[57];
+  v8 = pGlobalTXT_LocalizationStrings[146];
+  if ( v18 != 1 )
+    v8 = pGlobalTXT_LocalizationStrings[148];
+  v9 = pGlobalTXT_LocalizationStrings[245];
+  if ( v14 != 1 )
+    v9 = pGlobalTXT_LocalizationStrings[132];
+  sprintf(pTmpBuf2, " %lu %s, %lu %s, %lu %s ", v14, v9, v18, v8, v17, v7);
+  strcat(pTmpBuf, pTmpBuf2);
+  pWindow.DrawTitleText(pFont, 1u, pWindow.uFrameHeight - 2 * LOBYTE(pFont->uFontHeight) - 5, 1u, pTmpBuf, 3u);
+  sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[94], v23);
+  pWindow.DrawTitleText(pFont, 1u, pWindow.uFrameHeight, 1u, pTmpBuf, 3u);
+  BYTE1(dword_6BE364_game_settings_1) |= 0x40u;
+  pRenderer->EndScene();
+  pRenderer->Present();
+  if ( pRenderer->pRenderD3D )
+    pRenderer->pBeforePresentFunction();
+  pRenderer->_49F1BC("MM7_Win.Pcx");
+  pAllocator->FreeChunk(pFont);
+  ptr_507BC0->Release();
+  ptr_507BC0 = 0;
+  if ( v15 == (void *)2 )
+  {
+    result = pMessageQueue_50CBD0->uNumMessages;
+  }
+  else
+  {
+    LODWORD(v23) = GetTickCount() + 5000;
+    while ( (unsigned int)v23 > GetTickCount() )
+      ;
+    while ( 1 )
+    {
+      v10 = PeekMessageA(&Msg, 0, 0, 0, 1u);
+      if ( !v10 )
+        break;
+      if ( Msg.message == 18 )
+        Game_DeinitializeAndTerminate(0);
+      TranslateMessage(&Msg);
+      DispatchMessageA(&Msg);
+    }
+    if ( pMessageQueue_50CBD0->uNumMessages )
+    {
+      LOBYTE(v10) = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+      pMessageQueue_50CBD0->uNumMessages = v10;
+    }
+    pKeyActionMap->ResetKeys();
+    pKeyActionMap->uLastKeyPressed = 0;
+    do
+    {
+      while ( PeekMessageA(&Msg, 0, 0, 0, 1u) )
+      {
+        if ( Msg.message == 18 )
+          Game_DeinitializeAndTerminate(0);
+        TranslateMessage(&Msg);
+        DispatchMessageA(&Msg);
+      }
+    }
+    while ( !pKeyActionMap->uLastKeyPressed );
+    result = pMessageQueue_50CBD0->uNumMessages;
+    if ( pMessageQueue_50CBD0->uNumMessages )
+    {
+      result = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+      pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+    }
+  }
+  if ( v15 )
+  {
+    if ( (signed int)result < 40 )
+    {
+      pMessageQueue_50CBD0->pMessages[result].eType = (UIMessageType)132;
+      goto LABEL_42;
+    }
+  }
+  else
+  {
+    if ( (signed int)result < 40 )
+    {
+      pMessageQueue_50CBD0->pMessages[result].eType = (UIMessageType)197;
+LABEL_42:
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
+      result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
+      *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
+      ++pMessageQueue_50CBD0->uNumMessages;
+      goto LABEL_43;
+    }
+  }
+LABEL_43:
+  bGameoverLoop = 0;
+  return result;
+}
+
+
+//----- (004C0262) --------------------------------------------------------
+void Viewport::SetScreen(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
+{
+  unsigned int x; // edx@1
+  unsigned int z; // esi@1
+  unsigned int y; // edi@3
+  unsigned int w; // eax@3
+  char no_3d; // zf@5
+  int v10; // eax@7
+
+  x = uX;
+  z = uZ;
+  if ( (signed int)uX > (signed int)uZ )
+  {
+    z = uZ ^ uX ^ uZ;                           // swap x and z
+    x = z ^ uZ ^ uX;
+  }
+  y = uY;
+  w = uW;
+  if ( (signed int)uY > (signed int)uW )
+  {
+    w = uW ^ uY ^ uW;                           // swap y and w
+    y = w ^ uW ^ uY;
+  }
+  this->uScreenX = x;
+  this->uScreenY = y;
+  this->uScreenZ = z;
+  this->uScreenW = w;
+  no_3d = pRenderer->pRenderD3D == 0;
+  this->uScreenWidth = z - x + 1;
+  this->uScreenCenterX = (signed int)(z + x) >> 1;
+  if ( no_3d )
+  {
+    v10 = w - y + 1;
+    this->uScreenHeight = v10;
+    this->uScreenCenterY = this->uScreenW - ((unsigned __int64)(this->field_30 * (signed __int64)v10) >> 16);
+  }
+  else
+  {
+    this->uScreenHeight = w - y + 1;
+    this->uScreenCenterY = (signed int)(w + y) >> 1;
+  }
+  SetViewport(this->uScreenX, this->uScreenY, this->uScreenZ, this->uScreenW);
+}
+
+//----- (004C02F8) --------------------------------------------------------
+void Viewport::_4C02F8(int a2)
+{
+  unsigned int v2; // ST0C_4@1
+
+  v2 = this->uScreenW;
+  this->field_30 = a2;
+  SetScreen(this->uScreenX, this->uScreenY, this->uScreenZ, v2);
+}
+
+//----- (004C0312) --------------------------------------------------------
+void Viewport::SetViewport(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
+{
+  unsigned int x; // ebx@1
+  unsigned int y; // edi@3
+  unsigned int z; // edx@5
+  unsigned int w; // eax@7
+
+  x = uX;
+  if ( (signed int)uX < (signed int)this->uScreenX )
+    x = this->uScreenX;
+  y = uY;
+  if ( (signed int)uY < (signed int)this->uScreenY )
+    y = this->uScreenY;
+  z = uZ;
+  if ( (signed int)uZ > (signed int)this->uScreenZ )
+    z = this->uScreenZ;
+  w = uW;
+  if ( (signed int)uW > (signed int)this->uScreenW )
+    w = this->uScreenW;
+  this->uViewportY = y;
+  this->uViewportX = x;
+  this->uViewportZ = z;
+  this->uViewportW = w;
+}
+
+
+
+
+
+
+//----- (004D6FB0) --------------------------------------------------------
+int /*__usercall*/ sr_sub_4D6FB0/*<eax>*/(stru315 *a1/*<ebp>*/)
+{
+  int v1; // ebp@1
+  unsigned int v2; // esi@1
+  unsigned int v3; // edi@1
+  int result; // eax@1
+  int v5; // ebx@2
+  int v6; // edx@2
+  int v7; // ebx@3
+  __int16 v8; // cx@3
+  int v9; // ebx@4
+  unsigned __int8 v10; // sf@5
+  unsigned __int8 v11; // of@5
+
+  v1 = a1->field_8;
+  v2 = *(int *)(v1 + 48);
+  v3 = *(int *)(v1 + 44);
+  result = *(int *)(v1 + 64);
+  if ( !(*(int *)(v1 + 40) & 1) )
+    goto LABEL_5;
+  --*(int *)(v1 + 40);
+  result -= 2;
+  v5 = *(int *)(v1 + 60);
+  v6 = *(int *)(v1 + 36);
+  *(int *)(v1 + 60) += 4;
+  while ( 1 )
+  {
+    *(int *)v5 = v6;
+    v9 = *(char *)(*(int *)(v1 + 56)
+                  + (*(int *)(v1 + 12) & (v2 >> 16))
+                  + ((*(int *)(v1 + 8) & v3) >> *(char *)(v1 + 16)));
+    result += 4;
+    v2 += *(int *)(v1 + 4);
+    v3 += *(int *)v1;
+    *(short *)(result - 2) = *(short *)(*(int *)(v1 + 52) + 2 * v9);
+LABEL_5:
+    v11 = __OFSUB__(*(int *)(v1 + 40), 2);
+    v10 = *(int *)(v1 + 40) - 2 < 0;
+    *(int *)(v1 + 40) -= 2;
+    if ( v10 ^ v11 )
+      break;
+    v7 = *(char *)(*(int *)(v1 + 56)
+                  + (*(int *)(v1 + 12) & (v2 >> 16))
+                  + ((*(int *)(v1 + 8) & v3) >> *(char *)(v1 + 16)));
+    v2 += *(int *)(v1 + 4);
+    v8 = *(short *)(*(int *)(v1 + 52) + 2 * v7);
+    v3 += *(int *)v1;
+    v5 = *(int *)(v1 + 60);
+    v6 = *(int *)(v1 + 36);
+    *(short *)result = v8;
+    *(int *)(v1 + 60) += 8;
+    *(int *)(v5 + 4) = v6;
+  }
+  *(int *)(v1 + 64) = result;
+  *(int *)(v1 + 48) = v2;
+  *(int *)(v1 + 44) = v3;
+  return result;
+}
+
+//----- (004D705A) --------------------------------------------------------
+int /*__usercall*/ sr_sub_4D705A/*<eax>*/(stru315 *a1/*<ebp>*/)
+{
+  int v1; // ebp@1
+  unsigned int v2; // esi@1
+  unsigned int v3; // edi@1
+  int result; // eax@1
+  int v5; // ebx@2
+  int v6; // edx@2
+  unsigned int v7; // ebx@3
+  unsigned int v8; // edx@3
+  __int16 v9; // cx@11
+  unsigned int v10; // ebx@12
+  unsigned int v11; // edx@12
+  unsigned __int8 v12; // sf@21
+  unsigned __int8 v13; // of@21
+
+  v1 = a1->field_8;
+  v2 = *(int *)(v1 + 48);
+  v3 = *(int *)(v1 + 44);
+  result = *(int *)(v1 + 64);
+  if ( !(*(int *)(v1 + 40) & 1) )
+    goto LABEL_21;
+  --*(int *)(v1 + 40);
+  result -= 2;
+  v5 = *(int *)(v1 + 60);
+  v6 = *(int *)(v1 + 36);
+  *(int *)(v1 + 60) += 4;
+  while ( 1 )
+  {
+    *(int *)v5 = v6;
+    v10 = v3;
+    v11 = v2;
+    if ( (signed int)v2 < *(int *)(v1 + 20) )
+      v11 = *(int *)(v1 + 20);
+    if ( (signed int)v3 < *(int *)(v1 + 28) )
+      v10 = *(int *)(v1 + 28);
+    if ( (signed int)v11 > *(int *)(v1 + 24) )
+      v11 = *(int *)(v1 + 24);
+    if ( (signed int)v10 > *(int *)(v1 + 32) )
+      v10 = *(int *)(v1 + 32);
+    result += 4;
+    v2 += *(int *)(v1 + 4);
+    v3 += *(int *)v1;
+    *(short *)(result - 2) = *(short *)(*(int *)(v1 + 52)
+                                      + 2
+                                      * *(char *)(*(int *)(v1 + 56)
+                                                 + (*(int *)(v1 + 12) & (v11 >> 16))
+                                                 + ((*(int *)(v1 + 8) & v10) >> *(char *)(v1 + 16))));
+LABEL_21:
+    v13 = __OFSUB__(*(int *)(v1 + 40), 2);
+    v12 = *(int *)(v1 + 40) - 2 < 0;
+    *(int *)(v1 + 40) -= 2;
+    if ( v12 ^ v13 )
+      break;
+    v7 = v3;
+    v8 = v2;
+    if ( (signed int)v2 < *(int *)(v1 + 20) )
+      v8 = *(int *)(v1 + 20);
+    if ( (signed int)v3 < *(int *)(v1 + 28) )
+      v7 = *(int *)(v1 + 28);
+    if ( (signed int)v8 > *(int *)(v1 + 24) )
+      v8 = *(int *)(v1 + 24);
+    if ( (signed int)v7 > *(int *)(v1 + 32) )
+      v7 = *(int *)(v1 + 32);
+    v2 += *(int *)(v1 + 4);
+    v9 = *(short *)(*(int *)(v1 + 52)
+                  + 2
+                  * *(char *)(*(int *)(v1 + 56)
+                             + (*(int *)(v1 + 12) & (v8 >> 16))
+                             + ((*(int *)(v1 + 8) & v7) >> *(char *)(v1 + 16))));
+    v3 += *(int *)v1;
+    v5 = *(int *)(v1 + 60);
+    v6 = *(int *)(v1 + 36);
+    *(short *)result = v9;
+    *(int *)(v1 + 60) += 8;
+    *(int *)(v5 + 4) = v6;
+  }
+  *(int *)(v1 + 64) = result;
+  *(int *)(v1 + 48) = v2;
+  *(int *)(v1 + 44) = v3;
+  return result;
+}
+
+//----- (004D714C) --------------------------------------------------------
+int __cdecl sr_sub_4D714C(stru315 *a1)
+{
+  stru315 *v1; // ebp@0
+  stru315 *v2; // ebp@1
+  unsigned int v3; // esi@1
+  int v4; // edi@1
+  int result; // eax@1
+  unsigned int *v6; // ebx@2
+  int v7; // edx@2
+  int v8; // ebx@3
+  unsigned __int16 v9; // cx@3
+  unsigned int *v10; // ebx@3
+  int v11; // edx@3
+  int v12; // ebx@4
+  unsigned __int8 v13; // sf@5
+  unsigned __int8 v14; // of@5
+
+  v2 = (stru315 *)v1->field_8;
+  v3 = v2->field_30;
+  v4 = v2->field_2C;
+  result = (int)v2->pColorBuffer;
+  if ( !(v2->field_28 & 1) )
+    goto LABEL_5;
+  --v2->field_28;
+  result += 2;
+  v6 = v2->pDepthBuffer;
+  v7 = v2->field_24;
+  --v2->pDepthBuffer;
+  *v6 = v7;
+  while ( 1 )
+  {
+    v12 = *((char *)v2->pTextureLOD
+          + (v2->field_C & (v3 >> 16))
+          + ((v2->field_8 & (unsigned int)v4) >> LOBYTE(v2->field_10)));
+    result -= 4;
+    v3 += v2->field_4;
+    v4 += v2->field_0;
+    *(short *)(result + 2) = v2->field_34_palette[v12];
+LABEL_5:
+    v14 = __OFSUB__(v2->field_28, 2);
+    v13 = v2->field_28 - 2 < 0;
+    v2->field_28 -= 2;
+    if ( v13 ^ v14 )
+      break;
+    v8 = *((char *)v2->pTextureLOD
+         + (v2->field_C & (v3 >> 16))
+         + ((v2->field_8 & (unsigned int)v4) >> LOBYTE(v2->field_10)));
+    v3 += v2->field_4;
+    v9 = v2->field_34_palette[v8];
+    v4 += v2->field_0;
+    v10 = v2->pDepthBuffer;
+    v11 = v2->field_24;
+    *(short *)result = v9;
+    v2->pDepthBuffer -= 2;
+    *v10 = v11;
+    *(v10 - 1) = v11;
+  }
+  v2->pColorBuffer = (unsigned __int16 *)result;
+  v2->field_30 = v3;
+  v2->field_2C = v4;
+  return result;
+}
+// 4D714C: inconsistent function type and number of purged bytes
+
+//----- (004D71F8) --------------------------------------------------------
+int __cdecl sr_sub_4D71F8(stru315 *a1)
+{
+  stru315 *v1; // ebp@0
+  stru315 *v2; // ebp@1
+  int v3; // esi@1
+  int v4; // edi@1
+  int result; // eax@1
+  unsigned int *v6; // ebx@2
+  int v7; // edx@2
+  int v8; // ebx@3
+  unsigned int v9; // edx@3
+  unsigned __int16 v10; // cx@11
+  unsigned int *v11; // ebx@11
+  int v12; // edx@11
+  int v13; // ebx@12
+  unsigned int v14; // edx@12
+  unsigned __int8 v15; // sf@21
+  unsigned __int8 v16; // of@21
+
+  v2 = (stru315 *)v1->field_8;
+  v3 = v2->field_30;
+  v4 = v2->field_2C;
+  result = (int)v2->pColorBuffer;
+  if ( !(v2->field_28 & 1) )
+    goto LABEL_21;
+  --v2->field_28;
+  result += 2;
+  v6 = v2->pDepthBuffer;
+  v7 = v2->field_24;
+  --v2->pDepthBuffer;
+  *v6 = v7;
+  while ( 1 )
+  {
+    v13 = v4;
+    v14 = v3;
+    if ( v3 < v2->field_14 )
+      v14 = v2->field_14;
+    if ( v4 < v2->field_1C )
+      v13 = v2->field_1C;
+    if ( (signed int)v14 > v2->field_18 )
+      v14 = v2->field_18;
+    if ( v13 > v2->field_20 )
+      v13 = v2->field_20;
+    result -= 4;
+    v3 += v2->field_4;
+    v4 += v2->field_0;
+    *(short *)(result + 2) = v2->field_34_palette[*((char *)v2->pTextureLOD
+                                                  + (v2->field_C & (v14 >> 16))
+                                                  + ((v2->field_8 & (unsigned int)v13) >> LOBYTE(v2->field_10)))];
+LABEL_21:
+    v16 = __OFSUB__(v2->field_28, 2);
+    v15 = v2->field_28 - 2 < 0;
+    v2->field_28 -= 2;
+    if ( v15 ^ v16 )
+      break;
+    v8 = v4;
+    v9 = v3;
+    if ( v3 < v2->field_14 )
+      v9 = v2->field_14;
+    if ( v4 < v2->field_1C )
+      v8 = v2->field_1C;
+    if ( (signed int)v9 > v2->field_18 )
+      v9 = v2->field_18;
+    if ( v8 > v2->field_20 )
+      v8 = v2->field_20;
+    v3 += v2->field_4;
+    v10 = v2->field_34_palette[*((char *)v2->pTextureLOD
+                               + (v2->field_C & (v9 >> 16))
+                               + ((v2->field_8 & (unsigned int)v8) >> LOBYTE(v2->field_10)))];
+    v4 += v2->field_0;
+    v11 = v2->pDepthBuffer;
+    v12 = v2->field_24;
+    *(short *)result = v10;
+    v2->pDepthBuffer -= 2;
+    *v11 = v12;
+    *(v11 - 1) = v12;
+  }
+  v2->pColorBuffer = (unsigned __int16 *)result;
+  v2->field_30 = v3;
+  v2->field_2C = v4;
+  return result;
+}
+// 4D71F8: inconsistent function type and number of purged bytes
+
+//----- (004D72EC) --------------------------------------------------------
+int /*__usercall*/ sr_sub_4D72EC/*<eax>*/(int a1/*<ebp>*/)
+{
+  int v1; // ebp@1
+  unsigned int v2; // esi@1
+  unsigned int v3; // edi@1
+  int result; // eax@1
+  int v5; // ebx@2
+  int v6; // edx@2
+  unsigned int v7; // edx@3
+  unsigned int v8; // ebx@3
+  int v9; // ebx@11
+  unsigned int v10; // edx@14
+  unsigned int v11; // ebx@14
+  int v12; // ebx@22
+  unsigned __int8 v13; // sf@25
+  unsigned __int8 v14; // of@25
+
+  v1 = *(int *)(a1 + 8);
+  v2 = *(int *)(v1 + 48);
+  v3 = *(int *)(v1 + 44);
+  result = *(int *)(v1 + 64);
+  if ( !(*(int *)(v1 + 40) & 1) )
+    goto LABEL_25;
+  --*(int *)(v1 + 40);
+  result -= 2;
+  v5 = *(int *)(v1 + 60);
+  v6 = *(int *)(v1 + 36);
+  *(int *)(v1 + 60) += 4;
+  while ( 1 )
+  {
+    *(int *)v5 = v6;
+    v10 = v2;
+    v11 = v3;
+    if ( (signed int)v2 < *(int *)(v1 + 20) )
+      v10 = *(int *)(v1 + 20);
+    if ( (signed int)v3 < *(int *)(v1 + 28) )
+      v11 = *(int *)(v1 + 28);
+    if ( (signed int)v10 > *(int *)(v1 + 24) )
+      v10 = *(int *)(v1 + 24);
+    if ( (signed int)v11 > *(int *)(v1 + 32) )
+      v11 = *(int *)(v1 + 32);
+    v12 = *(char *)(*(int *)(v1 + 56)
+                   + (*(int *)(v1 + 12) & (v10 >> 16))
+                   + ((*(int *)(v1 + 8) & v11) >> *(char *)(v1 + 16)));
+    result += 4;
+    v2 += *(int *)(v1 + 4);
+    if ( v12 )
+      *(short *)(result - 2) = *(short *)(*(int *)(v1 + 52) + 2 * v12);
+    v3 += *(int *)v1;
+LABEL_25:
+    v14 = __OFSUB__(*(int *)(v1 + 40), 2);
+    v13 = *(int *)(v1 + 40) - 2 < 0;
+    *(int *)(v1 + 40) -= 2;
+    if ( v13 ^ v14 )
+      break;
+    v7 = v2;
+    v8 = v3;
+    if ( (signed int)v2 < *(int *)(v1 + 20) )
+      v7 = *(int *)(v1 + 20);
+    if ( (signed int)v3 < *(int *)(v1 + 28) )
+      v8 = *(int *)(v1 + 28);
+    if ( (signed int)v7 > *(int *)(v1 + 24) )
+      v7 = *(int *)(v1 + 24);
+    if ( (signed int)v8 > *(int *)(v1 + 32) )
+      v8 = *(int *)(v1 + 32);
+    v9 = *(char *)(*(int *)(v1 + 56)
+                  + (*(int *)(v1 + 12) & (v7 >> 16))
+                  + ((*(int *)(v1 + 8) & v8) >> *(char *)(v1 + 16)));
+    v2 += *(int *)(v1 + 4);
+    if ( v9 )
+      *(short *)result = *(short *)(*(int *)(v1 + 52) + 2 * v9);
+    v3 += *(int *)v1;
+    v5 = *(int *)(v1 + 60);
+    v6 = *(int *)(v1 + 36);
+    *(int *)(v1 + 60) += 8;
+    *(int *)(v5 + 4) = v6;
+  }
+  return result;
+}
+
+//----- (004D73DF) --------------------------------------------------------
+int /*__usercall*/ sr_sub_4D73DF/*<eax>*/(int a1/*<ebp>*/)
+{
+  int v1; // ebp@1
+  unsigned int v2; // esi@1
+  unsigned int v3; // edi@1
+  int result; // eax@1
+  int v5; // ebx@2
+  int v6; // edx@2
+  int v7; // edx@3
+  int v8; // edx@6
+  unsigned __int8 v9; // sf@9
+  unsigned __int8 v10; // of@9
+
+  v1 = *(int *)(a1 + 8);
+  v2 = *(int *)(v1 + 48);
+  v3 = *(int *)(v1 + 44);
+  result = *(int *)(v1 + 64);
+  if ( !(*(int *)(v1 + 40) & 1) )
+    goto LABEL_9;
+  --*(int *)(v1 + 40);
+  result -= 2;
+  v5 = *(int *)(v1 + 60);
+  v6 = *(int *)(v1 + 36);
+  *(int *)(v1 + 60) += 4;
+  while ( 1 )
+  {
+    *(int *)v5 = v6;
+    v8 = *(int *)(v1 + 12) & (v2 >> 16);
+    result += 4;
+    v2 += *(int *)(v1 + 4);
+    if ( *(char *)(*(int *)(v1 + 56) + v8 + ((*(int *)(v1 + 8) & v3) >> *(char *)(v1 + 16))) )
+      *(short *)(result - 2) = *(short *)(*(int *)(v1 + 52)
+                                        + 2
+                                        * *(char *)(*(int *)(v1 + 56)
+                                                   + v8
+                                                   + ((*(int *)(v1 + 8) & v3) >> *(char *)(v1 + 16))));
+    v3 += *(int *)v1;
+LABEL_9:
+    v10 = __OFSUB__(*(int *)(v1 + 40), 2);
+    v9 = *(int *)(v1 + 40) - 2 < 0;
+    *(int *)(v1 + 40) -= 2;
+    if ( v9 ^ v10 )
+      break;
+    v7 = *(int *)(v1 + 12) & (v2 >> 16);
+    v2 += *(int *)(v1 + 4);
+    if ( *(char *)(*(int *)(v1 + 56) + v7 + ((*(int *)(v1 + 8) & v3) >> *(char *)(v1 + 16))) )
+      *(short *)result = *(short *)(*(int *)(v1 + 52)
+                                  + 2
+                                  * *(char *)(*(int *)(v1 + 56)
+                                             + v7
+                                             + ((*(int *)(v1 + 8) & v3) >> *(char *)(v1 + 16))));
+    v3 += *(int *)v1;
+    v5 = *(int *)(v1 + 60);
+    v6 = *(int *)(v1 + 36);
+    *(int *)(v1 + 60) += 8;
+    *(int *)(v5 + 4) = v6;
+  }
+  return result;
+}
+
+//----- (004D754B) --------------------------------------------------------
+void __cdecl sr_sub_4D754B(stru315 *a1, stru316 *a2)
+{
+  int v2; // ecx@1
+  unsigned int v3; // eax@2
+  int v4; // ecx@2
+  int v5; // eax@10
+  unsigned __int16 *v6; // edx@10
+  int v7; // ebx@11
+  int v8; // ecx@13
+  unsigned __int16 v9; // bx@16
+  int v10; // ecx@16
+  unsigned __int16 *v11; // eax@16
+  unsigned int *v12; // edx@16
+  int v13; // ecx@16
+  int v14; // eax@16
+  int v15; // ebx@16
+  int v16; // [sp-4h] [bp-Ch]@2
+
+  v2 = a1->field_28;
+  if ( v2 )
+  {
+    do
+    {
+      v16 = v2;
+      v3 = a1->field_30;
+      v4 = a1->field_2C;
+      if ( (signed int)v3 >= a1->field_18 )
+        v3 = a1->field_18;
+      if ( (signed int)v3 <= a1->field_14 )
+        v3 = a1->field_14;
+      if ( v4 >= a1->field_20 )
+        v4 = a1->field_20;
+      if ( v4 <= a1->field_1C )
+        v4 = a1->field_1C;
+      v5 = *((char *)a1->pTextureLOD + (a1->field_C & (v3 >> 16)) + (((unsigned int)v4 & a1->field_8) >> a1->field_10));
+      v6 = a1->field_34_palette;
+      if ( a2->field_20 )
+      {
+        v7 = (unsigned int)a2->field_10 >> 16;
+        if ( v7 >= a2->field_C )
+          v7 = a2->field_C;
+        v8 = 0;
+        if ( a2->field_8 - v7 >= 0 )
+          v8 = a2->field_8 - v7;
+        v5 += v8 << 8;
+        v6 = a2->field_24_palette;
+      }
+      v9 = v6[v5];
+      v10 = a1->field_24;
+      v11 = a1->pColorBuffer;
+      v12 = a1->pDepthBuffer;
+      *v11 = v9;
+      *v12 = v10;
+      a1->pColorBuffer = v11 + 1;
+      a1->pDepthBuffer = v12 + 1;
+      v13 = a1->field_30;
+      a2->field_10 += a2->field_18;
+      v14 = a1->field_2C;
+      v15 = a1->field_0;
+      a1->field_30 = a1->field_4 + v13;
+      a1->field_2C = v15 + v14;
+      v2 = v16 - 1;
+    }
+    while ( v16 != 1 );
+  }
+}
+
+//----- (004D7630) --------------------------------------------------------
+void __cdecl sr_sub_4D7630(stru315 *a1, stru316 *a2)
+{
+  int v2; // ecx@1
+  int v3; // eax@2
+  unsigned __int16 *v4; // edx@2
+  int v5; // ebx@3
+  int v6; // ecx@5
+  unsigned __int16 v7; // bx@8
+  int v8; // ecx@8
+  unsigned __int16 *v9; // eax@8
+  unsigned int *v10; // edx@8
+  int v11; // ecx@8
+  int v12; // eax@8
+  int v13; // ebx@8
+  int v14; // [sp-4h] [bp-Ch]@2
+
+  v2 = a1->field_28;
+  if ( v2 )
+  {
+    do
+    {
+      v14 = v2;
+      v3 = *((char *)a1->pTextureLOD
+           + (a1->field_C & ((unsigned int)a1->field_30 >> 16))
+           + ((unsigned int)(a1->field_2C & a1->field_8) >> a1->field_10));
+      v4 = a1->field_34_palette;
+      if ( a2->field_20 )
+      {
+        v5 = (unsigned int)a2->field_14 >> 16;
+        if ( v5 >= a2->field_C )
+          v5 = a2->field_C;
+        v6 = 0;
+        if ( a2->field_8 - v5 >= 0 )
+          v6 = a2->field_8 - v5;
+        v3 += v6 << 8;
+        v4 = a2->field_24_palette;
+      }
+      v7 = v4[v3];
+      v8 = a1->field_24;
+      v9 = a1->pColorBuffer;
+      v10 = a1->pDepthBuffer;
+      *v9 = v7;
+      *v10 = v8;
+      a1->pColorBuffer = v9 - 1;
+      a1->pDepthBuffer = v10 - 1;
+      v11 = a1->field_30;
+      a2->field_14 -= a2->field_18;
+      v12 = a1->field_2C;
+      v13 = a1->field_0;
+      a1->field_30 = a1->field_4 + v11;
+      a1->field_2C = v13 + v12;
+      v2 = v14 - 1;
+    }
+    while ( v14 != 1 );
+  }
+}
+
+//----- (004D76ED) --------------------------------------------------------
+void __cdecl sr_sub_4D76ED(stru315 *a1, stru316 *a2)
+{
+  int v2; // ecx@1
+  unsigned int v3; // eax@2
+  int v4; // ecx@2
+  int v5; // eax@10
+  unsigned __int16 *v6; // edx@10
+  int v7; // ebx@11
+  int v8; // ecx@13
+  unsigned __int16 v9; // bx@16
+  int v10; // ecx@16
+  unsigned __int16 *v11; // eax@16
+  unsigned int *v12; // edx@16
+  int v13; // ecx@16
+  int v14; // eax@16
+  int v15; // ebx@16
+  int v16; // [sp-4h] [bp-Ch]@2
+
+  v2 = a1->field_28;
+  if ( v2 )
+  {
+    do
+    {
+      v16 = v2;
+      v3 = a1->field_30;
+      v4 = a1->field_2C;
+      if ( (signed int)v3 >= a1->field_18 )
+        v3 = a1->field_18;
+      if ( (signed int)v3 <= a1->field_14 )
+        v3 = a1->field_14;
+      if ( v4 >= a1->field_20 )
+        v4 = a1->field_20;
+      if ( v4 <= a1->field_1C )
+        v4 = a1->field_1C;
+      v5 = *((char *)a1->pTextureLOD + (a1->field_C & (v3 >> 16)) + (((unsigned int)v4 & a1->field_8) >> a1->field_10));
+      v6 = a1->field_34_palette;
+      if ( a2->field_20 )
+      {
+        v7 = (unsigned int)a2->field_14 >> 16;
+        if ( v7 >= a2->field_C )
+          v7 = a2->field_C;
+        v8 = 0;
+        if ( a2->field_8 - v7 >= 0 )
+          v8 = a2->field_8 - v7;
+        v5 += v8 << 8;
+        v6 = a2->field_24_palette;
+      }
+      v9 = v6[v5];
+      v10 = a1->field_24;
+      v11 = a1->pColorBuffer;
+      v12 = a1->pDepthBuffer;
+      *v11 = v9;
+      *v12 = v10;
+      a1->pColorBuffer = v11 - 1;
+      a1->pDepthBuffer = v12 - 1;
+      v13 = a1->field_30;
+      a2->field_14 -= a2->field_18;
+      v14 = a1->field_2C;
+      v15 = a1->field_0;
+      a1->field_30 = a1->field_4 + v13;
+      a1->field_2C = v15 + v14;
+      v2 = v16 - 1;
+    }
+    while ( v16 != 1 );
+  }
+}
+
+//----- (004D77D2) --------------------------------------------------------
+void __cdecl sr_sub_4D77D2(stru315 *a1, stru316 *a2)
+{
+  int v2; // ecx@1
+  unsigned __int16 *v3; // ebx@2
+  int v4; // eax@2
+  unsigned __int16 *v5; // edx@2
+  int v6; // ebx@4
+  int v7; // ecx@6
+  unsigned __int16 v8; // bx@9
+  int v9; // ecx@9
+  unsigned int *v10; // edx@9
+  unsigned int *v11; // edx@10
+  int v12; // ecx@10
+  int v13; // eax@10
+  int v14; // ebx@10
+  int v15; // [sp-4h] [bp-Ch]@2
+
+  v2 = a1->field_28;
+  if ( v2 )
+  {
+    do
+    {
+      v15 = v2;
+      v3 = a1->pTextureLOD;
+      v4 = *((char *)v3
+           + (a1->field_C & ((unsigned int)a1->field_30 >> 16))
+           + ((unsigned int)(a1->field_2C & a1->field_8) >> a1->field_10));
+      v5 = a1->field_34_palette;
+      if ( *((char *)v3
+           + (a1->field_C & ((unsigned int)a1->field_30 >> 16))
+           + ((unsigned int)(a1->field_2C & a1->field_8) >> a1->field_10)) )
+      {
+        if ( a2->field_20 )
+        {
+          v6 = (unsigned int)a2->field_10 >> 16;
+          if ( v6 >= a2->field_C )
+            v6 = a2->field_C;
+          v7 = 0;
+          if ( a2->field_8 - v6 >= 0 )
+            v7 = a2->field_8 - v6;
+          v4 += v7 << 8;
+          v5 = a2->field_24_palette;
+        }
+        v8 = v5[v4];
+        v9 = a1->field_24;
+        v10 = a1->pDepthBuffer;
+        *a1->pColorBuffer = v8;
+        *v10 = v9;
+      }
+      v11 = a1->pDepthBuffer + 1;
+      ++a1->pColorBuffer;
+      a1->pDepthBuffer = v11;
+      v12 = a1->field_30;
+      a2->field_10 += a2->field_18;
+      v13 = a1->field_2C;
+      v14 = a1->field_0;
+      a1->field_30 = a1->field_4 + v12;
+      a1->field_2C = v14 + v13;
+      v2 = v15 - 1;
+    }
+    while ( v15 != 1 );
+  }
+}
+
+//----- (004D789A) --------------------------------------------------------
+void __cdecl sr_sub_4D789A(stru315 *a1, stru316 *a2)
+{
+  int v2; // ecx@1
+  unsigned int v3; // eax@2
+  int v4; // ecx@2
+  int v5; // eax@10
+  unsigned __int16 *v6; // edx@10
+  int v7; // ebx@12
+  int v8; // ecx@14
+  unsigned __int16 v9; // bx@17
+  int v10; // ecx@17
+  unsigned int *v11; // edx@17
+  unsigned int *v12; // edx@18
+  int v13; // ecx@18
+  int v14; // eax@18
+  int v15; // ebx@18
+  int v16; // [sp-4h] [bp-Ch]@2
+
+  v2 = a1->field_28;
+  if ( v2 )
+  {
+    do
+    {
+      v16 = v2;
+      v3 = a1->field_30;
+      v4 = a1->field_2C;
+      if ( (signed int)v3 >= a1->field_18 )
+        v3 = a1->field_18;
+      if ( (signed int)v3 <= a1->field_14 )
+        v3 = a1->field_14;
+      if ( v4 >= a1->field_20 )
+        v4 = a1->field_20;
+      if ( v4 <= a1->field_1C )
+        v4 = a1->field_1C;
+      v5 = *((char *)a1->pTextureLOD + (a1->field_C & (v3 >> 16)) + (((unsigned int)v4 & a1->field_8) >> a1->field_10));
+      v6 = a1->field_34_palette;
+      if ( v5 )
+      {
+        if ( a2->field_20 )
+        {
+          v7 = (unsigned int)a2->field_10 >> 16;
+          if ( v7 >= a2->field_C )
+            v7 = a2->field_C;
+          v8 = 0;
+          if ( a2->field_8 - v7 >= 0 )
+            v8 = a2->field_8 - v7;
+          v5 += v8 << 8;
+          v6 = a2->field_24_palette;
+        }
+        v9 = v6[v5];
+        v10 = a1->field_24;
+        v11 = a1->pDepthBuffer;
+        *a1->pColorBuffer = v9;
+        *v11 = v10;
+      }
+      v12 = a1->pDepthBuffer + 1;
+      ++a1->pColorBuffer;
+      a1->pDepthBuffer = v12;
+      v13 = a1->field_30;
+      a2->field_10 += a2->field_18;
+      v14 = a1->field_2C;
+      v15 = a1->field_0;
+      a1->field_30 = a1->field_4 + v13;
+      a1->field_2C = v15 + v14;
+      v2 = v16 - 1;
+    }
+    while ( v16 != 1 );
+  }
+}
+
+
+
+
+//----- (00451007) --------------------------------------------------------
+int stru350::sub_451007_scale_image_bicubic(unsigned short *pSrc, int srcWidth, int srcHeight, int srcPitch,
+                                            unsigned short *pDst, int dstWidth, int dstHeight, int dstPitch,
+                                            int a10, int a11)
+{
+  int v11; // esi@1
+  int result; // eax@1
+  int v13; // edi@8
+  int v14; // ecx@10
+  double v15; // st7@11
+  double v16; // st6@11
+  float v17; // ST3C_4@12
+  float v18; // ST38_4@12
+  unsigned int v19; // esi@12
+  int v20; // eax@16
+  int v21; // eax@18
+  unsigned int v22; // ecx@25
+  unsigned int v23; // eax@29
+  unsigned __int16 *v24; // ecx@29
+  int v25; // edi@33
+  int v26; // ecx@35
+  double v27; // st7@36
+  double v28; // st6@36
+  float v29; // ST34_4@37
+  float v30; // ST30_4@37
+  unsigned int v31; // esi@37
+  int v32; // eax@41
+  int v33; // eax@43
+  unsigned int v34; // ecx@50
+  unsigned __int16 v35; // ax@54
+  unsigned __int16 *v36; // ecx@54
+  int v37; // edi@58
+  int v38; // ecx@60
+  double v39; // st7@61
+  double v40; // st6@61
+  float v41; // ST34_4@62
+  float v42; // ST30_4@62
+  unsigned int v43; // esi@62
+  int v44; // eax@66
+  int v45; // eax@68
+  unsigned int v46; // ecx@75
+  char v47; // al@79
+  unsigned __int16 *v48; // ecx@79
+  int v49; // edi@86
+  int v50; // ecx@88
+  double v51; // st7@89
+  double v52; // st6@89
+  float v53; // ST34_4@90
+  float v54; // ST30_4@90
+  unsigned int v55; // esi@90
+  int v56; // eax@94
+  int v57; // eax@96
+  unsigned int v58; // ecx@103
+  unsigned int v59; // eax@107
+  unsigned __int16 *v60; // ecx@107
+  int v61; // edi@111
+  int v62; // ecx@113
+  double v63; // st7@114
+  double v64; // st6@114
+  float v65; // ST34_4@115
+  float v66; // ST30_4@115
+  unsigned int v67; // esi@115
+  int v68; // eax@119
+  int v69; // eax@121
+  unsigned int v70; // ecx@128
+  unsigned __int16 v71; // ax@132
+  unsigned __int16 *v72; // ecx@132
+  int v73; // edi@136
+  int v74; // ecx@138
+  double v75; // st7@139
+  double v76; // st6@139
+  float v77; // ST34_4@140
+  float v78; // ST30_4@140
+  unsigned int v79; // esi@140
+  int v80; // eax@144
+  int v81; // eax@146
+  unsigned int v82; // ecx@153
+  char v83; // al@157
+  unsigned __int16 *v84; // ecx@157
+  int v85; // edi@164
+  int v86; // ecx@166
+  double v87; // st7@167
+  double v88; // st6@167
+  float v89; // ST34_4@168
+  float v90; // ST30_4@168
+  unsigned int v91; // esi@168
+  signed int v92; // eax@170
+  int v93; // eax@171
+  int v94; // eax@173
+  unsigned int v95; // ecx@181
+  unsigned int v96; // eax@185
+  unsigned __int16 *v97; // ecx@185
+  int v98; // edi@189
+  int v99; // ecx@191
+  double v100; // st7@192
+  double v101; // st6@192
+  float v102; // ST34_4@193
+  float v103; // ST30_4@193
+  unsigned int v104; // esi@193
+  signed int v105; // eax@195
+  int v106; // eax@196
+  int v107; // eax@198
+  unsigned int v108; // ecx@206
+  unsigned __int16 v109; // ax@210
+  unsigned __int16 *v110; // ecx@210
+  int v111; // edi@214
+  int v112; // ecx@216
+  double v113; // st7@217
+  double v114; // st6@217
+  float v115; // ST34_4@218
+  float v116; // ST30_4@218
+  unsigned int v117; // esi@218
+  signed int v118; // eax@220
+  int v119; // eax@221
+  int v120; // eax@223
+  unsigned int v121; // ecx@231
+  char v122; // al@235
+  unsigned __int16 *v123; // ecx@235
+  double v124; // [sp+Ch] [bp-7Ch]@12
+  double v125; // [sp+Ch] [bp-7Ch]@37
+  double v126; // [sp+Ch] [bp-7Ch]@62
+  double v127; // [sp+Ch] [bp-7Ch]@90
+  //double v128; // [sp+Ch] [bp-7Ch]@115
+  uint _v128;
+  double v129; // [sp+Ch] [bp-7Ch]@140
+  double v130; // [sp+Ch] [bp-7Ch]@168
+  double v131; // [sp+Ch] [bp-7Ch]@193
+  double v132; // [sp+Ch] [bp-7Ch]@218
+  double v133; // [sp+14h] [bp-74h]@12
+  double v134; // [sp+14h] [bp-74h]@37
+  double v135; // [sp+14h] [bp-74h]@62
+  double v136; // [sp+14h] [bp-74h]@90
+  //double v137; // [sp+14h] [bp-74h]@115
+  uint _v137;
+  double v138; // [sp+14h] [bp-74h]@140
+  double v139; // [sp+14h] [bp-74h]@168
+  double v140; // [sp+14h] [bp-74h]@193
+  double v141; // [sp+14h] [bp-74h]@218
+  double v142; // [sp+1Ch] [bp-6Ch]@12
+  double v143; // [sp+1Ch] [bp-6Ch]@37
+  double v144; // [sp+1Ch] [bp-6Ch]@62
+  double v145; // [sp+1Ch] [bp-6Ch]@90
+  //double v146; // [sp+1Ch] [bp-6Ch]@115
+  uint _v146;
+  double v147; // [sp+1Ch] [bp-6Ch]@140
+  double v148; // [sp+1Ch] [bp-6Ch]@168
+  double v149; // [sp+1Ch] [bp-6Ch]@193
+  double v150; // [sp+1Ch] [bp-6Ch]@218
+  double v151; // [sp+24h] [bp-64h]@12
+  double v152; // [sp+24h] [bp-64h]@37
+  double v153; // [sp+24h] [bp-64h]@62
+  double v154; // [sp+24h] [bp-64h]@90
+  //double v155; // [sp+24h] [bp-64h]@115
+  uint _v155;
+  double v156; // [sp+24h] [bp-64h]@140
+  double v157; // [sp+24h] [bp-64h]@168
+  double v158; // [sp+24h] [bp-64h]@193
+  double v159; // [sp+24h] [bp-64h]@218
+  int v160; // [sp+3Ch] [bp-4Ch]@13
+  int v161; // [sp+40h] [bp-48h]@15
+  int v162; // [sp+44h] [bp-44h]@40
+  int v163; // [sp+44h] [bp-44h]@65
+  int v164; // [sp+44h] [bp-44h]@93
+  int v165; // [sp+44h] [bp-44h]@118
+  int v166; // [sp+44h] [bp-44h]@143
+  int v167; // [sp+44h] [bp-44h]@169
+  int v168; // [sp+44h] [bp-44h]@194
+  int v169; // [sp+44h] [bp-44h]@219
+  int v170; // [sp+48h] [bp-40h]@38
+  int v171; // [sp+48h] [bp-40h]@63
+  int v172; // [sp+48h] [bp-40h]@91
+  int v173; // [sp+48h] [bp-40h]@116
+  int v174; // [sp+48h] [bp-40h]@141
+  unsigned __int16 *v175; // [sp+4Ch] [bp-3Ch]@13
+  int *v176; // [sp+50h] [bp-38h]@15
+  int *v177; // [sp+50h] [bp-38h]@40
+  int *v178; // [sp+50h] [bp-38h]@65
+  int *v179; // [sp+50h] [bp-38h]@93
+  int *v180; // [sp+50h] [bp-38h]@118
+  int *v181; // [sp+50h] [bp-38h]@143
+  char *v182; // [sp+50h] [bp-38h]@169
+  char *v183; // [sp+50h] [bp-38h]@194
+  char *v184; // [sp+50h] [bp-38h]@219
+  unsigned __int16 *v185; // [sp+54h] [bp-34h]@38
+  unsigned __int16 *v186; // [sp+54h] [bp-34h]@63
+  unsigned __int16 *v187; // [sp+54h] [bp-34h]@91
+  unsigned __int16 *v188; // [sp+54h] [bp-34h]@116
+  unsigned __int16 *v189; // [sp+54h] [bp-34h]@141
+  signed int v190; // [sp+54h] [bp-34h]@170
+  signed int v191; // [sp+54h] [bp-34h]@195
+  signed int v192; // [sp+54h] [bp-34h]@220
+  unsigned __int16 *v193; // [sp+5Ch] [bp-2Ch]@7
+  unsigned __int16 *v194; // [sp+5Ch] [bp-2Ch]@32
+  unsigned __int16 *v195; // [sp+5Ch] [bp-2Ch]@57
+  unsigned __int16 *v196; // [sp+5Ch] [bp-2Ch]@85
+  unsigned __int16 *v197; // [sp+5Ch] [bp-2Ch]@110
+  unsigned __int16 *v198; // [sp+5Ch] [bp-2Ch]@135
+  unsigned __int16 *v199; // [sp+5Ch] [bp-2Ch]@163
+  unsigned __int16 *v200; // [sp+5Ch] [bp-2Ch]@188
+  unsigned __int16 *v201; // [sp+5Ch] [bp-2Ch]@213
+  //stru350 *v202; // [sp+60h] [bp-28h]@1
+  int v203; // [sp+64h] [bp-24h]@12
+  int v204; // [sp+64h] [bp-24h]@37
+  int v205; // [sp+64h] [bp-24h]@62
+  int v206; // [sp+64h] [bp-24h]@90
+  int v207; // [sp+64h] [bp-24h]@115
+  int v208; // [sp+64h] [bp-24h]@140
+  int v209; // [sp+64h] [bp-24h]@168
+  int v210; // [sp+64h] [bp-24h]@193
+  int v211; // [sp+64h] [bp-24h]@218
+  float v212; // [sp+6Ch] [bp-1Ch]@11
+  float v213; // [sp+6Ch] [bp-1Ch]@36
+  float v214; // [sp+6Ch] [bp-1Ch]@61
+  float v215; // [sp+6Ch] [bp-1Ch]@89
+  float v216; // [sp+6Ch] [bp-1Ch]@114
+  float v217; // [sp+6Ch] [bp-1Ch]@139
+  float v218; // [sp+6Ch] [bp-1Ch]@167
+  float v219; // [sp+6Ch] [bp-1Ch]@192
+  float v220; // [sp+6Ch] [bp-1Ch]@217
+  float v221; // [sp+70h] [bp-18h]@11
+  float v222; // [sp+70h] [bp-18h]@36
+  float v223; // [sp+70h] [bp-18h]@61
+  float v224; // [sp+70h] [bp-18h]@89
+  float v225; // [sp+70h] [bp-18h]@114
+  float v226; // [sp+70h] [bp-18h]@139
+  float v227; // [sp+70h] [bp-18h]@167
+  float v228; // [sp+70h] [bp-18h]@192
+  float v229; // [sp+70h] [bp-18h]@217
+  signed int v230; // [sp+74h] [bp-14h]@1
+  signed int v231; // [sp+78h] [bp-10h]@7
+  signed int v232; // [sp+78h] [bp-10h]@32
+  signed int v233; // [sp+78h] [bp-10h]@57
+  signed int v234; // [sp+78h] [bp-10h]@85
+  signed int v235; // [sp+78h] [bp-10h]@110
+  signed int v236; // [sp+78h] [bp-10h]@135
+  signed int v237; // [sp+78h] [bp-10h]@163
+  signed int v238; // [sp+78h] [bp-10h]@188
+  signed int v239; // [sp+78h] [bp-10h]@213
+  __int64 v240; // [sp+7Ch] [bp-Ch]@12
+  __int64 v241; // [sp+7Ch] [bp-Ch]@37
+  __int64 v242; // [sp+7Ch] [bp-Ch]@62
+  __int64 v243; // [sp+7Ch] [bp-Ch]@90
+  __int64 v244; // [sp+7Ch] [bp-Ch]@115
+  __int64 v245; // [sp+7Ch] [bp-Ch]@140
+  unsigned int v246; // [sp+7Ch] [bp-Ch]@168
+  unsigned int v247; // [sp+7Ch] [bp-Ch]@193
+  unsigned int v248; // [sp+7Ch] [bp-Ch]@218
+  unsigned int v249; // [sp+80h] [bp-8h]@168
+  unsigned int v250; // [sp+80h] [bp-8h]@193
+  unsigned int v251; // [sp+80h] [bp-8h]@218
+  unsigned int v252; // [sp+84h] [bp-4h]@12
+  unsigned int v253; // [sp+84h] [bp-4h]@37
+  unsigned int v254; // [sp+84h] [bp-4h]@62
+  unsigned int v255; // [sp+84h] [bp-4h]@90
+  unsigned int v256; // [sp+84h] [bp-4h]@115
+  unsigned int v257; // [sp+84h] [bp-4h]@140
+  unsigned int v258; // [sp+84h] [bp-4h]@168
+  unsigned int v259; // [sp+84h] [bp-4h]@193
+  unsigned int v260; // [sp+84h] [bp-4h]@218
+  signed int a6a; // [sp+A0h] [bp+18h]@10
+  float a6s; // [sp+A0h] [bp+18h]@12
+  float a6t; // [sp+A0h] [bp+18h]@12
+  unsigned int a6b; // [sp+A0h] [bp+18h]@12
+  signed int a6c; // [sp+A0h] [bp+18h]@35
+  float a6u; // [sp+A0h] [bp+18h]@37
+  float a6v; // [sp+A0h] [bp+18h]@37
+  unsigned int a6d; // [sp+A0h] [bp+18h]@37
+  signed int a6e; // [sp+A0h] [bp+18h]@60
+  float a6w; // [sp+A0h] [bp+18h]@62
+  float a6x; // [sp+A0h] [bp+18h]@62
+  unsigned int a6f; // [sp+A0h] [bp+18h]@62
+  signed int a6g; // [sp+A0h] [bp+18h]@88
+  float a6y; // [sp+A0h] [bp+18h]@90
+  float a6z; // [sp+A0h] [bp+18h]@90
+  unsigned int a6h; // [sp+A0h] [bp+18h]@90
+  signed int a6i; // [sp+A0h] [bp+18h]@113
+  float a6ba; // [sp+A0h] [bp+18h]@115
+  float a6bb; // [sp+A0h] [bp+18h]@115
+  unsigned int a6j; // [sp+A0h] [bp+18h]@115
+  signed int a6k; // [sp+A0h] [bp+18h]@138
+  float a6bc; // [sp+A0h] [bp+18h]@140
+  float a6bd; // [sp+A0h] [bp+18h]@140
+  unsigned int a6l; // [sp+A0h] [bp+18h]@140
+  signed int a6m; // [sp+A0h] [bp+18h]@166
+  float a6be; // [sp+A0h] [bp+18h]@168
+  float a6bf; // [sp+A0h] [bp+18h]@168
+  unsigned int a6n; // [sp+A0h] [bp+18h]@168
+  signed int a6o; // [sp+A0h] [bp+18h]@191
+  float a6bg; // [sp+A0h] [bp+18h]@193
+  float a6bh; // [sp+A0h] [bp+18h]@193
+  unsigned int a6p; // [sp+A0h] [bp+18h]@193
+  signed int a6q; // [sp+A0h] [bp+18h]@216
+  float a6bi; // [sp+A0h] [bp+18h]@218
+  float a6bj; // [sp+A0h] [bp+18h]@218
+  unsigned int a6r; // [sp+A0h] [bp+18h]@218
+  int a9a; // [sp+ACh] [bp+24h]@8
+  int a9b; // [sp+ACh] [bp+24h]@33
+  int a9c; // [sp+ACh] [bp+24h]@86
+  int a9d; // [sp+ACh] [bp+24h]@111
+  int a9e; // [sp+ACh] [bp+24h]@164
+  int a9f; // [sp+ACh] [bp+24h]@189
+
+  v11 = 0;
+  result = this->field_0.field_C;
+  //v202 = this;
+  v230 = 0;
+  if ( result != 8 )
+  {
+    if ( result != 16 )
+    {
+      if ( result != 32 )
+        return result;
+      result = this->field_20.field_C;
+      if ( result != 8 )
+      {
+        if ( result != 16 )
+        {
+          if ( result != 32 || (result = (int)pDst, v193 = pDst, v231 = 0, dstHeight <= 0) )
+            return result;
+          v13 = dstWidth;
+          a9a = 4 * (dstPitch - dstWidth);
+          while ( 1 )
+          {
+            v14 = 0;
+            a6a = 0;
+            if ( dstWidth > v11 )
+              break;
+LABEL_30:
+            v193 = (unsigned __int16 *)((char *)v193 + a9a);
+            ++v231;
+            result = v231;
+            if ( v231 >= dstHeight )
+              return result;
+            v11 = 0;
+          }
+          v221 = (double)dstWidth;
+          v212 = (double)srcWidth;
+          v15 = (double)dstHeight;
+          v16 = (double)srcHeight;
+          while ( 1 )
+          {
+            a6s = (double)a6a / v221 * v212;
+            v151 = floorf(a6s + 0.5f);//a6s + 6.7553994e15;
+            v203 = v14 + 1;
+            a6t = (double)(v14 + 1) / v221 * v212;
+            v142 = floorf(a6t + 0.5f);//a6t + 6.7553994e15;
+            v17 = (double)v231 / v15 * v16;
+            v133 = floorf(v17 + 0.5f);//v17 + 6.7553994e15;
+            v18 = (double)(v231 + 1) / v15 * v16;
+            v124 = floorf(v18 + 0.5f);//v18 + 6.7553994e15;
+            v19 = (LODWORD(v124) - LODWORD(v133)) * (LODWORD(v142) - LODWORD(v151));
+            v252 = 0;
+            a6b = 0;
+            v240 = 0i64;
+            if ( SLODWORD(v133) < SLODWORD(v124) )
+              break;
+LABEL_25:
+            v22 = (unsigned int)v240 / ((LODWORD(v124) - LODWORD(v133)) * (LODWORD(v142) - LODWORD(v151)));
+            if ( v19 )
+            {
+              a6b /= v19;
+              v252 /= v19;
+              HIDWORD(v240) /= v19;
+            }
+            if ( v22 != 255 )
+              v22 &= 0x7FFFFFFFu;
+            v23 = _450F55(HIDWORD(v240) | ((v252 | ((a6b | (v22 << 8)) << 8)) << 8));
+            v24 = v193;
+            v193 += 2;
+            *(_DWORD *)v24 = v23;
+            v14 = v203;
+            a6a = v203;
+            if ( v203 >= dstWidth )
+              goto LABEL_30;
+          }
+          v160 = LODWORD(v124) - LODWORD(v133);
+          v175 = &pSrc[2 * (LODWORD(v151) + srcPitch * LODWORD(v133))];
+          while ( SLODWORD(v151) >= SLODWORD(v142) )
+          {
+LABEL_24:
+            v175 += 2 * srcPitch;
+            --v160;
+            if ( !v160 )
+              goto LABEL_25;
+          }
+          v176 = (int *)v175;
+          v161 = LODWORD(v142) - LODWORD(v151);
+          while ( 1 )
+          {
+            v20 = *v176;
+            if ( a10 )
+            {
+              v230 = 1;
+              v13 = v20 != a11 ? 0xFF : 0;
+            }
+            v21 = _450FB1(v20);
+            if ( !v230 )
+              break;
+            LODWORD(v240) = v13 + v240;
+            v230 = 0;
+            if ( v13 )
+              goto LABEL_22;
+            --v19;
+LABEL_23:
+            ++v176;
+            --v161;
+            if ( !v161 )
+              goto LABEL_24;
+          }
+          LODWORD(v240) = ((unsigned int)v21 >> 24) + v240;
+LABEL_22:
+          a6b += BYTE2(v21);
+          v252 += BYTE1(v21);
+          HIDWORD(v240) += (unsigned __int8)v21;
+          goto LABEL_23;
+        }
+        result = (int)pDst;
+        v194 = pDst;
+        v232 = 0;
+        if ( dstHeight <= 0 )
+          return result;
+        v25 = dstWidth;
+        a9b = 2 * (dstPitch - dstWidth);
+        while ( 1 )
+        {
+          v26 = 0;
+          a6c = 0;
+          if ( dstWidth > v11 )
+            break;
+LABEL_55:
+          v194 = (unsigned __int16 *)((char *)v194 + a9b);
+          ++v232;
+          result = v232;
+          if ( v232 >= dstHeight )
+            return result;
+          v11 = 0;
+        }
+        v222 = (double)dstWidth;
+        v213 = (double)srcWidth;
+        v27 = (double)dstHeight;
+        v28 = (double)srcHeight;
+        while ( 1 )
+        {
+          a6u = (double)a6c / v222 * v213;
+          v125 = a6u + 6.7553994e15;
+          v204 = v26 + 1;
+          a6v = (double)(v26 + 1) / v222 * v213;
+          v134 = a6v + 6.7553994e15;
+          v29 = (double)v232 / v27 * v28;
+          v143 = v29 + 6.7553994e15;
+          v30 = (double)(v232 + 1) / v27 * v28;
+          v152 = v30 + 6.7553994e15;
+          v31 = (LODWORD(v152) - LODWORD(v143)) * (LODWORD(v134) - LODWORD(v125));
+          v253 = 0;
+          a6d = 0;
+          v241 = 0i64;
+          if ( SLODWORD(v143) < SLODWORD(v152) )
+            break;
+LABEL_50:
+          v34 = (unsigned int)v241 / ((LODWORD(v152) - LODWORD(v143)) * (LODWORD(v134) - LODWORD(v125)));
+          if ( v31 )
+          {
+            a6d /= v31;
+            v253 /= v31;
+            HIDWORD(v241) /= v31;
+          }
+          if ( v34 != 255 )
+            v34 &= 0x7FFFFFFFu;
+          v35 = _450F55(HIDWORD(v241) | ((v253 | ((a6d | (v34 << 8)) << 8)) << 8));
+          v36 = v194;
+          ++v194;
+          *v36 = v35;
+          v26 = v204;
+          a6c = v204;
+          if ( v204 >= dstWidth )
+            goto LABEL_55;
+        }
+        v170 = LODWORD(v152) - LODWORD(v143);
+        v185 = &pSrc[2 * (LODWORD(v125) + srcPitch * LODWORD(v143))];
+        while ( SLODWORD(v125) >= SLODWORD(v134) )
+        {
+LABEL_49:
+          v185 += 2 * srcPitch;
+          --v170;
+          if ( !v170 )
+            goto LABEL_50;
+        }
+        v177 = (int *)v185;
+        v162 = LODWORD(v134) - LODWORD(v125);
+        while ( 1 )
+        {
+          v32 = *v177;
+          if ( a10 )
+          {
+            v230 = 1;
+            v25 = v32 != a11 ? 0xFF : 0;
+          }
+          v33 = _450FB1(v32);
+          if ( !v230 )
+            break;
+          LODWORD(v241) = v25 + v241;
+          v230 = 0;
+          if ( v25 )
+            goto LABEL_47;
+          --v31;
+LABEL_48:
+          ++v177;
+          --v162;
+          if ( !v162 )
+            goto LABEL_49;
+        }
+        LODWORD(v241) = ((unsigned int)v33 >> 24) + v241;
+LABEL_47:
+        a6d += BYTE2(v33);
+        v253 += BYTE1(v33);
+        HIDWORD(v241) += (unsigned __int8)v33;
+        goto LABEL_48;
+      }
+      result = (int)pDst;
+      v195 = pDst;
+      v233 = 0;
+      if ( dstHeight <= 0 )
+        return result;
+      v37 = dstWidth;
+      while ( 1 )
+      {
+        v38 = 0;
+        a6e = 0;
+        if ( dstWidth > v11 )
+          break;
+LABEL_80:
+        v195 = (unsigned __int16 *)((char *)v195 + dstPitch - dstWidth);
+        ++v233;
+        result = v233;
+        if ( v233 >= dstHeight )
+          return result;
+        v11 = 0;
+      }
+      v223 = (double)dstWidth;
+      v214 = (double)srcWidth;
+      v39 = (double)dstHeight;
+      v40 = (double)srcHeight;
+      while ( 1 )
+      {
+        a6w = (double)a6e / v223 * v214;
+        v126 = a6w + 6.7553994e15;
+        v205 = v38 + 1;
+        a6x = (double)(v38 + 1) / v223 * v214;
+        v135 = a6x + 6.7553994e15;
+        v41 = (double)v233 / v39 * v40;
+        v144 = v41 + 6.7553994e15;
+        v42 = (double)(v233 + 1) / v39 * v40;
+        v153 = v42 + 6.7553994e15;
+        v43 = (LODWORD(v153) - LODWORD(v144)) * (LODWORD(v135) - LODWORD(v126));
+        v254 = 0;
+        a6f = 0;
+        v242 = 0i64;
+        if ( SLODWORD(v144) < SLODWORD(v153) )
+          break;
+LABEL_75:
+        v46 = (unsigned int)v242 / ((LODWORD(v153) - LODWORD(v144)) * (LODWORD(v135) - LODWORD(v126)));
+        if ( v43 )
+        {
+          a6f /= v43;
+          v254 /= v43;
+          HIDWORD(v242) /= v43;
+        }
+        if ( v46 != 255 )
+          v46 &= 0x7FFFFFFFu;
+        v47 = _450F55(HIDWORD(v242) | ((v254 | ((a6f | (v46 << 8)) << 8)) << 8));
+        v48 = v195;
+        v195 = (unsigned __int16 *)((char *)v195 + 1);
+        *(_BYTE *)v48 = v47;
+        v38 = v205;
+        a6e = v205;
+        if ( v205 >= dstWidth )
+          goto LABEL_80;
+      }
+      v171 = LODWORD(v153) - LODWORD(v144);
+      v186 = &pSrc[2 * (LODWORD(v126) + srcPitch * LODWORD(v144))];
+      while ( SLODWORD(v126) >= SLODWORD(v135) )
+      {
+LABEL_74:
+        v186 += 2 * srcPitch;
+        --v171;
+        if ( !v171 )
+          goto LABEL_75;
+      }
+      v178 = (int *)v186;
+      v163 = LODWORD(v135) - LODWORD(v126);
+      while ( 1 )
+      {
+        v44 = *v178;
+        if ( a10 )
+        {
+          v230 = 1;
+          v37 = v44 != a11 ? 0xFF : 0;
+        }
+        v45 = _450FB1(v44);
+        if ( !v230 )
+          break;
+        LODWORD(v242) = v37 + v242;
+        v230 = 0;
+        if ( v37 )
+          goto LABEL_72;
+        --v43;
+LABEL_73:
+        ++v178;
+        --v163;
+        if ( !v163 )
+          goto LABEL_74;
+      }
+      LODWORD(v242) = ((unsigned int)v45 >> 24) + v242;
+LABEL_72:
+      a6f += BYTE2(v45);
+      v254 += BYTE1(v45);
+      HIDWORD(v242) += (unsigned __int8)v45;
+      goto LABEL_73;
+    }
+    result = this->field_20.field_C;
+    if ( result != 8 )
+    {
+      if ( result != 16 )
+      {
+        if ( result != 32 || (result = (int)pDst, v196 = pDst, v234 = 0, dstHeight <= 0) )
+          return result;
+        v49 = dstWidth;
+        a9c = 4 * (dstPitch - dstWidth);
+        while ( 1 )
+        {
+          v50 = 0;
+          a6g = 0;
+          if ( dstWidth > v11 )
+            break;
+LABEL_108:
+          v196 = (unsigned __int16 *)((char *)v196 + a9c);
+          ++v234;
+          result = v234;
+          if ( v234 >= dstHeight )
+            return result;
+          v11 = 0;
+        }
+        v224 = (double)dstWidth;
+        v215 = (double)srcWidth;
+        v51 = (double)dstHeight;
+        v52 = (double)srcHeight;
+        while ( 1 )
+        {
+          a6y = (double)a6g / v224 * v215;
+          v127 = a6y + 6.7553994e15;
+          v206 = v50 + 1;
+          a6z = (double)(v50 + 1) / v224 * v215;
+          v136 = a6z + 6.7553994e15;
+          v53 = (double)v234 / v51 * v52;
+          v145 = v53 + 6.7553994e15;
+          v54 = (double)(v234 + 1) / v51 * v52;
+          v154 = v54 + 6.7553994e15;
+          v55 = (LODWORD(v154) - LODWORD(v145)) * (LODWORD(v136) - LODWORD(v127));
+          v255 = 0;
+          a6h = 0;
+          v243 = 0i64;
+          if ( SLODWORD(v145) < SLODWORD(v154) )
+            break;
+LABEL_103:
+          v58 = (unsigned int)v243 / ((LODWORD(v154) - LODWORD(v145)) * (LODWORD(v136) - LODWORD(v127)));
+          if ( v55 )
+          {
+            a6h /= v55;
+            v255 /= v55;
+            HIDWORD(v243) /= v55;
+          }
+          if ( v58 != 255 )
+            v58 &= 0x7FFFFFFFu;
+          v59 = _450F55(HIDWORD(v243) | ((v255 | ((a6h | (v58 << 8)) << 8)) << 8));
+          v60 = v196;
+          v196 += 2;
+          *(_DWORD *)v60 = v59;
+          v50 = v206;
+          a6g = v206;
+          if ( v206 >= dstWidth )
+            goto LABEL_108;
+        }
+        v172 = LODWORD(v154) - LODWORD(v145);
+        v187 = &pSrc[LODWORD(v127) + srcPitch * LODWORD(v145)];
+        while ( SLODWORD(v127) >= SLODWORD(v136) )
+        {
+LABEL_102:
+          v187 += srcPitch;
+          --v172;
+          if ( !v172 )
+            goto LABEL_103;
+        }
+        v179 = (int *)v187;
+        v164 = LODWORD(v136) - LODWORD(v127);
+        while ( 1 )
+        {
+          v56 = *(_WORD *)v179;
+          if ( a10 )
+          {
+            v230 = 1;
+            v49 = v56 != a11 ? 0xFF : 0;
+          }
+          v57 = _450FB1(v56);
+          if ( !v230 )
+            break;
+          LODWORD(v243) = v49 + v243;
+          v230 = 0;
+          if ( v49 )
+            goto LABEL_100;
+          --v55;
+LABEL_101:
+          v179 = (int *)((char *)v179 + 2);
+          --v164;
+          if ( !v164 )
+            goto LABEL_102;
+        }
+        LODWORD(v243) = ((unsigned int)v57 >> 24) + v243;
+LABEL_100:
+        a6h += BYTE2(v57);
+        v255 += BYTE1(v57);
+        HIDWORD(v243) += (unsigned __int8)v57;
+        goto LABEL_101;
+      }
+      result = (int)pDst;
+      v197 = pDst;
+      v235 = 0;
+      if ( dstHeight <= 0 )
+        return result;
+      v61 = dstWidth;
+      a9d = 2 * (dstPitch - dstWidth);
+      while ( 1 )
+      {
+        v62 = 0;
+        a6i = 0;
+        if ( dstWidth > v11 )
+          break;
+LABEL_133:
+        v197 = (unsigned __int16 *)((char *)v197 + a9d);
+        ++v235;
+        result = v235;
+        if ( v235 >= dstHeight )
+          return result;
+        v11 = 0;
+      }
+      v225 = (double)dstWidth;
+      v216 = (double)srcWidth;
+      v63 = (double)dstHeight;
+      v64 = (double)srcHeight;
+      while ( 1 )
+      {
+        a6ba = (double)a6i / v225 * v216;
+        _v128 = floorf(a6ba + 0.5f);
+        //v128 = a6ba + 6.7553994e15;
+        v207 = v62 + 1;
+        a6bb = (double)(v62 + 1) / v225 * v216;
+        //v137 = a6bb + 6.7553994e15;
+        _v137 = floorf(a6bb + 0.5f);
+        v65 = (double)v235 / v63 * v64;
+        //v146 = v65 + 6.7553994e15;
+        _v146 = floorf(v65 + 0.5f);
+        v66 = (double)(v235 + 1) / v63 * v64;
+        //v155 = v66 + 6.7553994e15;
+        _v155 = floorf(v66 + 0.5f);
+        //v67 = (LODWORD(v155) - LODWORD(v146)) * (LODWORD(v137) - LODWORD(v128));
+        v67 = (_v155 - _v146) * (_v137 - _v128);
+        v256 = 0;
+        a6j = 0;
+        v244 = 0i64;
+        //if ( SLODWORD(v146) < SLODWORD(v155) )
+        if (_v146 < _v155)
+          break;
+LABEL_128:
+        //v70 = (unsigned int)v244 / ((LODWORD(v155) - LODWORD(v146)) * (LODWORD(v137) - LODWORD(v128)));
+        v70 = (unsigned int)v244 / ((_v155 - _v146) * (_v137 - _v128));
+        if ( v67 )
+        {
+          a6j /= v67;
+          v256 /= v67;
+          HIDWORD(v244) /= v67;
+        }
+        if ( v70 != 255 )
+          v70 &= 0x7FFFFFFFu;
+        v71 = _450F55(HIDWORD(v244) | ((v256 | ((a6j | (v70 << 8)) << 8)) << 8));
+        v72 = v197;
+        ++v197;
+        *v72 = v71;
+        v62 = v207;
+        a6i = v207;
+        if ( v207 >= dstWidth )
+          goto LABEL_133;
+      }
+      //v173 = LODWORD(v155) - LODWORD(v146);
+      v173 = _v155 - _v146;
+      //v188 = &pSrc[LODWORD(v128) + srcPitch * LODWORD(v146)];
+      v188 = &pSrc[_v128 + srcPitch * _v146];
+      //while ( SLODWORD(v128) >= SLODWORD(v137) )
+      while (_v128 >= _v137)
+      {
+LABEL_127:
+        v188 += srcPitch;
+        --v173;
+        if ( !v173 )
+          goto LABEL_128;
+      }
+      v180 = (int *)v188;
+      //v165 = LODWORD(v137) - LODWORD(v128);
+      v165 = _v137 - _v128;
+      while ( 1 )
+      {
+        v68 = *(_WORD *)v180;
+        if ( a10 )
+        {
+          v230 = 1;
+          v61 = v68 != a11 ? 0xFF : 0;
+        }
+        v69 = _450FB1(v68);
+        if ( !v230 )
+          break;
+        LODWORD(v244) = v61 + v244;
+        v230 = 0;
+        if ( v61 )
+          goto LABEL_125;
+        --v67;
+LABEL_126:
+        v180 = (int *)((char *)v180 + 2);
+        --v165;
+        if ( !v165 )
+          goto LABEL_127;
+      }
+      LODWORD(v244) = ((unsigned int)v69 >> 24) + v244;
+LABEL_125:
+      a6j += BYTE2(v69);
+      v256 += BYTE1(v69);
+      HIDWORD(v244) += (unsigned __int8)v69;
+      goto LABEL_126;
+    }
+    result = (int)pDst;
+    v198 = pDst;
+    v236 = 0;
+    if ( dstHeight <= 0 )
+      return result;
+    v73 = dstWidth;
+    while ( 1 )
+    {
+      v74 = 0;
+      a6k = 0;
+      if ( dstWidth > v11 )
+        break;
+LABEL_158:
+      v198 = (unsigned __int16 *)((char *)v198 + dstPitch - dstWidth);
+      ++v236;
+      result = v236;
+      if ( v236 >= dstHeight )
+        return result;
+      v11 = 0;
+    }
+    v226 = (double)dstWidth;
+    v217 = (double)srcWidth;
+    v75 = (double)dstHeight;
+    v76 = (double)srcHeight;
+    while ( 1 )
+    {
+      a6bc = (double)a6k / v226 * v217;
+      v129 = a6bc + 6.7553994e15;
+      v208 = v74 + 1;
+      a6bd = (double)(v74 + 1) / v226 * v217;
+      v138 = a6bd + 6.7553994e15;
+      v77 = (double)v236 / v75 * v76;
+      v147 = v77 + 6.7553994e15;
+      v78 = (double)(v236 + 1) / v75 * v76;
+      v156 = v78 + 6.7553994e15;
+      v257 = 0;
+      v79 = (LODWORD(v156) - LODWORD(v147)) * (LODWORD(v138) - LODWORD(v129));
+      a6l = 0;
+      v245 = 0i64;
+      if ( SLODWORD(v147) < SLODWORD(v156) )
+        break;
+LABEL_153:
+      v82 = (unsigned int)v245 / ((LODWORD(v156) - LODWORD(v147)) * (LODWORD(v138) - LODWORD(v129)));
+      if ( v79 )
+      {
+        a6l /= v79;
+        v257 /= v79;
+        HIDWORD(v245) /= v79;
+      }
+      if ( v82 != 255 )
+        v82 &= 0x7FFFFFFFu;
+      v83 = _450F55(HIDWORD(v245) | ((v257 | ((a6l | (v82 << 8)) << 8)) << 8));
+      v84 = v198;
+      v198 = (unsigned __int16 *)((char *)v198 + 1);
+      *(_BYTE *)v84 = v83;
+      v74 = v208;
+      a6k = v208;
+      if ( v208 >= dstWidth )
+        goto LABEL_158;
+    }
+    v174 = LODWORD(v156) - LODWORD(v147);
+    v189 = &pSrc[LODWORD(v129) + srcPitch * LODWORD(v147)];
+    while ( SLODWORD(v129) >= SLODWORD(v138) )
+    {
+LABEL_152:
+      v189 += srcPitch;
+      --v174;
+      if ( !v174 )
+        goto LABEL_153;
+    }
+    v166 = LODWORD(v138) - LODWORD(v129);
+    v181 = (int *)v189;
+    while ( 1 )
+    {
+      v80 = *(_WORD *)v181;
+      if ( a10 )
+      {
+        v230 = 1;
+        v73 = v80 != a11 ? 0xFF : 0;
+      }
+      v81 = _450FB1(v80);
+      if ( !v230 )
+        break;
+      LODWORD(v245) = v73 + v245;
+      v230 = 0;
+      if ( v73 )
+        goto LABEL_150;
+      --v79;
+LABEL_151:
+      v181 = (int *)((char *)v181 + 2);
+      --v166;
+      if ( !v166 )
+        goto LABEL_152;
+    }
+    LODWORD(v245) = ((unsigned int)v81 >> 24) + v245;
+LABEL_150:
+    a6l += BYTE2(v81);
+    v257 += BYTE1(v81);
+    HIDWORD(v245) += (unsigned __int8)v81;
+    goto LABEL_151;
+  }
+  result = this->field_20.field_C;
+  if ( result == 8 )
+  {
+    result = (int)pDst;
+    v201 = pDst;
+    v239 = 0;
+    if ( dstHeight <= 0 )
+      return result;
+    v111 = dstWidth;
+    while ( 1 )
+    {
+      v112 = 0;
+      a6q = 0;
+      if ( dstWidth <= v11 )
+        goto LABEL_236;
+      v229 = (double)dstWidth;
+      v220 = (double)srcWidth;
+      v113 = (double)dstHeight;
+      v114 = (double)srcHeight;
+      do
+      {
+        a6bi = (double)a6q / v229 * v220;
+        v132 = a6bi + 6.7553994e15;
+        v211 = v112 + 1;
+        a6bj = (double)(v112 + 1) / v229 * v220;
+        v141 = a6bj + 6.7553994e15;
+        v115 = (double)v239 / v113 * v114;
+        v150 = v115 + 6.7553994e15;
+        v116 = (double)(v239 + 1) / v113 * v114;
+        v159 = v116 + 6.7553994e15;
+        v251 = 0;
+        v117 = (LODWORD(v159) - LODWORD(v150)) * (LODWORD(v141) - LODWORD(v132));
+        v260 = 0;
+        a6r = 0;
+        v248 = 0;
+        if ( SLODWORD(v150) >= SLODWORD(v159) )
+          goto LABEL_231;
+        v169 = LODWORD(v159) - LODWORD(v150);
+        v184 = (char *)pSrc + srcPitch * LODWORD(v150);
+        do
+        {
+          v118 = LODWORD(v132);
+          v192 = LODWORD(v132);
+          while ( v118 < SLODWORD(v141) )
+          {
+            v119 = (unsigned __int8)v184[v192];
+            if ( a10 )
+            {
+              v230 = 1;
+              v111 = v119 != a11 ? 0xFF : 0;
+            }
+            v120 = _450FB1(v119);
+            if ( v230 )
+            {
+              v248 += v111;
+              v230 = 0;
+              if ( !v111 )
+              {
+                --v117;
+                goto LABEL_228;
+              }
+            }
+            else
+            {
+              v248 += (unsigned int)v120 >> 24;
+            }
+            a6r += BYTE2(v120);
+            v260 += BYTE1(v120);
+            v251 += (unsigned __int8)v120;
+LABEL_228:
+            ++v192;
+            v118 = v192;
+          }
+          v184 += srcPitch;
+          --v169;
+        }
+        while ( v169 );
+LABEL_231:
+        v121 = v248 / ((LODWORD(v159) - LODWORD(v150)) * (LODWORD(v141) - LODWORD(v132)));
+        if ( v117 )
+        {
+          a6r /= v117;
+          v260 /= v117;
+          v251 /= v117;
+        }
+        if ( v121 != 255 )
+          v121 &= 0x7FFFFFFFu;
+        v122 = _450F55(v251 | ((v260 | ((a6r | (v121 << 8)) << 8)) << 8));
+        v123 = v201;
+        v201 = (unsigned __int16 *)((char *)v201 + 1);
+        *(_BYTE *)v123 = v122;
+        v112 = v211;
+        a6q = v211;
+      }
+      while ( v211 < dstWidth );
+LABEL_236:
+      v201 = (unsigned __int16 *)((char *)v201 + dstPitch - dstWidth);
+      ++v239;
+      result = v239;
+      if ( v239 >= dstHeight )
+        return result;
+      v11 = 0;
+    }
+  }
+  if ( result == 16 )
+  {
+    result = (int)pDst;
+    v200 = pDst;
+    v238 = 0;
+    if ( dstHeight <= 0 )
+      return result;
+    v98 = dstWidth;
+    a9f = 2 * (dstPitch - dstWidth);
+    while ( 1 )
+    {
+      v99 = 0;
+      a6o = 0;
+      if ( dstWidth <= v11 )
+        goto LABEL_211;
+      v228 = (double)dstWidth;
+      v219 = (double)srcWidth;
+      v100 = (double)dstHeight;
+      v101 = (double)srcHeight;
+      do
+      {
+        a6bg = (double)a6o / v228 * v219;
+        v131 = a6bg + 6.7553994e15;
+        v210 = v99 + 1;
+        a6bh = (double)(v99 + 1) / v228 * v219;
+        v140 = a6bh + 6.7553994e15;
+        v102 = (double)v238 / v100 * v101;
+        v149 = v102 + 6.7553994e15;
+        v103 = (double)(v238 + 1) / v100 * v101;
+        v158 = v103 + 6.7553994e15;
+        v250 = 0;
+        v104 = (LODWORD(v158) - LODWORD(v149)) * (LODWORD(v140) - LODWORD(v131));
+        v259 = 0;
+        a6p = 0;
+        v247 = 0;
+        if ( SLODWORD(v149) >= SLODWORD(v158) )
+          goto LABEL_206;
+        v168 = LODWORD(v158) - LODWORD(v149);
+        v183 = (char *)pSrc + srcPitch * LODWORD(v149);
+        do
+        {
+          v105 = LODWORD(v131);
+          v191 = LODWORD(v131);
+          while ( v105 < SLODWORD(v140) )
+          {
+            v106 = (unsigned __int8)v183[v191];
+            if ( a10 )
+            {
+              v230 = 1;
+              v98 = v106 != a11 ? 0xFF : 0;
+            }
+            v107 = _450FB1(v106);
+            if ( v230 )
+            {
+              v247 += v98;
+              v230 = 0;
+              if ( !v98 )
+              {
+                --v104;
+                goto LABEL_203;
+              }
+            }
+            else
+            {
+              v247 += (unsigned int)v107 >> 24;
+            }
+            a6p += BYTE2(v107);
+            v259 += BYTE1(v107);
+            v250 += (unsigned __int8)v107;
+LABEL_203:
+            ++v191;
+            v105 = v191;
+          }
+          v183 += srcPitch;
+          --v168;
+        }
+        while ( v168 );
+LABEL_206:
+        v108 = v247 / ((LODWORD(v158) - LODWORD(v149)) * (LODWORD(v140) - LODWORD(v131)));
+        if ( v104 )
+        {
+          a6p /= v104;
+          v259 /= v104;
+          v250 /= v104;
+        }
+        if ( v108 != 255 )
+          v108 &= 0x7FFFFFFFu;
+        v109 = _450F55(v250 | ((v259 | ((a6p | (v108 << 8)) << 8)) << 8));
+        v110 = v200;
+        ++v200;
+        *v110 = v109;
+        v99 = v210;
+        a6o = v210;
+      }
+      while ( v210 < dstWidth );
+LABEL_211:
+      v200 = (unsigned __int16 *)((char *)v200 + a9f);
+      ++v238;
+      result = v238;
+      if ( v238 >= dstHeight )
+        return result;
+      v11 = 0;
+    }
+  }
+  if ( result != 32 || (result = (int)pDst, v199 = pDst, v237 = 0, dstHeight <= 0) )
+    return result;
+  v85 = dstWidth;
+  a9e = 4 * (dstPitch - dstWidth);
+  while ( 2 )
+  {
+    v86 = 0;
+    a6m = 0;
+    if ( dstWidth <= v11 )
+      goto LABEL_186;
+    v227 = (double)dstWidth;
+    v218 = (double)srcWidth;
+    v87 = (double)dstHeight;
+    v88 = (double)srcHeight;
+    do
+    {
+      a6be = (double)a6m / v227 * v218;
+      v130 = a6be + 6.7553994e15;
+      v209 = v86 + 1;
+      a6bf = (double)(v86 + 1) / v227 * v218;
+      v139 = a6bf + 6.7553994e15;
+      v89 = (double)v237 / v87 * v88;
+      v148 = v89 + 6.7553994e15;
+      v90 = (double)(v237 + 1) / v87 * v88;
+      v157 = v90 + 6.7553994e15;
+      v249 = 0;
+      v91 = (LODWORD(v157) - LODWORD(v148)) * (LODWORD(v139) - LODWORD(v130));
+      v258 = 0;
+      a6n = 0;
+      v246 = 0;
+      if ( SLODWORD(v148) >= SLODWORD(v157) )
+        goto LABEL_181;
+      v167 = LODWORD(v157) - LODWORD(v148);
+      v182 = (char *)pSrc + srcPitch * LODWORD(v148);
+      do
+      {
+        v92 = LODWORD(v130);
+        v190 = LODWORD(v130);
+        while ( v92 < SLODWORD(v139) )
+        {
+          v93 = (unsigned __int8)v182[v190];
+          if ( a10 )
+          {
+            v230 = 1;
+            v85 = v93 != a11 ? 0xFF : 0;
+          }
+          v94 = _450FB1(v93);
+          if ( v230 )
+          {
+            v246 += v85;
+            v230 = 0;
+            if ( !v85 )
+            {
+              --v91;
+              goto LABEL_178;
+            }
+          }
+          else
+          {
+            v246 += (unsigned int)v94 >> 24;
+          }
+          a6n += BYTE2(v94);
+          v258 += BYTE1(v94);
+          v249 += (unsigned __int8)v94;
+LABEL_178:
+          ++v190;
+          v92 = v190;
+        }
+        v182 += srcPitch;
+        --v167;
+      }
+      while ( v167 );
+LABEL_181:
+      v95 = v246 / ((LODWORD(v157) - LODWORD(v148)) * (LODWORD(v139) - LODWORD(v130)));
+      if ( v91 )
+      {
+        a6n /= v91;
+        v258 /= v91;
+        v249 /= v91;
+      }
+      if ( v95 != 255 )
+        v95 &= 0x7FFFFFFFu;
+      v96 = _450F55(v249 | ((v258 | ((a6n | (v95 << 8)) << 8)) << 8));
+      v97 = v199;
+      v199 += 2;
+      *(_DWORD *)v97 = v96;
+      v86 = v209;
+      a6m = v209;
+    }
+    while ( v209 < dstWidth );
+LABEL_186:
+    v199 = (unsigned __int16 *)((char *)v199 + a9e);
+    ++v237;
+    result = v237;
+    if ( v237 < dstHeight )
+    {
+      v11 = 0;
+      continue;
+    }
+    return result;
+  }
+}
+
+
+
+
+
+
+
+//----- (0044E1EC) --------------------------------------------------------
+int TextureFrameTable::FromFileTxt(const char *Args)
+{
+  TextureFrameTable *v2; // ebx@1
+  FILE *v3; // eax@1
+  int v4; // esi@3
+  const void *v5; // ST0C_4@10
+  void *v6; // eax@10
+  FILE *v7; // ST0C_4@12
+  char *i; // eax@12
+  signed int v9; // esi@15
+  int v10; // eax@17
+  int v11; // edx@22
+  int v12; // ecx@23
+  int v13; // eax@24
+  signed int j; // eax@27
+  TextureFrame *v15; // edx@28
+  int v16; // esi@28
+  int k; // ecx@29
+  char Buf; // [sp+Ch] [bp-2F8h]@3
+  FrameTableTxtLine v20; // [sp+200h] [bp-104h]@4
+  int v21; // [sp+27Ch] [bp-88h]@4
+  char *Str1; // [sp+280h] [bp-84h]@5
+  char *Str; // [sp+284h] [bp-80h]@15
+  int v24; // [sp+2F8h] [bp-Ch]@3
+  int v25; // [sp+2FCh] [bp-8h]@3
+  FILE *File; // [sp+300h] [bp-4h]@1
+  int Argsa; // [sp+30Ch] [bp+8h]@28
+
+  v2 = this;
+  v3 = fopen(Args, "r");
+  File = v3;
+  if ( !v3 )
+    Abortf("CTextureFrameTable::load - Unable to open file: %s.", Args);
+  v4 = 0;
+  v24 = 0;
+  v25 = 1;
+  if ( fgets(&Buf, 490, v3) )
+  {
+    do
+    {
+      *strchr(&Buf, 10) = 0;
+      memcpy(&v21, texture_frame_table_txt_parser(&Buf, &v20), 0x7Cu);
+      if ( v21 && *Str1 != 47 )
+      {
+        if ( v21 < 2 )
+          Abortf("CTextureFrameTable::load, too few arguments, %s line %i.", Args, v25);
+        ++v24;
+      }
+      ++v25;
+    }
+    while ( fgets(&Buf, 490, File) );
+    v4 = v24;
+  }
+  v5 = v2->pTextures;
+  v2->uNumTextures = v4;
+  v6 = pAllocator->AllocNamedChunk(v5, 20 * v4, "Txt Frames");
+  v2->pTextures = (TextureFrame *)v6;
+  if ( !v6 )
+    Abortf("CTextureFrameTable::load - Out of Memory!");
+  v7 = File;
+  v2->uNumTextures = 0;
+  fseek(v7, 0, 0);
+  for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
+  {
+    *strchr(&Buf, 10) = 0;
+    memcpy(&v21, texture_frame_table_txt_parser(&Buf, &v20), 0x7Cu);
+    if ( v21 && *Str1 != 47 )
+    {
+      strcpy(v2->pTextures[v2->uNumTextures].pTextureName, Str1);
+      v2->pTextures[v2->uNumTextures].uAnimTime = atoi(Str);
+      v9 = 2;
+      for ( v2->pTextures[v2->uNumTextures].uFlags = 0; v9 < v21; ++v9 )
+      {
+        if ( !_strcmpi((&Str1)[4 * v9], "New") )
+        {
+          v10 = (int)&v2->pTextures[v2->uNumTextures].uFlags;
+          *(char *)v10 |= 2u;
+        }
+      }
+      ++v2->uNumTextures;
+    }
+  }
+  fclose(File);
+  v11 = 0;
+  if ( (signed int)(v2->uNumTextures - 1) > 0 )
+  {
+    v12 = 0;
+    do
+    {
+      v13 = (int)&v2->pTextures[v12];
+      if ( !(*(char *)(v13 + 38) & 2) )
+        *(char *)(v13 + 18) |= 1u;
+      ++v11;
+      ++v12;
+    }
+    while ( v11 < (signed int)(v2->uNumTextures - 1) );
+  }
+  for ( j = 0; j < (signed int)v2->uNumTextures; *(short *)(Argsa + 16) = v16 )
+  {
+    v15 = v2->pTextures;
+    Argsa = (int)&v15[j];
+    v16 = *(short *)(Argsa + 14);
+    if ( *(char *)(Argsa + 18) & 1 )
+    {
+      ++j;
+      for ( k = (int)&v15[j]; *(char *)(k + 18) & 1; k += 20 )
+      {
+        v16 += *(short *)(k + 14);
+        ++j;
+      }
+      LOWORD(v16) = v15[j].uAnimTime + v16;
+    }
+    ++j;
+  }
+  return 1;
+}
+
+
+
+
+
+
+
+
+//----- (0044F57C) --------------------------------------------------------
+void SpawnEncounter(MapInfo *pMapInfo, SpawnPointMM7 *spawn, int a3, int a4, int a5)
+{
+  //MapInfo *v5; // esi@1
+  //SpawnPointMM7 *v6; // ebx@1
+  int v7; // eax@2
+  char v8; // zf@5
+  int v9; // edi@9
+  int v10; // eax@9
+  int v11; // ecx@9
+  int v12; // edx@9
+  int v13; // eax@9
+  int v14; // eax@14
+  int v15; // ecx@14
+  int v16; // eax@19
+  int v17; // ecx@19
+  int v18; // esi@31
+  //int pPosX; // ecx@32
+  //int v20; // edx@32
+  //int v21; // eax@32
+  Actor *pMonster; // esi@35
+  int v23; // edx@36
+  signed int v24; // edi@36
+  int v25; // ecx@36
+  unsigned __int16 v26; // ax@47
+  MonsterDesc *v27; // edi@48
+  signed int v28; // eax@48
+  __int16 v29; // cx@50
+  __int16 v30; // ax@50
+  __int16 v31; // ax@50
+  int v32; // eax@50
+  int v33; // edi@50
+  int v34; // eax@50
+  int v35; // eax@50
+  int v36; // eax@50
+  int v37; // eax@51
+  int v38; // eax@52
+  int v39; // edi@52
+  std::string v40; // [sp-18h] [bp-100h]@60
+  void *v41; // [sp-14h] [bp-FCh]@50
+  //void *v42; // [sp-10h] [bp-F8h]@50
+  //size_t v43; // [sp-Ch] [bp-F4h]@50
+  const char *v44; // [sp-8h] [bp-F0h]@13
+  char *pTexture; // [sp-4h] [bp-ECh]@9
+  char Str[32]; // [sp+Ch] [bp-DCh]@60
+  char Str2[120]; // [sp+2Ch] [bp-BCh]@29
+  unsigned int uFaceID; // [sp+A4h] [bp-44h]@52
+  MonsterInfo *Src; // [sp+A8h] [bp-40h]@50
+  int v50; // [sp+ACh] [bp-3Ch]@47
+  char Source[32]; // [sp+B0h] [bp-38h]@20
+  int v52; // [sp+D0h] [bp-18h]@34
+  int v53; // [sp+D4h] [bp-14h]@34
+  int pSector; // [sp+D8h] [bp-10h]@32
+  int pPosX; // [sp+DCh] [bp-Ch]@32
+  int v56; // [sp+E0h] [bp-8h]@8
+  int v57; // [sp+E4h] [bp-4h]@1
+
+  //auto a2 = spawn;
+  v57 = 0;
+  //v5 = pMapInfo;
+  //v6 = spawn;
+  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    v7 = pOutdoor->ddm.field_C_alert;
+  else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+    v7 = pIndoor->dlv.field_C_alert;
+  else
+    v7 = 0;
+  if (v7)
+    v8 = (spawn->uAttributes & 1) == 0;
+  else
+    v8 = (spawn->uAttributes & 1) == 1;
+  if (v8)
+    return;
+    //result = (void *)(spawn->uIndex - 1);
+  v56 = 1;
+  switch (spawn->uIndex - 1)
+  {
+    case 0u:
+        v9 = pMapInfo->uEncounterMonster1AtLeast;
+        v10 = rand();
+        v11 = pMapInfo->uEncounterMonster1AtMost;
+        pTexture = pMapInfo->pEncounterMonster1Texture;
+        v12 = v10 % (v11 - v9 + 1);
+        v13 = pMapInfo->field_34;
+        goto LABEL_20;
+    case 3u:
+        pTexture = pMapInfo->pEncounterMonster1Texture;
+        v44 = "%s A";
+        goto LABEL_25;
+    case 4u:
+        pTexture = pMapInfo->pEncounterMonster2Texture;
+        v44 = "%s A";
+        goto LABEL_25;
+    case 5u:
+        pTexture = pMapInfo->pEncounterMonster3Texture;
+        v44 = "%s A";
+        goto LABEL_25;
+    case 1u:
+        v9 = pMapInfo->uEncounterMonster2AtLeast;
+        v14 = rand();
+        v15 = pMapInfo->uEncounterMonster2AtMost;
+        pTexture = pMapInfo->pEncounterMonster2Texture;
+        v12 = v14 % (v15 - v9 + 1);
+        v13 = pMapInfo->field_37;
+        goto LABEL_20;
+    case 6u:
+        pTexture = pMapInfo->pEncounterMonster1Texture;
+        v44 = "%s B";
+        goto LABEL_25;
+    case 7u:
+        pTexture = pMapInfo->pEncounterMonster2Texture;
+        v44 = "%s B";
+        goto LABEL_25;
+    case 8u:
+        pTexture = pMapInfo->pEncounterMonster3Texture;
+        v44 = "%s B";
+        goto LABEL_25;
+    case 2u:
+        v9 = pMapInfo->uEncounterMonster3AtLeast;
+        v16 = rand();
+        v17 = pMapInfo->uEncounterMonster3AtMost;
+        pTexture = pMapInfo->pEncounterMonster3Texture;
+        v12 = v16 % (v17 - v9 + 1);
+        v13 = pMapInfo->field_3A;
+LABEL_20:
+        v57 = v13;
+        v56 = v9 + v12;
+        strcpy(Source, pTexture);
+        goto LABEL_26;
+    case 9u:
+        pTexture = pMapInfo->pEncounterMonster1Texture;
+        v44 = "%s C";
+        goto LABEL_25;
+    case 0xAu:
+        pTexture = pMapInfo->pEncounterMonster2Texture;
+        v44 = "%s C";
+        goto LABEL_25;
+    case 0xBu:
+        pTexture = pMapInfo->pEncounterMonster3Texture;
+        v44 = "%s C";
+LABEL_25:
+        sprintf(Source, v44, pTexture);
+LABEL_26:
+        if (Source[0] == '0')
+          return;
+        v57 += a3;
+        if ( v57 > 4 )
+          v57 = 4;
+        strcpy(Str2, Source);
+        if ( a4 )
+          v56 = a4;
+        v18 = v56;
+        if ( (signed int)(v56 + uNumActors) >= 500 )
+          return;
+        pSector = 0;
+        pPosX = spawn->vPosition.x;
+        a4 = spawn->vPosition.y;
+        a3 = spawn->vPosition.z;
+        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+          pSector = pIndoor->GetSector(spawn->vPosition.x, spawn->vPosition.y, spawn->vPosition.z);
+        v53 = 0;
+        v52 = (((uCurrentlyLoadedLevelType != LEVEL_Outdoor) - 1) & 0x40) + 64;
+        if ( v18 <= 0 )
+          return;
+        break;
+      default:
+        return;
+  }
+  for (uint i = v53; i < v56; ++i)
+  {
+      pMonster = &pActors[uNumActors];
+      pActors[uNumActors].Reset();
+      if ( v57 )
+      {
+        v23 = rand() % 100;
+        v24 = 3;
+        v25 = (unsigned __int16)word_4E8152[3 * v57];
+        if ( v23 >= v25 )
+        {
+          if ( v23 < v25 + (unsigned __int16)word_4E8152[3 * v57 + 1] )
+            v24 = 2;
+        }
+        else
+        {
+          v24 = 1;
+        }
+        if ( v24 == 1 )
+        {
+          pTexture = Source;
+          v44 = "%s A";
+        }
+        else
+        {
+          if ( v24 == 2 )
+          {
+            pTexture = Source;
+            v44 = "%s B";
+          }
+          else
+          {
+            if ( v24 != 3 )
+              goto LABEL_58;
+            pTexture = Source;
+            v44 = "%s C";
+          }
+        }
+        sprintf(Str2, v44, pTexture);
+      }
+      v26 = pMonsterList->GetMonsterByName(Str2);
+      v50 = (signed __int16)v26;
+      pTexture = Str2;
+      if ( (signed __int16)v26 == -1 )
+      {
+        sprintf(Str, "Can't create random monster: '%s'! See MapStats.txt and Monsters.txt!", pTexture);
+        MessageBoxA(nullptr, Str, nullptr, 0);
+        ExitProcess(0);
+      }
+      v27 = &pMonsterList->pMonsters[(signed __int16)v26];
+      v28 = pMonsterStats->_4563FF(pTexture);
+      if ( !v28 )
+        v28 = 1;
+      Src = &pMonsterStats->pInfos[v28];
+      strcpy(pMonster->pActorName, Src->pName);
+      pMonster->sCurrentHP = Src->uHP;
+      assert(sizeof(MonsterInfo) == 88);
+      memcpy(&pMonster->pMonsterInfo, Src, sizeof(MonsterInfo));
+      pMonster->word_000086_some_monster_id = v50 + 1;
+      pMonster->uActorRadius = v27->uMonsterRadius;
+      pMonster->uActorHeight = v27->uMonsterHeight;
+      pMonster->uMovementSpeed = v27->uMovementSpeed;
+      pMonster->vInitialPosition.x = spawn->vPosition.x;
+      pMonster->vPosition.x = spawn->vPosition.x;
+      pMonster->uTetherDistance = 256;
+      pMonster->vInitialPosition.y = a4;
+      pMonster->vPosition.y = a4;
+      pTexture = 0;
+      pMonster->vInitialPosition.z = a3;
+      pMonster->vPosition.z = a3;
+      pMonster->uSectorID = pSector;
+      pMonster->uGroup = spawn->uGroup;
+      pMonster->PrepareSprites((char)pTexture);
+      pMonster->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
+      v32 = rand();
+      v33 = v32 % 2048;
+      v34 = stru_5C6E00->SinCos(v32 % 2048);
+      a4 = v34;
+      a3 = (unsigned __int64)(v34 * (signed __int64)v52) >> 16;
+      pPosX = a3 + spawn->vPosition.x;
+      v35 = stru_5C6E00->SinCos(v33 - stru_5C6E00->uIntegerHalfPi);
+      a4 = v35;
+      a3 = (unsigned __int64)(v35 * (signed __int64)v52) >> 16;
+      a4 = a3 + spawn->vPosition.y;
+      v36 = spawn->vPosition.z;
+      a3 = spawn->vPosition.z;
+      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+        goto LABEL_55;
+      v37 = pIndoor->GetSector(pPosX, a4, v36);
+      if ( v37 == pSector )
+      {
+        v38 = _46CEC3_get_floor_level(pPosX, a4, a3, v37, &uFaceID);
+        v39 = v38;
+        if ( v38 != -30000 )
+        {
+          if ( abs(v38 - a3) <= 1024 )
+          {
+            a3 = v39;
+LABEL_55:
+            if ( a5 )
+              pMonster->uAttributes |= 0x080000;
+            ++uNumActors;
+            goto LABEL_58;
+          }
+        }
+      }
+LABEL_58:
+      ;
+      //v53 = (char *)v53 + 1;
+      //result = v53;
+    }
+    //while ( (signed int)v53 < v56 );
+}
+
+
+
+
+//----- (0044FA4C) --------------------------------------------------------
+signed int __fastcall sub_44FA4C_spawn_light_elemental(int a1, int a2, int a3)
+{
+  signed int v3; // ecx@6
+  char *v4; // edx@7
+  signed int result; // eax@13
+  Actor *v6; // esi@16
+  char *v7; // ebx@16
+  MonsterDesc *v8; // edi@16
+  unsigned __int16 v9; // ax@16
+  int v10; // ebx@16
+  int v11; // edi@16
+  int v12; // eax@16
+  int v13; // ecx@16
+  int v14; // ebx@16
+  const char *v15; // [sp-4h] [bp-24h]@2
+  unsigned __int16 v16; // [sp+0h] [bp-20h]@1
+  int v17; // [sp+4h] [bp-1Ch]@1
+  unsigned int uFaceID; // [sp+8h] [bp-18h]@16
+  int v19; // [sp+Ch] [bp-14h]@16
+  size_t v20; // [sp+10h] [bp-10h]@6
+  int v21; // [sp+14h] [bp-Ch]@14
+  int v22; // [sp+18h] [bp-8h]@14
+  unsigned int v23; // [sp+1Ch] [bp-4h]@6
+
+  v16 = a2;
+  v17 = a1;
+  if ( a2 == 4 )
+  {
+    v15 = "Elemental Light C";
+  }
+  else
+  {
+    if ( a2 == 3 )
+      v15 = "Elemental Light B";
+    else
+      v15 = "Elemental Light A";
+  }
+  v23 = (signed __int16)pMonsterList->GetMonsterByName(v15);
+  v3 = 0;
+  v20 = uNumActors;
+  if ( (signed int)uNumActors > 0 )
+  {
+    v4 = (char *)&pActors[0].uAIState;
+    while ( *(short *)v4 != Removed )
+    {
+      ++v3;
+      v4 += 836;
+      if ( v3 >= (signed int)uNumActors )
+        goto LABEL_12;
+    }
+    v20 = v3;
+  }
+LABEL_12:
+  if ( v20 != uNumActors || (result = uNumActors + 1, (signed int)(uNumActors + 1) < 500) )
+  {
+    v21 = 0;
+    v22 = pParty->vPosition.z;
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+      v21 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+    v6 = &pActors[v20];
+    v7 = (char *)&pMonsterStats->pInfos[v23 + 1];
+    v19 = (((uCurrentlyLoadedLevelType != LEVEL_Outdoor) - 1) & 0x40) + 64;
+    v6->Reset();
+    v8 = &pMonsterList->pMonsters[v23];
+    strcpy(v6->pActorName, *(const char **)v7);
+    v6->sCurrentHP = *((short *)v7 + 32);
+    memcpy(&v6->pMonsterInfo, v7, 0x58u);
+    v6->word_000086_some_monster_id = v23 + 1;
+    v6->uActorRadius = v8->uMonsterRadius;
+    v6->uActorHeight = v8->uMonsterHeight;
+    v9 = v8->uMovementSpeed;
+    v6->pMonsterInfo.uTreasureDiceRolls = 0;
+    v6->pMonsterInfo.uTreasureType = 0;
+    v6->pMonsterInfo.uExp = 0;
+    v6->uMovementSpeed = v9;
+    v10 = rand() % 2048;
+    v11 = ((unsigned __int64)(stru_5C6E00->SinCos(v10) * (signed __int64)v19) >> 16) + pParty->vPosition.x;
+    uFaceID = stru_5C6E00->SinCos(v10 - stru_5C6E00->uIntegerHalfPi);
+    v23 = (unsigned __int64)(uFaceID * (signed __int64)v19) >> 16;
+    v12 = pParty->vPosition.y;
+    v13 = (unsigned __int64)(uFaceID * (signed __int64)v19) >> 16;
+    v6->vInitialPosition.x = v11;
+    v14 = v13 + v12;
+    LOWORD(v12) = v22;
+    v6->vInitialPosition.z = v22;
+    v6->vPosition.z = v12;
+    LOWORD(v12) = v21;
+    v6->vPosition.x = v11;
+    v6->vInitialPosition.y = v14;
+    v6->vPosition.y = v14;
+    v6->uTetherDistance = 256;
+    v6->uSectorID = v12;
+    v6->PrepareSprites(0);
+    v6->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
+    v6->uAlly = 9999;
+    v6->uGroup = 0;
+    v6->uCurrentActionTime = 0;
+    v6->uAIState = Summoned;
+    v6->uCurrentActionLength = 256;
+    v6->UpdateAnimation();
+    if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor
+      || (v22 = pParty->vPosition.z,
+          result = pIndoor->GetSector(v11, v14, pParty->vPosition.z),
+          result == v21)
+      && (result = _46CEC3_get_floor_level(v11, v14, v22, result, &uFaceID), result != -30000)
+      && (result = abs(result - v22), result <= 1024) )
+    {
+      if ( v20 == uNumActors )
+        ++uNumActors;
+      v6->uSummonerID = 8 * v17 | 4;
+      result = v6->pActorBuffs[2].Apply(
+                 pParty->uTimePlayed + (signed __int64)((double)(a3 << 7) * 0.033333335),
+                 v16,
+                 v17,
+                 0,
+                 0);
+    }
+  }
+  return result;
+}
+
+
+//----- (0044FFD8) --------------------------------------------------------
+int MapInfo::SpawnRandomTreasure(SpawnPointMM7 *a2)
+{
+  MapInfo *v2; // ebx@1
+  SpawnPointMM7 *v3; // esi@1
+  int v4; // eax@1
+  int v5; // edx@1
+  int v6; // eax@1
+  int v7; // ecx@1
+  int v8; // ebx@1
+  int v9; // eax@1
+  signed int v10; // ebx@1
+  signed int result; // eax@1
+  signed __int64 v12; // qtt@1
+  int v13; // ebx@1
+  int v14; // edx@10
+  signed int v15; // ebx@20
+  unsigned __int16 v16; // dx@20
+  char *v17; // ecx@21
+  unsigned __int16 v18; // ax@24
+  int v19; // ST0C_4@27
+  int v20; // ST08_4@27
+  int v21; // ST04_4@27
+  int v22; // eax@27
+  signed int v23; // ebx@29
+  unsigned __int16 v24; // dx@29
+  char *v25; // ecx@30
+  unsigned __int16 v26; // ax@33
+  int v27; // ecx@35
+  int v28; // eax@35
+  int v29; // esi@35
+  __int16 v30; // ax@35
+  LayingItem a1a; // [sp+Ch] [bp-7Ch]@1
+  int v32; // [sp+7Ch] [bp-Ch]@1
+  int v33; // [sp+80h] [bp-8h]@1
+  int v34; // [sp+84h] [bp-4h]@1
+
+  __debugbreak();
+
+  auto a1 = this;
+
+  v2 = a1;
+  v3 = a2;
+  v4 = rand();
+  v34 = 0;
+  v5 = v4 % 100;
+  v6 = 2 * (v2->field_2F + 7 * v3->uIndex) - 14;
+  v7 = (unsigned __int8)byte_4E8168[v6 + 16];
+  v8 = (unsigned __int8)byte_4E8168[v6 + 17];
+  v32 = v5;
+  v33 = v7;
+  v9 = rand();
+  v10 = v8 - v33 + 1;
+  v12 = v9;
+  result = v9 / v10;
+  v13 = v33 + (unsigned __int64)(v12 % v10);
+  if ( v13 < 7 )
+  {
+    if ( v32 < 20 )
+      return result;
+    if ( v32 >= 60 )
+    {
+      v19 = v3->vPosition.z;
+      v20 = v3->vPosition.y;
+      v21 = v3->vPosition.x;
+      v22 = rand();
+      return sub_450521_ProllyDropItemAt(v13, v22 % 27 + 20, v21, v20, v19, 0);
+    }
+    if ( v3->uIndex == 1 )
+    {
+      v14 = rand() % 51 + 50;
+    }
+    else
+    {
+      if ( v3->uIndex != 2 )
+      {
+        if ( v3->uIndex == 3 )
+        {
+          v14 = rand() % 301 + 200;
+        }
+        else
+        {
+          if ( v3->uIndex != 4 )
+          {
+            if ( v3->uIndex == 5 )
+            {
+              v14 = rand() % 1001 + 1000;
+            }
+            else
+            {
+              if ( v3->uIndex != 6 )
+              {
+LABEL_20:
+                v15 = 0;
+                v16 = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID;
+                a1a.uItemType = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID;
+                if ( (signed int)pObjectList->uNumObjects <= 0 )
+                {
+LABEL_24:
+                  v18 = 0;
+                }
+                else
+                {
+                  v17 = (char *)&pObjectList->pObjects->uObjectID;
+                  while ( v16 != *(short *)v17 )
+                  {
+                    ++v15;
+                    v17 += 56;
+                    if ( v15 >= (signed int)pObjectList->uNumObjects )
+                      goto LABEL_24;
+                  }
+                  v18 = v15;
+                }
+                a1a.stru_24.uAttributes |= 1u;
+                a1a.uObjectDescID = v18;
+                a1a.stru_24.uAdditionalValue = v34;
+                goto LABEL_35;
+              }
+              v14 = rand() % 3001 + 2000;
+            }
+            a1a.stru_24.uItemID = 199;
+LABEL_19:
+            v34 = v14;
+            goto LABEL_20;
+          }
+          v14 = rand() % 501 + 500;
+        }
+        a1a.stru_24.uItemID = 198;
+        goto LABEL_19;
+      }
+      v14 = rand() % 101 + 100;
+    }
+    a1a.stru_24.uItemID = 197;
+    goto LABEL_19;
+  }
+  result = a1a.stru_24.GenerateArtifact();
+  if ( !result )
+    return result;
+  v23 = 0;
+  v24 = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID;
+  a1a.uItemType = pItemsTable->pItems[a1a.stru_24.uItemID].uSpriteID;
+  if ( (signed int)pObjectList->uNumObjects <= 0 )
+  {
+LABEL_33:
+    v26 = 0;
+  }
+  else
+  {
+    v25 = (char *)&pObjectList->pObjects->uObjectID;
+    while ( v24 != *(short *)v25 )
+    {
+      ++v23;
+      v25 += 56;
+      if ( v23 >= (signed int)pObjectList->uNumObjects )
+        goto LABEL_33;
+    }
+    v26 = v23;
+  }
+  a1a.uObjectDescID = v26;
+  a1a.stru_24.Reset();
+LABEL_35:
+  v27 = v3->vPosition.y;
+  v28 = v3->vPosition.x;
+  v29 = v3->vPosition.z;
+  a1a.vPosition.y = v27;
+  a1a.uAttributes = 0;
+  a1a.uSoundID = 0;
+  a1a.uFacing = 0;
+  a1a.vPosition.z = v29;
+  a1a.vPosition.x = v28;
+  a1a.field_50 = 0;
+  a1a.field_4C = 0;
+  a1a.field_48 = 0;
+  v30 = pIndoor->GetSector(v28, v27, v29);
+  a1a.field_5C = 0;
+  a1a.field_58 = 0;
+  a1a.uSpriteFrameID = 0;
+  a1a.uSectorID = v30;
+  return a1a.Create(0, 0, 0, 0);
+}
+
+//----- (00450218) --------------------------------------------------------
+void __cdecl sub_450218_prolly_generate_chests_loot()
+{
+  unsigned int v0; // eax@1
+  Chest *v1; // ebx@1
+  MapInfo *v2; // esi@1
+  ItemGen *v3; // ebx@2
+  int v4; // ebp@4
+  int v5; // edi@4
+  int v6; // esi@4
+  int v7; // eax@4
+  signed int v8; // esi@4
+  int v9; // edx@4
+  int v10; // esi@8
+  int v11; // ebp@25
+  int v12; // esi@25
+  signed int v13; // ebp@27
+  ItemGen *v14; // edi@28
+  signed int v15; // edx@32
+  signed __int64 v16; // qtt@32
+  int v17; // esi@34
+  signed int v18; // [sp+10h] [bp-18h]@1
+  int v19; // [sp+14h] [bp-14h]@4
+  MapInfo *v20; // [sp+18h] [bp-10h]@1
+  Chest *v21; // [sp+1Ch] [bp-Ch]@1
+  int v22; // [sp+20h] [bp-8h]@26
+  signed int v23; // [sp+24h] [bp-4h]@2
+
+  v18 = rand() % 100;
+  v0 = pMapStats->GetMapInfo(pCurrentMapName);
+  v1 = pChests;
+  v2 = &pMapStats->pInfos[v0];
+  v21 = pChests;
+  v20 = &pMapStats->pInfos[v0];
+  do
+  {
+    v3 = v1->mm7__vector_pItems;
+    v23 = 140;
+    do
+    {
+      if ( (v3->uItemID & 0x80000000u) == 0 )
+        goto LABEL_56;
+      v4 = rand() % 5 + 1;
+      v5 = (unsigned __int8)byte_4E8168[2 * (v2->field_2F + 7 * abs((int)v3->uItemID)) + 2];
+      v6 = (unsigned __int8)byte_4E8168[2 * (v2->field_2F + 7 * abs((int)v3->uItemID)) + 3];
+      v7 = rand();
+      v8 = v6 - v5 + 1;
+      v9 = v5 + v7 % v8;
+      v19 = v5 + v7 % v8;
+      if ( v9 < 7 )
+      {
+        if ( v18 < 20 )
+        {
+          v3->Reset();
+          goto LABEL_25;
+        }
+        if ( v18 < 60 )
+        {
+          v10 = 0;
+          v3->Reset();
+          if ( v19 == 1 )
+          {
+            v10 = rand() % 51 + 50;
+          }
+          else
+          {
+            if ( v19 != 2 )
+            {
+              if ( v19 == 3 )
+              {
+                v10 = rand() % 301 + 200;
+              }
+              else
+              {
+                if ( v19 != 4 )
+                {
+                  if ( v19 == 5 )
+                  {
+                    v10 = rand() % 1001 + 1000;
+LABEL_15:
+                    v3->uItemID = 199;
+                  }
+                  else
+                  {
+                    if ( v19 == 6 )
+                    {
+                      v10 = rand() % 3001 + 2000;
+                      goto LABEL_15;
+                    }
+                  }
+LABEL_23:
+                  v3->uAttributes |= 1u;
+                  v3->uAdditionalValue = v10;
+LABEL_25:
+                  v11 = v4 - 1;
+                  v12 = 0;
+                  if ( v11 > 0 )
+                  {
+                    v22 = v11;
+                    while ( 1 )
+                    {
+                      v13 = v12;
+                      if ( v12 >= 140 )
+                        goto LABEL_52;
+                      v14 = &v21->mm7__vector_pItems[v12];
+                      while ( v14->uItemID )
+                      {
+                        ++v13;
+                        ++v14;
+                        if ( v13 >= 140 )
+                          goto LABEL_52;
+                      }
+                      v16 = rand();
+                      v15 = v16 % 100;
+                      v18 = v16 % 100;
+                      if ( v15 < 20 )
+                        goto LABEL_52;
+                      if ( v15 >= 60 )
+                      {
+                        pItemsTable->GenerateItem(v19, 0, v14);
+                        goto LABEL_51;
+                      }
+                      v17 = 0;
+                      v14->Reset();
+                      if ( v19 == 1 )
+                      {
+                        v17 = rand() % 51 + 50;
+                        goto LABEL_48;
+                      }
+                      if ( v19 == 2 )
+                      {
+                        v17 = rand() % 101 + 100;
+LABEL_48:
+                        v14->uItemID = 197;
+                        goto LABEL_49;
+                      }
+                      if ( v19 == 3 )
+                      {
+                        v17 = rand() % 301 + 200;
+                        goto LABEL_44;
+                      }
+                      if ( v19 == 4 )
+                      {
+                        v17 = rand() % 501 + 500;
+LABEL_44:
+                        v14->uItemID = 198;
+                        goto LABEL_49;
+                      }
+                      if ( v19 == 5 )
+                        break;
+                      if ( v19 == 6 )
+                      {
+                        v17 = rand() % 3001 + 2000;
+LABEL_41:
+                        v14->uItemID = 199;
+                      }
+LABEL_49:
+                      v14->uAdditionalValue = v17;
+LABEL_51:
+                      v12 = v13 + 1;
+LABEL_52:
+                      --v22;
+                      if ( !v22 )
+                        goto LABEL_55;
+                    }
+                    v17 = rand() % 1001 + 1000;
+                    goto LABEL_41;
+                  }
+                  goto LABEL_55;
+                }
+                v10 = rand() % 501 + 500;
+              }
+              v3->uItemID = 198;
+              goto LABEL_23;
+            }
+            v10 = rand() % 101 + 100;
+          }
+          v3->uItemID = 197;
+          goto LABEL_23;
+        }
+        pItemsTable->GenerateItem(v9, 0, v3);
+        goto LABEL_25;
+      }
+      v3->GenerateArtifact();
+LABEL_55:
+      v2 = v20;
+LABEL_56:
+      ++v3;
+      --v23;
+    }
+    while ( v23 );
+    v1 = v21 + 1;
+    ++v21;
+  }
+  while ( (signed int)v21 < (signed int)&uNumChests );
+}
+
+//----- (00450521) --------------------------------------------------------
+signed int __fastcall sub_450521_ProllyDropItemAt(int ecx0, signed int a2, int a3, int a4, int a5, unsigned __int16 a6)
+{
+  int v6; // edi@1
+  int v7; // esi@1
+  signed int v8; // edi@1
+  unsigned __int16 v9; // cx@1
+  char *v10; // edx@2
+  unsigned __int16 v11; // ax@5
+  LayingItem a1; // [sp+8h] [bp-70h]@1
+
+  v6 = ecx0;
+  v7 = a2;
+  pItemsTable->GenerateItem(v6, v7, &a1.stru_24);
+  v8 = 0;
+  v9 = pItemsTable->pItems[a1.stru_24.uItemID].uSpriteID;
+  a1.uItemType = pItemsTable->pItems[a1.stru_24.uItemID].uSpriteID;
+  if ( (signed int)pObjectList->uNumObjects <= 0 )
+  {
+LABEL_5:
+    v11 = 0;
+  }
+  else
+  {
+    v10 = (char *)&pObjectList->pObjects->uObjectID;
+    while ( v9 != *(short *)v10 )
+    {
+      ++v8;
+      v10 += 56;
+      if ( v8 >= (signed int)pObjectList->uNumObjects )
+        goto LABEL_5;
+    }
+    v11 = v8;
+  }
+  a1.uObjectDescID = v11;
+  a1.vPosition.y = a4;
+  a1.vPosition.x = a3;
+  a1.vPosition.z = a5;
+  a1.uFacing = a6;
+  a1.uAttributes = 0;
+  a1.uSectorID = pIndoor->GetSector(a3, a4, a5);
+  a1.uSpriteFrameID = 0;
+  return a1.Create(0, 0, 0, 0);
+}
+
+
+
+
+//----- (0045063B) --------------------------------------------------------
+int __fastcall sub_45063B(MapInfo *a1, int a2)
+{
+  signed int v2; // edi@1
+  Actor *v3; // esi@2
+  signed __int64 v4; // qax@3
+  int result; // eax@8
+  int v6; // edi@11
+  int v7; // ebx@11
+  int v8; // edi@11
+  int v9; // ebx@12
+  int v10; // eax@12
+  char v11; // zf@16
+  int v12; // edi@20
+  int v13; // eax@20
+  int v14; // ebx@20
+  int v15; // eax@20
+  int v16; // eax@20
+  int v17; // eax@20
+  int v18; // eax@21
+  SpawnPointMM7 v19; // [sp+Ch] [bp-38h]@1
+  int v20; // [sp+24h] [bp-20h]@11
+  MapInfo *v21; // [sp+28h] [bp-1Ch]@1
+  int v22; // [sp+2Ch] [bp-18h]@3
+  int v23; // [sp+30h] [bp-14h]@11
+  int v24; // [sp+34h] [bp-10h]@1
+  unsigned int uFaceID; // [sp+38h] [bp-Ch]@10
+  int v26; // [sp+3Ch] [bp-8h]@11
+  int v27; // [sp+40h] [bp-4h]@11
+
+  v21 = a1;
+  v24 = a2;
+  v2 = 0;
+  if ( (signed int)uNumActors <= 0 )
+    goto LABEL_8;
+  v3 = pActors;
+  while ( 1 )
+  {
+    v22 = v3->pMonsterInfo.uID - 1;
+    v4 = (signed __int64)((double)v22 * 0.3333333333333333);
+    if ( (int)v4 != 40 )
+    {
+      if ( (int)v4 != 41 && (int)v4 != 44 && v3->CanAct() )
+        break;
+    }
+    ++v2;
+    ++v3;
+    if ( v2 >= (signed int)uNumActors )
+      goto LABEL_8;
+  }
+  if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+  {
+    v22 = 0;
+    uFaceID = 0;
+    while ( 1 )
+    {
+      ++uFaceID;
+      v6 = rand() % 1024 + 512;
+      v7 = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
+      v20 = stru_5C6E00->SinCos(v7);
+      v23 = (unsigned __int64)(v20 * (signed __int64)v6) >> 16;
+      v19.vPosition.x = pParty->vPosition.x + v23;
+      v20 = stru_5C6E00->SinCos(v7 - stru_5C6E00->uIntegerHalfPi);
+      v23 = (unsigned __int64)(v20 * (signed __int64)v6) >> 16;
+      v8 = 0;
+      v19.uIndex = v24;
+      v19.vPosition.y = v23 + pParty->vPosition.y;
+      v19.vPosition.z = pParty->vPosition.z;
+      v26 = 0;
+      v27 = 0;
+      v19.vPosition.z = sub_46D49E_prolly_get_world_y_under_party(
+                          v19.vPosition.x,
+                          v23 + pParty->vPosition.y,
+                          pParty->vPosition.z,
+                          0,
+                          &v26,
+                          &v27,
+                          0);
+      v23 = 0;
+      if ( (signed int)pOutdoor->uNumBModels > 0 )
+      {
+        while ( 1 )
+        {
+          v9 = abs(v19.vPosition.y - pOutdoor->pBModels[v8].vBoundingCenter.y);
+          v10 = abs(v19.vPosition.x - pOutdoor->pBModels[v8].vBoundingCenter.x);
+          if ( sub_4621DA(v10, v9, 0) < pOutdoor->pBModels[v8].sBoundingRadius + 256 )
+            break;
+          ++v23;
+          ++v8;
+          if ( v23 >= (signed int)pOutdoor->uNumBModels )
+            goto LABEL_16;
+        }
+        v22 = 1;
+      }
+LABEL_16:
+      v11 = uFaceID == 100;
+      if ( uFaceID >= 100 )
+        break;
+      if ( v22 )
+      {
+        v11 = uFaceID == 100;
+        break;
+      }
+    }
+  }
+  else
+  {
+    v26 = 0;
+    v22 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+    do
+    {
+      ++v26;
+      v12 = rand() % 512 + 256;
+      v13 = rand();
+      v14 = v13 % (signed int)stru_5C6E00->uIntegerDoublePi;
+      v15 = stru_5C6E00->SinCos(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
+      v20 = v15;
+      v23 = (unsigned __int64)(v15 * (signed __int64)v12) >> 16;
+      v19.vPosition.x = pParty->vPosition.x + v23;
+      v16 = stru_5C6E00->SinCos(v14 - stru_5C6E00->uIntegerHalfPi);
+      v20 = v16;
+      v23 = (unsigned __int64)(v16 * (signed __int64)v12) >> 16;
+      v19.vPosition.y = v23 + pParty->vPosition.y;
+      v19.vPosition.z = pParty->vPosition.z;
+      v19.uIndex = v24;
+      v17 = pIndoor->GetSector(v19.vPosition.x, v23 + pParty->vPosition.y, pParty->vPosition.z);
+      if ( v17 == v22 )
+      {
+        v18 = _46CEC3_get_floor_level(v19.vPosition.x, v19.vPosition.y, v19.vPosition.z, v17, &uFaceID);
+        v19.vPosition.z = v18;
+        if ( v18 != -30000 )
+        {
+          if ( abs(v18 - pParty->vPosition.z) <= 1024 )
+            break;
+        }
+      }
+    }
+    while ( v26 < 100 );
+    v11 = v26 == 100;
+  }
+  if ( v11 )
+  {
+LABEL_8:
+    result = 0;
+  }
+  else
+  {
+    SpawnEncounter(v21, &v19, 0, 0, 1);
+    result = v24;
+  }
+  return result;
+}
+
+
+
+//----- (00450929) --------------------------------------------------------
+int LevelDecoration::GetGlobalEvent()
+{
+  LevelDecoration *v1; // esi@1
+  signed int v2; // eax@1
+  int v3; // eax@5
+  int v4; // eax@6
+  int v5; // eax@7
+  int v6; // eax@8
+  int v7; // eax@9
+  int result; // eax@14
+  int v9; // eax@18
+  int v10; // eax@19
+  int v11; // eax@20
+  int v12; // eax@21
+  int v13; // eax@22
+
+  v1 = this;
+  rand();
+  v2 = v1->uDecorationDescID;
+  if ( v2 > 208 )
+  {
+    switch ( v2 )
+    {
+      case 209:
+        result = rand() % 7 + 183;
+        break;
+      case 210:
+        result = 150;
+        break;
+      case 211:
+        result = 151;
+        break;
+      case 212:
+        result = 152;
+        break;
+      case 213:
+        result = 153;
+        break;
+      case 214:
+        result = 154;
+        break;
+      case 215:
+        result = 155;
+        break;
+      case 216:
+        result = 156;
+        break;
+      case 217:
+        result = 157;
+        break;
+      case 218:
+        result = 158;
+        break;
+      case 219:
+        result = 159;
+        break;
+      case 220:
+        result = 160;
+        break;
+      case 221:
+        result = 161;
+        break;
+      default:
+        goto LABEL_45;
+    }
+  }
+  else
+  {
+    if ( v2 == 208 )
+    {
+      result = rand() % 7 + 176;
+    }
+    else
+    {
+      if ( v2 > 24 )
+      {
+        v9 = v2 - 34;
+        if ( !v9 )
+          return rand() % 6 + 4;
+        v10 = v9 - 150;
+        if ( !v10 )
+          return 33;
+        v11 = v10 - 3;
+        if ( !v11 || (v12 = v11 - 3) == 0 )
+          return 37;
+        v13 = v12 - 16;
+        if ( !v13 )
+          return rand() % 7 + 162;
+        if ( v13 == 1 )
+          return rand() % 7 + 169;
+      }
+      else
+      {
+        if ( v2 == 24 )
+          return 36;
+        v3 = v2 - 4;
+        if ( !v3 )
+          return 16;
+        v4 = v3 - 1;
+        if ( !v4 )
+          return 32;
+        v5 = v4 - 1;
+        if ( !v5 )
+          return rand() % 4 + 12;
+        v6 = v5 - 5;
+        if ( !v6 )
+          return 34;
+        v7 = v6 - 2;
+        if ( !v7 )
+          return 17;
+        if ( v7 == 1 )
+          return 18;
+      }
+LABEL_45:
+      result = 0;
+    }
+  }
+  return result;
+}
+
+//----- (00450AAA) --------------------------------------------------------
+void RespawnGlobalDecorations()
+{
+  memset(stru_5E4C90._decor_events, 0, 125);
+
+  uint decorEventIdx = 0;
+  for (uint i = 0; i < uNumLevelDecorations; ++i)
+  {
+    auto decor = pLevelDecorations + i;
+
+    if (!decor->field_16_event_id)
+    {
+      if (decor->IsInteractive())
+      {
+        if (decorEventIdx < 124)
+        {
+          decor->_idx_in_stru123 = decorEventIdx + 75;
+          stru_5E4C90._decor_events[decorEventIdx++] = decor->GetGlobalEvent();
+        }
+      }
+    }
+  }
+}
+
+//----- (00450B0A) --------------------------------------------------------
+bool __fastcall SpawnActor(unsigned int uMonsterID)
+{
+  unsigned int v1; // ebx@1
+  bool result; // eax@2
+  MonsterDesc *v3; // esi@5
+  MonsterInfo *v4; // edi@5
+  Vec3_int_ v5; // ST08_12@5
+  unsigned int v6; // ecx@5
+  Actor *v7; // eax@7
+  Actor actor; // [sp+4h] [bp-350h]@5
+  Vec3_int_ pOut; // [sp+348h] [bp-Ch]@5
+
+  v1 = uMonsterID;
+  if ( uNumActors == 499 )
+  {
+    result = 0;
+  }
+  else
+  {
+    if ( (signed int)uMonsterID >= (signed int)pMonsterList->uNumMonsters )
+      v1 = 0;
+    v3 = &pMonsterList->pMonsters[v1];
+    v4 = &pMonsterStats->pInfos[v1 + 1];
+    memset(&actor, 0, 0x344u);
+    strcpy(actor.pActorName, v4->pName);
+    actor.sCurrentHP = LOWORD(v4->uHP);
+    memcpy(&actor.pMonsterInfo, &pMonsterStats->pInfos[v1 + 1], 0x58u);
+    actor.word_000086_some_monster_id = v1 + 1;
+    actor.uActorRadius = v3->uMonsterRadius;
+    actor.uActorHeight = v3->uMonsterHeight;
+    actor.uMovementSpeed = v3->uMovementSpeed;
+    v5 = pParty->vPosition;
+    Vec3_int_::Rotate(200, pParty->sRotationY, 0, v5, &pOut.x, &pOut.z, &pOut.y);
+    actor.vInitialPosition.x = pOut.x;
+    actor.vPosition.x = pOut.x;
+    actor.uTetherDistance = 256;
+    actor.vInitialPosition.y = LOWORD(pOut.z);
+    actor.vPosition.y = LOWORD(pOut.z);
+    actor.vInitialPosition.z = LOWORD(pOut.y);
+    actor.vPosition.z = LOWORD(pOut.y);
+    pSprites_LOD->DeleteSomeSprites();
+    pPaletteManager->ResetNonTestLocked();
+    v6 = uNumActors - 1;
+    if ( dword_5C6DF8 == 1 )
+    {
+      dword_5C6DF8 = 0;
+      v6 = uNumActors++;
+    }
+    v7 = &pActors[v6];
+    memcpy(v7, &actor, 0x344u);
+    v7->PrepareSprites(1);
+    result = 1;
+  }
+  return result;
+}
+// 5C6DF8: using guessed type int dword_5C6DF8;
+
+
+//----- (00450DA3) --------------------------------------------------------
+int __cdecl GetAlertStatus()
+{
+  int result; // eax@2
+
+  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    result = pOutdoor->ddm.field_C_alert;
+  else
+    result = uCurrentlyLoadedLevelType == LEVEL_Outdoor ? pIndoor->dlv.field_C_alert : 0;
+  return result;
+}
+
+
+
+//----- (00450DDE) --------------------------------------------------------
+stru350 *stru350::_450DDE()
+{
+  _450DF1(&stru_4E82A4, &stru_4E82A4);
+  return this;
+}
+
+
+//----- (00450DF1) --------------------------------------------------------
+bool stru350::_450DF1(const stru355 *p1, const stru355 *p2)
+{
+  //stru350 *v3; // esi@1
+  //void *result; // eax@1
+  unsigned int v5; // ecx@2
+  int v6; // edi@2
+  int v7; // edx@2
+  unsigned int v8; // ecx@8
+  int v9; // edi@8
+  int v10; // edx@8
+  int v11; // ecx@12
+  int v12; // edi@12
+  unsigned int v13; // ecx@12
+  int v14; // edx@12
+  int v15; // ecx@16
+  unsigned int v16; // edx@16
+  int v17; // ecx@16
+  int v18; // edi@16
+  char v19; // zf@20
+  unsigned int v20; // ecx@21
+  int v21; // edi@21
+  int v22; // edx@21
+  unsigned int v23; // ecx@27
+  int v24; // edi@27
+  int v25; // edx@27
+  int v26; // ecx@31
+  int v27; // edi@31
+  unsigned int v28; // ecx@31
+  int v29; // edx@31
+  int v30; // ebx@35
+  int v31; // ecx@35
+  int v32; // edi@35
+  int v33; // edx@35
+  unsigned int i; // ecx@35
+  int v35; // ecx@39
+  unsigned int v36; // edx@39
+  int v37; // ecx@39
+  int v38; // ebx@39
+
+  //v3 = this;
+  memcpy(&field_0, p1, sizeof(stru355));
+  memcpy(&field_20, p2, sizeof(stru355));
+  //result = memcpy(&v3->field_20, p2, 0x20u);
+  //LOBYTE(result) = 1;
+  if (field_0.field_4 & 1)
+  {
+    v5 = field_0.field_1C;
+    v6 = 0;
+    v7 = 0;
+    while ( !(v5 & 1) )
+    {
+      ++v6;
+      v5 >>= 1;
+    }
+    do
+    {
+      v5 >>= 1;
+      ++v7;
+    }
+    while ( v5 & 1 );
+    field_40 = 32 - v7 - v6;
+  }
+  else
+  {
+    field_40 = 0;
+  }
+  v8 = field_0.field_10;
+  v9 = 0;
+  v10 = 0;
+  while ( !(v8 & 1) )
+  {
+    ++v9;
+    v8 >>= 1;
+  }
+  do
+  {
+    v8 >>= 1;
+    ++v10;
+  }
+  while ( v8 & 1 );
+  v11 = 24 - v10 - v9;
+  v12 = 0;
+  field_48 = v11;
+  v13 = field_0.field_14;
+  v14 = 0;
+  while ( !(v13 & 1) )
+  {
+    ++v12;
+    v13 >>= 1;
+  }
+  do
+  {
+    v13 >>= 1;
+    ++v14;
+  }
+  while ( v13 & 1 );
+  v15 = 16 - v14;
+  v16 = field_0.field_18;
+  field_50 = v15 - v12;
+  v17 = 0;
+  v18 = 0;
+  while ( !(v16 & 1) )
+  {
+    ++v17;
+    v16 >>= 1;
+  }
+  do
+  {
+    v16 >>= 1;
+    ++v18;
+  }
+  while ( v16 & 1 );
+  v19 = (field_20.field_4 & 1) == 0;
+  field_58 = v17 - v18 + 8;
+  if ( v19 )
+  {
+    field_44 = 0;
+  }
+  else
+  {
+    v20 = field_20.field_1C;
+    v21 = 0;
+    v22 = 0;
+    while ( !(v20 & 1) )
+    {
+      ++v21;
+      v20 >>= 1;
+    }
+    do
+    {
+      v20 >>= 1;
+      ++v22;
+    }
+    while ( v20 & 1 );
+    field_44 = 32 - v22 - v21;
+  }
+  v23 = field_20.field_10;
+  v24 = 0;
+  v25 = 0;
+  while ( !(v23 & 1) )
+  {
+    ++v24;
+    v23 >>= 1;
+  }
+  do
+  {
+    v23 >>= 1;
+    ++v25;
+  }
+  while ( v23 & 1 );
+  v26 = 24 - v25 - v24;
+  v27 = 0;
+  field_4C = v26;
+  v28 = field_20.field_14;
+  v29 = 0;
+  while ( !(v28 & 1) )
+  {
+    ++v27;
+    v28 >>= 1;
+  }
+  do
+  {
+    v28 >>= 1;
+    ++v29;
+  }
+  while ( v28 & 1 );
+  v30 = 0;
+  v31 = 16 - v29 - v27;
+  v32 = field_20.field_18;
+  field_54 = v31;
+  v33 = 0;
+  for ( i = v32; !(i & 1); i >>= 1 )
+    ++v30;
+  do
+  {
+    i >>= 1;
+    ++v33;
+  }
+  while ( i & 1 );
+  v35 = 32 - v33;
+  v36 = v32;
+  field_5C = v35 - v30;
+  v37 = 0;
+  v38 = 0;
+  while ( !(v36 & 1) )
+  {
+    ++v37;
+    v36 >>= 1;
+  }
+  do
+  {
+    v36 >>= 1;
+    ++v38;
+  }
+  while ( v36 & 1 );
+  field_5C = v37 - v38 + 8;
+  return true;
+}
+
+
+
+
+//----- (00450F55) --------------------------------------------------------
+unsigned int stru350::_450F55(int a2)
+{
+  int v2 = a2 & stru_4E82A4.field_1C;
+  if (field_20.field_4 & 1)
+    v2 = (unsigned int)v2 >> this->field_44;
+  return v2 & field_20.field_1C |
+         field_20.field_10 & ((a2 & (unsigned int)stru_4E82A4.field_10) >> field_4C) |
+         field_20.field_14 & ((a2 & (unsigned int)stru_4E82A4.field_14) >> field_54) |
+         field_20.field_18 & ((a2 & (unsigned int)stru_4E82A4.field_18) >> field_5C);
+}
+
+//----- (00450FB1) --------------------------------------------------------
+int stru350::_450FB1(int a2)
+{
+  int v2 = 0;
+  int v4 = field_0.field_4 & 1;
+  if ( v4 )
+    v2 = a2 & field_0.field_1C;
+  if ( v4 )
+    v2 <<= field_40;
+  return v2 | ((a2 & field_0.field_10) << field_48) | ((a2 & field_0.field_14) << field_50) | ((a2 & field_0.field_18) << field_58);
+}
+
+
+//----- (00452442) --------------------------------------------------------
+unsigned int __fastcall sub_452442(unsigned __int16 a1, unsigned __int16 a2, int a3, int a4)
+{
+  int v4; // ebx@0
+  __int16 v5; // ST14_2@1
+  __int16 v6; // dx@1
+  int v7; // ecx@1
+  __int16 v8; // ST10_2@1
+  int v9; // edi@1
+  unsigned __int16 v10; // dh@1@1
+  int v11; // ebx@1
+  int v12; // ebx@1
+  __int16 a3a; // [sp+1Ch] [bp+8h]@1
+
+  v5 = a2 >> 2;
+  v6 = (unsigned __int16)a4 >> 2;
+  v8 = a1 >> 2;
+  a3a = (unsigned __int16)a3 >> 2;
+  LOWORD(v7) = a3a;
+  v9 = v7;
+  LOWORD(v4) = ((unsigned __int16)a4 >> 2) & 0xE0;
+  LOWORD(v7) = a3a & 0xE0;
+  LOWORD(v9) = v9 & 0x1C00;
+  v11 = v7 + v4;
+  LOWORD(v7) = v5 & 0xE0;
+  v12 = v7 + v11;
+  LOWORD(v7) = v8 & 0xE0;
+  return ((v8 & 7) + (v5 & 7) + (a3a & 7) + (v6 & 7)) | (v7 + v12) | ((v8 & 0x1C00)
+                                                                    + (v5 & 0x1C00)
+                                                                    + v9
+                                                                    + (__PAIR__(v10, (unsigned __int16)a4 >> 2) & 0x1C00));
+}
+
+
+
+//----- (0045281E) --------------------------------------------------------
+//    Calculates atan2(y/x)
+// return value: angle in integer format (multiplier of Pi/1024)  
+unsigned int stru193_math::Atan2(int x, int y)
+{
+  signed int quadrant;
+  __int64 dividend;
+  int quotient;
+  int lowIdx;
+  int highIdx;
+  int angle;
+
+  auto X = x;
+  auto Y = y;
+
+  if ( abs(X) < 65536 )
+  {
+    if ( (abs(Y) >> 15) >= abs(X) )
+      X = 0;
+  }
+
+  if ( !X )
+  {
+    if ( Y > 0 )
+    {
+      return uIntegerHalfPi;   //Pi/2
+    }
+    else
+    {
+      return uIntegerHalfPi + uIntegerPi; //3*(Pi/2)
+    }
+  }
+
+  if ( Y )
+  {
+    if ( X < 0 )
+    {
+      X = -X;
+      if ( Y > 0 )
+      {
+        quadrant = 4;        
+      }
+      else
+      {
+        quadrant = 3;        
+      }      
+    }
+    else
+    {
+      if ( Y > 0 )
+      {
+        quadrant = 1;       
+      }
+      else
+      {
+        quadrant = 2;
+      }      
+    }
+
+    if ( Y < 0 )
+      Y = -Y;
+
+    LODWORD(dividend) = Y << 16;
+    HIDWORD(dividend) = Y >> 16;
+    quotient = dividend / X;        
+
+    //looks like binary search
+    {
+      int i;
+      highIdx = uIntegerHalfPi;
+      lowIdx = 0;
+
+      for (i = 0; i < 6; ++i)
+      {        
+        if (quotient <= pTanTable[(lowIdx + highIdx) / 2])      
+          highIdx = (lowIdx + highIdx) / 2;
+        else
+          lowIdx = (lowIdx + highIdx) / 2;    
+      }
+    }
+
+    angle = lowIdx + 1;
+    while ( angle < (highIdx - 1) && quotient >= pTanTable[angle] )
+      ++angle;
+
+    switch (quadrant)
+    {
+    case 1: //X > 0, Y > 0
+      return angle;        
+
+    case 2: //X > 0, Y < 0
+      return uIntegerDoublePi - angle;   //2*Pi - angle
+
+    case 3: //X > 0, Y < 0
+      return uIntegerPi + angle;        //Pi + angle 
+
+    case 4: //X < 0, Y > 0
+      return uIntegerPi - angle;        //Pi - angle  
+    }
+
+    //should newer get here
+    return 0;
+  }
+
+  if ( X < 0 )    //Y == 0, X < 0
+    return uIntegerPi;  
+
+  return 0;
+}
+
+
+
+
+//----- (00452969) --------------------------------------------------------
+stru193_math::stru193_math()
+{
+  stru193_math *v1; // esi@1
+  char *v2; // edi@1
+  double v3; // ST18_8@2
+  signed int v4; // edx@3
+  int v5; // eax@4
+  int v6; // ecx@4
+  signed int v7; // [sp+20h] [bp-4h]@1
+
+  v1 = this;
+  this->uIntegerDoublePi = 2048;
+  this->uIntegerPi = 1024;
+  this->uIntegerHalfPi = 512;
+  this->uDoublePiMask = 2047;
+  this->uPiMask = 1023;
+  this->uHalfPiMask = 511;
+  this->pTanTable[0] = 0;
+  this->pCosTable[0] = 65536;
+  this->pInvCosTable[0] = 65536;
+  v7 = 1;
+  v2 = (char *)&this->pInvCosTable[1];
+  do
+  {
+    v3 = (double)v7 * 3.141592653589793 * 0.0009765625;
+    *((int *)v2 - 1040) = (signed __int64)(tan(v3) * (double)v1->pCosTable[0] + 0.5);
+    *((int *)v2 - 520) = (signed __int64)(cos(v3) * (double)v1->pCosTable[0] + 0.5);
+    ++v7;
+    *(int *)v2 = (signed __int64)(1.0 / cos(v3) * (double)v1->pCosTable[0] + 0.5);
+    v2 += 4;
+  }
+  while ( v7 < (signed int)v1->uIntegerHalfPi );
+  v4 = v1->uIntegerHalfPi;
+  if ( v4 < 520 )
+  {
+    v5 = (int)&v1->pCosTable[v4];
+    v6 = 520 - v4;
+    do
+    {
+      *(int *)v5 = 0;
+      *(int *)(v5 + 2080) = 0xEFFFFFFFu;
+      *(int *)(v5 - 2080) = 0xEFFFFFFFu;
+      v5 += 4;
+      --v6;
+    }
+    while ( v6 );
+  }
+}
+
+//----- (00452A9E) --------------------------------------------------------
+signed int __fastcall sub_452A9E(signed int a1)
+{
+  signed int result; // eax@2
+  int v2; // edx@3
+  signed int v3; // edi@3
+  signed int v4; // ebx@3
+  int v5; // esi@4
+
+  if ( a1 > 1 )
+  {
+    v2 = 0;
+    v3 = a1;
+    result = 0;
+    v4 = 16;
+    do
+    {
+      result *= 2;
+      v2 = ((unsigned int)v3 >> 30) | 4 * v2;
+      v5 = 2 * result + 1;
+      v3 *= 4;
+      if ( v2 >= (unsigned int)v5 )
+      {
+        ++result;
+        v2 -= v5;
+      }
+      --v4;
+    }
+    while ( v4 );
+    if ( a1 - result * result >= (unsigned int)(result - 1) )
+      ++result;
+  }
+  else
+  {
+    result = a1;
+  }
+  return result;
+}
+
+//----- (00452AE2) --------------------------------------------------------
+int __fastcall MakeColorMaskFromBitDepth(int a1)
+{
+  signed __int64 v1; // qax@1
+
+  v1 = 4294967296i64;
+  if ( a1 > 0 )
+  {
+    do
+    {
+      LODWORD(v1) = HIDWORD(v1) + v1;
+      HIDWORD(v1) *= 2;
+      --a1;
+    }
+    while ( a1 );
+  }
+  return v1;
+}
+
+//----- (00452AF3) --------------------------------------------------------
+void __fastcall fill_pixels_fast(unsigned int a1, unsigned __int16 *pPixels, unsigned int uNumPixels)
+{
+  void *v3; // edi@1
+  unsigned int v4; // eax@1
+  unsigned __int16 *v5; // edi@3
+  unsigned int i; // ecx@3
+
+  v3 = pPixels;
+  v4 = a1 | (a1 << 16);
+  if ( (unsigned __int8)pPixels & 2 )           // first 2 pixels
+  {
+    *pPixels = v4;
+    v3 = pPixels + 1;
+    --uNumPixels;
+  }
+  memset32(v3, v4, uNumPixels >> 1);            // 4 pixels at once
+  v5 = (unsigned __int16 *)((char *)v3 + 4 * (uNumPixels >> 1));
+  for ( i = uNumPixels & 1; i; --i )            // leftover pixels
+  {
+    *v5 = v4;
+    ++v5;
+  }
+}
+
+//----- (00452B2E) --------------------------------------------------------
+int __fastcall GetDiceResult(unsigned int uNumDice, unsigned int uDiceSides)
+{
+  signed int v2; // edi@1
+  int v3; // esi@1
+  int result; // eax@2
+  unsigned int v5; // ebx@4
+
+  v2 = uDiceSides;
+  v3 = 0;
+  if ( uDiceSides )
+  {
+    if ( (signed int)uNumDice > 0 )
+    {
+      v5 = uNumDice;
+      do
+      {
+        --v5;
+        v3 += rand() % v2 + 1;
+      }
+      while ( v5 );
+    }
+    result = v3;
+  }
+  else
+  {
+    result = 0;
+  }
+  return result;
+}
+
+
+//----- (00452B95) --------------------------------------------------------
+void __cdecl SetSomeItemsNames()
+{
+  pSomeItemsNames[0] = pGlobalTXT_LocalizationStrings[568];
+  pSomeItemsNames[1] = pGlobalTXT_LocalizationStrings[271];
+  pSomeItemsNames[2] = pGlobalTXT_LocalizationStrings[272];
+  pSomeItemsNames[3] = pGlobalTXT_LocalizationStrings[273];
+  pSomeItemsNames[4] = pGlobalTXT_LocalizationStrings[274];
+  pSomeItemsNames[5] = pGlobalTXT_LocalizationStrings[275];
+  pSomeItemsNames[6] = pGlobalTXT_LocalizationStrings[276];
+  pSomeItemsNames[7] = pGlobalTXT_LocalizationStrings[277];
+  pSomeItemsNames[8] = pGlobalTXT_LocalizationStrings[278];
+  pSomeItemsNames[9] = pGlobalTXT_LocalizationStrings[279];
+  pSomeItemsNames[10] = pGlobalTXT_LocalizationStrings[280];
+  pSomeItemsNames[11] = pGlobalTXT_LocalizationStrings[281];
+  pSomeItemsNames[12] = pGlobalTXT_LocalizationStrings[282];
+  pSomeItemsNames[13] = pGlobalTXT_LocalizationStrings[143];
+  memset(&stru_5E4C50, 0, sizeof(stru_5E4C50));
+}
+
+//----- (00452C30) --------------------------------------------------------
+char *RemoveQuotes(char *Str)
+{
+  char *v1; // esi@1
+
+  v1 = Str;
+  if ( *Str == '"' )
+  {
+    Str[strlen(Str) - 1] = 0;
+    v1 = Str + 1;
+  }
+  return v1;
+}
+
+//----- (00452C49) --------------------------------------------------------
+void InitializeGameText()
+{
+  //char *v0; // ebx@1
+  char *v1; // eax@3
+  int v2; // ebp@4
+  char v3; // dl@5
+  char *v4; // ecx@5
+  int v5; // esi@9
+  //char **v6; // [sp+10h] [bp-8h]@3
+  signed int v7; // [sp+14h] [bp-4h]@4
+
+  //v0 = 0;
+  if (pGlobalTXT_Raw)
+    pAllocator->FreeChunk(pGlobalTXT_Raw);
+
+  pGlobalTXT_Raw = nullptr;
+  pGlobalTXT_Raw = (char *)pEvents_LOD->LoadRaw("global.txt", 0);
+
+  strtok(pGlobalTXT_Raw, "\r");
+  strtok(nullptr, "\r");
+  v1 = strtok(nullptr, "\r") + 1;
+
+  for (uint i = 0; i < 677; ++i)
+  {
+    char *p = v1;
+    while (*++p != '\t' && *p);
+
+    pGlobalTXT_LocalizationStrings[i] = RemoveQuotes(p + 1);
+
+    v1 = strtok(nullptr, "\r") + 1;
+  }
+
+  aMonthNames[0] = pGlobalTXT_LocalizationStrings[415];
+  aMonthNames[1] = pGlobalTXT_LocalizationStrings[416];
+  aMonthNames[2] = pGlobalTXT_LocalizationStrings[417];
+  pSomeItemsNames[10] = pGlobalTXT_LocalizationStrings[280];
+  aMonthNames[3] = pGlobalTXT_LocalizationStrings[418];
+  pSomeItemsNames[11] = pGlobalTXT_LocalizationStrings[281];
+  aMonthNames[4] = pGlobalTXT_LocalizationStrings[419];
+  pSomeItemsNames[12] = pGlobalTXT_LocalizationStrings[282];
+  aMonthNames[5] = pGlobalTXT_LocalizationStrings[420];
+  pSomeItemsNames[13] = pGlobalTXT_LocalizationStrings[143];
+  aMonthNames[6] = pGlobalTXT_LocalizationStrings[421];
+  aCharacterConditionNames[0] = pGlobalTXT_LocalizationStrings[52];
+  aMonthNames[7] = pGlobalTXT_LocalizationStrings[422];
+  aCharacterConditionNames[1] = pGlobalTXT_LocalizationStrings[241];
+  aMonthNames[8] = pGlobalTXT_LocalizationStrings[423];
+  aCharacterConditionNames[2] = pGlobalTXT_LocalizationStrings[14];
+  aMonthNames[9] = pGlobalTXT_LocalizationStrings[424];
+  aCharacterConditionNames[3] = pGlobalTXT_LocalizationStrings[4];
+  aMonthNames[10] = pGlobalTXT_LocalizationStrings[425];
+  aCharacterConditionNames[4] = pGlobalTXT_LocalizationStrings[69];
+  aMonthNames[11] = pGlobalTXT_LocalizationStrings[426];
+  aCharacterConditionNames[5] = pGlobalTXT_LocalizationStrings[117];
+  pSomeItemsNames[0] = pGlobalTXT_LocalizationStrings[568];
+  aCharacterConditionNames[6] = pGlobalTXT_LocalizationStrings[166];
+  aCharacterConditionNames[8] = pGlobalTXT_LocalizationStrings[166];
+  aCharacterConditionNames[10] = pGlobalTXT_LocalizationStrings[166];
+  pSomeItemsNames[5] = pGlobalTXT_LocalizationStrings[275];
+  aCharacterConditionNames[12] = pGlobalTXT_LocalizationStrings[162];
+  pSomeItemsNames[6] = pGlobalTXT_LocalizationStrings[276];
+  aCharacterConditionNames[13] = pGlobalTXT_LocalizationStrings[231];
+  pSomeItemsNames[7] = pGlobalTXT_LocalizationStrings[277];
+  aCharacterConditionNames[14] = pGlobalTXT_LocalizationStrings[58];
+  pSomeItemsNames[8] = pGlobalTXT_LocalizationStrings[278];
+  aCharacterConditionNames[15] = pGlobalTXT_LocalizationStrings[220];
+  pSomeItemsNames[1] = pGlobalTXT_LocalizationStrings[271];
+  pSomeItemsNames[2] = pGlobalTXT_LocalizationStrings[272];
+  pSomeItemsNames[3] = pGlobalTXT_LocalizationStrings[273];
+  pSomeItemsNames[4] = pGlobalTXT_LocalizationStrings[274];
+  pSomeItemsNames[9] = pGlobalTXT_LocalizationStrings[279];
+  aCharacterConditionNames[7] = pGlobalTXT_LocalizationStrings[65];
+  aCharacterConditionNames[9] = pGlobalTXT_LocalizationStrings[65];
+  aCharacterConditionNames[11] = pGlobalTXT_LocalizationStrings[65];
+  aCharacterConditionNames[16] = pGlobalTXT_LocalizationStrings[76];
+  pClassNames[9] = pGlobalTXT_LocalizationStrings[26];
+  pClassNames[10] = pGlobalTXT_LocalizationStrings[432];
+  pClassNames[11] = pGlobalTXT_LocalizationStrings[27];
+  pClassNames[12] = pGlobalTXT_LocalizationStrings[262];
+  pClassNames[13] = pGlobalTXT_LocalizationStrings[263];
+  pClassNames[14] = pGlobalTXT_LocalizationStrings[264];
+  pClassNames[15] = pGlobalTXT_LocalizationStrings[28];
+  pClassNames[16] = pGlobalTXT_LocalizationStrings[265];
+  pClassNames[17] = pGlobalTXT_LocalizationStrings[267];
+  pClassNames[18] = pGlobalTXT_LocalizationStrings[119];
+  pClassNames[19] = pGlobalTXT_LocalizationStrings[124];
+  pClassNames[20] = pGlobalTXT_LocalizationStrings[31];
+  pClassNames[21] = pGlobalTXT_LocalizationStrings[370];
+  pClassNames[22] = pGlobalTXT_LocalizationStrings[33];
+  aCharacterConditionNames[17] = pGlobalTXT_LocalizationStrings[601];
+  pClassNames[23] = pGlobalTXT_LocalizationStrings[40];
+  aCharacterConditionNames[18] = pGlobalTXT_LocalizationStrings[98];
+  pClassNames[24] = pGlobalTXT_LocalizationStrings[256];
+  pClassNames[0] = pGlobalTXT_LocalizationStrings[253];
+  pClassNames[25] = pGlobalTXT_LocalizationStrings[257];
+  pClassNames[1] = pGlobalTXT_LocalizationStrings[254];
+  pClassNames[26] = pGlobalTXT_LocalizationStrings[44];
+  pClassNames[2] = pGlobalTXT_LocalizationStrings[255];
+  pClassNames[27] = pGlobalTXT_LocalizationStrings[46];
+  pClassNames[3] = pGlobalTXT_LocalizationStrings[2];
+  pClassNames[28] = pGlobalTXT_LocalizationStrings[268];
+  pClassNames[4] = pGlobalTXT_LocalizationStrings[307];
+  pClassNames[29] = pGlobalTXT_LocalizationStrings[269];
+  pClassNames[5] = pGlobalTXT_LocalizationStrings[114];
+  pClassNames[30] = pGlobalTXT_LocalizationStrings[270];
+  pClassNames[6] = pGlobalTXT_LocalizationStrings[3];
+  pClassNames[31] = pGlobalTXT_LocalizationStrings[48];
+  pClassNames[7] = pGlobalTXT_LocalizationStrings[13];
+  pClassNames[32] = pGlobalTXT_LocalizationStrings[259];
+  pClassNames[8] = pGlobalTXT_LocalizationStrings[21];
+  pClassNames[33] = pGlobalTXT_LocalizationStrings[260];
+  pClassNames[34] = pGlobalTXT_LocalizationStrings[261];
+  pClassNames[35] = pGlobalTXT_LocalizationStrings[49];
+  pSkillNames[0] = pGlobalTXT_LocalizationStrings[271];
+  pSkillNames[1] = pGlobalTXT_LocalizationStrings[272];
+  pSkillNames[2] = pGlobalTXT_LocalizationStrings[273];
+  pSkillNames[3] = pGlobalTXT_LocalizationStrings[274];
+  pSkillNames[4] = pGlobalTXT_LocalizationStrings[275];
+  pSkillNames[5] = pGlobalTXT_LocalizationStrings[276];
+  pSkillNames[6] = pGlobalTXT_LocalizationStrings[277];
+  pSkillNames[7] = pGlobalTXT_LocalizationStrings[278];
+  pSkillNames[23] = pGlobalTXT_LocalizationStrings[294];
+  pSkillNames[9] = pGlobalTXT_LocalizationStrings[280];
+  pSkillNames[24] = pGlobalTXT_LocalizationStrings[295];
+  pSkillNames[10] = pGlobalTXT_LocalizationStrings[281];
+  pSkillNames[25] = pGlobalTXT_LocalizationStrings[296];
+  pSkillNames[11] = pGlobalTXT_LocalizationStrings[282];
+  pSkillNames[26] = pGlobalTXT_LocalizationStrings[297];
+  pSkillNames[12] = pGlobalTXT_LocalizationStrings[283];
+  pSkillNames[27] = pGlobalTXT_LocalizationStrings[298];
+  pSkillNames[13] = pGlobalTXT_LocalizationStrings[284];
+  pSkillNames[28] = pGlobalTXT_LocalizationStrings[299];
+  pSkillNames[14] = pGlobalTXT_LocalizationStrings[285];
+  pSkillNames[29] = pGlobalTXT_LocalizationStrings[300];
+  pSkillNames[15] = pGlobalTXT_LocalizationStrings[286];
+  pSkillNames[30] = pGlobalTXT_LocalizationStrings[50];
+  pSkillNames[16] = pGlobalTXT_LocalizationStrings[289];
+  pSkillNames[31] = pGlobalTXT_LocalizationStrings[77];
+  aDayNames[0] = pGlobalTXT_LocalizationStrings[145];
+  pSkillNames[17] = pGlobalTXT_LocalizationStrings[290];
+  pSkillNames[32] = pGlobalTXT_LocalizationStrings[88];
+  aDayNames[1] = pGlobalTXT_LocalizationStrings[230];
+  pSkillNames[18] = pGlobalTXT_LocalizationStrings[291];
+  pSkillNames[33] = pGlobalTXT_LocalizationStrings[89];
+  aDayNames[2] = pGlobalTXT_LocalizationStrings[243];
+  pSkillNames[19] = pGlobalTXT_LocalizationStrings[287];
+  pSkillNames[34] = pGlobalTXT_LocalizationStrings[90];
+  aDayNames[3] = pGlobalTXT_LocalizationStrings[227];
+  pSkillNames[20] = pGlobalTXT_LocalizationStrings[288];
+  pSkillNames[35] = pGlobalTXT_LocalizationStrings[95];
+  aDayNames[4] = pGlobalTXT_LocalizationStrings[91];
+  pSkillNames[21] = pGlobalTXT_LocalizationStrings[292];
+  pSkillNames[36] = pGlobalTXT_LocalizationStrings[301];
+  aDayNames[5] = pGlobalTXT_LocalizationStrings[188];
+  pSkillNames[8] = pGlobalTXT_LocalizationStrings[279];
+  pSkillNames[22] = pGlobalTXT_LocalizationStrings[293];
+  pSkillNames[37] = pGlobalTXT_LocalizationStrings[153];
+  aDayNames[6] = pGlobalTXT_LocalizationStrings[222];
+  aNPCProfessionNames[0] = pGlobalTXT_LocalizationStrings[153];
+  aNPCProfessionNames[1] = pGlobalTXT_LocalizationStrings[308];
+  aNPCProfessionNames[2] = pGlobalTXT_LocalizationStrings[309];
+  aNPCProfessionNames[3] = pGlobalTXT_LocalizationStrings[7];
+  aNPCProfessionNames[4] = pGlobalTXT_LocalizationStrings[306];
+  aNPCProfessionNames[5] = pGlobalTXT_LocalizationStrings[310];
+  aNPCProfessionNames[6] = pGlobalTXT_LocalizationStrings[311];
+  aNPCProfessionNames[7] = pGlobalTXT_LocalizationStrings[312];
+  aSpellSchoolNames[0] = pGlobalTXT_LocalizationStrings[87];
+  aNPCProfessionNames[8] = pGlobalTXT_LocalizationStrings[313];
+  aSpellSchoolNames[1] = pGlobalTXT_LocalizationStrings[6];
+  aNPCProfessionNames[9] = pGlobalTXT_LocalizationStrings[314];
+  aNPCProfessionNames[21] = pGlobalTXT_LocalizationStrings[293];
+  aNPCProfessionNames[10] = pGlobalTXT_LocalizationStrings[105];
+  aSpellSchoolNames[2] = pGlobalTXT_LocalizationStrings[240];
+  aNPCProfessionNames[11] = pGlobalTXT_LocalizationStrings[315];
+  aNPCProfessionNames[22] = pGlobalTXT_LocalizationStrings[324];
+  aNPCProfessionNames[12] = pGlobalTXT_LocalizationStrings[316];
+  aSpellSchoolNames[3] = pGlobalTXT_LocalizationStrings[70];
+  aNPCProfessionNames[13] = pGlobalTXT_LocalizationStrings[317];
+  aNPCProfessionNames[23] = pGlobalTXT_LocalizationStrings[498];
+  aSpellSchoolNames[4] = pGlobalTXT_LocalizationStrings[214];
+  aNPCProfessionNames[14] = pGlobalTXT_LocalizationStrings[115];
+  aNPCProfessionNames[24] = pGlobalTXT_LocalizationStrings[525];
+  aSpellSchoolNames[5] = pGlobalTXT_LocalizationStrings[142];
+  aNPCProfessionNames[15] = pGlobalTXT_LocalizationStrings[318];
+  aNPCProfessionNames[25] = pGlobalTXT_LocalizationStrings[327];
+  aSpellSchoolNames[6] = pGlobalTXT_LocalizationStrings[29];
+  aNPCProfessionNames[16] = pGlobalTXT_LocalizationStrings[319];
+  aNPCProfessionNames[26] = pGlobalTXT_LocalizationStrings[328];
+  aSpellSchoolNames[7] = pGlobalTXT_LocalizationStrings[133];
+  aNPCProfessionNames[17] = pGlobalTXT_LocalizationStrings[320];
+  aNPCProfessionNames[27] = pGlobalTXT_LocalizationStrings[329];
+  aSpellSchoolNames[8] = pGlobalTXT_LocalizationStrings[54];
+  aNPCProfessionNames[18] = pGlobalTXT_LocalizationStrings[321];
+  aNPCProfessionNames[28] = pGlobalTXT_LocalizationStrings[330];
+  aAMPMNames[0] = pGlobalTXT_LocalizationStrings[472];
+  aNPCProfessionNames[19] = pGlobalTXT_LocalizationStrings[322];
+  aNPCProfessionNames[29] = pGlobalTXT_LocalizationStrings[331];
+  aAMPMNames[1] = pGlobalTXT_LocalizationStrings[473];
+  aNPCProfessionNames[20] = pGlobalTXT_LocalizationStrings[323];
+  aNPCProfessionNames[30] = pGlobalTXT_LocalizationStrings[332];
+  aNPCProfessionNames[31] = pGlobalTXT_LocalizationStrings[333];
+  aNPCProfessionNames[32] = pGlobalTXT_LocalizationStrings[334];
+  aNPCProfessionNames[33] = pGlobalTXT_LocalizationStrings[335];
+  aNPCProfessionNames[34] = pGlobalTXT_LocalizationStrings[336];
+  aNPCProfessionNames[35] = pGlobalTXT_LocalizationStrings[337];
+  aNPCProfessionNames[36] = pGlobalTXT_LocalizationStrings[338];
+  aNPCProfessionNames[37] = pGlobalTXT_LocalizationStrings[339];
+  aNPCProfessionNames[38] = pGlobalTXT_LocalizationStrings[340];
+  aNPCProfessionNames[39] = pGlobalTXT_LocalizationStrings[341];
+  aNPCProfessionNames[40] = pGlobalTXT_LocalizationStrings[342];
+  aNPCProfessionNames[56] = pGlobalTXT_LocalizationStrings[21];
+  aNPCProfessionNames[41] = pGlobalTXT_LocalizationStrings[343];
+  aNPCProfessionNames[57] = pGlobalTXT_LocalizationStrings[600];
+  aNPCProfessionNames[42] = pGlobalTXT_LocalizationStrings[596];
+  aNPCProfessionNames[58] = pGlobalTXT_LocalizationStrings[370];
+  aNPCProfessionNames[43] = pGlobalTXT_LocalizationStrings[345];
+  aMoonPhaseNames[0] = pGlobalTXT_LocalizationStrings[150];
+  aNPCProfessionNames[44] = pGlobalTXT_LocalizationStrings[346];
+  aMoonPhaseNames[1] = pGlobalTXT_LocalizationStrings[171];
+  aNPCProfessionNames[45] = pGlobalTXT_LocalizationStrings[347];
+  aMoonPhaseNames[2] = pGlobalTXT_LocalizationStrings[102];
+  aNPCProfessionNames[46] = pGlobalTXT_LocalizationStrings[348];
+  aMoonPhaseNames[3] = pGlobalTXT_LocalizationStrings[169];
+  aNPCProfessionNames[47] = pGlobalTXT_LocalizationStrings[349];
+  aMoonPhaseNames[4] = pGlobalTXT_LocalizationStrings[92];
+  aNPCProfessionNames[48] = pGlobalTXT_LocalizationStrings[350];
+  aAttributeNames[0] = pGlobalTXT_LocalizationStrings[144];
+  aNPCProfessionNames[49] = pGlobalTXT_LocalizationStrings[597];
+  aAttributeNames[1] = pGlobalTXT_LocalizationStrings[116];
+  aNPCProfessionNames[50] = pGlobalTXT_LocalizationStrings[352];
+  aAttributeNames[2] = pGlobalTXT_LocalizationStrings[163];
+  aNPCProfessionNames[51] = pGlobalTXT_LocalizationStrings[353];
+  aAttributeNames[3] = pGlobalTXT_LocalizationStrings[75];
+  aNPCProfessionNames[52] = pGlobalTXT_LocalizationStrings[598];
+  aAttributeNames[4] = pGlobalTXT_LocalizationStrings[1];
+  aNPCProfessionNames[53] = pGlobalTXT_LocalizationStrings[344];
+  aAttributeNames[5] = pGlobalTXT_LocalizationStrings[211];
+  aNPCProfessionNames[54] = pGlobalTXT_LocalizationStrings[26];
+  aAttributeNames[6] = pGlobalTXT_LocalizationStrings[136];
+  aNPCProfessionNames[55] = pGlobalTXT_LocalizationStrings[599];
+  aSpellNames[14] = pGlobalTXT_LocalizationStrings[279];
+  aSpellNames[33] = pGlobalTXT_LocalizationStrings[279];
+  aSpellNames[9] = pGlobalTXT_LocalizationStrings[440];
+  aSpellNames[34] = pGlobalTXT_LocalizationStrings[442];
+  aSpellNames[0] = pGlobalTXT_LocalizationStrings[202];
+  aSpellNames[10] = pGlobalTXT_LocalizationStrings[218];
+  aSpellNames[20] = pGlobalTXT_LocalizationStrings[202];
+  aSpellNames[35] = pGlobalTXT_LocalizationStrings[235];
+  aSpellNames[11] = pGlobalTXT_LocalizationStrings[217];
+  aSpellNames[21] = pGlobalTXT_LocalizationStrings[443];
+  aSpellNames[36] = pGlobalTXT_LocalizationStrings[246];
+  aSpellNames[12] = pGlobalTXT_LocalizationStrings[213];
+  aSpellNames[24] = pGlobalTXT_LocalizationStrings[221];
+  aSpellNames[37] = pGlobalTXT_LocalizationStrings[247];
+  aSpellNames[13] = pGlobalTXT_LocalizationStrings[462];
+  aSpellNames[26] = pGlobalTXT_LocalizationStrings[228];
+  aSpellNames[38] = pGlobalTXT_LocalizationStrings[248];
+  aSpellNames[15] = pGlobalTXT_LocalizationStrings[442];
+  aSpellNames[28] = pGlobalTXT_LocalizationStrings[440];
+  aSpellNames[39] = pGlobalTXT_LocalizationStrings[674];
+  aSpellNames[16] = pGlobalTXT_LocalizationStrings[452];
+  aSpellNames[29] = pGlobalTXT_LocalizationStrings[213];
+  aSpellNames[40] = pGlobalTXT_LocalizationStrings[249];
+  aSpellNames[2] = pGlobalTXT_LocalizationStrings[219];
+  aSpellNames[17] = pGlobalTXT_LocalizationStrings[194];
+  aSpellNames[30] = pGlobalTXT_LocalizationStrings[229];
+  aSpellNames[41] = pGlobalTXT_LocalizationStrings[258];
+  aSpellNames[5] = pGlobalTXT_LocalizationStrings[454];
+  aSpellNames[3] = pGlobalTXT_LocalizationStrings[215];
+  aSpellNames[7] = pGlobalTXT_LocalizationStrings[455];
+  aSpellNames[18] = pGlobalTXT_LocalizationStrings[456];
+  aSpellNames[31] = pGlobalTXT_LocalizationStrings[233];
+  aSpellNames[42] = pGlobalTXT_LocalizationStrings[194];
+  aSpellNames[6] = pGlobalTXT_LocalizationStrings[24];
+  aSpellNames[25] = pGlobalTXT_LocalizationStrings[24];
+  aSpellNames[1] = pGlobalTXT_LocalizationStrings[204];
+  aSpellNames[4] = pGlobalTXT_LocalizationStrings[208];
+  aSpellNames[8] = pGlobalTXT_LocalizationStrings[441];
+  aSpellNames[19] = pGlobalTXT_LocalizationStrings[453];
+  aSpellNames[22] = pGlobalTXT_LocalizationStrings[204];
+  aSpellNames[23] = pGlobalTXT_LocalizationStrings[208];
+  aSpellNames[27] = pGlobalTXT_LocalizationStrings[441];
+  aSpellNames[32] = pGlobalTXT_LocalizationStrings[234];
+  aSpellNames[43] = pGlobalTXT_LocalizationStrings[657];
+}
+
+
+
+
+
+
+
+//----- (00453E6D) --------------------------------------------------------
+void StorylineText::Initialize()
+{
+  char *v1; // ebx@1
+  StorylineText *v2; // esi@1
+  char *v3; // ecx@4
+  char v4; // dl@5
+  char *v5; // eax@5
+  int v6; // esi@9
+  int v7; // [sp+Ch] [bp-10h]@3
+  int v8; // [sp+10h] [bp-Ch]@4
+  char *v9; // [sp+14h] [bp-8h]@4
+  int Str; // [sp+18h] [bp-4h]@3
+
+  v1 = 0;
+  v2 = this;
+  if ( pHistoryTXT_Raw )
+    pAllocator->FreeChunk(pHistoryTXT_Raw);
+  pHistoryTXT_Raw = 0;
+  pHistoryTXT_Raw = (char *)pEvents_LOD->LoadRaw("history.txt", 0);
+  strtok(pHistoryTXT_Raw, "\r");
+  Str = (int)&v2->field_4[4];
+  v7 = 29;
+  do
+  {
+    v9 = v1;
+    v8 = (signed int)v1;
+    v3 = strtok(v1, "\r");
+    do
+    {
+      v4 = *v3;
+      v5 = 0;
+      if ( *v3 != 9 )
+      {
+        v1 = 0;
+        do
+        {
+          if ( !v4 )
+            break;
+          ++v5;
+          v4 = v3[(int)v5];
+        }
+        while ( v4 != 9 );
+      }
+      v6 = (int)&v3[(int)v5];
+      if ( v3[(int)v5] == (char)v1 )
+        v8 = 1;
+      *(char *)v6 = (char)v1;
+      if ( v5 == v1 )
+      {
+        v8 = 1;
+      }
+      else
+      {
+        if ( v9 == (char *)1 )
+        {
+          *(char **)(Str - 8) = RemoveQuotes(v3);
+        }
+        else
+        {
+          if ( v9 == (char *)2 )
+          {
+            *(char *)Str = atoi(v3);
+          }
+          else
+          {
+            if ( v9 - 2 == (char *)1 )
+              *(char * *)(Str - 4) = RemoveQuotes(v3);
+          }
+        }
+      }
+      ++v9;
+      v3 = (char *)(v6 + 1);
+    }
+    while ( (signed int)(v9 - 1) <= 3 && (char *)v8 == v1 );
+    Str += 12;
+    --v7;
+  }
+  while ( v7 );
+}
+
+//----- (00453F62) --------------------------------------------------------
+void MapStats::Initialize()
+{
+  MapStats *v1; // esi@1
+  unsigned int v2; // ebx@3
+  char *v3; // eax@4
+  char *v4; // edi@4
+  char v5; // cl@5
+  int v6; // eax@5
+  size_t v7; // eax@32
+  size_t v8; // eax@35
+  size_t v9; // eax@42
+  size_t v10; // eax@45
+  size_t v11; // eax@52
+  size_t v12; // eax@55
+  char Str[32]; // [sp+Ch] [bp-34h]@30
+  char *v14; // [sp+2Ch] [bp-14h]@9
+  int v15; // [sp+30h] [bp-10h]@4
+  int v16; // [sp+34h] [bp-Ch]@4
+  unsigned int v17; // [sp+38h] [bp-8h]@30
+  MapStats *v18; // [sp+3Ch] [bp-4h]@30
+
+  v1 = this;
+  if ( pMapStatsTXT_Raw )
+    pAllocator->FreeChunk(pMapStatsTXT_Raw);
+  pMapStatsTXT_Raw = 0;
+  pMapStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("MapStats.txt", 0);
+  strtok(pMapStatsTXT_Raw, "\r");
+  strtok(0, "\r");
+  strtok(0, "\r");
+  v2 = 1;
+  v1->uNumMaps = 77;
+  do
+  {
+    v3 = strtok(0, "\r");
+    v16 = 0;
+    v15 = 0;
+    v4 = v3;
+    do
+    {
+      v5 = *v4;
+      v6 = 0;
+      while ( v5 != 9 && v5 )
+      {
+        ++v6;
+        v5 = v4[v6];
+      }
+      v14 = &v4[v6];
+      if ( !v4[v6] )
+        v15 = 1;
+      v4[v6] = 0;
+      if ( v6 )
+      {
+        switch ( v16 )
+        {
+          case 1:
+            v1->pInfos[v2].pName = (char *)RemoveQuotes(v4);
+            break;
+          case 2:
+            v1->pInfos[v2].pFilename = (char *)RemoveQuotes(v4);
+            break;
+          case 3:
+            v1->pInfos[v2].uNumResets = atoi(v4);
+            break;
+          case 4:
+            v1->pInfos[v2].uFirstVisitedAt = atoi(v4);
+            break;
+          case 5:
+            v1->pInfos[v2]._per = atoi(v4);
+            break;
+          case 6:
+            v1->pInfos[v2].uRespawnIntervalDays = atoi(v4);
+            break;
+          case 7:
+            v1->pInfos[v2]._alert_days = atoi(v4);
+            break;
+          case 8:
+            v1->pInfos[v2]._steal_perm = atoi(v4);
+            break;
+          case 9:
+            v1->pInfos[v2].field_2D = atoi(v4);
+            break;
+          case 10:
+            v1->pInfos[v2].field_2E = atoi(v4);
+            break;
+          case 11:
+            v1->pInfos[v2].field_2F = atoi(v4);
+            break;
+          case 12:
+            v1->pInfos[v2].field_30 = atoi(v4);
+            break;
+          case 13:
+            v1->pInfos[v2].field_31 = atoi(v4);
+            break;
+          case 14:
+            v1->pInfos[v2].field_32 = atoi(v4);
+            break;
+          case 15:
+            v1->pInfos[v2].field_33 = atoi(v4);
+            break;
+          case 16:
+            v1->pInfos[v2].pEncounterMonster1Texture = (char *)RemoveQuotes(v4);
+            break;
+          case 18:
+            v1->pInfos[v2].field_34 = atoi(v4);
+            break;
+          case 19:
+            v18 = (MapStats *)((char *)v1 + 68 * v2);
+            v18->pInfos[0].uEncounterMonster1AtLeast = 1;
+            strcpy(Str, v4);
+            v17 = 0;
+            if ( strlen(Str) )
+            {
+              while ( Str[v17] != 45 )
+              {
+                ++v17;
+                v7 = strlen(Str);
+                if ( v17 >= v7 )
+                  goto LABEL_35;
+              }
+              Str[v17] = 0;
+              v18->pInfos[0].uEncounterMonster1AtLeast = atoi(Str);
+            }
+LABEL_35:
+            v8 = strlen(Str);
+            if ( v17 == v8 )
+              v18->pInfos[0].uEncounterMonster1AtMost = atoi(&v4[v17 + 1]);
+            else
+              v18->pInfos[0].uEncounterMonster1AtMost = v18->pInfos[0].uEncounterMonster1AtLeast;
+            break;
+          case 20:
+            v1->pInfos[v2].pEncounterMonster2Texture = (char *)RemoveQuotes(v4);
+            break;
+          case 22:
+            v1->pInfos[v2].field_37 = atoi(v4);
+            break;
+          case 23:
+            v18 = (MapStats *)((char *)v1 + 68 * v2);
+            v18->pInfos[0].uEncounterMonster2AtLeast = 1;
+            strcpy(Str, v4);
+            v17 = 0;
+            if ( strlen(Str) )
+            {
+              while ( Str[v17] != 45 )
+              {
+                ++v17;
+                v9 = strlen(Str);
+                if ( v17 >= v9 )
+                  goto LABEL_45;
+              }
+              Str[v17] = 0;
+              v18->pInfos[0].uEncounterMonster2AtLeast = atoi(Str);
+            }
+LABEL_45:
+            v10 = strlen(Str);
+            if ( v17 == v10 )
+              v18->pInfos[0].uEncounterMonster2AtMost = atoi(&v4[v17 + 1]);
+            else
+              v18->pInfos[0].uEncounterMonster2AtMost = v18->pInfos[0].uEncounterMonster2AtLeast;
+            break;
+          case 24:
+            v1->pInfos[v2].pEncounterMonster3Texture = (char *)RemoveQuotes(v4);
+            break;
+          case 26:
+            v1->pInfos[v2].field_3A = atoi(v4);
+            break;
+          case 27:
+            v18 = (MapStats *)((char *)v1 + 68 * v2);
+            v18->pInfos[0].uEncounterMonster3AtLeast = 1;
+            strcpy(Str, v4);
+            v17 = 0;
+            if ( strlen(Str) )
+            {
+              while ( Str[v17] != 45 )
+              {
+                ++v17;
+                v11 = strlen(Str);
+                if ( v17 >= v11 )
+                  goto LABEL_55;
+              }
+              Str[v17] = 0;
+              v18->pInfos[0].uEncounterMonster3AtLeast = atoi(Str);
+            }
+LABEL_55:
+            v12 = strlen(Str);
+            if ( v17 == v12 )
+              v18->pInfos[0].uEncounterMonster3AtMost = atoi(&v4[v17 + 1]);
+            else
+              v18->pInfos[0].uEncounterMonster3AtMost = v18->pInfos[0].uEncounterMonster3AtLeast;
+            break;
+          case 28:
+            v1->pInfos[v2].uRedbookTrackID = atoi(v4);
+            break;
+          case 29:
+            if ( strcmp(v4, "GENERIC") )
+            {
+              if ( strcmp(v4, "PADDEDCELL") )
+              {
+                if ( strcmp(v4, "ROOM") )
+                {
+                  if ( strcmp(v4, "BATHROOM") )
+                  {
+                    if ( strcmp(v4, "LIVINGROOM") )
+                    {
+                      if ( strcmp(v4, "STONEROOM") )
+                      {
+                        if ( strcmp(v4, "AUDITORIUM") )
+                        {
+                          if ( strcmp(v4, "CONCERTHALL") )
+                          {
+                            if ( strcmp(v4, "CAVE") )
+                            {
+                              if ( strcmp(v4, "ARENA") )
+                              {
+                                if ( strcmp(v4, "HANGAR") )
+                                {
+                                  if ( strcmp(v4, "CARPETEDHALLWAY") )
+                                  {
+                                    if ( strcmp(v4, "HALLWAY") )
+                                    {
+                                      if ( strcmp(v4, "STONECORRIDOR") )
+                                      {
+                                        if ( strcmp(v4, "ALLEY") )
+                                        {
+                                          if ( strcmp(v4, "FOREST") )
+                                          {
+                                            if ( strcmp(v4, "CITY") )
+                                            {
+                                              if ( strcmp(v4, "MOUNTAINS") )
+                                              {
+                                                if ( strcmp(v4, "QUARRY") )
+                                                {
+                                                  if ( strcmp(v4, "PLAIN") )
+                                                  {
+                                                    if ( strcmp(v4, "PARKINGLOT") )
+                                                    {
+                                                      if ( strcmp(v4, "SEWERPIPE") )
+                                                      {
+                                                        if ( strcmp(v4, "UNDERWATER") )
+                                                        {
+                                                          if ( strcmp(v4, "DRUGGED") )
+                                                          {
+                                                            if ( strcmp(v4, "DIZZY") )
+                                                            {
+                                                              if ( strcmp(v4, "PSYCHOTIC") )
+                                                                v1->pInfos[v2].uEAXEnv = 26;
+                                                              else
+                                                                v1->pInfos[v2].uEAXEnv = 25;
+                                                            }
+                                                            else
+                                                            {
+                                                              v1->pInfos[v2].uEAXEnv = 24;
+                                                            }
+                                                          }
+                                                          else
+                                                          {
+                                                            v1->pInfos[v2].uEAXEnv = 23;
+                                                          }
+                                                        }
+                                                        else
+                                                        {
+                                                          v1->pInfos[v2].uEAXEnv = 22;
+                                                        }
+                                                      }
+                                                      else
+                                                      {
+                                                        v1->pInfos[v2].uEAXEnv = 21;
+                                                      }
+                                                    }
+                                                    else
+                                                    {
+                                                      v1->pInfos[v2].uEAXEnv = 20;
+                                                    }
+                                                  }
+                                                  else
+                                                  {
+                                                    v1->pInfos[v2].uEAXEnv = 19;
+                                                  }
+                                                }
+                                                else
+                                                {
+                                                  v1->pInfos[v2].uEAXEnv = 18;
+                                                }
+                                              }
+                                              else
+                                              {
+                                                v1->pInfos[v2].uEAXEnv = 17;
+                                              }
+                                            }
+                                            else
+                                            {
+                                              v1->pInfos[v2].uEAXEnv = 16;
+                                            }
+                                          }
+                                          else
+                                          {
+                                            v1->pInfos[v2].uEAXEnv = 15;
+                                          }
+                                        }
+                                        else
+                                        {
+                                          v1->pInfos[v2].uEAXEnv = 14;
+                                        }
+                                      }
+                                      else
+                                      {
+                                        v1->pInfos[v2].uEAXEnv = 13;
+                                      }
+                                    }
+                                    else
+                                    {
+                                      v1->pInfos[v2].uEAXEnv = 12;
+                                    }
+                                  }
+                                  else
+                                  {
+                                    v1->pInfos[v2].uEAXEnv = 11;
+                                  }
+                                }
+                                else
+                                {
+                                  v1->pInfos[v2].uEAXEnv = 10;
+                                }
+                              }
+                              else
+                              {
+                                v1->pInfos[v2].uEAXEnv = 9;
+                              }
+                            }
+                            else
+                            {
+                              v1->pInfos[v2].uEAXEnv = 8;
+                            }
+                          }
+                          else
+                          {
+                            v1->pInfos[v2].uEAXEnv = 7;
+                          }
+                        }
+                        else
+                        {
+                          v1->pInfos[v2].uEAXEnv = 6;
+                        }
+                      }
+                      else
+                      {
+                        v1->pInfos[v2].uEAXEnv = 5;
+                      }
+                    }
+                    else
+                    {
+                      v1->pInfos[v2].uEAXEnv = 4;
+                    }
+                  }
+                  else
+                  {
+                    v1->pInfos[v2].uEAXEnv = 3;
+                  }
+                }
+                else
+                {
+                  v1->pInfos[v2].uEAXEnv = 2;
+                }
+              }
+              else
+              {
+                v1->pInfos[v2].uEAXEnv = 1;
+              }
+            }
+            else
+            {
+              v1->pInfos[v2].uEAXEnv = 0;
+            }
+            break;
+          default:
+            break;
+        }
+      }
+      else
+      {
+        v15 = 1;
+      }
+      ++v16;
+      v4 = v14 + 1;
+    }
+    while ( v16 - 1 <= 29 && !v15 );
+    ++v2;
+  }
+  while ( (signed int)v2 < 77 );
+  v1->uNumMaps = v2;
+}
+// 453F62: using guessed type char Str[32];
+
+
+
+
+
+
+//----- (004547A3) --------------------------------------------------------
+unsigned int MapStats::GetMapInfo(const char *Str2)
+{
+  MapStats *v2; // esi@1
+  unsigned int v3; // edi@1
+  const char **v4; // ebx@2
+  unsigned int result; // eax@6
+
+  v2 = this;
+  v3 = 1;
+  if ( (signed int)this->uNumMaps <= 1 )
+  {
+LABEL_6:
+    result = 0;
+  }
+  else
+  {
+    v4 = (const char **)&this->pInfos[1].pFilename;
+    while ( !*v4 || _strcmpi(*v4, Str2) )
+    {
+      ++v3;
+      v4 += 17;
+      if ( (signed int)v3 >= (signed int)v2->uNumMaps )
+        goto LABEL_6;
+    }
+    result = v3;
+  }
+  return result;
+}
+
+//----- (004547E4) --------------------------------------------------------
+void FactionTable::Initialize()
+{
+  char *v1; // ebx@1
+  char *v2; // eax@4
+  signed int v3; // edi@4
+  int v4; // ebp@4
+  char v5; // dl@5
+  char *v6; // ecx@5
+  int v7; // esi@9
+  signed int v8; // [sp+4h] [bp-Ch]@3
+  signed int v9; // [sp+8h] [bp-8h]@4
+  FactionTable *v10; // [sp+Ch] [bp-4h]@1
+
+  v1 = 0;
+  v10 = this;
+  if ( pHostileTXT_Raw )
+    pAllocator->FreeChunk(pHostileTXT_Raw);
+  pHostileTXT_Raw = 0;
+  pHostileTXT_Raw = (char *)pEvents_LOD->LoadRaw("hostile.txt", 0);
+  strtok(pHostileTXT_Raw, "\r");
+  v8 = 0;
+  do
+  {
+    v2 = strtok(v1, "\r") + 1;
+    v3 = 0;
+    v9 = (signed int)v1;
+    v4 = (int)((char *)&v10[-7] + v8 - 5);
+    do
+    {
+      v5 = *v2;
+      v6 = 0;
+      if ( *v2 != 9 )
+      {
+        v1 = 0;
+        do
+        {
+          if ( !v5 )
+            break;
+          ++v6;
+          v5 = v2[(int)v6];
+        }
+        while ( v5 != 9 );
+      }
+      v7 = (int)&v2[(int)v6];
+      if ( v2[(int)v6] == (char)v1 )
+        v9 = 1;
+      *(char *)v7 = (char)v1;
+      if ( v6 == v1 )
+      {
+        v9 = 1;
+      }
+      else
+      {
+        if ( v3 >= 1 && v3 <= 90 )
+          *(char *)v4 = atoi(v2);
+      }
+      ++v3;
+      v4 += 89;
+      v2 = (char *)(v7 + 1);
+    }
+    while ( v3 - 1 <= 90 && (char *)v9 == v1 );
+    ++v8;
+  }
+  while ( v8 < 89 );
+
+  if ( pHostileTXT_Raw != v1 )
+  {
+    pAllocator->FreeChunk(pHostileTXT_Raw);
+    pHostileTXT_Raw = v1;
+  }
+}
+
+//----- (004548E2) --------------------------------------------------------
+unsigned int __fastcall ParseSpellType(FrameTableTxtLine *a1, int a2)
+{
+  int v2; // edi@1
+  int v3; // esi@1
+  unsigned int result; // eax@1
+  std::string v5; // [sp-18h] [bp-28h]@75
+  const char *v6; // [sp-8h] [bp-18h]@75
+  signed int v7; // [sp-4h] [bp-14h]@3
+  std::string *v8; // [sp+8h] [bp-8h]@75
+  int a3; // [sp+Fh] [bp-1h]@75
+
+  v2 = (int)a1;
+  v3 = a2;
+  result = (int)a1->pProperties[0];
+  if ( result )
+  {
+    if ( !_strcmpi((const char *)result, "Dispel") )
+    {
+      v7 = 80;
+LABEL_71:
+      result = v7;
+LABEL_76:
+      ++*(int *)v3;
+      return result;
+    }
+    if ( _strcmpi(*(const char **)(v2 + 4), "Day") )
+    {
+      if ( _strcmpi(*(const char **)(v2 + 4), "Hour") )
+      {
+        if ( _strcmpi(*(const char **)(v2 + 4), "Shield") )
+        {
+          if ( !_strcmpi(*(const char **)(v2 + 4), "Spirit") )
+          {
+            v7 = 52;
+            goto LABEL_71;
+          }
+          if ( !_strcmpi(*(const char **)(v2 + 4), "Power") )
+          {
+            v7 = 77;
+            goto LABEL_71;
+          }
+          if ( !_strcmpi(*(const char **)(v2 + 4), "Meteor") )
+          {
+            v7 = 9;
+            goto LABEL_71;
+          }
+          if ( !_strcmpi(*(const char **)(v2 + 4), "Lightning") )
+          {
+            v7 = 18;
+            goto LABEL_71;
+          }
+          if ( _strcmpi(*(const char **)(v2 + 4), "Implosion") )
+          {
+            if ( !_strcmpi(*(const char **)(v2 + 4), "Stone") )
+            {
+              v7 = 38;
+              goto LABEL_71;
+            }
+            if ( _strcmpi(*(const char **)(v2 + 4), "Haste") )
+            {
+              if ( _strcmpi(*(const char **)(v2 + 4), "Heroism") )
+              {
+                if ( !_strcmpi(*(const char **)(v2 + 4), "Pain") )
+                {
+                  v7 = 95;
+                  goto LABEL_71;
+                }
+                if ( _strcmpi(*(const char **)(v2 + 4), "Sparks") )
+                {
+                  if ( !_strcmpi(*(const char **)(v2 + 4), "Light") )
+                  {
+                    v7 = 78;
+                    goto LABEL_71;
+                  }
+                  if ( !_strcmpi(*(const char **)(v2 + 4), "Toxic") )
+                  {
+                    v7 = 90;
+                    goto LABEL_71;
+                  }
+                  if ( _strcmpi(*(const char **)(v2 + 4), "ShrapMetal") )
+                  {
+                    if ( _strcmpi(*(const char **)(v2 + 4), "Paralyze") )
+                    {
+                      if ( _strcmpi(*(const char **)(v2 + 4), "Fireball") )
+                      {
+                        if ( _strcmpi(*(const char **)(v2 + 4), "Incinerate") )
+                        {
+                          if ( !_strcmpi(*(const char **)(v2 + 4), "Fire") )
+                          {
+                            v7 = 2;
+                            goto LABEL_71;
+                          }
+                          if ( !_strcmpi(*(const char **)(v2 + 4), "Rock") )
+                          {
+                            v7 = 41;
+                            goto LABEL_71;
+                          }
+                          if ( !_strcmpi(*(const char **)(v2 + 4), "Mass") )
+                          {
+                            v7 = 44;
+                            goto LABEL_71;
+                          }
+                          if ( !_strcmpi(*(const char **)(v2 + 4), "Ice") )
+                          {
+                            v7 = 26;
+                            goto LABEL_71;
+                          }
+                          if ( !_strcmpi(*(const char **)(v2 + 4), "Acid") )
+                          {
+                            v7 = 29;
+                            goto LABEL_71;
+                          }
+                          if ( _strcmpi(*(const char **)(v2 + 4), "Bless") )
+                          {
+                            if ( !_strcmpi(*(const char **)(v2 + 4), "Dragon") )
+                            {
+                              v7 = 97;
+                              goto LABEL_71;
+                            }
+                            if ( _strcmpi(*(const char **)(v2 + 4), "Reanimate") )
+                            {
+                              if ( !_strcmpi(*(const char **)(v2 + 4), "Summon") )
+                              {
+                                v7 = 82;
+                                goto LABEL_71;
+                              }
+                              if ( _strcmpi(*(const char **)(v2 + 4), "Fate") )
+                              {
+                                if ( _strcmpi(*(const char **)(v2 + 4), "Harm") )
+                                {
+                                  if ( !_strcmpi(*(const char **)(v2 + 4), "Mind") )
+                                  {
+                                    v7 = 57;
+                                    goto LABEL_71;
+                                  }
+                                  if ( _strcmpi(*(const char **)(v2 + 4), "Blades") )
+                                  {
+                                    if ( !_strcmpi(*(const char **)(v2 + 4), "Psychic") )
+                                    {
+                                      v7 = 65;
+                                      goto LABEL_71;
+                                    }
+                                    if ( _strcmpi(*(const char **)(v2 + 4), "Hammerhands") )
+                                    {
+                                      sprintf(pTmpBuf, "Unknown monster spell %s", *(int *)(v2 + 4));
+                                      MessageBoxA(nullptr, pTmpBuf, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Itemdata.cpp:1562", 0);
+                                      result = 0;
+                                      goto LABEL_76;
+                                    }
+                                    v7 = 73;
+                                  }
+                                  else
+                                  {
+                                    v7 = 39;
+                                  }
+                                }
+                                else
+                                {
+                                  v7 = 70;
+                                }
+                              }
+                              else
+                              {
+                                v7 = 47;
+                              }
+                            }
+                            else
+                            {
+                              v7 = 89;
+                            }
+                          }
+                          else
+                          {
+                            v7 = 46;
+                          }
+                        }
+                        else
+                        {
+                          v7 = 11;
+                        }
+                      }
+                      else
+                      {
+                        v7 = 6;
+                      }
+                    }
+                    else
+                    {
+                      v7 = 81;
+                    }
+                  }
+                  else
+                  {
+                    v7 = 93;
+                  }
+                }
+                else
+                {
+                  v7 = 15;
+                }
+              }
+              else
+              {
+                v7 = 51;
+              }
+            }
+            else
+            {
+              v7 = 5;
+            }
+          }
+          else
+          {
+            v7 = 20;
+          }
+        }
+        else
+        {
+          v7 = 17;
+        }
+        return v7;
+      }
+      v7 = 86;
+    }
+    else
+    {
+      v7 = 85;
+    }
+    *(int *)v3 += 2;
+    result = v7;
+  }
+  return result;
+}
+
+//----- (00454CB4) --------------------------------------------------------
+int __thiscall ParseAttackType(unsigned __int8 *a1)
+{
+  unsigned __int8 *v1; // esi@1
+  int result; // eax@4
+  int v3; // eax@15
+  int v4; // eax@18
+
+  v1 = a1;
+  if ( !a1 )
+    return 4;
+  if ( tolower(*a1) == 'f' )
+    return 0;
+  if ( tolower(*v1) == 'a' )
+    return 1;
+  if ( tolower(*v1) == 'w' )
+    return 2;
+  if ( tolower(*v1) == 'e' )
+  {
+    tolower(v1[1]);
+    return 3;
+  }
+  if ( tolower(*v1) == 's' )
+    return 6;
+  if ( tolower(*v1) == 'm' )
+  {
+    v3 = -(tolower(v1[1]) != 'i');
+    LOBYTE(v3) = v3 & 0xFE;
+    result = v3 + 7;
+  }
+  else
+  {
+    if ( tolower(*v1) == 'l' )
+      return 9;
+    v4 = -(tolower(*v1) != 'd');
+    LOBYTE(v4) = v4 & 0xFA;
+    result = v4 + 10;
+  }
+  return result;
+}
+
+//----- (00454D7D) --------------------------------------------------------
+char __fastcall ParseDamage(const char *Str, int a2, int a3, int a4)
+{
+  int v4; // esi@1
+  const char *v5; // edi@1
+  signed int v6; // ebx@1
+  int *v7; // esi@2
+  int v8; // eax@3
+  size_t v10; // [sp+Ch] [bp-Ch]@1
+  int v11; // [sp+10h] [bp-8h]@1
+  signed int v12; // [sp+14h] [bp-4h]@1
+
+  v4 = a2;
+  v5 = Str;
+  *(char *)a2 = 0;
+  *(char *)a3 = 1;
+  v11 = a2;
+  *(char *)a4 = 0;
+  v6 = 0;
+  v10 = strlen(Str);
+  v12 = 0;
+  if ( (signed int)v10 <= 0 )
+  {
+LABEL_9:
+    LOBYTE(v8) = *v5;
+    if ( (unsigned __int8)*v5 >= 0x30u && (unsigned __int8)v8 <= 0x39u )
+    {
+      *(char *)v4 = atoi(v5);
+      LOBYTE(v8) = a3;
+      *(char *)a3 = 1;
+    }
+    return v8;
+  }
+  do
+  {
+    v7 = (int *)&v5[v6];
+    if ( tolower((unsigned __int8)v5[v6]) == 100 )
+    {
+      *(char *)v7 = 0;
+      *(char *)v11 = atoi(v5);
+      LOBYTE(v8) = atoi(&v5[v6 + 1]);
+      v12 = 1;
+      *(char *)a3 = v8;
+      *(char *)v7 = 100;
+    }
+    else
+    {
+      v8 = tolower(*(char *)v7);
+      if ( v8 == 43 )
+      {
+        LOBYTE(v8) = atoi(&v5[v6 + 1]);
+        *(char *)a4 = v8;
+      }
+    }
+    ++v6;
+  }
+  while ( v6 < (signed int)v10 );
+  if ( !v12 )
+  {
+    v4 = v11;
+    goto LABEL_9;
+  }
+  return v8;
+}
+
+//----- (00454E3A) --------------------------------------------------------
+int __fastcall ParseMissleAttackType(const char *Str1)
+{
+  const char *v1; // esi@1
+  int v2; // edi@1
+  int v4; // [sp-4h] [bp-Ch]@4
+
+  v1 = Str1;
+  v2 = 0;
+  if ( _strcmpi(Str1, "ARROW") )
+  {
+    if ( _strcmpi(v1, "ARROWF") )
+    {
+      if ( _strcmpi(v1, "FIRE") )
+      {
+        if ( _strcmpi(v1, "AIR") )
+        {
+          if ( _strcmpi(v1, "WATER") )
+          {
+            if ( _strcmpi(v1, "EARTH") )
+            {
+              if ( _strcmpi(v1, "SPIRIT") )
+              {
+                if ( _strcmpi(v1, "MIND") )
+                {
+                  if ( _strcmpi(v1, "BODY") )
+                  {
+                    if ( _strcmpi(v1, "LIGHT") )
+                    {
+                      if ( _strcmpi(v1, "DARK") )
+                      {
+                        if ( _strcmpi(v1, "ENER") )
+                          return v2;
+                        v4 = 13;
+                      }
+                      else
+                      {
+                        v4 = 11;
+                      }
+                    }
+                    else
+                    {
+                      v4 = 10;
+                    }
+                  }
+                  else
+                  {
+                    v4 = 9;
+                  }
+                }
+                else
+                {
+                  v4 = 8;
+                }
+              }
+              else
+              {
+                v4 = 7;
+              }
+            }
+            else
+            {
+              v4 = 6;
+            }
+          }
+          else
+          {
+            v4 = 5;
+          }
+        }
+        else
+        {
+          v4 = 4;
+        }
+      }
+      else
+      {
+        v4 = 3;
+      }
+    }
+    else
+    {
+      v4 = 2;
+    }
+    return v4;
+  }
+  return 1;
+}
+
+
+
+
+
+
+//----- (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;
+}
+
+
+//----- (0045828B) --------------------------------------------------------
+unsigned int __fastcall GetSpellColor(signed int a1)
+{
+  unsigned __int16 v1; // dx@3
+  unsigned __int16 v2; // cx@6
+  unsigned __int16 v4; // [sp-4h] [bp-4h]@3
+
+  if ( a1 < 1 )
+  {
+    if ( a1 < 12 )
+    {
+      if ( a1 < 23 )
+      {
+        if ( a1 < 34 )
+        {
+          if ( a1 < 45 )
+          {
+            if ( a1 < 56 )
+            {
+              if ( a1 < 67 )
+              {
+                if ( a1 < 78 )
+                {
+                  if ( a1 < 89 )
+                    goto LABEL_31;
+                  goto LABEL_28;
+                }
+LABEL_25:
+                if ( a1 < 89 )
+                {
+                  v4 = 155;
+                  v2 = 255;
+                  goto LABEL_30;
+                }
+LABEL_28:
+                if ( a1 < 100 )
+                {
+                  v4 = 240;
+                  v2 = 192;
+                  goto LABEL_30;
+                }
+LABEL_31:
+                v4 = 0;
+                v1 = 0;
+                goto LABEL_32;
+              }
+LABEL_21:
+              if ( a1 < 78 )
+              {
+                v4 = 0;
+                v1 = 128;
+                goto LABEL_23;
+              }
+              goto LABEL_25;
+            }
+LABEL_18:
+            if ( a1 < 67 )
+            {
+              v4 = 255;
+              v1 = 15;
+              v2 = 235;
+              return GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v2, v1, v4);
+            }
+            goto LABEL_21;
+          }
+LABEL_15:
+          if ( a1 < 56 )
+          {
+            v2 = 225;
+            goto LABEL_13;
+          }
+          goto LABEL_18;
+        }
+LABEL_11:
+        if ( a1 < 45 )
+        {
+          v2 = 128;
+LABEL_13:
+          v4 = v2;
+LABEL_30:
+          v1 = v2;
+          return GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v2, v1, v4);
+        }
+        goto LABEL_15;
+      }
+LABEL_8:
+      if ( a1 < 34 )
+      {
+        v4 = 255;
+        v1 = 128;
+LABEL_32:
+        v2 = 0;
+        return GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v2, v1, v4);
+      }
+      goto LABEL_11;
+    }
+  }
+  else
+  {
+    if ( a1 < 12 )
+    {
+      v4 = 0;
+      v1 = 85;
+LABEL_23:
+      v2 = 255;
+      return GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v2, v1, v4);
+    }
+  }
+  if ( a1 >= 23 )
+    goto LABEL_8;
+  v4 = 255;
+  v1 = 212;
+  v2 = 150;
+  return GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v2, v1, v4);
+}
+
+
+//----- (004583B0) --------------------------------------------------------
+LevelDecoration::LevelDecoration()
+{
+  this->field_1A = 0;
+  this->field_18 = 0;
+  this->vPosition.z = 0;
+  this->vPosition.y = 0;
+  this->vPosition.x = 0;
+  this->uDecorationDescID = 0;
+  this->field_2 = 0;
+  this->field_16_event_id = 0;
+  this->uCog = 0;
+}
+
+
+
+
+
+
+
+
+
+//----- (00458600) --------------------------------------------------------
+void DecorationList::ToFile()
+{
+  DecorationList *v1; // esi@1
+  FILE *v2; // eax@1
+  FILE *v3; // edi@1
+
+  v1 = this;
+  v2 = fopen("data\\ddeclist.bin", "wb");
+  v3 = v2;
+  if ( !v2 )
+    Abortf("Unable to save ddeclist.bin!");
+  fwrite(v1, 4u, 1u, v2);
+  fwrite(v1->pDecorations, 0x54u, v1->uNumDecorations, v3);
+  fclose(v3);
+}
+
+//----- (0045864C) --------------------------------------------------------
+void DecorationList::FromFile(void *pSerialized)
+{
+  uNumDecorations = *(int *)pSerialized;
+  pDecorations = (DecorationDesc *)pAllocator->AllocNamedChunk(pDecorations,
+                           84 * uNumDecorations, "Dec Descrip");
+  memcpy(pDecorations, (char *)pSerialized + 4, 84 * uNumDecorations);
+}
+
+//----- (00458693) --------------------------------------------------------
+void DecorationList::InitializeDecorationSprite(unsigned int uDecID)
+{
+  pSpriteFrameTable->InitializeSprite(this->pDecorations[uDecID].uSpriteID);
+}
+
+//----- (004586B0) --------------------------------------------------------
+bool DecorationList::FromFileTxt(const char *Args)
+{
+  DecorationList *v2; // ebx@1
+  FILE *v3; // eax@1
+  unsigned int v4; // esi@3
+  void *v5; // eax@10
+  FILE *v6; // ST18_4@12
+  char *i; // eax@12
+  unsigned __int16 v8; // ax@16
+  const char *v9; // ST20_4@16
+  const char *v10; // ST18_4@16
+  __int16 v11; // ax@16
+  const char *v12; // ST14_4@16
+  unsigned __int16 v13; // ax@16
+  const char *v14; // ST10_4@16
+  __int16 v15; // ax@16
+  const char *v16; // ST0C_4@16
+  unsigned __int8 v17; // al@16
+  const char *v18; // ST08_4@16
+  unsigned __int8 v19; // al@16
+  const char *v20; // ST04_4@16
+  unsigned __int8 v21; // al@16
+  const char *v22; // ST00_4@16
+  unsigned __int8 v23; // zf@16
+  char v24; // sf@16
+  unsigned __int8 v25; // of@16
+  int j; // edi@17
+  const char *v27; // esi@18
+  int v28; // eax@19
+  int v29; // eax@21
+  int v30; // eax@23
+  int v31; // eax@25
+  int v32; // eax@27
+  int v33; // eax@29
+  int v34; // eax@31
+  int v35; // eax@33
+  FrameTableTxtLine v37; // [sp+Ch] [bp-460h]@17
+  FrameTableTxtLine v38; // [sp+88h] [bp-3E4h]@13
+  char Dest; // [sp+104h] [bp-368h]@17
+  char Buf; // [sp+17Ch] [bp-2F0h]@3
+  FrameTableTxtLine v41; // [sp+370h] [bp-FCh]@4
+  FrameTableTxtLine v42; // [sp+3ECh] [bp-80h]@4
+  FILE *File; // [sp+468h] [bp-4h]@1
+  unsigned int Argsa; // [sp+474h] [bp+8h]@3
+
+  v2 = this;
+  v3 = fopen(Args, "r");
+  File = v3;
+  if ( !v3 )
+    Abortf("DecorationDescriptionList::load - Unable to open file: %s.");
+  v4 = 0;
+  Argsa = 0;
+  if ( fgets(&Buf, 490, v3) )
+  {
+    do
+    {
+      *strchr(&Buf, 10) = 0;
+      memcpy(&v42, frame_table_txt_parser(&Buf, &v41), sizeof(v42));
+      if ( v42.field_0 && *v42.pProperties[0] != 47 && v42.field_0 >= 3 )
+        ++Argsa;
+    }
+    while ( fgets(&Buf, 490, File) );
+    v4 = Argsa;
+  }
+  v2->uNumDecorations = v4;
+  v5 = pAllocator->AllocNamedChunk(v2->pDecorations, 84 * v4, "Dec Descrip");
+  v2->pDecorations = (DecorationDesc *)v5;
+  if ( !v5 )
+    Abortf("DecorationDescriptionList::load - Out of Memory!");
+  v6 = File;
+  v2->uNumDecorations = 0;
+  fseek(v6, 0, 0);
+  for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
+  {
+    *strchr(&Buf, 10) = 0;
+    memcpy(&v42, frame_table_txt_parser(&Buf, &v38), sizeof(v42));
+    if ( v42.field_0 && *v42.pProperties[0] != 47 && v42.field_0 >= 3 )
+    {
+      strcpy(v2->pDecorations[v2->uNumDecorations].pName, v42.pProperties[1]);
+      v8 = pSpriteFrameTable->FastFindSprite(v2->pDecorations[v2->uNumDecorations].pName);
+      v9 = v42.pProperties[2];
+      v2->pDecorations[v2->uNumDecorations].uSpriteID = v8;
+      strcpy(v2->pDecorations[v2->uNumDecorations].field_20, v9);
+      v10 = v42.pProperties[3];
+      v2->pDecorations[v2->uNumDecorations].uType = 0;
+      v11 = atoi(v10);
+      v12 = v42.pProperties[4];
+      v2->pDecorations[v2->uNumDecorations].uRadius = v11;
+      v13 = atoi(v12);
+      v14 = v42.pProperties[5];
+      v2->pDecorations[v2->uNumDecorations].uDecorationHeight = v13;
+      v15 = atoi(v14);
+      v16 = v42.pProperties[6];
+      v2->pDecorations[v2->uNumDecorations].uLightRadius = v15;
+      v17 = atoi(v16);
+      v18 = v42.pProperties[7];
+      v2->pDecorations[v2->uNumDecorations].uColoredLightRed = v17;
+      v19 = atoi(v18);
+      v20 = v42.pProperties[8];
+      v2->pDecorations[v2->uNumDecorations].uColoredLightGreen = v19;
+      v21 = atoi(v20);
+      v22 = v42.pProperties[9];
+      v2->pDecorations[v2->uNumDecorations].uColoredLightBlue = v21;
+      v2->pDecorations[v2->uNumDecorations].uSoundID = atoi(v22);
+      v25 = __OFSUB__(v42.field_0, 10);
+      v23 = v42.field_0 == 10;
+      v24 = v42.field_0 - 10 < 0;
+      v2->pDecorations[v2->uNumDecorations].uFlags = 0;
+      if ( !((unsigned __int8)(v24 ^ v25) | v23) )
+      {
+        strcpy(&Dest, v42.pProperties[10]);
+        memcpy(&v41, frame_table_txt_parser(&Dest, &v37), sizeof(v41));
+        for ( j = 0; j < v41.field_0; ++j )
+        {
+          v27 = v41.pProperties[j];
+          if ( _strcmpi(v41.pProperties[j], "NBM") )
+          {
+            if ( _strcmpi(v27, "Invisible") )
+            {
+              if ( _strcmpi(v27, "FS") )
+              {
+                if ( _strcmpi(v27, "FM") )
+                {
+                  if ( _strcmpi(v27, "FF") )
+                  {
+                    if ( _strcmpi(v27, "Marker") )
+                    {
+                      if ( _strcmpi(v27, "LoopSlow") )
+                      {
+                        if ( _strcmpi(v27, "EmitFire") )
+                        {
+                          if ( _strcmpi(v27, "Dawn") )
+                          {
+                            if ( !_strcmpi(v27, "Dusk") )
+                              HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 2u;
+                          }
+                          else
+                          {
+                            HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 1u;
+                          }
+                        }
+                        else
+                        {
+                          v35 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+                          *(char *)v35 |= 0x80u;
+                        }
+                      }
+                      else
+                      {
+                        v34 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+                        *(char *)v34 |= 0x40u;
+                      }
+                    }
+                    else
+                    {
+                      v33 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+                      *(char *)v33 |= 0x20u;
+                    }
+                  }
+                  else
+                  {
+                    v32 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+                    *(char *)v32 |= 0x10u;
+                  }
+                }
+                else
+                {
+                  v31 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+                  *(char *)v31 |= 8u;
+                }
+              }
+              else
+              {
+                v30 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+                *(char *)v30 |= 4u;
+              }
+            }
+            else
+            {
+              v29 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+              *(char *)v29 |= 2u;
+            }
+          }
+          else
+          {
+            v28 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags;
+            *(char *)v28 |= 1u;
+          }
+        }
+      }
+      ++v2->uNumDecorations;
+    }
+  }
+  fclose(File);
+  return 1;
+}
+
+
+
+
+
+//----- (00459064) --------------------------------------------------------
+void ObjectList::InitializeSprites()
+{
+  for (uint i = 0; i < uNumObjects; ++i)
+    pSpriteFrameTable->InitializeSprite(pObjects[i].uSpriteID);
+}
+
+//----- (00459090) --------------------------------------------------------
+void ObjectList::ToFile()
+{
+  ObjectList *v1; // esi@1
+  FILE *v2; // eax@1
+  FILE *v3; // edi@1
+
+  v1 = this;
+  v2 = fopen("data\\dobjlist.bin", "wb");
+  v3 = v2;
+  if ( !v2 )
+    Abortf("Unable to save dobjlist.bin!");
+  fwrite(v1, 4u, 1u, v2);
+  fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3);
+  fclose(v3);
+}
+
+//----- (004590DC) --------------------------------------------------------
+void ObjectList::FromFile(void *pSerialized)
+{
+  uNumObjects = *(int *)pSerialized;
+  pObjects = (ObjectDesc *)pAllocator->AllocNamedChunk(pObjects, 56 * uNumObjects, "Obj Descrip");
+  memcpy(pObjects, (char *)pSerialized + 4, 56 * uNumObjects);
+}
+
+//----- (00459123) --------------------------------------------------------
+bool ObjectList::FromFileTxt(const char *Args)
+{
+  ObjectList *v2; // ebx@1
+  __int32 v3; // edi@1
+  FILE *v4; // eax@1
+  unsigned int v5; // esi@3
+  void *v6; // eax@9
+  FILE *v7; // ST0C_4@11
+  char *i; // eax@11
+  unsigned __int16 v9; // ax@14
+  const char *v10; // ST20_4@14
+  __int16 v11; // ax@14
+  const char *v12; // ST1C_4@14
+  __int16 v13; // ax@14
+  const char *v14; // ST18_4@14
+  __int16 v15; // ax@14
+  const char *v16; // ST14_4@14
+  __int16 v17; // ax@14
+  const char *v18; // ST10_4@14
+  __int16 v19; // ax@14
+  const char *v20; // ST0C_4@14
+  int v21; // esi@16
+  const char *v22; // edi@16
+  int v23; // eax@17
+  int v24; // eax@19
+  int v25; // eax@21
+  int v26; // eax@21
+  int v27; // eax@21
+  int v28; // eax@23
+  int v29; // eax@25
+  int v30; // eax@27
+  int v31; // eax@29
+  const char *v32; // edi@30
+  const char *v33; // ST20_4@35
+  int v34; // eax@35
+  char v35; // al@35
+  const char *v36; // ST1C_4@35
+  char v37; // al@35
+  const char *v38; // ST18_4@35
+  FrameTableTxtLine v40; // [sp+8h] [bp-460h]@14
+  FrameTableTxtLine v41; // [sp+84h] [bp-3E4h]@12
+  char Dest; // [sp+100h] [bp-368h]@14
+  char Buf; // [sp+178h] [bp-2F0h]@3
+  FrameTableTxtLine v44; // [sp+36Ch] [bp-FCh]@4
+  FrameTableTxtLine v45; // [sp+3E8h] [bp-80h]@4
+  FILE *File; // [sp+464h] [bp-4h]@1
+  unsigned int Argsa; // [sp+470h] [bp+8h]@3
+  int Argsb; // [sp+470h] [bp+8h]@15
+
+  v2 = this;
+  pAllocator->FreeChunk(this->pObjects);
+  v3 = 0;
+  v2->pObjects = 0;
+  v2->uNumObjects = 0;
+  v4 = fopen(Args, "r");
+  File = v4;
+  if ( !v4 )
+    Abortf("ObjectDescriptionList::load - Unable to open file: %s.");
+  v5 = 0;
+  Argsa = 0;
+  if ( fgets(&Buf, 490, v4) )
+  {
+    do
+    {
+      *strchr(&Buf, 10) = 0;
+      memcpy(&v45, frame_table_txt_parser(&Buf, &v44), sizeof(v45));
+      if ( v45.field_0 && *v45.pProperties[0] != '/' )
+        ++Argsa;
+    }
+    while ( fgets(&Buf, 490, File) );
+    v5 = Argsa;
+    v3 = 0;
+  }
+  v2->uNumObjects = v5;
+  v6 = pAllocator->AllocNamedChunk(v2->pObjects, 56 * v5, "Obj Descrip");
+  v2->pObjects = (ObjectDesc *)v6;
+  if ( v6 == (void *)v3 )
+    Abortf("ObjectDescriptionList::load - Out of Memory!");
+  memset(v6, v3, 56 * v2->uNumObjects);
+  v7 = File;
+  v2->uNumObjects = v3;
+  fseek(v7, v3, v3);
+  for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
+  {
+    *strchr(&Buf, 10) = 0;
+    memcpy(&v45, frame_table_txt_parser(&Buf, &v41), sizeof(v45));
+    if ( v45.field_0 && *v45.pProperties[0] != 47 )
+    {
+      strcpy(v2->pObjects[v2->uNumObjects].field_0, v45.pProperties[0]);
+      v9 = pSpriteFrameTable->FastFindSprite((char *)v45.pProperties[1]);
+      v10 = v45.pProperties[2];
+      v2->pObjects[v2->uNumObjects].uSpriteID = v9;
+      v11 = atoi(v10);
+      v12 = v45.pProperties[3];
+      v2->pObjects[v2->uNumObjects].uObjectID = v11;
+      v13 = atoi(v12);
+      v14 = v45.pProperties[4];
+      v2->pObjects[v2->uNumObjects].uRadius = v13;
+      v15 = atoi(v14);
+      v16 = v45.pProperties[5];
+      v2->pObjects[v2->uNumObjects].uHeight = v15;
+      v17 = atoi(v16);
+      v18 = v45.pProperties[6];
+      v2->pObjects[v2->uNumObjects].uLifetime = v17;
+      v19 = atoi(v18);
+      v20 = v45.pProperties[7];
+      v2->pObjects[v2->uNumObjects].uSpeed = v19;
+      strcpy(&Dest, v20);
+      memcpy(&v44, frame_table_txt_parser(&Dest, &v40), sizeof(v44));
+      if ( v45.field_0 > 7 )
+      {
+        for ( Argsb = 0; Argsb < v44.field_0; ++Argsb )
+        {
+          v21 = Argsb;
+          v22 = v44.pProperties[Argsb];
+          if ( !_strcmpi(v44.pProperties[Argsb], "NoDraw") )
+          {
+            v23 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v23 |= 1u;
+          }
+          if ( !_strcmpi(v22, "Lifetime") )
+          {
+            v24 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v24 |= 4u;
+          }
+          if ( !_strcmpi(v22, "FTLifetime") )
+          {
+            v25 = (int)&v2->pObjects[v2->uNumObjects];
+            *(short *)(v25 + 42) = 8 * pSpriteFrameTable->pSpriteSFrames[*(short *)(v25 + 40)].uAnimLength;
+            v26 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v26 |= 8u;
+            v27 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v27 |= 4u;
+          }
+          if ( !_strcmpi(v22, "NoPickup") )
+          {
+            v28 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v28 |= 0x10u;
+          }
+          if ( !_strcmpi(v22, "NoGravity") )
+          {
+            v29 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v29 |= 0x20u;
+          }
+          if ( !_strcmpi(v22, "FlagOnIntercept") )
+          {
+            v30 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v30 |= 0x40u;
+          }
+          if ( !_strcmpi(v22, "Bounce") )
+          {
+            v31 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)v31 |= 0x80u;
+          }
+          v32 = v45.pProperties[v21];
+          if ( !_strcmpi(v45.pProperties[v21], "Fire") )
+            HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 2u;
+          if ( !_strcmpi(v32, "Lines") )
+            HIBYTE(v2->pObjects[v2->uNumObjects].uFlags) |= 4u;
+          if ( !_strcmpi(v44.pProperties[v21], "bits") )
+          {
+            v33 = v44.pProperties[v21 + 1];
+            v34 = (int)&v2->pObjects[v2->uNumObjects].uFlags;
+            *(char *)(v34 + 1) |= 1u;
+            v35 = atoi(v33);
+            v36 = v44.pProperties[v21 + 2];
+            v2->pObjects[v2->uNumObjects].uParticleTrailColorR = v35;
+            v37 = atoi(v36);
+            v38 = v44.pProperties[v21 + 3];
+            v2->pObjects[v2->uNumObjects].uParticleTrailColorG = v37;
+            v2->pObjects[v2->uNumObjects].uParticleTrailColorB = atoi(v38);
+          }
+        }
+      }
+      ++v2->uNumObjects;
+    }
+  }
+  fclose(File);
+  return 1;
+}
+
+
+//----- (0045E03A) --------------------------------------------------------
+unsigned __int16 *__fastcall MakeScreenshot(signed int width, signed int height)
+{
+  signed int v2; // edi@1
+  unsigned __int16 *v3; // ebx@1
+  int v4; // edx@7
+  unsigned __int8 v5; // cf@9
+  unsigned int v6; // ecx@9
+  unsigned __int16 *v7; // edi@9
+  int j; // ecx@9
+  unsigned __int16 *v9; // edi@15
+  int v10; // ecx@15
+  LONG v11; // esi@15
+  signed __int64 v12; // qax@18
+  unsigned int v13; // ST10_4@21
+  HRESULT v14; // eax@21
+  int v15; // edi@29
+  signed __int64 v16; // qax@30
+  signed int v17; // edx@34
+  unsigned __int16 *v18; // edi@36
+  int k; // ecx@36
+  DDSURFACEDESC2 Dst; // [sp+4h] [bp-A0h]@6
+  unsigned __int16 *pPixels; // [sp+80h] [bp-24h]@1
+  float v23; // [sp+84h] [bp-20h]@1
+  unsigned __int16 *_this; // [sp+88h] [bp-1Ch]@21
+  float v25; // [sp+8Ch] [bp-18h]@1
+  unsigned int v26; // [sp+90h] [bp-14h]@17
+  int v27; // [sp+94h] [bp-10h]@1
+  int v28; // [sp+98h] [bp-Ch]@16
+  int i; // [sp+9Ch] [bp-8h]@15
+  int v30; // [sp+A0h] [bp-4h]@1
+
+  v30 = width;
+  v2 = height;
+  v27 = height;
+  v23 = 452.0 / (double)width;
+  v25 = 336.0 / (double)height;
+  pPixels = (unsigned __int16 *)malloc(2 * height * width);
+  v3 = pPixels;
+  if ( pRenderer->pRenderD3D )
+  {
+    pRenderer->BeginSceneD3D();
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    {
+      pIndoor->Draw();
+    }
+    else
+    {
+      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+        pOutdoor->Draw();
+    }
+    pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
+    memset(&Dst, 0, 0x7Cu);
+    Dst.dwSize = 124;
+    if ( pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &Dst, 1u) )
+    {
+      v9 = (unsigned __int16 *)Dst.lpSurface;
+      v10 = 0;
+      v11 = Dst.lPitch >> 1;
+      for ( i = 0; i < v27; ++i )
+      {
+        v28 = v10;
+        if ( v30 > v10 )
+        {
+          v26 = v11 * (unsigned __int64)(signed __int64)((double)i * v25 + 8.0);
+          do
+          {
+            v12 = (signed __int64)((double)v28++ * v23 + 8.0);
+            *v3 = v9[v26 + (int)v12];
+            ++v3;
+          }
+          while ( v28 < v30 );
+          v10 = 0;
+        }
+      }
+      v13 = v10;
+      ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
+    }
+    else
+    {
+      v4 = v27;
+      if ( v27 > 0 )
+      {
+        do
+        {
+          if ( v30 > 0 )
+          {
+            v5 = v30 & 1;
+            v6 = (unsigned int)v30 >> 1;
+            memset(v3, 0, 4 * ((unsigned int)v30 >> 1));
+            v7 = &v3[2 * v6];
+            for ( j = v5; j; --j )
+            {
+              *v7 = 0;
+              ++v7;
+            }
+            v3 += v30;
+          }
+          --v4;
+        }
+        while ( v4 );
+      }
+    }
+  }
+  else
+  {
+    pRenderer->BeginScene();
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    {
+      pIndoor->Draw();
+    }
+    else
+    {
+      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+        pOutdoor->Draw();
+    }
+    _this = pRenderer->pTargetSurface;
+    v26 = pRenderer->uTargetSurfacePitch;
+    if ( pRenderer->pTargetSurface )
+    {
+      i = 0;
+      if ( v2 > 0 )
+      {
+        do
+        {
+          v28 = 0;
+          if ( v30 > 0 )
+          {
+            v15 = v26 * (unsigned __int64)(signed __int64)((double)i * v25 + 8.0);
+            do
+            {
+              v16 = (signed __int64)((double)v28++ * v23 + 8.0);
+              *v3 = _this[v15 + (int)v16];
+              ++v3;
+            }
+            while ( v28 < v30 );
+          }
+          ++i;
+        }
+        while ( i < v27 );
+      }
+    }
+    else
+    {
+      if ( v2 > 0 )
+      {
+        v17 = v2;
+        do
+        {
+          if ( v30 > 0 )
+          {
+            memset(v3, 0, 4 * ((unsigned int)v30 >> 1));
+            v18 = &v3[2 * ((unsigned int)v30 >> 1)];
+            for ( k = v30 & 1; k; --k )
+            {
+              *v18 = 0;
+              ++v18;
+            }
+            v3 += v30;
+          }
+          --v17;
+        }
+        while ( v17 );
+      }
+    }
+    pRenderer->EndScene();
+  }
+  return pPixels;
+}
+
+//----- (0045E26C) --------------------------------------------------------
+void __thiscall SaveScreenshot(const char *pFilename)
+{
+  const char *v1; // edi@1
+  unsigned __int16 *v2; // esi@1
+
+  v1 = pFilename;
+  v2 = MakeScreenshot(92, 68);
+  pRenderer->SavePCXImage(v1, (char *)v2, 92, 68);
+  free(v2);
+}
+
+
+
+
+//----- (004601B7) --------------------------------------------------------
+void GameUI_MainMenu_DoDrawLoad(int a1)
+{
+  unsigned __int16 v1; // bx@1
+  unsigned int v2; // edi@4
+  unsigned int v3; // eax@4
+  unsigned int v4; // eax@8
+  int v5; // edi@8
+  unsigned int v6; // eax@8
+  unsigned int pMapID; // eax@10
+  signed __int64 v8; // qax@10
+  unsigned int v9; // ebx@10
+  unsigned __int64 v10; // qax@10
+  __int64 v11; // qax@10
+  char v12; // di@10
+  unsigned __int64 v13; // qtt@10
+  unsigned int v14; // ecx@10
+  __int64 pOurHour; // qax@10
+  int v16; // edi@10
+  signed int pHour; // ebx@22
+  //const char *v18; // ST14_4@32
+  int v19; // eax@32
+  const char *v20; // ST18_4@32
+  int v21; // eax@32
+  //const char *v22; // ST14_4@32
+  int v23; // eax@32
+  const char *pSlotName; // edi@36
+  int v25; // eax@43
+  GUIWindow pWindow; // [sp+Ch] [bp-78h]@8
+  /*unsigned int Dst; // [sp+Ch] [bp-78h]@8
+  unsigned int v27; // [sp+10h] [bp-74h]@8
+  int v28; // [sp+14h] [bp-70h]@8
+  int v29; // [sp+18h] [bp-6Ch]@8
+  unsigned int v30; // [sp+1Ch] [bp-68h]@8
+  unsigned int v31; // [sp+20h] [bp-64h]@8*/
+  int pMinutes; // [sp+60h] [bp-24h]@10
+  int pMonthNum; // [sp+68h] [bp-1Ch]@10
+  unsigned int pSaveFiles; // [sp+70h] [bp-14h]@10
+  __int64 pAMPM2; // [sp+74h] [bp-10h]@10
+  int pYear; // [sp+7Ch] [bp-8h]@10
+  int a4; // [sp+80h] [bp-4h]@1
+  int pFilesID;
+
+  v1 = 255;
+  a4 = a1;
+  GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFF, 0xFF, 0xFF);
+  GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFF, 0xFF, 0x9B);
+  pRenderer->BeginScene();
+  if ( GetCurrentMenuID() != MENU_SAVELOAD && GetCurrentMenuID() != MENU_LOAD )
+  {
+    pRenderer->DrawTextureIndexed(8, 8, uTextureID_loadsave != -1 ? &pIcons_LOD->pTextures[uTextureID_loadsave] : 0);
+    if ( a4 )
+    {
+      v2 = uTextureID_save_up;
+      v3 = uTextureID_LS_saveU;
+    }
+    else
+    {
+      v2 = uTextureID_load_up;
+      v3 = uTextureID_LS_loadU;
+    }
+    pRenderer->DrawTextureIndexed(241, 302, (Texture *)(v3 != -1 ? &pIcons_LOD->pTextures[v3] : 0));
+    pRenderer->DrawTextureIndexed(18, 139, (Texture *)(v2 != -1 ? &pIcons_LOD->pTextures[v2] : 0));
+    pRenderer->DrawTextureIndexed(351, 302, (Texture *)(uTextureID_x_u != -1 ? &pIcons_LOD->pTextures[uTextureID_x_u] : 0));
+    v1 = 255;
+  }
+  if ( pSavegameUsedSlots[uLoadGameUI_SelectedSlot] )
+  {
+    memset(&pWindow, 0, 0x54);
+    pWindow.uFrameX = pGUIWindow_CurrentMenu->uFrameX + 240;
+    v4 = pGUIWindow_CurrentMenu->uFrameY - pFontSmallnum->uFontHeight;
+    pWindow.uFrameWidth = 220;
+    v4 += 157;
+    pWindow.uFrameY = v4;
+    v5 = pFontSmallnum->uFontHeight;
+    pWindow.uFrameZ = pWindow.uFrameX + 219;
+    pWindow.uFrameHeight = v5;
+    pWindow.uFrameW = v5 + v4 - 1;
+    v6 = uLoadGameUI_SelectedSlot;
+    if (pSavegameThumbnails[uLoadGameUI_SelectedSlot].pPixels)
+    {
+      pRenderer->DrawTextureRGB(pGUIWindow_CurrentMenu->uFrameX + 276, pGUIWindow_CurrentMenu->uFrameY + 171, pSavegameThumbnails + uLoadGameUI_SelectedSlot);
+      v6 = uLoadGameUI_SelectedSlot;
+    }
+    pMapID = pMapStats->GetMapInfo(pSavegameHeader[v6].pLocationName);
+    pWindow.DrawTitleText(pFontSmallnum, 0, 0, 0, pMapStats->pInfos[pMapID].pName, 3);
+    v8 = (signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60;
+    pMinutes = (int)((signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60) >> 32;
+    v9 = v8;
+    v8 /= 60i64;
+    pAMPM2 = v8;
+    v10 = (unsigned int)v8 / 24;
+    pSaveFiles = v10;
+    v11 = (unsigned int)(v10 / 7);
+    v12 = v11;
+    LODWORD(v13) = (unsigned int)v11 >> 2;
+    HIDWORD(v13) = HIDWORD(v11);
+    pMonthNum = v13 % 12;
+    pYear = v13 / 12;
+    pMinutes = (int)__PAIR__(pMinutes, v9) % 60;
+    pOurHour = pAMPM2 % 24;
+    v14 = (unsigned __int64)(pAMPM2 % 24) >> 32;
+    LODWORD(pAMPM2) = pAMPM2 % 24;
+    HIDWORD(pOurHour) = pSaveFiles % 28;
+    pYear += 1168;//ãîä íà÷àëà
+    v16 = v12 & 3;
+    pWindow.uFrameY = pGUIWindow_CurrentMenu->uFrameY + 261;
+    HIDWORD(pAMPM2) = v14 == 0 && ((signed int)v14 > 0 || (unsigned int)pOurHour >= 12)
+                && (signed int)v14 <= 0 && (v14 != 0 || (unsigned int)pOurHour < 24);
+    if ( v14  != 0 || (signed int)v14 <= 0 && (unsigned int)pOurHour <= 12 )
+    {
+      if ( !(v14 | (unsigned int)pOurHour) )
+      {
+        pSaveFiles = 0;
+        pHour = 12;
+        goto LABEL_23;
+      }
+    }
+    else
+    {
+      v14 = (__PAIR__(v14, (unsigned int)pOurHour) - 12) >> 32;
+      LODWORD(pOurHour) = pOurHour - 12;
+    }
+    pHour = pOurHour;
+    pSaveFiles = v14;
+LABEL_23:
+    auto day = aDayNames[HIDWORD(pOurHour) % 7];
+    auto ampm = aAMPMNames[HIDWORD(pAMPM2)];
+    auto month = aMonthNames[pMonthNum];
+    //sprintf(pTmpBuf, "%s %d:%02d%s\n%d %s %d", _d, v17, (int)32, _a, 3, _m, pFilesID);
+    sprintf(pTmpBuf, "%s %d:%02d%s\n%d %s %d", day, pHour, pMinutes, ampm, 7 * v16 + HIDWORD(pOurHour) % 7 + 1, month, pYear);
+    pWindow.DrawTitleText(pFontSmallnum, 0, 0, 0, pTmpBuf, 3u);
+    v1 = 255;
+  }
+  if ( pGUIWindow_CurrentMenu->field_40 == 2 )
+  {
+    pGUIWindow_CurrentMenu->field_40 = 0;
+    strcpy((char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot, (const char *)pKeyActionMap->pPressedKeysBuffer);
+    if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+    {
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)83;
+      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+      *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+      ++pMessageQueue_50CBD0->uNumMessages;
+    }
+  }
+  else
+  {
+    if ( pGUIWindow_CurrentMenu->field_40 == 3 )
+      pGUIWindow_CurrentMenu->field_40 = 0;
+  }
+  if (GetCurrentMenuID() == MENU_LOAD)
+  {
+    //v18 = pGlobalTXT_LocalizationStrings[135];
+    v19 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[135]);//"Çàãðóçêà"
+    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v19 + 25, 220, 0, pGlobalTXT_LocalizationStrings[135], 0, 0, 0);
+    v20 = (const char *)(pSavegameHeader + uLoadGameUI_SelectedSlot);
+    v21 = pFontSmallnum->AlignText_Center(0xBA, (const char *)pSavegameHeader + 100 * uLoadGameUI_SelectedSlot);
+    pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, v21 + 25, 0x106, 0, v20, 185, 0);
+    //v22 = pGlobalTXT_LocalizationStrings[165];
+    v23 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[165]);//"Ïîæàëóéñòà, ïîæîæäèòå"
+    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v23 + 25, 304, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0);
+  }
+  else
+  {
+    if ( a4 )
+      pSaveFiles = 40;
+    else
+      pSaveFiles = uNumSavegameFiles;
+    a4 = 199;
+    pFilesID = dword_6A0C9C;
+    pSlotName = (const char *)(&pSavegameHeader[dword_6A0C9C]);//draw name for save slot
+    do
+    {
+      if ( pFilesID >= (signed int)pSaveFiles )
+        break;
+      short clr;
+      HIDWORD(pAMPM2) = clr = (pFilesID == uLoadGameUI_SelectedSlot ? GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v1, v1, 0x64) : 0);
+      if ( pGUIWindow_CurrentMenu->field_40 != 1 || pFilesID != uLoadGameUI_SelectedSlot )
+      {
+        pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 0x1B, a4, clr, pSlotName, 185, 0);
+      }
+      else
+      {
+        v25 = pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 0x1B, a4, clr, (const char *)pKeyActionMap->pPressedKeysBuffer, 175, 1);
+        pGUIWindow_CurrentMenu->DrawFlashingInputCursor(v25 + 27, a4, pFontSmallnum);
+      }
+      a4 += 21;
+      ++pFilesID;
+      pSlotName += 100;
+    }
+    while ( a4 < 346 );
+  }
+  pRenderer->EndScene();
+}
+// 6A0C9C: using guessed type int dword_6A0C9C;
+
+//----- (004606F7) --------------------------------------------------------
+void __cdecl GameUI_MainMenu_DrawLoad()
+{
+  GameUI_MainMenu_DoDrawLoad(0);
+}
+
+//----- (004606FE) --------------------------------------------------------
+void __cdecl sub_4606FE()
+{
+  GameUI_MainMenu_DoDrawLoad(1);
+}
+
+//----- (00460706) --------------------------------------------------------
+void TryLoadLevelFromLOD()
+{
+  FILE *v0; // eax@1
+  FILE *v1; // esi@1
+  __int32 v2; // edi@2
+  char Ext[256]; // [sp+4h] [bp-40Ch]@1
+  char Dir[256]; // [sp+104h] [bp-30Ch]@1
+  char Filename[256]; // [sp+204h] [bp-20Ch]@1
+  char a1[260]; // [sp+304h] [bp-10Ch]@1
+  char Drive[4]; // [sp+408h] [bp-8h]@1
+  int DstBuf; // [sp+40Ch] [bp-4h]@2
+
+  strcpy(a1, pCurrentMapName);
+  _splitpath(a1, Drive, Dir, Filename, Ext);
+  sprintf(a1, "levels\\%s%s", Filename, ".lod");
+  v0 = fopen(a1, "rb");
+  v1 = v0;
+  if ( v0 )
+  {
+    fseek(v0, 0, 2);
+    v2 = ftell(v1);
+    rewind(v1);
+    ptr_6A0D08 = pAllocator->AllocNamedChunk(ptr_6A0D08, v2, "LevelLod");
+    fread(ptr_6A0D08, v2, 1u, v1);
+    fseek(v1, v2 - 6, 0);
+    DstBuf = 0;
+    fread(&DstBuf, 4u, 1u, v1);
+    fread(&_6A0D10_txt_lod_loading__unused, 2u, 1u, v1);
+    _6A0D0C_txt_lod_loading = (int)((char *)ptr_6A0D08 + DstBuf);
+    fclose(v1);
+  }
+}
+
+//----- (0046080D) --------------------------------------------------------
+void __cdecl sub_46080D()
+{
+  pAllocator->FreeChunk(ptr_6A0D08);
+  ptr_6A0D08 = 0;
+  _6A0D0C_txt_lod_loading = 0;
+}
+
+//----- (0046082C) --------------------------------------------------------
+bool Initialize_GamesLOD_NewLOD()
+{
+  pGames_LOD = new LODWriteableFile;
+  pGames_LOD->AllocSubIndicesAndIO(300, 0);
+  if (pGames_LOD->LoadFile("data\\games.lod", 1))
+  {
+    pNew_LOD = new LODWriteableFile;
+    pNew_LOD->AllocSubIndicesAndIO(300, 0x186A0u);
+    return true;
+  }
+  return false;
+}
+
+
+
+
+
+//----- (0046086A) --------------------------------------------------------
+bool Autosave()
+{
+  int flag; // esi@3
+  FILE *v3; // eax@7
+  LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3
+  LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4
+  LOD::Directory v7; // [sp+12Ch] [bp-4Ch]@9
+  LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3
+  void *pSave; // [sp+170h] [bp-8h]@3
+
+  if ( pVideoPlayer->AnyMovieLoaded() )
+    pVideoPlayer->Unload();
+  flag = 0;
+  pSave = pAllocator->AllocNamedChunk(0, 0xF4240, 0);
+  pNew_LOD->CloseWriteFile();
+  remove("data\\new.lod");
+  this_.Reset();
+  strcpy(this_.LodVersion, "MMVII");
+  strcpy(this_.LodDescription, "newmaps for MMVII");
+  this_.LODSize = 100;
+  this_.dword_0000A8 = 0;
+  a3.dword_000018 = 0;
+  a3.word_00001E = 0;
+  strcpy(a3.pFilename, "current");
+  pNew_LOD->_461492(&this_, &a3, "data\\new.lod");
+  if ( pNew_LOD->LoadFile("data\\new.lod", 0) )
+  {
+    pNew_LOD->CreateTempFile();
+    pNew_LOD->uNumSubIndices = 0;
+    pDir.Reset();
+
+    for (int i = pGames_LOD->uNumSubIndices / 2; i < pGames_LOD->uNumSubIndices; ++i)
+    {
+      memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir));
+      v3 = pGames_LOD->FindContainer(pGames_LOD->pSubIndices[i].pFilename, 1);
+      fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, v3);
+      pNew_LOD->AppendDirectory(&pDir, pSave);
+    }
+    v7.Reset();
+    strcpy(pSavegameHeader->pLocationName, "out01.odm");
+    strcpy(v7.pFilename, "header.bin");
+    v7.uDataSize = 100;
+    pNew_LOD->AppendDirectory(&v7, &pSavegameHeader);
+    pNew_LOD->Save();
+    pParty->vPrevPosition.y = 0;
+    pParty->vPrevPosition.x = 12552;
+    pParty->vPosition.x = 12552;
+    pParty->vPosition.z = 0;
+    pParty->uFallStartY = 0;
+    pParty->sPrevRotationX = 0;
+    pParty->sRotationX = 0;
+    pParty->vPrevPosition.z = 1816;
+    pParty->vPosition.y = 1816;
+    flag = 1;
+    pParty->sPrevRotationY = 512;
+    pParty->sRotationY = 512;
+    SaveGame(1, (__int16 *)1);
+  }
+  pAllocator->FreeChunk(pSave);
+  return flag;
+}
+
+
+//----- (004610AA) --------------------------------------------------------
+void __fastcall PrepareToLoadODM(unsigned int bLoading, OutdoorCamera *a2)
+{
+  unsigned int v2; // edi@1
+  OutdoorCamera *v3; // esi@1
+
+  v2 = bLoading;
+  v3 = a2;
+  pGameLoadingUI_ProgressBar->Reset(0x1Bu);
+  pSoundList->_4A9D79(0);
+  uCurrentlyLoadedLevelType = (LEVEL_TYPE)2;
+  ODM_LoadAndInitialize(pCurrentMapName, v3);
+  if ( !v2 )
+    TeleportToStartingPoint(uLevel_StartingPointType);
+  viewparams->_443365();
+  PlayLevelMusic();
+}
+// 6BE35C: using guessed type int uLevel_StartingPointType;
+
+//----- (00461103) --------------------------------------------------------
+void __cdecl sub_461103()
+{
+  //GUIProgressBar *v0; // ebx@1
+  //signed int v1; // ebp@1
+  //char *v2; // esi@2
+  __int16 v3; // cx@3
+  int v4; // edx@8
+  //size_t v5; // edi@14
+  signed int v6; // esi@14
+  //char *v7; // edx@15
+  signed int v8; // ecx@16
+  int v9; // ecx@23
+  MonsterInfo *v10; // ebx@23
+  //int *v11; // esi@23
+  int v12; // esi@25
+  int v13; // eax@26
+  __int16 v14; // ax@41
+  //signed int v15; // [sp+10h] [bp-4Ch]@1
+  //signed int v16; // [sp+10h] [bp-4Ch]@14
+  signed int v17; // [sp+14h] [bp-48h]@3
+  signed int v18; // [sp+14h] [bp-48h]@23
+  int v19; // [sp+18h] [bp-44h]@1
+  signed int v20; // [sp+18h] [bp-44h]@14
+  int v21[16]; // [sp+1Ch] [bp-40h]@17
+
+  sub_450218_prolly_generate_chests_loot();
+  //v0 = pGameLoadingUI_ProgressBar;
+  pGameLoadingUI_ProgressBar->Progress();
+  pParty->uFlags |= 2u;
+  pParty->field_7B5_in_arena_quest = 0;
+  //v1 = 0;
+  dword_5C6DF8 = 1;
+  pNPCStats->field_17FC0 = 0;
+  v19 = pMapStats->GetMapInfo(pCurrentMapName);
+
+  //v15 = 0;
+  for (uint i = 0; i < uNumActors; ++i)
+  //if ( (signed int)uNumActors > 0 )
+  {
+    auto pActor = pActors + i;
+    //v2 = (char *)&pActors[0].uNPC_ID;
+    //do
+    //{
+      v3 = pActor->pMonsterInfo.uID;
+      v17 = 0;
+      if ( v3 >= 115 && v3 <= 186 || v3 >= 232 && v3 <= 249 )
+        v17 = 1;
+      //v1 = 0;
+      v4 = (v3 - 1) % 3;
+      if ( 2 == v4 )
+      {
+        if ( pActor->uNPC_ID && pActor->uNPC_ID < 5000 )
+          continue;
+      }
+      else
+      {
+        if ( v4 != 1 )
+        {
+          if ( v4 != 0 || pActor->uNPC_ID )
+            continue;
+          goto LABEL_12;
+        }
+      }
+      if ( pActor->uNPC_ID > 0 && pActor->uNPC_ID < 5000 )
+        continue;
+      if ( v17 )
+      {
+        pNPCStats->InitializeAdditionalNPCs(&pNPCStats->array_13EF4[pNPCStats->field_17FC0], v3, 0, v19);
+        v14 = LOWORD(pNPCStats->field_17FC0) + 5000;
+        ++pNPCStats->field_17FC0;
+        pActor->uNPC_ID = v14;
+        continue;
+      }
+LABEL_12:
+      pActor->uNPC_ID = 0;
+//LABEL_13:
+      //++v15;
+      //v2 += 836;
+    //}
+    //while ( v15 < (signed int)uNumActors );
+  }
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  //v5 = uNumActors;
+  v6 = 0;
+  v20 = 0;
+  //v16 = v1;
+
+  for (uint i = 0; i < uNumActors; ++i)
+  {
+    auto pActor = pActors + i;
+    //v7 = (char *)&pActors[0].pMonsterInfo;
+    //do
+    //{
+      v8 = 0;
+      if ( v6 > 0 )
+      {
+        do
+        {
+          if ( v21[v8] == pActor->pMonsterInfo.uID - 1 )
+            break;
+          ++v8;
+        }
+        while ( v8 < v6 );
+      }
+
+      if ( v8 == v6 )
+      {
+        v21[v6++] = pActor->pMonsterInfo.uID - 1;
+        v20 = v6;
+        if ( v6 == 16 )
+          break;
+      }
+      //++v16;
+      //v7 += 836;
+    //}
+    //while ( v16 < (signed int)v5 );
+  }
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  if ( v6 > 0 )
+  {
+    int _v0 = 0;
+    do
+    {
+      v9 = v21[_v0];
+      v18 = 4;
+      v10 = &pMonsterStats->pInfos[v9 + 1];
+      //v11 = (int *)pMonsterList->pMonsters[v9].pSoundSampleIDs;
+      auto v11 = &pMonsterList->pMonsters[v9];
+      do
+      {
+        pSoundList->LoadSound(v11->pSoundSampleIDs[4 - v18], 0);
+        //v11 = (int *)((char *)v11 + 2);
+        --v18;
+      }
+      while ( v18 );
+      v12 = 0;
+      do
+        v13 = pSoundList->LoadSound(v12++ + word_4EE088_sound_ids[v10->uSpell1ID], 1);
+      while ( v13 );
+      ++_v0;
+    }
+    while ( _v0 < v6 );
+    //v0 = pGameLoadingUI_ProgressBar;
+    //v1 = 0;
+  }
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  if ( dword_6BE368_debug_settings_2 & 4 )
+    uNumActors = 0;
+  if ( dword_6BE368_debug_settings_2 & 8 )
+    uNumLevelDecorations = 0;
+  sub_4613C4();
+
+  pGameLoadingUI_ProgressBar->Progress();
+
+  pIndoorCamera->pos.y = 0;
+  pIndoorCamera->pos.x = 0;
+  pIndoorCamera->pos.z = 100;
+  pIndoorCamera->sRotationY = 0;
+  pIndoorCamera->sRotationX = 0;
+  viewparams->bRedrawGameUI = 1;
+  uLevel_StartingPointType = 0;
+  pSprites_LOD->_461397();
+  pPaletteManager->LockTestAll();
+  if ( pParty->pPickedItem.uItemID != 0 )
+    pMouse->SetCursorBitmapFromItemID(pParty->pPickedItem.uItemID);
+}
+
+
+
+//----- (004613C4) --------------------------------------------------------
+int __cdecl sub_4613C4()
+{
+  unsigned __int16 v0; // ax@1
+  size_t v1; // ecx@1
+  int v2; // esi@1
+  int result; // eax@1
+  LevelDecoration *v4; // edx@2
+  int v5; // edi@4
+
+  _6836C8_num_decorations_6807E8 = 0;
+  v0 = pDecorationList->GetDecorIdByName("Event Trigger");
+  v1 = uNumLevelDecorations;
+  v2 = (signed __int16)v0;
+  result = 0;
+  if ( (signed int)uNumLevelDecorations > 0 )
+  {
+    v4 = pLevelDecorations;
+    do
+    {
+      if ( v4->uDecorationDescID == v2 )
+      {
+        v5 = _6836C8_num_decorations_6807E8++;
+        _6807E8_level_decorations_ids[v5] = result;
+      }
+      ++result;
+      ++v4;
+    }
+    while ( result < (signed int)v1 );
+  }
+  return result;
+}
+// 6836C8: using guessed type int 6836C8_num_decorations_6807E8;
+
+
+
+
+
+
+
+
+
+
+
+
+
+//----- (004621DA) --------------------------------------------------------
+int __fastcall sub_4621DA(signed int a1, signed int a2, signed int a3)
+{
+  signed int v3; // eax@2
+  signed int v4; // eax@3
+  signed int v5; // esi@4
+  signed int v6; // esi@6
+
+  if ( a1 < a2 )
+  {
+    v3 = a1;
+    a1 = a2;
+    a2 = v3;
+  }
+  v4 = a3;
+  if ( a1 < a3 )
+  {
+    v5 = a1;
+    a1 = a3;
+    v4 = v5;
+  }
+  if ( a2 < v4 )
+  {
+    v6 = a2;
+    a2 = v4;
+    v4 = v6;
+  }
+  return (11 * a2 >> 5) + a1 + (v4 >> 2);
+}
+
+
+
+
+
+
+OPENFILENAMEA ofn;
+//----- (0046271C) --------------------------------------------------------
+void __cdecl crt_init_globals_46271C()
+{
+  ofn.lStructSize = 0x4Cu;
+  ofn.hwndOwner = hWnd;
+  ofn.hInstance = 0;
+  ofn.lpstrFilter = "Indoor  BLV Files (*.blv)";
+  ofn.lpstrCustomFilter = 0;
+  ofn.nMaxCustFilter = 0;
+  ofn.nFilterIndex = 0;
+  ofn.lpstrFile = 0;
+  ofn.nMaxFile = 260;
+  ofn.nMaxFileTitle = 512;
+  ofn.lpstrInitialDir = "levels";
+  ofn.lpstrTitle = "Might and Magic® VII - Load Which Level?";
+  ofn.Flags = 4;
+  ofn.nFileOffset = 0;
+  ofn.nFileExtension = 0;
+  ofn.lpstrDefExt = "blv";
+  ofn.lCustData = 0;
+  ofn.lpfnHook = 0;
+  ofn.lpTemplateName = 0;
+  ofn.lpstrFileTitle = pTmpBuf;
+}
+
+//----- (004627B7) --------------------------------------------------------
+void __cdecl MainMenu_Loop()
+{
+  GUIButton *pButton; // eax@27
+  unsigned int pControlParam; // ecx@35
+  int v10; // ecx@36
+  int v11; // ecx@37
+  unsigned int pY; // [sp-18h] [bp-54h]@39
+  Texture *pTexture; // [sp-14h] [bp-50h]@39
+  GUIButton *pButton2; // [sp+0h] [bp-3Ch]@27
+  GUIWindow *pWindow; // [sp+4h] [bp-38h]@11
+  
+  pCurrentScreen = 0; // îêíî Ãëàâíîå ìåíþ
+  if (pAsyncMouse)
+    pAsyncMouse->Resume();
+  if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
+    pAsyncKeyboard->Resume();
+  pGUIWindow2 = 0;
+  pAudioPlayer->StopChannels(-1, -1);
+  pMouse->RemoveHoldingItem();
+  ++pIcons_LOD->uTexturePacksCount;
+  if ( !pIcons_LOD->uNumPrevLoadedFiles )
+    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
+  pWindow_MainMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0); // ñîçäàíèå îêíà
+  auto pNew = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); // ñîçäàíèå êíîïîê
+  pMainMenu_BtnNew = pWindow_MainMenu->CreateButton(495, 172, pNew->uTextureWidth, pNew->uTextureHeight, 1, 0, 
+                                                    UIMSG_MainMenu_ShowPartyCreationWnd, 0, 78, "", pNew, 0);
+  auto pLoad = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
+  pMainMenu_BtnLoad = pWindow_MainMenu->CreateButton(495, 227, pLoad->uTextureWidth, pLoad->uTextureHeight, 1, 0, 
+                                                     UIMSG_MainMenu_ShowLoadWindow, 1, 76, "", pLoad, 0);
+  auto pCredits = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
+  pMainMenu_BtnCredits = pWindow_MainMenu->CreateButton(495, 282, pCredits->uTextureWidth, pCredits->uTextureHeight, 1, 0, 
+                                                         UIMSG_ShowCredits, 2, 67, "", pCredits, 0);
+  auto pExit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
+  pMainMenu_BtnExit = pWindow_MainMenu->CreateButton(495, 337, pExit->uTextureWidth, pExit->uTextureHeight, 1, 0, 
+                                                        UIMSG_ExitToWindows, 3, 0, "", pExit, 0);
+  pTexture_PCX.Release();
+  pTexture_PCX.Load("title.pcx", 0);
+  SetCurrentMenuID(MENU_MAIN);
+  SetForegroundWindow(hWnd);
+  SendMessageW(hWnd, WM_ACTIVATEAPP, 1, 0);
+  while (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_SAVELOAD)
+  {
+    POINT pt;
+    pMouse->GetCursorPos(&pt);
+    pWindow = pWindow_MainMenu;
+    if ( GetCurrentMenuID() == MENU_SAVELOAD)//åñëè ìåíþ çàãðóçêè
+    {
+      if ( pCurrentScreen != 12 )//åñëè íå îêíî çàãðóçêè èãðû
+      {
+        pTexture_PCX.Release();
+        pTexture_PCX.Load("lsave640.pcx", 0);
+        pGUIWindow2 = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
+        pCurrentScreen = 12; //îêíî çàãðóçêè èãðû
+        GameUI_DrawLoadMenu(0);//ïðîöåññ ïðîðèñîâêè îêíà Çàãðóçêà
+      }
+      pWindow = pGUIWindow_CurrentMenu;
+    }
+
+    MSG msg;
+    while ( PeekMessageA(&msg, 0, 0, 0, PM_REMOVE) )//îæèäàíèå ñîîáùåíèÿ èç âíåøíåãî èñòî÷íèêà
+    {
+      if (msg.message == WM_QUIT)
+        Game_DeinitializeAndTerminate(0);
+      TranslateMessage(&msg);
+      DispatchMessageA(&msg);
+    }
+    if (dword_6BE364_game_settings_1 & 0x0100)
+    {
+      WaitMessage();
+    }
+    else
+    {
+      pRenderer->BeginScene();
+      pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
+      if (pAsyncMouse)
+        pAsyncMouse->_46B736_consume_click_lists(1);
+      GUI_MainMenuMessageProc();//ïðîöåäóðà ïðîâåðêè ñîîáùåíèé ïîñòóïàþùèõ èç âíåøíèõ óñòðîéñòâ äëÿ âñåé ãðóïïû âñòóïèòåëüíûõ îêîí
+      GUI_UpdateWindows();
+      if (pAsyncMouse)
+        pAsyncMouse->_46B736_consume_click_lists(1);
+      if (GetCurrentMenuID() != MENU_MAIN)// åñëè íå Ãëàâíîå ìåíþ
+      {
+        if (GetCurrentMenuID() == MENU_LOAD)// åñëè ìåíþ Çàãðóçêà
+        {
+          pIcons_LOD->_4114F2();
+          pGUIWindow_CurrentMenu->Release();
+          pGUIWindow_CurrentMenu = 0;
+          pCurrentScreen = 0;
+          viewparams->bRedrawGameUI = 1;
+        }
+      }
+      else
+      {
+        if ( !ptr_507BDC )// ???
+        {
+          pButton = pWindow->pControlsHead;
+          for ( pButton = pWindow->pControlsHead; pButton; pButton = pButton->pNext )
+          {
+           if ( pt.x >= (signed int)pButton->uX && pt.x <= (signed int)pButton->uZ
+                && pt.y >= (signed int)pButton->uY && pt.y <= (signed int)pButton->uW
+                && pWindow == pWindow_MainMenu )
+           {
+            pControlParam = pButton->uControlParam;
+            switch (pControlParam) // ïîäñâåòêà êíîïîê
+            {
+              case 0:
+              pTexture = pNew;
+              pY = 172;
+              break;
+              case 1:
+              pTexture = pLoad;
+              pY = 227;
+              break;
+              case 2:
+              pTexture = pCredits;
+              pY = 282;
+              break;
+              case 3:
+              pTexture = pExit;
+              pY = 337;
+              break;
+            }
+            pRenderer->DrawTextureIndexed(495, pY, pTexture); //ïîäñâåòêà êíîïîê
+           }
+          }
+        }
+      }
+      pRenderer->EndScene();
+      pRenderer->Present();
+    }
+  }
+  /*GUI_MainMenuMessageProc(); //Ritor1: unknow
+  pRenderer->BeginScene();
+  GUI_UpdateWindows();
+  pRenderer->EndScene();
+  pRenderer->Present();
+  pTexture_PCX.Release();*/
+  if ( pGUIWindow2 )
+  {
+    pGUIWindow2->Release();
+    pGUIWindow2 = 0;
+  }
+  pWindow_MainMenu->Release();
+  pIcons_LOD->_4114F2();
+}
+
+
+
+
+//----- (004637EB) --------------------------------------------------------
+int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam)
+{
+  unsigned int v4; // esi@1
+  Render *v5; // ecx@14
+  HANDLE v6; // eax@32
+  Keyboard *v7; // eax@33
+  //HDC v9; // edi@41
+  HDC v10; // edi@50
+  int v11; // esi@50
+  char v12; // zf@132
+  signed int v13; // eax@135
+  int v14; // eax@139
+  int v15; // eax@140
+  int v16; // eax@141
+  int v17; // eax@142
+  int v18; // eax@150
+  int v19; // eax@151
+  int v20; // eax@152
+  int v21; // eax@161
+  int v22; // eax@162
+  int v23; // eax@163
+  int v24; // eax@170
+  int v25; // eax@171
+  int v26; // eax@172
+  char v27; // al@174
+  bool v28; // ebx@201
+  char v29; // dl@209
+  char v30; // cl@210
+  bool v31; // ebx@211
+  void *v32; // ebx@214
+  float v33; // ST04_4@246
+  float v34; // ST04_4@254
+  HWND v35; // [sp+8h] [bp-64h]@103
+  UINT v36; // [sp+Ch] [bp-60h]@103
+  WPARAM v37; // [sp+10h] [bp-5Ch]@103
+  LPARAM v38; // [sp+14h] [bp-58h]@103
+  struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13
+  int pXY[2]; // [sp+64h] [bp-8h]@261
+  int a2; // [sp+7Ch] [bp+10h]@50
+
+  switch (Msg)
+  {
+    case WM_SETTEXT: return DefWindowProcW(hWnd, Msg, wParam, lParam);
+  };
+
+  v4 = lParam;
+  if ( Msg > WM_SYSCOMMAND )
+  {
+    switch ( Msg )
+    {
+      default:
+        goto _def_wnd_proc;
+      case WM_DEVICECHANGE:
+        if ( wParam == 0x8000 )
+          PostMessageA(hInsertCDWindow, WM_CHOOSEFONT_GETLOGFONT, 0, 0);
+        return 0;
+      case WM_SIZING:
+        return 1;
+      case WM_LBUTTONDOWN:
+        v28 = 0;
+        if ( pArcomageGame->bGameInProgress )
+        {
+          if (pAsyncMouse)
+            goto _def_wnd_proc;
+          pArcomageGame->stru1.field_0 = 7;
+          v29 = 1;
+LABEL_210:
+          v30 = 0;
+          goto LABEL_263;
+        }
+        if ( pVideoPlayer->pVideoFrame.pPixels )
+          pVideoPlayer->bStopBeforeSchedule = 1;
+        if ( !pAsyncMouse )
+          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+        if (GetCurrentMenuID() != MENU_CREATEPARTY)
+          goto LABEL_230;
+        goto LABEL_229;
+      case WM_RBUTTONDOWN:
+        v31 = 0;
+        if ( !pArcomageGame->bGameInProgress )
+          goto LABEL_240;
+        if (pAsyncMouse)
+          goto _def_wnd_proc;
+        pArcomageGame->stru1.field_0 = 8;
+        v29 = 1;
+        goto LABEL_262;
+      case WM_LBUTTONUP:
+        v32 = 0;
+        if ( !pArcomageGame->bGameInProgress )
+          goto LABEL_218;
+        if (pAsyncMouse)
+          goto _def_wnd_proc;
+        pArcomageGame->stru1.field_0 = 3;
+        v29 = 0;
+        goto LABEL_210;
+      case WM_RBUTTONUP:
+        v32 = 0;
+        if ( !pArcomageGame->bGameInProgress )
+        {
+LABEL_218:
+          if ( pAsyncMouse != v32 )
+            goto _def_wnd_proc;
+          back_to_game();
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+        }
+        if (pAsyncMouse)
+          goto _def_wnd_proc;
+        pArcomageGame->stru1.field_0 = 4;
+        v29 = 0;
+        goto LABEL_262;
+      case WM_LBUTTONDBLCLK:
+        v28 = 0;
+        if ( pArcomageGame->bGameInProgress )
+        {
+          if (pAsyncMouse)
+            goto _def_wnd_proc;
+          pArcomageGame->stru1.field_0 = 7;
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+        }
+        if ( pVideoPlayer->pVideoFrame.pPixels )
+          pVideoPlayer->bStopBeforeSchedule = 1;
+        if ( !pAsyncMouse )
+          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+        if ( uCurrentMenuID != 6 )
+          goto LABEL_230;
+        if ( !pAsyncMouse )
+        {
+LABEL_229:
+          sub_41CD4F(0x29u);
+LABEL_230:
+          if ( pAsyncMouse == (void *)v28 )
+            pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+        }
+        if ( pGame != (Game *)v28 )
+        {
+          if ( pAsyncMouse != (void *)v28 )
+            goto _def_wnd_proc;
+          pGame->PickMouse(512.0, (unsigned __int16)lParam, lParam >> 16, v28, &a3, &a4);
+        }
+        if ( pAsyncMouse == (void *)v28 )
+        {
+          UI_OnMouseLeftClick(0);
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+        }
+        goto _def_wnd_proc;
+      case WM_RBUTTONDBLCLK:
+        v31 = 0;
+        if ( !pArcomageGame->bGameInProgress )
+        {
+LABEL_240:
+          if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
+            pVideoPlayer->bStopBeforeSchedule = 1;
+          if (!pAsyncMouse)
+            pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+          if (pGame)
+          {
+            if (pAsyncMouse)
+              goto _def_wnd_proc;
+            v33 = GetPickDepth();
+            pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &stru_F93E30, &a4);
+          }
+          if (!pAsyncMouse)
+          {
+            sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
+            return DefWindowProcA(hWnd, Msg, wParam, v4);
+          }
+          goto _def_wnd_proc;
+        }
+        if (pAsyncMouse)
+          goto _def_wnd_proc;
+        pArcomageGame->stru1.field_0 = 8;
+        return DefWindowProcA(hWnd, Msg, wParam, v4);
+      case WM_MBUTTONDOWN:
+        if ( pRenderer->pRenderD3D )
+        {
+          if ( pGame && !pAsyncMouse )
+          {
+            v34 = GetPickDepth();
+            pGame->PickMouse(v34, (unsigned __int16)lParam, lParam >> 16, 1, &a3, &a5);
+            return DefWindowProcA(hWnd, Msg, wParam, v4);
+          }
+          goto _def_wnd_proc;
+        }
+        if ( !pGame )
+          goto _def_wnd_proc;
+        sub_417871(0);
+        return DefWindowProcA(hWnd, Msg, wParam, v4);
+      case WM_MOUSEMOVE:
+        if ( pArcomageGame->bGameInProgress )
+        {
+          if (pAsyncMouse)
+            goto _def_wnd_proc;
+          pXY[0] = (unsigned __int16)lParam;
+          pXY[1] = lParam >> 16;
+          ArcomageGame::OnMouseMove((POINT *)pXY);
+          ArcomageGame::OnMouseClick(0, wParam & 1);
+          v29 = (wParam >> 1) & 1;
+LABEL_262:
+          v30 = 1;
+LABEL_263:
+          ArcomageGame::OnMouseClick(v30, v29);
+        }
+        else
+        {
+          if (pAsyncMouse)
+            goto _def_wnd_proc;
+          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
+        }
+        return DefWindowProcA(hWnd, Msg, wParam, v4);
+    }
+  }
+  if ( Msg == WM_SYSCOMMAND )
+  {
+    if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
+      return 0;
+    goto _def_wnd_proc;
+  }
+  if ( Msg > WM_ACTIVATEAPP )
+  {
+    if ( Msg == WM_WINDOWPOSCHANGED )
+    {
+      if (pVideoPlayer)
+      {
+        if (pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer)
+        {
+          BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0);
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+        }
+      }
+      goto _def_wnd_proc;
+    }
+    if ( Msg != WM_KEYFIRST )
+    {
+      if ( Msg == WM_KEYUP )
+      {
+        if ( wParam == VK_CONTROL )
+        {
+          dword_507B98_ctrl_pressed = 0;
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+        }
+        goto _def_wnd_proc;
+      }
+      if ( Msg == WM_CHAR )
+      {
+        if ( !pKeyActionMap->_459F10(wParam) && !viewparams->field_4C )
+        {
+          GUI_HandleHotkey(wParam);
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+        }
+        goto _def_wnd_proc;
+      }
+      if ( Msg != WM_COMMAND )
+        goto _def_wnd_proc;
+      if ( wParam != 101 )
+      {
+        if ( wParam == 103 )
+        {
+          pRenderer->SavePCXScreenshot();
+          return 0;
+        }
+        if ( wParam == 104 )
+        {
+          pRenderer->ChangeBetweenWinFullscreenModes();
+          if ( pArcomageGame->bGameInProgress )
+            pArcomageGame->field_F6 = 1;
+          return 0;
+        }
+        if ( wParam != 40001 )
+          return DefWindowProcA(hWnd, Msg, wParam, v4);
+      }
+      v38 = 0;
+      v37 = 0;
+      v36 = 2;
+      v35 = ::hWnd;
+LABEL_104:
+      SendMessageA(v35, v36, v37, v38);
+      return 0;
+    }
+    if ( dword_506E68 != -1 )
+    {
+      pKeyActionMap->_459F10(wParam);
+      return DefWindowProcA(hWnd, Msg, wParam, v4);
+    }
+    if ( !pArcomageGame->bGameInProgress )
+    {
+      if ( pVideoPlayer->pVideoFrame.pPixels )
+        pVideoPlayer->bStopBeforeSchedule = 1;
+      if ( wParam != 13 )
+      {
+        if ( wParam == 17 )
+        {
+          dword_507B98_ctrl_pressed = 1;
+          return 0;
+        }
+        if ( wParam == 27 )
+        {
+          if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+          {
+            v12 = ptr_507BC0 == 0;
+            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)113;
+            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = !v12;
+            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+            ++pMessageQueue_50CBD0->uNumMessages;
+          }
+          return 0;
+        }
+        if ( wParam <= 0x24 )
+          return 0;
+        if ( wParam > 0x28 )
+        {
+          if ( wParam != 115 || pVideoPlayer->AnyMovieLoaded() )
+            return 0;
+          v38 = 0;
+          v37 = 104;
+LABEL_126:
+          v36 = 273;
+          v35 = hWnd;
+          goto LABEL_104;
+        }
+        if ( pCurrentScreen
+          && pCurrentScreen != 21 )
+          return 0;
+      }
+      if ( !viewparams->field_4C )
+        sub_41CD4F(wParam);
+      return 0;
+    }
+    pArcomageGame->stru1.field_0 = 1;
+    if ( (unsigned __int16)GetAsyncKeyState(VK_SHIFT) >> 8 >= 0 )
+    {
+      v27 = MapVirtualKeyA((unsigned __int16)wParam, 2u);
+    }
+    else
+    {
+      v13 = (unsigned __int16)MapVirtualKeyA((unsigned __int16)wParam, 2u);
+      if ( (signed int)(unsigned __int16)v13 > 54 )
+      {
+        if ( v13 > 61 )
+        {
+          v24 = v13 - 91;
+          if ( !v24 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 123;
+            goto LABEL_181;
+          }
+          v25 = v24 - 1;
+          if ( !v25 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 124;
+            goto LABEL_181;
+          }
+          v26 = v25 - 1;
+          if ( !v26 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 125;
+            goto LABEL_181;
+          }
+          if ( v26 == 3 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 126;
+            goto LABEL_181;
+          }
+        }
+        else
+        {
+          if ( v13 == 61 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 43;
+            goto LABEL_181;
+          }
+          v21 = v13 - 55;
+          if ( !v21 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 38;
+            goto LABEL_181;
+          }
+          v22 = v21 - 1;
+          if ( !v22 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 42;
+            goto LABEL_181;
+          }
+          v23 = v22 - 1;
+          if ( !v23 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 40;
+            goto LABEL_181;
+          }
+          if ( v23 == 2 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 58;
+            goto LABEL_181;
+          }
+        }
+      }
+      else
+      {
+        if ( (unsigned __int16)v13 == 54 )
+        {
+          LOBYTE(pArcomageGame->stru1.field_8) = 94;
+          goto LABEL_181;
+        }
+        if ( v13 > 49 )
+        {
+          v18 = v13 - 50;
+          if ( !v18 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 64;
+            goto LABEL_181;
+          }
+          v19 = v18 - 1;
+          if ( !v19 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 35;
+            goto LABEL_181;
+          }
+          v20 = v19 - 1;
+          if ( !v20 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 36;
+            goto LABEL_181;
+          }
+          if ( v20 == 1 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 37;
+            goto LABEL_181;
+          }
+        }
+        else
+        {
+          if ( v13 == 49 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 33;
+            goto LABEL_181;
+          }
+          v14 = v13 - 39;
+          if ( !v14 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 34;
+            goto LABEL_181;
+          }
+          v15 = v14 - 5;
+          if ( !v15 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 60;
+            goto LABEL_181;
+          }
+          v16 = v15 - 2;
+          if ( !v16 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 62;
+            goto LABEL_181;
+          }
+          v17 = v16 - 1;
+          if ( !v17 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 63;
+            goto LABEL_181;
+          }
+          if ( v17 == 1 )
+          {
+            LOBYTE(pArcomageGame->stru1.field_8) = 41;
+LABEL_181:
+            if ( wParam == 27 )
+            {
+              pArcomageGame->field_F5 = 1;
+              pArcomageGame->field_F4 = 1;
+              pArcomageGame->uGameResult = 2;
+              pArcomageGame->field_B0 = -2;
+              goto _def_wnd_proc;
+            }
+            if ( wParam != 114 )
+            {
+              if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
+                SendMessageA(hWnd, 0x111u, 0x68u, 0);
+              goto _def_wnd_proc;
+            }
+            v38 = 0;
+            v37 = 103;
+            goto LABEL_126;
+          }
+        }
+      }
+      v27 = MapVirtualKeyA((unsigned __int16)wParam, 2u);
+    }
+    LOBYTE(pArcomageGame->stru1.field_8) = v27;
+    goto LABEL_181;
+  }
+  if ( Msg == WM_ACTIVATEAPP )
+  {
+    if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
+    {
+      if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
+      {
+        dword_4E98BC_bApplicationActive = 1;
+        if ( pRenderer->bWindowMode )
+        {
+          v10 = GetDC(0);
+          a2 = GetDeviceCaps(v10, BITSPIXEL);
+          v11 = GetDeviceCaps(v10, PLANES);
+          ReleaseDC(0, v10);
+          if ( a2 != 16 || v11 != 1 )
+            Abortf(pGlobalTXT_LocalizationStrings[62]);
+        }
+        BYTE1(dword_6BE364_game_settings_1) &= 0xFEu;
+        if (pAsyncMouse)
+          pAsyncMouse->Resume();
+        if ( pArcomageGame->bGameInProgress )
+        {
+          pArcomageGame->field_F9 = 1;
+        }
+        else
+        {
+          if ( BYTE1(dword_6BE364_game_settings_1) & 2 )
+            BYTE1(dword_6BE364_game_settings_1) &= 0xFDu;
+          else
+            pEventTimer->Resume();
+          if ( BYTE1(dword_6BE364_game_settings_1) & 4 )
+            BYTE1(dword_6BE364_game_settings_1) &= 0xFBu;
+          else
+            pMiscTimer->Resume();
+          if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
+            pAsyncKeyboard->Resume();
+          viewparams->bRedrawGameUI = 1;
+          if ( pVideoPlayer->pSmackerMovie )
+          {
+            pRenderer->RestoreFrontBuffer();
+            pRenderer->_4A184C();
+            pVideoPlayer->_4BF5B2();
+          }
+        }
+        if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie )
+          AIL_redbook_resume(pAudioPlayer->hAILRedbook);
+      }
+    }
+    else
+    {
+      if ( !(dword_6BE364_game_settings_1 & 0x100) )
+      {
+        dword_4E98BC_bApplicationActive = 0;
+        if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
+          pVideoPlayer->bStopBeforeSchedule = 1;
+        if (pAsyncMouse)
+          pAsyncMouse->Suspend();
+        if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
+          SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
+        ClipCursor(0);
+        dword_6BE364_game_settings_1 |= 0x100u;
+        if ( pEventTimer->bPaused )
+          BYTE1(dword_6BE364_game_settings_1) |= 2u;
+        else
+          pEventTimer->Pause();
+        if ( pMiscTimer->bPaused )
+          BYTE1(dword_6BE364_game_settings_1) |= 4u;
+        else
+          pMiscTimer->Pause();
+        if ( pGame && LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
+          pAsyncKeyboard->Suspend();
+        pAudioPlayer->StopChannels(-1, -1);
+        if ( pAudioPlayer->hAILRedbook )
+          AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+      }
+    }
+    return 0;
+  }
+  if (Msg == WM_CREATE)
+  {
+    auto hDC = GetDC(hWnd);
+    {
+      if (GetDeviceCaps(hDC, BITSPIXEL) < 8)
+      {
+        ReleaseDC(hWnd, hDC);
+        Log::Warning(L"You must be running in 256 color mode or higher.");
+        Abortf("You must be running in 256 color mode or higher. You can change the screen depth with the control panel display icon.");
+      }
+    }
+    ReleaseDC(hWnd, hDC);
+    return 0;
+  }
+  if ( Msg == WM_DESTROY )
+  {
+    v6 = GetCurrentProcess();
+    SetPriorityClass(v6, 0x20u);
+    if ( pGame )
+    {
+      v7 = pGame->pKeyboardInstance;
+      if ( v7 )
+      {
+        if ( LOBYTE(v7->bUsingAsynKeyboard) && pAsyncKeyboard )
+          pAsyncKeyboard->_45B3A4();
+      }
+    }
+    if (pAsyncMouse)
+      pAsyncMouse->_46B1DD();
+    PostQuitMessage(0);
+    return 0;
+  }
+  if ( Msg == WM_SETFOCUS )
+  {
+    if ( ::hWnd == (HWND)wParam )
+    {
+      dword_4E98BC_bApplicationActive = 0;
+      if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
+        SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
+      ClipCursor(0);
+      if (pAsyncMouse)
+      {
+        pAsyncMouse->Suspend();
+        return DefWindowProcA(hWnd, Msg, wParam, v4);
+      }
+    }
+_def_wnd_proc:
+    v4 = lParam;
+    return DefWindowProcA(hWnd, Msg, wParam, v4);
+  }
+  if ( Msg != WM_KILLFOCUS )
+  {
+    if ( Msg == WM_PAINT )
+    {
+      if ( !GetUpdateRect(hWnd, 0, 0) || !dword_4E98BC_bApplicationActive && !pRenderer->bWindowMode )
+        return 0;
+      BeginPaint(hWnd, &Paint);
+      if ( pArcomageGame->bGameInProgress )
+      {
+        pArcomageGame->field_F9 = 1;
+        v5 = pRenderer;
+      }
+      else
+      {
+        if ( !pRenderer->pRenderD3D && !pRenderer->UsingDirect3D() || !AreRenderSurfacesOk() )
+          goto LABEL_20;
+        v5 = pRenderer;
+      }
+      pRenderer->Present();
+LABEL_20:
+      EndPaint(hWnd, &Paint);
+      return 0;
+    }
+    goto _def_wnd_proc;
+  }
+  if ( ::hWnd != (HWND)wParam || (dword_4E98BC_bApplicationActive = 1, pRenderer->bWindowMode) || !pAsyncMouse )
+    return DefWindowProcA(hWnd, Msg, wParam, v4);
+  pAsyncMouse->Resume();
+  if ( !pAsyncMouse )
+    goto _def_wnd_proc;
+  pAsyncMouse->Clip();
+  return DefWindowProcA(hWnd, Msg, wParam, v4);
+}
+
+//----- (00464479) --------------------------------------------------------
+void __cdecl ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows()
+{
+  int v0; // esi@9
+
+  if (pMouse)
+    pMouse->SetCursorBitmap("MICON1");
+
+  pPaletteManager->ResetNonLocked();
+  pBitmaps_LOD->ReleaseAll2();
+  pSprites_LOD->DeleteSomeOtherSprites();
+  pIcons_LOD->ReleaseAll2();
+  if (pRenderer->pRenderD3D)
+  {
+    pRenderer->field_1036B8 = 0;
+    pRenderer->_gpu_memory_used = 0;
+  }
+  sub_46080D();
+  if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+    pIndoor->Release();
+  else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+    pOutdoor->Release2();
+
+  pAudioPlayer->StopChannels(-1, -1);
+  pSoundList->_4A9D79(0);
+  uCurrentlyLoadedLevelType = LEVEL_null;
+  pSpriteFrameTable->ResetSomeSpriteFlags();
+  v0 = uNumVisibleWindows;
+  pParty->field_1613C = 0;
+  while ( v0 > 0 )
+    pWindowList[pVisibleWindowsIdxs[v0--] - 1].Release();
+}
+
+
+
+//----- (004646F0) --------------------------------------------------------
+void PrepareWorld(unsigned int this_)
+{
+  unsigned int v1; // ebx@1
+
+  v1 = this_;
+  if ( pRenderer->pRenderD3D )
+    pGame->pVisInstance->_4C1A02();
+  pEventTimer->Pause();
+  pMiscTimer->Pause();
+  pParty->uFlags = 2;
+  pStru277->_427D48(1);
+  ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+  DoPrepareWorld(0, (v1 == 0) + 1);
+  pMiscTimer->Resume();
+  pEventTimer->Resume();
+}
+
+//----- (00464761) --------------------------------------------------------
+void __thiscall Game_DeinitializeAndTerminate(int exitCode)
+{
+  int v1; // esi@1
+  HANDLE v2; // eax@1
+
+  v1 = exitCode;
+  v2 = GetCurrentProcess();
+  SetPriorityClass(v2, 0x20u);
+  ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+  pGame->Deinitialize();
+  pRenderer->Release2();
+  if ( !DestroyWindow(hWnd) )
+    GetLastError();
+  hWnd = 0;
+  exit(v1);
+}
+
+//----- (004647AB) --------------------------------------------------------
+void __cdecl FinalInitialization()
+{
+  pViewport->SetScreen(viewparams->uSomeX, viewparams->uSomeY, viewparams->uSomeZ, viewparams->uSomeW);
+  pViewport->_4C02F8((signed __int64)(flt_6BE3A0 * 65536.0));
+
+  pIndoorCamera = new IndoorCamera;
+  pIndoorCamera->Initialize(
+    65,
+    viewparams->uScreenZ - viewparams->uScreenX + 1,
+    viewparams->uScreenW - viewparams->uScreenY + 1);
+
+  InitializeTurnBasedAnimations(&stru_50C198);
+  pBitmaps_LOD->dword_11B84 = pBitmaps_LOD->uNumLoadedFiles;
+  pSprites_LOD->field_ECA0 = pSprites_LOD->uNumLoadedSprites;
+  pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
+}
+// 6BE3A0: using guessed type float flt_6BE3A0;
+
+//----- (00464839) --------------------------------------------------------
+char __cdecl Is_out15odm_underwater()
+{
+  return _strcmpi(pCurrentMapName, "out15.odm") == 0;
+}
+
+//----- (00464851) --------------------------------------------------------
+void __cdecl SetUnderwaterFog()
+{
+  day_fogrange_1 = 50;
+  day_fogrange_2 = 5000;
+}
+
+
+
+//----- (00464866) --------------------------------------------------------
+void __fastcall DoPrepareWorld(unsigned int bLoading, int a2)
+{
+  int v2; // esi@1
+  char *v3; // eax@1
+  //char *v4; // eax@1
+  unsigned int v5; // eax@3
+  //size_t v6; // ecx@10
+  //char *v7; // eax@11
+  char Str1[20]; // [sp+Ch] [bp-18h]@1
+  unsigned int v9; // [sp+20h] [bp-4h]@1
+
+  v2 = a2;
+  v9 = bLoading;
+  ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+  pDecalBuilder->Reset(0);
+  pGameLoadingUI_ProgressBar->_443484((GUIProgressBar::Type)v2);
+  strcpy(Str1, pCurrentMapName);
+  v3 = strtok(Str1, ".");
+  strcpy(Str1, v3);
+  Level_LoadEvtAndStr(Str1);
+  LoadLevel_InitializeLevelEvt();
+  strcpy(Str1, pCurrentMapName);
+  _strrev(Str1);
+  strtok(Str1, ".");
+  _strrev(Str1);
+
+  for (uint i = 0; i < 1000; ++i)
+    pLayingItems[i].uObjectDescID = 0;
+
+  v5 = pMapStats->GetMapInfo(pCurrentMapName);
+  bUnderwater = 0;
+  uLevelMapStatsID = v5;
+  pGame->uFlags2 &= 0xFFFFFFF7u;
+  if ( !_strcmpi(pCurrentMapName, "out15.odm") )
+  {
+    bUnderwater = 1;
+    pGame->uFlags2 |= 8u;
+  }
+  pParty->field_6F4_packedid = 0;
+  if ( _strcmpi(Str1, "blv") )
+    PrepareToLoadODM(v9, 0);
+  else
+    PrepareToLoadBLV(v9);
+  pAudioPlayer->SetMapEAX();
+  sub_461103();
+  if ( !_strcmpi(pCurrentMapName, "d11.blv") || !_strcmpi(pCurrentMapName, "d10.blv") )
+  {
+    //spawning grounds & good analogue - no loot & exp from monsters
+
+    for (uint i = 0; i < uNumActors; ++i)
+    {
+      pActors[i].pMonsterInfo.uTreasureType = 0;
+      pActors[i].pMonsterInfo.uTreasureDiceRolls = 0;
+      pActors[i].pMonsterInfo.uExp = 0;
+    }
+  }
+  bDialogueUI_InitializeActor_NPC_ID = 0;
+  OnMapLoad();
+  pGameLoadingUI_ProgressBar->Progress();
+  pGameLoadingUI_ProgressBar->Release();
+  _flushall();
+}
+
+
+//----- (004649EF) --------------------------------------------------------
+int __fastcall ReadWindowsRegistryInt(const char *pKey, int uDefValue)
+{
+  int v3; // [sp+4h] [bp-24h]@1
+  DWORD cbData; // [sp+8h] [bp-20h]@1
+  LPCSTR lpValueName; // [sp+Ch] [bp-1Ch]@1
+  DWORD dwDisposition; // [sp+10h] [bp-18h]@2
+  BYTE Data[4]; // [sp+14h] [bp-14h]@5
+  HKEY hKey; // [sp+18h] [bp-10h]@1
+  HKEY phkResult; // [sp+1Ch] [bp-Ch]@1
+  HKEY v10; // [sp+20h] [bp-8h]@1
+  HKEY v11; // [sp+24h] [bp-4h]@1
+
+  v3 = uDefValue;
+  lpValueName = pKey;
+  v11 = 0;
+  v10 = 0;
+  hKey = 0;
+  phkResult = 0;
+  cbData = 4;
+  if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) )
+  {
+    if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
+    {
+      if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v10, &dwDisposition) )
+      {
+        if ( !RegCreateKeyExA(v10, "1.0", 0, "", 0, 0xF003Fu, 0, &v11, &dwDisposition) )
+        {
+          if ( RegQueryValueExA(v11, lpValueName, 0, 0, Data, &cbData) )
+          {
+            *(int *)Data = v3;
+            RegSetValueExA(v11, lpValueName, 0, 4u, Data, 4u);
+          }
+          RegCloseKey(v11);
+        }
+        RegCloseKey(v10);
+      }
+      RegCloseKey(phkResult);
+    }
+    RegCloseKey(hKey);
+  }
+  return *(int *)Data;
+}
+
+//----- (00464B02) --------------------------------------------------------
+void __fastcall WriteWindowsRegistryString(const char *pKey, const char *pString)
+{
+  size_t v2; // eax@5
+  const char *lpValueName; // [sp+4h] [bp-1Ch]@1
+  const char *Str; // [sp+8h] [bp-18h]@1
+  DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
+  HKEY hKey; // [sp+10h] [bp-10h]@1
+  HKEY phkResult; // [sp+14h] [bp-Ch]@1
+  HKEY v8; // [sp+18h] [bp-8h]@1
+  HKEY v9; // [sp+1Ch] [bp-4h]@1
+
+  Str = pString;
+  lpValueName = pKey;
+  v9 = 0;
+  v8 = 0;
+  hKey = 0;
+  phkResult = 0;
+  if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) )
+  {
+    if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
+    {
+      if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) )
+      {
+        if ( !RegCreateKeyExA(v8, "1.0", 0, "", 0, 0xF003Fu, 0, &v9, &dwDisposition) )
+        {
+          v2 = strlen(Str);
+          RegSetValueExA(v9, lpValueName, 0, 1u, (const BYTE *)Str, v2 + 1);
+          RegCloseKey(v9);
+        }
+        RegCloseKey(v8);
+      }
+      RegCloseKey(phkResult);
+    }
+    RegCloseKey(hKey);
+  }
+}
+
+//----- (00464BEF) --------------------------------------------------------
+void __fastcall ReadWindowsRegistryString(const char *pKeyName, char *pOutString, int uBufLen, const char *pDefaultValue)
+{
+  LSTATUS (__stdcall *v4)(HKEY); // esi@1
+  LSTATUS result; // eax@7
+  DWORD Type; // [sp+Ch] [bp-24h]@5
+  LPCSTR lpValueName; // [sp+10h] [bp-20h]@1
+  DWORD cbData; // [sp+14h] [bp-1Ch]@1
+  LPBYTE Dest; // [sp+18h] [bp-18h]@1
+  DWORD dwDisposition; // [sp+1Ch] [bp-14h]@2
+  HKEY phkResult; // [sp+20h] [bp-10h]@1
+  HKEY hKey; // [sp+24h] [bp-Ch]@1
+  HKEY v13; // [sp+28h] [bp-8h]@1
+  HKEY v14; // [sp+2Ch] [bp-4h]@1
+
+  cbData = uBufLen;
+  Dest = (LPBYTE)pOutString;
+  lpValueName = pKeyName;
+  v14 = 0;
+  v13 = 0;
+  hKey = 0;
+  phkResult = 0;
+  v4 = RegCloseKey;
+  if ( RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey)
+    || RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition)
+    || RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v13, &dwDisposition)
+    || RegCreateKeyExA(v13, "1.0", 0, "", 0, 0xF003Fu, 0, &v14, &dwDisposition) )
+    goto LABEL_7;
+  if ( RegQueryValueExA(v14, lpValueName, 0, &Type, Dest, &cbData) )
+  {
+    RegCloseKey(v14);
+    v14 = 0;
+LABEL_7:
+    result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
+    goto LABEL_8;
+  }
+  v4 = RegCloseKey;
+  RegCloseKey(v14);
+  v14 = 0;
+  RegCloseKey(v13);
+  v13 = 0;
+  RegCloseKey(phkResult);
+  phkResult = 0;
+  result = RegCloseKey(hKey);
+  hKey = 0;
+LABEL_8:
+  if ( v14 )
+    result = v4(v14);
+  if ( v13 )
+    result = v4(v13);
+  if ( hKey )
+    result = v4(hKey);
+  if ( phkResult )
+    result = v4(phkResult);
+}
+
+//----- (00464D32) --------------------------------------------------------
+void __fastcall WriteWindowsRegistryInt(const char *pKey, int val)
+{
+  const char *lpValueName; // [sp+4h] [bp-1Ch]@1
+  BYTE Data[4]; // [sp+8h] [bp-18h]@1
+  DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
+  HKEY hKey; // [sp+10h] [bp-10h]@1
+  HKEY phkResult; // [sp+14h] [bp-Ch]@1
+  HKEY v7; // [sp+18h] [bp-8h]@1
+  HKEY v8; // [sp+1Ch] [bp-4h]@1
+
+  *(int *)Data = val;
+  lpValueName = pKey;
+  v8 = 0;
+  v7 = 0;
+  hKey = 0;
+  phkResult = 0;
+  if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) )
+  {
+    if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
+    {
+      if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v7, &dwDisposition) )
+      {
+        if ( !RegCreateKeyExA(v7, "1.0", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) )
+        {
+          RegSetValueExA(v8, lpValueName, 0, 4u, Data, 4u);
+          RegCloseKey(v8);
+        }
+        RegCloseKey(v7);
+      }
+      RegCloseKey(phkResult);
+    }
+    RegCloseKey(hKey);
+  }
+}
+
+//----- (00464E17) --------------------------------------------------------
+bool __fastcall CheckMM7CD(char c)
+{
+  char DstBuf[256]; // [sp+Ch] [bp-218h]@1
+  char strCommand[256]; // [sp+10Ch] [bp-118h]@1
+  char Filename[20]; // [sp+20Ch] [bp-18h]@1
+
+
+  wchar_t pMagicPath[1024];
+  swprintf(pMagicPath, L"%C:\\anims\\magic7.vid", c);
+  if (GetFileAttributesW(pMagicPath) == -1)
+    return false;
+
+  wsprintfA(strCommand, "open %c: type cdaudio alias CD", c);
+  if (!mciSendStringA(strCommand, DstBuf, 0xFFu, 0))
+  {
+    wsprintfA(strCommand, "info CD UPC wait");
+    mciSendStringA(strCommand, DstBuf, 0xFFu, 0);
+    wsprintfA(strCommand, "close CD");
+    mciSendStringA(strCommand, DstBuf, 0xFFu, 0);
+  }
+
+  memcpy(Filename, "X:\\anims\\magic7.vid", sizeof(Filename));
+  *Filename = c;
+
+  auto f = fopen(Filename, "rb");
+  if (!f)
+    return false;
+
+  if (!fseek(f, 0, SEEK_END))
+  {
+    if (!fseek(f, -100, SEEK_CUR))
+      fread(DstBuf, 1u, 0x64u, f);
+
+    fclose(f);
+    return true;
+  }
+  fclose(f);
+  return false;
+}
+
+//----- (00464F1B) --------------------------------------------------------
+signed int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4)
+{
+  char v4; // zf@3
+  int v6; // eax@10
+  int v7; // eax@11
+  int v8; // eax@12
+  int v9; // eax@13
+  BOOL (__stdcall *v10)(HWND, int, LPCSTR); // edi@15
+  const CHAR *v11; // [sp-Ch] [bp-Ch]@15
+  INT_PTR v12; // [sp-4h] [bp-4h]@5
+
+  if ( a2 == 272 )
+  {
+    hInsertCDWindow = hDlg;
+    v6 = (GetUserDefaultLangID() & 0x3FF) - 7;
+    if ( v6 )
+    {
+      v7 = v6 - 3;
+      if ( v7 )
+      {
+        v8 = v7 - 2;
+        if ( v8 )
+        {
+          v9 = v8 - 4;
+          if ( v9 )
+          {
+            if ( v9 != 5 )
+              return 0;
+            SetWindowTextA(hDlg, "Wloz CD-ROM numer 2");
+            v10 = SetDlgItemTextA;
+            SetDlgItemTextA(hDlg, 1010, "Wloz CD-ROM numer 2 Might and Magic® VII.");
+            v11 = "Odwolaj";
+          }
+          else
+          {
+            SetWindowTextA(hDlg, "Inserire il secondo CD");
+            v10 = SetDlgItemTextA;
+            SetDlgItemTextA(hDlg, 1010, "Inserire il secondo CD di Might and Magic® VII.");
+            v11 = "Annulla";
+          }
+        }
+        else
+        {
+          SetWindowTextA(hDlg, "Insérez le CD 2");
+          v10 = SetDlgItemTextA;
+          SetDlgItemTextA(hDlg, 1010, "Insérez Might & Magic® VII CD 2.");
+          v11 = "Supprimer";
+        }
+      }
+      else
+      {
+        SetWindowTextA(hDlg, "Por favor, inserte disco 2");
+        v10 = SetDlgItemTextA;
+        SetDlgItemTextA(hDlg, 1010, "Por favor, inserte disco 2 de Might & Magic® VII.");
+        v11 = "Cancelar";
+      }
+    }
+    else
+    {
+      SetWindowTextA(hDlg, "Bitte CD 2 einlegen");
+      v10 = SetDlgItemTextA;
+      SetDlgItemTextA(hDlg, 1010, "Bitte CD 2 von Might and Magic® VII einlegen.");
+      v11 = "Abbrechen";
+    }
+    v10(hDlg, 2, v11);
+    return 0;
+  }
+  if ( a2 == 273 )
+  {
+    if ( a3 == 2 )
+    {
+      v12 = 0;
+LABEL_9:
+      EndDialog(hDlg, v12);
+      return 1;
+    }
+    v4 = a3 == 1;
+  }
+  else
+  {
+    v4 = a2 == 1025;
+  }
+  if ( v4 )
+  {
+    v12 = 1;
+    goto LABEL_9;
+  }
+  return 0;
+}
+
+//----- (00465061) --------------------------------------------------------
+bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive)
+{
+  char drive[4] = {'X', ':', '\\', 0};
+
+  bool bGotCDFromRegistry = false;
+
+  HKEY hSoftware = nullptr,
+       hNWC = nullptr,
+       hMM7 = nullptr,
+       hVersion = nullptr;
+  if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hSoftware))
+  {
+    if (!RegOpenKeyExA(hSoftware, "New World Computing", 0, 0x2001Fu, &hNWC))
+    {
+      if (!RegOpenKeyExA(hNWC, "Might and Magic VII", 0, 0x2001Fu, &hMM7))
+      {
+        if (!RegOpenKeyExA(hMM7, "1.0", 0, 0x2001Fu, &hVersion))
+        {
+          DWORD cbData = 3;
+          if (!RegQueryValueExA(hVersion, "CDDrive", 0, 0, (BYTE *)drive, &cbData))
+            bGotCDFromRegistry = true;
+        }
+        RegCloseKey(hVersion);
+      }
+      RegCloseKey(hMM7);
+    }
+    RegCloseKey(hNWC);
+  }
+  RegCloseKey(hSoftware);
+
+  if (bGotCDFromRegistry)
+    if (CheckMM7CD(*drive))
+    {
+      cMM7GameCDDriveLetter = *drive;
+      return true;
+    }
+
+  while (true)
+  {
+    for (uint i = 0; i < 26; ++i)
+    {
+      drive[0] = 'A' + i;
+
+      if (GetDriveTypeA(drive) == DRIVE_CDROM)
+        if (CheckMM7CD(*drive))
+        {
+          cMM7GameCDDriveLetter = *drive;
+          WriteWindowsRegistryString("CDDrive", drive);
+          return true;
+        }
+    }
+
+    if (DialogBoxParamA(GetModuleHandleW(nullptr), "InsertCD", ::hWnd, (DLGPROC)InsertMM7CDDialogFunc, 0))
+      continue;
+    return false;
+  }
+}
+
+//----- (004651F4) --------------------------------------------------------
+bool MM7_Initialize()
+{
+  wchar_t pCurrentDir[1024];
+  _wgetcwd(pCurrentDir, 1024);
+
+  wchar_t pMM6IniFile[1024];
+  wsprintf(pMM6IniFile, L"%s\\mm6.ini", pCurrentDir);
+
+  bCanLoadFromCD = GetPrivateProfileIntW(L"settings", L"use_cd", 1, pMM6IniFile);
+  if (bNoCD)
+    bCanLoadFromCD = false;
+  if (bCanLoadFromCD)
+  {
+    if (!FindMM7CD(hWnd, &cMM7GameCDDriveLetter))
+      return false;
+  }
+
+
+
+  srand(GetTickCount());
+  /*GetDiskFreeSpaceA(0, &SectorsPerCluster, &BytesPerSector, &hdc, &TotalNumberOfClusters);
+  v4 = hdc * BytesPerSector * SectorsPerCluster;
+  if ( (unsigned int)v4 < 0x1E00000 )
+  {
+    sprintfex(
+      pTmpBuf,
+      "Due to Window Virtual Memory requirements Might and Magic® VII\nrequires 30MB of free hard drive space to operate properly.\n\nAvailable on Current Drive = %luk",
+      (unsigned int)v4 / 1024i64);
+    v41 = 48;
+    v40 = "More Hard Drive Space Required";
+    v39 = pTmpBuf;
+*/
+  
+  WNDCLASSEXW wcxw;
+  {
+    wcxw.cbSize = sizeof(wcxw);
+    wcxw.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
+    wcxw.lpfnWndProc = (WNDPROC)aWinProc;
+    wcxw.cbClsExtra = 0;
+    wcxw.cbWndExtra = 0;
+    wcxw.hInstance = GetModuleHandleW(nullptr);
+    wcxw.hCursor = 0;
+    wcxw.hIcon = wcxw.hIconSm = LoadIconW(wcxw.hInstance, L"MM7_ICON");
+    wcxw.lpszMenuName = nullptr;
+    wcxw.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
+    wcxw.lpszClassName = L"M&MTrilogy";
+  }
+  if (!RegisterClassExW(&wcxw))
+  {
+    Log::Warning(L"Cannot register window class");
+    return false;
+  }
+
+  auto hDesktopDC = GetDC(nullptr);
+  uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES);
+  uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES);
+
+  if (GetDeviceCaps(hDesktopDC, BITSPIXEL) != 16 ||
+      GetDeviceCaps(hDesktopDC, PLANES) != 1 )
+    dword_6BE364_game_settings_1 |= 2;
+
+  ReleaseDC(nullptr, hDesktopDC);
+
+
+  uint uTotalWinWidth = 2 * GetSystemMetrics(SM_CXFRAME) + 640;
+  uint uTotalWinHeight = GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYFRAME) + 480;
+
+  uint uWinCenteredPosX = (uDesktopWidth - uTotalWinWidth) / 2;
+  uint uWinCenteredPosY = (uDesktopHeight - uTotalWinHeight) / 2;
+
+  uWindowX = ReadWindowsRegistryInt("window X", uWinCenteredPosX);
+  uWindowX = 0;
+  WriteWindowsRegistryInt("window X", uWindowX);
+
+  uWindowY = ReadWindowsRegistryInt("window Y", uWinCenteredPosY);
+  uWindowY = 0;
+  WriteWindowsRegistryInt("window Y", uWindowY);
+
+  hWnd = CreateWindowExW(0, wcxw.lpszClassName, L"Might and Magic® VII",
+                         uWindowStyle = WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER,
+                         uWindowX, uWindowY,
+                         640, 480,
+                         nullptr,
+                         hOSMenu = nullptr,
+                         wcxw.hInstance,
+                         nullptr);
+  SetWindowTextW(hWnd, L"Might and Magic® VII");
+
+  SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
+
+  pRenderer = Render::Create();
+  if (!pRenderer)
+  {
+    Log::Warning(L"Render creation failed");
+    return false;
+  }
+  else
+  {
+    bool bWindowMode = ReadWindowsRegistryInt("startinwindow", false);
+    uint uDefaultDevice = ReadWindowsRegistryInt("D3D Device", 1);
+    bool bColoredLights = ReadWindowsRegistryInt("Colored Lights", false);
+    uint uLevelOfDetail = ReadWindowsRegistryInt("Detail Level", 1);
+    uint bTinting = ReadWindowsRegistryInt("Tinting", 1) != 0;
+
+    if (!pRenderer->Initialize(bWindowMode, uDefaultDevice, bColoredLights, uLevelOfDetail, bTinting))
+    {
+      Log::Warning(L"Render failed to initialize");
+      return false;
+    }
+  }
+
+  pAllocator = Allocator::Create();
+  if (!pAllocator->Initialize(26 * 1024))
+  {
+    MessageBoxW(nullptr,
+                L"Unable to Allocate 26Mb of RAM",
+                L"More RAM Memory Required", MB_ICONEXCLAMATION);
+    return false;
+  }
+  
+
+  pParty = new Party;
+  pParty->uWalkSpeed = GetPrivateProfileIntW(L"debug", L"walkspeed", 384, pMM6IniFile);
+  pParty->uDefaultEyelevel = GetPrivateProfileIntW(L"party", L"eyelevel", 160, pMM6IniFile);
+  pParty->sEyelevel = pParty->uDefaultEyelevel;
+  pParty->uDefaultPartyHeight = GetPrivateProfileIntW(L"party", L"height", 192, pMM6IniFile);
+  pParty->uPartyHeight = pParty->uDefaultPartyHeight;
+  
+  bUseRegistry = GetPrivateProfileIntW(L"settings", L"registry", 1, pMM6IniFile);
+  MM6_Initialize(pMM6IniFile);
+
+  pKeyActionMap = new KeyboardActionMapping;
+
+  pEventTimer = Timer::Create();
+  pEventTimer->Initialize();
+
+  OnTimer(1);
+  GameUI_StatusBar_UpdateTimedString(1);
+  pGame = Game::Create();
+  pMouse = pGame->pMouseInstance;
+  
+
+  RECT rcWindow;
+  GetWindowRect(hWnd, &rcWindow);
+
+  RECT rcClient;
+  GetClientRect(hWnd, &rcClient);
+  uWindowWidth = rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640;
+  uWindowHeight = rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480;
+  MoveWindow(hWnd, uWindowX, uWindowY,
+    rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640,
+    rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480, 0);
+  ShowWindow(hWnd, SW_SHOWNORMAL);
+
+  pIcons_LOD = new LODFile_IconsBitmaps;
+  if (!pIcons_LOD->LoadIconsOrEvents("data\\icons.lod"))
+  {
+    MessageBoxW(nullptr,
+                L"Some files are missing\n\nPlease Reinstall.",
+                L"Files Missing", MB_ICONEXCLAMATION);
+    return false;
+  }
+  pIcons_LOD->dword_011BA4 = 0;
+  
+  pEvents_LOD = new LODFile_IconsBitmaps;
+  if (!pEvents_LOD->LoadIconsOrEvents("data\\events.lod"))
+  {
+    MessageBoxW(nullptr,
+                L"Some files are missing\n\nPlease Reinstall.",
+                L"Files Missing", MB_ICONEXCLAMATION);
+    return false;
+  }
+
+  InitializeGameText();
+  
+  pBitmaps_LOD = new LODFile_IconsBitmaps;
+  if (!pBitmaps_LOD->LoadBitmaps("data\\bitmaps.lod"))
+  {
+    MessageBoxA(nullptr,
+                pGlobalTXT_LocalizationStrings[63],
+                pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
+    return false;
+  }
+
+  if (bUseRegistry)
+    bUseLoResSprites = ReadWindowsRegistryInt("resolution", 0);
+  else
+    bUseLoResSprites = GetPrivateProfileIntW(L"settings", L"resolution", 0, pMM6IniFile);
+
+  const char *pSpritesFile = nullptr;
+  if (bUseLoResSprites)
+    pSpritesFile = "data\\spriteLO.lod";
+  else
+    pSpritesFile = "data\\sprites.lod";
+
+  pSprites_LOD = new LODFile_Sprites;
+  if (!pSprites_LOD->LoadSprites(pSpritesFile))
+  {
+    MessageBoxA(nullptr,
+                pGlobalTXT_LocalizationStrings[63],
+                pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
+    return false;
+  }
+
+  if (bDebugResouces)
+  {
+    pSpriteFrameTable = new SpriteFrameTable;
+    if (!pSpriteFrameTable->FromFileTxt("data\\sft.txt"))
+      Abortf("Unable to open sft.txt");
+
+    pDecorationList = new DecorationList;
+    if (!pDecorationList->FromFileTxt("data\\declist.txt"))
+      Abortf("Unable to open declist.txt");
+
+    pObjectList = new ObjectList;
+    if (!pObjectList->FromFileTxt("data\\objlist.txt"))
+      Abortf("Unable to open objlist.txt");
+
+    pMonsterList = new MonsterList;
+    if (!pMonsterList->FromFileTxt("data\\monlist.txt"))
+      Abortf("Unable to open monlist.txt");
+
+    pIconsFrameTable = new IconFrameTable;
+    if (!pIconsFrameTable->FromFileTxt("data\\ift.txt"))
+      Abortf("Unable to open ift.txt");
+
+    pTextureFrameTable = new TextureFrameTable;
+    if (!pTextureFrameTable->FromFileTxt("data\\tft.def"))
+      Abortf("Unable to open tft.def");
+
+    pTileTable = new TileTable;
+    if (!pTileTable->FromFileTxt("data\\tile.def"))
+      Abortf("Unable to open tile.def");
+
+    pPlayerFrameTable = new PlayerFrameTable;
+    if (!pPlayerFrameTable->FromFileTxt("data\\pft.def"))
+      Abortf("Unable to open pft.def");
+
+    pChestList = new ChestList;
+    if (!pChestList->FromFileTxt("data\\chest.def"))
+      Abortf("Unable to open chest.def");
+
+    pOverlayList = new OverlayList;
+    if (!pOverlayList->FromFileTxt("data\\overlay.def"))
+      Abortf("Unable to open overlay.def");
+
+    pSoundList = new SoundList;
+    if (!pSoundList->FromFileTxt("data\\sounds.def"))
+      Abortf("Unable to open sounds.def");
+  }
+  else
+  {
+    auto pSFT = pEvents_LOD->LoadRaw("dsft.bin", 1);
+    pSpriteFrameTable = new SpriteFrameTable;
+    pSpriteFrameTable->FromFile(pSFT);
+    free(pSFT);
+
+    auto pTFT = pEvents_LOD->LoadRaw("dtft.bin", 1);
+    pTextureFrameTable = new TextureFrameTable;
+    pTextureFrameTable->FromFile(pTFT);
+    free(pTFT);
+
+    auto pTiles = pEvents_LOD->LoadRaw("dtile.bin", 1);
+    pTileTable = new TileTable;
+    pTileTable->FromFile(pTiles);
+    free(pTiles);
+
+    auto pPFT = pEvents_LOD->LoadRaw("dpft.bin", 1);
+    pPlayerFrameTable = new PlayerFrameTable;
+    pPlayerFrameTable->FromFile(pPFT);
+    free(pPFT);
+
+    auto pIFT = pEvents_LOD->LoadRaw("dift.bin", 1);
+    pIconsFrameTable = new IconFrameTable;
+    pIconsFrameTable->FromFile(pIFT);
+    free(pIFT);
+
+    auto pDecs = pEvents_LOD->LoadRaw("ddeclist.bin", 1);
+    pDecorationList = new DecorationList;
+    pDecorationList->FromFile(pDecs);
+    free(pDecs);
+
+    auto pObjs = pEvents_LOD->LoadRaw("dobjlist.bin", 1);
+    pObjectList = new ObjectList;
+    pObjectList->FromFile(pObjs);
+    free(pObjs);
+
+    auto pMons = pEvents_LOD->LoadRaw("dmonlist.bin", 1);
+    pMonsterList = new MonsterList;
+    pMonsterList->FromFile(pMons);
+    free(pMons);
+
+    auto pChests = pEvents_LOD->LoadRaw("dchest.bin", 1);
+    pChestList = new ChestList;
+    pChestList->FromFile(pChests);
+    free(pChests);
+
+    auto pOverlays = pEvents_LOD->LoadRaw("doverlay.bin", 1);
+    pOverlayList = new OverlayList;
+    pOverlayList->FromFile(pOverlays);
+    free(pOverlays);
+
+    auto pSounds = pEvents_LOD->LoadRaw("dsounds.bin", 1);
+    pSoundList = new SoundList;
+    pSoundList->FromFile(pSounds);
+    free(pSounds);
+  }
+
+
+  if (bDebugResouces)
+  {
+    pSpriteFrameTable->ToFile();
+    pDecorationList->ToFile();
+    pObjectList->ToFile();
+    pMonsterList->ToFile();
+    pIconsFrameTable->ToFile();
+    pTextureFrameTable->ToFile();
+    pTileTable->ToFile();
+    pPlayerFrameTable->ToFile();
+    pChestList->ToFile();
+    pOverlayList->ToFile();
+    pSoundList->ToFile();
+  }
+
+
+  if (dword_6BE364_game_settings_1 & 2 || !(dword_6BE368_debug_settings_2 & 1))// 
+                                                //   color depth != 16
+                                                // or
+                                                //   not in window
+  {
+    SetMenu(hWnd, 0);
+    SetWindowLongA(hWnd, GWL_EXSTYLE, 0);
+    SetWindowLongA(hWnd, GWL_STYLE, WS_VISIBLE);
+    if (pAsyncMouse)
+      pAsyncMouse->Clip();
+    pRenderer->InitializeFullscreen(hWnd);
+  }
+  else
+  {
+    ClipCursor(nullptr);
+    pRenderer->SwitchToWindow(hWnd);
+  }
+
+  uSoundVolumeMultiplier = ReadWindowsRegistryInt("soundflag", 9);
+  if (uSoundVolumeMultiplier > 9)
+    uSoundVolumeMultiplier = 9;
+  uMusicVolimeMultiplier = ReadWindowsRegistryInt("musicflag", 9);
+  if (uMusicVolimeMultiplier > 9)
+    uMusicVolimeMultiplier = 9;
+  uVoicesVolumeMultiplier = ReadWindowsRegistryInt("CharVoices", 9);
+  if (uVoicesVolumeMultiplier > 9)
+    uVoicesVolumeMultiplier = 9;
+  bShowDamage = ReadWindowsRegistryInt("ShowDamage", 1) != 0;
+  byte_6BE388_graphicsmode = ReadWindowsRegistryInt("graphicsmode", 1);
+  if (byte_6BE388_graphicsmode < 0 || byte_6BE388_graphicsmode > 2)
+    byte_6BE388_graphicsmode = 0;
+
+  uGammaPos = ReadWindowsRegistryInt("GammaPos", 4);
+  if (uGammaPos < 0 || uGammaPos > 9)
+    uGammaPos = 4;
+  pGame->pGammaController->Initialize(uGammaPos * 0.1 + 0.6);
+
+  if ( ReadWindowsRegistryInt("Bloodsplats", 1) )
+    pGame->uFlags2 |= 0x20u;
+  else
+    pGame->uFlags2 &= 0xFFFFFFDFu;
+
+  uTurnSpeed = ReadWindowsRegistryInt("TurnDelta", 0);
+  dword_6BE384_2dacceloff = ReadWindowsRegistryInt("2dacceloff", 0);
+
+  if (!bNoSound)
+    pAudioPlayer->Initialize(hWnd);
+
+  pVideoPlayer = new VideoPlayer;
+  pVideoPlayer->Initialize();
+
+  dword_6BE364_game_settings_1 |= 0x4000;
+
+  if ( uTurnSpeed )
+  {
+    switch ( uTurnSpeed )
+    {
+      case 1u:
+        uTurnSpeed = 128;
+        break;
+      case 2u:
+        uTurnSpeed = 64;
+        break;
+      case 3u:
+        uTurnSpeed = 0;
+        break;
+    }
+  }
+  else
+  {
+    uTurnSpeed = (unsigned int)uCPUSpeed < 0xC7 ? 128 : 64;
+  }
+  return true;
+}
+
+
+
+
+//----- (00465D0B) --------------------------------------------------------
+void __cdecl SecondaryInitialization()
+{
+  __int16 v4; // ax@4
+  signed int v5; // esi@5
+  int v6; // ecx@6
+  int v7; // edx@7
+  ObjectDesc *v8; // eax@7
+  char pContainer[32]; // [sp+10h] [bp-Ch]@9
+
+  pMouse->Initialize(hWnd);
+  CreateAsyncMouse();
+  CreateAsyncKeyboard();
+
+  pItemsTable = new ItemsTable;
+  pItemsTable->Initialize();
+
+  pBitmaps_LOD->dword_011BA8 = 1;
+  pBitmaps_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+  pIcons_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+  pPaletteManager->SetColorChannelInfo(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+  pPaletteManager->pPalette_mistColor[0] = 128;
+  pPaletteManager->pPalette_mistColor[1] = 128;
+  pPaletteManager->pPalette_mistColor[2] = 128;
+  pPaletteManager->RecalculateAll();
+  pSprites_LOD->field_ECAC = 1;
+  pObjectList->InitializeSprites();
+  pOverlayList->InitializeSprites();
+  if (!bNoSound)
+    pSoundList->Initialize();
+
+  static const char *pUIAnimNames[4] =
+  {
+    "glow03", "glow05",
+    "torchA", "wizeyeA"
+  };
+  static unsigned short _4E98D0[4][4] =
+  {
+    {479, 0, 329, 0},
+    {585, 0, 332, 0},
+    {468, 0,   0, 0},
+    {606, 0,   0, 0}
+  };
+
+
+  for (uint i = 0; i < 4; ++i)
+  {
+    pUIAnims[i]->uIconID = pIconsFrameTable->FindIcon(pUIAnimNames[i]);
+    pIconsFrameTable->InitializeAnimation(pUIAnims[i]->uIconID);
+
+    pUIAnims[i]->uAnimLength = 0;
+    pUIAnims[i]->uAnimTime = 0;
+    pUIAnims[i]->x = _4E98D0[i][0];
+    pUIAnims[i]->y = _4E98D0[i][2];
+  }
+
+  v5 = 0;
+  if ( (signed int)pObjectList->uNumObjects > 0 )
+  {
+    v6 = 0;
+    do
+    {
+      BYTE3(v7) = 0;
+      v8 = &pObjectList->pObjects[v6];
+      ++v6;
+      *(short *)((char *)&v7 + 1) = v8->uParticleTrailColorR;
+      LOBYTE(v7) = v8->uParticleTrailColorG;
+      ++v5;
+      v8->uParticleTrailColor = v8->uParticleTrailColorB | (v7 << 8);
+    }
+    while ( v5 < (signed int)pObjectList->uNumObjects );
+  }
+  flt_6BE3A0 = 0.55000001f;
+  MainMenuUI_Create();
+  pGame->pStru6Instance->LoadAnimations();
+
+  for (uint i = 0; i < 7; ++i)
+  {
+    sprintf(pContainer, "HDWTR%03u", i);
+    pRenderer->pHDWaterBitmapIDs[i] = pBitmaps_LOD->LoadTexture(pContainer);
+  }
+
+  pNPCStats = new NPCStats;
+  pNPCStats->Initialize();
+
+  Initialize_GlobalEVT();
+  pBitmaps_LOD->dword_11B80 = pBitmaps_LOD->uNumLoadedFiles;
+  if ( pBitmaps_LOD->dword_11B84 < (signed int)pBitmaps_LOD->uNumLoadedFiles )
+    pBitmaps_LOD->dword_11B84 = pBitmaps_LOD->uNumLoadedFiles;
+  pSprites_LOD->field_ECA4 = pSprites_LOD->uNumLoadedSprites;
+  if ( pSprites_LOD->field_ECA0 < (signed int)pSprites_LOD->uNumLoadedSprites )
+    pSprites_LOD->field_ECA0 = pSprites_LOD->uNumLoadedSprites;
+  pPaletteManager->LockAll();
+
+  _mkdir("Saves");
+  for (uint i = 0; i < 5; ++i)
+    for (uint j = 0; j < 6; ++j)
+    {
+      sprintf(pTmpBuf, "data\\lloyd%d%d.pcx", i, j);
+      remove(pTmpBuf);
+    }
+  /*do
+  {
+    v11 = 1;
+    do
+    {
+      sprintfex(pTmpBuf, "data\\lloyd%d%d.pcx", v10, v11);
+      remove(pTmpBuf);
+      ++v11;
+    }
+    while ( v11 < 6 );
+    ++v10;
+  }
+  while ( v10 < 5 );*/
+
+  Initialize_GamesLOD_NewLOD();
+  dword_576E2C = 512;
+  dword_576E28 = 9;
+}
+
+
+
+
+
+
+
+
+
+//----- (00462C94) --------------------------------------------------------
+bool MM_Main(const wchar_t *pCmdLine)
+{
+  HWND hPrevWnd; // eax@1
+  HWND hPrevWnd_; // esi@1
+  HWND v6; // eax@4
+  int v8; // eax@15
+  //bool v9; // edx@16
+  //OtherOverlay *v10; // esi@44
+  //signed int v11; // edi@44
+  unsigned int v12; // ecx@56
+  HANDLE v13; // eax@68
+  unsigned int startms; // [sp+8h] [bp-24h]@55
+  RECT Rect; // [sp+Ch] [bp-20h]@15
+  int a2[4]; // [sp+1Ch] [bp-10h]@15
+
+  auto mm7text_dll = LoadLibraryW(L"mm7text.dll");
+  sprintfex = (int (__cdecl *)(char *a1, const char *a2, ...))GetProcAddress(mm7text_dll, "_sprintfex");
+
+  if (pCmdLine && *pCmdLine)
+  {
+    if (wcsstr(pCmdLine, L"-usedefs"))
+      bDebugResouces = 1;
+    if (wcsstr(pCmdLine, L"-window"))
+      dword_6BE368_debug_settings_2 |= 1u;
+
+    if (wcsstr(pCmdLine, L"-nointro"))
+      bNoIntro = true;//dword_6BE364_game_settings_1 |= 4;
+    if (wcsstr(pCmdLine, L"-nologo"))
+      bNoLogo = true;//dword_6BE364_game_settings_1 |= 8;
+    if (wcsstr(pCmdLine, L"-nosound"))
+      bNoSound = true; //dword_6BE364_game_settings_1 |= 0x10;
+
+    bWalkSound = ReadWindowsRegistryInt("WalkSound", 1) != 0;
+    if (wcsstr(pCmdLine, L"-nowalksound"))
+      bWalkSound = false;//dword_6BE364_game_settings_1 |= 0x20;
+    if (wcsstr(pCmdLine, L"-noanim"))
+    {
+      dword_6BE364_game_settings_1 |= 0x40;
+      bNoVideo = true;
+    }
+    if (wcsstr(pCmdLine, L"-nocd"))
+      bNoCD = true;
+  }
+  stru_51076C.registry_debug_flags = ReadWindowsRegistryInt("debug flags", 0);
+
+
+  v8 = sub_4AC1C9(0, (Vec4_int_ *)a2);
+  Rect.left = *(int *)v8;
+  Rect.top = *(int *)(v8 + 4);
+  Rect.right = *(int *)(v8 + 8);
+  Rect.bottom = *(int *)(v8 + 12);
+  uCPUSpeed = Rect.bottom;
+  
+  if (MM7_Initialize())
+  {
+    Log::Warning(L"MM init: ok");
+
+    pEventTimer->Pause();
+    if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
+    {
+      SetWindowPos(hWnd, (HWND)((int)HWND_MESSAGE|0x2), 320, 240, 640, 480, 0);
+      Rect.left = 325;
+      Rect.top = 245;
+      Rect.right = 326;
+      Rect.bottom = 246;
+      ClipCursor(&Rect);
+    }
+    SetUserInterface(1, false);
+    ShowIntroVideo_and_LoadingScreen();
+    WriteWindowsRegistryInt("Ran once", 1);
+    dword_6BE364_game_settings_1 |= 0x4000;
+    pGame->InitializeGammaController();
+    SecondaryInitialization();
+    pRenderer->Clip_v2(0, 0, 639u, 479u);
+    FinalInitialization();
+
+    Log::Warning(L"MM: entering main loop");
+    while ( 1 )
+    {
+      MainMenu_Loop(); // ïðîðèñîâêà Ãëàâíîãî ìåíþ è òóò æå ïðîðèñîâêà ìåíþ Çàãðóçêà
+      uGameState = 0;
+//LABEL_21:
+      while ( 1 )
+      {
+        switch (uGameState)
+        {
+          case GAME_FINISHED: // âûõîä èç èãðû
+            pGame->Deinitialize();
+            return true; // âûõîä èç ôóíêöèè MM_Main â Win_Main
+        }
+        if (GetCurrentMenuID() == MENU_FINISHED) // ìåíþ Âûõîä
+        {
+          uGameState = GAME_FINISHED;
+          continue; // â íà÷àëî öèêëà
+        }
+        if (GetCurrentMenuID() == MENU_NEWGAME)                // ìåíþ Íîâàÿ èãðà
+        {
+          if ( pAudioPlayer->hAILRedbook )
+            AIL_redbook_stop(pAudioPlayer->hAILRedbook);      // îñòàíîâèòü ìóçûêó
+          pParty->Reset();                                    // ñáðîñ ãðóïïû
+          for (uint k = 0; k < 50; ++k)
+            pOtherOverlayList->pOverlays[k].Reset();
+          strcpy(pCurrentMapName, pStartingMapName);         // òåêóùàÿ êàðòà
+          pParty->CreateDefaultParty(0);                     // ñîçäàòü ãðóïïó ïî óìîë÷àíèþ
+          PlayerCreationUI_Initialize();
+          if ( PlayerCreationUI_Loop() )                    //ïðîöåññ ñîçäàíèÿ ãðóïïû
+          {
+            DeleteCCharFont();
+            break;// âûõîä èç öèêëà
+          }
+          DeleteCCharFont();
+          bFlashQuestBook = true;
+          pGame->pCShow->PlayMovie(MOVIE_Emerald, 0);       //çàñòàâêà
+          Autosave();                                       //àâòîñîõðàíåíèå
+          //goto LABEL_48;
+          pGame->Loop(); // ïðîöåññ èãðû
+          break; // âûõîä èç öèêëà
+        }
+        if (GetCurrentMenuID() == MENU_CREDITS) // ìåíþ Ñîçäàòåëè
+        {
+         if ( pAudioPlayer->hAILRedbook )
+          AIL_redbook_stop(pAudioPlayer->hAILRedbook);// îòêëþ÷èòü çâóê
+         extern MENU_STATE __cdecl CreditsMenu__Loop();
+         CreditsMenu__Loop(); // ïðîöåññ âîñïðîèçâåäåíèÿ îêíà Ñîçäàòåëè
+         break;
+        }
+        if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LOAD) //??? íåèçâåñòíî ÷òî ýòî
+          __debugbreak();
+        /*{
+          uGameState = 0;
+        }*/
+        else
+         __debugbreak();// ïîêà áðÿêïîèíòû
+        /*{
+          if (GetCurrentMenuID() != MENU_10)
+            goto LABEL_49;
+          pMouse->Activate(0);
+          if (pAsyncMouse)
+            pAsyncMouse->Suspend();
+          if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
+            pAsyncKeyboard->Suspend();
+          pParty->Reset();
+          pParty->CreateDefaultParty(1);
+          crt_init_globals_46271C();
+          extern OPENFILENAMEA ofn;
+          if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
+          {
+            pMouse->Activate(1);
+            if (pAsyncMouse)
+              pAsyncMouse->Resume();
+            if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
+              pAsyncKeyboard->Resume();
+            break;
+          }
+          _chdir("..\\");
+          strcpy(pCurrentMapName, ofn.lpstrFileTitle);
+          pMouse->Activate(1);
+          if (pAsyncMouse)
+            pAsyncMouse->Resume();
+          if ( LOBYTE(pGame->pKeyboardInstance->bUsingAsynKeyboard) && pAsyncKeyboard )
+            pAsyncKeyboard->Resume();
+        }
+//LABEL_48:
+//        pGame->Loop(); //game
+LABEL_49:*/
+        if ( uGameState == 3 )
+          __debugbreak();
+        /*{
+          v12 = 5;
+          SetCurrentMenuID((MENU_STATE)v12);
+          //goto LABEL_21;
+          uGameState = 0;
+          continue;
+        }*/
+        if ( uGameState == 4 )
+          __debugbreak();
+        /*{
+          v12 = 1;
+          SetCurrentMenuID((MENU_STATE)v12);
+          //goto LABEL_21;
+          uGameState = 0;
+          continue;
+        }*/
+        if ( uGameState == 7 )
+          __debugbreak();
+        /*{
+          pAudioPlayer->StopChannels(-1, -1);
+          uGameState = 0;
+          break;
+        }*/
+      }
+      if (!bNoSound && pAudioPlayer->hAILRedbook)
+      {
+        pAudioPlayer->SetMusicVolume((pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
+        AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+        unsigned int end_ms;
+        AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 0xE, &startms, &end_ms);
+        AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
+      }
+    }
+  }
+  else
+  Log::Warning(L"MM init: failed");
+  pGame->Deinitialize();
+}
+
+
+
+
+
+//----- (004637E0) --------------------------------------------------------
+char __cdecl sub_4637E0_is_there_popup_onscreen()
+{
+  return dword_507BF0_is_there_popup_onscreen == 1;
+}
+// 507BF0: using guessed type int dword_507BF0_is_there_popup_onscreen;
+
+
+
+//----- (00465F5A) --------------------------------------------------------
+void __cdecl CreateAsyncMouse()
+{
+  LOG_DECOMPILATION_WARNING();
+  /*
+  if (!pAsyncMouse &&
+      pRenderer->bUserDirect3D &&
+      pRenderer->uAcquiredDirect3DDevice == 1)
+  {
+    pAsyncMouse = new AsyncMouse(&pRenderer->pDirectDraw4);
+    if (pAsyncMouse)
+      pAsyncMouse->Resume();
+  }*/
+}
+
+//----- (00465FF0) --------------------------------------------------------
+void __cdecl CreateAsyncKeyboard()
+{
+  LOG_DECOMPILATION_WARNING();
+  /*
+  if (!pAsyncKeyboard &&
+      pGame->pKeyboardInstance->bUsingAsynKeyboard)
+  {
+    pAsyncKeyboard = new AsyncKeyboard;
+    if (pAsyncKeyboard)
+      pAsyncKeyboard->Resume();
+  }*/
+}
+
+//----- (00466082) --------------------------------------------------------
+void MM6_Initialize(const wchar_t *pIniFilename)
+{
+  //int v0; // eax@1
+  UINT v1; // eax@18
+  size_t v2; // eax@31
+  size_t v3; // ebx@32
+  size_t v4; // edi@36
+  //char v5[120]; // [sp+Ch] [bp-17Ch]@1
+  //char String[120]; // [sp+84h] [bp-104h]@32
+  char pDefaultGroundTexture[16]; // [sp+FCh] [bp-8Ch]@32
+  //char pIniFilename[120]; // [sp+10Ch] [bp-7Ch]@1
+  unsigned int v9; // [sp+184h] [bp-4h]@28
+
+  //_getcwd(v5, 120);
+  //sprintfex(pIniFilename, "%s\\mm6.ini", v5);
+  viewparams = new ViewingParams;
+  viewparams->uScreenX = GetPrivateProfileIntW(L"screen", L"vx1", 8, pIniFilename);
+  viewparams->uScreenY = GetPrivateProfileIntW(L"screen", L"vy1", 8, pIniFilename);
+  viewparams->uScreenZ = GetPrivateProfileIntW(L"screen", L"vx2", 468, pIniFilename);
+  viewparams->uScreenW = GetPrivateProfileIntW(L"screen", L"vy2", 351, pIniFilename);
+
+
+  pAudioPlayer = new AudioPlayer;
+  pAudioPlayer->uMixerChannels = GetPrivateProfileIntW(L"settings", L"mixerchannels", 16, pIniFilename);
+  if ( pAudioPlayer->uMixerChannels > 16 )
+    pAudioPlayer->uMixerChannels = 16;
+
+
+  if (GetPrivateProfileIntW(L"debug", L"nomonster", 0, pIniFilename))
+    dword_6BE368_debug_settings_2 |= 4;
+  if (bUseRegistry)
+    v1 = ReadWindowsRegistryInt("startinwindow", 0);
+  else
+    v1 = GetPrivateProfileIntW(L"debug", L"startinwindow", 0, pIniFilename);
+  if (v1)
+    dword_6BE368_debug_settings_2 |= 1;
+  if (GetPrivateProfileIntW(L"debug", L"showFR", 0, pIniFilename))
+    dword_6BE368_debug_settings_2 |= 2;
+  if (GetPrivateProfileIntW(L"debug", L"nodamage", 0, pIniFilename))
+    dword_6BE368_debug_settings_2 |= 0x10;
+  if (GetPrivateProfileIntW(L"debug", L"nodecoration", 0, pIniFilename))
+    dword_6BE368_debug_settings_2 |= 8;
+
+  wchar_t pStartingMapNameW[1024];
+  GetPrivateProfileStringW(L"file", L"startmap", L"out01.odm", pStartingMapNameW, 0x20u, pIniFilename);
+  sprintf(pStartingMapName, "%S", pStartingMapNameW);
+
+  v9 = 0;
+  if ( strlen(pStartingMapName) )
+  {
+    do
+    {
+      if ( pStartingMapName[v9] == 32 )
+        pStartingMapName[v9] = 0;
+      ++v9;
+      v2 = strlen(pStartingMapName);
+    }
+    while ( v9 < v2 );
+  }
+
+  pOutdoorCamera = new OutdoorCamera;
+  outdoor_day_top_r      = GetPrivateProfileIntW(L"outdoor", L"RGBDayTop.r", 81, pIniFilename);
+  outdoor_day_top_g      = GetPrivateProfileIntW(L"outdoor", L"RGBDayTop.g", 121, pIniFilename);
+  outdoor_day_top_b      = GetPrivateProfileIntW(L"outdoor", L"RGBDayTop.b", 236, pIniFilename);
+  outdoor_day_bottom_r   = GetPrivateProfileIntW(L"outdoor", L"RGBDayBottom.r", 153, pIniFilename);
+  outdoor_day_bottom_g   = GetPrivateProfileIntW(L"outdoor", L"RGBDayBottom.g", 193, pIniFilename);
+  outdoor_day_bottom_b   = GetPrivateProfileIntW(L"outdoor", L"RGBDayBottom.b", 237, pIniFilename);
+  outdoor_night_top_r    = GetPrivateProfileIntW(L"outdoor", L"RGBNightTop.r", 0, pIniFilename);
+  outdoor_night_top_g    = GetPrivateProfileIntW(L"outdoor", L"RGBNightTop.g", 0, pIniFilename);
+  outdoor_night_top_b    = GetPrivateProfileIntW(L"outdoor", L"RGBNightTop.b", 0, pIniFilename);
+  outdoor_night_bottom_r = GetPrivateProfileIntW(L"outdoor", L"RGBNightBottom.r", 11, pIniFilename);
+  outdoor_night_bottom_g = GetPrivateProfileIntW(L"outdoor", L"RGBNightBottom.g", 41, pIniFilename);
+  outdoor_night_bottom_b = GetPrivateProfileIntW(L"outdoor", L"RGBNightBottom.b", 129, pIniFilename);
+  pOutdoorCamera->outdoor_no_mist = GetPrivateProfileIntW(L"debug", L"noMist", 0, pIniFilename);
+  pOutdoorCamera->bNoSky          = GetPrivateProfileIntW(L"outdoor", L"nosky", 0, pIniFilename);
+  pOutdoorCamera->bDoNotRenderDecorations = GetPrivateProfileIntW(L"render", L"nodecorations", 0, pIniFilename);
+  pOutdoorCamera->outdoor_no_wavy_water   = GetPrivateProfileIntW(L"outdoor", L"nowavywater", 0, pIniFilename);
+  outdoor_grid_band_1 = GetPrivateProfileIntW(L"outdoor", L"gridband1", 10, pIniFilename);
+  outdoor_grid_band_2 = GetPrivateProfileIntW(L"outdoor", L"gridband2", 15, pIniFilename);
+  outdoor_grid_band_3 = GetPrivateProfileIntW(L"outdoor", L"gridband3", 25, pIniFilename);
+  pOutdoorCamera->terrain_gamma  = GetPrivateProfileIntW(L"outdoor", L"ter_gamma", 0, pIniFilename);
+  pOutdoorCamera->building_gamme = GetPrivateProfileIntW(L"outdoor", L"bld_gamma", 0, pIniFilename);
+  mipmapping_terrain_mm1  = GetPrivateProfileIntW(L"mipmapping", L"ter_mm1", 2048, pIniFilename);
+  mipmapping_terrain_mm2  = GetPrivateProfileIntW(L"mipmapping", L"ter_mm2", 4096, pIniFilename);
+  mipmapping_terrain_mm3  = GetPrivateProfileIntW(L"mipmapping", L"ter_mm3", 8192, pIniFilename);
+  mipmapping_building_mm1 = GetPrivateProfileIntW(L"mipmapping", L"bld_mm1", 1024, pIniFilename);
+  mipmapping_building_mm2 = GetPrivateProfileIntW(L"mipmapping", L"bld_mm2", 2048, pIniFilename);
+  mipmapping_building_mm3 = GetPrivateProfileIntW(L"mipmapping", L"bld_mm3", 4096, pIniFilename);
+  pOutdoorCamera->shading_dist_shade     = GetPrivateProfileIntW(L"shading", L"dist_shade", 2048, pIniFilename);
+  pOutdoorCamera->shading_dist_shademist = GetPrivateProfileIntW(L"shading", L"dist_shademist", 4096, pIniFilename);
+  pOutdoorCamera->shading_dist_mist      = GetPrivateProfileIntW(L"shading", L"dist_mist", 8192, pIniFilename);
+
+  wchar_t pDefaultSkyTextureW[1024];
+  GetPrivateProfileStringW(L"textures", L"sky", L"plansky1", pDefaultSkyTextureW, 0x10u, pIniFilename);
+  sprintf(pDefaultSkyTexture, "%S", pDefaultSkyTextureW);
+
+  wchar_t pDefaultGroundTextureW[1024];
+  GetPrivateProfileStringW(L"textures", L"default", L"dirt", pDefaultGroundTextureW, 0x10u, pIniFilename);
+  sprintf(pDefaultGroundTexture, "%S", pDefaultGroundTextureW);
+
+  wchar_t pFloat[1024];
+  GetPrivateProfileStringW(L"debug", L"recmod1", L"1.0", pFloat, 0x10u, pIniFilename);
+  swscanf(pFloat, L"%f", &flt_6BE3A4_debug_recmod1);
+
+  GetPrivateProfileStringW(L"debug", L"recmod2", L"1.0", pFloat, 0x10u, pIniFilename);
+  swscanf(pFloat, L"%f", &flt_6BE3A8_debug_recmod2);
+
+  flt_6BE3AC_debug_recmod1_x_1_6 = flt_6BE3A4_debug_recmod1 * 1.666666666666667;
+
+  v3 = 0;
+  if ( strlen(pDefaultSkyTexture) )
+  {
+    do
+    {
+      if ( pDefaultSkyTexture[v3] == ' ' )
+        pDefaultSkyTexture[v3] = 0;
+      ++v3;
+    }
+    while ( v3 < strlen(pDefaultSkyTexture) );
+  }
+  v4 = 0;
+  if ( strlen(pDefaultGroundTexture) )
+  {
+    do
+    {
+      if ( pDefaultGroundTexture[v4] == ' ' )
+        pDefaultGroundTexture[v4] = 0;
+      ++v4;
+    }
+    while ( v4 < strlen(pDefaultGroundTexture) );
+  }
+
+  texmapping_terrain_subdivsize  = GetPrivateProfileIntW(L"texmapping", L"terrain_subdivsize", 16, pIniFilename);
+  texmapping_terrain_subdivpow2  = GetPrivateProfileIntW(L"texmapping", L"terrain_subdivpow2", 4, pIniFilename);
+  texmapping_building_subdivsize = GetPrivateProfileIntW(L"texmapping", L"building_subdivsize", 32, pIniFilename);
+  texmapping_building_subdivpow2 = GetPrivateProfileIntW(L"texmapping", L"building_subdivpow2", 5, pIniFilename);
+
+  MM7Initialization();
+}
+
+//----- (004666D5) --------------------------------------------------------
+void __cdecl MM7Initialization()
+{
+  if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+  {
+    if ( !byte_6BE388_graphicsmode )
+    {
+      outdoor_grid_band_1 = 10;
+      outdoor_grid_band_2 = 15;
+      outdoor_grid_band_3 = 20;
+      pOutdoorCamera->shading_dist_mist = 8192;
+      pOutdoorCamera->bNoSky = 0;
+      LOBYTE(viewparams->field_20) = 0;
+    }
+    mipmapping_terrain_mm1 = 1024;
+    mipmapping_terrain_mm2 = 2048;
+    mipmapping_building_mm1 = 1024;
+    mipmapping_building_mm2 = 2048;
+    pOutdoorCamera->shading_dist_shade = 2048;
+    pOutdoorCamera->terrain_gamma = 0;
+    pOutdoorCamera->building_gamme = 0;
+    mipmapping_terrain_mm3 = 4096;
+    mipmapping_building_mm3 = 4096;
+    pOutdoorCamera->shading_dist_shademist = 4096;
+    pOutdoorCamera->outdoor_no_wavy_water = 0;
+    sub_47F4D3(outdoor_grid_band_1, outdoor_grid_band_2, outdoor_grid_band_3);
+  }
+  else
+  {
+    LOBYTE(viewparams->field_20) = 0;
+  }
+  pParty->uFlags |= 2u;
+  viewparams->uSomeY = viewparams->uScreenY;
+  viewparams->uSomeX = viewparams->uScreenX;
+  viewparams->uSomeZ = viewparams->uScreenZ;
+  viewparams->uSomeW = viewparams->uScreenW;
+
+  pViewport->SetScreen(viewparams->uScreenX, viewparams->uScreenY, viewparams->uScreenZ, viewparams->uScreenW);
+  if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+    pOutdoorCamera->_485F64();
+}
+
+
+//----- (00466B8C) --------------------------------------------------------
+int __cdecl AbortWithError()
+{
+  if ( !aborting_app )
+  {
+    ClipCursor(0);
+    aborting_app = 1;
+    if ( !pRenderer->bWindowMode )
+      pRenderer->ChangeBetweenWinFullscreenModes();
+    if ( MessageBoxA(0, pGlobalTXT_LocalizationStrings[176], pGlobalTXT_LocalizationStrings[59], 0x34u) == 6 )
+      SaveGame(1, 0);                           // "Internal Error"
+                                                // "Might and Magic VII has detected an internal error and will be forced to close.  Would you like us to autosave your game before closing?"
+    Game_DeinitializeAndTerminate(1);
+  }
+  return 0;
+}
+// 720018: using guessed type int aborting_app;
+
+//----- (00466BE5) --------------------------------------------------------
+void Abortf(const char *Format, ...)
+{
+  va_list va; // [sp+8h] [bp+8h]@1
+
+  va_start(va, Format);
+  if ( !pRenderer->bWindowMode )
+    pRenderer->ChangeBetweenWinFullscreenModes();
+  vsprintf(pTmpBuf, Format, va);
+  if ( pMouse )
+    pMouse->Activate(0);
+  ClipCursor(0);
+  MessageBoxA(0, pTmpBuf, "Error", 0x30u);
+  Game_DeinitializeAndTerminate(1);
+}
+
+//----- (00466C40) --------------------------------------------------------
+const wchar_t *MENU_STATE_to_string(MENU_STATE m)
+{
+  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 MENU_7:           return L"MENU_7";
+    case MENU_Credits:     return L"MENU_Credits";
+    case MENU_LOAD:        return L"MENU_LOAD";
+    case MENU_10:          return L"MENU_10";
+    default:               return L"unk";
+  };
+};
+void SetCurrentMenuID(MENU_STATE uMenu)
+{
+  if ((int)uCurrentMenuID != -1)
+  {
+    if (pGame->pKeyboardInstance->bUsingAsynKeyboard && pAsyncKeyboard)
+      pAsyncKeyboard->Resume();
+  }
+  uCurrentMenuID = uMenu;
+
+  Log::Warning(L"CurrentMenu = %s", MENU_STATE_to_string(uMenu));
+}
+
+//----- (00466CA0) --------------------------------------------------------
+MENU_STATE GetCurrentMenuID()
+{
+  return uCurrentMenuID;
+}
+
+
+
+
+
+/*
+    v17 = 0;
+    if ( v4 > -2005532222 )
+    {
+      switch ( v4 + 2005532212 )
+      {
+        case 0:
+          v7 = "DDERR_SURFACENOTATTACHED";
+          goto LABEL_173;
+        case 10:
+          v7 = "DDERR_TOOBIGHEIGHT";
+          goto LABEL_173;
+        case 20:
+          v7 = "DDERR_TOOBIGSIZE";
+          goto LABEL_173;
+        case 30:
+          v7 = "DDERR_TOOBIGWIDTH";
+          goto LABEL_173;
+        case 50:
+          v7 = "DDERR_UNSUPPORTEDFORMAT";
+          goto LABEL_173;
+        case 60:
+          v7 = "DDERR_UNSUPPORTEDMASK";
+          goto LABEL_173;
+        case 61:
+          v7 = "DDERR_INVALIDSTREAM";
+          goto LABEL_173;
+        case 77:
+          v7 = "DDERR_VERTICALBLANKINPROGRESS";
+          goto LABEL_173;
+        case 80:
+          v7 = "DDERR_WASSTILLDRAWING";
+          goto LABEL_173;
+        case 100:
+          v7 = "DDERR_XALIGN";
+          goto LABEL_173;
+        case 101:
+          v7 = "DDERR_INVALIDDIRECTDRAWGUID";
+          goto LABEL_173;
+        case 102:
+          v7 = "DDERR_DIRECTDRAWALREADYCREATED";
+          goto LABEL_173;
+        case 103:
+          v7 = "DDERR_NODIRECTDRAWHW";
+          goto LABEL_173;
+        case 104:
+          v7 = "DDERR_PRIMARYSURFACEALREADYEXISTS";
+          goto LABEL_173;
+        case 105:
+          v7 = "DDERR_NOEMULATION";
+          goto LABEL_173;
+        case 106:
+          v7 = "DDERR_REGIONTOOSMALL";
+          goto LABEL_173;
+        case 107:
+          v7 = "DDERR_CLIPPERISUSINGHWND";
+          goto LABEL_173;
+        case 108:
+          v7 = "DDERR_NOCLIPPERATTACHED";
+          goto LABEL_173;
+        case 109:
+          v7 = "DDERR_NOHWND";
+          goto LABEL_173;
+        case 110:
+          v7 = "DDERR_HWNDSUBCLASSED";
+          goto LABEL_173;
+        case 111:
+          v7 = "DDERR_HWNDALREADYSET";
+          goto LABEL_173;
+        case 112:
+          v7 = "DDERR_NOPALETTEATTACHED";
+          goto LABEL_173;
+        case 113:
+          v7 = "DDERR_NOPALETTEHW";
+          goto LABEL_173;
+        case 114:
+          v7 = "DDERR_BLTFASTCANTCLIP";
+          goto LABEL_173;
+        case 115:
+          v7 = "DDERR_NOBLTHW";
+          goto LABEL_173;
+        case 116:
+          v7 = "DDERR_NODDROPSHW";
+          goto LABEL_173;
+        case 117:
+          v7 = "DDERR_OVERLAYNOTVISIBLE";
+          goto LABEL_173;
+        case 118:
+          v7 = "DDERR_NOOVERLAYDEST";
+          goto LABEL_173;
+        case 119:
+          v7 = "DDERR_INVALIDPOSITION";
+          goto LABEL_173;
+        case 120:
+          v7 = "DDERR_NOTAOVERLAYSURFACE";
+          goto LABEL_173;
+        case 121:
+          v7 = "DDERR_EXCLUSIVEMODEALREADYSET";
+          goto LABEL_173;
+        case 122:
+          v7 = "DDERR_NOTFLIPPABLE";
+          goto LABEL_173;
+        case 123:
+          v7 = "DDERR_CANTDUPLICATE";
+          goto LABEL_173;
+        case 125:
+          v7 = "DDERR_CANTCREATEDC";
+          goto LABEL_173;
+        case 126:
+          v7 = "DDERR_NODC";
+          goto LABEL_173;
+        case 127:
+          v7 = "DDERR_WRONGMODE";
+          goto LABEL_173;
+        case 128:
+          v7 = "DDERR_IMPLICITLYCREATED";
+          goto LABEL_173;
+        case 129:
+          v7 = "DDERR_NOTPALETTIZED";
+          goto LABEL_173;
+        case 130:
+          v7 = "DDERR_UNSUPPORTEDMODE";
+          goto LABEL_173;
+        case 131:
+          v7 = "DDERR_NOMIPMAPHW";
+          goto LABEL_173;
+        case 132:
+          v7 = "DDERR_INVALIDSURFACETYPE";
+          goto LABEL_173;
+        case 140:
+          v7 = "DDERR_NOOPTIMIZEHW";
+          goto LABEL_173;
+        case 141:
+          v7 = "DDERR_NOTLOADED";
+          goto LABEL_173;
+        case 142:
+          v7 = "DDERR_NOFOCUSWINDOW";
+          goto LABEL_173;
+        case 160:
+          v7 = "DDERR_DCALREADYCREATED";
+          goto LABEL_173;
+        case 170:
+          v7 = "DDERR_NONONLOCALVIDMEM";
+          goto LABEL_173;
+        case 180:
+          v7 = "DDERR_CANTPAGELOCK";
+          goto LABEL_173;
+        case 200:
+          v7 = "DDERR_CANTPAGEUNLOCK";
+          goto LABEL_173;
+        case 220:
+          v7 = "DDERR_NOTPAGELOCKED";
+          goto LABEL_173;
+        case 230:
+          v7 = "DDERR_MOREDATA";
+          goto LABEL_173;
+        case 231:
+          v7 = "DDERR_EXPIRED";
+          goto LABEL_173;
+        case 235:
+          v7 = "DDERR_VIDEONOTACTIVE";
+          goto LABEL_173;
+        case 239:
+          v7 = "DDERR_DEVICEDOESNTOWNSURFACE";
+          goto LABEL_173;
+        default:
+          goto LABEL_174;
+        case 124:
+          goto LABEL_176;
+      }
+      goto LABEL_176;
+    }
+    if ( v4 != -2005532222 )
+    {
+      if ( v4 > -2005532447 )
+      {
+        if ( v4 <= -2005532337 )
+        {
+          if ( v4 == -2005532337 )
+          {
+            v7 = "DDERR_NOVSYNCHW";
+            goto LABEL_173;
+          }
+          if ( v4 > -2005532392 )
+          {
+            if ( v4 == -2005532382 )
+            {
+              v7 = "DDERR_NOROTATIONHW";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532362 )
+            {
+              v7 = "DDERR_NOSTRETCHHW";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532356 )
+            {
+              v7 = "DDERR_NOT4BITCOLOR";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532355 )
+            {
+              v7 = "DDERR_NOT4BITCOLORINDEX";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532352 )
+            {
+              v7 = "DDERR_NOT8BITCOLOR";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532342 )
+            {
+              v7 = "DDERR_NOTEXTUREHW";
+              goto LABEL_173;
+            }
+          }
+          else
+          {
+            if ( v4 == -2005532392 )
+            {
+              v7 = "DDERR_NORASTEROPHW";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532442 )
+            {
+              v7 = "DDERR_NOFLIPHW";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532432 )
+            {
+              v7 = "DDERR_NOGDI";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532422 )
+            {
+              v7 = "DDERR_NOMIRRORHW";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532417 )
+            {
+              v7 = "DDERR_NOTFOUND";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532412 )
+            {
+              v7 = "DDERR_NOOVERLAYHW";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532402 )
+            {
+              v7 = "DDERR_OVERLAPPINGRECTS";
+              goto LABEL_173;
+            }
+          }
+          goto LABEL_174;
+        }
+        if ( v4 <= -2005532285 )
+        {
+          if ( v4 == -2005532285 )
+          {
+            v7 = "DDERR_PALETTEBUSY";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532332 )
+          {
+            v7 = "DDERR_NOZBUFFERHW";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532322 )
+          {
+            v7 = "DDERR_NOZOVERLAYHW";
+            goto LABEL_173;
+          }
+          if ( v4 == DDERR_OUTOFCAPS )
+          {
+            v7 = "DDERR_OUTOFCAPS";
+            goto LABEL_173;
+          }
+          if ( v4 == DDERR_OUTOFVIDEOMEMORY )
+          {
+            v7 = "DDERR_OUTOFVIDEOMEMORY";
+            goto LABEL_173;
+          }
+          if ( v4 == DDERR_OVERLAYCANTCLIP )
+          {
+            v7 = "DDERR_OVERLAYCANTCLIP";
+            goto LABEL_173;
+          }
+          if ( v4 == DDERR_OVERLAYCOLORKEYONLYONEACTIVE )
+          {
+            v7 = "DDERR_OVERLAYCOLORKEYONLYONEACTIVE";
+            goto LABEL_173;
+          }
+          goto LABEL_174;
+        }
+        if ( v4 == -2005532272 )
+        {
+          v7 = "DDERR_COLORKEYNOTSET";
+          goto LABEL_173;
+        }
+        if ( v4 == -2005532262 )
+        {
+          v7 = "DDERR_SURFACEALREADYATTACHED";
+          goto LABEL_173;
+        }
+        if ( v4 == -2005532252 )
+        {
+          v7 = "DDERR_SURFACEALREADYDEPENDENT";
+          goto LABEL_173;
+        }
+        if ( v4 != -2005532242 )
+        {
+          if ( v4 == -2005532237 )
+          {
+            v7 = "DDERR_CANTLOCKSURFACE";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532232 )
+          {
+            v7 = "DDERR_SURFACEISOBSCURED";
+            goto LABEL_173;
+          }
+          goto LABEL_174;
+        }
+      }
+      else
+      {
+        if ( v4 == -2005532447 )
+        {
+          v7 = "DDERR_NOEXCLUSIVEMODE";
+          goto LABEL_173;
+        }
+        if ( v4 <= -2005532562 )
+        {
+          if ( v4 == -2005532562 )
+          {
+            v7 = "DDERR_INVALIDCLIPLIST";
+            goto LABEL_173;
+          }
+          if ( v4 > -2005532662 )
+          {
+            if ( v4 == -2005532652 )
+            {
+              v7 = "DDERR_CANNOTDETACHSURFACE";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532632 )
+            {
+              v7 = "DDERR_CURRENTLYNOTAVAIL";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532617 )
+            {
+              v7 = "DDERR_EXCEPTION";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532582 )
+            {
+              v7 = "DDERR_HEIGHTALIGN";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532577 )
+            {
+              v7 = "DDERR_INCOMPATIBLEPRIMARY";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532572 )
+            {
+              v7 = "DDERR_INVALIDCAPS";
+              goto LABEL_173;
+            }
+          }
+          else
+          {
+            if ( v4 == -2005532662 )
+            {
+              v7 = "DDERR_CANNOTATTACHSURFACE";
+              goto LABEL_173;
+            }
+            if ( v4 == -2147467263 )
+            {
+              v7 = "DDERR_UNSUPPORTED";
+              goto LABEL_173;
+            }
+            if ( v4 == -2147467259 )
+            {
+              v7 = "DDERR_GENERIC";
+              goto LABEL_173;
+            }
+            if ( v4 == -2147221008 )
+            {
+              v7 = "DDERR_NOTINITIALIZED";
+              goto LABEL_173;
+            }
+            if ( v4 == -2147024882 )
+            {
+              v7 = "DDERR_OUTOFMEMORY";
+              goto LABEL_173;
+            }
+            if ( v4 == -2147024809 )
+            {
+              v7 = "DDERR_INVALIDPARAMS";
+              goto LABEL_173;
+            }
+            if ( v4 == -2005532667 )
+            {
+              v7 = "DDERR_ALREADYINITIALIZED";
+LABEL_173:
+              v13 = strlen(v7);
+              v12 = (char *)v7;
+LABEL_175:
+              std::stringoperator_assign__const_char_ptr__(&a1, v12, v13);
+              v13 = a3;
+              pRenderer->field_40110 = 0;
+              v15 = &v11;
+              std::string40E2C8(&v11, Str, (int)((char *)&hr + 3));
+              v10 = 48;
+              LOBYTE(v17) = 1;
+              Str = (char *)&v9;
+              std::string40E2C8(&v9, "Direct Draw Error", (int)((char *)&a3 + 3));
+              LOBYTE(v17) = 0;
+              CheckHRESULT_stru0::ShowMessageBox(v6, &a1, v9, v10, v11, v13);
+              v5 = 1;
+              goto LABEL_176;
+            }
+          }
+LABEL_174:
+          sprintfex(&Src, "Unknown DirectDraw/Direct3D error number %X", v4);
+          v13 = strlen(&Src);
+          v12 = &Src;
+          goto LABEL_175;
+        }
+        if ( v4 > -2005532492 )
+        {
+          if ( v4 == -2005532467 )
+          {
+            v7 = "DDERR_NOCLIPLIST";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532462 )
+          {
+            v7 = "DDERR_NOCOLORCONVHW";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532460 )
+          {
+            v7 = "DDERR_NOCOOPERATIVELEVELSET";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532457 )
+          {
+            v7 = "DDERR_NOCOLORKEY";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532452 )
+          {
+            v7 = "DDERR_NOCOLORKEYHW";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532450 )
+          {
+            v7 = "DDERR_NODIRECTDRAWSUPPORT";
+            goto LABEL_173;
+          }
+          goto LABEL_174;
+        }
+        if ( v4 == -2005532492 )
+        {
+          v7 = "DDERR_NOALPHAHW";
+          goto LABEL_173;
+        }
+        if ( v4 == -2005532552 )
+        {
+          v7 = "DDERR_INVALIDMODE";
+          goto LABEL_173;
+        }
+        if ( v4 == -2005532542 )
+        {
+          v7 = "DDERR_INVALIDOBJECT";
+          goto LABEL_173;
+        }
+        if ( v4 == -2005532527 )
+        {
+          v7 = "DDERR_INVALIDPIXELFORMAT";
+          goto LABEL_173;
+        }
+        if ( v4 != -2005532522 )
+        {
+          if ( v4 == -2005532512 )
+          {
+            v7 = "DDERR_LOCKEDSURFACES";
+            goto LABEL_173;
+          }
+          if ( v4 == -2005532502 )
+          {
+            v7 = "DDERR_NO3D";
+            goto LABEL_173;
+          }
+          goto LABEL_174;
+        }
+      }*/
+
+
+
+//----- (00467D5D) --------------------------------------------------------
+int __thiscall sub_467D5D(int _this)
+{
+  return *(int *)(_this + 7204);
+}
+
+
+
+//----- (00467E7F) --------------------------------------------------------
+void __thiscall sub_467E7F_EquipBody(unsigned int uEquipType)
+{
+  unsigned int v1; // esi@1
+  int v2; // ebx@1
+  Player *v3; // eax@1
+  int v4; // edx@1
+  int v5; // esi@2
+  int v6; // eax@2
+  unsigned int v7; // eax@3
+  ItemGen _this; // [sp+Ch] [bp-30h]@1
+  Player *v9; // [sp+30h] [bp-Ch]@1
+  int v10; // [sp+34h] [bp-8h]@1
+  int *v11; // [sp+38h] [bp-4h]@1
+
+  v1 = uEquipType;
+  _this.Reset();
+  v2 = (unsigned __int8)byte_4E8394[v1 + 4];
+  v3 = pPlayers[uActiveCharacter];
+  v9 = v3;
+  v11 = (int *)((char *)&v3->pEquipment + 4 * v2);
+  v4 = *v11;
+  v10 = *v11;
+  if ( v10 )
+  {
+    memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+    v5 = (int)((char *)v3 + 4 * (9 * v4 - 9));
+    *(char *)(v5 + 556) = 0;
+    pParty->pPickedItem.Reset();
+    pParty->SetHoldingItem((ItemGen *)(v5 + 532));
+    v6 = v10;
+    _this.uBodyAnchor = v2 + 1;
+    memcpy((void *)(v5 + 532), &_this, 0x24u);
+    *v11 = v6;
+  }
+  else
+  {
+    v7 = v3->FindFreeInventorySlot();
+    if ( (v7 & 0x80000000u) == 0 )
+    {
+      pParty->pPickedItem.uBodyAnchor = v2 + 1;
+      memcpy(&v9->pInventoryItems[v7], &pParty->pPickedItem, sizeof(v9->pInventoryItems[v7]));
+      *v11 = v7 + 1;
+      pMouse->RemoveHoldingItem();
+    }
+  }
+}
+
+//----- (00467F48) --------------------------------------------------------
+void __fastcall sub_467F48(signed int a1)
+{
+  signed int v1; // esi@1
+
+  v1 = a1;
+  if ( !pGUIWindow_ScrollWindow && a1 >= 700 )
+  {
+    if ( a1 <= 782 )
+    {
+      uTextureID_720980 = pIcons_LOD->LoadTexture("leather", TEXTURE_16BIT_PALETTE);
+      pGUIWindow_ScrollWindow = GUIWindow::Create(0, 0, 640, 480, (enum WindowType)30, v1 - 700, 0);
+    }
+  }
+}
+// 720980: using guessed type int uTextureID_720980;
+
+//----- (00467F9F) --------------------------------------------------------
+void __cdecl free_book_subwindow()
+{
+  if ( pGUIWindow_ScrollWindow )
+  {
+    pGUIWindow_ScrollWindow->Release();
+    pGUIWindow_ScrollWindow = 0;
+  }
+}
+
+//----- (00467FB6) --------------------------------------------------------
+char __cdecl sub_467FB6()
+{
+  unsigned int v0; // eax@1
+  char *v1; // ST18_4@3
+  unsigned int v2; // eax@3
+  GUIWindow a1; // [sp+Ch] [bp-54h]@1
+
+  memcpy(&a1, pGUIWindow_ScrollWindow, sizeof(a1));
+  a1.Hint = 0;
+  a1.uFrameX = 1;
+  a1.uFrameY = 1;
+  a1.uFrameWidth = 468;
+  v0 = pFontSmallnum->CalcTextHeight(pScrolls[(unsigned int)pGUIWindow_ScrollWindow->ptr_1C], &a1, 0, 0)
+     + 2 * LOBYTE(pFontCreate->uFontHeight)
+     + 24;
+  a1.uFrameHeight = v0;
+  if ( (signed int)(v0 + a1.uFrameY) > 479 )
+  {
+    v0 = 479 - a1.uFrameY;
+    a1.uFrameHeight = 479 - a1.uFrameY;
+  }
+  a1.uFrameZ = a1.uFrameWidth + a1.uFrameX - 1;
+  a1.uFrameW = v0 + a1.uFrameY - 1;
+  a1.DrawMessageBox(0);
+  a1.uFrameX += 12;
+  a1.uFrameWidth -= 24;
+  a1.uFrameY += 12;
+  a1.uFrameHeight -= 12;
+  a1.uFrameZ = a1.uFrameWidth + a1.uFrameX - 1;
+  a1.uFrameW = a1.uFrameHeight + a1.uFrameY - 1;
+  v1 = pItemsTable->pItems[(unsigned int)pGUIWindow_ScrollWindow->ptr_1C + 700].pName;
+  v2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
+  sprintf(pTmpBuf, format_4E2D80, v2, v1);
+  a1.DrawTitleText(pFontCreate, 0, 0, 0, pTmpBuf, 3u);
+  return a1.DrawText(
+           pFontSmallnum,
+           1,
+           LOBYTE(pFontCreate->uFontHeight) - 3,
+           0,
+           pScrolls[(unsigned int)pGUIWindow_ScrollWindow->ptr_1C],
+           0,
+           0,
+           0);
+}
+
+
+
+
+//----- (00468F8A) --------------------------------------------------------
+void __cdecl OnPaperdollLeftClick()
+{
+  Player *v0; // ebx@1
+  int v1; // ecx@1
+  unsigned int v2; // edi@1
+  unsigned int v3; // edx@4
+  unsigned int v4; // esi@5
+  unsigned __int16 v5; // ax@7
+  unsigned int v6; // edi@19
+  int v7; // esi@27
+  unsigned int v8; // eax@29
+  int v9; // edx@32
+  int v10; // esi@34
+  int v11; // eax@34
+  int v12; // esi@38
+  int v13; // eax@38
+  char v14; // zf@38
+  int v15; // esi@42
+  int v16; // eax@42
+  int v17; // eax@44
+  unsigned int v18; // ecx@55
+  unsigned int v19; // eax@55
+  int v20; // esi@60
+  int v21; // eax@60
+  unsigned int v22; // eax@61
+  unsigned int v23; // eax@62
+  int v24; // esi@65
+  int v25; // eax@65
+  unsigned int v26; // eax@69
+  int v27; // esi@81
+  int v28; // eax@81
+  int v29; // esi@84
+  int v30; // eax@84
+  int v31; // eax@85
+  unsigned int v32; // ecx@88
+  unsigned int v33; // eax@88
+  int v34; // esi@90
+  unsigned int v35; // eax@91
+  int v36; // esi@93
+  int v37; // edi@93
+  ItemGen *v38; // edi@93
+  __int16 v39; // dx@99
+  signed int v40; // [sp-1Ch] [bp-68h]@80
+  unsigned int v41; // [sp-18h] [bp-64h]@80
+  signed int v42; // [sp-14h] [bp-60h]@80
+  signed int v43; // [sp-10h] [bp-5Ch]@80
+  int v44; // [sp-Ch] [bp-58h]@80
+  unsigned int v45; // [sp-8h] [bp-54h]@80
+  int v46; // [sp-4h] [bp-50h]@80
+  ItemGen _this; // [sp+Ch] [bp-40h]@1
+  unsigned int v48; // [sp+30h] [bp-1Ch]@88
+  unsigned int v49; // [sp+34h] [bp-18h]@57
+  unsigned int v50; // [sp+38h] [bp-14h]@50
+  int v51; // [sp+3Ch] [bp-10h]@1
+  unsigned int v52; // [sp+40h] [bp-Ch]@5
+  int v53; // [sp+44h] [bp-8h]@1
+  unsigned int v54; // [sp+48h] [bp-4h]@1
+
+  v51 = 0;
+  _this.Reset();
+  v0 = pPlayers[uActiveCharacter];
+  v1 = v0->pEquipment.uMainHand;
+  v2 = v0->pEquipment.uOffHand;
+  v54 = v0->pEquipment.uOffHand;
+  v53 = v1;
+  if ( v1 && pItemsTable->pItems[*(int *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v1 + 5]].uEquipType == 1 )
+    v51 = v1;
+  v3 = pParty->pPickedItem.uItemID;
+  if ( pParty->pPickedItem.uItemID )
+  {
+    v52 = pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType;
+    v4 = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSkillType;
+    if ( v4 == 4 )
+    {
+      if ( v2 )
+      {
+LABEL_7:
+        LOBYTE(v5) = v0->GetActualSkillLevel(PLAYER_SKILL_SPEAR);
+        if ( (signed int)SkillToMastery(v5) < 3 )
+        {
+LABEL_8:
+          v0->PlaySound(39, 0);
+          return;
+        }
+        v3 = pParty->pPickedItem.uItemID;
+        goto LABEL_16;
+      }
+    }
+    else
+    {
+      if ( (v4 == 8 || v4 == 1 || v4 == 2)
+        && v1
+        && pItemsTable->pItems[*(int *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v1 + 5]].uSkillType == 4 )
+        goto LABEL_7;
+    }
+LABEL_16:
+    if ( !v0->CanEquip_RaceAndAlignmentCheck(v3) )
+      goto LABEL_8;
+    if ( pParty->pPickedItem.uItemID == 604 )
+    {
+      sub_467E7F_EquipBody(3u);
+      WetsuitOn(uActiveCharacter);
+      return;
+    }
+    v6 = v52;
+    switch ( v52 )
+    {
+      case 2u:
+      case 3u:
+      case 5u:
+      case 6u:
+      case 7u:
+      case 8u:
+      case 9u:
+      case 0xBu:
+        if ( !v0->HasSkill(v4) )
+          goto LABEL_8;
+        if ( sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(uActiveCharacter) && (v6 != 3 || bUnderwater) )
+          goto LABEL_95;
+        sub_467E7F_EquipBody(v6);
+        if ( pParty->pPickedItem.uItemID == 604 )
+          WetsuitOff(uActiveCharacter);
+        return;
+      case 0xAu:
+        if ( sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(uActiveCharacter) )
+          goto LABEL_95;
+        v52 = 10;
+        v7 = (int)&v0->pEquipment.field_28;
+        while ( 1 )
+        {
+          if ( !*(int *)v7 )
+          {
+            v8 = v0->FindFreeInventorySlot();
+            if ( (v8 & 0x80000000u) == 0 )
+              break;
+          }
+          ++v52;
+          v7 += 4;
+          if ( (signed int)v52 > 15 )
+            goto LABEL_33;
+        }
+        v9 = v52;
+        pParty->pPickedItem.uBodyAnchor = v52 + 1;
+        memcpy(&v0->pInventoryItems[v8], &pParty->pPickedItem, sizeof(v0->pInventoryItems[v8]));
+        *(&v0->pEquipment.uOffHand + v9) = v8 + 1;
+        pMouse->RemoveHoldingItem();
+LABEL_33:
+        if ( v52 == 16 )
+        {
+          v52 = v0->pEquipment.field_3C - 1;
+          memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+          v10 = (int)((char *)v0 + 36 * v52);
+          *(char *)(v10 + 556) = 0;
+          pParty->pPickedItem.Reset();
+          pParty->SetHoldingItem((ItemGen *)(v10 + 532));
+          _this.uBodyAnchor = 16;
+          v11 = v52 + 1;
+          memcpy((void *)(v10 + 532), &_this, 0x24u);
+          v0->pEquipment.field_3C = v11;
+        }
+        return;
+      case 4u:
+        if ( sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(uActiveCharacter) )
+          goto LABEL_95;
+        if ( !v0->HasSkill(v4) )
+          goto LABEL_8;
+        if ( v54 )
+        {
+          --v54;
+          memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+          v12 = (int)((char *)v0 + 36 * v54);
+          *(char *)(v12 + 556) = 0;
+          pParty->pPickedItem.Reset();
+          pParty->SetHoldingItem((ItemGen *)(v12 + 532));
+          _this.uBodyAnchor = 1;
+          v13 = v54 + 1;
+          v14 = v51 == 0;
+          memcpy((void *)(v12 + 532), &_this, 0x24u);
+          v0->pEquipment.uOffHand = v13;
+          if ( v14 )
+            return;
+        }
+        else
+        {
+          v52 = v0->FindFreeInventorySlot();
+          if ( (v52 & 0x80000000u) != 0 )
+            return;
+          if ( !v51 )
+          {
+            pParty->pPickedItem.uBodyAnchor = 1;
+            v17 = v52 + 1;
+            memcpy(&v0->pInventoryItems[v52], &pParty->pPickedItem, sizeof(v0->pInventoryItems[v52]));
+            v0->pEquipment.uOffHand = v17;
+            goto LABEL_45;
+          }
+          memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+          v15 = (int)((char *)v0 + 36 * (v53 - 1));
+          *(char *)(v15 + 556) = 0;
+          pParty->pPickedItem.Reset();
+          pParty->SetHoldingItem((ItemGen *)(v15 + 532));
+          _this.uBodyAnchor = 1;
+          v16 = v52 + 1;
+          memcpy(&v0->pInventoryItems[v52], &_this, sizeof(v0->pInventoryItems[v52]));
+          v0->pEquipment.uOffHand = v16;
+        }
+        v0->pEquipment.uMainHand = 0;
+        return;
+      case 0u:
+      case 0xCu:
+        if ( sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(uActiveCharacter)
+          && pParty->pPickedItem.uItemID != 64
+          && pParty->pPickedItem.uItemID != 65 )
+          goto LABEL_95;
+        if ( !v0->HasSkill(v4) )
+          goto LABEL_8;
+        v50 = 0;
+        if ( v4 == 2 && (unsigned __int16)(v0->pActiveSkills[2] & 0xFFC0)
+          || v4 == 1 && (signed int)SkillToMastery(v0->pActiveSkills[1]) >= 3 )
+        {
+          if (pAsyncMouse)
+          {
+            v18 = *((int *)pAsyncMouse + 6);
+            v19 = *((int *)pAsyncMouse + 7);
+          }
+          else
+          {
+            v18 = pMouse->uMouseClickX;
+            v19 = pMouse->uMouseClickY;
+          }
+          v49 = v19;
+          if ( (signed int)v18 >= 560 )
+          {
+            if ( !v51 )
+            {
+              if ( v54 )
+              {
+                --v54;
+                memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+                v20 = (int)((char *)v0 + 36 * v54);
+                *(char *)(v20 + 556) = 0;
+                pParty->pPickedItem.Reset();
+                pParty->SetHoldingItem((ItemGen *)(v20 + 532));
+                _this.uBodyAnchor = 1;
+                v21 = v54 + 1;
+                v14 = v52 == 12;
+                memcpy((void *)(v20 + 532), &_this, 0x24u);
+                v0->pEquipment.uOffHand = v21;
+                if ( !v14 )
+                  return;
+                v22 = _this.uItemID;
+LABEL_73:
+                v50 = v22;
+                goto LABEL_74;
+              }
+              v23 = v0->FindFreeInventorySlot();
+              if ( (v23 & 0x80000000u) != 0 )
+                return;
+              pParty->pPickedItem.uBodyAnchor = 1;
+              v50 = (unsigned int)&v0->pInventoryItems[v23];
+              memcpy(&v0->pInventoryItems[v23], &pParty->pPickedItem, sizeof(v0->pInventoryItems[v23]));
+              v0->pEquipment.uOffHand = v23 + 1;
+LABEL_71:
+              pMouse->RemoveHoldingItem();
+              if ( v52 != 12 )
+                return;
+              v22 = *(int *)v50;
+              goto LABEL_73;
+            }
+          }
+        }
+        if ( !v53 )
+        {
+          v26 = v0->FindFreeInventorySlot();
+          if ( (v26 & 0x80000000u) != 0 )
+            return;
+          pParty->pPickedItem.uBodyAnchor = 2;
+          v50 = (unsigned int)&v0->pInventoryItems[v26];
+          memcpy(&v0->pInventoryItems[v26], &pParty->pPickedItem, sizeof(v0->pInventoryItems[v26]));
+          v0->pEquipment.uMainHand = v26 + 1;
+          goto LABEL_71;
+        }
+        --v53;
+        memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+        v24 = (int)((char *)v0 + 36 * v53);
+        *(char *)(v24 + 556) = 0;
+        pParty->pPickedItem.Reset();
+        pParty->SetHoldingItem((ItemGen *)(v24 + 532));
+        _this.uBodyAnchor = 2;
+        v25 = v53 + 1;
+        v14 = v52 == 12;
+        memcpy((void *)(v24 + 532), &_this, 0x24u);
+        v0->pEquipment.uMainHand = v25;
+        if ( v14 )
+          v50 = _this.uItemID;
+        if ( v51 )
+          v0->pEquipment.uOffHand = 0;
+LABEL_74:
+        if ( v50 )
+          stru_A750F8[uActiveCharacter - 1]._494836(
+            *((int *)&pSpellDatas[66].field_8 + v50),
+            uActiveCharacter - 1 + 9);
+        break;
+      case 1u:
+        if ( sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(uActiveCharacter) )
+          goto LABEL_95;
+        if ( !v0->HasSkill(v4) )
+          goto LABEL_8;
+        if ( v53 )
+        {
+          if ( v54 )
+          {
+            v46 = 0;
+            v45 = 0;
+            v44 = 0;
+            v43 = 0;
+            v42 = -1;
+            v41 = 0;
+            v40 = 0;
+            goto LABEL_96;
+          }
+          --v53;
+          memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+          v27 = (int)((char *)v0 + 36 * v53);
+          *(char *)(v27 + 556) = 0;
+          pParty->pPickedItem.Reset();
+          pParty->SetHoldingItem((ItemGen *)(v27 + 532));
+          _this.uBodyAnchor = 2;
+          v28 = v53 + 1;
+          memcpy((void *)(v27 + 532), &_this, 0x24u);
+          v0->pEquipment.uMainHand = v28;
+        }
+        else
+        {
+          v52 = v0->FindFreeInventorySlot();
+          if ( (v52 & 0x80000000u) == 0 )
+          {
+            if ( v54 )
+            {
+              memcpy(&_this, &pParty->pPickedItem, sizeof(_this));
+              v29 = (int)((char *)v0 + 36 * (v54 - 1));
+              *(char *)(v29 + 556) = 0;
+              pParty->pPickedItem.Reset();
+              pParty->SetHoldingItem((ItemGen *)(v29 + 532));
+              _this.uBodyAnchor = 2;
+              v30 = v52 + 1;
+              memcpy(&v0->pInventoryItems[v52], &_this, sizeof(v0->pInventoryItems[v52]));
+              v0->pEquipment.uOffHand = 0;
+              v0->pEquipment.uMainHand = v30;
+            }
+            else
+            {
+              pParty->pPickedItem.uBodyAnchor = 2;
+              v31 = v52 + 1;
+              memcpy(&v0->pInventoryItems[v52], &pParty->pPickedItem, sizeof(v0->pInventoryItems[v52]));
+              v0->pEquipment.uMainHand = v31;
+LABEL_45:
+              pMouse->RemoveHoldingItem();
+            }
+          }
+        }
+        return;
+      default:
+        v0->UseItem_DrinkPotion_etc(uActiveCharacter, 0);
+        return;
+    }
+    return;
+  }
+  if (pAsyncMouse)
+  {
+    v32 = *((int *)pAsyncMouse + 6);
+    v33 = *((int *)pAsyncMouse + 7);
+    v49 = *((int *)pAsyncMouse + 7);
+    v48 = v32;
+  }
+  else
+  {
+    v32 = pMouse->uMouseClickX;
+    v33 = pMouse->uMouseClickY;
+  }
+  v34 = pRenderer->pActiveZBuffer[v32 + pSRZBufferLineOffsets[v33]] & 0xFFFF;
+  if ( v34 )
+  {
+    v36 = v34 - 1;
+    v37 = (int)((char *)v0 + 36 * v36);
+    v50 = v37;
+    v38 = (ItemGen *)(v37 + 532);
+    v14 = v38->uItemID == 604;
+    v52 = pItemsTable->pItems[v38->uItemID].uEquipType;
+    if ( v14 )
+    {
+      if ( bUnderwater )
+      {
+LABEL_95:
+        v46 = 0;
+        v45 = 0;
+        v44 = 0;
+        v43 = 0;
+        v42 = -1;
+        v41 = 0;
+        v40 = 0;
+LABEL_96:
+        pAudioPlayer->PlaySound(SOUND_27, v40, v41, v42, v43, v44, v45, v46);
+        return;
+      }
+      WetsuitOff(uActiveCharacter);
+    }
+    if ( unk_50C9A0 )
+    {
+      *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;
+      *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
+      v39 = v52;
+      *((int *)pGUIWindow_Settings->ptr_1C + 3) = v36;
+      *((short *)pGUIWindow_Settings->ptr_1C + 3) = v39;
+      ptr_50C9A4 = v38;
+      unk_50C9A0 = 0;
+      if ( pMessageQueue_50CBD0->uNumMessages )
+        pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+      pMouse->SetCursorBitmap("MICON1");
+      dword_50C9D4 = 0;
+      dword_50C9D0 = 113;
+      dword_50C9D8 = 256;
+    }
+    else
+    {
+      if ( !ptr_50C9A4 )
+      {
+        pParty->SetHoldingItem(v38);
+        *(&v0->uBirthYear + *(char *)(v50 + 556)) = 0;
+        v38->Reset();
+      }
+    }
+  }
+  else
+  {
+    v35 = v0->pEquipment.uBow;
+    if ( v35 )
+    {
+      auto _a = (ItemGen *)&v0->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v35 + 5];
+      pParty->SetHoldingItem(_a);
+      _a->Reset();
+      v0->pEquipment.uBow = 0;
+    }
+  }
+}
+
+
+
+
+//----- (0046A0A1) --------------------------------------------------------
+int __thiscall UnprojectX(int x)
+{
+  double v1; // st7@3
+  int v3; // [sp-4h] [bp-8h]@5
+
+  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+  {
+    if ( pRenderer->pRenderD3D )
+      v1 = pGame->pIndoorCameraD3D->fov;
+    else
+      v1 = pIndoorCamera->flt_1C_fov;
+    v3 = (signed __int64)v1;
+  }
+  else
+  {
+    v3 = pOutdoorCamera->int_fov_rad;
+  }
+  return stru_5C6E00->Atan2(x - pViewport->uScreenCenterX, v3) - stru_5C6E00->uIntegerHalfPi;
+}
+
+//----- (0046A0F6) --------------------------------------------------------
+int __thiscall UnprojectY(int _this)
+{
+  double v1; // st7@3
+  int v3; // [sp-4h] [bp-8h]@5
+
+  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+  {
+    if ( pRenderer->pRenderD3D )
+      v1 = pGame->pIndoorCameraD3D->fov;
+    else
+      v1 = pIndoorCamera->flt_1C_fov;
+    v3 = (signed __int64)v1;
+  }
+  else
+  {
+    v3 = pOutdoorCamera->int_fov_rad;
+  }
+  return stru_5C6E00->Atan2(_this - pViewport->uScreenCenterY, v3) - stru_5C6E00->uIntegerHalfPi;
+}
+
+//----- (0046A14B) --------------------------------------------------------
+char __cdecl OnPressSpace()
+{
+  SHORT v0; // ax@2
+  int *v1; // eax@2
+  char *v2; // ebx@5
+  unsigned int v3; // esi@5
+  signed int v4; // edi@7
+  unsigned int v5; // edx@7
+  int v6; // ecx@8
+  int v7; // eax@8
+  int v8; // ecx@17
+  int *v9; // esi@22
+  signed int v10; // ebx@22
+  int i; // edi@23
+  int v12; // edx@24
+  int v13; // ecx@24
+  int j; // esi@28
+  int v16; // [sp+4h] [bp-1Ch]@0
+  char *v17; // [sp+8h] [bp-18h]@5
+  unsigned int v18; // [sp+Ch] [bp-14h]@5
+  int v19; // [sp+10h] [bp-10h]@8
+  int *v20; // [sp+14h] [bp-Ch]@5
+  int *v21; // [sp+18h] [bp-8h]@7
+  int v22; // [sp+1Ch] [bp-4h]@4
+
+  if ( pRenderer->pRenderD3D )
+  {
+    v0 = GetAsyncKeyState(17);
+    pGame->_44EB12((v0 & 0x8001) != 0, &a3, &a4);
+    v1 = (int *)pGame->pVisInstance->get_picked_object_zbuf_val();
+    if ( v1 != (int *)-1 )
+      LOBYTE(v1) = DoInteractionWithTopmostZObject((unsigned __int16)v1, (signed int)(unsigned __int16)v1 >> 3);
+    return (char)v1;
+  }
+  v22 = 0;
+  v1 = (int *)((signed int)(viewparams->uScreenZ + viewparams->uScreenX) >> 1);
+  if ( (signed int)viewparams->uScreenY >= (signed int)viewparams->uScreenW )
+    goto LABEL_21;
+  v2 = (char *)v1 - 50;
+  v1 = (int *)((char *)v1 + 50);
+  v3 = 640 * viewparams->uScreenY;
+  v17 = v2;
+  v20 = v1;
+  v18 = ((viewparams->uScreenW - viewparams->uScreenY - 1) >> 1) + 1;
+  do
+  {
+    if ( (signed int)v2 >= (signed int)v20 )
+      goto LABEL_20;
+    v1 = &pRenderer->pActiveZBuffer[(int)&v2[v3]];
+    v21 = &pRenderer->pActiveZBuffer[(int)&v2[v3]];
+    v4 = v22;
+    v5 = (((char *)v20 - v2 - 1) >> 1) + 1;
+    do
+    {
+      v6 = 0;
+      v7 = *v1 & 0xFFFF;
+      v19 = 0;
+      if ( v4 > 0 )
+      {
+        do
+        {
+          if ( dword_7207F0[v6] == v7 )
+            break;
+          ++v6;
+          v19 = v6;
+        }
+        while ( v6 < v22 );
+      }
+      if ( (v7 & 7) == 5 )
+      {
+        v16 = (unsigned int)v7 >> 3;
+        if ( (signed int)(((unsigned int)*v21 >> 16)
+                        - pDecorationList->pDecorations[pLevelDecorations[(unsigned int)v7 >> 3].uDecorationDescID].uRadius) > 512 )
+          goto LABEL_18;
+      }
+      else
+      {
+        if ( (unsigned int)*v21 > 0x2000000 )
+          goto LABEL_18;
+      }
+      if ( v19 == v22 && v4 < 100 )
+      {
+        ++v22;
+        ++v4;
+        v8 = *v21;
+        dword_7207EC[v4] = v7;
+        dword_72065C[v4] = v8;
+      }
+LABEL_18:
+      v1 = v21 + 2;
+      --v5;
+      v21 += 2;
+    }
+    while ( v5 );
+    v2 = v17;
+LABEL_20:
+    v3 += 1280;
+    --v18;
+  }
+  while ( v18 );
+LABEL_21:
+  if ( v22 > 0 )
+  {
+    v9 = dword_720660;
+    v10 = 1;
+    do
+    {
+      for ( i = v10; i < v22; ++i )
+      {
+        v12 = *v9;
+        v13 = dword_720660[i];
+        if ( v13 < *v9 )
+        {
+          *v9 = v13;
+          dword_720660[i] = v12;
+        }
+      }
+      ++v10;
+      ++v9;
+      LOBYTE(v1) = v10 - 1;
+    }
+    while ( v10 - 1 < v22 );
+  }
+  for ( j = 0; j < v22; ++j )
+  {
+    LOBYTE(v1) = DoInteractionWithTopmostZObject(dword_720660[j] & 0xFFFF, v16);
+    if ( !(char)v1 )
+      break;
+  }
+  return (char)v1;
+}
+// 72065C: using guessed type int dword_72065C[];
+// 7207EC: using guessed type int dword_7207EC[];
+
+//----- (0046A334) --------------------------------------------------------
+char __fastcall DoInteractionWithTopmostZObject(int a1, int a2)
+{
+  int v2; // edx@1
+  BLVFace *v4; // eax@9
+  unsigned int v5; // ecx@9
+  unsigned __int16 v6; // ax@11
+  ODMFace *v7; // eax@16
+  LevelDecoration *v8; // esi@19
+  __int16 v9; // ax@19
+  int v10; // eax@22
+  int v11; // ecx@22
+  int v12; // edi@23
+  Actor *v13; // esi@23
+  unsigned __int16 v14; // ax@23
+  unsigned __int16 v15; // ax@33
+  const char *v16; // eax@34
+  int v17; // edi@36
+  int v18; // eax@36
+  ItemGen *v19; // esi@39
+  unsigned int v20; // eax@39
+  int v21; // ecx@40
+  std::string v22; // [sp-18h] [bp-2Ch]@5
+  const char *v23; // [sp-8h] [bp-1Ch]@5
+  int v24; // [sp-4h] [bp-18h]@5
+  char v25; // [sp+8h] [bp-Ch]@5
+  int v26; // [sp+Ch] [bp-8h]@1
+  int a3; // [sp+13h] [bp-1h]@5
+
+  v26 = a2;
+  v2 = a1;
+  switch ( a1 & 7 )
+  {
+    case 2:
+      v17 = a1 >> 3;
+      v26 = a1 >> 3;
+      v18 = a1 >> 3;
+      if ( pObjectList->pObjects[pLayingItems[v18].uObjectDescID].uFlags & 0x10
+        || v17 >= 1000
+        || !pLayingItems[v18].uObjectDescID )
+        return 1;
+      v19 = &pLayingItems[v18].stru_24;
+      v20 = pLayingItems[v18].stru_24.uItemID;
+      if ( pItemsTable->pItems[v20].uEquipType == 18 )
+      {
+        party_finds_gold(v19->uAdditionalValue, 0);
+        viewparams->bRedrawGameUI = 1;
+        v21 = v17;
+      }
+      else
+      {
+        if ( pParty->pPickedItem.uItemID )
+          return 1;
+        v24 = (int)pItemsTable->pItems[v20].pUnidentifiedName;
+        sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[471], v24);
+        ShowStatusBarString(pTmpBuf2, 2u);
+        if ( v19->uItemID == 506 )
+          _449B7E_toggle_bit(pParty->_award_bits, 184, 1u);
+        if ( v19->uItemID == 455 )
+          _449B7E_toggle_bit(pParty->_award_bits, 185, 1u);
+        if ( !pParty->AddItem(v19) )
+          pParty->SetHoldingItem(v19);
+        v21 = v26;
+      }
+      LayingItem::_42F933(v21);
+      break;
+    case 3:
+      v12 = a1 >> 3;
+      v13 = &pActors[a1 >> 3];
+      v14 = v13->uAIState;
+      if ( v14 == 4 || v14 == 17 )
+        return 1;
+      if ( v14 == 5 )
+      {
+        stru_50C198.LootActor(&pActors[a1 >> 3]);
+      }
+      else
+      {
+        if ( !v13->GetActorsRelation(0) && !(BYTE2(v13->uAttributes) & 8) && v13->CanAct() )
+        {
+          Actor::FaceObject(v12, 4u, 0, 0);
+          if ( v13->uNPC_ID )
+          {
+            if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+            {
+              pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)161;
+              pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v12;
+              *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+              ++pMessageQueue_50CBD0->uNumMessages;
+            }
+          }
+          else
+          {
+            v15 = pNPCStats->pGroups_copy[v13->uGroup];
+            if ( v15 )
+            {
+              v16 = pNPCStats->pCatchPhrases[v15];
+              if ( v16 )
+              {
+                pParty->uFlags |= 2u;
+                strcpy(byte_5B0938, v16);
+                sub_4451A8_press_any_key(0, 0, 0);
+              }
+            }
+          }
+        }
+      }
+      break;
+    case 5:
+      v8 = &pLevelDecorations[a1 >> 3];
+      v9 = v8->field_16_event_id;
+      if ( v9 )
+      {
+        EventProcessor(v9, a1, 1);
+        LOBYTE(v8->field_2) |= 8u;
+      }
+      else
+      {
+        if ( !pLevelDecorations[a1 >> 3].IsInteractive() )
+          return 1;
+        v10 = v8->_idx_in_stru123;
+        v24 = 1;
+        v11 = stru_5E4C90._decor_events[v10 - 75] + 380;
+        _5C3420_pDecoration = v8;
+        EventProcessor(v11, 0, 1);
+        _5C3420_pDecoration = 0;
+      }
+      break;
+    default:
+      if ( (a1 & 7) != 6 )
+      {
+    MessageBoxW(nullptr, L"Warning: Invalid ID reached!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Mouse.cpp:2020", 0);
+        return 1;
+      }
+      if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )
+      {
+        if ( a1 >> 9 >= pOutdoor->uNumBModels
+          || (v7 = &pOutdoor->pBModels[a1 >> 9].pFaces[(a1 >> 3) & 0x3F], BYTE2(v7->uAttributes) & 0x10)
+          || (v6 = v7->sCogTriggeredID) == 0 )
+          return 1;
+LABEL_13:
+        EventProcessor((signed __int16)v6, v2, 1);
+        return 0;
+      }
+      v4 = &pIndoor->pFaces[a1 >> 3];
+      v5 = v4->uAttributes;
+      if ( !(v5 & 0x2000000) )
+      {
+        ShowNothingHereStatus();
+        return 1;
+      }
+      if ( v5 & 0x100000 || (v6 = pIndoor->pFaceExtras[v4->uFaceExtraID].uEventID) == 0 )
+        return 1;
+      if ( pCurrentScreen != 19 )
+        goto LABEL_13;
+      break;
+  }
+  return 0;
+}
+// 4E28F8: using guessed type int pCurrentScreen;
+
+//----- (0046A6AC) --------------------------------------------------------
+int __fastcall sub_46A6AC(int a1, int a2, int a3)
+{
+  int result; // eax@2
+  unsigned int v4; // edx@3
+  int *v5; // esi@6
+  unsigned int v6; // ebx@6
+  signed int v7; // edi@9
+  unsigned __int16 v8; // ax@9
+  int i; // eax@14
+  int v10; // ecx@19
+  int v11; // [sp+0h] [bp-18h]@1
+  unsigned int v12; // [sp+4h] [bp-14h]@3
+  unsigned int v13; // [sp+8h] [bp-10h]@4
+  int v14; // [sp+Ch] [bp-Ch]@1
+  int *v15; // [sp+10h] [bp-8h]@4
+  int v16; // [sp+14h] [bp-4h]@3
+
+  v11 = a2;
+  v14 = a1;
+  if ( pRenderer->pRenderD3D )
+  {
+    result = sub_46A7C8(a1, a2, a3);
+  }
+  else
+  {
+    v16 = 0;
+    v4 = viewparams->uScreenX;
+    v12 = viewparams->uScreenZ;
+    if ( (signed int)viewparams->uScreenY < (signed int)viewparams->uScreenW )
+    {
+      v15 = &pRenderer->pActiveZBuffer[viewparams->uScreenX + 640 * viewparams->uScreenY];
+      v13 = ((viewparams->uScreenW - viewparams->uScreenY - 1) >> 1) + 1;
+      do
+      {
+        if ( (signed int)v4 < (signed int)v12 )
+        {
+          v5 = v15;
+          v6 = ((v12 - v4 - 1) >> 1) + 1;
+          do
+          {
+            if ( (*(char *)v5 & 7) == 3 )
+            {
+              if ( *v5 <= a3 << 16 )
+              {
+                v7 = (signed int)(unsigned __int16)*v5 >> 3;
+                v8 = pActors[v7].uAIState;
+                if ( v8 != 5 )
+                {
+                  if ( v8 != 4 && v8 != 11 && v8 != 17 && v8 != 19 )
+                  {
+                    for ( i = 0; i < v16; ++i )
+                    {
+                      if ( *(int *)(v14 + 4 * i) == v7 )
+                        break;
+                    }
+                    if ( i == v16 )
+                    {
+                      if ( i < v11 - 1 )
+                      {
+                        v10 = v16++;
+                        *(int *)(v14 + 4 * v10) = v7;
+                      }
+                    }
+                  }
+                }
+              }
+            }
+            v5 += 2;
+            --v6;
+          }
+          while ( v6 );
+        }
+        v15 += 1280;
+        --v13;
+      }
+      while ( v13 );
+    }
+    result = v16;
+  }
+  return result;
+}
+
+//----- (0046A7C8) --------------------------------------------------------
+int __fastcall sub_46A7C8(int a1, int a2, signed int a3)
+{
+  unsigned int v3; // eax@2
+  int v4; // ecx@2
+  unsigned int v5; // eax@2
+  unsigned int v6; // eax@4
+  unsigned int v7; // edi@4
+  unsigned __int16 v8; // ax@4
+  float v9; // ST00_4@9
+  int v10; // ecx@11
+  unsigned int v12; // [sp+10h] [bp-14h]@1
+  int v13; // [sp+14h] [bp-10h]@1
+  int v14; // [sp+18h] [bp-Ch]@1
+  int v15; // [sp+1Ch] [bp-8h]@1
+  unsigned int a1a; // [sp+20h] [bp-4h]@1
+
+  v13 = a1;
+  v14 = a2;
+  v15 = 0;
+  a1a = 0;
+  v12 = pRenderer->GetBillboardDrawListSize();
+  if ( (signed int)v12 > 0 )
+  {
+    do
+    {
+      v3 = pRenderer->GetParentBillboardID(a1a);
+      v4 = pBillboardRenderList[v3].sZValue;
+      v5 = (unsigned __int16)pBillboardRenderList[v3].sZValue;
+      if ( (v5 & 7) == 3 )
+      {
+        if ( v4 <= (unsigned int)(a3 << 16) )
+        {
+          v6 = v5 >> 3;
+          v7 = v6;
+          v8 = pActors[v6].uAIState;
+          if ( v8 != 5 )
+          {
+            if ( v8 != 4 )
+            {
+              if ( v8 != 11 )
+              {
+                if ( v8 != 19 )
+                {
+                  if ( v8 != 17 )
+                  {
+                    v9 = (double)a3;
+                    if ( pGame->pVisInstance->DoesRayIntersectBillboard(v9, a1a) )
+                    {
+                      if ( v15 < v14 - 1 )
+                      {
+                        v10 = v15++;
+                        *(int *)(v13 + 4 * v10) = v7;
+                      }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+      ++a1a;
+    }
+    while ( (signed int)a1a < (signed int)v12 );
+  }
+  return v15;
+}
+
+//----- (0046A89E) --------------------------------------------------------
+int __fastcall sub_46A89E(int a1, int a2, signed int a3)
+{
+  signed int v3; // edi@1
+  char *v4; // esi@2
+  int v5; // ebx@3
+  int v6; // eax@3
+  int v7; // ebx@3
+  unsigned int v8; // ecx@3
+  int v9; // edx@4
+  unsigned int v10; // edx@6
+  unsigned int v11; // edx@8
+  __int16 v12; // ax@10
+  int v13; // ecx@15
+  int v15; // [sp+4h] [bp-18h]@1
+  int v16; // [sp+8h] [bp-14h]@1
+  int v17; // [sp+Ch] [bp-10h]@3
+  int v18; // [sp+10h] [bp-Ch]@3
+  int v19; // [sp+18h] [bp-4h]@1
+
+  v3 = 0;
+  v15 = a2;
+  v16 = a1;
+  v19 = 0;
+  if ( (signed int)uNumActors > 0 )
+  {
+    v4 = (char *)&pActors[0].uAIState;
+    do
+    {
+      v5 = abs(*((short *)v4 - 17) - pParty->vPosition.x);
+      v17 = abs(*((short *)v4 - 16) - pParty->vPosition.y);
+      v18 = abs(*((short *)v4 - 15) - pParty->vPosition.z);
+      v6 = v5;
+      v7 = v17;
+      v8 = v18;
+      if ( v6 < v17 )
+      {
+        v9 = v6;
+        v6 = v17;
+        v7 = v9;
+      }
+      if ( v6 < v18 )
+      {
+        v10 = v6;
+        v6 = v18;
+        v8 = v10;
+      }
+      if ( v7 < (signed int)v8 )
+      {
+        v11 = v8;
+        v8 = v7;
+        v7 = v11;
+      }
+      if ( (signed int)(((unsigned int)(11 * v7) >> 5) + (v8 >> 2) + v6) <= a3 )
+      {
+        v12 = *(short *)v4;
+        if ( *(short *)v4 != 5 )
+        {
+          if ( v12 != 4 )
+          {
+            if ( v12 != 11 )
+            {
+              if ( v12 != 19 )
+              {
+                if ( v12 != 17 )
+                {
+                  v13 = v19++;
+                  *(int *)(v16 + 4 * v13) = v3;
+                  if ( v19 >= v15 - 1 )
+                    break;
+                }
+              }
+            }
+          }
+        }
+      }
+      ++v3;
+      v4 += 836;
+    }
+    while ( v3 < (signed int)uNumActors );
+  }
+  return v19;
+}
+
+//----- (0046A99B) --------------------------------------------------------
+int __cdecl sub_46A99B()
+{
+  int v0; // ebx@1
+  signed int v1; // ecx@1
+  signed int v2; // esi@1
+  int v3; // edx@1
+  signed int v4; // eax@1
+  int v5; // ecx@2
+  int *v6; // eax@3
+  int v7; // ecx@3
+  int v8; // edx@5
+  int v9; // edi@6
+  unsigned __int8 v10; // zf@14
+  char v11; // sf@14
+  char v12; // of@14
+  int *v14; // esi@19
+  signed int v15; // ebx@19
+  int i; // edi@20
+  int v17; // ecx@21
+  int v18; // edi@26
+  int v19; // esi@27
+  unsigned int v20; // ecx@27
+  BLVFace *v21; // eax@32
+  unsigned int v22; // ecx@33
+  const char *v23; // eax@35
+  const char *v24; // ecx@36
+  LevelDecoration *v25; // ecx@43
+  LevelDecoration *v26; // edi@43
+  __int16 v27; // ax@43
+  int v28; // [sp+Ch] [bp-18h]@1
+  int v29; // [sp+14h] [bp-10h]@2
+  int v30; // [sp+18h] [bp-Ch]@1
+  signed int v31; // [sp+1Ch] [bp-8h]@3
+  int v32; // [sp+20h] [bp-4h]@1
+
+  v0 = 0;
+  v1 = (signed int)(viewparams->uScreenW + viewparams->uScreenY) >> 1;
+  v2 = (signed int)(viewparams->uScreenX + viewparams->uScreenZ) >> 1;
+  v3 = v1 - 50;
+  v32 = 0;
+  v4 = 100;
+  v30 = v1 - 50;
+  v28 = v1 + 50;
+  if ( v1 - 50 >= v1 + 50 )
+    return 0;
+  v5 = 640 * v3;
+  v29 = 640 * v3;
+  while ( 2 )
+  {
+    v31 = 100;
+    v6 = &pRenderer->pActiveZBuffer[v2 + v5 - v4 / 2];
+    v7 = v0;
+    while ( 1 )
+    {
+      v8 = *v6;
+      --v31;
+      if ( (unsigned int)*v6 <= 0x2000000 )
+      {
+        v9 = 0;
+        if ( v7 > 0 )
+        {
+          do
+          {
+            if ( dword_7201B0_zvalues[v9] == (unsigned __int16)v8 )
+              break;
+            ++v9;
+          }
+          while ( v9 < v0 );
+        }
+        if ( v9 == v0 )
+        {
+          if ( v8 & 7 )
+          {
+            dword_720020_zvalues[v7] = v8;
+            dword_7201B0_zvalues[v7] = (unsigned __int16)v8;
+            ++v7;
+            ++v0;
+            v32 = v0;
+            if ( v7 == 99 )
+            {
+              v12 = 0;
+              v10 = v0 == 0;
+              v11 = v0 < 0;
+              goto LABEL_18;
+            }
+          }
+        }
+      }
+      if ( !v31 )
+        break;
+      ++v6;
+    }
+    v4 = -1;
+    ++v30;
+    v5 = v29 + 640;
+    v29 += 640;
+    if ( v30 < v28 )
+      continue;
+    break;
+  }
+  v12 = 0;
+  v10 = v0 == 0;
+  v11 = v0 < 0;
+  if ( !v0 )
+    return 0;
+LABEL_18:
+  if ( !((unsigned __int8)(v11 ^ v12) | v10) )
+  {
+    v14 = dword_720020_zvalues;
+    v15 = 1;
+    do
+    {
+      for ( i = v15; i < v32; ++i )
+      {
+        v17 = dword_720020_zvalues[i];
+        if ( v17 < *v14 )
+        {
+          dword_720020_zvalues[i] = *v14;
+          *v14 = v17;
+        }
+      }
+      ++v15;
+      ++v14;
+    }
+    while ( v15 - 1 < v32 );
+    v0 = v32;
+  }
+  v18 = 0;
+  if ( v0 <= 0 )
+    return 0;
+  while ( 1 )
+  {
+    v19 = dword_720020_zvalues[v18] & 0xFFFF;
+    v20 = (dword_720020_zvalues[v18] & 0xFFFFu) >> 3;
+    if ( (dword_720020_zvalues[v18] & 7) == 2 )
+    {
+      if ( v20 >= 0x3E8 )
+        return 0;
+      if ( !(pLayingItems[v20].uAttributes & 0x10) )
+      {
+        v23 = pLayingItems[v20].stru_24.GetDisplayName();
+LABEL_36:
+        v24 = v23;
+        goto LABEL_51;
+      }
+      goto LABEL_41;
+    }
+    if ( (dword_720020_zvalues[v18] & 7) == 3 )
+    {
+      if ( v20 >= 0xBB8 )
+        return 0;
+      v24 = (const char *)&pActors[v20];
+      goto LABEL_51;
+    }
+    if ( (dword_720020_zvalues[v18] & 7) == 5 )
+      break;
+    if ( (dword_720020_zvalues[v18] & 7) == 6 )
+    {
+      if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+      {
+        v21 = &pIndoor->pFaces[v20];
+        if ( !(BYTE3(v21->uAttributes) & 2) )
+          goto LABEL_41;
+        v22 = pIndoor->pFaceExtras[v21->uFaceExtraID].uEventID;
+      }
+      else
+      {
+        if ( (dword_720020_zvalues[v18] & 0xFFFFu) >> 9 >= pOutdoor->uNumBModels )
+          goto LABEL_41;
+        v22 = pOutdoor->pBModels[(dword_720020_zvalues[v18] & 0xFFFFu) >> 9].pFaces[((dword_720020_zvalues[v18] & 0xFFFFu) >> 3) & 0x3F].sCogTriggeredID;
+      }
+      if ( v22 )
+      {
+        v23 = _444732_GetEventHintString(v22);
+        if ( v23 )
+          goto LABEL_36;
+      }
+    }
+LABEL_41:
+    ++v18;
+    if ( v18 >= v0 )
+      return 0;
+  }
+  v25 = &pLevelDecorations[v20];
+  v26 = v25;
+  v27 = v25->field_16_event_id;
+  if ( v27 )
+  {
+    v23 = _444732_GetEventHintString(v27);
+    if ( !v23 )
+      return v19;
+    goto LABEL_36;
+  }
+  if ( v25->IsInteractive() )
+    v24 = pNPCTopics[stru_5E4C90._decor_events[v26->_idx_in_stru123 - 75] + 379].pTopic;
+  else
+    v24 = pDecorationList->pDecorations[v26->uDecorationDescID].field_20;
+LABEL_51:
+  sub_41C0B8_set_status_string(v24);
+  return v19;
+}
+
+
+//----- (0046BDA8) --------------------------------------------------------
+unsigned int __cdecl GetGravityStrength()
+{
+  int v0; // eax@1
+
+  v0 = ~LOBYTE(pGame->uFlags2) & 8;
+  LOBYTE(v0) = v0 | 2;
+  return (unsigned int)v0 >> 1;
+}
+
+//----- (0046BDC0) --------------------------------------------------------
+void __cdecl sub_46BDC0_UpdateUserInput_and_MapSpecificStuff()
+{
+  if ( dword_6BE364_game_settings_1 & 0x80 )
+  {
+    LOBYTE(dword_6BE364_game_settings_1) = dword_6BE364_game_settings_1 & 0x7F;
+  }
+  else
+  {
+    if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+    {
+      BLV_UpdateUserInputAndOther();
+    }
+    else
+    {
+      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+        ODM_UpdateUserInputAndOther();
+    }
+    _438F8F_area_of_effect__damage_evaluate();
+  }
+}
+
+
+
+//----- (0046BDF1) --------------------------------------------------------
+void __cdecl BLV_UpdateUserInputAndOther()
+{
+  UpdateObjects();
+  BLV_ProcessPartyActions();
+  UpdateActors_BLV();
+  BLV_UpdateDoors();
+  _46CC4B_check_event_triggers();
+}
+
+//----- (0046BE0A) --------------------------------------------------------
+void __cdecl ODM_UpdateUserInputAndOther()
+{
+  bool v0; // eax@5
+  int pOut; // [sp+8h] [bp-20h]@5
+
+  UpdateObjects();
+  ODM_ProcessPartyActions();
+  if ( pParty->vPosition.x < -22528
+    || pParty->vPosition.x > 22528
+    || pParty->vPosition.y < -22528
+    || pParty->vPosition.y > 22528 )
+  {
+    strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
+    v0 = pOutdoor->GetTravelDestination(pParty->vPosition.x, pParty->vPosition.y, (char *)&pOut, 32);
+    if ( !bUnderwater && (pParty->uFlags & 0x8C || BYTE1(pParty->uFlags) & 2 || pParty->bFlying) || !v0 )
+    {
+      if ( pParty->vPosition.x < -22528 )
+        pParty->vPosition.x = -22528;
+      if ( pParty->vPosition.x > 22528 )
+        pParty->vPosition.x = 22528;
+      if ( pParty->vPosition.y < -22528 )
+        pParty->vPosition.y = -22528;
+      if ( pParty->vPosition.y > 22528 )
+        pParty->vPosition.y = 22528;
+    }
+    else
+    {
+      pAudioPlayer->StopChannels(-1, -1);
+      UI_CreateTravelDialogue();
+    }
+  }
+  //UpdateActors_ODM();Ritor1: it's temporarily
+  _46CC4B_check_event_triggers();
+}
+
+
+
+
+//----- (0046BEF1) --------------------------------------------------------
+void LayingItem::_46BEF1_apply_spells()
+{
+  LayingItem *v1; // edi@1
+  char *v2; // esi@2
+  __int16 v3; // fps@4
+  unsigned __int8 v4; // c0@4
+  unsigned __int8 v5; // c3@4
+  signed int v6; // [sp+8h] [bp-4h]@1
+
+  v6 = 0;
+  v1 = this;
+  if ( (signed int)uNumActors > 0 )
+  {
+    v2 = (char *)&pActors[0].vPosition.y;
+    do
+    {
+      if ( ((Actor *)(v2 - 144))->CanAct() )
+      {
+        //UNDEF(v3);
+        if ( !(v4 | v5) )
+        {
+          if ( stru_50C198.GetMagicalResistance((Actor *)(v2 - 144), 0xAu) )
+          {
+            ((SpellBuff *)&v2[16 * v1->field_48 + 68])->Apply(
+              pParty->uTimePlayed + (signed int)(signed __int64)((double)(v1->field_4C << 7) * 0.033333335),
+              v1->field_50,
+              4u,
+              0,
+              0);
+            *(v2 - 106) |= 8u;
+          }
+        }
+      }
+      ++v6;
+      v2 += 836;
+    }
+    while ( v6 < (signed int)uNumActors );
+  }
+}
+
+
+//----- (0046BFFA) --------------------------------------------------------
+bool __fastcall _46BFFA_check_object_intercept(unsigned int uLayingItemID, signed int a2)
+{
+  LayingItem *v2; // esi@1
+  ObjectDesc *v3; // ebx@1
+  unsigned __int16 v5; // cx@9
+  unsigned __int16 v6; // cx@14
+  signed int v7; // edx@14
+  unsigned int v8; // eax@19
+  unsigned int v9; // edi@19
+  signed int v10; // ebx@19
+  char *v11; // edx@20
+  unsigned __int16 v12; // ax@23
+  int v13; // eax@27
+  unsigned int v14; // ebx@33
+  unsigned __int16 v15; // ax@35
+  int v16; // eax@36
+  unsigned int v17; // eax@37
+  __int16 v18; // di@37
+  signed int v19; // edx@37
+  unsigned __int8 v20; // sf@37
+  char *v21; // ecx@38
+  unsigned __int16 v22; // ax@41
+  unsigned int v23; // eax@46
+  signed int v24; // ebx@46
+  char *v25; // edx@47
+  int v26; // edx@54
+  int v27; // edx@55
+  int v28; // edx@56
+  int v29; // edx@57
+  unsigned __int16 v30; // ax@60
+  unsigned int v31; // ecx@60
+  int v32; // edi@60
+  unsigned int v33; // eax@65
+  signed int v34; // edx@65
+  char *v35; // ecx@66
+  unsigned __int16 v36; // ax@69
+  int v37; // ST14_4@72
+  int v38; // eax@72
+  int v39; // ST10_4@72
+  int v40; // ST0C_4@72
+  int v41; // edx@76
+  int v42; // edx@77
+  int v43; // edx@78
+  unsigned __int8 v44; // zf@79
+  int v45; // edx@79
+  unsigned __int16 v46; // ax@80
+  int v47; // eax@81
+  int v48; // edx@87
+  int v49; // edx@88
+  int v50; // edx@89
+  unsigned int v51; // eax@93
+  signed int v52; // ebx@93
+  char *v53; // edx@94
+  unsigned __int16 v54; // ax@98
+  unsigned int v55; // ecx@98
+  signed int v56; // ebx@98
+  char *v57; // edx@99
+  unsigned __int16 v58; // ax@102
+  unsigned __int16 v59; // ax@107
+  unsigned int v60; // ecx@107
+  signed int v61; // ebx@107
+  char *v62; // edx@108
+  unsigned __int16 v63; // ax@111
+  int v64; // ebx@114
+  signed int v65; // eax@114
+  unsigned int v66; // edi@123
+  unsigned __int16 v67; // ax@124
+  unsigned int v68; // ecx@124
+  signed int v69; // ebx@124
+  char *v70; // edx@125
+  unsigned __int16 v71; // ax@128
+  unsigned int v72; // ebx@131
+  int v73; // ST14_4@132
+  int v74; // ST10_4@132
+  int v75; // ebx@132
+  int v76; // ST0C_4@132
+  unsigned __int16 v77; // ax@132
+  int v78; // eax@133
+  char v79; // zf@139
+  unsigned int v80; // eax@140
+  signed int v81; // edx@140
+  char *v82; // ecx@141
+  unsigned __int16 v83; // ax@144
+  unsigned __int16 v84; // ax@151
+  unsigned int v85; // ecx@151
+  signed int v86; // ebx@151
+  char *v87; // edx@152
+  unsigned __int16 v88; // ax@155
+  unsigned int v89; // eax@158
+  int v90; // ST34_4@159
+  int v91; // eax@159
+  unsigned int v92; // eax@163
+  unsigned int v93; // eax@177
+  char *v94; // ecx@178
+  unsigned __int16 v95; // ax@181
+  unsigned __int16 v96; // ax@184
+  int v97; // eax@185
+  unsigned __int16 v98; // ax@191
+  unsigned int v99; // ecx@191
+  char v100; // ST18_1@198
+  int v101; // ST14_4@198
+  int v102; // eax@198
+  int v103; // ST10_4@198
+  int v104; // ST0C_4@198
+  unsigned __int16 v105; // ax@200
+  signed int v106; // eax@208
+  unsigned int v107; // edx@220
+  signed int v108; // ebx@225
+  unsigned int v109; // eax@234
+  signed int v110; // ebx@234
+  char *v111; // ecx@235
+  unsigned __int16 v112; // ax@238
+  unsigned __int16 v113; // si@241
+  int v114; // eax@242
+  int v115; // eax@245
+  signed int v116; // eax@245
+  unsigned __int16 v117; // ax@251
+  unsigned int v118; // ecx@251
+  signed int v119; // ebx@251
+  char *v120; // edx@252
+  unsigned __int16 v121; // ax@255
+  unsigned int v122; // eax@260
+  char *v123; // edx@261
+  int v124; // eax@267
+  int v125; // [sp-20h] [bp-4Ch]@28
+  signed int v126; // [sp-1Ch] [bp-48h]@27
+  unsigned int v127; // [sp-18h] [bp-44h]@27
+  signed int v128; // [sp-14h] [bp-40h]@27
+  signed int v129; // [sp-10h] [bp-3Ch]@27
+  int v130; // [sp-Ch] [bp-38h]@27
+  unsigned int v131; // [sp-8h] [bp-34h]@27
+  char v132; // [sp-8h] [bp-34h]@131
+  int v133; // [sp-4h] [bp-30h]@27
+  char v134; // [sp-4h] [bp-30h]@131
+  signed int v135; // [sp-4h] [bp-30h]@217
+  int v136; // [sp+Ch] [bp-20h]@208
+  int v137; // [sp+10h] [bp-1Ch]@208
+  signed int v138; // [sp+14h] [bp-18h]@207
+  signed int v139; // [sp+18h] [bp-14h]@208
+  char *v140; // [sp+1Ch] [bp-10h]@61
+  signed int v141; // [sp+1Ch] [bp-10h]@117
+  unsigned int v142; // [sp+1Ch] [bp-10h]@158
+  signed int v143; // [sp+1Ch] [bp-10h]@172
+  char *v144; // [sp+1Ch] [bp-10h]@192
+  signed int v145; // [sp+20h] [bp-Ch]@1
+  signed int v146; // [sp+20h] [bp-Ch]@60
+  int v147; // [sp+20h] [bp-Ch]@72
+  signed int v148; // [sp+20h] [bp-Ch]@158
+  int v149; // [sp+20h] [bp-Ch]@198
+  unsigned __int16 v150; // [sp+20h] [bp-Ch]@208
+  int v151; // [sp+24h] [bp-8h]@1
+  signed int v152; // [sp+24h] [bp-8h]@208
+  unsigned int v153; // [sp+28h] [bp-4h]@1
+
+  v153 = uLayingItemID;
+  v2 = &pLayingItems[uLayingItemID];
+  v3 = &pObjectList->pObjects[v2->uObjectDescID];
+  v145 = a2;
+  v151 = a2 & 7;
+  if ( (a2 & 7) == 3 )
+  {
+    if ( (v2->field_58 & 7) == 3 && !pActors[v2->field_58 >> 3].GetActorsRelation(&pActors[a2 >> 3]) )
+      return 1;
+  }
+  else
+  {
+    if ( (a2 & 7) == 4 && (v2->field_58 & 7) == 4 )
+      return 1;
+  }
+  if ( pParty->bTurnBasedModeOn == 1 )
+  {
+    v5 = v2->uAttributes;
+    if ( v5 & 4 )
+    {
+      --pTurnEngine->field_1C;
+      v2->uAttributes = v5 & 0xFFFB;
+    }
+  }
+  if ( v151 == 6 && (v2->field_58 & 7) != 4 )
+    BYTE2(pActors[v2->field_58 >> 3].uAttributes) |= 4u;
+  v6 = v2->uItemType;
+  v7 = v2->uItemType;
+  if ( v7 > 3060 )
+  {
+    if ( v7 > 6090 )
+    {
+      if ( v7 > 8090 )
+      {
+        if ( v7 == 9010 )
+          goto LABEL_247;
+        if ( v7 != 9030 )
+        {
+          if ( v7 != 9040 )
+          {
+            if ( v7 != 9080 )
+              return 0;
+LABEL_191:
+            v98 = v6 + 1;
+            v99 = pObjectList->uNumObjects;
+            v32 = 0;
+            v2->uItemType = v98;
+            v146 = 0;
+            if ( (signed int)v99 > 0 )
+            {
+              v144 = (char *)&pObjectList->pObjects->uObjectID;
+              while ( v98 != *(short *)v144 )
+              {
+                ++v146;
+                v144 += 56;
+                if ( v146 >= (signed int)v99 )
+                  goto LABEL_195;
+              }
+              goto LABEL_80;
+            }
+LABEL_195:
+            v46 = 0;
+            goto LABEL_196;
+          }
+          goto LABEL_93;
+        }
+LABEL_172:
+        v143 = 17030;
+        switch ( v6 )
+        {
+          case 0x1798u:
+            v143 = 15040;
+            break;
+          case 0xFAAu:
+            v143 = 13010;
+            break;
+          case 0x2346u:
+            v143 = 18030;
+            break;
+        }
+        v138 = 1;
+        if ( v151 != 3 )
+        {
+          if ( v6 != 9030 || v2->field_50 != 4 )
+            goto LABEL_246;
+          v2->_46BEF1_apply_spells();
+LABEL_233:
+          if ( !v138 )
+          {
+            v109 = pObjectList->uNumObjects;
+            ++v2->uItemType;
+            v110 = 0;
+            if ( (signed int)v109 <= 0 )
+            {
+LABEL_238:
+              v112 = 0;
+            }
+            else
+            {
+              v111 = (char *)&pObjectList->pObjects->uObjectID;
+              while ( v2->uItemType != *(short *)v111 )
+              {
+                ++v110;
+                v111 += 56;
+                if ( v110 >= (signed int)v109 )
+                  goto LABEL_238;
+              }
+              v112 = v110;
+            }
+            v2->uObjectDescID = v112;
+            if ( !v112 )
+              LayingItem::_42F933(v153);
+            v2->vVelocity.z = 0;
+            v2->vVelocity.y = 0;
+            v2->vVelocity.x = 0;
+            v2->uSpriteFrameID = 0;
+            v113 = v2->uSoundID;
+            if ( v113 )
+              v114 = (signed __int16)v113 + 4;
+            else
+              v114 = 0;
+            v133 = 0;
+            v131 = 0;
+            v130 = v114;
+            v115 = 8 * v153;
+            v129 = 0;
+            v128 = -1;
+            LOBYTE(v115) = 8 * v153 | 2;
+            v127 = 0;
+            v126 = v115;
+            v116 = v143;
+            goto LABEL_269;
+          }
+LABEL_246:
+          LayingItem::_42F933(v153);
+          return 0;
+        }
+        v106 = v145;
+        v150 = 0;
+        v139 = v106 >> 3;
+        v137 = v2->field_4C;
+        v152 = v2->field_50;
+        v136 = v2->field_48;
+        if ( v6 == 9030 )
+        {
+          v150 = 2;
+          if ( v152 == 2 )
+          {
+            v150 = 3;
+          }
+          else
+          {
+            if ( v152 >= 3 )
+              v150 = 4;
+          }
+          BYTE2(pActors[v139].uAttributes) |= 8u;
+        }
+        if ( v7 == 6040 )
+        {
+          v135 = 7;
+        }
+        else
+        {
+          if ( v7 == 8030 )
+          {
+            v135 = 9;
+          }
+          else
+          {
+            if ( v7 != 9030 )
+            {
+              v107 = v136;
+LABEL_222:
+              if ( v6 != 9030 || v152 != 4 )
+              {
+                v108 = v139;
+                if ( stru_50C198.GetMagicalResistance(&pActors[v139], v107) )
+                {
+                  v138 = 0;
+                  if ( v2->uItemType == 8030 )
+                  {
+                    pActors[v108].uAIState = Standing;
+                    pActors[v108].UpdateAnimation();
+                  }
+                  ((SpellBuff *)((char *)&pActors[0].pActorBuffs[v136] + v108 * 836))->Apply(
+                    pParty->uTimePlayed + (signed int)(signed __int64)((double)(v137 << 7) * 0.033333335),
+                    v152,
+                    v150,
+                    0,
+                    0);
+                }
+              }
+              else
+              {
+                v2->_46BEF1_apply_spells();
+              }
+              v2->field_4C = 0;
+              v2->field_50 = 0;
+              v2->field_48 = 0;
+              goto LABEL_233;
+            }
+            v135 = 10;
+          }
+        }
+        v107 = v135;
+        goto LABEL_222;
+      }
+      if ( v7 == 8090 || v7 == 7030 || v7 == 7090 || v7 == 8000 )
+        goto LABEL_93;
+      if ( v7 == 8010 )
+      {
+        if ( v151 == 3
+          && MonsterStats::BelongsToSupertype(pActors[v145 >> 3].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
+          sub_43A97E(v153, v145);
+        v93 = pObjectList->uNumObjects;
+        ++v2->uItemType;
+        v9 = 0;
+        v52 = 0;
+        if ( (signed int)v93 > 0 )
+        {
+          v94 = (char *)&pObjectList->pObjects->uObjectID;
+          while ( v2->uItemType != *(short *)v94 )
+          {
+            ++v52;
+            v94 += 56;
+            if ( v52 >= (signed int)v93 )
+              goto LABEL_181;
+          }
+          goto LABEL_202;
+        }
+        goto LABEL_181;
+      }
+      v79 = v7 == 8030;
+    }
+    else
+    {
+      if ( v7 == 6090 )
+        goto LABEL_93;
+      if ( v7 <= 4070 )
+      {
+        if ( v7 != 4070 )
+        {
+          v48 = v7 - 3090;
+          if ( v48 )
+          {
+            v49 = v48 - 2;
+            if ( v49 )
+            {
+              v50 = v49 - 908;
+              if ( !v50 )
+                goto LABEL_93;
+              v45 = v50 - 30;
+              v44 = v45 == 0;
+              goto LABEL_91;
+            }
+            v54 = v6 - 1;
+            v55 = pObjectList->uNumObjects;
+            v9 = 0;
+            v56 = 0;
+            v44 = pObjectList->uNumObjects == 0;
+            v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+            v2->uItemType = v54;
+            if ( v20 | v44 )
+            {
+LABEL_102:
+              v58 = 0;
+            }
+            else
+            {
+              v57 = (char *)&pObjectList->pObjects->uObjectID;
+              while ( v54 != *(short *)v57 )
+              {
+                ++v56;
+                v57 += 56;
+                if ( v56 >= (signed int)v55 )
+                  goto LABEL_102;
+              }
+              v58 = v56;
+            }
+            v2->uObjectDescID = v58;
+            if ( !v58 )
+              LayingItem::_42F933(v153);
+            v14 = v153;
+            v2->vVelocity.z = 0;
+            v2->vVelocity.y = 0;
+            v2->vVelocity.x = 0;
+            v2->uSpriteFrameID = 0;
+            sub_43A97E(v153, v145);
+LABEL_35:
+            v15 = v2->uSoundID;
+            if ( v15 == (short)v9 )
+              v16 = 0;
+            else
+              v16 = (signed __int16)v15 + 4;
+            v133 = v9;
+            v131 = v9;
+            v130 = v16;
+            v92 = v14;
+LABEL_267:
+            v124 = 8 * v92;
+            v129 = v9;
+            v128 = -1;
+            LOBYTE(v124) = v124 | 2;
+            v127 = v9;
+            v126 = v124;
+LABEL_268:
+            v116 = word_4EE088_sound_ids[v2->field_48];
+LABEL_269:
+            v125 = v116 + 1;
+            goto LABEL_29;
+          }
+          v59 = v6 + 2;
+          v60 = pObjectList->uNumObjects;
+          v9 = 0;
+          v61 = 0;
+          v44 = pObjectList->uNumObjects == 0;
+          v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+          v2->uItemType = v59;
+          if ( v20 | v44 )
+          {
+LABEL_111:
+            v63 = 0;
+          }
+          else
+          {
+            v62 = (char *)&pObjectList->pObjects->uObjectID;
+            while ( v59 != *(short *)v62 )
+            {
+              ++v61;
+              v62 += 56;
+              if ( v61 >= (signed int)v60 )
+                goto LABEL_111;
+            }
+            v63 = v61;
+          }
+          v2->uObjectDescID = v63;
+          if ( !v63 )
+            LayingItem::_42F933(v153);
+          v64 = v2->uFacing - stru_5C6E00->uIntegerDoublePi;
+          v44 = v2->field_50 == 4;
+          v2->vVelocity.z = 0;
+          v2->vVelocity.y = 0;
+          v2->vVelocity.x = 0;
+          v65 = 7;
+          if ( v44 )
+            v65 = 9;
+          if ( v65 > 0 )
+          {
+            v141 = v65;
+            do
+            {
+              v64 += (signed int)stru_5C6E00->uIntegerHalfPi >> 1;
+              v2->Create(v64, 0, 1000, 0);
+              --v141;
+            }
+            while ( v141 );
+          }
+LABEL_160:
+          v14 = v153;
+LABEL_34:
+          LayingItem::_42F933(v14);
+          goto LABEL_35;
+        }
+        if ( v151 == 6 || v151 == 5 || (v66 = 0, !v151) )
+          return 1;
+        v67 = v6 + 1;
+        v68 = pObjectList->uNumObjects;
+        v69 = 0;
+        v44 = pObjectList->uNumObjects == 0;
+        v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+        v2->uItemType = v67;
+        if ( v20 | v44 )
+        {
+LABEL_128:
+          v71 = 0;
+        }
+        else
+        {
+          v70 = (char *)&pObjectList->pObjects->uObjectID;
+          while ( v67 != *(short *)v70 )
+          {
+            ++v69;
+            v70 += 56;
+            if ( v69 >= (signed int)v68 )
+              goto LABEL_128;
+          }
+          v71 = v69;
+        }
+        v2->uObjectDescID = v71;
+        if ( !v71 )
+          LayingItem::_42F933(v153);
+        v134 = 0;
+        v72 = v153;
+        v132 = 0;
+LABEL_132:
+        v73 = v2->vPosition.z;
+        v74 = v2->vPosition.y;
+        v75 = 8 * v72 | 2;
+        v2->vVelocity.z = v66;
+        v2->vVelocity.y = v66;
+        v76 = v2->vPosition.x;
+        v2->vVelocity.x = v66;
+        v2->uSpriteFrameID = v66;
+        stru_50FE08.Add(v75, 512, v76, v74, v73, v132, v134);
+        v77 = v2->uSoundID;
+        if ( v77 == (short)v66 )
+          v78 = 0;
+        else
+          v78 = (signed __int16)v77 + 4;
+        v133 = v66;
+        v131 = v66;
+        v130 = v78;
+        v129 = v66;
+        v128 = -1;
+        v127 = v66;
+        v126 = v75;
+        goto LABEL_268;
+      }
+      if ( v7 == 4090 )
+      {
+        v84 = v6 + 2;
+        v85 = pObjectList->uNumObjects;
+        v9 = 0;
+        v86 = 0;
+        v44 = pObjectList->uNumObjects == 0;
+        v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+        v2->uItemType = v84;
+        if ( v20 | v44 )
+        {
+LABEL_155:
+          v88 = 0;
+        }
+        else
+        {
+          v87 = (char *)&pObjectList->pObjects->uObjectID;
+          while ( v84 != *(short *)v87 )
+          {
+            ++v86;
+            v87 += 56;
+            if ( v86 >= (signed int)v85 )
+              goto LABEL_155;
+          }
+          v88 = v86;
+        }
+        v2->uObjectDescID = v88;
+        if ( !v88 )
+          LayingItem::_42F933(v153);
+        v89 = v2->uFacing - stru_5C6E00->uIntegerDoublePi;
+        v2->vVelocity.z = 0;
+        v2->vVelocity.y = 0;
+        v2->vVelocity.x = 0;
+        v142 = v89;
+        v148 = 7;
+        do
+        {
+          pRnd->SetRange(-128, 128);
+          v90 = pRnd->GetInRange();
+          pRnd->SetRange(5, 500);
+          v91 = pRnd->GetInRange();
+          v142 += (signed int)stru_5C6E00->uIntegerHalfPi >> 1;
+          v2->Create(v90 + v142, 0, v91, 0);
+          --v148;
+        }
+        while ( v148 );
+        goto LABEL_160;
+      }
+      if ( v7 == 4092 )
+      {
+        v80 = pObjectList->uNumObjects;
+        v66 = 0;
+        v81 = 0;
+        v44 = pObjectList->uNumObjects == 0;
+        v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+        v2->uItemType = 4091;
+        if ( v20 | v44 )
+        {
+LABEL_144:
+          v83 = 0;
+        }
+        else
+        {
+          v82 = (char *)&pObjectList->pObjects->uObjectID;
+          while ( *(short *)v82 != 4091 )
+          {
+            ++v81;
+            v82 += 56;
+            if ( v81 >= (signed int)v80 )
+              goto LABEL_144;
+          }
+          v83 = v81;
+        }
+        v2->uObjectDescID = v83;
+        if ( !v83 )
+          LayingItem::_42F933(v153);
+        v134 = 0;
+        v72 = v153;
+        v132 = v2->field_61;
+        goto LABEL_132;
+      }
+      if ( v7 == 4100 || v7 == 6010 )
+        goto LABEL_93;
+      v79 = v7 == 6040;
+    }
+    if ( !v79 )
+      return 0;
+    goto LABEL_172;
+  }
+  if ( v7 == 3060 )
+    goto LABEL_93;
+  if ( v7 <= 555 )
+  {
+    if ( v7 == 555 )
+    {
+      sub_43A97E(v153, v145);
+      v23 = pObjectList->uNumObjects;
+      ++v2->uItemType;
+      v18 = 0;
+      v24 = 0;
+      if ( (signed int)v23 <= 0 )
+      {
+LABEL_41:
+        v22 = 0;
+      }
+      else
+      {
+        v25 = (char *)&pObjectList->pObjects->uObjectID;
+        while ( v2->uItemType != *(short *)v25 )
+        {
+          ++v24;
+          v25 += 56;
+          if ( v24 >= (signed int)v23 )
+            goto LABEL_41;
+        }
+        v22 = v24;
+      }
+LABEL_42:
+      v2->uObjectDescID = v22;
+      if ( v22 == v18 )
+        LayingItem::_42F933(v153);
+      v2->vVelocity.z = v18;
+      v2->vVelocity.y = v18;
+      v2->vVelocity.x = v18;
+      v2->uSpriteFrameID = v18;
+    }
+    else
+    {
+      switch ( v7 )
+      {
+        case 500:
+        case 505:
+        case 510:
+        case 515:
+        case 520:
+        case 525:
+        case 530:
+        case 535:
+        case 540:
+          sub_43A97E(v153, v145);
+          v8 = pObjectList->uNumObjects;
+          ++v2->uItemType;
+          v9 = 0;
+          v10 = 0;
+          if ( (signed int)v8 <= 0 )
+            goto LABEL_23;
+          v11 = (char *)&pObjectList->pObjects->uObjectID;
+          break;
+        case 545:
+        case 550:
+          if ( v2->stru_24.uItemID != 405 && v2->stru_24.uAdditionalValue != 3 )
+          {
+            v14 = v153;
+            v9 = 0;
+            v2->vVelocity.z = 0;
+            v2->vVelocity.y = 0;
+            v2->vVelocity.x = 0;
+            v2->uSpriteFrameID = 0;
+            sub_43A97E(v153, v145);
+            goto LABEL_34;
+          }
+          v17 = pObjectList->uNumObjects;
+          v18 = 0;
+          v19 = 0;
+          v44 = pObjectList->uNumObjects == 0;
+          v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+          v2->uItemType = 600;
+          if ( v20 | v44 )
+            goto LABEL_41;
+          v21 = (char *)&pObjectList->pObjects->uObjectID;
+          while ( *(short *)v21 != 600 )
+          {
+            ++v19;
+            v21 += 56;
+            if ( v19 >= (signed int)v17 )
+              goto LABEL_41;
+          }
+          v22 = v19;
+          goto LABEL_42;
+        default:
+          return 0;
+      }
+      while ( v2->uItemType != *(short *)v11 )
+      {
+        ++v10;
+        v11 += 56;
+        if ( v10 >= (signed int)v8 )
+        {
+LABEL_23:
+          v12 = 0;
+          goto LABEL_24;
+        }
+      }
+      v12 = v10;
+LABEL_24:
+      v2->uObjectDescID = v12;
+      if ( !v12 )
+        LayingItem::_42F933(v153);
+      v44 = v2->uItemType == 555;
+      v2->vVelocity.z = 0;
+      v2->vVelocity.y = 0;
+      v2->vVelocity.x = 0;
+      v2->uSpriteFrameID = 0;
+      if ( !v44 )
+        goto LABEL_27;
+    }
+    return 0;
+  }
+  if ( v7 > 1100 )
+  {
+    v41 = v7 - 2030;
+    if ( !v41 )
+      goto LABEL_247;
+    v42 = v41 - 30;
+    if ( v42 )
+    {
+      v43 = v42 - 40;
+      if ( !v43 )
+        goto LABEL_59;
+      v45 = v43 - 910;
+      v44 = v45 == 0;
+LABEL_91:
+      if ( !v44 && v45 != 20 )
+        return 0;
+    }
+LABEL_93:
+    sub_43A97E(v153, v145);
+    v51 = pObjectList->uNumObjects;
+    ++v2->uItemType;
+    v9 = 0;
+    v52 = 0;
+    if ( (signed int)v51 > 0 )
+    {
+      v53 = (char *)&pObjectList->pObjects->uObjectID;
+      while ( v2->uItemType != *(short *)v53 )
+      {
+        ++v52;
+        v53 += 56;
+        if ( v52 >= (signed int)v51 )
+          goto LABEL_181;
+      }
+      goto LABEL_202;
+    }
+LABEL_181:
+    v95 = 0;
+LABEL_182:
+    v2->uObjectDescID = v95;
+    if ( v95 == (short)v9 )
+      LayingItem::_42F933(v153);
+    v96 = v2->uSoundID;
+    v2->vVelocity.z = v9;
+    v2->vVelocity.y = v9;
+    v2->vVelocity.x = v9;
+    v2->uSpriteFrameID = v9;
+    if ( v96 == (short)v9 )
+      v97 = 0;
+    else
+      v97 = (signed __int16)v96 + 4;
+    v133 = v9;
+    v131 = v9;
+    v130 = v97;
+    v92 = v153;
+    goto LABEL_267;
+  }
+  if ( v7 == 1100 )
+    goto LABEL_93;
+  v26 = v7 - 600;
+  if ( !v26 )
+  {
+    v33 = pObjectList->uNumObjects;
+    v34 = 0;
+    v44 = pObjectList->uNumObjects == 0;
+    v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+    v2->uItemType = 601;
+    if ( v20 | v44 )
+    {
+LABEL_69:
+      v36 = 0;
+    }
+    else
+    {
+      v35 = (char *)&pObjectList->pObjects->uObjectID;
+      while ( *(short *)v35 != 601 )
+      {
+        ++v34;
+        v35 += 56;
+        if ( v34 >= (signed int)v33 )
+          goto LABEL_69;
+      }
+      v36 = v34;
+    }
+    v2->uObjectDescID = v36;
+    if ( !v36 )
+      LayingItem::_42F933(v153);
+    v37 = v2->vPosition.z;
+    v2->vVelocity.z = 0;
+    v38 = 8 * v153;
+    v39 = v2->vPosition.y;
+    LOBYTE(v38) = 8 * v153 | 2;
+    v2->vVelocity.y = 0;
+    v2->vVelocity.x = 0;
+    v40 = v2->vPosition.x;
+    v2->uSpriteFrameID = 0;
+    v147 = v38;
+    stru_50FE08.Add(v38, 512, v40, v39, v37, 0, 0);
+    if ( HIBYTE(v3->uFlags) & 1 )
+      array_5118E8._440E91(v2->vPosition.x, v2->vPosition.y, v2->vPosition.z, 0, v3->uParticleTrailColor);
+    v133 = 0;
+    v131 = 0;
+    v130 = 0;
+    v129 = 0;
+    v128 = -1;
+    v127 = 0;
+    v126 = v147;
+    goto LABEL_28;
+  }
+  v27 = v26 - 410;
+  if ( !v27 )
+    goto LABEL_93;
+  v28 = v27 - 40;
+  if ( !v28 )
+    goto LABEL_191;
+  v29 = v28 - 10;
+  if ( v29 )
+  {
+    if ( v29 != 20 )
+      return 0;
+LABEL_59:
+    if ( v151 != 3 )
+    {
+      v30 = v6 + 1;
+      v31 = pObjectList->uNumObjects;
+      v32 = 0;
+      v2->uItemType = v30;
+      v146 = 0;
+      if ( (signed int)v31 > 0 )
+      {
+        v140 = (char *)&pObjectList->pObjects->uObjectID;
+        while ( v30 != *(short *)v140 )
+        {
+          ++v146;
+          v140 += 56;
+          if ( v146 >= (signed int)v31 )
+            goto LABEL_195;
+        }
+LABEL_80:
+        v46 = v146;
+LABEL_196:
+        v2->uObjectDescID = v46;
+        if ( v46 == (short)v32 )
+          LayingItem::_42F933(v153);
+        v100 = v2->field_61;
+        v101 = v2->vPosition.z;
+        v2->uSpriteFrameID = v32;
+        v102 = 8 * v153;
+        v103 = v2->vPosition.y;
+        LOBYTE(v102) = 8 * v153 | 2;
+        v2->vVelocity.x = v32;
+        v2->vVelocity.y = v32;
+        v104 = v2->vPosition.x;
+        v2->vVelocity.z = v32;
+        v149 = v102;
+        stru_50FE08.Add(v102, 512, v104, v103, v101, v100, v32);
+        if ( HIBYTE(v3->uFlags) & 1 )
+          array_5118E8._440E91(
+            v2->vPosition.x,
+            v2->vPosition.y,
+            v2->vPosition.z,
+            v32,
+            v3->uParticleTrailColor);
+        v105 = v2->uSoundID;
+        if ( v105 == (short)v32 )
+          v47 = 0;
+        else
+          v47 = (signed __int16)v105 + 4;
+        v133 = v32;
+        v131 = v32;
+        v130 = v47;
+        v129 = v32;
+        v128 = -1;
+        v127 = v32;
+        v126 = v149;
+        goto LABEL_268;
+      }
+      goto LABEL_195;
+    }
+    return 1;
+  }
+LABEL_247:
+  if ( v151 == 6 || v151 == 5 || (v9 = 0, !v151) )
+    return 1;
+  if ( v151 != 2 )
+  {
+    sub_43A97E(v153, v145);
+    v122 = pObjectList->uNumObjects;
+    ++v2->uItemType;
+    v52 = 0;
+    if ( (signed int)v122 > 0 )
+    {
+      v123 = (char *)&pObjectList->pObjects->uObjectID;
+      while ( v2->uItemType != *(short *)v123 )
+      {
+        ++v52;
+        v123 += 56;
+        if ( v52 >= (signed int)v122 )
+          goto LABEL_181;
+      }
+LABEL_202:
+      v95 = v52;
+      goto LABEL_182;
+    }
+    goto LABEL_181;
+  }
+  v117 = v6 + 1;
+  v118 = pObjectList->uNumObjects;
+  v119 = 0;
+  v44 = pObjectList->uNumObjects == 0;
+  v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+  v2->uItemType = v117;
+  if ( v20 | v44 )
+  {
+LABEL_255:
+    v121 = 0;
+  }
+  else
+  {
+    v120 = (char *)&pObjectList->pObjects->uObjectID;
+    while ( v117 != *(short *)v120 )
+    {
+      ++v119;
+      v120 += 56;
+      if ( v119 >= (signed int)v118 )
+        goto LABEL_255;
+    }
+    v121 = v119;
+  }
+  v2->uObjectDescID = v121;
+  if ( !v121 )
+    LayingItem::_42F933(v153);
+  v2->vVelocity.z = 0;
+  v2->vVelocity.y = 0;
+  v2->vVelocity.x = 0;
+  v2->uSpriteFrameID = 0;
+LABEL_27:
+  v133 = v9;
+  v131 = v9;
+  v130 = v9;
+  v13 = 8 * v153;
+  v129 = v9;
+  v128 = -1;
+  LOBYTE(v13) = 8 * v153 | 2;
+  v127 = v9;
+  v126 = v13;
+LABEL_28:
+  v125 = 8;
+LABEL_29:
+  pAudioPlayer->PlaySound((SoundID)v125, v126, v127, v128, v129, v130, v131, v133);
+  return 0;
+}
+