view mm7_1.cpp @ 960:9a5db2cf999a

UIMSG and WINDOW_Type
author Ritor1
date Sat, 04 May 2013 17:45:17 +0600
parents c0d0656aa662
children 5a12082c803d
line wrap: on
line source

/* This file has been generated by the Hex-Rays decompiler.
   Copyright (c) 2007-2011 Hex-Rays <info@hex-rays.com>

   Detected compiler: Visual C++
*/

//#include <defs.h>
#include <assert.h>

#include "MM7.h"
#include "MapInfo.h"
#include "Game.h"
#include "GUIWindow.h"
#include "GUIFont.h"
#include "GUIProgressBar.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 "SpriteObject.h"
#include "ObjectList.h"
#include "Chest.h"
#include "PaletteManager.h"
#include "DecorationList.h"
#include "SaveLoad.h"
#include "stru123.h"
#include "Time.h"
#include "IconFrameTable.h"
#include "Awards.h"
#include "Autonotes.h"
#include "stru160.h"
#include "TurnEngine.h"
#include "CastSpellInfo.h"
#include "Weather.h"
#include "stru298.h"
#include "StorylineTextTable.h"
#include "Events2D.h"
#include "texts.h"
#include "UIHouses.h"
#include "mm7_data.h"

int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam);
int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4);
bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive);
bool __fastcall Initialize(HINSTANCE hInst, char *pCmdLine);


//----- (004A1780) mm6_chinese---------------------------------------------
int fixpoint_div(int a1, int a2)
{
  return ((__int64)a1 << 16) / a2;
}

int fixpoint_mul(int a1, int a2)
{
  return (((__int64)a1 << 16) * a2) >> 16;
}

//----- (004453C0) mm6-----------------------------------------------------
//----- (004A1760) mm6_chinese---------------------------------------------
int fixpoint_sub0(int a1, int a2)
{
  return ((__int64)a1 * (__int64)a2) >> 16;
}

//----- (004196A0) --------------------------------------------------------
void __cdecl sub_4196A0()
{
  GUIButton *i; // esi@2
  GUIButton *j; // esi@7

  if ( dword_507CC0 )
  {
    dword_507CC0 = 0;
    for ( i = pGUIWindow_CurrentMenu->pControlsHead; i; i = j )
    {
	  j=i->pNext;
	  if ( BYTE1(i->field_1C) & 0x80 )
	  {
        i->Release();
		pAllocator->FreeChunk(i);
	  }
    }
    for ( j = pGUIWindow_CurrentMenu->pControlsHead; j; j = j->pNext )
    {
      if ( j->msg == UIMSG_InventoryLeftClick)
      {
        j->uX = dword_50698C;
        j->uY = dword_506988;
        j->uZ = dword_506984;
        j->uW = dword_506980;
        pGUIWindow_CurrentMenu->_41D08F(1, 0, 0, 0);
      }
    }
  }
}

//----- (0041CD4F) --------------------------------------------------------
bool __thiscall sub_41CD4F(unsigned int _this)
{
  unsigned int v1; // edi@1
  unsigned int v2; // eax@2
  int v3; // esi@3
  int v4; // ecx@10
  GUIButton *v5; // eax@11
  int v6; // edx@12
  int v7; // ecx@20
  char v8; // zf@21
  GUIButton *v9; // ecx@24
  int v10; // esi@24
  //int v11; // edx@26
  int v12; // edx@28
  int v13; // esi@32
  GUIButton *v14; // eax@37
  int v15; // edx@38
  int v17; // ecx@50
  int v18; // edx@50
  GUIButton *v19; // ecx@54
  int v20; // esi@54
  //int v21; // edx@56
  int v22; // ecx@59
  int v23; // edx@59
  int v24; // ecx@60
  int v25; // esi@63
  unsigned int v26; // [sp+Ch] [bp-14h]@1
  int v27; // [sp+10h] [bp-10h]@1
  int v28; // [sp+14h] [bp-Ch]@10
  int v29; // [sp+14h] [bp-Ch]@36
  unsigned int uClickX; // [sp+18h] [bp-8h]@10
  unsigned int uClickY; // [sp+1Ch] [bp-4h]@10

  v1 = 0;
  v26 = _this;
  v27 = uNumVisibleWindows;
  if ( uNumVisibleWindows < 0 )
    return 0;
  v2 = pMessageQueue_50CBD0->uNumMessages;
  while ( 1 )
  {
    v3 = pVisibleWindowsIdxs[v27] - 1;
    if ( pWindowList[v3].field_44 != v1 )
	{
		switch(v26)
		{
			case VK_LEFT:
				{
				v12 = pWindowList[v3].field_34;
				if ( pWindowList[v3].pCurrentPosActiveItem - pWindowList[v3].pStartingPosActiveItem - v12 >= 0 )
				{
				  v8 = pCurrentScreen == SCREEN_PARTY_CREATION;
				  pWindowList[v3].pCurrentPosActiveItem -= v12;
				  if ( v8 )
				  {
					pAudioPlayer->PlaySound(SOUND_Button, v1, v1, -1, v1, v1, v1, v1);
					v2 = pMessageQueue_50CBD0->uNumMessages;
				  }
				}
				if ( pWindowList[v3].field_30 != v1 )
				{
					break;
				}
				v9 = pWindowList[v3].pControlsHead;
				v13 = pWindowList[v3].pCurrentPosActiveItem;
				if ( v13 > (signed int)v1 )
				{
				  do
				  {
					v9 = v9->pNext;
					--v13;
				  }
				  while ( v13 );
				}

                pMessageQueue_50CBD0->AddMessage(v9->msg, v9->msg_param, v1);
				break;
				}
			case VK_RIGHT:
				{
				v7 = pWindowList[v3].pCurrentPosActiveItem + pWindowList[v3].field_34;
				if ( v7 < pWindowList[v3].pNumPresenceButton + pWindowList[v3].pStartingPosActiveItem )
				{
					v8 = pCurrentScreen == SCREEN_PARTY_CREATION;
					pWindowList[v3].pCurrentPosActiveItem = v7;
					if ( v8 )
					{
						pAudioPlayer->PlaySound(SOUND_Button, v1, v1, -1, v1, v1, v1, v1);
						v2 = pMessageQueue_50CBD0->uNumMessages;
					}
				}
				if ( pWindowList[v3].field_30 != v1 )
				{
					break;
				}
				v9 = pWindowList[v3].pControlsHead;
				v10 = pWindowList[v3].pCurrentPosActiveItem;
				if ( v10 > (signed int)v1 )
				{
					do
					{
						v9 = v9->pNext;
						--v10;
					}
					while ( v10 );
				}
				pMessageQueue_50CBD0->AddMessage(v9->msg, v9->msg_param, v1);
				break;				
				}
			case VK_DOWN:
				{
				v17 = pWindowList[v3].pStartingPosActiveItem;
				v18 = pWindowList[v3].pCurrentPosActiveItem;
				if ( v18 >= pWindowList[v3].pNumPresenceButton + v17 - 1 )
					pWindowList[v3].pCurrentPosActiveItem = v17;
				else
					pWindowList[v3].pCurrentPosActiveItem = v18 + 1;
				if ( pWindowList[v3].field_30 != v1 )
					return 1;
				v19 = pWindowList[v3].pControlsHead;
				v20 = pWindowList[v3].pCurrentPosActiveItem;
				if ( v20 > (signed int)v1 )
				{
					do
					{
						v19 = v19->pNext;
						--v20;
					}
					while ( v20 );
				}
				pMessageQueue_50CBD0->AddMessage(v19->msg, v19->msg_param, v1);
				return 1;
				}
			case VK_SELECT:
				{
				pMouse->GetClickPos(&uClickX, &uClickY);
				v4 = pWindowList[v3].pStartingPosActiveItem;
				v28 = v4 + pWindowList[v3].pNumPresenceButton;
				if ( v4 < v4 + pWindowList[v3].pNumPresenceButton )
				{
					while ( 1 )
					{
						v5 = pWindowList[v3].pControlsHead;
						if ( v4 > 0 )
						{
							v6 = v4;
							do
							{
								v5 = v5->pNext;
								--v6;
							}
							while ( v6 );
						}
						if ( (signed int)uClickX >= (signed int)v5->uX
						&& (signed int)uClickX <= (signed int)v5->uZ
						&& (signed int)uClickY >= (signed int)v5->uY
						&& (signed int)uClickY <= (signed int)v5->uW )
							break;
						++v4;
						if ( v4 >= v28 )
						{
							v1 = 0;
							v2 = pMessageQueue_50CBD0->uNumMessages;
							--v27;
							if ( v27 < 0 )
  								return 0;
							continue;
						}
					}
					pWindowList[v3].pCurrentPosActiveItem = v4;
					return 1;
				}
				v2 = pMessageQueue_50CBD0->uNumMessages;
				break;
				}
			case VK_UP:
				{
				v22 = pWindowList[v3].pCurrentPosActiveItem;
				v23 = pWindowList[v3].pStartingPosActiveItem;
				if ( v22 <= v23 )
					v24 = pWindowList[v3].pNumPresenceButton + v23 - 1;
				else
					v24 = v22 - 1;
				v8 = pWindowList[v3].field_30 == v1;
				pWindowList[v3].pCurrentPosActiveItem = v24;
				if ( !v8 )
					return 1;
				v19 = pWindowList[v3].pControlsHead;
				v25 = pWindowList[v3].pCurrentPosActiveItem;
				if ( v25 > (signed int)v1 )
				{
					do
					{
						v19 = v19->pNext;
						--v25;
					}
					while ( v25 );
				}

				pMessageQueue_50CBD0->AddMessage(v19->msg, v19->msg_param, v1);
				return 1;
				}
			case VK_NEXT:
				{
				if ( pWindowList[v3].field_30 != v1 )
				{
					pMouse->GetClickPos(&uClickX, &uClickY);
					v4 = pWindowList[v3].pStartingPosActiveItem;
					v29 = v4 + pWindowList[v3].pNumPresenceButton;
					if ( v4 < v4 + pWindowList[v3].pNumPresenceButton )
					{
						while ( 1 )
						{
							v14 = pWindowList[v3].pControlsHead;
							if ( v4 > 0 )
							{
								v15 = v4;
								do
								{
									v14 = v14->pNext;
									--v15;
								}
								while ( v15 );
							}
							if ( (signed int)uClickX >= (signed int)v14->uX
							&& (signed int)uClickX <= (signed int)v14->uZ
							&& (signed int)uClickY >= (signed int)v14->uY
							&& (signed int)uClickY <= (signed int)v14->uW )
							{
								pWindowList[v3].pCurrentPosActiveItem = v4;
								return 1;
							}
							++v4;
							if ( v4 >= v29 )
							{
								v1 = 0;
								v2 = pMessageQueue_50CBD0->uNumMessages;
								break;
							}
						}
					}
					else
					{
						v2 = pMessageQueue_50CBD0->uNumMessages;
					}
				}
				break;
				}
			default:
				{
				break;
				}
			
		}
	}
    --v27;
    if ( v27 < 0 )
      return 0;
  }

}

//----- (0041D20D) --------------------------------------------------------
char __fastcall sub_41D20D_buff_remaining_time_string(int ecx0, GUIWindow *edx0, __int64 a3, GUIFont *a2)
{
  unsigned int v4; // edi@1
  unsigned int v5; // esi@1
  unsigned int v6; // ebp@1
  unsigned int v7; // ebx@1
  signed __int64 v8; // ST34_8@1
  signed __int64 v9; // kr00_8@1
  char *v10; // eax@2
  char *v11; // eax@7
  char *v12; // eax@13
  char *v13; // eax@19
  int uY; // [sp+0h] [bp-20h]@1
  GUIWindow *a1; // [sp+4h] [bp-1Ch]@1
  signed __int64 v17; // [sp+10h] [bp-10h]@1
  signed __int64 v18; // [sp+18h] [bp-8h]@1
  unsigned int v19; // [sp+24h] [bp+4h]@1

  a1 = edx0;
  uY = ecx0;
  v4 = (unsigned __int64)(signed __int64)((double)a3 * 0.234375) >> 32;
  v5 = (signed __int64)((double)a3 * 0.234375);
  v6 = (unsigned __int64)((signed __int64)((double)a3 * 0.234375) / 60) >> 32;
  v7 = (signed __int64)((double)a3 * 0.234375) / 60;
  v8 = (signed __int64)((double)a3 * 0.234375) / 60 / 60;
  v19 = (unsigned int)v8 / 0x18;
  v18 = (signed __int64)__PAIR__(v4, v5) % 60;
  v17 = (signed __int64)__PAIR__(v6, v7) % 60;
  v9 = v8 % 24;
  strcpy(pTmpBuf, "\r020");
  if ( (unsigned int)v8 / 0x18 )
  {
    v10 = pGlobalTXT_LocalizationStrings[57];   // Days
    if ( v19 <= 1 )
      v10 = pGlobalTXT_LocalizationStrings[56]; // Day
    sprintf(pTmpBuf2, "%d %s ", v19, v10);
    strcat(pTmpBuf, pTmpBuf2);
  }
  if ( v9 )
  {
    if ( v9 <= 1 )
      v11 = pGlobalTXT_LocalizationStrings[109];// Hour
    else
      v11 = pGlobalTXT_LocalizationStrings[110];// Hours
    sprintf(pTmpBuf2, "%d %s ", v9, v11);
    strcat(pTmpBuf, pTmpBuf2);
  }
  if ( v17 && !v19 )
  {
    if ( v17 <= 1 )
      v12 = pGlobalTXT_LocalizationStrings[437];// Minute
    else
      v12 = pGlobalTXT_LocalizationStrings[436];// Minutes
    sprintf(pTmpBuf2, "%d %s ", v17, v12);
    strcat(pTmpBuf, pTmpBuf2);
  }
  if ( v18 && !v9 )
  {
    if ( v18 <= 1 )
      v13 = pGlobalTXT_LocalizationStrings[439];// Second
    else
      v13 = pGlobalTXT_LocalizationStrings[438];// Seconds
    sprintf(pTmpBuf2, "%d %s ", v18, v13);
    strcat(pTmpBuf, pTmpBuf2);
  }
  return a1->DrawText(a2, 32, uY, 0, pTmpBuf, 0, 0, 0);
}

//----- (0041F54A) --------------------------------------------------------
void __cdecl LoadActualSkyFrame()
{
  if ( pTexture_RestUI_CurrentSkyFrame )
    pTexture_RestUI_CurrentSkyFrame->Release();
  if ( pTexture_RestUI_CurrentHourglassFrame )
    pTexture_RestUI_CurrentHourglassFrame->Release();
  pIcons_LOD->_40F9C5();
  sprintf(pTmpBuf, "TERRA%03d", pParty->uCurrentMinute / 6 + 10 * pParty->uCurrentHour);
  pTexture_RestUI_CurrentSkyFrame = pIcons_LOD->LoadTexturePtr(pTmpBuf, TEXTURE_16BIT_PALETTE);
}

//----- (0041F5BE) --------------------------------------------------------
void __cdecl Sleep6Hours()
{
  if ( _506F18_num_hours_to_sleep < 6 )
  {
    pParty->pPlayers[3].pConditions[2] = 0i64;
    pParty->pPlayers[2].pConditions[2] = 0i64;
    pParty->pPlayers[1].pConditions[2] = 0i64;
    pParty->pPlayers[0].pConditions[2] = 0i64;
    if ( _506F18_num_hours_to_sleep )
    {
      Rest(_506F18_num_hours_to_sleep);
      _506F18_num_hours_to_sleep = 0;
      LoadActualSkyFrame();
    }
    if ( dword_506F14 == 2 )
    {
      pGUIWindow_CurrentMenu->Release();
      pEventTimer->Resume();
      if ( pTexture_RestUI_CurrentSkyFrame )
        pTexture_RestUI_CurrentSkyFrame->Release();
      if ( pTexture_RestUI_CurrentHourglassFrame )
        pTexture_RestUI_CurrentHourglassFrame->Release();
      pTexture_RestUI_CurrentHourglassFrame = 0;
      pTexture_RestUI_CurrentSkyFrame = 0;
      pIcons_LOD->_4114F2();
      pIcons_LOD->_40F9C5();
      pCurrentScreen = SCREEN_GAME;
      viewparams->bRedrawGameUI = 1;
      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
      {
        pOutdoor->UpdateSunlightVectors();
        pOutdoor->UpdateFog();
      }
    }
    dword_506F14 = 0;
  }
  else
  {
    Rest(6u);
    _506F18_num_hours_to_sleep -= 6;
    LoadActualSkyFrame();
  }
  viewparams->bRedrawGameUI = 1;
}

//----- (0042038D) --------------------------------------------------------
void __cdecl sub_42038D()
{
  POINT *v0; // esi@2
  int v1; // ecx@2
  const char *v2; // eax@3
  POINT v3; // [sp+0h] [bp-10h]@2
  POINT a2; // [sp+8h] [bp-8h]@1

  if ( pMouse->GetCursorPos(&a2)->y < 350 )
  {
    v0 = pMouse->GetCursorPos(&a2);
    v1 = pRenderer->pActiveZBuffer[v0->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v3)->y]];
    if ( v1 )
    {
      auto _w = (ItemGen *)(&pOtherOverlayList->pOverlays[49].field_4 + 2662 * (unsigned int)pChestWindow->ptr_1C
                                             + 18 * *((short *)&pChests[0].igChestItems[139].uExpireTime
                                               + v1 + 2662 * (unsigned int)pChestWindow->ptr_1C + 3));

      _w = (ItemGen *)(&pChests[(unsigned int)pChestWindow->ptr_1C] -32 
		  + 18 * *((short *)&pChests[(unsigned int)pChestWindow->ptr_1C].igChestItems[139].uExpireTime + v1 + 3));
      v2 = _w->GetDisplayName();
      sub_41C0B8_set_status_string(v2);
    }
  }
}

//----- (00420C05) --------------------------------------------------------
void __fastcall party_finds_gold(unsigned int uNumGold, int _1_dont_share_with_followers___2_the_same_but_without_a_message__else_normal)
{
  unsigned int v2; // edi@1
  int v3; // ebp@1
  unsigned int v4; // esi@1
  int v5; // ecx@6
  NPCData *v6; // eax@6
  signed int v7; // edx@8
  signed int v8; // ebx@10
  char *v9; // edi@11
  signed int v10; // ecx@17
  int v11; // eax@21
  NPCData *v12; // ecx@21
  unsigned int v13; // ecx@23
  signed int v14; // [sp+Ch] [bp-4h]@6

  v2 = 0;
  v3 = 0;
  v4 = uNumGold;
  if ( _1_dont_share_with_followers___2_the_same_but_without_a_message__else_normal )
  {
    if ( _1_dont_share_with_followers___2_the_same_but_without_a_message__else_normal == 1 )
    {
      sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[467], uNumGold);// You found %lu gold!
    }
    else
    {
      if ( _1_dont_share_with_followers___2_the_same_but_without_a_message__else_normal == 2 )
        pTmpBuf2[0] = 0;
    }
  }
  else
  {
    v14 = 0;
    v5 = 0;
    v6 = pParty->pHirelings;
    do
    {
      if ( v6->pName )
      {
        v7 = v14++;
        pTmpBuf[v7] = v5;
      }
      ++v6;
      ++v5;
    }
    while ( (signed int)v6 < (signed int)&pParty->pPickedItem );
    v8 = 0;
    if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
    {
      v9 = (char *)pNPCStats->pNewNPCData;
      do
      {
        if ( v9[8] & 0x80
          && (!pParty->pHirelings[0].pName || strcmp(*(const char **)v9, pParty->pHirelings[0].pName))
          && (!pParty->pHirelings[1].pName || strcmp(*(const char **)v9, pParty->pHirelings[1].pName)) )
        {
          v10 = v14++;
          pTmpBuf[v10] = v8 + 2;
        }
        ++v8;
        v9 += 76;
      }
      while ( v8 < (signed int)pNPCStats->uNumNewNPCs );
      v2 = 0;
    }
    if ( v14 > 0 )
    {
      do
      {
        v11 = (unsigned __int8)pTmpBuf[v2];
        v12 = &pNPCStats->pNPCData[v11 + 499];
        if ( (unsigned __int8)pTmpBuf[v2] < 2 )
          v12 = &pParty->pHirelings[v11];
        v13 = v12->uProfession;
        if ( v13 )
          v3 += pNPCStats->pProfessions[v13].uHirePrice;//*(&pNPCStats->field_13A58 + 5 * v13);
        ++v2;
      }
      while ( (signed int)v2 < v14 );
    }
    if ( CheckHiredNPCSpeciality(Factor) )
      v4 += (signed int)(10 * v4) / 100;
    if ( CheckHiredNPCSpeciality(Banker) )
      v4 += (signed int)(20 * v4) / 100;
    if ( CheckHiredNPCSpeciality(Pirate) )
      v4 += (signed int)(10 * v4) / 100;
    if ( v3 )
    {
      v3 = (signed int)(v4 * v3 / 100) / 100;
      if ( v3 < 1 )
        v3 = 1;
      sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[466], v4, v3);// You found %lu gold (followers take %lu)!
    }
    else
    {
      sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[467], v4);// You found %lu gold!
    }
    v2 = 0;
  }
  pParty->uNumGold += v4 - v3;
  pUIAnim_Gold->uAnimTime = v2;
  pUIAnim_Gold->uAnimLength = 8 * pIconsFrameTable->pIcons[(signed __int16)pUIAnim_Gold->uIconID].uAnimLength;
  if ( pTmpBuf2[0] )
    ShowStatusBarString(pTmpBuf2, 2u);
  pAudioPlayer->PlaySound(SOUND_GoldReceived, v2, v2, -1, v2, v2, v2, v2);
}

//----- (00420E01) --------------------------------------------------------
void __cdecl sub_420E01()
{
  int chest_id; // edi@1
  POINT *v1; // esi@2
  int v2; // eax@2
  int v3; // ebx@4
  int v4; // esi@6
  int v5; // ecx@6
  //SpriteObject v6; // [sp+Ch] [bp-80h]@1
  POINT v7; // [sp+7Ch] [bp-10h]@2
  POINT a2; // [sp+84h] [bp-8h]@2
  
  SpriteObject v6; // [sp+Ch] [bp-80h]@1
  //SpriteObject::SpriteObject(&v6);

  chest_id = pGUIWindow_CurrentMenu->par1C;
  if ( pParty->pPickedItem.uItemID )
  {
    if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) )
      pMouse->RemoveHoldingItem();
  }
  else
  {
    v1 = pMouse->GetCursorPos(&a2);
    v2 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v7)->y]] & 0xFFFF;
    if ( v2 )
    {
      if ( v2 )
        v3 = v2 - 1;
      else
        v3 = -1;
      v4 = pChests[chest_id].pInventoryIndices[v3] - 1;
      if ( pItemsTable->pItems[pChests[chest_id].igChestItems[v4].uItemID].uEquipType == EQUIP_GOLD )
      {
        party_finds_gold(pChests[chest_id].igChestItems[v4].uSpecEnchantmentType, 0); 
        viewparams->bRedrawGameUI = 1;
      }
      else
      {
        pParty->SetHoldingItem(&pChests[chest_id].igChestItems[v4]);
      }
      sub_420B13(v4, v3);
    }
  }
}

//----- (004219BE) --------------------------------------------------------
GUIWindow *CastSpellInfo::sub_4219BE()
{
  int v1; // esi@1
  GUIWindow *v2; // ebx@1

  auto a4 = this;
  v1 = (int)a4;
  pEventTimer->Pause();
  pAudioPlayer->StopChannels(-1, -1);
  bRingsShownInCharScreen = 0;
  CharacterUI_LoadPaperdollTextures();
  pCurrentScreen = SCREEN_CASTING;
  v2 = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell_InInventory, v1, 0);
  pCharacterScreen_ExitBtn = v2->CreateButton(394, 318, 75, 33, 1, 0, UIMSG_ClickExitCharacterWindowBtn, 0, 0,
                 pGlobalTXT_LocalizationStrings[79], // Close
                 pIcons_LOD->GetTexture(papredoll_dbrds[2]),
                 pIcons_LOD->GetTexture(papredoll_dbrds[1]), 0);
  v2->CreateButton(0, 0, 0x1DCu, 0x159u, 1, 122, UIMSG_InventoryLeftClick, 0, 0, "", 0);
  pCharacterScreen_DollBtn = v2->CreateButton(0x1DCu, 0, 0xA4u, 0x159u, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
  v2->CreateButton( 61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
  v2->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
  v2->CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
  v2->CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
  return v2;
}

//----- (00421B2C) --------------------------------------------------------
bool __cdecl sub_421B2C_PlaceInInventory_or_DropPickedItem()
{
  unsigned int v0; // eax@2
  Texture *v1; // ebx@2
  int v2; // eax@3
  Player *v3; // esi@5
  int v4; // eax@6
  unsigned __int16 v5; // dx@11
  signed int v6; // eax@11
  char *v7; // edi@12
  __int16 v8; // ax@16
  SpriteObject a1; // [sp+4h] [bp-78h]@11
  int v11; // [sp+74h] [bp-8h]@2
  int v12; // [sp+78h] [bp-4h]@5

  if ( !pParty->pPickedItem.uItemID )
    return 1;
  v0 = pIcons_LOD->LoadTexture(
         pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName,
         TEXTURE_16BIT_PALETTE);
  v1 = pIcons_LOD->GetTexture(v0);
  v11 = areWeLoadingTexture;
  if ( uActiveCharacter
    && (v2 = pPlayers[uActiveCharacter]->AddItem(0xFFFFFFFFu, pParty->pPickedItem.uItemID)) != 0 )
  {
    memcpy(&pPlayers[uActiveCharacter]->pInventoryItems[v2-1], &pParty->pPickedItem, 0x24u);
	pMouse->RemoveHoldingItem();
  }
  else
  {
    v12 = 0;
    v3 = pParty->pPlayers;
	while ( v3 <= &pParty->pPlayers[3] )
    {
      v4 = v3->AddItem(0xFFFFFFFFu, pParty->pPickedItem.uItemID);
      if ( v4 )
	  {
		memcpy(&pParty->pPlayers[v12].pInventoryItems[v4], &pParty->pPickedItem, 0x24u);
		pMouse->RemoveHoldingItem();
		break;
	  }
	  ++v12;
      ++v3;
    }
    if ( v12 == 4 )
	{
		v5 = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSpriteID;
		v6 = 0;
		a1.uType = pItemsTable->pItems[pParty->pPickedItem.uItemID].uSpriteID;
		if ( (signed int)pObjectList->uNumObjects <= 0 )
		{
		  LOWORD(v6) = 0;
		}
		else
		{
		  v7 = (char *)&pObjectList->pObjects->uObjectID;
		  while ( v5 != *(short *)v7 )
		  {
			++v6;
			v7 += 56;
			if ( v6 >= (signed int)pObjectList->uNumObjects )
			{
				LOWORD(v6) = 0;
				break;
			}
		  }
		}
		a1.spell_caster_pid = OBJECT_Player;
		a1.uObjectDescID = v6;
		a1.vPosition.y = pParty->vPosition.y;
		a1.vPosition.x = pParty->vPosition.x;
		a1.vPosition.z = pParty->sEyelevel + pParty->vPosition.z;
		a1.uSoundID = 0;
		a1.uFacing = 0;
		a1.uAttributes = 8;
		v8 = pIndoor->GetSector(
			   pParty->vPosition.x,
			   pParty->vPosition.y,
			   pParty->sEyelevel + pParty->vPosition.z);
		a1.uSpriteFrameID = 0;
		a1.uSectorID = v8;
		memcpy(&a1.stru_24, &pParty->pPickedItem, sizeof(a1.stru_24));
		a1.Create(pParty->sRotationY, 184, 200, 0);
		pMouse->RemoveHoldingItem();
	}
  }
  if ( !v11 )
  {
    v1->Release();
    pIcons_LOD->_40F9C5();
  }
  return 1;
}

//----- (00421D00) --------------------------------------------------------
void __fastcall GameUI_OnPlayerPortraitLeftClick(unsigned int uPlayerID)
{
  //unsigned int v1; // esi@1
  //int v2; // eax@2
  //Player *v3; // ecx@2
  //Player *v4; // ecx@5
  unsigned int v5; // [sp-4h] [bp-10h]@21

  //v1 = uPlayerID;
  auto player = &pParty->pPlayers[uPlayerID - 1];
  if (pParty->pPickedItem.uItemID)
  {
    //v3 = player;
    if (auto slot = player->AddItem(0xFFFFFFFFu, pParty->pPickedItem.uItemID))
    {
      memcpy(&player->pInventoryItems[slot-1], &pParty->pPickedItem, 0x24u);
      viewparams->bRedrawGameUI = true;
      pMouse->RemoveHoldingItem();
      return;
    }

    if (!player->CanAct())
    {
      player = pPlayers[uActiveCharacter];
    }
    if(player->CanAct() || !pPlayers[uActiveCharacter]->CanAct())
		player->PlaySound(SPEECH_NoRoom, 0);
  }

//LABEL_9:
  if (pCurrentScreen == SCREEN_GAME)
  {
    viewparams->bRedrawGameUI = true;
    if ( uActiveCharacter != uPlayerID )
      //goto LABEL_27;
    {
      if ( pPlayers[uPlayerID]->uTimeToRecovery )
        return;

      uActiveCharacter = uPlayerID;
      return;
    }
    v5 = 7;
//LABEL_22:
    pGUIWindow_CurrentMenu = GameUI_InitializeCharacterWindow(v5);
    return;
  }
  if ( pCurrentScreen == SCREEN_SPELL_BOOK )
    return;
  if ( pCurrentScreen == SCREEN_CHEST )
  {
//LABEL_23:
    viewparams->bRedrawGameUI = true;
    if ( uActiveCharacter == uPlayerID )
    {
      pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
      pCurrentScreen = SCREEN_F;
      //goto LABEL_28;
      uActiveCharacter = uPlayerID;
      return;
    }
//LABEL_27:
    if ( pPlayers[uPlayerID]->uTimeToRecovery )
      return;
    //goto LABEL_28;
    uActiveCharacter = uPlayerID;
    return;
  }
  if ( pCurrentScreen != SCREEN_HOUSE )
  {
    if ( pCurrentScreen == SCREEN_E )
    {
//LABEL_28:
      uActiveCharacter = uPlayerID;
      return;
    }
    if ( pCurrentScreen != SCREEN_F )
    {
      viewparams->bRedrawGameUI = true;
      uActiveCharacter = uPlayerID;
      if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 102 )
        FillAwardsData();
      return;
    }
    //goto LABEL_23;
    viewparams->bRedrawGameUI = true;
    if ( uActiveCharacter == uPlayerID )
    {
      pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
      pCurrentScreen = SCREEN_F;
      //goto LABEL_28;
      uActiveCharacter = uPlayerID;
      return;
    }
//LABEL_27:
    if ( pPlayers[uPlayerID]->uTimeToRecovery )
      return;
    //goto LABEL_28;
    uActiveCharacter = uPlayerID;
    return;
  }
  if ( window_SpeakInHouse->field_40 == 1 )
    return;
  viewparams->bRedrawGameUI = true;
  if ( uActiveCharacter != uPlayerID )
    //goto LABEL_28;
    uActiveCharacter = uPlayerID;
    return;
  if (dialog_menu_id == HOUSE_DIALOGUE_SHOP_BUY_STANDARD || dialog_menu_id == HOUSE_DIALOGUE_SHOP_6)
  {
    __debugbreak(); // fix indexing
    pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
    v5 = 14;
    //goto LABEL_22;
    pGUIWindow_CurrentMenu = GameUI_InitializeCharacterWindow(v5);
    return;
  }
}
// 4E28F8: using guessed type int pCurrentScreen;
// F8B19C: using guessed type int dword_F8B19C;

//----- (00421EA6) --------------------------------------------------------
void __cdecl sub_421EA6_OnInventoryLeftClick()
{
  Player *v0; // ebx@1
  signed int v1; // eax@2
  signed int v2; // ecx@2
  int v3; // eax@2
  char v4; // sf@2
  int v5; // eax@2
  unsigned int v6; // eax@7
  unsigned int v7; // esi@12
  unsigned int v8; // eax@12
  unsigned int v9; // eax@16
  unsigned int v10; // eax@18
  ItemGen this_; // [sp+Ch] [bp-3Ch]@1
  POINT a2; // [sp+30h] [bp-18h]@4
  unsigned int v13; // [sp+38h] [bp-10h]@13
  unsigned int pY; // [sp+3Ch] [bp-Ch]@2
  unsigned int pX; // [sp+40h] [bp-8h]@2
  int a4; // [sp+44h] [bp-4h]@2

  v0 = pPlayers[uActiveCharacter];
  if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103 )
  {
    pMouse->GetClickPos(&pX, &pY);
    pY = pY - 17;
    v2 =pX - 14;
    pX = v2;
    v3 = 14 * (pY >> 5);
    v2 >>= 5;
    v4 = v2 + v3 < 0;
    v5 = v2 + v3;
    a4 = v5;
    if ( !v4 )
    {
      if ( v5 <= 126 && pMouse->GetCursorPos(&a2)->x < 462
            && pMouse->GetCursorPos(&a2)->x >= 14 )
      {
        if ( unk_50C9A0 )
        {
          v6 = v0->GetItemIDAtInventoryIndex(&a4);
          if ( v6 )
          {
            *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;
            *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
            *((int *)pGUIWindow_Settings->ptr_1C + 3) = v6 - 1;
            *((short *)pGUIWindow_Settings->ptr_1C + 3) = a4;
            ptr_50C9A4 = (ItemGen *)&v0->pInventoryItems[v6-1];
            unk_50C9A0 = 0;
            if ( pMessageQueue_50CBD0->uNumMessages )
              pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
            pMouse->SetCursorBitmap("MICON1");
            dword_50C9D0 = 113;
            dword_50C9D4 = 0;
            dword_50C9D8 = 256;
          }
          return;
        }
        if ( ptr_50C9A4 )
          return;
        v7 = pParty->pPickedItem.uItemID;
        v8 = v0->GetItemIDAtInventoryIndex(&a4);
        if ( !v7 )
        {
          if ( !v8 )
            return;
          memcpy(&pParty->pPickedItem, &v0->pInventoryItems[v8-1], sizeof(pParty->pPickedItem));
          v0->RemoveItemAtInventoryIndex(a4);
          v9 = pParty->pPickedItem.uItemID;
          pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
          return;
        }
        v13 = v8;
        if ( v8 )
        {
          a2.y = (LONG)&v0->pInventoryItems[v8-1];
          memcpy(&this_, (const void *)a2.y, sizeof(this_));
          v0->RemoveItemAtInventoryIndex(a4);
          pX = v0->AddItem2(a4, &pParty->pPickedItem);
          if ( !pX )
          {
            pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem);
            if ( !pX )
            {
              v0->_49298B(&this_, v13 - 1, a4);
              memcpy((void *)a2.y, &this_, sizeof(ItemGen));
              return;
            }
          }
          v9 = this_.uItemID;
          memcpy(&pParty->pPickedItem, &this_, sizeof(pParty->pPickedItem));
          pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
          return;
        }
        v10 = v0->AddItem(a4, v7);
        pX = v10;
        if ( v10 || (v10 = v0->AddItem(0xFFFFFFFFu, pParty->pPickedItem.uItemID), (pX = v10) != 0) )
        {
          memcpy(&v0->pInventoryItems[v10-1], &pParty->pPickedItem, 0x24u);
          pMouse->RemoveHoldingItem();
        }
      }
    }
  }
}

//----- (0042213C) --------------------------------------------------------
void __cdecl OnGameViewportClick()
{
  signed int v0; // ebx@2
  POINT *v1; // esi@3
  signed int v2; // eax@9
  BLVFace *v3; // eax@10
  unsigned int v4; // eax@11
  unsigned __int16 v5; // dx@14
  signed int v6; // eax@14
  char *v7; // esi@15
  int *v8; // eax@19
  int v9; // eax@19
  unsigned int v10; // eax@19
  int v11; // ecx@21
  ODMFace *v12; // eax@22
  LevelDecoration *v13; // esi@24
  __int16 v14; // ax@25
  int v15; // ecx@29
  signed int v16; // edx@30
  Actor *v17; // esi@30
  int v18; // ebx@47
  unsigned __int16 v19; // ax@50
  const char *v20; // eax@51
  signed int v21; // eax@58
  ItemGen *v22; // esi@62
  unsigned int v23; // eax@62
  SpriteObject a1; // [sp+Ch] [bp-80h]@1
  POINT v25; // [sp+7Ch] [bp-10h]@3
  POINT a2; // [sp+84h] [bp-8h]@3

  if ( pRenderer->pRenderD3D )
  {
    v0 = pGame->pVisInstance->get_picked_object_zbuf_val();
  }
  else
  {
    v1 = pMouse->GetCursorPos(&a2);
    v0 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v25)->y]];
  }
  if ( PID_TYPE(v0) == OBJECT_Item)
  {
    a2.y = (signed int)(unsigned __int16)v0 >> 3;
    v21 = (signed int)(unsigned __int16)v0 >> 3;
    if ( !(pObjectList->pObjects[pSpriteObjects[v21].uObjectDescID].uFlags & 0x10)
      && a2.y < 1000
      && pSpriteObjects[v21].uObjectDescID
      && (unsigned int)v0 < 0x2000000 )
    {
      v22 = &pSpriteObjects[v21].stru_24;
      v23 = pSpriteObjects[v21].stru_24.uItemID;
      if ( pItemsTable->pItems[v23].uEquipType == 18 )
      {
        party_finds_gold(v22->uSpecEnchantmentType, 0);
        viewparams->bRedrawGameUI = 1;
      }
      else
      {
        sprintfex(pTmpBuf2, pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[v23].pUnidentifiedName);
        ShowStatusBarString(pTmpBuf2, 2u);
        if ( v22->uItemID == 506 )
          _449B7E_toggle_bit(pParty->_quest_bits, 184, 1u);
        if ( v22->uItemID == 455 )
          _449B7E_toggle_bit(pParty->_quest_bits, 185, 1u);
        if ( !pParty->AddItem(v22) )
          pParty->SetHoldingItem(v22);
      }
      SpriteObject::OnInteraction(a2.y);
      return;
    }
    v4 = pParty->pPickedItem.uItemID;
    if ( !pParty->pPickedItem.uItemID )
		return;
    goto LABEL_14;
  }
  if ( PID_TYPE(v0) != OBJECT_Actor)
  {
    if ( PID_TYPE(v0) == OBJECT_Decoration)
    {
      v13 = &pLevelDecorations[(signed int)(unsigned __int16)v0 >> 3];
      if ( (signed int)(((unsigned int)v0 >> 16) - pDecorationList->pDecorations[v13->uDecorationDescID].uRadius) >= 512 )
	  {
          v4 = pParty->pPickedItem.uItemID;
          if ( !pParty->pPickedItem.uItemID )
            return;
          goto LABEL_14;
	  }
      v14 = v13->field_16_event_id;
      if ( !v14 )
      {
        if ( pLevelDecorations[(signed int)(unsigned __int16)v0 >> 3].IsInteractive() )
        {
          v15 = stru_5E4C90._decor_events[v13->_idx_in_stru123 - 75] + 380;
          activeLevelDecoration = &pLevelDecorations[(signed int)(unsigned __int16)v0 >> 3];
          EventProcessor(v15, 0, 1);
          activeLevelDecoration = NULL;
        }
        return;
      }
      v11 = v14;
    }
    else
    {
      if ( PID_TYPE(v0) != OBJECT_BModel || (signed)v0 >= 0x2000000 )
	  {
          v4 = pParty->pPickedItem.uItemID;
          if ( !pParty->pPickedItem.uItemID )
            return;
          goto LABEL_14;
	  }
      v2 = (signed int)(unsigned __int16)v0 >> 3;
      if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
      {
        v3 = &pIndoor->pFaces[v2];
        if ( !(v3->uAttributes & 0x2000000) )
        {
LABEL_11:
			v4 = pParty->pPickedItem.uItemID;
			if ( !pParty->pPickedItem.uItemID )
			{
				ShowNothingHereStatus();
				v4 = pParty->pPickedItem.uItemID;
				if ( !pParty->pPickedItem.uItemID )
					return;
			}
LABEL_14:
			v5 = pItemsTable->pItems[v4].uSpriteID;
			v6 = 0;
			a1.uType = v5;
			if ( (signed int)pObjectList->uNumObjects <= 0 )
			{
				LOWORD(v6) = 0;
			}
			else
			{
				v7 = (char *)&pObjectList->pObjects->uObjectID;
				while ( v5 != *(short *)v7 )
				{
					++v6;
					v7 += 56;
					if ( v6 >= (signed int)pObjectList->uNumObjects )
					{
						LOWORD(v6) = 0;
						break;
					}
				}
			}
			a1.uObjectDescID = v6;
			a1.vPosition.y = pParty->vPosition.y;
			a1.spell_caster_pid = OBJECT_Player;
			a1.vPosition.x = pParty->vPosition.x;
			a1.vPosition.z = pParty->sEyelevel + pParty->vPosition.z;
			a1.uSoundID = 0;
			a1.uFacing = 0;
			a1.uAttributes = 8;
			a1.uSectorID = pIndoor->GetSector(
								pParty->vPosition.x,
								pParty->vPosition.y,
								pParty->sEyelevel + pParty->vPosition.z);
			a1.uSpriteFrameID = 0;
			memcpy(&a1.stru_24, &pParty->pPickedItem, 0x24u);
			v8 = (int *)pMouse->GetCursorPos(&v25);
			v9 = UnprojectX(*v8);
			a1.Create(pParty->sRotationY + v9, 184, 200, 0);
			v10 = pIcons_LOD->LoadTexture(
					pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName,
					TEXTURE_16BIT_PALETTE);
			if (v10 != -1)
				pIcons_LOD->pTextures[v10].Release();
			pMouse->RemoveHoldingItem();
			pIcons_LOD->_40F9C5();
			return;
        }
        v11 = pIndoor->pFaceExtras[v3->uFaceExtraID].uEventID;
      }
      else
      {
        v12 = &pOutdoor->pBModels[(signed int)(unsigned __int16)v0 >> 9].pFaces[v2 & 0x3F];
        if ( !(v12->uAttributes & 0x2000000) )
          goto LABEL_11;
        v11 = v12->sCogTriggeredID;
      }
    }
    EventProcessor(v11, (unsigned __int16)v0, 1);
    return;
  }
  v16 = (signed int)(unsigned __int16)v0 >> 3;
  a2.y = v16;
  v17 = &pActors[v16];
  if ( v17->uAIState == 5 )
  {
    if ( (unsigned int)v0 < 0x2000000 )
    {
      stru_50C198.LootActor(&pActors[v16]);
      return;
    }
    v4 = pParty->pPickedItem.uItemID;
    if ( !pParty->pPickedItem.uItemID )
		return;
    goto LABEL_14;
  }
  if ( GetAsyncKeyState(VK_SHIFT) >= 0 )
  {
    if ( !v17->GetActorsRelation(0) && !(BYTE2(v17->uAttributes) & 8) )
    {
      if ( (unsigned int)v0 >= 0x2000000 )
	  {
          v4 = pParty->pPickedItem.uItemID;
          if ( !pParty->pPickedItem.uItemID )
            return;
          goto LABEL_14;
	  }
      if ( !v17->CanAct() )
        return;
      v18 = a2.y;
      Actor::FaceObject(a2.y, 4u, 0, 0);
      if ( !v17->sNPC_ID )
      {
        v19 = pNPCStats->pGroups_copy[v17->uGroup];
        if ( v19 )
        {
          v20 = pNPCStats->pCatchPhrases[v19];
          if ( v20 )
          {
            pParty->uFlags |= 2u;
            strcpy(byte_5B0938, v20);
            sub_4451A8_press_any_key(0, 0, 0);
          }
        }
        return;
      }
      /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
        return;
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)161;
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v18;
LABEL_42:
      *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
      ++pMessageQueue_50CBD0->uNumMessages;
      return;*/
      pMessageQueue_50CBD0->AddMessage(UIMSG_StartNPCDialogue, v18, 0);
      return;
    }
    if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
    {
      pTurnEngine->field_18 |= 8u;
      return;
    }
    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
    {
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)23;
      goto LABEL_41;
    }*/
    pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
  }
  else
  {
    if ( pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3 )
    {
      pParty->uFlags |= PARTY_FLAGS_1_FALLING;
      return;
    }
    if ( uActiveCharacter
      && sub_427769_spell(pPlayers[uActiveCharacter]->uQuickSpell))
    {
      pMessageQueue_50CBD0->AddMessage(UIMSG_19, 0, 0);
      /*&& (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)25;
LABEL_41:
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
      goto LABEL_42;*/
    }
  }
}

//----- (004226C2) --------------------------------------------------------
bool PauseGameDrawing()
{
  if ( pCurrentScreen != SCREEN_GAME
    && pCurrentScreen != SCREEN_NPC_DIALOGUE
    && pCurrentScreen != SCREEN_CHANGE_LOCATION )
  {
    if ( pCurrentScreen == SCREEN_INPUT_BLV )
      return pVideoPlayer->pSmackerMovie != 0;
    if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG )
      return true;
  }
  return false;
}
// 4E28F8: using guessed type int pCurrentScreen;

//----- (004226EF) --------------------------------------------------------
void SetUserInterface(PartyAlignment align, bool bReplace)
{
  unsigned int v3; // eax@7
  unsigned __int16 v4; // dx@7
  unsigned __int16 v5; // cx@7
  unsigned __int16 v6; // [sp-4h] [bp-14h]@7


    if (align == PartyAlignment_Evil)
    {
      if ( bReplace )
      {
        pTexture_RightFrame->Reload("ib-r-C.pcx");
        pTexture_BottomFrame->Reload("ib-b-C.pcx");
        pTexture_TopFrame->Reload("ib-t-C.pcx");
        pTexture_LeftFrame->Reload("ib-l-C.pcx");
        pTexture_StatusBar->Reload("IB-Foot-c.pcx");
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_right_panel], "ib-mb-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079D8], "ib-autmask-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079B4], "IB-COMP-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079D0], "IB-InitG-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079C8], "IB-InitY-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079CC], "IB-InitR-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_NPCLeft], "IB-NPCLD-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_NPCRight], "IB-NPCRD-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_ZoomIn], "ib-autout-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_ZoomOut], "ib-autin-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_50C98C], "IB-selec-C", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_CastSpell], "ib-m1d-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_Rest], "ib-m2d-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_QuickReference], "ib-m3d-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_GameSettings], "ib-m4d-c", 2);

        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Bless], "isg-01-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Preservation], "isg-02-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Hammerhands], "isg-03-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_PainReflection], "isg-04-c", 2);

        pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeC");
        pIconsFrameTable->InitializeAnimation(pUIAnim_WizardEye->uIconID);
        pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchC");
        pIconsFrameTable->InitializeAnimation(pUIAnum_Torchlight->uIconID);

        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uExitCancelTextureId], "ib-bcu-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50795C], "evtnpc-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507958], "fr_inven-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Parchment], "parchment", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B4], "cornr_ll-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B0], "cornr_lr-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076AC], "cornr_ul-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A8], "cornr_ur-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A4], "edge_btm-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A0], "edge_lf-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50769C], "edge_rt-c", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507698], "edge_top-c", 2);
        pIcons_LOD->ReloadTexture(pTexture_591428, "endcap-c", 2);
      }
      else
      {
        pTexture_RightFrame->Load("ib-r-C.pcx", 0);
        pTexture_BottomFrame->Load("ib-b-c.pcx", 0);
        pTexture_TopFrame->Load("ib-t-C.pcx", 0);
        pTexture_LeftFrame->Load("ib-l-C.pcx", 0);
        pTexture_StatusBar->Load("IB-Foot-c.pcx", 0);
        uTextureID_right_panel = pIcons_LOD->LoadTexture("ib-mb-C", TEXTURE_16BIT_PALETTE);
        dword_5079D8 = pIcons_LOD->LoadTexture("ib-autmask-c", TEXTURE_16BIT_PALETTE);
        dword_5079B4 = pIcons_LOD->LoadTexture("IB-COMP-C", TEXTURE_16BIT_PALETTE);
        dword_5079D0 = pIcons_LOD->LoadTexture("IB-InitG-c", TEXTURE_16BIT_PALETTE);
        dword_5079C8 = pIcons_LOD->LoadTexture("IB-InitY-c", TEXTURE_16BIT_PALETTE);
        dword_5079CC = pIcons_LOD->LoadTexture("IB-InitR-c", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_NPCLeft = pIcons_LOD->LoadTexture("IB-NPCLD-C", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_NPCRight = pIcons_LOD->LoadTexture("IB-NPCRD-C", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_ZoomIn = pIcons_LOD->LoadTexture("ib-autout-C", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_ZoomOut = pIcons_LOD->LoadTexture("ib-autin-C", TEXTURE_16BIT_PALETTE);
        dword_50C98C = pIcons_LOD->LoadTexture("IB-selec-C", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_CastSpell = pIcons_LOD->LoadTexture("ib-m1d-c", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_Rest = pIcons_LOD->LoadTexture("ib-m2d-c", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_QuickReference = pIcons_LOD->LoadTexture("ib-m3d-c", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_GameSettings = pIcons_LOD->LoadTexture("ib-m4d-c", TEXTURE_16BIT_PALETTE);
        uExitCancelTextureId = pIcons_LOD->LoadTexture("ib-bcu-c", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_Bless = pIcons_LOD->LoadTexture("isg-01-c", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_Preservation = pIcons_LOD->LoadTexture("isg-02-c", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_Hammerhands = pIcons_LOD->LoadTexture("isg-03-c", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_PainReflection = pIcons_LOD->LoadTexture("isg-04-c", TEXTURE_16BIT_PALETTE);
        uTextureID_50795C = pIcons_LOD->LoadTexture("evtnpc-c", TEXTURE_16BIT_PALETTE);
        uTextureID_507958 = pIcons_LOD->LoadTexture("fr_inven", TEXTURE_16BIT_PALETTE);
        pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeC");
        pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnim_WizardEye->uIconID);
        pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchC");
        pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnum_Torchlight->uIconID);
      }
      v3 = TargetColor(0xC8u, 0, 0);
      v4 = 0;
      v6 = 0;
      v5 = 10;
    }
    else if (align == PartyAlignment_Neutral)
    {
      if ( bReplace )
      {
        pTexture_RightFrame->Reload("ib-r-a.pcx");
        pTexture_BottomFrame->Reload("ib-b-a.pcx");
        pTexture_TopFrame->Reload("ib-t-a.pcx");
        pTexture_LeftFrame->Reload("ib-l-a.pcx");
        pTexture_StatusBar->Reload("IB-Foot-a.pcx");
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_right_panel], "ib-mb-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079D8], "ib-autmask-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079B4], "IB-COMP-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079D0], "IB-InitG-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079C8], "IB-InitY-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079CC], "IB-InitR-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_NPCLeft], "IB-NPCLD-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_NPCRight], "IB-NPCRD-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_ZoomIn], "ib-autout-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_ZoomOut], "ib-autin-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_50C98C], "IB-selec-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_CastSpell], "ib-m1d-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_Rest], "ib-m2d-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_QuickReference], "ib-m3d-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_GameSettings], "ib-m4d-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Bless], "isg-01-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Preservation], "isg-02-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Hammerhands], "isg-03-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_PainReflection], "isg-04-a", 2);
        pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeA");
        pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnim_WizardEye->uIconID);
        pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchA");
        pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnum_Torchlight->uIconID);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uExitCancelTextureId], "ib-bcu-a", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50795C], "evtnpc", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507958], "fr_inven", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Parchment], "parchment", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B4], "cornr_ll", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B0], "cornr_lr", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076AC], "cornr_ul", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A8], "cornr_ur", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A4], "edge_btm", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A0], "edge_lf", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50769C], "edge_rt", 2);
        pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507698], "edge_top", 2);
        pIcons_LOD->ReloadTexture(pTexture_591428, "endcap", 2);
      }
      else
      {
        pTexture_RightFrame->Load("ib-r-A.pcx", 0);
        pTexture_BottomFrame->Load("ib-b-A.pcx", 0);
        pTexture_TopFrame->Load("ib-t-A.pcx", 0);
        pTexture_LeftFrame->Load("ib-l-A.pcx", 0);
        pTexture_StatusBar->Load("IB-Foot-a.pcx", 0);
        uTextureID_right_panel = pIcons_LOD->LoadTexture("ib-mb-A", TEXTURE_16BIT_PALETTE);
        dword_5079D8 = pIcons_LOD->LoadTexture("ib-autmask-a", TEXTURE_16BIT_PALETTE);
        dword_5079B4 = pIcons_LOD->LoadTexture("IB-COMP-A", TEXTURE_16BIT_PALETTE);
        dword_5079D0 = pIcons_LOD->LoadTexture("IB-InitG-a", TEXTURE_16BIT_PALETTE);
        dword_5079C8 = pIcons_LOD->LoadTexture("IB-InitY-a", TEXTURE_16BIT_PALETTE);
        dword_5079CC = pIcons_LOD->LoadTexture("IB-InitR-a", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_NPCLeft = pIcons_LOD->LoadTexture("IB-NPCLD-A", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_NPCRight = pIcons_LOD->LoadTexture("IB-NPCRD-A", TEXTURE_16BIT_PALETTE);
        dword_50C98C = pIcons_LOD->LoadTexture("IB-selec-A", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_CastSpell = pIcons_LOD->LoadTexture("ib-m1d-a", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_Rest = pIcons_LOD->LoadTexture("ib-m2d-a", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_QuickReference = pIcons_LOD->LoadTexture("ib-m3d-a", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_GameSettings = pIcons_LOD->LoadTexture("ib-m4d-a", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_ZoomIn = pIcons_LOD->LoadTexture("ib-autout-a", TEXTURE_16BIT_PALETTE);
        uTextureID_Btn_ZoomOut = pIcons_LOD->LoadTexture("ib-autin-a", TEXTURE_16BIT_PALETTE);
        uExitCancelTextureId = pIcons_LOD->LoadTexture("ib-bcu-a", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_Bless = pIcons_LOD->LoadTexture("isg-01-a", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_Preservation = pIcons_LOD->LoadTexture("isg-02-a", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_Hammerhands = pIcons_LOD->LoadTexture("isg-03-a", TEXTURE_16BIT_PALETTE);
        uTextureID_PlayerBuff_PainReflection = pIcons_LOD->LoadTexture("isg-04-a", TEXTURE_16BIT_PALETTE);
        uTextureID_50795C = pIcons_LOD->LoadTexture("evtnpc", TEXTURE_16BIT_PALETTE);
        uTextureID_507958 = pIcons_LOD->LoadTexture("fr_inven", TEXTURE_16BIT_PALETTE);
        pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeA");
        pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnim_WizardEye->uIconID);
        pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchA");
        pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnum_Torchlight->uIconID);
        uTextureID_Parchment = pIcons_LOD->LoadTexture("parchment", TEXTURE_16BIT_PALETTE);
        uTextureID_5076B4 = pIcons_LOD->LoadTexture("cornr_ll", TEXTURE_16BIT_PALETTE);
        uTextureID_5076B0 = pIcons_LOD->LoadTexture("cornr_lr", TEXTURE_16BIT_PALETTE);
        uTextureID_5076AC = pIcons_LOD->LoadTexture("cornr_ul", TEXTURE_16BIT_PALETTE);
        uTextureID_5076A8 = pIcons_LOD->LoadTexture("cornr_ur", TEXTURE_16BIT_PALETTE);
        uTextureID_5076A4 = pIcons_LOD->LoadTexture("edge_btm", TEXTURE_16BIT_PALETTE);
        uTextureID_5076A0 = pIcons_LOD->LoadTexture("edge_lf", TEXTURE_16BIT_PALETTE);
        uTextureID_50769C = pIcons_LOD->LoadTexture("edge_rt", TEXTURE_16BIT_PALETTE);
        uTextureID_507698 = pIcons_LOD->LoadTexture("edge_top", TEXTURE_16BIT_PALETTE);
        pTexture_591428 = pIcons_LOD->LoadTexturePtr("endcap", TEXTURE_16BIT_PALETTE);

      }
      v3 = TargetColor(0xAu, 0, 0);
      v4 = 214;
      v5 = 230;
      v6 = 193;
    }
  else if (align == PartyAlignment_Good)
  {
    if ( bReplace )
    {
      pTexture_RightFrame->Reload("ib-r-B.pcx");
      pTexture_BottomFrame->Reload("ib-b-B.pcx");
      pTexture_TopFrame->Reload("ib-t-B.pcx");
      pTexture_LeftFrame->Reload("ib-l-B.pcx");
      pTexture_StatusBar->Reload("IB-Foot-b.pcx");
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_right_panel], "ib-mb-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079D8], "ib-autmask-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079B4], "IB-COMP-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079D0], "IB-InitG-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079C8], "IB-InitY-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_5079CC], "IB-InitR-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_NPCLeft], "IB-NPCLD-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_NPCRight], "IB-NPCRD-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_ZoomIn], "ib-autout-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_ZoomOut], "ib-autin-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[dword_50C98C], "IB-selec-B", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_CastSpell], "ib-m1d-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_Rest], "ib-m2d-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_QuickReference], "ib-m3d-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Btn_GameSettings], "ib-m4d-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Bless], "isg-01-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Preservation], "isg-02-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_Hammerhands], "isg-03-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_PlayerBuff_PainReflection], "isg-04-b", 2);
      pUIAnim_WizardEye->uIconID = pIconsFrameTable->FindIcon("wizeyeB");
      pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnim_WizardEye->uIconID);
      pUIAnum_Torchlight->uIconID = pIconsFrameTable->FindIcon("torchB");
      pIconsFrameTable->InitializeAnimation((signed __int16)pUIAnum_Torchlight->uIconID);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uExitCancelTextureId], "ib-bcu-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50795C], "evtnpc-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507958], "fr_inven-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_Parchment], "parchment", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B4], "cornr_ll-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076B0], "cornr_lr-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076AC], "cornr_ul-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A8], "cornr_ur-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A4], "edge_btm-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_5076A0], "edge_lf-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_50769C], "edge_rt-b", 2);
      pIcons_LOD->ReloadTexture(&pIcons_LOD->pTextures[uTextureID_507698], "edge_top-b", 2);
      pIcons_LOD->ReloadTexture(pTexture_591428, "endcap-b", 2);
    }
    v3 = TargetColor(0, 0, 0xC8u);
    v5 = 255;
    v4 = 225;
    v6 = 255;
  }
  else assert(false);

  uGameUIFontMain = v3;
  uGameUIFontShadow = TargetColor(v5, v4, v6);
}

//----- (00423AEE) --------------------------------------------------------
void __cdecl reset_some_strus_flt_2Cs()
{
  float *v0; // eax@1
  signed int v1; // ecx@1
  signed int v2; // edx@1
  float *v3; // eax@3
  signed int v4; // edx@3
  float *v5; // eax@5
  signed int v6; // edx@5
  float *v7; // eax@7
  signed int v8; // edx@7
  float *v9; // eax@9

  v0 = &array_50AC10[0].flt_2C;
  v1 = 50;
  v2 = 50;
  do
  {
    *v0 = 0.0;
    v0 += 12;
    --v2;
  }
  while ( v2 );
  v3 = &array_50A2B0[0].flt_2C;
  v4 = 50;
  do
  {
    *v3 = 0.0;
    v3 += 12;
    --v4;
  }
  while ( v4 );
  v5 = &array_509950[0].flt_2C;
  v6 = 50;
  do
  {
    *v5 = 0.0;
    v5 += 12;
    --v6;
  }
  while ( v6 );
  v7 = &array_508FF0[0].flt_2C;
  v8 = 50;
  do
  {
    *v7 = 0.0;
    v7 += 12;
    --v8;
  }
  while ( v8 );
  v9 = &array_508690[0].flt_2C;
  do
  {
    *v9 = 0.0;
    v9 += 12;
    --v1;
  }
  while ( v1 );
}

//----- (00423B4A) --------------------------------------------------------
void __cdecl sub_423B4A()
{
  float *v0; // eax@1
  signed int v1; // ecx@1

  v0 = &array_507D30[0].flt_2C;
  v1 = 50;
  do
  {
    *v0 = 0.0;
    v0 += 12;
    --v1;
  }
  while ( v1 );
}

//----- (00423B5D) --------------------------------------------------------
int __fastcall sub_423B5D(unsigned int uFaceID)
{
  BLVFace *v1; // ebx@1
  Vec3_short_ *v2; // esi@1
  //int v3; // ST28_4@1
  __int16 v4; // ST2C_2@1
  //signed int v5; // esi@1
  //Vec3_short_ *v6; // eax@4
  //signed int v7; // edi@5
  //signed int v8; // eax@5
  //signed int i_; // ecx@10
  int v10; // eax@10
  int v11; // edx@11
  int v12; // ST28_4@12
  signed int v13; // edx@12
  signed __int64 v14; // qtt@12
  int *v15; // ebx@12
  int v16; // ST28_4@14
  signed int v17; // eax@14
  signed __int64 v18; // qtt@14
  signed int v19; // edx@15
  signed int v20; // edx@17
  signed int v21; // ebx@19
  signed int v22; // esi@20
  int v23; // edi@21
  int v24; // eax@21
  int v25; // eax@22
  int v26; // eax@22
  signed int v27; // ST30_4@24
  signed __int64 v28; // qtt@24
  int v29; // ST18_4@25
  int v30; // eax@26
  int v31; // eax@27
  int v32; // eax@27
  signed int v33; // ST30_4@29
  signed __int64 v34; // qtt@29
  int v35; // ST30_4@30
  signed int v36; // edi@31
  unsigned int v37; // eax@31
  bool v38; // edx@31
  int v39; // ecx@31
  int v40; // ecx@32
  int v41; // esi@32
  int v42; // eax@34
  signed int v43; // ebx@41
  unsigned int v44; // eax@41
  signed int v45; // ecx@42
  int v46; // esi@42
  int v47; // eax@44
  signed int v48; // edi@51
  unsigned int v49; // eax@51
  bool v50; // edx@51
  int v51; // ecx@51
  int v52; // ecx@52
  signed int v53; // esi@52
  int v54; // eax@54
  int v55; // ebx@61
  unsigned int v56; // eax@61
  signed int v57; // ecx@62
  int v58; // esi@62
  int v59; // eax@64
  char v61; // zf@72
  signed int v62; // edx@75
  int v63; // ecx@76
  int v64; // esi@76
  int v65; // ecx@83
  //signed int v66; // [sp+14h] [bp-14h]@3
  int v67; // [sp+14h] [bp-14h]@34
  int v68; // [sp+14h] [bp-14h]@44
  int v69; // [sp+14h] [bp-14h]@54
  int v70; // [sp+14h] [bp-14h]@64
  signed int v71; // [sp+14h] [bp-14h]@75
  bool thisa; // [sp+18h] [bp-10h]@9
  int thisb; // [sp+18h] [bp-10h]@12
  int thisc; // [sp+18h] [bp-10h]@20
  bool thisd; // [sp+18h] [bp-10h]@41
  bool thise; // [sp+18h] [bp-10h]@61
  int thisf; // [sp+18h] [bp-10h]@74
  signed int v79; // [sp+1Ch] [bp-Ch]@9
  int v80; // [sp+1Ch] [bp-Ch]@76
  bool v81; // [sp+20h] [bp-8h]@10
  bool v82; // [sp+20h] [bp-8h]@32
  bool v83; // [sp+20h] [bp-8h]@42
  bool v84; // [sp+20h] [bp-8h]@52
  bool v85; // [sp+20h] [bp-8h]@62
  //signed int i; // [sp+24h] [bp-4h]@9
  signed int ia; // [sp+24h] [bp-4h]@19
  signed int ib; // [sp+24h] [bp-4h]@31
  signed int ic; // [sp+24h] [bp-4h]@41
  signed int id; // [sp+24h] [bp-4h]@51
  signed int ie; // [sp+24h] [bp-4h]@61

  v1 = &pIndoor->pFaces[uFaceID];
  //this = pGame->pIndoorCameraD3D;
  v2 = &pIndoor->pVertices[v1->pVertexIDs[0]];
  //v3 = *(_DWORD *)&v2->x;
  v4 = v2->z;
  //v5 = 0;
  if ( v1->pFacePlane_old.vNormal.x * (v2->x - pBLVRenderParams->vPartyPos.x)
     + v1->pFacePlane_old.vNormal.y * (v2->y - pBLVRenderParams->vPartyPos.y)
     + v1->pFacePlane_old.vNormal.z * (v2->z - pBLVRenderParams->vPartyPos.z) < 0 )
  {
    dword_50B700 = 1;
  }
  else
  {
    dword_50B700 = 0;
    if ( !v1->Portal() )
      return 0;
  }
  //v66 = v1->uNumVertices;
  for (uint i = 0; i < v1->uNumVertices; ++i)
  {
      auto v6 = &pIndoor->pVertices[v1->pVertexIDs[i]];
      pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible(
        v6->x,
        v6->y,
        v6->z,
        &_50B924_view_transformed_xs[i],
        &_50B834_view_transformed_zs[i],
        &_50B744_view_transformed_ys[i],
        0);
  }

  //v7 = v1->uNumVertices;
  //v8 = 0;
  if (v1->uNumVertices <= 0)
    return 0;

  bool bFound = false;
  for (uint i = 0; i < v1->uNumVertices; ++i)
    if (_50B924_view_transformed_xs[i] >= 0x80000u)
    {
      bFound = true;
      break;
    }
  if (!bFound)
    return 0;

  v79 = 0;
  _50B924_view_transformed_xs[v1->uNumVertices] = _50B924_view_transformed_xs[0];
  _50B834_view_transformed_zs[v1->uNumVertices] = _50B834_view_transformed_zs[0];
  _50B744_view_transformed_ys[v1->uNumVertices] = _50B744_view_transformed_ys[0];
  thisa = _50B924_view_transformed_xs[0] >= (signed int)0x80000u;
  //int i = 1;
  for (uint i = 1; i <= v1->uNumVertices; ++i)
  {
      v10 = _50B924_view_transformed_xs[i];
      v81 = v10 >= (signed int)0x80000u;
      if ( thisa ^ v81 )
      {
        v11 = _50B924_view_transformed_xs[i - 1];
        if ( v10 >= (signed int)0x80000u )
        {
          v12 = v10 - v11;
          v13 = 0x80000 - v11;
          LODWORD(v14) = v13 << 16;
          HIDWORD(v14) = v13 >> 16;
          v15 = &_50B744_view_transformed_ys[i - 1];
          dword_50B828[v79] = ((unsigned __int64)((_50B834_view_transformed_zs[i] - _50B834_view_transformed_zs[i - 1]) * v14 / v12) >> 16) + _50B834_view_transformed_zs[i - 1];
          thisb = (unsigned __int64)((_50B744_view_transformed_ys[i] - _50B744_view_transformed_ys[i - 1]) * v14 / v12) >> 16;
        }
        else
        {
          v16 = v11 - v10;
          v17 = 0x80000 - v10;
          LODWORD(v18) = v17 << 16;
          HIDWORD(v18) = v17 >> 16;
          v15 = &_50B744_view_transformed_ys[i];
          dword_50B828[v79] = ((unsigned __int64)((_50B834_view_transformed_zs[i - 1] - _50B834_view_transformed_zs[i]) * v18 / v16) >> 16) + _50B834_view_transformed_zs[i];
          thisb = (unsigned __int64)((_50B744_view_transformed_ys[i - 1] - _50B744_view_transformed_ys[i]) * v18 / v16) >> 16;
        }
        v19 = v79++;
        //v7 = v66;
        dword_50B738[v19] = thisb + *v15;
        dword_50B918[v19] = 0x80000u;
      }
      if ( v81 )
      {
        v20 = v79++;
        dword_50B918[v20] = _50B924_view_transformed_xs[i];
        dword_50B828[v20] = _50B834_view_transformed_zs[i];
        dword_50B738[v20] = _50B744_view_transformed_ys[i];
      }
      //++i;
      thisa = v81;
  }
  v21 = v79;
  dword_50B918[v79] = dword_50B918[0];
  dword_50B828[v79] = dword_50B828[0];
  dword_50B738[v79] = dword_50B738[0];
  for (ia = 0; ia < v79; ++ia)
  {
    v22 = ia;
    thisc = abs(dword_50B918[ia]);
    if ( abs(dword_50B828[ia]) >> 13 <= thisc )
    {
      v27 = dword_50B828[v22];
      LODWORD(v28) = v27 << 16;
      HIDWORD(v28) = v27 >> 16;
      v26 = v28 / dword_50B918[v22];
      v23 = 0;
    }
    else
    {
      v23 = 0;
      v24 = 0;
      if ( dword_50B828[v22] >= 0 )
      {
        LOBYTE(v24) = dword_50B918[v22] >= 0;
        v26 = ((v24 - 1) & 0xFF800000) + 0x400000;
      }
      else
      {
        LOBYTE(v24) = dword_50B918[v22] >= 0;
        v25 = v24 - 1;
        v26 = (v25 & 0x800000) - 0x400000;
      }
    }
    v29 = dword_50B738[v22];
    dword_50BAF8_xs[v22] = v26;
    if ( abs(v29) >> 13 <= thisc )
    {
      v33 = dword_50B738[v22];
      LODWORD(v34) = v33 << 16;
      HIDWORD(v34) = v33 >> 16;
      v32 = v34 / dword_50B918[v22];
    }
    else
    {
      v30 = 0;
      if ( dword_50B738[v22] >= v23 )
      {
        LOBYTE(v30) = dword_50B918[v22] >= v23;
        v32 = ((v30 - 1) & 0xFF800000) + 0x400000;
      }
      else
      {
        LOBYTE(v30) = dword_50B918[v22] >= v23;
        v31 = v30 - 1;
        v32 = (v31 & 0x800000) - 0x400000;
      }
    }
    dword_50BA08_ys[v22] = v32;
    dword_50BAF8_xs[v22] = (unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)dword_50BAF8_xs[v22]) >> 16;
    v35 = (unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)dword_50BA08_ys[v22]) >> 16;
    dword_50BAF8_xs[v22] = pBLVRenderParams->uViewportCenterX - dword_50BAF8_xs[v22];
    dword_50BA08_ys[v22] = pBLVRenderParams->uViewportCenterY - v35;
  }
  v36 = 0;
  dword_50BAF8_xs[v21] = dword_50BAF8_xs[0];
  dword_50BA08_ys[v21] = dword_50BA08_ys[0];
  v37 = pBLVRenderParams->uViewportX;
  v38 = dword_50BAF8_xs[0] < (signed int)pBLVRenderParams->uViewportX;
  LOBYTE(v38) = dword_50BAF8_xs[0] >= (signed int)pBLVRenderParams->uViewportX;
  v39 = 1;
  ib = 1;
  if ( v79 < 1 )
    return 0;
  do
  {
    v40 = v39;
    v41 = dword_50BAF8_xs[v40];
    v82 = v41 >= (signed int)v37;
    if ( v38 ^ v82 )
    {
      if ( v41 >= (signed int)v37 )
      {
        v67 = (signed int)(v37 - dword_50BAF8_xs[v40 - 1]) * (signed __int64)(dword_50BA08_ys[v40] - dword_50BA08_ys[v40 - 1]) / (v41 - dword_50BAF8_xs[v40 - 1]);
        v42 = dword_50BA08_ys[v40 - 1];
      }
      else
      {
        v67 = (signed int)(v37 - v41) * (signed __int64)(dword_50BA08_ys[v40 - 1] - dword_50BA08_ys[v40]) / (dword_50BAF8_xs[v40 - 1] - v41);
        v42 = dword_50BA08_ys[v40];
      }
      dword_50B9FC_ys[v36] = v67 + v42;
      v37 = pBLVRenderParams->uViewportX;
      dword_50BAEC_xs[v36] = pBLVRenderParams->uViewportX;
      ++v36;
    }
    v38 = v82;
    if ( v82 )
    {
      dword_50BAEC_xs[v36] = dword_50BAF8_xs[v40];
      dword_50B9FC_ys[v36] = dword_50BA08_ys[v40];
      ++v36;
    }
    v39 = ib++ + 1;
  }
  while ( ib <= v79 );

  if (v36 < 1)
    return 0;

  v43 = 0;
  dword_50BAEC_xs[v36] = dword_50BAEC_xs[0];
  dword_50B9FC_ys[v36] = dword_50B9FC_ys[0];
  v44 = pBLVRenderParams->uViewportZ;
  thisd = dword_50BAEC_xs[0] <= (signed int)pBLVRenderParams->uViewportZ;
  ic = 1;

  do
  {
    v45 = ic;
    v46 = dword_50BAEC_xs[ic];
    v83 = v46 <= (signed int)v44;
    if ( thisd ^ v83 )
    {
      if ( v46 <= (signed int)v44 )
      {
        v68 = (signed int)(v44 - dword_50BAEC_xs[v45 - 1]) * (signed __int64)(dword_50B9FC_ys[v45] - dword_50B9FC_ys[v45 - 1]) / (v46 - dword_50BAEC_xs[v45 - 1]);
        v47 = dword_50B9FC_ys[v45 - 1];
      }
      else
      {
        v68 = (signed int)(v44 - v46) * (signed __int64)(dword_50B9FC_ys[v45 - 1] - dword_50B9FC_ys[v45]) / (dword_50BAEC_xs[v45 - 1] - v46);
        v47 = dword_50B9FC_ys[v45];
      }
      dword_50B9F0[v43] = v68 + v47;
      v44 = pBLVRenderParams->uViewportZ;
      dword_50BAE0[v43] = pBLVRenderParams->uViewportZ;
      ++v43;
    }
    if ( v83 )
    {
      dword_50BAE0[v43] = dword_50BAEC_xs[v45];
      dword_50B9F0[v43++] = dword_50B9FC_ys[v45];
    }
    ++ic;
    thisd = v83;
  }
  while ( ic <= v36 );

  if (v43 < 1)
    return 0;

  v48 = 0;
  dword_50BAE0[v43] = dword_50BAE0[0];
  dword_50B9F0[v43] = dword_50B9F0[0];
  v49 = pBLVRenderParams->uViewportY;
  v50 = dword_50B9F0[0] < (signed int)pBLVRenderParams->uViewportY;
  LOBYTE(v50) = dword_50B9F0[0] >= (signed int)pBLVRenderParams->uViewportY;
  v51 = 1;
  id = 1;
  do
  {
    v52 = v51;
    v53 = dword_50B9F0[v52];
    v84 = v53 >= (signed int)v49;
    if ( v50 ^ v84 )
    {
      if ( v53 >= (signed int)v49 )
      {
        v69 = (signed int)(v49 - dword_50B9F0[v52 - 1]) * (signed __int64)(dword_50BAE0[v52] - dword_50BAE0[v52 - 1]) / (v53 - dword_50B9F0[v52 - 1]);
        v54 = dword_50BAE0[v52 - 1];
      }
      else
      {
        v69 = (signed int)(v49 - v53) * (signed __int64)(dword_50BAE0[v52 - 1] - dword_50BAE0[v52]) / (dword_50B9F0[v52 - 1] - v53);
        v54 = dword_50BAE0[v52];
      }
      dword_50BAD4[v48] = v69 + v54;
      v49 = pBLVRenderParams->uViewportY;
      dword_50B9E4[v48] = pBLVRenderParams->uViewportY;
      ++v48;
    }
    v50 = v84;
    if ( v84 )
    {
      dword_50BAD4[v48] = dword_50BAE0[v52];
      dword_50B9E4[v48++] = dword_50B9F0[v52];
    }
    v51 = id++ + 1;
  }
  while ( id <= v43 );

  if (v48 < 1)
    return 0;

  v55 = 0;
  dword_50BAD4[v48] = dword_50BAD4[0];
  dword_50B9E4[v48] = dword_50B9E4[0];
  v56 = pBLVRenderParams->uViewportW;
  thise = dword_50B9E4[0] <= (signed int)pBLVRenderParams->uViewportW;
  ie = 1;
  do
  {
    v57 = ie;
    v58 = dword_50B9E4[ie];
    v85 = v58 <= (signed int)v56;
    if ( thise ^ v85 )
    {
      if ( v58 <= (signed int)v56 )
      {
        v70 = (signed int)(v56 - dword_50B9E4[v57 - 1]) * (signed __int64)(dword_50BAD4[v57] - dword_50BAD4[v57 - 1]) / (v58 - dword_50B9E4[v57 - 1]);
        v59 = dword_50BAD4[v57 - 1];
      }
      else
      {
        v70 = (signed int)(v56 - v58) * (signed __int64)(dword_50BAD4[v57 - 1] - dword_50BAD4[v57]) / (dword_50B9E4[v57 - 1] - v58);
        v59 = dword_50BAD4[v57];
      }
      _50BAC8_screen_space_x[v55] = v70 + v59;
      v56 = pBLVRenderParams->uViewportW;
      _50B9D8_screen_space_y[v55] = pBLVRenderParams->uViewportW;
      ++v55;
    }
    if ( v85 )
    {
      _50BAC8_screen_space_x[v55] = dword_50BAD4[v57];
      _50B9D8_screen_space_y[v55++] = dword_50B9E4[v57];
    }
    ++ie;
    thise = v85;
  }
  while ( ie <= v48 );

  if ( !v55 )
    return 0;
  v61 = pRenderer->pRenderD3D == 0;
  _50BAC8_screen_space_x[v55] = _50BAC8_screen_space_x[0];
  _50B9D8_screen_space_y[v55] = _50B9D8_screen_space_y[0];
  if ( v61 && v55 > 3 )
  {
    _50BAC8_screen_space_x[v55 + 1] = _50BAC8_screen_space_x[1];
    _50B9D8_screen_space_y[v55 + 1] = _50B9D8_screen_space_y[1];
    thisf = 2 * (dword_50B700 != 0) - 1;
    if ( v55 > 0 )
    {
      v62 = 1;
      v71 = 1;
      do
      {
        v63 = v62 - 1;
        v64 = v62 + 1;
        v80 = v62 + 1;
        if ( v62 - 1 >= v55 )
          v63 -= v55;
        if ( v62 >= v55 )
          v62 -= v55;
        if ( v64 >= v55 )
          v64 -= v55;
        if ( thisf
           * ((_50B9D8_screen_space_y[v64] - _50B9D8_screen_space_y[v63]) * (_50BAC8_screen_space_x[v62] - _50BAC8_screen_space_x[v63])
            - (_50B9D8_screen_space_y[v62] - _50B9D8_screen_space_y[v63]) * (_50BAC8_screen_space_x[v64] - _50BAC8_screen_space_x[v63])) < 0 )
        {
          v62 = v80;
          v71 = v80;
        }
        else
        {
          v62 = v71;
          v65 = v71;
          if ( v71 < v55 || (v65 = v71 - v55, v71 - v55 < v55) )
          {
            memcpy(&_50B9D8_screen_space_y[v65], &_50B9D8_screen_space_y[v65 + 1], 4 * ((unsigned int)(4 * (v55 - v65)) >> 2));
            memcpy(&_50BAC8_screen_space_x[v65], &_50BAC8_screen_space_x[v65 + 1], 4 * ((unsigned int)(4 * (v55 - v65)) >> 2));
          }
          --v55;
        }
      }
      while ( v62 - 1 < v55 );
    }
    _50BAC8_screen_space_x[v55] = _50BAC8_screen_space_x[0];
    _50B9D8_screen_space_y[v55] = _50B9D8_screen_space_y[0];
  }
  return v55;
}

//----- (00424579) --------------------------------------------------------
int __fastcall sub_424579(int uFaceID, stru320 *a2)
{
  __debugbreak();
  return 0;
  /*BLVFace *v2; // eax@1
  Vec3_short_ *v3; // ebx@1
  Vec3_short_ *v4; // esi@1
  unsigned int v5; // esi@3
  int v7; // ST1C_4@5
  int v8; // ST1C_4@5
  int v9; // ST1C_4@5
  int v10; // ST1C_4@5
  int v11; // esi@5
  int v12; // ST1C_4@5
  unsigned int v15; // ecx@8
  unsigned int v19; // ecx@13
  signed int v20; // ecx@16
  signed int result; // eax@20
  signed int v24; // edx@22
  unsigned int v25; // [sp+Ch] [bp-1Ch]@3
  float v26; // [sp+14h] [bp-14h]@3
  float v27; // [sp+1Ch] [bp-Ch]@3
  float v28; // [sp+20h] [bp-8h]@3
  signed int v29; // [sp+24h] [bp-4h]@3

  v2 = &pIndoor->pFaces[uFaceID];
  v3 = pIndoor->pVertices;
  v4 = &pIndoor->pVertices[*v2->pVertexIDs];
  if ( v2->pFacePlane_old.vNormal.x * ((signed __int16)*(int *)&v4->x - pBLVRenderParams->vPartyPos.x)
     + v2->pFacePlane_old.vNormal.y * ((signed __int16)(*(int *)&v4->x >> 16) - pBLVRenderParams->vPartyPos.y)
     + v2->pFacePlane_old.vNormal.z * (v4->z - pBLVRenderParams->vPartyPos.z) < 0 )
  {
    dword_50B700 = 1;
  }
  else
  {
    dword_50B700 = 0;
    if ( !(v2->uAttributes & 1) )
      return 0;
  }
  v29 = 0;
  v5 = v2->uNumVertices;
  __asm { fld     pBLVRenderParams->fCosineY }
  v28 = pBLVRenderParams->fSineY;
  v26 = pBLVRenderParams->fCosineNegX;
  v27 = pBLVRenderParams->fSineNegX;
  v25 = v5;
  if ( (signed int)v5 > 0 )
  {
    _ECX = (char *)&array_50AC10[0].vWorldPosition.z;
    do
    {
      v7 = v3[v2->pVertexIDs[v29]].x;
      __asm
      {
        fild    [ebp+var_10]
        fstp    dword ptr [ecx-8]
      }
      v8 = v3[v2->pVertexIDs[v29]].y;
      __asm
      {
        fild    [ebp+var_10]
        fstp    dword ptr [ecx-4]
      }
      v9 = v3[v2->pVertexIDs[v29]].z;
      __asm
      {
        fild    [ebp+var_10]
        fstp    dword ptr [ecx]
      }
      _ECX += 48;
      v10 = a2->pDeltaUV[0] + v2->pVertexUIDs[v29];
      __asm
      {
        fild    [ebp+var_10]
        fstp    dword ptr [ecx-14h]
      }
      v11 = a2->pDeltaUV[1] + v2->pVertexVIDs[v29++];
      v12 = v11;
      v5 = v25;
      __asm
      {
        fild    [ebp+var_10]
        fstp    dword ptr [ecx-10h]
      }
    }
    while ( v29 < (signed int)v25 );
  }
  _EDX = (char *)&array_50AC10[0].vWorldViewPosition;
  if ( pBLVRenderParams->sPartyRotX )
  {
    if ( (signed int)v5 > 0 )
    {
      __asm
      {
        fild    pBLVRenderParams->vPartyPos.x
        fild    pBLVRenderParams->vPartyPos.y
        fild    pBLVRenderParams->vPartyPos.z
      }
      _EAX = (char *)&array_50AC10[0].vWorldPosition.z;
      v15 = v5;
      do
      {
        __asm
        {
          fld     dword ptr [eax-8]
          fsub    st, st(3)
          fld     dword ptr [eax-4]
          fsub    st, st(3)
          fld     st(1)
          fmul    st, st(6)
          fld     st(1)
          fmul    [ebp+var_8]
          fsubp   st(1), st
          fstp    [ebp+var_4]
          fld     dword ptr [eax]
          fsub    st, st(3)
        }
        _EAX += 48;
        --v15;
        __asm
        {
          fstp    [ebp+var_10]
          fld     [ebp+var_4]
          fmul    [ebp+var_14]
          fld     [ebp+var_10]
          fmul    [ebp+var_C]
          fsubp   st(1), st
          fstp    dword ptr [eax-2Ch]
          fld     st(1)
          fmul    [ebp+var_8]
          fld     st(1)
          fmul    st, st(7)
          faddp   st(1), st
          fstp    dword ptr [eax-28h]
          fstp    st
          fstp    st
          fld     [ebp+var_4]
          fmul    [ebp+var_C]
          fld     [ebp+var_10]
          fmul    [ebp+var_14]
          faddp   st(1), st
          fstp    dword ptr [eax-24h]
        }
      }
      while ( v15 );
LABEL_15:
      __asm
      {
        fstp    st
        fstp    st
        fstp    st
      }
      goto LABEL_16;
    }
  }
  else
  {
    if ( (signed int)v5 > 0 )
    {
      __asm
      {
        fild    pBLVRenderParams->vPartyPos.x
        fild    pBLVRenderParams->vPartyPos.y
        fild    pBLVRenderParams->vPartyPos.z
      }
      _EAX = (char *)&array_50AC10[0].vWorldViewPosition;
      v19 = v5;
      do
      {
        __asm
        {
          fld     dword ptr [eax-0Ch]
          fsub    st, st(3)
          fld     dword ptr [eax-8]
          fsub    st, st(3)
          fld     st(1)
          fmul    st, st(6)
          fld     st(1)
          fmul    [ebp+var_8]
          fsubp   st(1), st
          fstp    dword ptr [eax]
          fld     st(1)
          fmul    [ebp+var_8]
          fld     st(1)
          fmul    st, st(7)
        }
        _EAX += 48;
        --v19;
        __asm
        {
          faddp   st(1), st
          fstp    dword ptr [eax-2Ch]
          fstp    st
          fstp    st
          fld     dword ptr [eax-34h]
          fsub    st, st(1)
          fstp    dword ptr [eax-28h]
        }
      }
      while ( v19 );
      goto LABEL_15;
    }
  }
LABEL_16:
  v20 = 0;
  __asm { fstp    st }
  if ( (signed int)v5 <= 0 )
    return 0;
  do
  {
    __asm
    {
      fld     dword ptr [edx]
      fcomp   ds:flt_4D8524
      fnstsw  ax
    }
    if ( !(HIBYTE(_AX) & 1) )
      break;
    ++v20;
    _EDX += 48;
  }
  while ( v20 < (signed int)v5 );
  if ( v20 >= (signed int)v5 )
    return 0;
  result = sr_424CD7(v5);
  if ( result > 0 )
  {
    __asm { fild    pBLVRenderParams->field_40 }
    _ECX = (char *)&array_507D30[0].vWorldViewPosition;
    v24 = result;
    __asm
    {
      fmul    ds:flt_4D84A4
      fild    pBLVRenderParams->uViewportCenterX
      fild    pBLVRenderParams->uViewportCenterY
    }
    do
    {
      __asm
      {
        fld1
        fdiv    dword ptr [ecx]
      }
      _ECX += 48;
      --v24;
      __asm
      {
        fld     st
        fmul    dword ptr [ecx-2Ch]
        fmul    st, st(4)
        fsubr   st, st(3)
        fstp    dword ptr [ecx-24h]
        fmul    dword ptr [ecx-28h]
        fmul    st, st(3)
        fsubr   st, st(1)
        fstp    dword ptr [ecx-20h]
      }
    }
    while ( v24 );
    __asm
    {
      fstp    st
      fstp    st
      fstp    st
    }
  }
  memcpy(&array_507D30[result], array_507D30, sizeof(array_507D30[result]));
  return result;*/
}

//----- (00424829) --------------------------------------------------------
bool sub_424829(int a1, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int a4)
{
  int v4; // edi@1
  BspRenderer_stru2 *v5; // ebx@1
  int v6; // eax@3
  int v7; // esi@5
  int v8; // edx@5
  int v9; // ecx@6
  int v10; // eax@12
  int v11; // edi@13
  int v12; // edx@18
  int v13; // eax@22
  int v14; // edi@28
  int v15; // ecx@29
  int v16; // edi@30
  int v17; // edx@35
  int v18; // eax@39
  int v19; // eax@44
  int v20; // ecx@44
  int v21; // edi@45
  int v22; // edi@46
  __int16 *v23; // ecx@47
  int v24; // edx@48
  int v25; // eax@50
  int v26; // eax@55
  signed int v27; // edi@55
  int v28; // edx@56
  int v29; // edx@57
  int v30; // eax@59
  int v31; // eax@64
  signed int v32; // edi@64
  int v33; // edx@65
  __int16 *v34; // eax@66
  __int16 v35; // dx@66
  __int16 v36; // dx@67
  __int16 v37; // di@67
  __int16 v38; // dx@67
  BspRenderer_stru2 *v39; // ecx@69
  int v40; // edx@69
  int v41; // edi@70
  __int16 *v42; // eax@76
  __int16 *v43; // eax@81
  __int16 *v45; // eax@87
  int v46; // edx@87
  __int16 v47; // cx@88
  int v48; // eax@93
  int v49; // esi@93
  __int16 *v50; // ecx@94
  int v51; // eax@95
  int v52; // eax@97
  int v53; // [sp+Ch] [bp-34h]@44
  int v54; // [sp+10h] [bp-30h]@0
  int v55; // [sp+14h] [bp-2Ch]@12
  __int16 *v56; // [sp+14h] [bp-2Ch]@47
  __int16 *v57; // [sp+14h] [bp-2Ch]@76
  __int16 *v58; // [sp+14h] [bp-2Ch]@81
  __int16 *v59; // [sp+14h] [bp-2Ch]@87
  BspRenderer_stru2 *v60; // [sp+18h] [bp-28h]@1
  int v61; // [sp+1Ch] [bp-24h]@29
  int v62; // [sp+20h] [bp-20h]@0
  signed int v63; // [sp+24h] [bp-1Ch]@3
  signed int v64; // [sp+28h] [bp-18h]@3
  int v65; // [sp+2Ch] [bp-14h]@5
  int v66; // [sp+2Ch] [bp-14h]@39
  int v67; // [sp+30h] [bp-10h]@22
  int v68; // [sp+34h] [bp-Ch]@12
  int v69; // [sp+34h] [bp-Ch]@29
  int v70; // [sp+34h] [bp-Ch]@46
  int v71; // [sp+34h] [bp-Ch]@75
  int v72; // [sp+34h] [bp-Ch]@80
  int v73; // [sp+38h] [bp-8h]@11
  int v74; // [sp+3Ch] [bp-4h]@1
  int a3a; // [sp+48h] [bp+8h]@76
  int a3b; // [sp+48h] [bp+8h]@87

  v4 = a1;
  v5 = a2;
  v74 = a1;
  v60 = a2;
  if ( !a1
    || (!dword_50B700 ? (v64 = -1, v6 = 1, v63 = 1) : (v6 = 1, v63 = -1, v64 = 1),
        v7 = _50B9D8_screen_space_y[0],
        v65 = 0,
        v8 = _50B9D8_screen_space_y[0],
        a1 <= v6) )
    return 0;
  do
  {
    v9 = _50B9D8_screen_space_y[v6];
    if ( v9 >= v7 )
    {
      if ( v9 > v8 )
        v8 = _50B9D8_screen_space_y[v6];
    }
    else
    {
      v65 = v6;
      v7 = _50B9D8_screen_space_y[v6];
    }
    ++v6;
  }
  while ( v6 < v4 );
  v73 = v8;
  if ( v8 == v7 )
    return 0;
  v10 = v65;
  v68 = 0;
  v5->_viewport_space_y = v7;
  v5->_viewport_space_w = v8;
  v55 = v65;
  if ( v4 > 0 )
  {
    v11 = v65;
    do
    {
      v10 += v64;
      if ( v10 < v74 )
      {
        if ( v10 < 0 )
          v10 += v74;
      }
      else
      {
        v10 -= v74;
      }
      v12 = _50B9D8_screen_space_y[v10];
      if ( v12 <= _50B9D8_screen_space_y[v11] )
      {
        v55 = v10;
        v11 = v10;
      }
      if ( v12 == v73 )
        break;
      ++v68;
    }
    while ( v68 < v74 );
  }
  v13 = v55 + v64;
  v67 = v55 + v64;
  if ( v55 + v64 < v74 )
  {
    if ( v13 >= 0 )
      goto LABEL_27;
    v13 += v74;
  }
  else
  {
    v13 -= v74;
  }
  v67 = v13;
LABEL_27:
  if ( _50B9D8_screen_space_y[v13] != _50B9D8_screen_space_y[v55] )
  {
    v14 = _50BAC8_screen_space_x[v55];
    v62 = v14 << 16;
    v54 = ((_50BAC8_screen_space_x[v13] - v14) << 16) / (_50B9D8_screen_space_y[v13] - _50B9D8_screen_space_y[v55]);
    v5->array_18[v7] = LOWORD(_50BAC8_screen_space_x[v55]);
  }
  v15 = v65;
  v69 = 0;
  v61 = v65;
  if ( v74 > 0 )
  {
    v16 = v65;
    do
    {
      v15 += v63;
      if ( v15 < v74 )
      {
        if ( v15 < 0 )
          v15 += v74;
      }
      else
      {
        v15 -= v74;
      }
      v17 = _50B9D8_screen_space_y[v15];
      if ( v17 <= _50B9D8_screen_space_y[v16] )
      {
        v61 = v15;
        v16 = v15;
      }
      if ( v17 == v73 )
        break;
      ++v69;
    }
    while ( v69 < v74 );
  }
  v18 = v63 + v61;
  v66 = v63 + v61;
  if ( v63 + v61 < v74 )
  {
    if ( v18 >= 0 )
      goto LABEL_44;
    v18 += v74;
  }
  else
  {
    v18 -= v74;
  }
  v66 = v18;
LABEL_44:
  v19 = v18;
  v20 = v61;
  v53 = _50B9D8_screen_space_y[v19] - _50B9D8_screen_space_y[v61];
  if ( _50B9D8_screen_space_y[v19] != _50B9D8_screen_space_y[v61] )
  {
    v21 = _50BAC8_screen_space_x[v20];
    v5 = v60;
    v61 = v21 << 16;
    v53 = ((_50BAC8_screen_space_x[v19] - v21) << 16) / v53;
    v60->array_3D8[v73] = LOWORD(_50BAC8_screen_space_x[v20]);
  }
  v22 = v7;
  v70 = v7;
  if ( v7 <= v73 )
  {
    v56 = &v5->array_3D8[v7];
    v23 = &v5->array_18[v7];
    do
    {
      v24 = v67;
      if ( v22 < _50B9D8_screen_space_y[v67] || v22 == v73 )
        goto LABEL_57;
      v25 = v64 + v67;
      v67 = v25;
      if ( v25 < v74 )
      {
        if ( v25 >= 0 )
          goto LABEL_55;
        v25 += v74;
      }
      else
      {
        v25 -= v74;
      }
      v67 = v25;
LABEL_55:
      v26 = v25;
      v27 = _50B9D8_screen_space_y[v26] - _50B9D8_screen_space_y[v24];
      if ( _50B9D8_screen_space_y[v26] - _50B9D8_screen_space_y[v24] > 0 )
      {
        v28 = _50BAC8_screen_space_x[v24];
        v54 = ((_50BAC8_screen_space_x[v26] - v28) << 16) / v27;
        v62 = v28 << 16;
      }
LABEL_57:
      v29 = v66;
      if ( v70 >= _50B9D8_screen_space_y[v66] && v70 != v73 )
      {
        v30 = v63 + v66;
        v66 += v63;
        if ( v66 >= v74 )
        {
          v30 -= v74;
          goto LABEL_63;
        }
        if ( v30 < 0 )
        {
          v30 += v74;
LABEL_63:
          v66 = v30;
        }
        v31 = v30;
        v32 = _50B9D8_screen_space_y[v31] - _50B9D8_screen_space_y[v29];
        if ( _50B9D8_screen_space_y[v31] - _50B9D8_screen_space_y[v29] > 0 )
        {
          v33 = _50BAC8_screen_space_x[v29];
          v53 = ((_50BAC8_screen_space_x[v31] - v33) << 16) / v32;
          v61 = v33 << 16;
        }
      }
      *(__int16 *)((char *)v56 + (int)(char *)v5->array_18 - (char *)v5->array_3D8) = HIWORD(v62);
      *v56 = HIWORD(v61);
      v34 = v23 + 480;
      v35 = v23[480];
      if ( *v23 > v35 )
      {
        v36 = *v23 ^ v35;
        v37 = *v34;
        *v23 = v36;
        v38 = v37 ^ v36;
        *v23 ^= v38;
        *v34 = v38;
      }
      ++v56;
      v62 += v54;
      v22 = v70 + 1;
      v61 += v53;
      ++v23;
      ++v70;
    }
    while ( v70 <= v73 );
  }
  v39 = a3;
  v40 = v73;
  if ( v73 < a3->_viewport_space_y || (v41 = a3->_viewport_space_w, v7 > v41) )
    return 0;
  if ( v7 < a3->_viewport_space_y )
    v7 = a3->_viewport_space_y;
  if ( v73 > v41 )
  {
    v40 = a3->_viewport_space_w;
    v73 = a3->_viewport_space_w;
  }
  v71 = v7;
  if ( v7 <= v40 )
  {
    a3a = (char *)v5 - (char *)a3;
    v57 = &v5->array_18[v7];
    v42 = &v39->array_3D8[v7];
    do
    {
      if ( *(__int16 *)((char *)v42 + a3a) >= *(v42 - 480) && *v57 <= *v42 )
        break;
      ++v57;
      ++v7;
      ++v71;
      ++v42;
    }
    while ( v71 <= v40 );
  }
  v72 = v40;
  if ( v40 < v7 )
    return 0;
  v58 = &v5->array_18[v40];
  v43 = &v39->array_3D8[v40];
  do
  {
    if ( *(__int16 *)((char *)v43 + (int)(char *)v5 - (char *)v39) >= *(v43 - 480) && *v58 <= *v43 )
      break;
    --v58;
    --v40;
    --v72;
    --v43;
    v73 = v40;
  }
  while ( v72 >= v7 );
  if ( v7 >= v40 )
    return 0;
  a3b = (char *)v39 - (char *)v5;
  v59 = &v39->array_3D8[v7];
  v45 = &v5->array_18[v7];
  v46 = v73 - v7 + 1;
  do
  {
    v47 = *(__int16 *)((char *)v45 + a3b);
    if ( *v45 < v47 )
      *v45 = v47;
    if ( v45[480] > *v59 )
      v45[480] = *v59;
    ++v59;
    ++v45;
    --v46;
  }
  while ( v46 );
  v5->_viewport_space_y = v7;
  v5->_viewport_space_w = v73;
  v5->field_8 = v5->array_18[v7];
  v48 = v5->array_3D8[v7];
  v5->field_10 = v7;
  v5->field_14 = v7;
  v49 = v7 + 1;
  v5->field_C = v48;
  if ( v49 <= v73 )
  {
    v50 = &v5->array_3D8[v49];
    do
    {
      v51 = *(v50 - 480);
      if ( v51 < v5->field_8 )
      {
        v5->field_8 = v51;
        v5->field_10 = v49;
      }
      v52 = *v50;
      if ( v52 > v5->field_C )
      {
        v5->field_C = v52;
        v5->field_14 = v49;
      }
      ++v49;
      ++v50;
    }
    while ( v49 <= v73 );
  }
  return 1;
}
// 50B700: using guessed type int dword_50B700;

//----- (00424CD7) --------------------------------------------------------
signed int __fastcall sr_424CD7(unsigned int uVertexID)
{
  unsigned int v1; // edx@1
  signed int v2; // edi@1
  char *v3; // esi@4
  char *v4; // ecx@4
  unsigned int v5; // eax@4
  char *v6; // edx@4
  double v7; // st6@10
  double v8; // st5@10
  double v9; // st6@11
  unsigned __int8 v10; // c2@15
  unsigned __int8 v11; // c3@15
  RenderVertexSoft *v12; // edi@22
  char *v13; // eax@22
  double v14; // st6@22
  signed int result; // eax@24
  unsigned int v16; // [sp+8h] [bp-28h]@4
  bool v17; // [sp+Ch] [bp-24h]@6
  char *v18; // [sp+10h] [bp-20h]@4
  char *v19; // [sp+14h] [bp-1Ch]@4
  signed int v20; // [sp+18h] [bp-18h]@1
  RenderVertexSoft *v21; // [sp+1Ch] [bp-14h]@4
  char *v22; // [sp+20h] [bp-10h]@4
  char *v23; // [sp+24h] [bp-Ch]@4
  char *v24; // [sp+28h] [bp-8h]@4
  char *v25; // [sp+2Ch] [bp-4h]@4

  v1 = uVertexID;
  memcpy(&array_50AC10[uVertexID], array_50AC10, sizeof(array_50AC10[uVertexID]));
  v2 = 0;
  v20 = 0;
  if ( array_50AC10[0].vWorldViewPosition.x >= 8.0 )
    v2 = 1;
  if ( (signed int)(uVertexID + 1) <= 1 )
    return 0;
  v3 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v4 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v5 = v1;
  v23 = (char *)&array_507D30[0]._rhw;
  v21 = array_507D30;
  v18 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v19 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v22 = (char *)&array_507D30[0].vWorldViewPosition;
  v24 = (char *)&array_507D30[0].v;
  v25 = (char *)&array_507D30[0].u;
  v6 = (char *)&array_50AC10[0].v;
  v16 = v5;
  do
  {
    v17 = *((float *)v6 + 5) >= 8.0;
    if ( v2 != v17 )
    {
      if ( v17 )
      {
        v7 = (8.0 - *((float *)v6 - 7)) / (*((float *)v6 + 5) - *((float *)v6 - 7));
        *(float *)v4 = (*((float *)v6 + 6) - *((float *)v6 - 6)) * v7 + *((float *)v6 - 6);
        *(float *)v3 = (*((float *)v6 + 7) - *((float *)v6 - 5)) * v7 + *((float *)v6 - 5);
        *(float *)v25 = (*((float *)v6 + 11) - *((float *)v6 - 1)) * v7 + *((float *)v6 - 1);
        v8 = (*((float *)v6 + 12) - *(float *)v6) * v7 + *(float *)v6;
      }
      else
      {
        v9 = (8.0 - *((float *)v6 + 5)) / (*((float *)v6 - 7) - *((float *)v6 + 5));
        *(float *)v4 = (*((float *)v6 - 6) - *((float *)v6 + 6)) * v9 + *((float *)v6 + 6);
        *(float *)v3 = (*((float *)v6 - 5) - *((float *)v6 + 7)) * v9 + *((float *)v6 + 7);
        *(float *)v25 = (*((float *)v6 - 1) - *((float *)v6 + 11)) * v9 + *((float *)v6 + 11);
        v8 = (*(float *)v6 - *((float *)v6 + 12)) * v9 + *((float *)v6 + 12);
      }
      *(float *)v24 = v8;
      *(float *)v22 = 8.0;
      *(int *)v23 = 0x3E000000u;
      if ( v2 )
      {
        if ( 8.0 == *((float *)v6 - 7) && *(float *)v4 == *((float *)v6 - 6) )
        {
          v10 = 0;
          v11 = *(float *)v3 == *((float *)v6 - 5);
          goto LABEL_19;
        }
      }
      else
      {
        if ( 8.0 == *((float *)v6 + 5) && *(float *)v4 == *((float *)v6 + 6) )
        {
          v10 = 0;
          v11 = *(float *)v3 == *((float *)v6 + 7);
LABEL_19:
          if ( v11 | v10 )
            goto LABEL_21;
          goto LABEL_20;
        }
      }
LABEL_20:
      ++v21;
      v22 += 48;
      v24 += 48;
      v25 += 48;
      v4 += 48;
      v3 += 48;
      ++v20;
      v23 += 48;
      v19 = v4;
      v18 = v3;
    }
LABEL_21:
    if ( v17 )
    {
      v12 = v21;
      v13 = v23;
      v19 += 48;
      v18 += 48;
      v14 = 1.0 / (*((float *)v6 + 5) + 0.0000001);
      ++v20;
      v25 += 48;
      v24 += 48;
      v22 += 48;
      ++v21;
      v23 += 48;
      memcpy(v12, v6 + 8, 0x30u);
      v4 = v19;
      v3 = v18;
      *(float *)v13 = v14;
    }
    v2 = v17;
    v6 += 48;
    --v16;
  }
  while ( v16 );
  result = v20;
  if ( v20 < 3 )
    return 0;
  return result;
}