changeset 1194:9baf16113199

arcomage ui partialy drawn
author Gloval
date Sat, 08 Jun 2013 01:19:15 +0400
parents ca65b398c320
children 1f92c110a4f2
files Arcomage.cpp Arcomage.h Time.cpp
diffstat 3 files changed, 629 insertions(+), 615 deletions(-) [+]
line wrap: on
line diff
--- a/Arcomage.cpp	Fri Jun 07 13:43:24 2013 +0600
+++ b/Arcomage.cpp	Sat Jun 08 01:19:15 2013 +0400
@@ -27,7 +27,7 @@
 
 
 void am_409FE9();
-char __cdecl am_40A198();
+void am_40A198();
 void am_40A255();
 void  am_40A283(int a1);
 int  GetEmptyCardSlotIndex(int player_num);
@@ -39,10 +39,10 @@
 void am_40AA4E();
 void __cdecl am_chroma_blts();
 void __cdecl am_DrawUI();
-void __fastcall am_40B102(int a1, char *a2, POINT *pXY); // idb
-void  am_40B17E(int a1, char* a2, POINT *pXY); // idb
-void am_40B1F3(int a1, char* a2, POINT* a3);
-void  am_40B268(int a1, char *a2, POINT *pXY); // idb
+void am_40B102(int a1, char *text, POINT *pXY); // idb
+void am_40B17E(int a1, char* text, POINT *pXY); // idb
+void am_40B1F3(int a1, char* text, POINT* pXY);
+void am_40B268(int a1, char *text, POINT *pXY); // idb
 void __cdecl am_chroma_and_copy_blts();
 void __cdecl am_chroma_blt();
 void __cdecl am_40B4B9();
@@ -107,23 +107,26 @@
 #define SIG_xxxx  0x78787878
 
 ArcomageGame *pArcomageGame = new ArcomageGame;
-//ArcomageCard pCards[87];
+
 ArcomagePlayer am_Players[2];
 
 Acromage_st1 struct_st1[10];
 
 stru272 array_4FABD0[10];
 
-char byte_5052A8[108];
-int dword_505314[108]; // weak
-
-char byte_5054C8[32]; // idb
-char byte_5054E8[108];
-int dword_505554[108]; 
-
-char pArcomagePlayer2Name[8];
-char pArcomagePlayer1Name[8];
-char pDeckMaster[12];
+ArcomageDeck playDeck;
+
+//char byte_5052A8[108];
+//int dword_505314[108]; // weak
+
+ArcomageDeck deckMaster;
+//char byte_5054C8[32]; // idb
+//char byte_5054E8[108];
+//int dword_505554[108]; 
+
+char pArcomagePlayer2Name[]="Enemy";
+char pArcomagePlayer1Name[]="Player";
+char pDeckMaster[]="Master Deck";
 
 
 /*  267 */
@@ -621,7 +624,7 @@
 
 if ( blend_mode == 2 )
     {
-        uSrcPitch = 2 * (uSrcPitch - src_width);
+        uSrcPitch =  (uSrcPitch - src_width);
         for (int i=0; i< src_height; ++i)
             {
             for (int j=0; j< src_width; ++j)
@@ -637,7 +640,7 @@
     }
 else 
     {
-    uSrcPitch = 2 * (uSrcPitch - src_width);
+    uSrcPitch = (uSrcPitch - src_width);
     for (int i=0; i< src_height; ++i)
         {
         for (int j=0; j< src_width; ++j)
@@ -696,7 +699,7 @@
 
     if ( blend_mode == 2 )
         {
-        uSrcPitch = 2 * (uSrcPitch - src_width);
+        uSrcPitch =  (uSrcPitch - src_width);
         for (int i=0; i< src_height; ++i)
             {
             for (int j=0; j< src_width; ++j)
@@ -711,7 +714,7 @@
         }
     else 
         {
-        uSrcPitch = 2 * (uSrcPitch - src_width);
+        uSrcPitch =  (uSrcPitch - src_width);
         for (int i=0; i< src_height; ++i)
             {
             for (int j=0; j< src_width; ++j)
@@ -1612,22 +1615,19 @@
 //----- (00409FE9) --------------------------------------------------------
 void am_409FE9()
     {
-  signed int v0; // edi@1
-  signed int v1; // esi@4
-  int *v2; // ecx@7
-  int *v3; // eax@7
-  signed int v4; // edx@7
-  int v5; // edx@13
-  signed int v6; // ecx@13
-  signed int v7; // eax@13
+
+  signed int j; // edx@7
+  int card_id_counter; // edx@13
+  signed int i; // ecx@13
+  signed int card_dispenser_counter; // eax@13
 
   amuint_4FAA6C = dword_505890;
   sub_409BE8();
-  for(v0=0; v0<2; ++v0 )
+  for(i=0; i<2; ++i )
   {
-    if ( v0 )
+    if ( i )
     {
-      inv_strcpy(pArcomageGame->pPlayer2Name, am_Players[1].pPlayerName);
+      strcpy(am_Players[1].pPlayerName, pArcomageGame->pPlayer2Name);
       if ( byte_4E185C )
         am_Players[1].field_20 = 0;
       else
@@ -1635,42 +1635,41 @@
     }
     else
     {
-      inv_strcpy(pArcomageGame->pPlayer1Name, am_Players[0].pPlayerName);
+      strcpy(am_Players[0].pPlayerName, pArcomageGame->pPlayer1Name);
       am_Players[0].field_20 = 1;
     }
-    am_Players[v0].field_24 = amuint_4E1860;
-    am_Players[v0].field_28 = amuint_4E1864;
-    am_Players[v0].field_2C = amuint_4E1868;
-    am_Players[v0].field_30 = amuint_4E186C;
-    am_Players[v0].field_34 = amuint_4E1870;
-    am_Players[v0].field_38 = amuint_505884;
-    am_Players[v0].field_3C = amuint_505888;
-    am_Players[v0].field_40 = amuint_50588C;
-
-    for (v4=0; v4<10; ++v4 )
+    am_Players[i].field_24 = amuint_4E1860;
+    am_Players[i].field_28 = amuint_4E1864;
+    am_Players[i].field_2C = amuint_4E1868;
+    am_Players[i].field_30 = amuint_4E186C;
+    am_Players[i].field_34 = amuint_4E1870;
+    am_Players[i].field_38 = amuint_505884;
+    am_Players[i].field_3C = amuint_505888;
+    am_Players[i].field_40 = amuint_50588C;
+
+    for (j=0; j<10; ++j )
     {
-      am_Players[v0].cards_at_hand[v4] = -1;
+      am_Players[i].cards_at_hand[j] = -1;
       if ( am_byte_4E185D )
       {
-        am_Players[v0].arr_6C[v4].field_0 = -1;
-        am_Players[v0].arr_6C[v4].field_4 = -1;
+        am_Players[i].arr_6C[j].field_0 = -1;
+        am_Players[i].arr_6C[j].field_4 = -1;
       }
       else
       {
-      am_Players[v0].arr_6C[v4].field_0 = 0;
-      am_Players[v0].arr_6C[v4].field_4 = 0;
+      am_Players[i].arr_6C[j].field_0 = 0;
+      am_Players[i].arr_6C[j].field_4 = 0;
       }
     }
    
   }
-
-
-  inv_strcpy(pDeckMaster, byte_5054C8);
-  for (v6=0, v7=-2, v5=0; v6<108; ++v6, ++v7)
+ // inv_strcpy(pDeckMaster, byte_5054C8);
+  strcpy(deckMaster.name, pDeckMaster);
+  for (i=0, card_dispenser_counter=-2, card_id_counter=0; i<DECK_SIZE; ++i, ++card_dispenser_counter)
       {
-      byte_5054E8[v6] = 0;
-      dword_505554[v6] =v5;
-      switch ( v7 )
+      deckMaster.cardsInUse[i] = 0;
+      deckMaster.cards_IDs[i] =card_id_counter;
+      switch ( card_dispenser_counter )
           {
       case 0:
       case 2:
@@ -1695,94 +1694,63 @@
       case 89:
           break;
       default:
-          ++v5;
+          ++card_id_counter;
           }
       }
 
    am_40A198();
 }
-// 4E185C: using guessed type char byte_4E185C;
-// 4E185D: using guessed type char am_byte_4E185D;
-// 4E1860: using guessed type int amuint_4E1860;
-// 4E1864: using guessed type int amuint_4E1864;
-// 4E1868: using guessed type int amuint_4E1868;
-// 4E186C: using guessed type int amuint_4E186C;
-// 4E1870: using guessed type int amuint_4E1870;
-// 505554: using guessed type int dword_505554[];
-// 505884: using guessed type int amuint_505884;
-// 505888: using guessed type int amuint_505888;
-// 50588C: using guessed type int amuint_50588C;
-// 505890: using guessed type int dword_505890;
 
 //----- (0040A198) --------------------------------------------------------
-char __cdecl am_40A198()
-{
-  int *v0; // edi@1
-  int *v1; // edx@2
-  signed int v2; // esi@2
+void am_40A198()
+    {
+ 
   signed int v3; // eax@4
-  signed int v4; // esi@12
-  int v5; // eax@13
   int v6; // edx@13
-  char *v7; // eax@13
-  char result; // al@14
-  char v9[108]; // [sp+8h] [bp-6Ch]@1
+  char v7; // eax@13
+  char card_taken_flags[DECK_SIZE]; // [sp+8h] [bp-6Ch]@1
+  int i,j;
 
   ArcomageGame::PlaySound(0x14u);
-  memset(byte_5054E8, 0, sizeof(byte_5054E8));
-  memset(v9, 0, sizeof(v9));
-  v0 = am_Players[0].cards_at_hand;//variable incorrect
-  do
+  memset(deckMaster.cardsInUse, 0,DECK_SIZE );
+  memset(card_taken_flags, 0, DECK_SIZE);
+
+  for (i=0; i<2; ++i)
   {
-    v1 = v0;
-    v2 = 10;
-    do
+    for (j=0; j<10; ++j)
     {
-      if ( *v1 > -1 )
+      if ( am_Players[i].cards_at_hand[j] > -1 )
       {
-        v3 = 0;
-        while ( dword_505554[v3] != *v1 || byte_5054E8[v3] )
-        {
-          ++v3;
-          if ( v3 >= 108 )
-            goto LABEL_10;
-        }
-        byte_5054E8[v3] = 1;
+        for (v3 = 0; v3<DECK_SIZE; ++v3)
+            {
+            if (deckMaster.cards_IDs[v3] == am_Players[i].cards_at_hand[j] && deckMaster.cardsInUse[v3] == 0)
+                {
+                    deckMaster.cardsInUse[v3] = 1;
+                    break;
+                }
+            }
       }
-LABEL_10:
-      ++v1;
-      --v2;
     }
-    while ( v2 );
-    v0 += 47;
   }
-  while ( (signed int)v0 < 2 );//(signed int)&pArcomageGame->msg.pt.y );
-  v4 = 0;
-  do
+
+  for (i=0; i<DECK_SIZE; ++i)
   {
     do
     {
-      v5 = rand();
-      v6 = v5 % 108;
-      v7 = &v9[v5 % 108];
+      v6 = rand() % DECK_SIZE;
+      v7 = card_taken_flags[v6];
     }
-    while ( *v7 == 1 );
-    *v7 = 1;
-    dword_505314[v4] = dword_505554[v6];
-    result = byte_5054E8[v6];
-    //array_4FABD0[9].field_4[v4++ + 4232] = result;//затирает pArcomageGame
+    while ( v7 == 1 );
+    card_taken_flags[v6]=1;
+    playDeck.cards_IDs[i] = deckMaster.cards_IDs[v6];
+    playDeck.cardsInUse[i] = deckMaster.cardsInUse[v6];
   }
-  while ( v4 < 108 );
+
   dword_4FABC8 = 0;
   amuint_4FABC4 = -1;
   pArcomageGame->field_F6 = 1;
-  return result;
+
 }
-// 4FABC4: using guessed type int amuint_4FABC4;
-// 4FABC8: using guessed type int dword_4FABC8;
-// 505314: using guessed type int dword_505314[];
-// 505554: using guessed type int dword_505554[];
-// 40A198: using guessed type char var_6C[108];
 
 //----- (0040A255) --------------------------------------------------------
 void am_40A255()
@@ -1803,30 +1771,31 @@
   signed int v2; // eax@1
   int v3; // edi@1
   int v4; // esi@1
-  char v5; // bl@1
+  bool v5; // bl@1
   signed int result; // eax@7
   int v7; // esi@8
 
   v2 = dword_4FABC8;
   v3 = a1;
   v4 = a1;
-  v5 = 0;
+  v5 = false;
   do
   {
-    if ( v2 >= 108 )
+    if ( v2 >= DECK_SIZE )
     {
       am_40A198();
       v2 = dword_4FABC8;
     }
-    if ( !byte_5052A8[v2] )
+    if ( !playDeck.cardsInUse[v2] )
         {
-        v3 = dword_505314[v2];
-        v5 = 1;
+        v3 = playDeck.cards_IDs[v2];
+        v5 = true;
         }
     ++v2;
     dword_4FABC8 = v2;
   }
   while ( !v5 );
+
   ArcomageGame::PlaySound(0x15u);
   result = GetEmptyCardSlotIndex(v4);
   if ( result != -1 )
@@ -1875,16 +1844,14 @@
   unsigned __int8 v3; // of@4
   int v4; // eax@6
   char Dest[64]; // [sp+4h] [bp-64h]@4
-  int v6; // [sp+44h] [bp-24h]@6
-  int v7; // [sp+48h] [bp-20h]@6
-  int v8; // [sp+4Ch] [bp-1Ch]@6
-  int v9; // [sp+50h] [bp-18h]@6
+  RECT v6; // [sp+44h] [bp-24h]@6
+ 
   ArcomageGame_stru1 v10; // [sp+54h] [bp-14h]@7
-  int v11[2]; // [sp+60h] [bp-8h]@4
+  POINT v11; // [sp+60h] [bp-8h]@4
 
   if ( !pArcomageGame->field_F4 )
   {
-    if ( LOBYTE(am_Players[0].field_20) != 1 || LOBYTE(am_Players[1].field_20) != 1 )
+    if ( am_Players[0].field_20 != 1 || am_Players[1].field_20 != 1 )
     {
       ++amuint_4FAA6C;
       am_byte_4FAA75 = 1;
@@ -1894,13 +1861,13 @@
     else
     {
       //nullsub_1();
-      v11[0] = 0;
-      v11[1] = 0;
+      v11.x = 0;
+      v11.y = 0;
       inv_strcpy("След", Dest);
       v0 = 0;
-      v11[1] = 200;
-      v11[0] = 320 - 12 * v0 / 2;
-    //  pPrimaryWindow_draws_text(-1, Dest, v11);
+      v11.y = 200;
+      v11.x = 320 - 12 * v0 / 2;
+      pPrimaryWindow_draws_text(-1, Dest, &v11);
       am_byte_4FAA75 = 1;
       v1 = amuint_4FAA6C + 1;
       v3 = __OFSUB__(amuint_4FAA6C + 1, 2);
@@ -1912,13 +1879,13 @@
       }
       inv_strcpy(am_Players[v1].pPlayerName, Dest);
       v4 = 0;
-      v11[1] = 260;
-      v11[0] = 320 - 12 * v4 / 2;
-     // pPrimaryWindow_draws_text(-1, Dest, v11);
-      v6 = 0;
-      v8 = 640;
-      v7 = 0;
-      v9 = 480;
+      v11.y = 260;
+      v11.x = 320 - 12 * v4 / 2;
+      pPrimaryWindow_draws_text(-1, Dest, &v11);
+      v6.left = 0;
+      v6.right = 640;
+      v6.top = 0;
+      v6.bottom = 480;
       //nullsub_1();
       CallRenderPresent();
       //nullsub_1();
@@ -1945,12 +1912,12 @@
       pArcomageGame->field_F4 = 1;
       byte_4FAA74 = 1;
 LABEL_13:
-      v11[0] = 0;
-      v11[1] = 0;
-      v6 = 0;
-      v8 = 640;
-      v7 = 0;
-      v9 = 480;
+      v11.x = 0;
+      v11.y = 0;
+      v6.left = 0;
+      v6.right = 640;
+      v6.top = 0;
+      v6.bottom = 480;
       //nullsub_1();
       CallRenderPresent();
     }
@@ -1994,9 +1961,9 @@
   int v5; // esi@67
   char Dest[100]; // [sp+8h] [bp-A8h]@67
   int v8; // [sp+6Ch] [bp-44h]@3
-  int pSrcXYZW[4]; // [sp+70h] [bp-40h]@75
+  RECT pSrcXYZW; // [sp+70h] [bp-40h]@75
   int v10[4]; // [sp+80h] [bp-30h]@69
-  int pTargetXY[2]; // [sp+90h] [bp-20h]@75
+  POINT pTargetXY; // [sp+90h] [bp-20h]@75
   ArcomageGame_stru1 a2; // [sp+98h] [bp-18h]@8
   int v13; // [sp+A4h] [bp-Ch]@1
   int a1; // [sp+A8h] [bp-8h]@1
@@ -2015,19 +1982,13 @@
     byte_4FAA2D = 1;
   do
   {
-    do
-    {
+   
       do
       {
-        v2 = pEventTimer->Time();
-        v3 = v2 - pArcomageGame->event_timer_time;
-        v8 = HIDWORD(v3);
+        v3 = pEventTimer->Time() - pArcomageGame->event_timer_time;
       }
-      while ( SHIDWORD(v3) < 0 );
-    }
-    while ( SHIDWORD(v2) < (signed int)(((unsigned int)v2 < pArcomageGame->event_timer_time)
-                                      + ((unsigned __int64)pArcomageGame->event_timer_time >> 32)) | HIDWORD(v3) == 0
-         && (unsigned int)v3 < 6 );
+      while (v3 < 6);
+    
     pArcomageGame->event_timer_time = pEventTimer->Time();
     if ( pArcomageGame->field_F4 )
       v16 = 1;
@@ -2046,7 +2007,7 @@
       case 9:
         pArcomageGame->field_F6 = 1;
         break;
-      case 0xA:
+      case 10:
         pAudioPlayer->StopChannels(-1, -1);
         byte_4FAA74 = 1;
         v16 = 1;
@@ -2054,7 +2015,7 @@
         break;
     }
     v4 = amuint_4FAA6C;
-    if ( LOBYTE(am_Players[amuint_4FAA6C].field_20) != 1 && !byte_4FAA00 && !byte_4FAA2E && !byte_4FAA2D )
+    if (am_Players[amuint_4FAA6C].field_20 != 1 && !byte_4FAA00 && !byte_4FAA2E && !byte_4FAA2D )
     {
       if ( am_byte_4FAA75 )
         am_byte_4FAA76 = 1;
@@ -2064,7 +2025,7 @@
     }
     if ( amuint_4FAA4C != -1 && amuint_4FAA38 > 10 )
       amuint_4FAA38 = 10;
-    if ( byte_4FAA2E || byte_4FAA2D || LOBYTE(am_Players[v4].field_20) != 1 )
+    if ( byte_4FAA2E || byte_4FAA2D ||am_Players[v4].field_20 != 1 )
     {
       pArcomageGame->field_F6 = 1;
       if ( byte_4FAA2D )
@@ -2173,17 +2134,17 @@
         pArcomageGame->field_F4 = 1;
         dword_4FAA68 = 0;
       }
-      v10[0] = 0;
+      /*v10[0] = 0;
       v10[2] = 640;
       v10[1] = 0;
-      v10[3] = 480;
+      v10[3] = 480;*/
       //nullsub_1();
     }
-    if ( dword_4FABB8 != am_40BB67(a1) )
+    /* if ( dword_4FABB8 != am_40BB67(a1) )
     {
-      dword_4FABB8 = am_40BB67(a1);
-      pArcomageGame->field_F6 = 1;
-    }
+    dword_4FABB8 = am_40BB67(a1);
+    pArcomageGame->field_F6 = 1;
+    }*/
     if ( pArcomageGame->field_F6 )
     {
       am_blts(v13);
@@ -2192,14 +2153,14 @@
     }
     if ( pArcomageGame->field_F9 )
     {
-      pTargetXY[0] = 0;
-      pTargetXY[1] = 0;
-      pSrcXYZW[0] = 0;
-      pSrcXYZW[2] = 640;
-      pSrcXYZW[1] = 0;
-      pSrcXYZW[3] = 480;
+      pTargetXY.x = 0;
+      pTargetXY.y = 0;
+      pSrcXYZW.left = 0;
+      pSrcXYZW.right = 640;
+      pSrcXYZW.top = 0;
+      pSrcXYZW.bottom = 480;
       am_BeginScene(pArcomageGame->pBackgroundPixels, -1, 1);
-    //  Blt_Copy(pSrcXYZW, pTargetXY, 2);
+      Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
       am_EndScene();
       am_blts(v13);
       pRenderer->Present();
@@ -2209,21 +2170,7 @@
   while ( !v16 );
   return dword_4FAA68 > 0;
 }
-// 40DB22: using guessed type uint __stdcall unk__const_0(uint, uint);
-// 4E1874: using guessed type int dword_4E1874;
-// 4FAA00: using guessed type char byte_4FAA00;
-// 4FAA2D: using guessed type char byte_4FAA2D;
-// 4FAA2E: using guessed type char byte_4FAA2E;
-// 4FAA34: using guessed type int amuint_4FAA34;
-// 4FAA38: using guessed type int amuint_4FAA38;
-// 4FAA4C: using guessed type int amuint_4FAA4C;
-// 4FAA64: using guessed type int dword_4FAA64;
-// 4FAA68: using guessed type int dword_4FAA68;
-// 4FAA74: using guessed type char byte_4FAA74;
-// 4FAA75: using guessed type char am_byte_4FAA75;
-// 4FAA76: using guessed type char am_byte_4FAA76;
-// 4FAA77: using guessed type char am_byte_4FAA77;
-// 4FABB8: using guessed type int dword_4FABB8;
+
 
 //----- (0040A9AF) --------------------------------------------------------
 void am_blts( int a1 )
@@ -2502,279 +2449,246 @@
 // 4FAA77: using guessed type char am_byte_4FAA77;
 
 //----- (0040B102) --------------------------------------------------------
-void __fastcall am_40B102( int a1, char *a2, POINT *pXY )
+void am_40B102( int a1, char *text, POINT *pXY )
     {
-  //char *v3; // esi@1
-  //int v4; // eax@1
-  //unsigned __int8 v5; // bl@2
-  //char v6; // zf@2
-  //int v7; // eax@3
-  //int v8; // ecx@3
-  //int v9; // [sp+8h] [bp-18h]@3
-  //int v10; // [sp+Ch] [bp-14h]@3
-  //int v11; // [sp+10h] [bp-10h]@3
-  //int v12; // [sp+14h] [bp-Ch]@3
-  //int v13; // [sp+18h] [bp-8h]@1
-  //int v14; // [sp+1Ch] [bp-4h]@1
-
-  //v3 = a2;
-  //am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-  //v4 = pXY[1];
-  //v13 = *pXY;
-  //v14 = v4;
-  //do
-  //{
-  //  v5 = *v3++;
-  //  v6 = v5 == 0;
-  //  if ( v5 )
-  //  {
-  //    v7 = 22 * v5;
-  //    v8 = v7 - 864;
-  //    v7 -= 842;
-  //    v11 = v7;
-  //    LOWORD(v7) = pArcomageGame->field_54;
-  //    v9 = v8;
-  //    v10 = 190;
-  //    v12 = 207;
-  //    Blt_Chroma(&v9, &v13, v7, 1);
-  //    v13 += 22;
-  //    v6 = v5 == 0;
-  //  }
-  //}
-  //while ( !v6 );
-  //am_EndScene();
+  char *v3; // esi@1
+  unsigned char test_char; // bl@2
+  int v7; // eax@3
+  RECT pSrcRect;
+  POINT pTargetPoint;
+
+  v3 = text;
+  am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+  pTargetPoint.x = pXY->x;
+  pTargetPoint.y = pXY->y;
+  do
+  {
+    test_char = *v3;
+    ++v3;
+    if ( test_char )
+    {
+      v7 = 22 * test_char;
+      pSrcRect.right = v7 - 842;
+      pSrcRect.left = v7 - 864;
+      pSrcRect.top = 190;
+      pSrcRect.bottom = 207;
+      Blt_Chroma(&pSrcRect, &pTargetPoint, pArcomageGame->field_54, 1);
+      pTargetPoint.x += 22;
+    }
+  }
+  while ( test_char!= 0 );
+  am_EndScene();
 }
 
 //----- (0040B17E) --------------------------------------------------------
-void am_40B17E( int a1, char* a2, POINT *pXY )
+void am_40B17E( int a1, char* text, POINT *pXY )
     {
-  //int v3; // esi@1
-  //int v4; // eax@1
-  //unsigned __int8 v5; // bl@2
-  //char v6; // zf@2
-  //int v7; // eax@3
-  //int v8; // [sp+8h] [bp-18h]@3
-  //int v9; // [sp+Ch] [bp-14h]@3
-  //int v10; // [sp+10h] [bp-10h]@3
-  //int v11; // [sp+14h] [bp-Ch]@3
-  //int v12; // [sp+18h] [bp-8h]@1
-  //int v13; // [sp+1Ch] [bp-4h]@1
-
-  //v3 = a2;
-  //am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-  //v4 = pXY[1];
-  //v12 = *pXY;
-  //v13 = v4;
-  //do
-  //{
-  //  v5 = *(unsigned char *)v3++;
-  //  v6 = v5 == 0;
-  //  if ( v5 )
-  //  {
-  //    v7 = 13 * v5;
-  //    v8 = v7 - 370;
-  //    v10 = v7 - 357;
-  //    v9 = 128;
-  //    v11 = 138;
-  //    Blt_Copy(&v8, &v12, 2);
-  //    v12 += 13;
-  //    v6 = v5 == 0;
-  //  }
-  //}
-  //while ( !v6 );
-  //am_EndScene();
+
+    char *v3; // esi@1
+    unsigned char test_char; // bl@2
+    int v7; // eax@3
+    RECT pSrcRect;
+    POINT pTargetPoint;
+
+    v3 = text;
+    am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+    pTargetPoint.x = pXY->x;
+    pTargetPoint.y = pXY->y;
+    do
+        {
+        test_char = *v3;
+        ++v3;
+        if ( test_char )
+            {
+            v7 = 13 * test_char;
+            pSrcRect.right = v7 - 370;
+            pSrcRect.left = v7 - 357;
+            pSrcRect.top = 128;
+            pSrcRect.bottom = 138;
+            Blt_Copy(&pSrcRect, &pTargetPoint, 2);
+            pTargetPoint.x += 13;
+            }
+        }
+        while ( test_char!= 0 );
+        am_EndScene();
+
 }
 
 //----- (0040B1F3) --------------------------------------------------------
-void am_40B1F3( int a1, char* a2, POINT* a3 )
+void am_40B1F3( int a1, char* text, POINT* pXY )
     {
-  //int v3; // esi@1
-  //int v4; // eax@1
-  //unsigned __int8 v5; // bl@2
-  //char v6; // zf@2
-  //int v7; // eax@3
-  //int v8; // [sp+8h] [bp-18h]@3
-  //int v9; // [sp+Ch] [bp-14h]@3
-  //int v10; // [sp+10h] [bp-10h]@3
-  //int v11; // [sp+14h] [bp-Ch]@3
-  //int v12; // [sp+18h] [bp-8h]@1
-  //int v13; // [sp+1Ch] [bp-4h]@1
-
-  //v3 = a2;
-  //am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-  //v4 = *(unsigned int *)(a3 + 4);
-  //v12 = *(unsigned int *)a3;
-  //v13 = v4;
-  //do
-  //{
-  //  v5 = *(unsigned char *)v3++;
-  //  v6 = v5 == 0;
-  //  if ( v5 )
-  //  {
-  //    v7 = 13 * v5;
-  //    v8 = v7 - 370;
-  //    v10 = v7 - 357;
-  //    v9 = 138;
-  //    v11 = 148;
-  //    Blt_Copy(&v8, &v12, 2);
-  //    v12 += 13;
-  //    v6 = v5 == 0;
-  //  }
-  //}
-  //while ( !v6 );
-  //am_EndScene();
+
+    char *v3; // esi@1
+    unsigned char test_char; // bl@2
+    int v7; // eax@3
+    RECT pSrcRect;
+    POINT pTargetPoint;
+
+    v3 = text;
+    am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+    pTargetPoint.x = pXY->x;
+    pTargetPoint.y = pXY->y;
+    do
+        {
+        test_char = *v3;
+        ++v3;
+        if ( test_char )
+            {
+            v7 = 13 * test_char;
+            pSrcRect.right = v7 - 370;
+            pSrcRect.left = v7 - 357;
+            pSrcRect.top = 138;
+            pSrcRect.bottom = 148;
+            Blt_Copy(&pSrcRect, &pTargetPoint, 2);
+            pTargetPoint.x += 13;
+            }
+        }
+        while ( test_char!= 0 );
+        am_EndScene();
+  
 }
 
 //----- (0040B268) --------------------------------------------------------
-void am_40B268( int a1, char *a2, POINT *pXY )
+void am_40B268( int a1, char *text, POINT *pXY )
     {
-  //char *v3; // esi@1
-  //int v4; // eax@1
-  //unsigned __int8 v5; // bl@2
-  //char v6; // zf@2
-  //int v7; // eax@3
-  //int v8; // [sp+8h] [bp-18h]@3
-  //int v9; // [sp+Ch] [bp-14h]@3
-  //int v10; // [sp+10h] [bp-10h]@3
-  //int v11; // [sp+14h] [bp-Ch]@3
-  //int v12; // [sp+18h] [bp-8h]@1
-  //int v13; // [sp+1Ch] [bp-4h]@1
-
-  //v3 = a2;
-  //am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
-  //v4 = pXY[1];
-  //v12 = *pXY;
-  //v13 = v4;
-  //do
-  //{
-  //  v5 = *v3++;
-  //  v6 = v5 == 0;
-  //  if ( v5 )
-  //  {
-  //    v7 = 13 * v5;
-  //    v8 = v7 - 370;
-  //    v10 = v7 - 357;
-  //    v9 = 148;
-  //    v11 = 158;
-  //    Blt_Copy(&v8, &v12, 2);
-  //    v12 += 13;
-  //    v6 = v5 == 0;
-  //  }
-  //}
-  //while ( !v6 );
-  //am_EndScene();
+
+    char *v3; // esi@1
+    unsigned char test_char; // bl@2
+    int v7; // eax@3
+    RECT pSrcRect;
+    POINT pTargetPoint;
+
+    v3 = text;
+    am_BeginScene(pArcomageGame->pSpritesPixels, -1, 1);
+    pTargetPoint.x = pXY->x;
+    pTargetPoint.y = pXY->y;
+    do
+        {
+        test_char = *v3;
+        ++v3;
+        if ( test_char )
+            {
+            v7 = 13 * test_char;
+            pSrcRect.right = v7 - 370;
+            pSrcRect.left = v7 - 357;
+            pSrcRect.top = 148;
+            pSrcRect.bottom = 158;
+            Blt_Copy(&pSrcRect, &pTargetPoint, 2);
+            pTargetPoint.x += 13;
+            }
+        }
+        while ( test_char!= 0 );
+        am_EndScene();
+
 }
 
 //----- (0040B2DD) --------------------------------------------------------
 void __cdecl am_chroma_and_copy_blts()
 {
-  //int v0; // eax@1
-  //int v1; // esi@3
-  //int v2; // eax@3
-  //int v3; // eax@3
-  //int v4; // esi@5
-  //int v5; // eax@5
-  //int pSrcXYZW[4]; // [sp+0h] [bp-18h]@3
-  //int v7; // [sp+4h] [bp-14h]@3
-  //int v8; // [sp+8h] [bp-10h]@3
-  //int v9; // [sp+Ch] [bp-Ch]@3
-  //int pTargetXY[2]; // [sp+10h] [bp-8h]@3
-
-  //v0 = stru_505708[0].field_24;
-  //if ( stru_505708[0].field_24 > dword_4E1884 )
-  //  v0 = dword_4E1884;
-  //v7 = 0;
-  //pSrcXYZW[0] = 892;
-  //v8 = 937;
-  //pTargetXY[0] = 102;
-  //v1 = 200 * v0 / dword_4E1884;
-  //v9 = v1;
-  //pTargetXY[1] = 297 - v1;
-  //Blt_Copy(pSrcXYZW, pTargetXY, 2);
-  //v7 = 0;
-  //v2 = 203 - v1;
-  //pTargetXY[1] = 203 - v1;
-  //LOWORD(v2) = pArcomageGame->field_54;
-  //pSrcXYZW[0] = 384;
-  //v8 = 452;
-  //v9 = 94;
-  //pTargetXY[0] = 91;
-  //Blt_Chroma(pSrcXYZW, pTargetXY, v2, 2);
-  //v3 = stru_505708[1].field_24;
-  //if ( stru_505708[1].field_24 > dword_4E1884 )
-  //  v3 = dword_4E1884;
-  //v7 = 0;
-  //pSrcXYZW[0] = 892;
-  //v8 = 937;
-  //pTargetXY[0] = 494;
-  //v4 = 200 * v3 / dword_4E1884;
-  //v9 = v4;
-  //pTargetXY[1] = 297 - v4;
-  //Blt_Copy(pSrcXYZW, pTargetXY, 2);
-  //LOWORD(v5) = pArcomageGame->field_54;
-  //pSrcXYZW[0] = 384;
-  //v8 = 452;
-  //v7 = 94;
-  //v9 = 188;
-  //pTargetXY[0] = 483;
-  //pTargetXY[1] = 203 - v4;
-  //Blt_Chroma(pSrcXYZW, pTargetXY, v5, 2);
+
+int v0; // eax@1
+int v1; // esi@3
+int v2; // eax@3
+int v3; // eax@3
+int v4; // esi@5
+int v5; // eax@5
+RECT pSrcXYZW; // [sp+0h] [bp-18h]@3
+POINT pTargetXY; // [sp+10h] [bp-8h]@3
+
+v0= am_Players[0].field_24;
+if ( am_Players[0].field_24 > dword_4E1884 )
+      v0 = dword_4E1884;
+pSrcXYZW.top = 0;
+pSrcXYZW.left = 892;
+pSrcXYZW.right = 937;
+v1 = 200 * v0 / dword_4E1884;
+pSrcXYZW.bottom = v1;
+pTargetXY.x = 102;
+pTargetXY.y = 297 - v1;
+Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
+
+pSrcXYZW.top = 0;
+pSrcXYZW.left = 384;
+pSrcXYZW.right = 452;
+pSrcXYZW.bottom = 94;
+pTargetXY.y = 203 - v1;
+pTargetXY.x = 91;
+Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+
+v3 = am_Players[1].field_24;
+if (am_Players[1].field_24  > dword_4E1884 )
+    v3 = dword_4E1884;
+pSrcXYZW.top = 0;
+pSrcXYZW.left = 892;
+pSrcXYZW.right = 937;
+v4 = 200 * v3 / dword_4E1884;
+pSrcXYZW.bottom = v4;
+pTargetXY.x = 494;
+pTargetXY.y = 297 - v4;
+Blt_Copy(&pSrcXYZW, &pTargetXY, 2);
+
+pSrcXYZW.left = 384;
+pSrcXYZW.right = 452;
+pSrcXYZW.top = 94;
+pSrcXYZW.bottom = 188;
+pTargetXY.x = 483;
+pTargetXY.y = 203 - v4;
+Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+ 
 }
 // 4E1884: using guessed type int dword_4E1884;
 
 //----- (0040B400) --------------------------------------------------------
 void __cdecl am_chroma_blt()
 {
-//  int v0; // eax@1
-//  int v1; // eax@4
-//  int v2; // ecx@4
-//  int v3; // eax@5
-//  int v4; // eax@8
-//  int v5; // esi@8
-//  int pSrcXYZW[4]; // [sp+4h] [bp-18h]@4
-//  int pTargetXY[2]; // [sp+14h] [bp-8h]@4
-//
-//  v0 = stru_505708[0].field_28;
-//  if ( stru_505708[0].field_28 <= 100 )
-//  {
-//    if ( stru_505708[0].field_28 <= 0 )
-//      goto LABEL_5;
-//  }
-//  else
-//  {
-//    v0 = 100;
-//  }
-//  pSrcXYZW[1] = 0;
-//  pSrcXYZW[0] = 843;
-//  v1 = 200 * v0 / 100;
-//  pSrcXYZW[2] = 867;
-//  pTargetXY[0] = 177;
-//  pSrcXYZW[3] = v1;
-//  v2 = 297 - v1;
-//  LOWORD(v1) = pArcomageGame->field_54;
-//  pTargetXY[1] = v2;
-//  Blt_Chroma(pSrcXYZW, pTargetXY, v1, 2);
-//LABEL_5:
-//  v3 = stru_505708[1].field_28;
-//  if ( stru_505708[1].field_28 <= 100 )
-//  {
-//    if ( stru_505708[1].field_28 <= 0 )
-//      return;
-//  }
-//  else
-//  {
-//    v3 = 100;
-//  }
-//  pSrcXYZW[1] = 0;
-//  pSrcXYZW[0] = 843;
-//  v4 = 200 * v3 / 100;
-//  pSrcXYZW[2] = 867;
-//  pTargetXY[0] = 439;
-//  pSrcXYZW[3] = v4;
-//  v5 = 297 - v4;
-//  LOWORD(v4) = pArcomageGame->field_54;
-//  pTargetXY[1] = v5;
-//  Blt_Chroma(pSrcXYZW, pTargetXY, v4, 2);
+int v0; // eax@1
+int v1; // eax@4
+LONG v2; // ecx@4
+int v3; // eax@5
+int v4; // eax@8
+LONG v5; // esi@8
+RECT pSrcXYZW; // [sp+4h] [bp-18h]@4
+POINT pTargetXY; // [sp+14h] [bp-8h]@4
+
+v0 = am_Players[0].field_28;
+if ( am_Players[0].field_28 <= 100 )
+    {
+    if ( am_Players[0].field_28 <= 0 )
+        goto LABEL_5;
+    }
+else
+    {
+    v0 = 100;
+    }
+pSrcXYZW.top = 0;
+pSrcXYZW.left = 843;
+v1 = 200 * v0 / 100;
+pSrcXYZW.right = 867;
+pSrcXYZW.bottom = v1;
+pTargetXY.x = 177;
+pTargetXY.y = 297 - v1;
+Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+
+LABEL_5:
+v3 = am_Players[1].field_28;
+if ( am_Players[1].field_28 <= 100 )
+    {
+    if ( am_Players[1].field_28 <= 0 )
+        return;
+    }
+else
+    {
+    v3 = 100;
+    }
+pSrcXYZW.top = 0;
+pSrcXYZW.left = 843;
+v4 = 200 * v3 / 100;
+pSrcXYZW.right = 867;
+pSrcXYZW.bottom = v4;
+pTargetXY.x = 439;
+pTargetXY.y =  297 - v4;
+Blt_Chroma(&pSrcXYZW, &pTargetXY, pArcomageGame->field_54, 2);
+
 }
 
 //----- (0040B4B9) --------------------------------------------------------
@@ -3202,137 +3116,268 @@
 //----- (0040BB67) --------------------------------------------------------
 signed int __fastcall am_40BB67(int a1)
 {
-  int v1; // esi@1
-  signed int result; // eax@1
-  int v3; // ebx@1
-  char v4; // zf@1
-  int v5; // eax@3
-  int v6; // eax@4
-  int v7; // ecx@6
-  char *v8; // eax@6
-  int v9; // eax@10
-  int v10; // ecx@10
-  int v11; // eax@10
-  char v12; // ch@2@11
-  int v13; // ST00_4@12
-  unsigned __int16 v14; // ax@12
-  int v15; // eax@13
-  int v16; // ecx@13
-  int v17; // eax@13
-  char v18; // al@16
-  char v19; // ch@2@16
-  int v20; // ST00_4@19
-  unsigned __int16 v21; // ax@19
-  int pXYZW[4]; // [sp+Ch] [bp-3Ch]@3
-  stru273 v26; // [sp+1Ch] [bp-2Ch]@2
-  int a1a; // [sp+28h] [bp-20h]@1
-  int v25; // [sp+2Ch] [bp-1Ch]@3
-  int var18; // [sp+30h] [bp-18h]@3
-  int i; // [sp+34h] [bp-14h]@4
-  int v28; // [sp+38h] [bp-10h]@1
-  int a2; // [sp+3Ch] [bp-Ch]@3
-  int v30; // [sp+40h] [bp-8h]@1
-  char v31; // [sp+44h] [bp-4h]@12
-  char v32; // [sp+45h] [bp-3h]@12
-  char v33; // [sp+46h] [bp-2h]@12
-
-  v1 = a1;
-  v30 = 0;
-  result = -1;
-  v3 = 188 * a1;
-  a1a = a1;
-  v4 = LOBYTE(am_Players[a1].field_20) == 0;
-  v28 = -1;
-  if ( !v4 )
-  {
+
+
+int v1; // esi@1
+signed int result; // eax@1
+int v3; // ebx@1
+char v4; // zf@1
+int v5; // eax@3
+int v6; // eax@4
+int v7; // ecx@6
+char *v8; // eax@6
+int v9; // eax@10
+int v10; // ecx@10
+int v11; // eax@10
+char v12; // ch@2@11
+int v13; // ST00_4@12
+unsigned __int16 v14; // ax@12
+int v15; // eax@13
+int v16; // ecx@13
+int v17; // eax@13
+char v18; // al@16
+char v19; // ch@2@16
+int v20; // ST00_4@19
+unsigned __int16 v21; // ax@19
+RECT pXYZW; // [sp+Ch] [bp-3Ch]@3
+stru273 v26; // [sp+1Ch] [bp-2Ch]@2
+int player_num; // [sp+28h] [bp-20h]@1
+int v25; // [sp+2Ch] [bp-1Ch]@3
+__int32 var18; // [sp+30h] [bp-18h]@3
+int i; // [sp+34h] [bp-14h]@4
+int v28; // [sp+38h] [bp-10h]@1
+int hand_index; // [sp+3Ch] [bp-Ch]@3
+int v30; // [sp+40h] [bp-8h]@1
+char v31; // [sp+44h] [bp-4h]@12
+char v32; // [sp+45h] [bp-3h]@12
+char v33; // [sp+46h] [bp-2h]@12
+
+v1 = a1;
+v30 = 0;
+result = -1;
+//v3 = 188 * a1;
+player_num = a1;
+//v4 = LOBYTE(am_Players[a1].field_20) == 0;
+v28 = -1;
+if ( am_Players[a1].field_20 )
+    {
     if ( v26._40DD2F() )
-    {
-      v5 = GetPlayerHandCardCount(v1);
-      a2 = 0;
-      v25 = v5;
-      pXYZW[1] = 327;
-      pXYZW[3] = 455;
-      pXYZW[0] = (640 - 96 * v5) / (v5 + 1);
-      var18 = pXYZW[0] + 96;
-      pXYZW[2] = pXYZW[0] + 96;
-      if ( v5 > 0 )
-      {
-        v6 = 47 * v1;
-        for ( i = 47 * v1; ; v6 = i )
         {
-          v7 = v30;
-          v8 = (char *)&am_Players[0].cards_at_hand[v30 + v6];
-          if ( *(unsigned int *)v8 == -1 )
-          {
-            do
+        v5 = GetPlayerHandCardCount(v1);
+        hand_index = 0;
+        v25 = v5;
+        pXYZW.top = 327;
+        pXYZW.bottom = 455;
+        pXYZW.left = (640 - 96 * v5) / (v5 + 1);
+        var18 = pXYZW.left + 96;
+        pXYZW.right = pXYZW.left + 96;
+        if ( v5 > 0 )
             {
-              v8 += 4;
-              ++v7;
+           // v6 = 47 * v1;
+            for ( i = 47 * v1; ; v6 = i )
+                {
+                v7 = v30;
+              //  v8 = &am_Players[0].cards_at_hand[v30 + v6];
+
+                for (v7=0; v7<10; ++v7)
+                    {
+                    if (am_Players[v1].cards_at_hand[v7]!= -1 )
+                        break;
+                    }
+                //if ( *v8 )
+                //    {
+                //    do
+                //        {
+                //        //v8 += 4;
+                //        ++v7;
+                //        }
+                //        while ( *v8 == -1 );
+                        v30 = v7;
+                  //  }
+                if ( am_byte_4E185D )
+                    {
+                 //   v9 = v3 + 8 * v7;
+                    v10 = am_Players[v1].arr_6C[v7].field_0;//*(am_player[0].arr_6C[0] + v9);
+                    v11 = am_Players[v1].arr_6C[v7].field_4;//*(&am_player[0].arr_6C[0][1] + v9);
+                    pXYZW.left += v10;
+                    pXYZW.right += v10;
+                    pXYZW.top += v11;
+                    pXYZW.bottom += v11;
+                    }
+                if (v26.Inside(&pXYZW) )
+                    break;
+           
+                v13=0;
+                v14 = R8G8B8_to_TargetFormat(v13);
+                DrawRect(&pXYZW, v14, 0);
+                pXYZW.left += var18;
+                pXYZW.right += var18;
+                if ( am_byte_4E185D )
+                    {
+                    v16 = am_Players[v1].arr_6C[v30].field_0;//*(am_player[0].arr_6C[0] + v15);
+                    v17 = am_Players[v1].arr_6C[v30].field_4;//*(&am_player[0].arr_6C[0][1] + v15);
+                    pXYZW.left -= v16;
+                    pXYZW.right -= v16;
+                    pXYZW.top -= v17;
+                    pXYZW.bottom -= v17;
+                    }
+                ++v30;
+                ++hand_index;
+                if ( hand_index >= v25 )
+                    return v28;
+                }
+            v28 = hand_index;
+            v18 = am_40BF15(player_num, hand_index);
+            if ( v18 )
+                {
+                 v20=0x00FFFFFF;
+                }
+            else
+                {
+                v20=0x000000FF;
+                }
+           
+            v21 = R8G8B8_to_TargetFormat(v20);
+            DrawRect(&pXYZW, v21, 0);
             }
-            while ( *(unsigned int *)v8 == -1 );
-            v30 = v7;
-          }
-          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);
-            pXYZW[0] += v10;
-            pXYZW[2] += v10;
-            pXYZW[1] += v11;
-            pXYZW[3] += v11;
-          }
-          if ( true)//v26.Inside(pXYZW) )
-            break;
-          v31 = 0;
-          v32 = 0;
-          v33 = 0;
-          BYTE3(v13) = v12;
-          LOWORD(v13) = *(_WORD *)&v31;
-          BYTE2(v13) = 0;
-          v14 = R8G8B8_to_TargetFormat(v13);
-       //   DrawRect(pXYZW, v14, 0);
-          pXYZW[0] += var18;
-          pXYZW[2] += var18;
-          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);
-            pXYZW[0] -= v16;
-            pXYZW[2] -= v16;
-            pXYZW[1] -= v17;
-            pXYZW[3] -= v17;
-          }
-          ++v30;
-          ++a2;
-          if ( a2 >= v25 )
-            goto LABEL_20;
         }
-        v28 = a2;
-        v18 = am_40BF15(a1a, a2);
-        v31 = -1;
-        if ( v18 )
-        {
-          v32 = -1;
-          v33 = -1;
-        }
-        else
-        {
-          v32 = 0;
-          v33 = 0;
-        }
-        BYTE3(v20) = v19;
-        LOWORD(v20) = *(_WORD *)&v31;
-        BYTE2(v20) = v33;
-        v21 = R8G8B8_to_TargetFormat(v20);
-       // DrawRect(pXYZW, v21, 0);
-      }
+    result = v28;
     }
-LABEL_20:
-    result = v28;
-  }
-  return result;
+return result;
+
+
+
+//  int v1; // esi@1
+//  signed int result; // eax@1
+//  int v3; // ebx@1
+//  char v4; // zf@1
+//  int v5; // eax@3
+//  int v6; // eax@4
+//  int v7; // ecx@6
+//  char *v8; // eax@6
+//  int v9; // eax@10
+//  int v10; // ecx@10
+//  int v11; // eax@10
+//  char v12; // ch@2@11
+//  int v13; // ST00_4@12
+//  unsigned __int16 v14; // ax@12
+//  int v15; // eax@13
+//  int v16; // ecx@13
+//  int v17; // eax@13
+//  char v18; // al@16
+//  char v19; // ch@2@16
+//  int v20; // ST00_4@19
+//  unsigned __int16 v21; // ax@19
+//  int pXYZW[4]; // [sp+Ch] [bp-3Ch]@3
+//  stru273 v26; // [sp+1Ch] [bp-2Ch]@2
+//  int a1a; // [sp+28h] [bp-20h]@1
+//  int v25; // [sp+2Ch] [bp-1Ch]@3
+//  int var18; // [sp+30h] [bp-18h]@3
+//  int i; // [sp+34h] [bp-14h]@4
+//  int v28; // [sp+38h] [bp-10h]@1
+//  int a2; // [sp+3Ch] [bp-Ch]@3
+//  int v30; // [sp+40h] [bp-8h]@1
+//  char v31; // [sp+44h] [bp-4h]@12
+//  char v32; // [sp+45h] [bp-3h]@12
+//  char v33; // [sp+46h] [bp-2h]@12
+//
+//  v1 = a1;
+//  v30 = 0;
+//  result = -1;
+//  v3 = 188 * a1;
+//  a1a = a1;
+//  v4 = LOBYTE(am_Players[a1].field_20) == 0;
+//  v28 = -1;
+//  if ( !v4 )
+//  {
+//    if ( v26._40DD2F() )
+//    {
+//      v5 = GetPlayerHandCardCount(v1);
+//      a2 = 0;
+//      v25 = v5;
+//      pXYZW[1] = 327;
+//      pXYZW[3] = 455;
+//      pXYZW[0] = (640 - 96 * v5) / (v5 + 1);
+//      var18 = pXYZW[0] + 96;
+//      pXYZW[2] = pXYZW[0] + 96;
+//      if ( v5 > 0 )
+//      {
+//        v6 = 47 * v1;
+//        for ( i = 47 * v1; ; v6 = i )
+//        {
+//          v7 = v30;
+//          v8 = (char *)&am_Players[0].cards_at_hand[v30 + v6];
+//          if ( *(unsigned int *)v8 == -1 )
+//          {
+//            do
+//            {
+//              v8 += 4;
+//              ++v7;
+//            }
+//            while ( *(unsigned int *)v8 == -1 );
+//            v30 = v7;
+//          }
+//          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);
+//            pXYZW[0] += v10;
+//            pXYZW[2] += v10;
+//            pXYZW[1] += v11;
+//            pXYZW[3] += v11;
+//          }
+//          if ( true)//v26.Inside(pXYZW) )
+//            break;
+//          v31 = 0;
+//          v32 = 0;
+//          v33 = 0;
+//          BYTE3(v13) = v12;
+//          LOWORD(v13) = *(_WORD *)&v31;
+//          BYTE2(v13) = 0;
+//          v14 = R8G8B8_to_TargetFormat(v13);
+//       //   DrawRect(pXYZW, v14, 0);
+//          pXYZW[0] += var18;
+//          pXYZW[2] += var18;
+//          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);
+//            pXYZW[0] -= v16;
+//            pXYZW[2] -= v16;
+//            pXYZW[1] -= v17;
+//            pXYZW[3] -= v17;
+//          }
+//          ++v30;
+//          ++a2;
+//          if ( a2 >= v25 )
+//            goto LABEL_20;
+//        }
+//        v28 = a2;
+//        v18 = am_40BF15(a1a, a2);
+//        v31 = -1;
+//        if ( v18 )
+//        {
+//          v32 = -1;
+//          v33 = -1;
+//        }
+//        else
+//        {
+//          v32 = 0;
+//          v33 = 0;
+//        }
+//        BYTE3(v20) = v19;
+//        LOWORD(v20) = *(_WORD *)&v31;
+//        BYTE2(v20) = v33;
+//        v21 = R8G8B8_to_TargetFormat(v20);
+//       // DrawRect(pXYZW, v21, 0);
+//      }
+//    }
+//LABEL_20:
+//    result = v28;
+//  }
+//  return result;
 }
 // 4E185D: using guessed type char am_byte_4E185D;
 
@@ -3353,27 +3398,24 @@
   signed int v13; // edx@9
   unsigned int v14; // eax@12
   char result; // al@12
+  int i;
 
   if ( a2 <= -1 )
-    goto LABEL_16;
+    return 0;
   v2 = 0;
   v3 = 0;
-  v4 = (char *)am_Players[a1].cards_at_hand;
-  do
+
+  for(i=0; i<10; ++i)
   {
-    if ( *(unsigned int *)v4 != -1 )
+    if ( am_Players[a1].cards_at_hand[i] != -1 )
     {
       if ( a2 == v2 )
         break;
       ++v2;
     }
-    ++v3;
-    v4 += 4;
   }
-  while ( v3 < 10 );
-  v5 = v3 + 47 * a1;
-  v6 = 4 * v5 + 5265228;
-  if ( BYTE3(pCards[am_Players[0].cards_at_hand[v5]].field_28) )
+
+  if ( pCards[am_Players[a1].cards_at_hand[i]].field_2B) 
   {
     ArcomageGame::PlaySound(0x16u);
     v7 = amuint_4FAA6C;
@@ -3407,7 +3449,7 @@
   }
   else
   {
-LABEL_16:
+
     result = 0;
   }
   return result;
@@ -5481,15 +5523,11 @@
     {
   int v2; // ebp@1
   POINT *v3; // edi@1
-  char *v4; // ebx@1
   int result; // eax@3
-  unsigned int v6; // esi@7
-  stru272_stru0 *v7; // ecx@10
+  int v6;
   stru272_stru0 *v8; // ecx@12
-  int v9; // edx@17
-  int v10; // ecx@17
   signed int v11; // [sp+10h] [bp-8h]@1
-  stru272_stru0 **v12; // [sp+14h] [bp-4h]@1
+ 
 
   v11 = 0;
   v2 = a2;
@@ -5815,17 +5853,13 @@
 //----- (00409C8B) --------------------------------------------------------
 void __cdecl PrepareArcomage()
 {
-  int v0; // ecx@3
   signed __int64 v1; // qax@4
   int v2; // esi@4
   int v3; // esi@5
   signed int v4; // edi@5
-  stru272 *v5; // esi@7
   int v6; // edx@9
-  int v7; // ecx@9
   RECT pXYZW; // [sp+8h] [bp-1Ch]@5
   POINT pXY; // [sp+18h] [bp-Ch]@5
-  int v10; // [sp+20h] [bp-4h]@3
 
   pAudioPlayer->StopChannels(-1, -1);
   strcpy(pArcomageGame->pPlayer1Name, pArcomagePlayer1Name);
@@ -5877,7 +5911,7 @@
   byte_505880 = 0;
   dword_4FAA70 = 0;
   am_byte_4FAA77 = 0;
- // am_409FE9();
+  am_409FE9();
   am_40A255();
   //nullsub_1();
   pArcomageGame->field_F5 = 0;
--- a/Arcomage.h	Fri Jun 07 13:43:24 2013 +0600
+++ b/Arcomage.h	Sat Jun 08 01:19:15 2013 +0400
@@ -277,22 +277,17 @@
 };
 #pragma pack(pop)
 
+#define DECK_SIZE 108
 
-/*  266 */
-//#pragma pack(push, 1)
-//struct stru272
-//{
-//  void _40DFD1();
-//
-//  struct stru272_stru0 *ptr_0;
-//  char field_4[4264];
-//};
-//#pragma pack(pop)
+#pragma pack(push, 1)
+struct ArcomageDeck
+    {
+    char name[32];
+    char cardsInUse[DECK_SIZE];
+    int cards_IDs[DECK_SIZE];
+    };
 
-
-
-
-
+#pragma pack(pop)
 
 #pragma pack(push, 1)
 struct stru272
@@ -302,21 +297,6 @@
     char field_2;
     char field_3;
     stru272_stru2 field_4;
-    /*int field_4;
-    int field_8;
-    int field_C;
-    int field_10;
-    int field_14;
-    int field_18;
-    int field_1C;
-    float field_20f;
-    int field_24;
-    float field_28f;
-    float field_2Cf;
-    float field_30f;
-    int field_34;
-    int field_38;
-    stru272_stru1* field_3C;*/
     stru272_stru0 *field_40;
     stru272_stru1 field_44[150];
     };
--- a/Time.cpp	Fri Jun 07 13:43:24 2013 +0600
+++ b/Time.cpp	Sat Jun 08 01:19:15 2013 +0400
@@ -21,7 +21,7 @@
 //----- (00426317) --------------------------------------------------------
 unsigned __int64 Timer::Time()
 {
-  uint v2 = TimeQuant * timeGetTime() / 1000;
+  unsigned __int64 v2 = TimeQuant * timeGetTime() / 1000;
   if (v2 < uStartTime)
     uStartTime = 0;
   return v2;