changeset 973:ec7568e13b24

Minor code cleaning.
author Nomad
date Wed, 08 May 2013 21:37:12 +0200
parents c8a0f6d89c70
children ac85898f5903
files Mouse.cpp Player.cpp Render.cpp Render.h Texture.cpp UIBooks.cpp mm7_3.cpp mm7_4.cpp mm7_5.cpp
diffstat 9 files changed, 93 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/Mouse.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/Mouse.cpp	Wed May 08 21:37:12 2013 +0200
@@ -254,8 +254,8 @@
 //----- (00469C0D) --------------------------------------------------------
 void *Mouse::DoAllocCursorMem()
 {
-  return malloc(4 * (this->uCursorTextureID != -1 ? pIcons_LOD->pTextures[this->uCursorTextureID].uTextureWidth : 24)
-                  * (this->uCursorTextureID != -1 ? pIcons_LOD->pTextures[this->uCursorTextureID].uTextureHeight : 26));
+  auto tex = pIcons_LOD->GetTexture(uCursorTextureID);
+  return malloc(4 * tex->uTextureWidth * tex->uTextureHeight);
 }
 
 //----- (00469C39) --------------------------------------------------------
--- a/Player.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/Player.cpp	Wed May 08 21:37:12 2013 +0200
@@ -1360,20 +1360,18 @@
 //----- (00492528) --------------------------------------------------------
 bool Player::CanFitItem(unsigned int uSlot, unsigned int uItemID)
 {
-  unsigned int v3; // eax@1
+  //unsigned int v3; // eax@1
   Texture *v4; // esi@1
   unsigned int v5; // ebx@1
   signed int v6; // edi@5
   int *v7; // ecx@6
   signed int v8; // edx@7
   int *v9; // eax@8
-  Player *v11; // [sp+Ch] [bp-4h]@1
+  //Player *v11; // [sp+Ch] [bp-4h]@1
   unsigned int uItemIDa; // [sp+1Ch] [bp+Ch]@1
 
-  v11 = this;
-  v3 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-  v4 = (Texture *)(v3 != -1 ? &pIcons_LOD->pTextures[v3] : 0);
-  v5 = GetSizeInInventorySlots(v3 != -1 ? pIcons_LOD->pTextures[v3].uTextureWidth : 24);
+  v4 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+  v5 = GetSizeInInventorySlots(v4->uTextureWidth);
   uItemIDa = GetSizeInInventorySlots(v4->uTextureHeight);
   if ( !areWeLoadingTexture )
   {
@@ -1385,7 +1383,7 @@
     v6 = 0;
     if ( (signed int)uItemIDa <= 0 )
       return 1;
-    v7 = &v11->pInventoryIndices[uSlot];
+    v7 = &pInventoryIndices[uSlot];
     while ( 1 )
     {
       v8 = 0;
@@ -1435,7 +1433,7 @@
   ItemGen *v4; // eax@1
   int result; // eax@8
   unsigned int v6; // ebx@10
-  unsigned int v7; // eax@10
+  //unsigned int v7; // eax@10
   Texture *v8; // esi@10
   void *v9; // esi@13
   unsigned int v10; // [sp+0h] [bp-Ch]@10
@@ -1467,9 +1465,8 @@
   else
   {
     v6 = uItemID;
-    v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-    v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0);
-    v10 = GetSizeInInventorySlots(v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
+    v8 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+    v10 = GetSizeInInventorySlots(v8->uTextureWidth);
     uItemIDa = GetSizeInInventorySlots(v8->uTextureHeight);
     if ( !areWeLoadingTexture )
     {
@@ -1523,6 +1520,8 @@
   char *v5; // eax@6
   char *v6; // esi@6
 
+  __debugbreak(); // sub is definetly broken
+
   v2 = 0;
   v3 = this->pInventoryItems;
   while ( v3->uItemID )
@@ -1647,7 +1646,7 @@
   signed int v3; // ebx@1
   ItemGen *v4; // eax@1
   int result; // eax@6
-  unsigned int v6; // eax@7
+  //unsigned int v6; // eax@7
   Texture *v7; // esi@7
   unsigned int v8; // edx@9
   void *v9; // esi@10
@@ -1675,11 +1674,8 @@
   }
   else
   {
-    v6 = pIcons_LOD->LoadTexture(
-           pItemsTable->pItems[Src->uItemID].pIconName,
-           TEXTURE_16BIT_PALETTE);
-    v7 = (Texture *)(v6 != -1 ? (int)&pIcons_LOD->pTextures[v6] : 0);
-    v10 = GetSizeInInventorySlots(v6 != -1 ? pIcons_LOD->pTextures[v6].uTextureWidth : 24);
+    v7 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[Src->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+    v10 = GetSizeInInventorySlots(v7->uTextureWidth);
     v11 = GetSizeInInventorySlots(v7->uTextureHeight);
     if ( !areWeLoadingTexture )
     {
@@ -1711,17 +1707,15 @@
 //----- (0049298B) --------------------------------------------------------
 bool Player::_49298B(ItemGen *a2, int a3, int a4)
 {
-  Player *v4; // ebx@1
-  unsigned int v5; // eax@1
+  //Player *v4; // ebx@1
+  //unsigned int v5; // eax@1
   Texture *v6; // esi@1
   void *v7; // esi@4
   unsigned int v9; // [sp+Ch] [bp-4h]@1
   unsigned int a2a; // [sp+18h] [bp+8h]@1
 
-  v4 = this;
-  v5 = pIcons_LOD->LoadTexture(pItemsTable->pItems[a2->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
-  v6 = (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0);
-  v9 = GetSizeInInventorySlots(v5 != -1 ? pIcons_LOD->pTextures[v5].uTextureWidth : 24);
+  v6 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[a2->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
+  v9 = GetSizeInInventorySlots(v6->uTextureWidth);
   a2a = GetSizeInInventorySlots(v6->uTextureHeight);
   if ( !areWeLoadingTexture )
   {
@@ -1730,7 +1724,7 @@
   }
   if ( (signed int)a2a > 0 )
   {
-    v7 = &v4->pInventoryIndices[a4];
+    v7 = &pInventoryIndices[a4];
     do
     {
       if ( (signed int)v9 > 0 )
@@ -1740,7 +1734,7 @@
     }
     while ( a2a );
   }
-  v4->pInventoryIndices[a4] = a3 + 1;
+  pInventoryIndices[a4] = a3 + 1;
   return 1;
 }
 
@@ -1752,7 +1746,7 @@
   int *pIndices; // edi@1
   ItemGen *v3; // ecx@1
   unsigned int v4; // esi@1
-  unsigned int v5; // eax@1
+  //unsigned int v5; // eax@1
   Texture *v6; // esi@1
   unsigned int result; // eax@1
   unsigned int v8; // ebp@1
@@ -1763,9 +1757,8 @@
   v3 = &this->pInventoryItems[*pIndices-1];
   v4 = v3->uItemID;
   v3->Reset();
-  v5 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4].pIconName, TEXTURE_16BIT_PALETTE);
-  v6 = (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0);
-  uSlota = GetSizeInInventorySlots(v5 != -1 ? pIcons_LOD->pTextures[v5].uTextureWidth : 24);
+  v6 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[v4].pIconName, TEXTURE_16BIT_PALETTE);
+  uSlota = GetSizeInInventorySlots(v6->uTextureWidth);
   result = GetSizeInInventorySlots(v6->uTextureHeight);
   v8 = result;
   if ( !areWeLoadingTexture )
@@ -2380,7 +2373,7 @@
   unsigned int v3; // ecx@4
   signed int v4; // edx@4
   char *v5; // eax@8
-  unsigned int v6; // eax@10
+  //unsigned int v6; // eax@10
   Texture *v7; // ebx@10
   signed int v8; // esi@10
   Player *v9; // edi@11
@@ -2422,8 +2415,7 @@
   v5 = pItemsTable->pItems[v2].pIconName;
   if ( v5 )
   {
-    v6 = pIcons_LOD->LoadTexture(v5, TEXTURE_16BIT_PALETTE);
-    v7 = (Texture *)(v6 != -1 ? &pIcons_LOD->pTextures[v6] : 0);
+    v7 = pIcons_LOD->LoadTexturePtr(v5, TEXTURE_16BIT_PALETTE);
     v21 = areWeLoadingTexture;
     v8 = 0;
     while ( 1 )
--- a/Render.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/Render.cpp	Wed May 08 21:37:12 2013 +0200
@@ -208,7 +208,7 @@
 }
 
 //----- (00487389) --------------------------------------------------------
-__int16 Render::ExecOutdoorDrawSW()
+void Render::ExecOutdoorDrawSW()
 {
   unsigned __int16 *v0; // ebx@1
   unsigned int v1; // esi@1
@@ -227,7 +227,7 @@
   int v14; // ecx@37
   int v15; // eax@40
   Texture *v16; // ebp@51
-  unsigned int v17; // eax@51
+  //unsigned int v17; // eax@51
   int v18; // eax@54
   char v19; // al@56
   unsigned int v20; // eax@57
@@ -315,8 +315,7 @@
                     while ( 1 )
                     {
                       v16 = v4->pTexture;
-                      v17 = pBitmaps_LOD->LoadTexture("wtrtyl");
-                      v4->pTexture = (Texture *)(v17 != -1 ? (int)&pBitmaps_LOD->pTextures[v17] : 0);
+                      v4->pTexture = pBitmaps_LOD->LoadTexturePtr("wtrtyl");
                       if ( pOutdoorCamera->outdoor_no_wavy_water )
                         sr_sub_48408A_prolly_odm_water_no_waves(v3);
                       else
@@ -549,12 +548,19 @@
   }
   v9 = pOutdoorCamera->uNumSpans;
   unnamed_6BE060[0] = pOutdoorCamera->uNumSpans;
-  if ( pOutdoorCamera->numStru148s >= 1999
-    || (array_77EC08[1999]._48607B(&stru_8019C8),
-        array_77EC08[1999].ptr_38->_48694B(),
-        v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uMainTile_BitmapID],
-        (array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uMainTile_BitmapID != -1 ? (int)v2 : 0)) == 0) )
-    return (signed __int16)v2;
+  if (pOutdoorCamera->numStru148s >= 1999)
+    return;
+
+  array_77EC08[1999]._48607B(&stru_8019C8);
+  array_77EC08[1999].ptr_38->_48694B();
+
+  if (pOutdoor->uMainTile_BitmapID == -1)
+  {
+    array_77EC08[1999].pTexture = nullptr;
+    return;
+  }
+  else
+    array_77EC08[1999].pTexture = pBitmaps_LOD->GetTexture(pOutdoor->uMainTile_BitmapID);
   array_77EC08[1999].dimming_level = 23 - (-20 * pOutdoor->vSunlight.z >> 16);
   if ( array_77EC08[1999].dimming_level > 20 )
     array_77EC08[1999].dimming_level = 20;
@@ -570,10 +576,14 @@
   sin((double)pIndoorCamera->sRotationX * 0.0030664064);
   array_77EC08[1999]._48607B(&stru_8019C8);
   array_77EC08[1999].ptr_38->_48694B();
-  v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID];
-  array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0);
-  if ( !(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0) )
-    return (signed __int16)v2;
+
+  if (pOutdoor->uSky_TextureID == -1)
+  {
+    array_77EC08[1999].pTexture = nullptr;
+    return;
+  }
+  else
+    array_77EC08[1999].pTexture = pBitmaps_LOD->GetTexture(pOutdoor->uSky_TextureID);
   array_77EC08[1999].dimming_level = 0;
   v11 = stru_5C6E00->Sin(pIndoorCamera->sRotationX + 16);
   array_77EC08[1999].v_18.y = 0;
@@ -591,7 +601,7 @@
     v2 = (stru148 *)*(short *)PaletteManager::Get_Mist_or_Red_LUT(array_77EC08[1999].pTexture->palette_id2, 31, 1);
     a1b = (unsigned int)v2;
     if ( (signed int)v9 <= 0 )
-      return (signed __int16)v2;
+      return;
     v29 = v9;
     while ( 1 )
     {
@@ -630,7 +640,7 @@
       --v29;
       --v9;
       if ( !v9 )
-        return (signed __int16)v2;
+        return;
     }
   }
   if ( (signed int)v9 > 0 )
@@ -675,7 +685,6 @@
     }
     while ( v9 );
   }
-  return (signed __int16)v2;
 }
 
 //----- (00485044) --------------------------------------------------------
--- a/Render.h	Wed May 08 19:54:19 2013 +0200
+++ b/Render.h	Wed May 08 21:37:12 2013 +0200
@@ -367,7 +367,7 @@
   void RenderTerrainD3D();
   void DrawTerrainD3D(int a1, int edx0, int a3);
   void DrawTerrainSW(int a1, int a2, int a3);
-  __int16 ExecOutdoorDrawSW();
+  void ExecOutdoorDrawSW();
   void ChangeBetweenWinFullscreenModes();
   void DrawBillboardList_BLV();
 
--- a/Texture.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/Texture.cpp	Wed May 08 21:37:12 2013 +0200
@@ -277,12 +277,12 @@
     for ( i = uIconID; ; ++i )
     {
       v3->pTextures[i].uTextureID = pBitmaps_LOD->LoadTexture(v3->pTextures[i].pTextureName, TEXTURE_DEFAULT);
-      auto pTex = (v3->pTextures[i].uTextureID != -1 ? &pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID] : 0);
-      if (pTex)
-        pTex->palette_id2 = pPaletteManager->LoadPalette(pTex->palette_id1);
+
+      if (v3->pTextures[i].uTextureID != -1);
+        pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v3->pTextures[i].uTextureID].palette_id1);
       //result = (unsigned int)v3->pTextures;
       //if ( !(*(char *)(result + i * 20 + 18) & 1) )
-      if( v3->pTextures[i].uFlags&1)
+      if( v3->pTextures[i].uFlags & 1)
         break;
     }
   }
--- a/UIBooks.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/UIBooks.cpp	Wed May 08 21:37:12 2013 +0200
@@ -208,7 +208,7 @@
   v0 = pPlayers[uActiveCharacter];
   v1 = 11 * v0->lastOpenedSpellbookPage;
   v2 = pIcons_LOD->FindTextureByName("Pending");
-  v3 = (Texture *)(v2 != -1 ? (int)&pIcons_LOD->pTextures[v2] : 0);
+  v3 = pIcons_LOD->GetTexture(v2);
   pRenderer->ClearZBuffer(0, 479);
   v4 = 1;
   if ( __OFSUB__(v1, v1 + 11) ^ 1 )
@@ -1379,7 +1379,7 @@
             else
                 v50 = 1;
             }
-        pRenderer->DrawTransparentRedShade(v47, v49, (Texture *)(pTextureIDs_pMapDirs[v50] != -1 ? (int)&pIcons_LOD->pTextures[pTextureIDs_pMapDirs[v50]] : 0));
+        pRenderer->DrawTransparentRedShade(v47, v49, pIcons_LOD->GetTexture(pTextureIDs_pMapDirs[v50]));
         }
     result = TargetColor(0xFFu, 0xFFu, 0xFFu);
     v95 = 0;
--- a/mm7_3.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/mm7_3.cpp	Wed May 08 21:37:12 2013 +0200
@@ -12873,7 +12873,7 @@
       while ( (signed int)v41 < pDialogueWindow->pNumPresenceButton + pDialogueWindow->pStartingPosActiveItem );
     }
   }
-  pRenderer->DrawTextureIndexed(471, 445, (Texture *)(uExitCancelTextureId != -1 ? &pIcons_LOD->pTextures[uExitCancelTextureId] : 0));
+  pRenderer->DrawTextureIndexed(471, 445, pIcons_LOD->GetTexture(uExitCancelTextureId));
 }
 
 //----- (00445C8B) --------------------------------------------------------
--- a/mm7_4.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/mm7_4.cpp	Wed May 08 21:37:12 2013 +0200
@@ -7351,11 +7351,9 @@
         pInString = (char *)*(&pNPCStats->field_17884 + ((v10 & 3) == 2) + 2 * v9);
         v11 = pFontArrus->CalcTextHeight(pInString, &a1, 13, 0);
         v12 = v11 + 7;
-        pRenderer->_4A6A68(
-          8u,
-          352 - (v11 + 7),
-          (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-          (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - (v11 + 7));
+        pRenderer->_4A6A68(8, 352 - (v11 + 7),
+          pIcons_LOD->GetTexture(uTextureID_Leather),
+          pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight - (v11 + 7));
         pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
         v13 = FitTextInAWindow(pInString, pFontArrus, &a1, 0xDu, 0);
         pDialogueWindow->DrawText(pFontArrus, 13, 354 - v12, 0, v13, 0, 0, 0);
@@ -7556,11 +7554,9 @@
       v47 = pFontCreate;
       v48 = pFontCreate->CalcTextHeight(current_npc_text, &w, 13, 0) + 7;
     }
-    pRenderer->_4A6A68(
-      8u,
-      352 - v48,
-      (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-      (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v48);
+    pRenderer->_4A6A68(8, 352 - v48,
+      pIcons_LOD->GetTexture(uTextureID_Leather),
+      pIcons_LOD->GetTexture(uTextureID_Leather)->uTextureHeight - v48);
     pRenderer->DrawTextureIndexed(8u, 347 - v48, pTexture_591428);
     v49 = FitTextInAWindow(current_npc_text, v47, &w, 0xDu, 0);
     a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
--- a/mm7_5.cpp	Wed May 08 19:54:19 2013 +0200
+++ b/mm7_5.cpp	Wed May 08 21:37:12 2013 +0200
@@ -2864,7 +2864,7 @@
           papredoll_dbrds[2] = pIcons_LOD->LoadTexture("BUTTEXI1", TEXTURE_16BIT_PALETTE);
           pBtn_ExitCancel = pGUIWindow_CurrentMenu->CreateButton(0x187u, 0x13Cu, 0x4Bu, 0x21u, v0, 0, UIMSG_Escape, 0, 0,
                          pGlobalTXT_LocalizationStrings[79],// "Exit"
-                         (Texture *)(uTextureID_BUTTDESC2 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_BUTTDESC2] : 0), 0); //, v179);
+                         pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0); //, v179);
           continue;
         case UIMSG_GameMenuButton:
           if ( pCurrentScreen )
@@ -2909,8 +2909,8 @@
           pCharacterScreen_DollBtn->Release();
           if ( bRingsShownInCharScreen )
           {
-            v128 = (uTextureID_detaliz_close_button != -1 ? pIcons_LOD->pTextures[uTextureID_detaliz_close_button].uTextureHeight : 26);
-            v125 = (uTextureID_detaliz_close_button != -1 ? pIcons_LOD->pTextures[uTextureID_detaliz_close_button].uTextureWidth : 24);
+            v128 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureHeight;
+            v125 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureWidth;
             v123 = 445;
             v121 = 470;
           }
@@ -9450,7 +9450,8 @@
 //----- (0040F82D) --------------------------------------------------------
 void __fastcall ZBuffer_Fill(int *pZBuffer, int uTextureId, int iZValue)
 {
-  ZBuffer_DoFill(pZBuffer, (Texture *)(uTextureId != -1 ? (int)&pIcons_LOD->pTextures[uTextureId] : 0), iZValue);
+  assert(uTextureId != -1);
+  ZBuffer_DoFill(pZBuffer, pIcons_LOD->GetTexture(uTextureId), iZValue);
 }
 
 //----- (0040F845) --------------------------------------------------------
@@ -10201,10 +10202,10 @@
   int v39; // eax@129
   unsigned int pNumMessages; // eax@142
   GUIButton *pGUIButton; // ebp@146
-  unsigned int pX; // [sp-1Ch] [bp-124h]@17
-  unsigned int pY; // [sp-18h] [bp-120h]@17
-  Texture *pTexture; // [sp-14h] [bp-11Ch]@17
-  Texture *pTexture2; // [sp-14h] [bp-11Ch]@86
+  //unsigned int pX; // [sp-1Ch] [bp-124h]@17
+  //unsigned int pY; // [sp-18h] [bp-120h]@17
+  //Texture *pTexture; // [sp-14h] [bp-11Ch]@17
+  //Texture *pTexture2; // [sp-14h] [bp-11Ch]@86
   int i; // [sp+0h] [bp-108h]@3
   ItemGen pItemGen; // [sp+4h] [bp-104h]@98
   GUIButton GUIButton2; // [sp+28h] [bp-E0h]@133
@@ -10221,10 +10222,8 @@
     {
       case WINDOW_OptionsButtons:
       {
-        pTexture = (Texture *)(uTextureID_Options != -1 ? &pIcons_LOD->pTextures[uTextureID_Options] : 0);
-        pY = pViewport->uViewportTL_Y;
-        pX = pViewport->uViewportTL_X;
-        pRenderer->DrawTextureIndexed(pX, pY, pTexture);
+        pRenderer->DrawTextureIndexed(pViewport->uViewportTL_Y,
+                                      pViewport->uViewportTL_X, pIcons_LOD->GetTexture(uTextureID_Options));
         viewparams->bRedrawGameUI = 1;
         continue;
       }
@@ -10284,8 +10283,7 @@
           pRenderer->ClearZBuffer(0, 479);
           draw_leather();
           CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
-          pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
-             (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0));
+          pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
         }
         continue;
       }
@@ -10334,8 +10332,7 @@
         draw_leather();
         CharacterUI_InventoryTab_Draw(uActiveCharacter, 1);
         CharacterUI_DrawPaperdoll(uActiveCharacter);
-        pRenderer->DrawTextureTransparent(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
-            (Texture *)(uTextureID_x_x_u != -1 ? &pIcons_LOD->pTextures[uTextureID_x_x_u] : 0));
+        pRenderer->DrawTextureTransparent(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uTextureID_x_x_u));
         continue;
       }
       case WINDOW_FinalWindow:
@@ -10558,9 +10555,8 @@
       case WINDOW_BooksWindow:
       {
         pButton = (GUIButton *)pWindow->ptr_1C;
-        pY = pWindow->uFrameY;
-        pX = pWindow->uFrameX;
-        pRenderer->DrawTextureIndexed(pX, pY, pButton->pTextures[0]);
+        pRenderer->DrawTextureIndexed(pWindow->uFrameY,
+                                      pWindow->uFrameX, pButton->pTextures[0]);
         viewparams->bRedrawGameUI = 1;
         continue;
       }
@@ -11530,14 +11526,18 @@
         i->uX = 0;
       }
     }
-    pBtn_Up = pGUIWindow_CurrentMenu->CreateButton(438, 46, (uTextureID_ar_up_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_up_up].uTextureWidth : 24),
-                   (uTextureID_ar_up_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_up_up].uTextureHeight : 26),
-                   1, 0, UIMSG_ClickAwardsUpBtn, 0, 0, "", (Texture *)(uTextureID_ar_up_up != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_up_up] : 0),
-                   uTextureID_ar_up_dn != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_up_dn] : 0, 0);
-    pBtn_Down = pGUIWindow_CurrentMenu->CreateButton(438, 292, (uTextureID_ar_dn_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_dn_up].uTextureWidth : 24),
-                   (uTextureID_ar_dn_up != -1 ? pIcons_LOD->pTextures[uTextureID_ar_dn_up].uTextureHeight : 26),
-                   1, 0, UIMSG_ClickAwardsDownBtn, 0, 0, "", (Texture *)(uTextureID_ar_dn_up != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_dn_up] : 0),
-                   uTextureID_ar_dn_dn != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_ar_dn_dn] : 0, 0);
+    pBtn_Up = pGUIWindow_CurrentMenu->CreateButton(438, 46,
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_up)->uTextureWidth,
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_up)->uTextureHeight,
+                   1, 0, UIMSG_ClickAwardsUpBtn, 0, 0, "",
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_up),
+                   pIcons_LOD->GetTexture(uTextureID_ar_up_dn), 0);
+    pBtn_Down = pGUIWindow_CurrentMenu->CreateButton(438, 292,
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_up)->uTextureWidth,
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_up)->uTextureHeight,
+                   1, 0, UIMSG_ClickAwardsDownBtn, 0, 0, "",
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_up),
+                   pIcons_LOD->GetTexture(uTextureID_ar_dn_dn), 0);
     ptr_507BA4 = pGUIWindow_CurrentMenu->CreateButton(440, 62, 16, 232, 1, 0, UIMSG_C0, 0, 0, "", 0);
   }
 }