view GUIWindow.cpp @ 20:d3536563ef2d

Удалил файлы .suo и .user
author Lower
date Sat, 13 Oct 2012 21:16:44 +0600
parents 540178ef9b18
children 509744251c8e
line wrap: on
line source

#include "GUIWindow.h"
#include "GUIButton.h"
#include "GUIFont.h"
#include "Party.h"
#include "LOD.h"
#include "Keyboard.h"
#include "IndoorCamera.h"
#include "Math.h"
#include "VideoPlayer.h"
#include "Allocator.h"
#include "MapInfo.h"
#include "Time.h"
#include "AudioPlayer.h"
#include "Mouse.h"
#include "Viewport.h"
#include "Render.h"
#include "PlayerFrameTable.h"
#include "stru179.h"
#include "SaveLoad.h"
#include "FactionTable.h"
#include "StorylineTextTable.h"
#include "Events2D.h"


#include "mm7_data.h"




int pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[1]; // idb
struct GUIWindow *pWindow_MainMenu;
struct GUIWindow pWindowList[20];

struct GUIMessageQueue *pMessageQueue_50CBD0 = new GUIMessageQueue;


//----- (004356B9) --------------------------------------------------------
void GUIMessageQueue::PopMessage(enum UIMessageType *pType, int *pParam, int *a4)
{
  signed int v4; // edx@1
  GUIMessage *v5; // eax@2

  v4 = 0;
  if ( this->uNumMessages )
  {
    v5 = this->pMessages;
    *pType = this->pMessages[0].eType;
    *pParam = this->pMessages[0].param;
    *a4 = this->pMessages[0].field_8;
    if ( (signed int)(this->uNumMessages - 1) > 0 )
    {
      do
      {
        v5->eType = v5[1].eType;
        v5->param = v5[1].param;
        v5->field_8 = v5[1].field_8;
        ++v4;
        ++v5;
      }
      while ( v4 < (signed int)(this->uNumMessages - 1) );
    }
    --this->uNumMessages;
  }
}



//----- (0041D73D) --------------------------------------------------------
char GUIWindow::_41D73D_draw_buff_tooltip()
{
  GUIFont *v1; // esi@1
  GUIWindow *v2; // edi@1
  SpellBuff *v3; // eax@1
  unsigned int v4; // eax@5
  int v5; // ecx@5
  unsigned int v6; // eax@5
  unsigned int v7; // ecx@5
  char *v8; // ebx@7
  unsigned int v9; // eax@8
  unsigned int v10; // ecx@8
  __int64 v11; // ST28_8@11
  int v12; // esi@11
  const char *v13; // ST0C_4@11
  unsigned int v14; // eax@11
  char **v16; // [sp+14h] [bp-10h]@7
  GUIFont *a2; // [sp+18h] [bp-Ch]@1
  SpellBuff *v18; // [sp+1Ch] [bp-8h]@7
  int v19; // [sp+20h] [bp-4h]@1
  int v20; // [sp+20h] [bp-4h]@7

  v1 = pFontComic;
  v2 = this;
  a2 = pFontComic;
  v19 = 0;
  v3 = pParty->pPartyBuffs;
  do
  {
    if ( (signed __int64)v3->uExpireTime > 0 )
      ++v19;
    ++v3;
  }
  while ( (signed int)v3 < (signed int)pParty->pPlayers );
  v4 = LOBYTE(pFontArrus->uFontHeight) + 72;
  this->uFrameHeight = v4;
  v5 = v4 + (v19 - 1) * LOBYTE(pFontArrus->uFontHeight);
  v6 = v2->uFrameWidth;
  v2->uFrameHeight = v5;
  v7 = v2->uFrameHeight;
  v2->uFrameZ = v6 + v2->uFrameX - 1;
  v2->uFrameW = v2->uFrameY + v7 - 1;
  v2->_415551(0);
  v2->DrawText2(pFontArrus, 0, 0xCu, 0, pGlobalTXT_LocalizationStrings[451], 3u);
  if ( !v19 )
    v2->DrawText2(v1, 0, 0x28u, 0, pGlobalTXT_LocalizationStrings[153], 3u);
  v20 = 0;
  GetTickCount();
  v8 = &_4E2B21_buff_spell_tooltip_colors[1];
  v16 = aSpellNames;
  v18 = pParty->pPartyBuffs;
  do
  {
    v9 = LODWORD(v18->uExpireTime);
    v10 = HIDWORD(v18->uExpireTime);
    if ( (v10 & 0x80000000u) == 0 && ((signed int)v10 > 0 || v9) )
    {
      v11 = __PAIR__(v10, v9) - pParty->uTimePlayed;
      v12 = v20 * LOBYTE(v1->uFontHeight) + 40;
      v13 = *v16;
      ++v20;
      v14 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(
              (unsigned __int8)*(v8 - 1),
              (unsigned __int8)*v8,
              (unsigned __int8)v8[1]);
      v2->DrawText(a2, 52, v12, v14, v13, 0, 0, 0);
      LOBYTE(v9) = sub_41D20D_buff_remaining_time_string(v12, v2, v11, a2);
      v1 = a2;
    }
    ++v18;
    ++v16;
    v8 += 3;
  }
  while ( (signed int)v18 < (signed int)pParty->pPlayers );
  return v9;
}


//----- (0041D3B7) --------------------------------------------------------
char GUIWindow::_41D3B7()
{
  GUIWindow *v1; // edi@1
  Player *pPlayer; // esi@1
  int v3; // ecx@1
  SpellBuff *v4; // eax@1
  signed int v5; // ebx@1
  int v6; // eax@5
  int v7; // ebx@5
  unsigned int v8; // ecx@5
  int v9; // ebx@5
  unsigned int v10; // eax@5
  int v11; // eax@5
  unsigned int v12; // ecx@5
  Texture *v13; // eax@6
  unsigned int v14; // eax@12
  PlayerFrame *v15; // eax@12
  unsigned int v16; // eax@15
  signed int v17; // ST28_4@15
  int v18; // ST24_4@15
  signed int v19; // eax@15
  unsigned int v20; // eax@15
  int v21; // ST28_4@15
  int v22; // ST24_4@15
  int v23; // eax@15
  unsigned int v24; // eax@15
  unsigned int v25; // eax@15
  char *v26; // ST28_4@15
  signed int v27; // eax@15
  unsigned __int8 v28; // al@15
  char *v29; // eax@16
  unsigned int v30; // esi@18
  SpellBuff *v31; // edx@18
  char *v32; // edi@18
  signed int v33; // ecx@19
  unsigned int v34; // eax@19
  __int64 v35; // ST38_8@22
  int v36; // esi@22
  const char *v37; // ST1C_4@22
  unsigned int v38; // eax@22
  char *v39; // eax@24
  SpellBuff *v41; // [sp+14h] [bp-14h]@1
  GUIFont *a2; // [sp+18h] [bp-10h]@1
  GUIWindow *a1; // [sp+1Ch] [bp-Ch]@1
  signed int uFramesetID; // [sp+20h] [bp-8h]@9
  int uFramesetIDa; // [sp+20h] [bp-8h]@18
  const char **v46; // [sp+24h] [bp-4h]@18

  v1 = this;
  a2 = pFontComic;
  pPlayer = &pParty->pPlayers[(unsigned int)this->ptr_1C];
  a1 = this;
  v3 = 0;
  v4 = pPlayer->pPlayerBuffs;
  v5 = 24;
  v41 = pPlayer->pPlayerBuffs;
  do
  {
    if ( (signed __int64)v4->uExpireTime > 0 )
      ++v3;
    ++v4;
    --v5;
  }
  while ( v5 );
  v6 = LOBYTE(pFontArrus->uFontHeight) + 162;
  v1->uFrameHeight = v6;
  v7 = (v3 - 1) * LOBYTE(pFontArrus->uFontHeight);
  v8 = v1->uFrameX;
  v9 = v6 + v7;
  v10 = v1->uFrameWidth;
  v1->uFrameHeight = v9;
  v11 = v10 + v8 - 1;
  v12 = v1->uFrameY;
  v1->uFrameZ = v11;
  v1->uFrameW = v9 + v12 - 1;
  v1->_415551(0);
  if ( pPlayer->pConditions[16] )
  {
    v13 = pTexture_PlayerFaceEradicated;
  }
  else
  {
    if ( pPlayer->pConditions[14] )
    {
      v13 = pTexture_PlayerFaceDead;
    }
    else
    {
      uFramesetID = pPlayerFrameTable->GetFrameIdBy_field0(pPlayer->uExpressionID);
      if ( !uFramesetID )
        uFramesetID = 1;
      if ( pPlayer->uExpressionID == 21 )
      {
        v15 = pPlayerFrameTable->GetFrameBy_y(
                &pPlayer->field_1AA8,
                &pPlayer->field_1AA4,
                pMiscTimer->uTimeElapsed);
      }
      else
      {
        v14 = pMiscTimer->Time();
        v15 = pPlayerFrameTable->GetFrameBy_x(uFramesetID, v14);
      }
      pPlayer->field_1AA2 = v15->uTextureID - 1;
      v13 = (Texture *)A74CEC_player_faces_minus1_indexing[v15->uTextureID + 56 * (unsigned int)v1->ptr_1C];
    }
  }
  pRenderer->DrawTextureTransparent(v1->uFrameX + 24, v1->uFrameY + 24, v13);
  v16 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
  sprintfex(pTmpBuf, format_4E2DC8, v16);
  sprintfex(pTmpBuf2, pGlobalTXT_LocalizationStrings[429], pPlayer->pName, pClassNames[pPlayer->uClass]);
  strcat(pTmpBuf, pTmpBuf2);
  strcat(pTmpBuf, string_4E3294);
  v17 = pPlayer->GetMaxHealth();
  v18 = pPlayer->sHealth;
  v19 = pPlayer->GetMaxHealth();
  v20 = sub_4178FE(pPlayer->sHealth, v19);
  sprintfex(pTmpBuf2, "%s : ", pGlobalTXT_LocalizationStrings[108], v20, v18, v17);
  strcat(pTmpBuf, pTmpBuf2);
  v21 = pPlayer->GetMaxMana();
  v22 = pPlayer->sMana;
  v23 = pPlayer->GetMaxMana();
  v24 = sub_4178FE(pPlayer->sMana, v23);
  sprintfex(pTmpBuf2, "%s : ", pGlobalTXT_LocalizationStrings[212], v24, v22, v21);
  strcat(pTmpBuf, pTmpBuf2);
  v25 = pPlayer->GetMajorConditionrIdx();
  v26 = aCharacterConditionNames[v25];
  v27 = GetConditionDrawColor(v25);
  sprintfex(pTmpBuf2, "%s: ", pGlobalTXT_LocalizationStrings[47], v27, v26);
  strcat(pTmpBuf, pTmpBuf2);
  v28 = pPlayer->uQuickSpell;
  if ( v28 )
    v29 = pSpellStats->pInfos[v28].pShortName;
  else
    v29 = pGlobalTXT_LocalizationStrings[153];
  sprintfex(pTmpBuf2, "%s: %s", pGlobalTXT_LocalizationStrings[172], v29);
  strcat(pTmpBuf, pTmpBuf2);
  v30 = 0;
  a1->DrawText(pFontArrus, 120, 22, 0, pTmpBuf, 0, 0, 0);
  v31 = v41;
  uFramesetIDa = 0;
  v32 = &_4E2AD8_ui_colors[1];
  v46 = (const char **)&aSpellNames[20];
  do
  {
    v33 = HIDWORD(v31->uExpireTime);
    v34 = LODWORD(v31->uExpireTime);
    if ( v33 >= (signed int)v30 && (v33 > (signed int)v30 || v34 > v30) )
    {
      v35 = __PAIR__(v33, v34) - pParty->uTimePlayed;
      v36 = uFramesetIDa++ * LOBYTE(a2->uFontHeight) + 134;
      v37 = *v46;
      v38 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(
              (unsigned __int8)*(v32 - 1),
              (unsigned __int8)*v32,
              (unsigned __int8)v32[1]);
      a1->DrawText(a2, 52, v36, v38, v37, 0, 0, 0);
      sub_41D20D_buff_remaining_time_string(v36, a1, v35, a2);
      v31 = v41;
      v30 = 0;
    }
    ++v46;
    ++v31;
    v32 += 3;
    v41 = v31;
  }
  while ( (signed int)v46 < (signed int)&dword_506978 );
  v39 = nullstring;
  if ( uFramesetIDa == v30 )
    v39 = pGlobalTXT_LocalizationStrings[153];
  sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[450], v39);
  return a1->DrawText(pFontArrus, 14, 114, v30, pTmpBuf, v30, v30, v30);
}

//----- (0041D08F) --------------------------------------------------------
void GUIWindow::_41D08F(int a2, int a3, int a4, int a5)
{
  if ( a2 )
  {
    this->field_28 = a2;
    this->field_30 = a3;
    this->field_34 = a4;
    this->field_2C_focus_id = a5;
    this->field_38 = a5;
    this->field_44 = 1;
  }
  else
  {
    this->field_28 = 0;
    this->field_30 = a3;
    this->field_34 = a4;
    this->field_2C_focus_id = 0;
    this->field_38 = 0;
    this->field_44 = 0;
  }
}


//----- (0041C26A) --------------------------------------------------------
void GUIWindow::Release()
{
  GUIWindow *v1; // esi@1
  unsigned int v2; // eax@2
  int v3; // eax@5
  int v4; // eax@6
  int v5; // eax@14
  int v6; // eax@15
  int i; // edi@20
  GUIButton *v8; // eax@26
  GUIButton *v9; // edi@27
  int v10; // esi@28
  int v11; // ecx@28
  int v12; // edx@29

  v1 = this;
  if ( !this )
    return;
  v2 = this->eWindowType;
  if ( (signed int)v2 > 18 )
  {
    v5 = v2 - 19;
    if ( !v5 )
    {
      pIcons_LOD->_40F9C5();
      uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = dword_506978;
      pKeyActionMap->_459ED1(3);
      goto LABEL_26;
    }
    v6 = v5 - 6;
    if ( !v6 )
    {
      for ( i = 0; i < uNumDialogueNPCPortraits; ++i )
        pDialogueNPCPortraits[i]->Release();
      uNumDialogueNPCPortraits = 0;
      pTexture_Dialogue_Background->Release();

      pIcons_LOD->_40F9C5();
      pIcons_LOD->_4114F2();
      dword_5C35D4 = 0;
      if ( bFlipOnExit )
      {
        pIndoorCamera->sRotationY = (stru_5C6E00->uIntegerDoublePi - 1) & (stru_5C6E00->uIntegerPi
                                                                       + pIndoorCamera->sRotationY);
        pParty->sRotationY = pIndoorCamera->sRotationY;
      }
      pParty->uFlags |= 2u;
      goto LABEL_26;
    }
    if ( v6 == 1 )
    {
      pVideoPlayer->Unload();
      goto LABEL_18;
    }
  }
  else
  {
    if ( v2 == 18 )
    {
      sub_41140B();
      sub_411473();
    }
    else
    {
      if ( !v2 )
        return;
      v3 = v2 - 9;
      if ( v3 )
      {
        v4 = v3 - 1;
        if ( !v4 )
        {
          if ( !dword_591084 )
            pDialogueNPCPortraits[0]->Release();
          uNumDialogueNPCPortraits = 0;
          pTexture_Dialogue_Background->Release();

          pIcons_LOD->_40F9C5();
          goto LABEL_19;
        }
        if ( v4 != 7 )
          goto LABEL_26;
LABEL_18:
        pTexture_outside->Release();
        pTexture_Dialogue_Background->Release();
        pIcons_LOD->_40F9C5();
LABEL_19:
        uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = dword_506978;
        goto LABEL_26;
      }
      OnCloseSpellook();
    }
  }
LABEL_26:
  v8 = v1->pControlsHead;
  if ( v8 )
  {
    do
    {
      v9 = v8->pNext;
      pAllocator->FreeChunk(v8);
      v8 = v9;
    }
    while ( v9 );
  }
  v1->pControlsHead = 0;
  v1->pControlsTail = 0;
  v1->uNumControls = 0;
  v1->eWindowType = WINDOW_null;
  v10 = v1->field_3C;
  v11 = uNumVisibleWindows;
  while ( v10 < v11 )
  {
    v12 = pVisibleWindowsIdxs[v10 + 1];
    pVisibleWindowsIdxs[v10] = v12;
    --*((int *)&stru_506F20.field_18 + 21 * v12);
    ++v10;
  }
  pVisibleWindowsIdxs[v11] = 0;
  uNumVisibleWindows = v11 - 1;
}






//----- (0041CD3B) --------------------------------------------------------
GUIButton *GUIWindow::GetControl(unsigned int uID)
{
  GUIButton *result; // eax@1
  unsigned int v3; // ecx@1

  result = this->pControlsHead;
  v3 = uID;
  if ( (signed int)uID > 0 )
  {
    do
    {
      result = result->pNext;
      --v3;
    }
    while ( v3 );
  }
  return result;
}

//----- (00411BFC) --------------------------------------------------------
void GUIWindow::InitializeBookView()
{
  GUIWindow *v1; // ebp@1
  signed int v2; // ecx@8
  __int64 *v3; // ebp@9
  char *v4; // ecx@10
  char *v5; // eax@12
  int v6; // eax@12
  __int64 v7; // qax@12
  unsigned int v8; // esi@12
  GUIButton *v9; // eax@19
  signed int v10; // esi@19
  int v11; // eax@24
  int v12; // eax@27
  int i; // esi@28
  char *v14; // ebp@29
  int v15; // eax@31
  unsigned int v16; // esi@35
  Player *v17; // esi@38
  unsigned __int16 v18; // ax@38
  unsigned int v19; // edi@43
  unsigned int v20; // edi@45
  void *v21; // esi@45
  char *v22; // [sp+10h] [bp-5Ch]@9
  signed int v23; // [sp+10h] [bp-5Ch]@38
  int v24; // [sp+14h] [bp-58h]@9
  char *v25; // [sp+14h] [bp-58h]@21
  GUIWindow v26; // [sp+18h] [bp-54h]@8

  v1 = this;
  pAudioPlayer->StopChannels(-1, -1);
  InitializeBookFonts();
  v1->CreateButton(0x1DBu, 0x1BDu, 0x9Eu, 0x22u, 1, 0, 0x71u, 0, 0, pGlobalTXT_LocalizationStrings[79], 0);
  uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 3;
  dword_506524 = 0;
  dword_506528 = 0;
  dword_50651C = 0;
  dword_506520 = 0;
  if ( v1->ptr_1C == (void *)177 )
  {
    byte_506360 = 0;
    pTexture_CurrentBook     = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("lb_bordr", TEXTURE_16BIT_PALETTE)];
    pTexture_LloydBeacons[0] = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("sbmap", TEXTURE_16BIT_PALETTE)];
    pTexture_50635C          = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("sbmap", TEXTURE_16BIT_PALETTE)];
    pTex_tab_an_6b__zoom_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6b", TEXTURE_16BIT_PALETTE)];
    pTex_tab_an_6a__zoom_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6a", TEXTURE_16BIT_PALETTE)];
    pBtn_Book_1 = v1->CreateButton(
                    415u,
                    13u,
                    39u,
                    36u,
                    1,
                    0,
                    0xB2u,
                    0,
                    0,
                    pGlobalTXT_LocalizationStrings[375],
                    0);
    pBtn_Book_2 = v1->CreateButton(
                    415u,
                    48u,
                    39u,
                    36u,
                    1,
                    0,
                    0xB2u,
                    1u,
                    0,
                    pGlobalTXT_LocalizationStrings[523],
                    0);
    v17 = &pParty->pPlayers[_506348_current_lloyd_playerid];
    v23 = 1;
    v18 = v17->pActiveSkills[14];
    if ( HIBYTE(v18) & 1 || (v18 & 0x80u) != 0 )
    {
      v23 = 5;
    }
    else
    {
      if ( v18 & 0x40 )
        v23 = 3;
    }
    v19 = 0;
    if ( v23 > 0 )
    {
      do
      {
        v1->CreateButton(
          pLloydsBeaconsPreviewXs[v19],
          pLloydsBeaconsPreviewYs[v19],
          0x5Cu,
          0x44u,
          1,
          180,
          0xB3u,
          v19,
          0,
          nullstring,
          0);
        ++v19;
      }
      while ( (signed int)v19 < v23 );
    }
    v20 = 0;
    v21 = v17->pInstalledBeacons;
    do
    {
      if ( *(_QWORD *)v21 >= (signed __int64)pParty->uTimePlayed )
        LoadThumbnailLloydTexture(v20, _506348_current_lloyd_playerid + 1);
      else
        memset(v21, 0, 0x1Cu);
      ++v20;
      v21 = (char *)v21 + 28;
    }
    while ( (signed int)v20 < 5 );
  }
  else
  {
    if ( v1->ptr_1C == (void *)195 )
    {
      pTexture_CurrentBook       = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("townport", TEXTURE_16BIT_PALETTE)];
      pTexture_TownPortalHarmn   = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tpharmndy", TEXTURE_16BIT_PALETTE)];
      pTexture_TownPortalElf     = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tpelf", TEXTURE_16BIT_PALETTE)];
      pTexture_TownPortalWarlock = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tpwarlock", TEXTURE_16BIT_PALETTE)];
      pTexture_TownPortalIsland  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tpisland", TEXTURE_16BIT_PALETTE)];
      pTexture_TownPortalHeaven  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tpheaven", TEXTURE_16BIT_PALETTE)];
      v16 = 0;
      pTexture_TownPortalHell    = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture( "tphell", TEXTURE_16BIT_PALETTE)];
      do
      {
        v1->CreateButton(
          pTownPortalBook_xs[v16],
          pTownPortalBook_ys[v16],
          pTownPortalBook_ws[v16],
          pTownPortalBook_hs[v16],
          1,
          182,
          0xB7u,
          v16,
          0,
          nullstring,
          0);
        ++v16;
      }
      while ( (signed int)v16 < 6 );
    }
    else
    {
      if ( v1->ptr_1C == (void *)200 )
      {
        pTexture_CurrentBook     = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture( "sbquiknot", TEXTURE_16BIT_PALETTE)];
        pTextures_5064A0[10]     = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture( "divbar", TEXTURE_16BIT_PALETTE)];
        pTex_tab_an_6b__zoom_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6b", TEXTURE_16BIT_PALETTE)];
        pTex_tab_an_7b__zoot_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-7b", TEXTURE_16BIT_PALETTE)];
        pTex_tab_an_6a__zoom_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6a", TEXTURE_16BIT_PALETTE)];
        pTex_tab_an_7a__zoot_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-7a", TEXTURE_16BIT_PALETTE)];
        pBtn_Book_1 = v1->CreateButton(
                        pViewport->uViewportX + 398,
                        pViewport->uViewportY + 1,
                        pTex_tab_an_6b__zoom_on->uTextureWidth,
                        pTex_tab_an_6b__zoom_on->uTextureHeight,
                        1,
                        0,
                        0x47u,
                        0xBu,
                        0,
                        pGlobalTXT_LocalizationStrings[192],// "Scroll Up"
                        pTex_tab_an_6b__zoom_on,
                        0);
        pBtn_Book_2 = v1->CreateButton(
                        pViewport->uViewportX + 398,
                        pViewport->uViewportY + 38,
                        pTex_tab_an_7b__zoot_on->uTextureHeight,
                        pTex_tab_an_7b__zoot_on->uTextureHeight,
                        1,
                        0,
                        0x47u,
                        0xAu,
                        0,
                        pGlobalTXT_LocalizationStrings[193],// "Scroll Down"
                        pTex_tab_an_7b__zoot_on,
                        0);
        dword_506520 = 0;
        memset(&pStru179, 0, 0xFA0u);
        for ( i = dword_506528; i < 512; ++i )
        {
          v14 = (&dword_722F10)[4 * i];
          if ( (unsigned __int16)_449B57_test_bit(pParty->_award_bits, i) && v14 )
          {
            v15 = dword_506520++;
            pStru179->field_0[v15] = i;
          }
        }
      }
      else
      {
        if ( v1->ptr_1C == (void *)201 )
        {
          pTexture_AutonotesBook   = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("sbautnot", TEXTURE_16BIT_PALETTE)];
          pTextures_5064A0[10]     = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("divbar", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_6b__zoom_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6b", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_7b__zoot_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-7b", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_6a__zoom_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6a", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_7a__zoot_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-7a", TEXTURE_16BIT_PALETTE)];
          pTexture_506394 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-1b", TEXTURE_16BIT_PALETTE)];
          pTexture_506390 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-1a", TEXTURE_16BIT_PALETTE)];
          pTexture_50638C = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-2b", TEXTURE_16BIT_PALETTE)];
          pTexture_506388 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-2a", TEXTURE_16BIT_PALETTE)];
          pTexture_506384 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-3b", TEXTURE_16BIT_PALETTE)];
          pTexture_506380 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-3a", TEXTURE_16BIT_PALETTE)];
          pTexture_50637C = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-5b", TEXTURE_16BIT_PALETTE)];
          pTexture_506378 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-5a", TEXTURE_16BIT_PALETTE)];
          pTexture_506374 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-4b", TEXTURE_16BIT_PALETTE)];
          pTexture_506370 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-4a", TEXTURE_16BIT_PALETTE)];
          pTexture_50636C = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-8b", TEXTURE_16BIT_PALETTE)];
          pTexture_506368 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-8a", TEXTURE_16BIT_PALETTE)];
          pBtn_Book_1 = v1->CreateButton(
                          pViewport->uViewportX + 398,
                          pViewport->uViewportY + 1,
                          0x32u,
                          0x22u,
                          1,
                          0,
                          0x47u,
                          0xBu,
                          0,
                          pGlobalTXT_LocalizationStrings[193],
                          pTex_tab_an_6b__zoom_on,
                          0);
          pBtn_Book_2 = v1->CreateButton(
                          pViewport->uViewportX + 398,
                          pViewport->uViewportY + 38,
                          0x32u,
                          0x22u,
                          1,
                          0,
                          0x47u,
                          0xAu,
                          0,
                          pGlobalTXT_LocalizationStrings[192],
                          pTex_tab_an_7b__zoot_on,
                          0);
          pBtn_Book_3 = v1->CreateButton(
                          pViewport->uViewportX + 398,
                          pViewport->uViewportY + 113,
                          0x32u,
                          0x22u,
                          1,
                          0,
                          0x47u,
                          2u,
                          0,
                          pGlobalTXT_LocalizationStrings[85],// "Potion Notes"
                          pTexture_506394,
                          0);
          pBtn_Book_4 = v1->CreateButton(
                          pViewport->uViewportX + 399,
                          pViewport->uViewportY + 150,
                          0x32u,
                          0x22u,
                          1,
                          0,
                          0x47u,
                          3u,
                          0,
                          pGlobalTXT_LocalizationStrings[137],// "Fountain Notes"
                          pTexture_50638C,
                          0);
          pBtn_Book_5 = v1->CreateButton(
                          pViewport->uViewportX + 397,
                          pViewport->uViewportY + 188,
                          0x32u,
                          0x22u,
                          1,
                          0,
                          0x47u,
                          4u,
                          0,
                          pGlobalTXT_LocalizationStrings[8],// "Obelisk Notes"
                          pTexture_506384,
                          0);
          pBtn_Book_6 = v1->CreateButton(
                          pViewport->uViewportX + 397,
                          pViewport->uViewportY + 226,
                          0x32u,
                          0x22u,
                          1,
                          0,
                          0x47u,
                          5u,
                          0,
                          pGlobalTXT_LocalizationStrings[141],// "Seer Notes"
                          pTexture_50637C,
                          0);
          pBtn_Autonotes_Misc = v1->CreateButton(
                                  pViewport->uViewportX + 397,
                                  pViewport->uViewportY + 264,
                                  0x32u,
                                  0x22u,
                                  1,
                                  0,
                                  0x47u,
                                  6u,
                                  0,
                                  pGlobalTXT_LocalizationStrings[123],// "Miscellaneous Notes"
                                  pTexture_506374,
                                  0);
          v9 = v1->CreateButton(
                 pViewport->uViewportX + 397,
                 pViewport->uViewportY + 302,
                 0x32u,
                 0x22u,
                 1,
                 0,
                 0x47u,
                 7u,
                 0,
                 pGlobalTXT_LocalizationStrings[662],// "Instructors"
                 pTexture_50636C,
                 0);
          v10 = dword_506528;
          pBtn_Autonotes_Instructors = v9;
          dword_506520 = 0;
          while ( v10 < 196 )
          {
            if ( dword_506568 == dword_72371C[2 * v10] )
            {
              v25 = (&dword_723718_autonote_related)[8 * (signed __int16)v10];
              if ( (short)v10 )
              {
                if ( (unsigned __int16)_449B57_test_bit((unsigned __int8 *)pParty->_autonote_related_stuff, v10) && v25 )
                {
                  v11 = dword_506520++;
                  pStru179->field_0[v11] = (signed __int16)v10;
                }
              }
            }
            ++v10;
          }
        }
        else
        {
          if ( v1->ptr_1C == (void *)202 )
          {
            dword_506364 = 1;
            pTextures_5064A0[12]     = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("sbmap", TEXTURE_16BIT_PALETTE)];
            pTex_tab_an_6b__zoom_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("zoom-on", TEXTURE_16BIT_PALETTE)];
            pTex_tab_an_7b__zoot_on  = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("zoot-on", TEXTURE_16BIT_PALETTE)];
            pTex_tab_an_6a__zoom_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("zoom-off", TEXTURE_16BIT_PALETTE)];
            pTex_tab_an_7a__zoot_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("zoot-off", TEXTURE_16BIT_PALETTE)];
            pTexture_506394 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabNon", TEXTURE_16BIT_PALETTE)];
            pTexture_506390 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabNoff", TEXTURE_16BIT_PALETTE)];
            pTexture_50638C = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabSon", TEXTURE_16BIT_PALETTE)];
            pTexture_506388 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabSoff", TEXTURE_16BIT_PALETTE)];
            pTexture_506384 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabEon", TEXTURE_16BIT_PALETTE)];
            pTexture_506380 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabEoff", TEXTURE_16BIT_PALETTE)];
            pTexture_50637C = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabWon", TEXTURE_16BIT_PALETTE)];
            pTexture_506378 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tabWoff", TEXTURE_16BIT_PALETTE)];
            pBtn_Book_1 = v1->CreateButton(
                            pViewport->uViewportX + 398,
                            pViewport->uViewportY + 1,
                            0x32u,
                            0x22u,
                            1,
                            0,
                            0x47u,
                            0,
                            0,
                            pGlobalTXT_LocalizationStrings[251],// "Zoom In"
                            pTex_tab_an_6b__zoom_on,
                            0);
            pBtn_Book_2 = v1->CreateButton(
                            pViewport->uViewportX + 398,
                            pViewport->uViewportY + 38,
                            0x32u,
                            0x22u,
                            1,
                            0,
                            0x47u,
                            1u,
                            0,
                            pGlobalTXT_LocalizationStrings[252],// "Zoom Out"
                            pTex_tab_an_7b__zoot_on,
                            0);
            pBtn_Book_3 = v1->CreateButton(
                            pViewport->uViewportX + 397,
                            pViewport->uViewportY + 113,
                            0x32u,
                            0x22u,
                            1,
                            0,
                            0x47u,
                            2u,
                            0,
                            pGlobalTXT_LocalizationStrings[192],// Scroll Up
                            (Texture *)nullstring,
                            0);
            pBtn_Book_4 = v1->CreateButton(
                            pViewport->uViewportX + 397,
                            pViewport->uViewportY + 150,
                            0x32u,
                            0x22u,
                            1,
                            0,
                            0x47u,
                            3u,
                            0,
                            pGlobalTXT_LocalizationStrings[193],// Scroll Down
                            (Texture *)nullstring,
                            0);
            pBtn_Book_5 = v1->CreateButton(
                            pViewport->uViewportX + 397,
                            pViewport->uViewportY + 188,
                            0x32u,
                            0x22u,
                            1,
                            0,
                            0x47u,
                            4u,
                            0,
                            pGlobalTXT_LocalizationStrings[573],// "Scroll Right"
                            (Texture *)nullstring,
                            0);
            pBtn_Book_6 = v1->CreateButton(
                            pViewport->uViewportX + 397,
                            pViewport->uViewportY + 226,
                            0x32u,
                            0x22u,
                            1,
                            0,
                            0x47u,
                            5u,
                            0,
                            pGlobalTXT_LocalizationStrings[572],// "Scroll Left"
                            (Texture *)nullstring,
                            0);
            return;
          }
          if ( v1->ptr_1C == (void *)203 )
          {
            pTextures_5064A0[13] = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("sbdate-time", TEXTURE_16BIT_PALETTE)];
            pTex_moon_new = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("moon_new", TEXTURE_16BIT_PALETTE)];
            pTex_moon_4   = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("moon_4", TEXTURE_16BIT_PALETTE)];
            pTex_moon_2   = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("moon_2", TEXTURE_16BIT_PALETTE)];
            pTex_moon_2_2 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("moon_2", TEXTURE_16BIT_PALETTE)];
            pTex_moon_ful = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("moon_ful", TEXTURE_16BIT_PALETTE)];
            return;
          }
          if ( v1->ptr_1C != (void *)224 )
            return;
          pTextures_5064A0[11] = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("sbplayrnot", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_6b__zoom_on = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6b", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_7b__zoot_on = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-7b", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_6a__zoom_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-6a", TEXTURE_16BIT_PALETTE)];
          pTex_tab_an_7a__zoot_off = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("tab-an-7a", TEXTURE_16BIT_PALETTE)];
          pBtn_Book_1 = v1->CreateButton(
                          pViewport->uViewportX + 398,
                          pViewport->uViewportY + 1,
                          pTex_tab_an_6b__zoom_on->uTextureWidth,
                          pTex_tab_an_6b__zoom_on->uTextureHeight,
                          1,
                          0,
                          0x47u,
                          0xBu,
                          0,
                          pGlobalTXT_LocalizationStrings[192],
                          pTex_tab_an_6b__zoom_on,
                          0);
          pBtn_Book_2 = v1->CreateButton(
                          pViewport->uViewportX + 398,
                          pViewport->uViewportY + 38,
                          pTex_tab_an_7b__zoot_on->uTextureHeight,
                          pTex_tab_an_7b__zoot_on->uTextureHeight,
                          1,
                          0,
                          0x47u,
                          0xAu,
                          0,
                          pGlobalTXT_LocalizationStrings[193],
                          pTex_tab_an_7b__zoot_on,
                          0);
          dword_506520 = 0;
          v26.uFrameX = 48;
          v26.uFrameY = 70;
          v26.uFrameWidth = 360;
          v26.uFrameHeight = 264;
          v2 = LOBYTE(pAutonoteFont->uFontHeight) - 3;
          v26.uFrameZ = 407;
          v26.uFrameHeight = v2 * 264 / v2;
          v26.uFrameW = v26.uFrameHeight + 69;
          memset(&pStru179, 0, 0xFA0u);
          memset(byte_5C6D50, 0, 0x64u);
          if ( dword_506528 < 29 )
          {
            v3 = (__int64 *)&pParty->field_3C.field_4F0[2 * dword_506528];
            v24 = dword_506528 + 1;
            v22 = (char *)&pStorylineText->field_4[3 * dword_506528 + 2];
            do
            {
              v4 = *(char **)v22;
              if ( *v3 )
              {
                if ( v4 )
                {
                  v5 = sub_495461(v4, uActiveCharacter - 1, 0, 0, 0, v3);
                  v6 = pAutonoteFont->CalcTextHeight(v5, &v26, 1, 0);
                  v7 = (v6 - 3) / (signed int)v26.uFrameHeight;
                  v8 = v7 + 1;
                  if ( (signed int)v7 + 1 > 0 )
                  {
                    memset32((void *)(4 * dword_506520 + 6043152), v24, v8);
                    do
                    {
                      LODWORD(v7) = dword_506520++;
                      byte_5C6D50[(int)v7] = BYTE4(v7);
                      ++HIDWORD(v7);
                    }
                    while ( SHIDWORD(v7) < (signed int)v8 );
                  }
                }
              }
              v22 += 12;
              ++v3;
              ++v24;
              __debugbreak(); // fix condition
            }
            while ( (signed int)v22 < (signed int)&pFactionTable->relations + 8 );
          }
        }
      }
      v12 = dword_506520;
      dword_506520 = 0;
      dword_506524 = v12;
    }
  }
}




//----- (00415551) --------------------------------------------------------
void GUIWindow::_415551(int arg0)
{
  unsigned int v2; // edi@1
  GUIWindow *v3; // ebx@1
  signed int v4; // esi@2
  unsigned int v5; // eax@2
  unsigned int v6; // edx@4
  unsigned int v7; // ecx@6
  unsigned int v8; // eax@9
  __int32 v9; // eax@10
  unsigned int v10; // eax@18
  LONG v11; // ecx@18
  unsigned int v12; // edx@18
  unsigned int v13; // eax@18
  const char *v14; // ecx@18
  int v15; // eax@19
  unsigned int v16; // esi@19
  const char *v17; // ebx@25
  int v18; // eax@26
  GUIWindow v19; // [sp+Ch] [bp-60h]@18
  POINT a2; // [sp+60h] [bp-Ch]@8
  unsigned int v21; // [sp+68h] [bp-4h]@18
  unsigned int v22; // [sp+74h] [bp+8h]@2
  unsigned int v23; // [sp+74h] [bp+8h]@18

  v2 = 0;
  v3 = this;
  if ( arg0 )
  {
    v4 = pViewport->uViewportX;
    v5 = pViewport->uViewportZ;
    v2 = pViewport->uViewportY;
    v22 = pViewport->uViewportW;
  }
  else
  {
    v4 = 0;
    v5 = 640;
    v22 = 480;
  }
  v6 = this->uFrameX;
  if ( (signed int)this->uFrameX >= v4 )
  {
    v7 = this->uFrameWidth;
    if ( (signed int)(v7 + v6) <= (signed int)v5 )
      goto LABEL_9;
    v3->uFrameX = v5 - v7;
  }
  else
  {
    this->uFrameX = v4;
  }
  v3->uFrameY = pMouse->GetCursorPos(&a2)->y + 30;
LABEL_9:
  v8 = v3->uFrameY;
  if ( (signed int)v8 >= (signed int)v2 )
  {
    if ( (signed int)(v8 + v3->uFrameHeight) <= (signed int)v22 )
      goto LABEL_14;
    v9 = pMouse->GetCursorPos(&a2)->y - v3->uFrameHeight - 30;
  }
  else
  {
    v9 = pMouse->GetCursorPos(&a2)->y + 30;
  }
  v3->uFrameY = v9;
LABEL_14:
  if ( (signed int)v3->uFrameY < (signed int)v2 )
    v3->uFrameY = v2;
  if ( (signed int)v3->uFrameX < v4 )
    v3->uFrameX = v4;
  v10 = v3->uFrameWidth;
  v11 = v3->uFrameX;
  v12 = v3->uFrameY;
  v21 = v10;
  a2.y = v11;
  v3->uFrameZ = v10 + v11 - 1;
  v13 = v3->uFrameHeight;
  v3->uFrameW = v13 + v12 - 1;
  memcpy(&v19, v3, sizeof(v19));
  v19.uFrameX += 12;
  v19.uFrameWidth -= 24;
  v19.uFrameY += 12;
  v19.uFrameHeight -= 12;
  v19.uFrameZ = v19.uFrameWidth + v19.uFrameX - 1;
  v23 = v12;
  v19.uFrameW = v19.uFrameHeight + v19.uFrameY - 1;
  v14 = v3->str_48;
  if ( v14 )
  {
    v15 = pFontLucida->CalcTextHeight(v14, &v19, 0, 0);
    v12 = v23;
    v16 = v15 + 24;
  }
  else
  {
    v16 = v13;
  }
  if ( (signed int)v16 < 64 )
    v16 = 64;
  if ( (signed int)(v16 + v12) > 479 )
    v16 = 479 - v12;
  DrawPopupWindow(a2.y, v12, v21, v16);
  v17 = v3->str_48;
  if ( v17 )
  {
    v18 = pFontLucida->CalcTextHeight(v17, &v19, 0, 0);
    v19.DrawText2(pFontLucida, 0, (signed int)(v16 - v18) / 2 - 14, 0, v17, 3u);
  }
}


//----- (0041192C) --------------------------------------------------------
void __cdecl InitializeBookTextures()
{
  signed int v0; // ebp@3
  Texture **v1; // ebx@3

  pAudioPlayer->StopChannels(-1, -1);
  ++pIcons_LOD->uTexturePacksCount;
  if ( !pIcons_LOD->uNumPrevLoadedFiles )
    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
  pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
  pTextures_5064A0[9] = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("book", TEXTURE_16BIT_PALETTE)];
  pTexture_pagemask = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("pagemask", TEXTURE_16BIT_PALETTE)];
  pTexture_506448   = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("ib-m5-u", TEXTURE_16BIT_PALETTE)];
  ptr_506440        = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("ib-m5-d", TEXTURE_16BIT_PALETTE)];
  pTexture_50643C   = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("ib-m6-u",TEXTURE_16BIT_PALETTE)];
  v0 = 1;
  v1 = (Texture **)&pTextures_tabs[0][0].pName[4];
  pTexture_506444 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("ib-m6-d",TEXTURE_16BIT_PALETTE)];
  do
  {
    *(&pTexture_pagemask + v0) = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(
                                                         (const char *)pLloydsBeacons_SomeYs[v0 + 4],
                                                         TEXTURE_16BIT_PALETTE)];
    sprintfex(pTmpBuf, "tab%da", v0);
    *(v1 - 1) = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE)];
    sprintfex(pTmpBuf, "tab%db", v0++);
    *v1 = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE)];
    v1 += 2;
  }
  while ( (signed int)v1 <= (signed int)&unk_506494 );
}

//----- (00411AAA) --------------------------------------------------------
void __cdecl InitializeBookFonts()
{
  pAudioPlayer->StopChannels(-1, -1);
  ++pIcons_LOD->uTexturePacksCount;
  if ( !pIcons_LOD->uNumPrevLoadedFiles )
    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
  pAudioPlayer->PlaySound((SoundID)230, 0, 0, -1, 0, 0, 0, 0);
  pTexture_mapbordr = &pIcons_LOD->pTextures[pIcons_LOD->LoadTexture("mapbordr", TEXTURE_16BIT_PALETTE)];
  pBookFont = LoadFont("book.fnt", "FONTPAL", 0);
  pBook2Font = LoadFont("book2.fnt", "FONTPAL", 0);
  pAutonoteFont = LoadFont("autonote.fnt", "FONTPAL", 0);
  pSpellFont = LoadFont("spell.fnt", "FONTPAL", 0);
}

//----- (00411B59) --------------------------------------------------------
void __fastcall LoadThumbnailLloydTexture(unsigned int uSlot, unsigned int uPlayer)
{
  unsigned int v2; // esi@1
  unsigned int v3; // edi@1
  FILE *v4; // ebx@1
  FILE *v5; // eax@2
  char pContainerName[64]; // [sp+Ch] [bp-44h]@1
  unsigned int v7; // [sp+4Ch] [bp-4h]@1

  v2 = uSlot;
  v7 = uPlayer;
  v3 = uSlot + 1;
  sprintfex(pContainerName, "data\\lloyd%d%d.pcx", uPlayer, uSlot + 1);
  v4 = fopen(pContainerName, "rb");
  if ( v4 )
  {
    pSavegameThumbnails[v2].LoadFromFILE(v4, 0, 1u);
    fclose(v4);
  }
  else
  {
    sprintfex(pContainerName, "lloyd%d%d.pcx", v7, v3);
    v5 = pNew_LOD->FindContainer(pContainerName, 1);
    if ( v5 )
      pSavegameThumbnails[v2].LoadFromFILE(v5, 0, 0);
    else
      *((int *)&pSavegameThumbnails->pPixels + 10 * v2) = 0;
  }
}


//----- (00411621) --------------------------------------------------------
GUIButton *GUIWindow::_411621()
{
  Player *v1; // edi@1
  GUIWindow *v2; // esi@1
  unsigned int v3; // ebp@1
  int v4; // eax@3
  GUIButton *result; // eax@25
  int a2; // [sp+10h] [bp-8h]@1
  int v7; // [sp+14h] [bp-4h]@1

  v1 = pPlayers[uActiveCharacter];
  v2 = this;
  LoadSpellbook(v1->field_1A4E);
  v3 = 0;
  a2 = 0;
  v7 = (int)(&v1->pFileSpellbook + v1->field_1A4E);
  do
  {
    if ( *(char *)(v7 + v3) )
    {
      v4 = 2 * (12 * v1->field_1A4E + (unsigned __int8)*(&byte_4E2431[12 * v1->field_1A4E] + v3));
      v2->CreateButton(
        pViewport->uViewportX + dword_4E20D0[v4],
        pViewport->uViewportY + dword_4E20D0[v4 + 1],
        *(short *)(dword_50640C[v3] + 24),
        *(short *)(dword_50640C[v3] + 26),
        1,
        79,
        0x56u,
        v3,
        0,
        nullstring,
        0);
      ++a2;
    }
    ++v3;
  }
  while ( (signed int)v3 < 11 );
  v2->CreateButton(0, 0, 0, 0, 1, 0, 0x33u, 0, 9u, nullstring, 0);
  if ( a2 )
    v2->_41D08F(a2, 0, 0, 0);
  if ( v1->pActiveSkills[12] )
    v2->CreateButton(0x18Fu, 0xAu, 0x32u, 0x24u, 1, 0, 0x57u, 0, 0, aSpellSchoolNames[0], 0);
  if ( v1->pActiveSkills[13] )
    v2->CreateButton(0x18Fu, 0x2Eu, 0x32u, 0x24u, 1, 0, 0x57u, 1u, 0, aSpellSchoolNames[1], 0);
  if ( v1->pActiveSkills[14] )
    v2->CreateButton(0x18Fu, 0x53u, 0x32u, 0x24u, 1, 0, 0x57u, 2u, 0, aSpellSchoolNames[2], 0);
  if ( v1->pActiveSkills[15] )
    v2->CreateButton(0x18Fu, 0x79u, 0x32u, 0x24u, 1, 0, 0x57u, 3u, 0, aSpellSchoolNames[3], 0);
  if ( v1->pActiveSkills[16] )
    v2->CreateButton(0x18Fu, 0x9Eu, 0x32u, 0x24u, 1, 0, 0x57u, 4u, 0, aSpellSchoolNames[4], 0);
  if ( v1->pActiveSkills[17] )
    v2->CreateButton(0x190u, 0xC4u, 0x32u, 0x24u, 1, 0, 0x57u, 5u, 0, aSpellSchoolNames[5], 0);
  if ( v1->pActiveSkills[18] )
    v2->CreateButton(0x190u, 0xEAu, 0x32u, 0x24u, 1, 0, 0x57u, 6u, 0, aSpellSchoolNames[6], 0);
  if ( v1->pActiveSkills[19] )
    v2->CreateButton(0x190u, 0x10Fu, 0x32u, 0x24u, 1, 0, 0x57u, 7u, 0, aSpellSchoolNames[7], 0);
  if ( v1->pActiveSkills[20] )
    v2->CreateButton(0x190u, 0x133u, 0x32u, 0x24u, 1, 0, 0x57u, 8u, 0, aSpellSchoolNames[8], 0);
  v2->CreateButton(
    0x1DCu,
    0x1C2u,
    pTexture_506444->uTextureWidth,
    pTexture_506444->uTextureHeight,
    1,
    78,
    0x58u,
    0,
    0,
    nullstring,
    0);
  ptr_5064F8 = v2->CreateButton(
                 0x1DCu,
                 0x1C2u,
                 0x30u,
                 0x20u,
                 1,
                 78,
                 0x58u,
                 0,
                 0,
                 nullstring,
                 pTexture_506444,
                 0);
  v2->CreateButton(
    0x231u,
    0x1C2u,
    ptr_506440->uTextureWidth,
    ptr_506440->uTextureHeight,
    1,
    0,
    0x71u,
    0,
    0,
    pGlobalTXT_LocalizationStrings[79],
    0);
  result = v2->CreateButton(
             0x231u,
             0x1C2u,
             0x30u,
             0x20u,
             1,
             0,
             0x71u,
             0,
             0,
             pGlobalTXT_LocalizationStrings[79],
             ptr_506440,
             0);
  ptr_5064F4 = result;
  return result;
}
// 50640C: using guessed type int dword_50640C[];


//----- (004B3157) --------------------------------------------------------
void GUIWindow::_4B3157()
{
  unsigned __int16 v1; // di@2
  const char *v2; // edx@4
  signed int v3; // edx@5
  char *v4; // edi@9
  int v5; // eax@45
  int v6; // edi@45
  char *v7; // eax@45
  int v8; // edi@46
  int v9; // eax@50
  unsigned int v10; // [sp-10h] [bp-C8h]@53
  unsigned __int16 v11; // [sp-Ch] [bp-C4h]@53
  unsigned int v12; // [sp-Ch] [bp-C4h]@60
  char *v13; // [sp-8h] [bp-C0h]@50
  unsigned int v14; // [sp-8h] [bp-C0h]@60
  unsigned int v15; // [sp-4h] [bp-BCh]@50
  Texture *v16; // [sp-4h] [bp-BCh]@60
  GUIWindow w; // [sp+Ch] [bp-ACh]@4
  GUIWindow v18; // [sp+60h] [bp-58h]@2
  int v19; // [sp+B4h] [bp-4h]@2

  if ( !ptr_507BC0 )
    return;
  memcpy(&v18, this, sizeof(v18));
  v18.uFrameWidth -= 18;
  v18.uFrameZ -= 18;
  v1 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0xFFu);
  v19 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0x15u, 0x99u, 0xE9u);
  pRenderer->DrawTextureIndexed(0x1DDu, 0, pTexture_Dialogue_Background);
  pRenderer->DrawTextureTransparent(
    0x1D4u,
    0,
    (Texture *)(uTextureID_507B04 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_507B04] : 0));
  if ( array_5913D8[6] != (NPCData *)uNumDialogueNPCPortraits || !uHouse_ExitPic )
  {
    w.uFrameWidth = 130;
    w.uFrameHeight = 2 * LOBYTE(pFontCreate->uFontHeight);

    //v2 = (const char *)p2DEvents_minus1_::04[13 * (unsigned int)ptr_507BC0->ptr_1C];
    v2 = p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].pName;

    if ( v2 )
    {
      v3 = 2 * LOBYTE(pFontCreate->uFontHeight) - 6 - pFontCreate->CalcTextHeight(v2, &w, 0, 0);
      if ( v3 < 0 )
        v3 = 0;
      v18.DrawText2(
        pFontCreate,
        0x1EAu,
        v3 / 2 + 4,
        v1,
        //(const char *)p2DEvents_minus1_::04[13 * (unsigned int)ptr_507BC0->ptr_1C],
        p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].pName,
        3u);
    }
  }
  v18.uFrameWidth += 8;
  v18.uFrameZ += 8;
  if ( !array_5913D8[6] )
  {
    if ( dword_F8B198 == 31 )
    {
LABEL_36:
      sub_4B4F4F();
      goto LABEL_58;
    }
    if ( ptr_F8B1E8 )
    {
      w.uFrameWidth = 458;
      w.uFrameZ = 457;
      v5 = pFontArrus->CalcTextHeight(ptr_F8B1E8, &w, 13, 0);
      v6 = v5 + 7;
      pRenderer->_4A6A68(
        8u,
        352 - (v5 + 7),
        (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
        (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - (v5 + 7));
      pRenderer->DrawTextureIndexed(8u, 347 - v6, pTexture_591428);
      v7 = FitTextInAWindow(ptr_F8B1E8, pFontArrus, &w, 0xDu, 0);
      ptr_507BC0->DrawText(pFontArrus, 13, 354 - v6, 0, v7, 0, 0, 0);
    }
    v8 = 0;
    if ( uNumDialogueNPCPortraits <= 0 )
      goto LABEL_58;
    while ( 1 )
    {
      pRenderer->DrawTextureIndexed(
        *(&_4E5E50_transui_x + v8 + 6 * uNumDialogueNPCPortraits - 6) - 4,
        *(&_4E5EE0_transui_y + v8 + 6 * uNumDialogueNPCPortraits - 6) - 4,
        (Texture *)(uTextureID_50795C != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_50795C] : 0));
      pRenderer->DrawTextureIndexed(
        *(&_4E5E50_transui_x + v8 + 6 * uNumDialogueNPCPortraits - 6),
        *(&_4E5EE0_transui_y + v8 + 6 * uNumDialogueNPCPortraits - 6),
        pDialogueNPCPortraits[v8]);
      if ( uNumDialogueNPCPortraits < 4 )
        break;
LABEL_57:
      ++v8;
      if ( v8 >= uNumDialogueNPCPortraits )
        goto LABEL_58;
    }
    if ( v8 + 1 == uNumDialogueNPCPortraits && uHouse_ExitPic )
    {
      v15 = 3;
      v13 = pMapStats->pInfos[uHouse_ExitPic].pName;
      v9 = 94 * v8 + 113;
    }
    else
    {
      if ( !v8 && dword_591080 )
      {
        v15 = 3;
        //v13 = (char *)p2DEvents_minus1__10[13 * (unsigned int)ptr_507BC0->ptr_1C];
        v13 = (char *)p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].pProprieterTitle;
        v11 = v19;
        v10 = 113;
LABEL_56:
        v18.DrawText2(pFontCreate, 0x1E3u, v10, v11, v13, v15);
        goto LABEL_57;
      }
      v15 = 3;
      v13 = array_5913D8[v8 - (dword_591080 != 0)]->pName;
      v9 = dword_4E5EC8[v8 + 6 * uNumDialogueNPCPortraits] + pDialogueNPCPortraits[v8]->uTextureHeight + 2;
    }
    v11 = v19;
    v10 = v9;
    goto LABEL_56;
  }
  v4 = (char *)array_5913D8[6] - 1;
  pRenderer->DrawTextureIndexed(
    _4E5E50_transui_x - 4,
    _4E5EE0_transui_y - 4,
    (Texture *)(uTextureID_50795C != -1 ? &pIcons_LOD->pTextures[uTextureID_50795C] : 0));
  pRenderer->DrawTextureIndexed(_4E5E50_transui_x, _4E5EE0_transui_y, pDialogueNPCPortraits[(signed int)v4]);
  if ( uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions == 14 )
  {
    CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
    goto LABEL_58;
  }
  if ( v4 || !dword_591080 )
  {
    sub_4B2A74();
  }
  else
  {
    sprintfex(
      pTmpBuf,
      pGlobalTXT_LocalizationStrings[429],
      //p2DEvents_minus1_::08[13 * (unsigned int)ptr_507BC0->ptr_1C],
      p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].pProprieterName,
      //p2DEvents_minus1__10[13 * (unsigned int)ptr_507BC0->ptr_1C]);
      p2DEvents[(unsigned int)ptr_507BC0->ptr_1C - 1].pProprieterTitle);
    v18.DrawText2(pFontCreate, 0x1E3u, 0x71u, v19, pTmpBuf, 3u);
    if ( dword_F8B198 <= 18 )
    {
      switch ( dword_F8B198 )
      {
        case 18:
          sub_4B6478();
          break;
        case 1:
          sub_4B910F();
          break;
        case 2:
          sub_4BA928();
          break;
        case 3:
          ui_shop_teachers();
          break;
        case 4:
          sub_4B9CC6();
          break;
        default:
          if ( dword_F8B198 > 4 )
          {
            if ( dword_F8B198 <= 16 )
            {
              sub_4B5D7C();
            }
            else
            {
              if ( dword_F8B198 == 17 )
                sub_4B7911();
            }
          }
          break;
      }
      goto LABEL_58;
    }
    switch ( dword_F8B198 )
    {
      case 21:
        sub_4B8285_prolly_draw_arcomage_result();
        break;
      case 22:
        _4B7D7E_bank();
        break;
      case 23:
        sub_4B705E();
        break;
      default:
        if ( dword_F8B198 <= 26 )
          break;
        if ( dword_F8B198 <= 28 )
        {
          TravelByTransport();
        }
        else
        {
          if ( dword_F8B198 != 30 )
          {
            if ( dword_F8B198 != 31 )
              break;
            goto LABEL_36;
          }
          ui_training();
        }
        break;
    }
  }
LABEL_58:
  if ( array_5913D8[6] == (NPCData *)uNumDialogueNPCPortraits && uHouse_ExitPic )
  {
    pRenderer->DrawTextureIndexed(
      0x22Cu,
      0x1C3u,
      (Texture *)(uTextureID_x_x_u != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_x_x_u] : 0));
    v16 = (Texture *)(uTextureID_x_ok_u != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_x_ok_u] : 0);
    v14 = 451;
    v12 = 476;
  }
  else
  {
    v16 = (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0);
    v14 = 445;
    v12 = 471;
  }
  pRenderer->DrawTextureIndexed(v12, v14, v16);
}


//----- (004B1854) --------------------------------------------------------
char *GUIWindow::_4B1854(__int64 a2)
{
  unsigned int v2; // edi@1
  unsigned int v3; // esi@1
  unsigned int v4; // ebp@1
  unsigned int v5; // ebx@1
  signed __int64 v6; // ST2C_8@1
  signed __int64 v7; // kr00_8@1
  char *v8; // eax@2
  char *v9; // eax@7
  char *v10; // eax@13
  char *v11; // eax@19
  unsigned __int16 v12; // ST0C_2@22
  int v13; // eax@22
  GUIWindow *v15; // [sp+0h] [bp-1Ch]@1
  signed __int64 v16; // [sp+Ch] [bp-10h]@1
  signed __int64 v17; // [sp+14h] [bp-8h]@1
  unsigned int v18; // [sp+20h] [bp+4h]@1

  v15 = this;
  v2 = (unsigned __int64)(signed __int64)((double)a2 * 0.234375) >> 32;
  v3 = (signed __int64)((double)a2 * 0.234375);
  v4 = (unsigned __int64)((signed __int64)((double)a2 * 0.234375) / 60) >> 32;
  v5 = (signed __int64)((double)a2 * 0.234375) / 60;
  v6 = (signed __int64)((double)a2 * 0.234375) / 60 / 60;
  v18 = (unsigned int)v6 / 0x18;
  v17 = (signed __int64)__PAIR__(v2, v3) % 60;
  v16 = (signed __int64)__PAIR__(v4, v5) % 60;
  v7 = v6 % 24;
  strcpy(pTmpBuf, pGlobalTXT_LocalizationStrings[532]);
  if ( (unsigned int)v6 / 0x18 )
  {
    v8 = pGlobalTXT_LocalizationStrings[57];
    if ( v18 <= 1 )
      v8 = pGlobalTXT_LocalizationStrings[56];
    sprintfex(pTmpBuf2, "%d %s ", v18, v8);
    strcat(pTmpBuf, pTmpBuf2);
  }
  if ( v7 )
  {
    if ( v7 <= 1 )
      v9 = pGlobalTXT_LocalizationStrings[109];
    else
      v9 = pGlobalTXT_LocalizationStrings[110];
    sprintfex(pTmpBuf2, "%d %s ", v7, v9);
    strcat(pTmpBuf, pTmpBuf2);
  }
  if ( v16 && !v18 )
  {
    if ( v16 <= 1 )
      v10 = pGlobalTXT_LocalizationStrings[437];
    else
      v10 = pGlobalTXT_LocalizationStrings[436];
    sprintfex(pTmpBuf2, "%d %s ", v16, v10);
    strcat(pTmpBuf, pTmpBuf2);
  }
  if ( v17 && !v7 )
  {
    if ( v17 <= 1 )
      v11 = pGlobalTXT_LocalizationStrings[439];
    else
      v11 = pGlobalTXT_LocalizationStrings[438];
    sprintfex(pTmpBuf2, "%d %s ", v17, v11);
    strcat(pTmpBuf, pTmpBuf2);
  }
  v12 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
  v13 = pFontArrus->CalcTextHeight(pTmpBuf, v15, 0, 0);
  return v15->DrawText2(pFontArrus, 0, (212 - v13) / 2 + 101, v12, pTmpBuf, 3u);
}



//----- (0044D406) --------------------------------------------------------
char *GUIWindow::DrawText2(GUIFont *a2, unsigned int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing)
{
  GUIWindow *v7; // esi@1
  unsigned int v8; // ebx@1
  char *v9; // eax@1
  char *result; // eax@1
  unsigned int v11; // edi@1
  signed int v12; // esi@1
  int v13; // eax@2
  GUIFont *v14; // [sp+Ch] [bp-4h]@1
  const char *Stra; // [sp+24h] [bp+14h]@5

  v7 = this;
  v14 = a2;
  v8 = this->uFrameWidth - uHorizontalMargin;
  ui_current_text_color = uDefaultColor;
  v9 = FitTextInAWindow(pInString, a2, this, uHorizontalMargin, 0);
  result = strtok(v9, "\n");
  v11 = uHorizontalMargin + v7->uFrameX;
  v12 = uVerticalMargin + v7->uFrameY;
  while ( 1 )
  {
    Stra = result;
    if ( !result )
      break;
    v13 = (signed int)(v8 - v14->GetLineWidth(result)) >> 1;
    if ( v13 < 0 )
      v13 = 0;
    v14->DrawTextLine(uDefaultColor, v11 + v13, v12, Stra, 640);
    v12 += LOBYTE(v14->uFontHeight) - uLineSpacing;
    result = strtok(0, "\n");
  }
  return result;
}
// 5C6DB4: using guessed type int ui_current_text_color;



//----- (0044CE08) --------------------------------------------------------
char GUIWindow::DrawText(GUIFont *a2, signed int uX, int uY, unsigned int uFontColor, const char *Str, int a7, int a8, unsigned int uFontShadowColor)
{
  GUIWindow *v9; // edi@1
  GUIFont *v10; // ebx@1
  int v11; // eax@2
  signed int v12; // esi@9
  signed int v13; // edi@9
  int v14; // edx@9
  int v15; // eax@25
  unsigned int v16; // ecx@25
  int v17; // eax@27
  int v18; // edi@32
  int v19; // esi@38
  std::string v21; // [sp-18h] [bp-50h]@2
  const char *v22; // [sp-8h] [bp-40h]@2
  int v23; // [sp-4h] [bp-3Ch]@2
  char Dest; // [sp+Ch] [bp-2Ch]@32
  char v25; // [sp+Fh] [bp-29h]@32
  char v26; // [sp+11h] [bp-27h]@34
  const char *v27; // [sp+20h] [bp-18h]@25
  int v28; // [sp+24h] [bp-14h]@25
  int v29; // [sp+28h] [bp-10h]@1
  size_t v30; // [sp+2Ch] [bp-Ch]@4
  GUIWindow *v31; // [sp+30h] [bp-8h]@1
  const char *v32; // [sp+34h] [bp-4h]@7
  size_t pInString; // [sp+4Ch] [bp+14h]@11
  
  auto a1 = this;
  v29 = 0;
  v9 = a1;
  v10 = a2;
  v31 = a1;
  if ( !Str )
  {
    MessageBoxW(nullptr, L"Invalid string passed!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:859", 0);
    return v11;
  }
  v11 = strcmp(Str, "null");
  if ( v11 )
  {
    v30 = strlen(Str);
    LOBYTE(v11) = 0;
    if ( !uX )
      uX = 12;
    if ( a8 )
    {
      v32 = Str;
    }
    else
    {
      v11 = (int)FitTextInAWindow(Str, v10, v9, uX, 0);
      v32 = (const char *)v11;
    }
    v12 = uX + v9->uFrameX;
    v13 = uY + v9->uFrameY;
    v14 = 0;
    if ( !a8 || (v11 = v13 + LOBYTE(v10->uFontHeight), v11 <= a8) )
    {
      pInString = 0;
      if ( (signed int)v30 > 0 )
      {
        do
        {
          LOBYTE(v11) = v32[v14];
          if ( (unsigned __int8)v11 >= v10->cFirstChar && (unsigned __int8)v11 <= v10->cLastChar
            || (char)v11 == 12
            || (char)v11 == 13
            || (char)v11 == 9
            || (char)v11 == 10 )
          {
            switch ( (unsigned __int8)v11 )
            {
              case 9u:
                strncpy(&Dest, &v32[v14 + 1], 3u);
                v25 = 0;
                pInString += 3;
                v29 = atoi(&Dest);
                v19 = atoi(&Dest);
                LOBYTE(v11) = (char)v31;
                v12 = uX + v31->uFrameX + v19;
                break;
              case 0xAu:
                v11 = LOBYTE(v10->uFontHeight);
                uY = uY + v11 - 3;
                v13 = uY + v31->uFrameY;
                v12 = uX + v29 + v31->uFrameX;
                if ( a8 )
                  goto LABEL_36;
                break;
              case 0xCu:
                strncpy(&Dest, &v32[v14 + 1], 5u);
                v26 = 0;
                v11 = atoi(&Dest);
                pInString += 5;
                uFontColor = v11;
                break;
              case 0xDu:
                strncpy(&Dest, &v32[v14 + 1], 3u);
                v25 = 0;
                pInString += 3;
                v18 = atoi(&Dest);
                v11 = v10->GetLineWidth(&v32[pInString]);
                v12 = v31->uFrameZ - v11 - v18;
                v13 = uY + v31->uFrameY;
                if ( a8 )
                {
                  v11 = LOBYTE(v10->uFontHeight);
LABEL_36:
                  v11 = v11 + v13 - 3;
                  if ( v11 > a8 )
                    return v11;
                  break;
                }
                break;
              default:
                if ( (char)v11 == 34 && v32[v14 + 1] == 34 )
                {
                  ++v14;
                  pInString = v14;
                }
                v27 = &v32[v14];
                v15 = (unsigned __int8)v32[v14];
                v16 = *((int *)&v10->cFirstChar + 3 * v15 + 9);
                v28 = *((int *)&v10->cFirstChar + 3 * v15 + 9);
                if ( v14 > 0 )
                  v12 += v10->pMetrics[v15].uLeftSpacing;
                v17 = (int)((char *)&v10[1] + v10->field_C20[v15]);
                if ( (short)uFontColor )
                  pRenderer->DrawText(
                    v12,
                    v13,
                    (unsigned __int8 *)v17,
                    v16,
                    LOBYTE(v10->uFontHeight),
                    v10->pFontPalettes[0],
                    uFontColor,
                    uFontShadowColor);
                else
                  pRenderer->DrawTextPalette(
                    v12,
                    v13,
                    v17,
                    v16,
                    LOBYTE(v10->uFontHeight),
                    v10->pFontPalettes[0],
                    a7);
                LOBYTE(v11) = v30;
                v12 += v28;
                if ( (signed int)pInString < (signed int)v30 )
                {
                  LOBYTE(v11) = 3 * *v27;
                  v12 += v10->pMetrics[(unsigned __int8)*v27].uRightSpacing;
                }
                break;
            }
          }
          v14 = pInString++ + 1;
        }
        while ( (signed int)pInString < (signed int)v30 );
      }
    }
  }
  return v11;
}


//----- (0044CB4F) --------------------------------------------------------
int GUIWindow::DrawTextInRect(GUIFont *a2, unsigned int uX, unsigned int uY, unsigned int uColor, const char *Str1, int Source, int a8)
{
  GUIFont *v8; // edi@1
  int v9; // ebx@1
  int v11; // esi@3
  unsigned __int8 v12; // cl@7
  signed int v13; // esi@19
  signed int v14; // ebx@19
  unsigned __int8 v15; // cl@21
  int v16; // eax@22
  int v17; // ecx@22
  int v18; // ecx@23
  int v19; // ecx@24
  unsigned int v20; // ecx@26
  int v21; // eax@28
  int v22; // ebx@34
  int v23; // eax@34
  int v24; // ebx@36
  char Str; // [sp+Ch] [bp-20h]@34
  char v26; // [sp+Fh] [bp-1Dh]@34
  char v27; // [sp+11h] [bp-1Bh]@35
  int v28; // [sp+20h] [bp-Ch]@17
  GUIWindow *a1; // [sp+24h] [bp-8h]@1
  size_t v30; // [sp+28h] [bp-4h]@1
  size_t Str1a; // [sp+40h] [bp+14h]@5
  size_t Str1b; // [sp+40h] [bp+14h]@19
  const char *Sourcea; // [sp+44h] [bp+18h]@20
  int v34; // [sp+48h] [bp+1Ch]@26

  v8 = a2;
  a1 = this;
  v30 = strlen(Str1);
  v9 = v8->GetLineWidth(Str1);
  if ( v9 < Source )
  {
    a1->DrawText(v8, uX, uY, uColor, Str1, 0, 0, 0);
    return v9;
  }
  strcpy(pTmpBuf2, Str1);
  v11 = 0;
  if ( a8 )
    _strrev(pTmpBuf2);
  Str1a = 0;
  if ( (signed int)v30 > 0 )
  {
    do
    {
      if ( v11 >= Source )
        break;
      if ( v8->IsCharValid(pTmpBuf2[Str1a]) )
      {
        if ( v12 < 9u )
          goto LABEL_12;
        if ( v12 > 0xAu )
        {
          if ( v12 == 12 )
          {
            Str1a += 5;
          }
          else
          {
            if ( v12 != 13 )
            {
LABEL_12:
              if ( (signed int)Str1a > 0 )
                v11 += v8->pMetrics[v12].uLeftSpacing;
              v11 += *((int *)&v8->cFirstChar + 3 * v12 + 9);
              if ( (signed int)Str1a < (signed int)v30 )
                v11 += v8->pMetrics[v12].uRightSpacing;
              goto LABEL_16;
            }
          }
        }
      }
LABEL_16:
      ++Str1a;
    }
    while ( (signed int)Str1a < (signed int)v30 );
  }
  pTmpBuf[Str1a + 1999] = 0;
  v30 = strlen(pTmpBuf2);
  v28 = v8->GetLineWidth(pTmpBuf2);
  if ( a8 )
    _strrev(pTmpBuf2);
  Str1b = 0;
  v13 = uX + a1->uFrameX;
  v14 = uY + a1->uFrameY;
  if ( (signed int)v30 > 0 )
  {
    Sourcea = &pTmpBuf2[1];
    do
    {
      if ( v8->IsCharValid(pTmpBuf2[Str1b]) )
      {
        v16 = v15;
        v17 = v15 - 9;
        if ( v17 )
        {
          v18 = v17 - 1;
          if ( v18 )
          {
            v19 = v18 - 2;
            if ( v19 )
            {
              if ( v19 == 1 )
              {
                strncpy(&Str, Sourcea, 3u);
                v26 = 0;
                Str1b += 3;
                Sourcea += 3;
                v22 = atoi(&Str);
                v23 = v8->GetLineWidth(&pTmpBuf2[Str1b]);
                v13 = a1->uFrameZ - v23 - v22;
                v14 = uY;
              }
              else
              {
                v20 = *((int *)&v8->cFirstChar + 3 * v16 + 9);
                v34 = *((int *)&v8->cFirstChar + 3 * v16 + 9);
                if ( (signed int)Str1b > 0 )
                  v13 += v8->pMetrics[v16].uLeftSpacing;
                v21 = (int)((char *)&v8[1] + v8->field_C20[v16]);
                if ( (short)uColor )
                  pRenderer->DrawText(
                    v13,
                    v14,
                    (unsigned __int8 *)v21,
                    v20,
                    LOBYTE(v8->uFontHeight),
                    v8->pFontPalettes[0],
                    uColor,
                    0);
                else
                  pRenderer->DrawTextPalette(
                    v13,
                    v14,
                    v21,
                    v20,
                    LOBYTE(v8->uFontHeight),
                    v8->pFontPalettes[0],
                    0);
                v13 += v34;
                if ( (signed int)Str1b < (signed int)v30 )
                  v13 += v8->pMetrics[(unsigned __int8)pTmpBuf2[Str1b]].uRightSpacing;
              }
            }
            else
            {
              strncpy(&Str, Sourcea, 5u);
              v27 = 0;
              Str1b += 5;
              Sourcea += 5;
              uColor = atoi(&Str);
            }
          }
          else
          {
            v24 = LOBYTE(v8->uFontHeight);
            v13 = uX;
            uY = uY + v24 - 3;
            v14 = v24 + uY - 3;
          }
        }
        else
        {
          strncpy(&Str, Sourcea, 3u);
          v26 = 0;
          atoi(&Str);
          Str1b += 3;
          Sourcea += 3;
        }
      }
      ++Str1b;
      ++Sourcea;
    }
    while ( (signed int)Str1b < (signed int)v30 );
  }
  return v28;
}

//----- (0041D12F) --------------------------------------------------------
GUIButton *GUIWindow::CreateButton(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, int a6, int a7, unsigned int uControlID, unsigned int uControlParam, unsigned __int8 uHotkey, const char *pName, Texture *pTextures, ...)
{
  GUIButton *v12; // esi@1
  unsigned int v13; // eax@1
  unsigned int v14; // ebx@4
  unsigned int v15; // eax@4
  unsigned int v16; // ebx@4
  unsigned int v17; // eax@4
  Texture *v18; // eax@4
  Texture **v19; // ecx@5
  Texture **v20; // edx@5
  GUIButton *v21; // eax@7

  v12 = (GUIButton *)pAllocator->AllocNamedChunk(0, 0xBCu, "BUTTON");
  v12->pParent = this;
  v12->uX = uX + this->uFrameX;
  v13 = uY + this->uFrameY;
  v12->uHeight = uHeight;
  v12->uY = v13;
  v12->uWidth = uWidth;
  if ( a6 == 2 && !uHeight )
    v12->uHeight = uWidth;
  v14 = v12->uX;
  v12->uButtonType = a6;
  v15 = v14 + uWidth - 1;
  v16 = 0;
  v12->uZ = v15;
  v17 = v12->uY;
  v12->field_2C = 0;
  v12->uW = v17 + uHeight - 1;
  v12->field_1C = a7;
  v12->uControlID = uControlID;
  v12->uControlParam = uControlParam;
  v12->uHotkey = uHotkey;
  strlen(pName);
  strcpy(v12->pButtonName, pName);
  v18 = pTextures;
  if ( pTextures )
  {
    v19 = &pTextures;
    v20 = v12->pTextures;
    do
    {
      ++v19;
      *v20 = v18;
      ++v16;
      ++v20;
      v18 = *v19;
    }
    while ( *v19 );
  }
  v12->uNumTextures = v16;
  v21 = this->pControlsTail;
  if ( v21 )
    v21->pNext = v12;
  else
    this->pControlsHead = v12;
  v12->pPrev = this->pControlsTail;
  this->pControlsTail = v12;
  v12->pNext = 0;
  ++this->uNumControls;
  return v12;
}

//----- (00459C2B) --------------------------------------------------------
void GUIWindow::DrawFlashingInputCursor(signed int a3, int a4, GUIFont *a2)
{
  signed int v4; // esi@1
  GUIWindow *v5; // edi@1

  v4 = a3;
  v5 = this;
  if ( GetTickCount() % 1000 > 500 )
    DrawText(a2, v4, a4, 0, "_", 0, 0, 0);
}


//----- (0041C432) --------------------------------------------------------
GUIWindow *GUIWindow::Create(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, WindowType eWindowType, int a4, int a5)
{
  unsigned int uNextFreeWindowID; // ebp@1
  //int *v8; // eax@1
  //GUIWindow *pWindow; // esi@4
  int v10; // eax@4
  unsigned int v11; // ebx@15
  NPCData *v12; // ebp@15
  void *v13; // ecx@18
  bool v14; // eax@20
  void *v15; // ecx@23
  bool v16; // eax@25
  void *v17; // ecx@28
  bool v18; // eax@30
  void *v19; // ecx@33
  bool v20; // eax@35
  void *v21; // ecx@38
  bool v22; // eax@40
  void *v23; // ecx@43
  bool v24; // eax@45
  int v25; // eax@65
  unsigned int v26; // ebx@65
  char *v27; // eax@71
  const char *v29; // [sp-8h] [bp-18h]@68
  char *v30; // [sp-4h] [bp-14h]@68
  int uWidtha; // [sp+14h] [bp+4h]@66
  int a4a; // [sp+20h] [bp+10h]@15

  uNextFreeWindowID = 0;
  for (uNextFreeWindowID = 0; uNextFreeWindowID < 20; ++uNextFreeWindowID)
  {
    if (pWindowList[uNextFreeWindowID].eWindowType == WINDOW_null)
      break;
  }


  auto pWindow = &pWindowList[uNextFreeWindowID];
  pWindow->uFrameWidth = uWidth;
  pWindow->uFrameZ = uX + uWidth - 1;
  pWindow->uFrameW = uY + uHeight - 1;
  pWindow->ptr_1C = (void *)a4;
  pWindow->str_48 = (char *)a5;
  v10 = uNumVisibleWindows;
  pWindow->uFrameX = uX;
  ++v10;
  pWindow->uFrameY = uY;
  pWindow->uFrameHeight = uHeight;
  pWindow->eWindowType = eWindowType;
  pWindow->field_44 = 0;
  uNumVisibleWindows = v10;
  pWindow->field_3C = v10;
  pVisibleWindowsIdxs[v10] = uNextFreeWindowID + 1;
  if ( (signed int)eWindowType <= 20 )
  {
    if (eWindowType != WINDOW_Chest)
    {
      switch (eWindowType)
      {
        case WINDOW_Book:
          pWindow->InitializeBookView();
          break;
        case WINDOW_A:
          dword_506978 = uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
          uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 4;
          ptr_5076F4 = pWindow->CreateButton(
                         0x1D7u,
                         0x1BDu,
                         0xA9u,
                         0x23u,
                         1,
                         0,
                         0x71u,
                         0,
                         0,
                         pGlobalTXT_LocalizationStrings[79], //"Exit"
                         (Texture *)(uTextureID_506438 != -1 ? &pIcons_LOD->pTextures[uTextureID_506438] : 0),
                         0);
          if ( pWindow->ptr_1C != (void *)1 )
          {
            a4a = 0;
            v11 = LOBYTE(pFontArrus->uFontHeight) - 3;
            v12 = GetNPCData(uDialogue_SpeakingActorNPC_ID);
            if ( sub_445C8B(uDialogue_SpeakingActorNPC_ID) == 1 )
            {
              if ( v12->joins )
              {
                pWindow->CreateButton(0x1E0u, 0x82u, 0x8Cu, v11, 1, 0, 0x88u, 0xDu, 0, "", 0);
                a4a = 1;
              }
              v13 = (void *)v12->bDrawSomeAnim;
              if ( v13 )
              {
                if ( a4a < 4 )
                {
                  v14 = sub_4466C4(v13);
                  if ( v14 == 1 || v14 == 2 )
                    pWindow->CreateButton(
                      0x1E0u,
                      a4a++ * v11 + 130,
                      0x8Cu,
                      v11,
                      1,
                      0,
                      0x88u,
                      0x13u,
                      0,
                      nullstring,
                      0);
                }
              }
              v15 = (void *)v12->evtb;
              if ( v15 )
              {
                if ( a4a < 4 )
                {
                  v16 = sub_4466C4(v15);
                  if ( v16 == 1 || v16 == 2 )
                    pWindow->CreateButton(
                      0x1E0u,
                      a4a++ * v11 + 130,
                      0x8Cu,
                      v11,
                      1,
                      0,
                      0x88u,
                      0x14u,
                      0,
                      nullstring,
                      0);
                }
              }
              v17 = (void *)v12->evtc;
              if ( v17 )
              {
                if ( a4a < 4 )
                {
                  v18 = sub_4466C4(v17);
                  if ( v18 == 1 || v18 == 2 )
                    pWindow->CreateButton(
                      0x1E0u,
                      a4a++ * v11 + 130,
                      0x8Cu,
                      v11,
                      1,
                      0,
                      0x88u,
                      0x15u,
                      0,
                      nullstring,
                      0);
                }
              }
              v19 = (void *)v12->evtd;
              if ( v19 )
              {
                if ( a4a < 4 )
                {
                  v20 = sub_4466C4(v19);
                  if ( v20 == 1 || v20 == 2 )
                    pWindow->CreateButton(
                      0x1E0u,
                      a4a++ * v11 + 130,
                      0x8Cu,
                      v11,
                      1,
                      0,
                      0x88u,
                      0x16u,
                      0,
                      nullstring,
                      0);
                }
              }
              v21 = (void *)v12->evte;
              if ( v21 )
              {
                if ( a4a < 4 )
                {
                  v22 = sub_4466C4(v21);
                  if ( v22 == 1 || v22 == 2 )
                    pWindow->CreateButton(
                      0x1E0u,
                      a4a++ * v11 + 130,
                      0x8Cu,
                      v11,
                      1,
                      0,
                      0x88u,
                      0x17u,
                      0,
                      nullstring,
                      0);
                }
              }
              v23 = (void *)v12->evtf;
              if ( v23 )
              {
                if ( a4a < 4 )
                {
                  v24 = sub_4466C4(v23);
                  if ( v24 == 1 || v24 == 2 )
                    pWindow->CreateButton(
                      0x1E0u,
                      a4a++ * v11 + 130,
                      0x8Cu,
                      v11,
                      1,
                      0,
                      0x88u,
                      0x18u,
                      0,
                      nullstring,
                      0);
                }
              }
            }
            else
            {
              if ( v12->joins )
              {
                pWindow->CreateButton(
                  0x1E0u,
                  0x82u,
                  0x8Cu,
                  v11,
                  1,
                  0,
                  0x88u,
                  0x4Du,
                  0,
                  pGlobalTXT_LocalizationStrings[407],
                  0);
                if ( v12->uFlags & 0x80 )
                {
                  sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[408], v12->pName);
                  pWindow->CreateButton(0x1E0u, v11 + 130, 0x8Cu, v11, 1, 0, 0x88u, 0x4Cu, 0, pTmpBuf, 0);
                }
                else
                {
                  pWindow->CreateButton(
                    0x1E0u,
                    v11 + 130,
                    0x8Cu,
                    v11,
                    1,
                    0,
                    0x88u,
                    0x4Cu,
                    0,
                    pGlobalTXT_LocalizationStrings[406],
                    0);
                }
                a4a = 2;
              }
            }
            pWindow->_41D08F(a4a, 1, 0, 1);
          }
          break;
        case WINDOW_11:
          dword_506978 = uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
          uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 17;
          ptr_5076F4 = pWindow->CreateButton(
                         0x236u,
                         0x1BDu,
                         0x4Bu,
                         0x21u,
                         1,
                         0,
                         0x5Bu,
                         0,
                         0x4Eu,
                         pGlobalTXT_LocalizationStrings[156],
                         (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0),
                         0);
          ptr_5076FC = pWindow->CreateButton(
                         0x1E6u,
                         0x1BDu,
                         0x4Bu,
                         0x21u,
                         1,
                         0,
                         0x5Au,
                         0,
                         0x59u,
                         pWindow->str_48,
                         (Texture *)(uTextureID_BUTTYES2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTYES2] : 0),
                         0);
          pWindow->CreateButton(
            _4E5E50_transui_x,
            _4E5EE0_transui_y,
            0x3Fu,
            0x49u,
            1,
            0,
            0x5Au,
            1u,
            0x20u,
            pWindow->str_48,
            0,
            0,
            0);
          pWindow->CreateButton(8u, 8u, 0x1CCu, 0x158u, 1, 0, 0x5Au, 1u, 0, pWindow->str_48, 0);
          break;
        case WINDOW_12:
          InitializeBookTextures();
          pWindow->_411621();
          break;
        case WINDOW_13:
          dword_506978 = uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
          pKeyActionMap->_459E5A(0, 15, pWindow);
          uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 19;
          break;
      }
      return pWindow;
    }
LABEL_62:
    pWindow->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, 0x6Eu, 1u, 0x31u, nullstring, 0);
    pWindow->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, 0x6Eu, 2u, 0x32u, nullstring, 0);
    pWindow->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, 0x6Eu, 3u, 0x33u, nullstring, 0);
    pWindow->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, 0x6Eu, 4u, 0x34u, nullstring, 0);
    pWindow->CreateButton(0, 0, 0, 0, 1, 0, 0xB0u, 0, 9u, nullstring, 0);
    return pWindow;
  }
  if (eWindowType == WINDOW_HouseInterior)
  {
    uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 13;
    ptr_5076F4 = pWindow->CreateButton(
                   0x1D7u,
                   0x1BDu,
                   0xA9u,
                   0x23u,
                   1,
                   0,
                   0x71u,
                   0,
                   0,
                   pGlobalTXT_LocalizationStrings[80],
                   (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
                   0);
    v25 = uNumDialogueNPCPortraits;
    v26 = 0;
    if ( uNumDialogueNPCPortraits > 0 )
    {
      do
      {
        uWidtha = v26 + 1;
        if ( v26 + 1 == v25 && uHouse_ExitPic )
        {
          v30 = pMapStats->pInfos[uHouse_ExitPic].pName;
          v29 = pGlobalTXT_LocalizationStrings[411];
        }
        else
        {
          if ( v26 || !dword_591080 )
            v27 = array_5913D8[v26 - (dword_591080 != 0)]->pName;
          else
            //v27 = (char *)p2DEvents_minus1_::08[13 * a4];
            v27 = (char *)p2DEvents[a4 - 1].pProprieterName;
          v30 = v27;
          v29 = pGlobalTXT_LocalizationStrings[435];
        }
        sprintfex(&byte_591180[100 * v26], v29, v30);
        array_5913D8[v26 + 7] = (NPCData *)pWindow->CreateButton(
                                             *(&_4E5E50_transui_x + v26 + 6 * uNumDialogueNPCPortraits - 6),
                                             *(&_4E5EE0_transui_y + v26 + 6 * uNumDialogueNPCPortraits - 6),
                                             0x3Fu,
                                             0x49u,
                                             1,
                                             0,
                                             0x19Au,
                                             v26,
                                             0,
                                             &byte_591180[100 * v26],
                                             0,
                                             0,
                                             0);
        ++v26;
        v25 = uNumDialogueNPCPortraits;
      }
      while ( uWidtha < uNumDialogueNPCPortraits );
    }
    if ( v25 == 1 )
    {
      ptr_507BC0 = &pWindowList[uNextFreeWindowID];
      _4B4224_UpdateNPCTopics(0);
    }
  }
  else
  {
    if (eWindowType == WINDOW_1A)
    {
      dword_506978 = uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
      uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 18;
      ptr_5076F4 = pWindow->CreateButton(
                     0x236u,
                     0x1BDu,
                     0x4Bu,
                     0x21u,
                     1,
                     0,
                     0x19Cu,
                     0,
                     0x4Eu,
                     pGlobalTXT_LocalizationStrings[34],
                     (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0),
                     0);
      ptr_5076FC = pWindow->CreateButton(
                     0x1E6u,
                     0x1BDu,
                     0x4Bu,
                     0x21u,
                     1,
                     0,
                     0x19Bu,
                     0,
                     0x59u,
                     pWindow->str_48,
                     (Texture *)(uTextureID_BUTTYES2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTYES2] : 0),
                     0);
      pWindow->CreateButton(
        _4E5E50_transui_x,
        _4E5EE0_transui_y,
        0x3Fu,
        0x49u,
        1,
        0,
        0x19Bu,
        1u,
        0x20u,
        pWindow->str_48,
        0);
      pWindow->CreateButton(8u, 8u, 0x1CCu, 0x158u, 1, 0, 0x19Bu, 1u, 0, pWindow->str_48, 0);
      return pWindow;
    }
    if (eWindowType == WINDOW_1B)
    {
      pEventTimer->Pause();
      pAudioPlayer->StopChannels(-1, -1);
      pMouse->SetCursorBitmap("MICON2");
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[39], 2u);
      return pWindow;
    }
    if (eWindowType == WINDOW_1E)
      goto LABEL_62;
    if (eWindowType == WINDOW_1F)
    {
      pMouse->SetCursorBitmap("MICON2");
      ptr_5076F4 = pWindow->CreateButton(
                     0x188u,
                     0x13Eu,
                     0x4Bu,
                     0x21u,
                     1,
                     0,
                     0x71u,
                     0,
                     0,
                     pGlobalTXT_LocalizationStrings[34],
                     (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0),
                     0);
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[39], 2u);
      ++pIcons_LOD->uTexturePacksCount;
      pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
      uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 23;
      if ( !pIcons_LOD->uNumPrevLoadedFiles )
        pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
    }
  }
  return pWindow;
}