diff Arcomage.cpp @ 1185:24454b5c9268

more on acromage
author Gloval
date Fri, 07 Jun 2013 01:32:17 +0400
parents a90dc4aee8f4
children 569216b4f54d
line wrap: on
line diff
--- a/Arcomage.cpp	Thu Jun 06 08:33:43 2013 +0400
+++ b/Arcomage.cpp	Fri Jun 07 01:32:17 2013 +0400
@@ -26,17 +26,17 @@
 void sub_409BE8();
 
 
-char __cdecl am_409FE9();
+void am_409FE9();
 char __cdecl am_40A198();
 void am_40A255();
 void  am_40A283(int a1);
-signed int __fastcall am_40A324(int a1);
+int  GetEmptyCardSlotIndex(int player_num);
 void am_40A346(int player_num);
 void __cdecl am_40A383();
 bool  am_40A514();
 char __thiscall am_40A560(unsigned int _this);
-void __thiscall am_blts(int a1); // idb
-void __cdecl am_40AA4E();
+void  am_blts(int a1); // idb
+void am_40AA4E();
 void __cdecl am_chroma_blts();
 void __cdecl am_DrawUI();
 void __fastcall am_40B102(int a1, char *a2, POINT *pXY); // idb
@@ -47,13 +47,13 @@
 void __cdecl am_chroma_blt();
 void __cdecl am_40B4B9();
 void __fastcall am_40B76F(int a1);
-int __fastcall am_40BB49(int a1);
+int GetPlayerHandCardCount(int player_num);
 signed int __fastcall am_40BB67(int a1);
 char __fastcall am_40BCFB(int a1, signed int a2);
 bool __fastcall am_40BE0E(int a1, signed int a2);
-bool __fastcall am_40BF15(int a1, int a2);
+bool  am_40BF15(int player_num, int hand_card_indx);
 void __fastcall am_40BF77(int a1, unsigned int uCardID); // idb
-int __fastcall am_40D2B4(POINT*, int); // weak
+int  am_40D2B4(POINT* a1, int a2); // weak
 int __fastcall am_40D402(int, int); // weak
 int __cdecl am_40D444();
 
@@ -63,6 +63,7 @@
 void  Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3);
 void __cdecl am_EndScene();
 void __fastcall DrawRect(RECT *pXYZW, unsigned __int16 uColor, char bSolidFill); // idb
+void  SetPixel(POINT *pTargetXY, unsigned __int16 uColor);
 int __fastcall rand_interval(int a, int b); // idb
 char *__fastcall inv_strcat(const char *Source, char *Dest);
 char *__fastcall inv_strcpy(const char *Source, char *Dest);
@@ -113,14 +114,15 @@
 
 stru272 array_4FABD0[10];
 
-
+int dword_505554[108]; 
+char byte_5054E8[108];
 
 /*  267 */
 #pragma pack(push, 1)
 struct stru273
 {
   bool _40DD2F();
-  bool Inside(Vec4_int_ *pXYZW);
+  bool Inside(RECT*pXYZW);
 
   int x;
   int y;
@@ -131,16 +133,30 @@
 };
 #pragma pack(pop)
 
-
-
-int dword_4E1884 = 50; // weak
-int dword_4E1888 = 100 ; // weak
+char am_byte_4E185D; // weak
+
+int amuint_4E1860; // weak
+int amuint_4E1864; // weak
+int amuint_4E1868; // weak
+int amuint_4E186C; // weak
+int amuint_4E1870; // weak
+
 
 int dword_4E1874  = 5; // weak
-
 int dword_4E1878  = 1; // weak
 int dword_4E187C  = 1; // weak
 int dword_4E1880  = 1; // weak
+int dword_4E1884 = 50; // weak
+int dword_4E1888 = 100 ; // weak
+
+int dword_4DF3A4; // weak
+
+char byte_4FAA2C; // weak
+int amuint_4FAA6C; // idb
+char am_byte_4FAA77; // weak
+
+
+unsigned int amuint_4FABC0; // idb
 
 
 
@@ -152,7 +168,7 @@
   this->y = pArcomageGame->mouse_y;
   this->field_8 = pArcomageGame->mouse_left;
   this->field_9 = pArcomageGame->mouse_left == pArcomageGame->field_F7;
-  this->field_8 = pArcomageGame->mouse_left;
+  this->field_A = pArcomageGame->mouse_right;
   this->field_B = pArcomageGame->mouse_right == pArcomageGame->field_F8;
   pArcomageGame->field_F7 = pArcomageGame->mouse_left;
   pArcomageGame->field_F8 = pArcomageGame->mouse_right;
@@ -160,12 +176,11 @@
 }
 
 //----- (0040DD93) --------------------------------------------------------
-bool stru273::Inside(Vec4_int_ *pXYZW)
-{
-  int v2; // eax@3
-
-  auto a1 = this;
-  return a1->x >= pXYZW->x && a1->x <= pXYZW->z && (v2 = a1->y, v2 >= pXYZW->y) && v2 <= pXYZW->w;
+bool stru273::Inside(RECT*pXYZW )
+    {
+
+  return (x >= pXYZW->left) && (x <= pXYZW->right) && 
+          (y>= pXYZW->top) && (y <= pXYZW->bottom);
 }
 
 //----- (0040DFD1) --------------------------------------------------------
@@ -199,8 +214,6 @@
 //----- (0040E01A) --------------------------------------------------------
 int stru272_stru0::_40E01A(int a2)
     {
-    signed int result; // eax@2
-
     auto a1 = this;
     if ( a1->signature == SIG_trpg )
         {
@@ -220,50 +233,33 @@
         a1->field_40 = *(int *)(a2 + 52);
 //        a1->field_54 = *(int *)(a2 + 56);
         a1->field_59 = 1;
-        result = 0;
+        return 0;
         }
     else
-        {
-        result = 2;
-        }
-    return result;
+       return 2;
     }
 
 //----- (0040E0F5) --------------------------------------------------------
 int stru272_stru0::_40E0F5(char a2, char a3)
     {
-    signed int result; // eax@2
-    int v4; // edx@7
-    int v5; // eax@7
-
-    auto a1 = this;
-    if ( a1->signature == SIG_trpg)
+    if ( signature == SIG_trpg)
         {
         if ( a2 )
             {
-            a1->field_8 = 0;
-            a1->field_30 = 0.0;
+            field_8 = 0;
+            field_30 = 0.0;
             }
-        if ( a1->field_59 && a3 )
+        if ( field_59 && a3 )
             {
-            v4 = a1->field_4;
-          //  v5 = a1->field_54;
-            do
-                {
-                *(int *)v5 = 0;
-                v5 += 28;
-                --v4;
-                }
-                while ( v4 );
-                a1->field_58 = 0;
+
+            for (int i=0; i<field_4; ++i)
+                field_54[i].field_0 = 0;
+             field_58 = 0;
             }
-        result = 0;
+        return 0;
         }
     else
-        {
-        result = 2;
-        }
-    return result;
+        return 2;
     }
 
 //----- (0040E133) --------------------------------------------------------
@@ -351,20 +347,16 @@
 //----- (0040E2A7) --------------------------------------------------------
 int stru272_stru0::_40E2A7()
     {
-    int result; // eax@2
-
-    if ( this->signature == SIG_trpg )
+
+    if (signature == SIG_trpg )
         {
-        if ( this->field_8 <= 0 )
-            result = this->field_58 != 0 ? 2 : 0;
+        if ( field_8 <= 0 )
+            return field_58 != 0 ? 2 : 0;
         else
-            result = 1;
+            return 1;
         }
     else
-        {
-        result = 3;
-        }
-    return result;
+        return 3;
     }
 
 
@@ -890,7 +882,7 @@
 //      v145 = &stru_505708[a1];
 //      v130 = a1;
 //      v143 = &stru_505708[(a1 + 1) % 2];
-//      v136 = am_40BB49(a1);
+//      v136 = GetPlayerHandCardCount(a1);
 //      v65 = 0;
 //      do
 //      {
@@ -1193,7 +1185,7 @@
 //    v144 = &stru_505708[a1];
 //    v129 = a1;
 //    v142 = &stru_505708[(a1 + 1) % 2];
-//    v135 = am_40BB49(a1);
+//    v135 = GetPlayerHandCardCount(a1);
 //    v10 = 0;
 //    do
 //    {
@@ -1486,7 +1478,7 @@
 //  if ( am_byte_4FAA77 )
 //  {
 //LABEL_11:
-//    v7 = am_40BB49(v4);
+//    v7 = GetPlayerHandCardCount(v4);
 //    v8 = rand_interval(0, v7 - 1);
 //    result = am_40BCFB(v4, v8);
 //  }
@@ -1494,7 +1486,7 @@
 //  {
 //    while ( 1 )
 //    {
-//      v5 = am_40BB49(v4);
+//      v5 = GetPlayerHandCardCount(v4);
 //      v6 = rand_interval(0, v5 - 1);
 //      if ( am_40BF15(v4, v6) )
 //        break;
@@ -1532,21 +1524,21 @@
     am_40A346(amuint_4FAA6C);
     Sleep(10000);
 LABEL_8:
-   /* while ( byte_4FAA24 )
+    while ( byte_4FAA24 )
     {
       amuint_4FABC0 = -1;
       am_40A283(amuint_4FAA6C);
       while ( 1 )
       {
         byte_4FAA24 = am_40A560(amuint_4FAA6C);
-        if ( am_40BB49(amuint_4FAA6C) <= dword_4E1874 )
+        if ( GetPlayerHandCardCount(amuint_4FAA6C) <= dword_4E1874 )
           break;
         am_byte_4FAA77 = 1;
         if ( pArcomageGame->field_F4 )
           goto LABEL_8;
       }
       am_byte_4FAA77 = 0;
-    }*/
+    }
     pArcomageGame->field_F5 = am_40A514();
     if ( !pArcomageGame->field_F5 )
       am_40A383();
@@ -1588,8 +1580,8 @@
 
 
 //----- (00409FE9) --------------------------------------------------------
-char __cdecl am_409FE9()
-{
+void am_409FE9()
+    {
   signed int v0; // edi@1
   signed int v1; // esi@4
   int *v2; // ecx@7
@@ -1601,22 +1593,20 @@
 
   amuint_4FAA6C = dword_505890;
   sub_409BE8();
-  v0 = 0;
-  do
+  for(v0=0; v0<2; ++v0 )
   {
     if ( v0 )
     {
-      v1 = v0;
-      inv_strcpy(pArcomageGame->pPlayer2Name, am_Players[v0].pPlayerName);
+      inv_strcpy(pArcomageGame->pPlayer2Name, am_Players[1].pPlayerName);
       if ( byte_4E185C )
-        LOBYTE(am_Players[v1].field_20) = 0;
+        am_Players[1].field_20 = 0;
       else
-        LOBYTE(am_Players[v1].field_20) = 1;
+        am_Players[1].field_20 = 1;
     }
     else
     {
-      inv_strcpy(pArcomageGame->pPlayer1Name, (char *)am_Players);
-      LOBYTE(am_Players[0].field_20) = 1;
+      inv_strcpy(pArcomageGame->pPlayer1Name, am_Players[0].pPlayerName);
+      am_Players[0].field_20 = 1;
     }
     am_Players[v0].field_24 = amuint_4E1860;
     am_Players[v0].field_28 = amuint_4E1864;
@@ -1626,43 +1616,32 @@
     am_Players[v0].field_38 = amuint_505884;
     am_Players[v0].field_3C = amuint_505888;
     am_Players[v0].field_40 = amuint_50588C;
-    v2 = &am_Players[v0].arr_6C[0][1];
-    v3 = am_Players[v0].cards_at_hand;
-    v4 = 10;
-    do
+
+    for (v4=0; v4<10; ++v4 )
     {
-      *v3 = -1;
+      am_Players[v0].cards_at_hand[v4] = -1;
       if ( am_byte_4E185D )
       {
-        *(v2 - 1) = -1;
-        *v2 = -1;
+        am_Players[v0].arr_6C[v4].field_0 = -1;
+        am_Players[v0].arr_6C[v4].field_4 = -1;
       }
       else
       {
-        *(v2 - 1) = 0;
-        *v2 = 0;
+      am_Players[v0].arr_6C[v4].field_0 = 0;
+      am_Players[v0].arr_6C[v4].field_4 = 0;
       }
-      ++v3;
-      v2 += 2;
-      --v4;
     }
-    while ( v4 );
-    ++v0;
+   
   }
-  while ( v0 < 2 );
+
+
   inv_strcpy(pDeckMaster, byte_5054C8);
-  v5 = 0;
-  v6 = (signed int)dword_505554;
-  v7 = -2;
-  do
-  {
-    byte_5054E8[v7 + 2] = 0;
-    *(unsigned int *)v6 = v5;
-    switch ( v7 )
-    {
-      default:
-        ++v5;
-        break;
+  for (v6=0, v7=-2, v5=0; v6<108; ++v6, ++v7)
+      {
+      byte_5054E8[v6] = 0;
+      dword_505554[v6] =v5;
+      switch ( v7 )
+          {
       case 0:
       case 2:
       case 6:
@@ -1684,13 +1663,13 @@
       case 81:
       case 84:
       case 89:
-        break;
-    }
-    v6 += 4;
-    ++v7;
-  }
-  while ( v6 < (signed int)&unk_505704 );
-  return am_40A198();
+          break;
+      default:
+          ++v5;
+          }
+      }
+
+   am_40A198();
 }
 // 4E185C: using guessed type char byte_4E185C;
 // 4E185D: using guessed type char am_byte_4E185D;
@@ -1778,7 +1757,6 @@
 //----- (0040A255) --------------------------------------------------------
 void am_40A255()
     {
-
   for (int i = 0; i < dword_4E1874; ++i )
   {
       am_40A283(0);
@@ -1820,15 +1798,15 @@
   }
   while ( !v5 );
   ArcomageGame::PlaySound(0x15u);
-  result = am_40A324(v4);
+  result = GetEmptyCardSlotIndex(v4);
   if ( result != -1 )
   {
     amuint_4FAA4C = result;
     am_Players[0].cards_at_hand[result + 47 * v4] = v3;
     v7 = 188 * v4 + 8 * result;
-    *(int *)((char *)am_Players[0].arr_6C[0] + v7) = rand_interval(-4, 4);
+//    *(int *)((char *)am_Players[0].arr_6C[0] + v7) = rand_interval(-4, 4);
     result = rand_interval(-4, 4);
-    *(int *)((char *)&am_Players[0].arr_6C[0][1] + v7) = result;
+//    *(int *)((char *)&am_Players[0].arr_6C[0][1] + v7) = result;
     pArcomageGame->field_F6 = 1;
     byte_4FAA2D = 1;
   }
@@ -1840,34 +1818,26 @@
 // 505314: using guessed type int dword_505314[];
 
 //----- (0040A324) --------------------------------------------------------
-signed int __fastcall am_40A324(int a1)
-{
-  signed int result; // eax@1
-  signed int v2; // edx@1
-  char *v3; // ecx@1
-
-  result = -1;
-  v2 = 0;
-  v3 = (char *)am_Players[a1].cards_at_hand;
-  while ( *(unsigned int *)v3 != -1 )
-  {
-    ++v2;
-    v3 += 4;
-    if ( v2 >= 10 )
-      return result;
-  }
-  return v2;
+int GetEmptyCardSlotIndex( int player_num )
+    {
+  int i; 
+  for (i=0; i<10; ++i )
+      {
+       if (am_Players[player_num].cards_at_hand[i]==-1)
+           break;
+      }
+  if ( i >= 10 )
+      return -1;
+  else
+     return i;  
 }
 
 //----- (0040A346) --------------------------------------------------------
 void am_40A346( int player_num )
-    {
-  int v1; // ecx@1
-
-  v1 = player_num;
-  am_Players[v1].field_38 += dword_4E1878 + am_Players[v1].field_2C;
-  am_Players[v1].field_3C += dword_4E187C + am_Players[v1].field_30;
-  am_Players[v1].field_40 += dword_4E1880 + am_Players[v1].field_34;
+{
+  am_Players[player_num].field_38 += dword_4E1878 + am_Players[player_num].field_2C;
+  am_Players[player_num].field_3C += dword_4E187C + am_Players[player_num].field_30;
+  am_Players[player_num].field_40 += dword_4E1880 + am_Players[player_num].field_34;
 }
 
 
@@ -2044,7 +2014,8 @@
         {
           pAudioPlayer->StopChannels(-1, -1);
           dword_4FAA68 = 0;
-          goto LABEL_16;
+          v16 = 1;
+          pArcomageGame->field_F4 = 1;
         }
         break;
       case 9:
@@ -2053,7 +2024,6 @@
       case 0xA:
         pAudioPlayer->StopChannels(-1, -1);
         byte_4FAA74 = 1;
-LABEL_16:
         v16 = 1;
         pArcomageGame->field_F4 = 1;
         break;
@@ -2112,7 +2082,7 @@
           if ( dword_4FAA64 > 0 )
           {
             --dword_4FAA64;
-            am_byte_4FAA77 = am_40BB49(a1) > dword_4E1874;
+            am_byte_4FAA77 = GetPlayerHandCardCount(a1) > dword_4E1874;
           }
           byte_4FAA2E = 1;
         }
@@ -2123,7 +2093,7 @@
           if ( dword_4FAA64 > 0 )
           {
             --dword_4FAA64;
-            am_byte_4FAA77 = am_40BB49(a1) > dword_4E1874;
+            am_byte_4FAA77 = GetPlayerHandCardCount(a1) > dword_4E1874;
           }
           byte_4FAA2E = 1;
         }
@@ -2231,12 +2201,9 @@
 // 4FABB8: using guessed type int dword_4FABB8;
 
 //----- (0040A9AF) --------------------------------------------------------
-void __thiscall am_blts(int a1)
-{
-  int v1; // esi@1
-  stru272_stru0 **v2; // esi@1
-
-  v1 = a1;
+void am_blts( int a1 )
+    {
+
   am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
   am_chroma_blts();
   am_EndScene();
@@ -2247,86 +2214,59 @@
   am_DrawUI();
   am_EndScene();
   am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-  am_40B76F(v1);
-  v2 = (stru272_stru0 **)array_4FABD0;
-  do
-  {
-    if ( *((unsigned char *)v2 - 64) )
-      (*v2)->_40E133();
-    v2 += 1067;
-  }
-  while ( (signed int)v2 < (signed int)&unk_5052C8 );
+  am_40B76F(a1);
+
+  for( int i=0; i<10; ++i)
+      {
+      if (array_4FABD0[i].field_0)
+          array_4FABD0[i].field_40->_40E133();
+      }
   dword_4FABBC = am_40BB67(amuint_4FAA6C);
   am_40AA4E();
   am_EndScene();
 }
 
 //----- (0040AA4E) --------------------------------------------------------
-void __cdecl am_40AA4E()
-{
-  signed int v0; // ebx@1
-  char v1; // ch@2@3
-  char *v2; // esi@4
-  signed int v3; // edi@6
-  int *v4; // esi@6
+void am_40AA4E()
+    {
   int v5; // [sp-4h] [bp-2Ch]@4
-  int v6; // [sp+Ch] [bp-1Ch]@10
-  int v7; // [sp+10h] [bp-18h]@10
+  unsigned int v7;
   int v8; // [sp+14h] [bp-14h]@10
   int v9; // [sp+18h] [bp-10h]@10
-  int v10; // [sp+1Ch] [bp-Ch]@6
-  char v11; // [sp+20h] [bp-8h]@1
-  char v12; // [sp+21h] [bp-7h]@1
-  char v13; // [sp+22h] [bp-6h]@1
-  char v14; // [sp+24h] [bp-4h]@1
-  char v15; // [sp+25h] [bp-3h]@1
-  char v16; // [sp+26h] [bp-2h]@1
-
-  v14 = 0;
-  v15 = -1;
-  v16 = 0;
-  v11 = -1;
-  v12 = 0;
-  v13 = 0;
-  v0 = (signed int)byte_4FABD1;
-  do
-  {
-    if ( *(unsigned char *)(v0 - 1) && (*(stru272_stru0 **)(v0 + 63))->_40E2A7() == 2 )
-    {
-      BYTE3(v5) = v1;
-      v2 = &v14;
-      if ( !*(unsigned char *)v0 )
-        v2 = &v11;
-      LOWORD(v5) = *(_WORD *)v2;
-      BYTE2(v5) = v2[2];
-      v10 = (unsigned __int16)R8G8B8_to_TargetFormat(v5);
-      v3 = 0;
-      v4 = (int *)(v0 + 71);
-      do
+  RECT pXYZW;
+
+  v9 = 0x0000FF00;
+  v8 = 0x000000FF;
+
+  for (int i=0; i<10; ++i)
       {
-        if ( *(v4 - 1) > 0 )
-        {
-          if ( v3 % 2 )
-          {
-            Render::SetPixel((Vec2_int_ *)v4, v10);
-          }
-          else
-          {
-            v6 = *v4;
-            v8 = v6 + 2;
-            v7 = v4[1];
-            v9 = v7 + 2;
-           // DrawRect(&v6, v10, 1);
-          }
-        }
-        ++v3;
-        v4 += 7;
+        if(array_4FABD0[i].field_0 && (array_4FABD0[i].field_40->_40E2A7()==2))
+            {
+
+            v5 = v9;
+            if ( !array_4FABD0[i].field_1 )
+                v5 = v8;
+
+             v7 = R8G8B8_to_TargetFormat(v5);
+             for(int j=0; j<150; ++j )
+                 {
+                 if (array_4FABD0[i].field_44[j].field_0 > 0)
+                     {
+                      if (j%2)
+                           SetPixel(&array_4FABD0[i].field_44[j].field_4, v7);
+                      else
+                          {
+                          pXYZW.left = array_4FABD0[i].field_44[j].field_4.x;
+                          pXYZW.right = pXYZW.left + 2;
+                          pXYZW.top = array_4FABD0[i].field_44[j].field_4.y;
+                          pXYZW.bottom = pXYZW.top + 2;
+                          DrawRect(&pXYZW, v7, 1);
+                          }
+                     }
+                 }
+            }
       }
-      while ( v3 < 150 );
-    }
-    v0 += 4268;
-  }
-  while ( v0 < 1);//(signed int)&array_4FABD0[9].field_4[4201] );
+
 }
 
 //----- (0040AB0A) --------------------------------------------------------
@@ -2841,7 +2781,7 @@
 //  int pTargetXY[2]; // [sp+1Ch] [bp-Ch]@1
 //  int v24; // [sp+24h] [bp-4h]@1
 //
-//  v0 = am_40BB49(amuint_4FAA6C);
+//  v0 = GetPlayerHandCardCount(amuint_4FAA6C);
 //  v1 = 0;
 //  v2 = 0;
 //  pTargetXY[1] = 327;
@@ -3025,7 +2965,7 @@
 //    {
 //      am_uint_4FAA44_blt_xy[1] = 18;
 //      am_uint_4FAA44_blt_xy[0] = 120;
-//      v1 = am_40BB49(amuint_4FAA6C);
+//      v1 = GetPlayerHandCardCount(amuint_4FAA6C);
 //      v2 = (640 - 96 * v1) / v1 + 96;
 //      if ( am_byte_4E185D )
 //      {
@@ -3220,24 +3160,18 @@
 }
 
 //----- (0040BB49) --------------------------------------------------------
-int __fastcall am_40BB49(int a1)
-{
-  int result; // eax@1
-  char *v2; // ecx@1
-  signed int v3; // edx@1
-
-  result = 0;
-  v2 = (char *)am_Players[a1].cards_at_hand;
-  v3 = 10;
-  do
-  {
-    if ( *(unsigned int *)v2 != -1 )
-      ++result;
-    v2 += 4;
-    --v3;
-  }
-  while ( v3 );
-  return result;
+int GetPlayerHandCardCount( int player_num )
+    {
+  int card_count; // eax@1
+
+  card_count = 0;
+  for(int i=0; i<10; ++i)
+      {
+      if (am_Players[player_num].cards_at_hand[i]!=-1)
+            ++card_count;
+      }
+  return card_count;
+  
 }
 
 //----- (0040BB67) --------------------------------------------------------
@@ -3288,7 +3222,7 @@
   {
     if ( v26._40DD2F() )
     {
-      v5 = am_40BB49(v1);
+      v5 = GetPlayerHandCardCount(v1);
       a2 = 0;
       v25 = v5;
       pXYZW[1] = 327;
@@ -3316,14 +3250,14 @@
           if ( am_byte_4E185D )
           {
             v9 = v3 + 8 * v7;
-            v10 = *(int *)((char *)am_Players[0].arr_6C[0] + v9);
-            v11 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v9);
+          //  v10 = *(int *)((char *)am_Players[0].arr_6C[0] + v9);
+         //   v11 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v9);
             pXYZW[0] += v10;
             pXYZW[2] += v10;
             pXYZW[1] += v11;
             pXYZW[3] += v11;
           }
-          if ( v26.Inside((Vec4_int_ *)pXYZW) )
+          if ( true)//v26.Inside(pXYZW) )
             break;
           v31 = 0;
           v32 = 0;
@@ -3338,8 +3272,8 @@
           if ( am_byte_4E185D )
           {
             v15 = v3 + 8 * v30;
-            v16 = *(int *)((char *)am_Players[0].arr_6C[0] + v15);
-            v17 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v15);
+           // v16 = *(int *)((char *)am_Players[0].arr_6C[0] + v15);
+          //  v17 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v15);
             pXYZW[0] -= v16;
             pXYZW[2] -= v16;
             pXYZW[1] -= v17;
@@ -3418,10 +3352,10 @@
   {
     ArcomageGame::PlaySound(0x16u);
     v7 = amuint_4FAA6C;
-    v8 = am_40BB49(amuint_4FAA6C);
+    v8 = GetPlayerHandCardCount(amuint_4FAA6C);
     v9 = 188 * v7 + 8 * v3;
-    v10 = 96 * v3 + *(int *)((char *)am_Players[0].arr_6C[0] + v9) + (640 - 96 * v8) / (v8 + 1);
-    v11 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v9) + 327;
+//    v10 = 96 * v3 + *(int *)((char *)am_Players[0].arr_6C[0] + v9) + (640 - 96 * v8) / (v8 + 1);
+   // v11 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v9) + 327;
     amuint_4FAA5C_blt_xy[0] = v10;
     amuint_4FAA5C_blt_xy[1] = v11;
     v12 = 0;
@@ -3503,13 +3437,13 @@
   {
     ArcomageGame::PlaySound(0x17u);
     v8 = amuint_4FAA6C;
-    v9 = am_40BB49(amuint_4FAA6C);
+    v9 = GetPlayerHandCardCount(amuint_4FAA6C);
     v10 = 188 * v8 + 8 * v6;
     v11 = v6 + 47 * v3;
     amuint_4FAA54_blt_xy[1] = -30;
     pArcomageGame->field_F6 = 1;
-    v12 = 96 * v6 + *(int *)((char *)am_Players[0].arr_6C[0] + v10) + (640 - 96 * v9) / (v9 + 1);
-    v13 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v10) + 327;
+    //v12 = 96 * v6 + *(int *)((char *)am_Players[0].arr_6C[0] + v10) + (640 - 96 * v9) / (v9 + 1);
+  //  v13 = *(int *)((char *)&am_Players[0].arr_6C[0][1] + v10) + 327;
     amuint_4FAA5C_blt_xy[0] = v12;
     amuint_4FAA5C_blt_xy[1] = v13;
     amuint_4FAA54_blt_xy[0] = (272 - v12) / 5;
@@ -3533,27 +3467,27 @@
 }
 
 //----- (0040BF15) --------------------------------------------------------
-bool __fastcall am_40BF15(int a1, int a2)
-{
-  ArcomagePlayer *v2; // esi@1
+bool am_40BF15( int player_num, int hand_card_indx )
+    {
   bool result; // eax@1
   ArcomageCard *v4; // ecx@1
-
-  v2 = &am_Players[a1];
-  LOBYTE(result) = 1;
-  v4 = &pCards[v2->cards_at_hand[a2]];
-  if ( SBYTE1(v4->field_24) > v2->field_2C )
-    LOBYTE(result) = 0;
-  if ( SBYTE2(v4->field_24) > v2->field_30 )
-    LOBYTE(result) = 0;
-  if ( SBYTE3(v4->field_24) > v2->field_34 )
-    LOBYTE(result) = 0;
-  if ( SLOBYTE(v4->field_28) > v2->field_38 )
-    LOBYTE(result) = 0;
-  if ( SBYTE1(v4->field_28) > v2->field_3C )
-    LOBYTE(result) = 0;
-  if ( SBYTE2(v4->field_28) > v2->field_40 )
-    LOBYTE(result) = 0;
+  ArcomagePlayer *v2; // esi@1
+
+   v2 = &am_Players[player_num];
+  result = true;
+  v4 = &pCards[am_Players[player_num].cards_at_hand[hand_card_indx]];
+  if ( v4->field_25 > v2->field_2C )
+    result = false;
+  if ( v4->field_26 > v2->field_30 )
+    result = false;
+  if ( v4->field_27 > v2->field_34 )
+    result = false;
+  if ( v4->field_28 > v2->field_38 )
+    result = false;
+  if ( v4->field_29 > v2->field_3C )
+    result = false;
+  if ( v4->field_2A > v2->field_40 )
+    result = false;
   return result;
 }
 
@@ -3912,7 +3846,7 @@
 //        while ( v25 < SBYTE1(pCard->field_30) );
 //      }
 //      v26 = pCard;
-//      am_byte_4FAA77 = am_40BB49(v193) > dword_4E1874;
+//      am_byte_4FAA77 = GetPlayerHandCardCount(v193) > dword_4E1874;
 //      LOBYTE(v27) = BYTE2(pCard->field_30);
 //      if ( (_BYTE)v27 )
 //      {
@@ -4562,7 +4496,7 @@
 //        while ( v106 < pCard->field_48[6] );
 //      }
 //      v107 = pCard;
-//      am_byte_4FAA77 = am_40BB49(v193) > dword_4E1874;
+//      am_byte_4FAA77 = GetPlayerHandCardCount(v193) > dword_4E1874;
 //      LOBYTE(v108) = pCard->field_48[7];
 //      if ( (_BYTE)v108 )
 //      {
@@ -5518,10 +5452,10 @@
 
 
 //----- (0040D2B4) --------------------------------------------------------
-int __fastcall am_40D2B4(Vec2_int_ *a1, int a2)
-{
+int am_40D2B4( POINT* a1, int a2 )
+    {
   int v2; // ebp@1
-  Vec2_int_ *v3; // edi@1
+  POINT *v3; // edi@1
   char *v4; // ebx@1
   int result; // eax@3
   unsigned int v6; // esi@7
@@ -5535,92 +5469,65 @@
   v11 = 0;
   v2 = a2;
   v3 = a1;
-  v4 = byte_4FABD0;
-  v12 = (stru272_stru0 **)array_4FABD0;
-  while ( *v4 )
-  {
-    result = (*v12)->_40E2A7();
-    if ( !result )
-    {
-      *v4 = 0;
-      --v11;
-      v12 -= 1067;
-      v4 -= 4268;
-    }
-    ++v11;
-    v12 += 1067;
-    v4 += 4268;
-    if ( v11 >= 10 )
-      return result;
-  }
-  v6 = 4268 * v11;
-  byte_4FABD0[4268 * v11] = 1;
+  while ( array_4FABD0[v11].field_0 )
+      {
+      result = array_4FABD0[v11].field_40->_40E2A7();
+      if ( !result )
+          {
+          array_4FABD0[v11].field_0 = 0;
+          --v11;
+          }
+      ++v11;
+      if ( v11 >= 10 )
+          return result;
+      }
+  v6 = v11;
+  array_4FABD0[v11].field_0 = 1;
   if ( v2 <= 0 )
-  {
-    byte_4FABD1[v6] = 0;
-    v2 = -v2;
-  }
+      {
+      array_4FABD0[v6].field_1 = 0;
+      v2 = -v2;
+      }
   else
-  {
-    byte_4FABD1[v6] = 1;
-  }
-  *(unsigned int *)((char *)&unk_4FABD4 + v6) = v3->x - 20;
-  dword_4FABDC[v6 / 4] = v3->x + 20;
-  dword_4FABD8[v6 / 4] = v3->y - 20;
-  dword_4FABE0[v6 / 4] = v3->y + 20;
- // v7 = array_4FABD0[v6 / 0x10AC]
-  dword_4FABE4[v6 / 4] = -60;
-  dword_4FABE8[v6 / 4] = 60;
-  dword_4FABEC[v6 / 4] = 180;
-  dword_4FABF0[v6 / 4] = 0x3F000000u;
-  dword_4FABF4[v6 / 4] = 150;
-  dword_4FABF8[v6 / 4] = 0x42480000u;
-  dword_4FABFC[v6 / 4] = 0x40400000u;
-  dword_4FAC00[v6 / 4] = 0x41000000u;
-  dword_4FAC04[v6 / 4] = 5;
-  dword_4FAC08[v6 / 4] = 15;
-  dword_4FAC0C[v6 / 4] = (int)array_4FABD0[v6 / 0x10AC].field_4;
-  v7->_40E01A((int)((char *)&unk_4FABD4 + v6));
+      {
+      array_4FABD0[v6].field_1 = 1;
+      }
+  array_4FABD0[v6].field_4 = v3->x - 20;
+  array_4FABD0[v6].field_C = v3->x + 20;
+  array_4FABD0[v6].field_8 = v3->y - 20;
+  array_4FABD0[v6].field_10 = v3->y + 20;
+  array_4FABD0[v6].field_14 = -60;
+  array_4FABD0[v6].field_18 = 60;
+  array_4FABD0[v6].field_1C = 180;
+  array_4FABD0[v6].field_20f = 0.5;
+  array_4FABD0[v6].field_24 = 150;
+  array_4FABD0[v6].field_28f = 50.0;
+  array_4FABD0[v6].field_2Cf = 3.0;
+  array_4FABD0[v6].field_30f = 8.0;
+  array_4FABD0[v6].field_34 = 5;
+  array_4FABD0[v6].field_38 = 15;
+  array_4FABD0[v6].field_3C = &array_4FABD0[v6].field_44[0];
+  v8 = array_4FABD0[v6].field_40;
+  v8->_40E01A(array_4FABD0[v6].field_4);
   if ( 10 * v2 > 150 )
-    v2 = 15;
-//  v8 = array_4FABD0[v6 / 0x10AC].ptr_0;
+      v2 = 15;
+
   if ( v8->signature != SIG_trpg )
     return 2;
   if ( !v8->field_59 )
     return 3;
   v8->field_8 = 10 * v2;
-  v9 = v8->field_4;
   v8->field_30 = 0.0;
   v8->field_58 = 0;
   v8->field_44 = 0;
   v8->field_4C = 0;
   v8->field_48 = 0;
   v8->field_50 = 0;
-  /*v10 = v8->field_54;
-  do
-  {
-  *(unsigned int *)v10 = 0;
-  v10 += 28;
-  --v9;
-  }*/
-  while ( v9 );
+  for (int i=0; i<v8->field_4; ++i)
+      v8->field_54[i].field_0=0;
   return 0;
 }
-// 40D2B4: using guessed type int __fastcall am_40D2B4(uint, uint);
-// 4FABD8: using guessed type int dword_4FABD8[];
-// 4FABDC: using guessed type int dword_4FABDC[];
-// 4FABE0: using guessed type int dword_4FABE0[];
-// 4FABE4: using guessed type int dword_4FABE4[];
-// 4FABE8: using guessed type int dword_4FABE8[];
-// 4FABEC: using guessed type int dword_4FABEC[];
-// 4FABF0: using guessed type int dword_4FABF0[];
-// 4FABF4: using guessed type int dword_4FABF4[];
-// 4FABF8: using guessed type int dword_4FABF8[];
-// 4FABFC: using guessed type int dword_4FABFC[];
-// 4FAC00: using guessed type int dword_4FAC00[];
-// 4FAC04: using guessed type int dword_4FAC04[];
-// 4FAC08: using guessed type int dword_4FAC08[];
-// 4FAC0C: using guessed type int dword_4FAC0C[];
+
 
 //----- (0040D402) --------------------------------------------------------
 int __fastcall am_40D402(int a1, int a2)
@@ -5970,32 +5877,29 @@
 
 
 //----- (00409BE8) --------------------------------------------------------
-void __cdecl sub_409BE8()
+void sub_409BE8()
 {
-  void *v0; // eax@1
   stru348 *v1; // eax@1
-  int v2; // ecx@1
-  int v3; // eax@1
-
-  v0 = window_SpeakInHouse->ptr_1C;
-  dword_4E1874 = 5;
-  v1 = &stru_4E1890[(int)((char *)v0 - 108)];
+    
+  v1 = &stru_4E1890[window_SpeakInHouse->par1C - 108];
   amuint_4E1860 = v1->field_4;
   amuint_4E1864 = v1->field_6;
   amuint_4E1868 = v1->field_8 - 1;
   amuint_4E186C = v1->field_A - 1;
   amuint_4E1870 = v1->field_C - 1;
-  amuint_505884 = v1->field_E;
-  amuint_505888 = v1->field_10;
-  amuint_50588C = v1->field_12;
+  dword_4E1874 = 5;
   dword_4E1878 = 1;
   dword_4E187C = 1;
   dword_4E1880 = 1;
   dword_4E1884 = v1->field_0;
-  v2 = v1->field_2;
-  v3 = v1->field_14;
-  dword_4E1888 = v2;
-  dword_4DF3A4 = v3;
+  dword_4E1888 = v1->field_2;
+
+  dword_4DF3A4 = v1->field_14;
+
+  amuint_505884 = v1->field_E;
+  amuint_505888 = v1->field_10;
+  amuint_50588C = v1->field_12;
+  
 }
 
 
@@ -6009,31 +5913,46 @@
 
 
 //----- (0040DB27) --------------------------------------------------------
-void __fastcall DrawRect(Vec4_int_ *pXYZW, unsigned __int16 uColor, char bSolidFill)
+void __fastcall DrawRect(RECT *pXYZW, unsigned __int16 uColor, char bSolidFill)
     {
-    Vec4_int_ *v3; // esi@1
-    unsigned __int16 v4; // bp@1
-    unsigned int i; // ebx@3
+    RECT *v3; // esi@1
 
     v3 = pXYZW;
-    v4 = uColor;
     pRenderer->BeginScene();
     pRenderer->SetRasterClipRect(0, 0, 639u, 479u);
     if ( bSolidFill )
         {
-        for ( i = v3->y; (signed int)i <= v3->w; ++i )
-            pRenderer->RasterLine2D(v3->x, i, v3->z, i, v4);
+        for ( int i = v3->top; i <= v3->bottom;  ++i )
+            pRenderer->RasterLine2D(v3->left, i, v3->right, i, uColor);
         }
     else
         {
-        pRenderer->RasterLine2D(v3->x, v3->y, v3->z, v3->y, v4);
-        pRenderer->RasterLine2D(v3->z, v3->y, v3->z, v3->w, v4);
-        pRenderer->RasterLine2D(v3->z, v3->w, v3->x, v3->w, v4);
-        pRenderer->RasterLine2D(v3->x, v3->w, v3->x, v3->y, v4);
+        pRenderer->RasterLine2D(v3->left, v3->top, v3->right, v3->top, uColor);
+        pRenderer->RasterLine2D(v3->right, v3->top, v3->right, v3->bottom, uColor);
+        pRenderer->RasterLine2D(v3->right, v3->bottom, v3->left, v3->bottom, uColor);
+        pRenderer->RasterLine2D(v3->left, v3->bottom, v3->left, v3->top, uColor);
         }
     pRenderer->EndScene();
     }
 
+
+//----- (0040DBD3) --------------------------------------------------------
+void SetPixel( POINT *pTargetXY, unsigned __int16 uColor )
+    {
+    pRenderer->BeginScene();
+    if ( pRenderer->uNumSceneBegins )
+        {
+        int xVal = pTargetXY->x;
+        int yVal = pTargetXY->y;
+        if ( xVal >= 0 && xVal <= 639 && yVal >= 0 && yVal <= 479)
+            {
+            pRenderer->pTargetSurface[xVal + pRenderer->uTargetSurfacePitch * yVal] = uColor;
+            }
+        pRenderer->EndScene();
+        }
+    }
+
+
 //----- (0040DDB1) --------------------------------------------------------
 int __fastcall rand_interval(int a, int b)
     {