Damage calculation of server from decompiled code to C

I’m implementing a function for damage calculation based on de-compiled code I tried to rewrite to C.

I just want to know if there are mistakes or there are still ways to improve my code.

This is my code:

unsigned char* dword_4FDE44 = reinterpret_cast<unsigned char*>(0x4FDE44);  unsigned __int16 unk0 = *(WORD *)(a1 + 10042); unsigned char* unk1 = dword_4FDE44 + 372 * unk0;  if (unk1) {     unsigned char* player = sub_473F40(*(WORD *)(a1 + 10059));     unsigned char* monster = sub_43182C(a2);      if (player && monster)     {         bool xDiff = abs(*(WORD *)(monster + 44) - *(WORD *)(a1 + 6)) <= a1[10039];         bool yDiff = abs(*(WORD *)(monster + 46) - *(WORD *)(a1 + 8)) <= a1[10039];         bool isMobAlive = *(DWORD *)(monster + 48) > 0;          if (xDiff && yDiff && isMobAlive)         {             unsigned char* item = sub_45CDC8(*(WORD *)(a1 + 10061));              if (item)             {                 int unk2 = sub_43FA87(player, unk0, monster[608] + 112) & 3;                 int chance = sub_43C915(0, 100);                 int damage = 0;                  if (chance < unk2)                 {                     if (*(BYTE *)(a1 + 4))                     {                         damage = sub_43C915(*(WORD *)(item + 12), *(WORD *)(item + 14));                         if (*(DWORD *)(player + 11524) & 0x200000)                             damage += *((WORD *)dword_4FDE44 + 6721) * damage / 100;                     }                     else                     {                         damage = *(DWORD *)(a1 + 16) - sub_445CA7(*(WORD *)(monster));                     }                     if (damage < 0)                         damage = 0;                      sub_441A30(player, monster, damage);                     sub_444B50(player, monster, damage);                     if (*(DWORD *)(monster + 1256))                         sub_41EF83((void *)(monster + 1256), monster, damage, player, 1);                     *(WORD *)(monster + 572) = *(WORD *)(player + 12);                     *(WORD *)(monster + 568) = *(WORD *)(monster + 572);                     if (unk0 == 114)                         sub_42C243(monster, 13, unk1[32], *((WORD *)unk1 + 42));                 }                 else                 {                     sub_441A30(player, monster, 0);                     if (*(DWORD *)(monster + 1256))                         sub_41EF83((void *)(monster + 1256), monster, 0, player, 1);                     damage = -1;                 }                  if (monster[1077] > 0)                 {                     unsigned char Dst[103];                     memcpy(&Dst, (const void *)(monster + 1077), 103);                      for (int i = 0; i < Dst[0]; ++i)                     {                         if (*(WORD *)(Dst + (2 * i + 1)) == *(WORD *)(player + 12))                         {                             unsigned char buf0[10];                             *(WORD *)(&buf0) = 1370;                             *(WORD *)(&buf0[2]) = a2;                             *(WORD *)(&buf0[4]) = damage;                             *(WORD *)(&buf0[6]) = unk0;                             *(WORD *)(&buf0[8]) = *(WORD *)(a1 + 2);                             sub_412CB0(buf0, 10, *(WORD *)(player + 12));                             *(WORD *)(Dst + (2 * i + 1)) = *(WORD *)(Dst + (2 * Dst[0]-- - 1));                             break;                         }                     }                      unsigned char buf1[8];                     *(WORD *)(&buf1) = 1356;                     *(WORD *)(&buf1[2]) = a2;                     *(WORD *)(&buf1[4]) = unk0;                     *(WORD *)(&buf1[6]) = *(WORD *)(a1 + 2);                     sub_415970(buf1, 8, Dst, *(WORD *)(Dst + 1));                 }             }         }     } } 

And this was my reference:

  int v2; // eax@15   __int16 v3; // [sp+4h] [bp-A8h]@27   unsigned __int16 v4; // [sp+6h] [bp-A6h]@27   __int16 v5; // [sp+8h] [bp-A4h]@27   __int16 v6; // [sp+Ah] [bp-A2h]@27   __int16 v7; // [sp+Ch] [bp-A0h]@27   int i; // [sp+10h] [bp-9Ch]@24   int v9; // [sp+14h] [bp-98h]@9   char *v10; // [sp+18h] [bp-94h]@24   int v11; // [sp+1Ch] [bp-90h]@8   int v12; // [sp+20h] [bp-8Ch]@12   char Dst; // [sp+24h] [bp-88h]@24   int v14; // [sp+8Ch] [bp-20h]@2   int v15; // [sp+90h] [bp-1Ch]@14   char *v16; // [sp+94h] [bp-18h]@1   int v17; // [sp+98h] [bp-14h]@1   int v18; // [sp+9Ch] [bp-10h]@3   int v19; // [sp+A0h] [bp-Ch]@23   __int16 v20; // [sp+A4h] [bp-8h]@23   __int16 v21; // [sp+A6h] [bp-6h]@23   int v22; // [sp+A8h] [bp-4h]@1    v22 = *(_DWORD *)(a1 + 16);   LOWORD(v17) = *(_WORD *)(a1 + 10042);   v16 = (char *)dword_4FDE44 + 372 * (unsigned __int16)v17;   if ( v16 )   {     v14 = sub_473F40(*(_WORD *)(a1 + 10059));     if ( v14 )     {       v18 = (int)sub_43182C(a2);       if ( v18 )       {         if ( abs(*(_WORD *)(v18 + 44) - *(_WORD *)(a1 + 6)) <= *(_BYTE *)(a1 + 10039) )         {           if ( abs(*(_WORD *)(v18 + 46) - *(_WORD *)(a1 + 8)) <= *(_BYTE *)(a1 + 10039) )           {             if ( *(_DWORD *)(v18 + 48) > 0 )             {               v11 = sub_45CDC8(*(_WORD *)(a1 + 10061));               if ( v11 )               {                 v9 = sub_43FA87(v14, v17, *(_BYTE *)(*(_DWORD *)(v18 + 608) + 112) & 3);                 if ( sub_43C915(0, 100) < v9 )                 {                   if ( *(_BYTE *)(a1 + 4) )                   {                     v12 = sub_43C915(*(_WORD *)(v11 + 12), *(_WORD *)(v11 + 14));                     v2 = *(_DWORD *)(v14 + 11524);                     if ( v2 & 0x200000 )                       v12 += *((_WORD *)dword_4FDE44 + 6721) * v12 / 100;                   }                   else                   {                     LOWORD(v15) = sub_445CA7(v18);                     v12 = v22 - (unsigned __int16)v15;                   }                   if ( v12 < 0 )                     v12 = 0;                   sub_441A30(v14, v18, v12);                   sub_444B50(v14, v18, v12);                   if ( *(_DWORD *)(v18 + 1256) )                     sub_41EF83(*(_DWORD *)(v18 + 1256), v18, v12, v14, 1);                   *(_WORD *)(v18 + 572) = *(_WORD *)(v14 + 12);                   *(_WORD *)(v18 + 568) = *(_WORD *)(v18 + 572);                   if ( (unsigned __int16)v17 == 114 )                     sub_42C243(v18, 0xDu, v16[32], *((_WORD *)v16 + 42));                 }                 else                 {                   sub_441A30(v14, v18, 0);                   if ( *(_DWORD *)(v18 + 1256) )                     sub_41EF83(*(_DWORD *)(v18 + 1256), v18, 0, v14, 1);                   v12 = -1;                 }                 LOWORD(v19) = 1356;                 HIWORD(v19) = a2;                 v20 = *(_WORD *)(a1 + 10042);                 v21 = *(_WORD *)(a1 + 2);                 if ( (signed int)*(_BYTE *)(v18 + 1077) > 0 )                 {                   memcpy(&Dst, (const void *)(v18 + 1077), 0x67u);                   v10 = &Dst;                   for ( i = 0; i < (unsigned __int8)*v10; ++i )                   {                     if ( *(_WORD *)&v10[2 * i + 1] == *(_WORD *)(v14 + 12) )                     {                       v3 = 1370;                       v4 = a2;                       v5 = v12;                       v6 = *(_WORD *)(a1 + 10042);                       v7 = *(_WORD *)(a1 + 2);                       sub_412CB0((int)&v3, 0xAu, *(_WORD *)(v14 + 12));                       *(_WORD *)&v10[2 * i + 1] = *(_WORD *)&v10[2 * (unsigned __int8)(*v10)-- - 1];                       break;                     }                   }                   sub_415970((int)&v19, 8, (int)&Dst, *(_WORD *)(v10 + 1));                 }               }             }           }         }       }     }   } 

One of the functions I’m a bit confused about is:

int __thiscall sub_41EF83(int this, int a2, unsigned __int16 a3, int a4, char a5) 

Which I implemented as:

typedef void(__thiscall *T41EF83)(void*, unsigned char*, unsigned __int16, unsigned char*, char); T41EF83 sub_41EF83 = (T41EF83)(0x41EF83); 

Note: I have basic knowledge of C/C++.

Apk decompiled file

after I decompiled an apk file(a game) on kali, i found this interesting files: https://i.stack.imgur.com/ZhNYU.jpg . This are the cars from game. I had some questions: How i can open it? How to edit the car 3d deisign ? The problem is thath i don’t saw this formats of files(.cpu and .gpu).

I hope you will help me to find an answer for this dilema. Thanks!