Skip to content

Decompiled : Decoding Tile AID

iamkisly edited this page Dec 18, 2016 · 1 revision

В общих чертах изложенное на данной странице повторяет спецификацию от Crypton, но имеются некоторые не упомянутые моменты, которые он просто проигнорировал. Я начну с конца, на мой взгляд, так будет понятнее.

Функция sub_454B90, генерирует конечный текстовый формат.

char aArtTileSSCC_ar[] = "art\\tile\\%s%s%c%c.art"; // idb
char aArtTileSbseCC_[] = "art\\tile\\%sbse%c%c.art"; // idb
char *off_578D54[3] = { "06b489237ea5dc10", "art\\tile", "art\\tile\\tilevariant.dat" }; // weak

//----- (00454B90) --------------------------------------------------------
int __cdecl sub_454B90(char *a1, char *a2, int a3, int a4, char *a5)
{
  int v5; // esi@1
  int v6; // edi@3
  int result; // eax@8

  v5 = a4;
  if ( a4 >= 8 )
    v5 = a4 - 8;
  v6 = a3;
  if ( a3 == 15 || !_strcmpi(a1, a2) )
  {
    sprintf(a5, aArtTileSbseCC_, a1, off_578D54[0][v6], v5 + 97); //97 ~ ASCII 'a'
    return 1;
  }
  if ( !v6 )
  {
    sprintf(a5, aArtTileSbseCC_, a2, *off_578D54[0], v5 + 97);
    return 1;
  }
  if ( sub_4553F0(a1, (int)&a4) )
  {
    if ( sub_4553F0(a2, (int)&a3) )
    {
      if ( a4 >= a3 )
        sprintf(a5, aArtTileSSCC_ar, a2, a1, off_578D54[0][-v6 + 15], v5 + 97);
      else
        sprintf(a5, aArtTileSSCC_ar, a1, a2, off_578D54[0][v6], v5 + 97);
      result = 1;
    }
    else
    {
      sprintf(a5, aArtTileSbseCC_, a2, off_578D54[0][-v6 + 15], v5 + 97);
      result = 1;
    }
  }
  else
  {
    sprintf(a5, aArtTileSbseCC_, a1, off_578D54[0][v6], v5 + 97);
    result = 1;
  }
  return result;
}
// 578D54: using guessed type char *off_578D54[3];

Вызывается из sub_454AB0

char aAskingForTileN[43] = "Asking for tile name with non tile art ID."; // weak

//----- (00454AB0) --------------------------------------------------------
int __cdecl sub_454AB0(int a1, char *a2)
{
  int v2; // esi@1
  int result; // eax@2
  int v4; // ebx@3
  int v5; // edi@3
  int v6; // ebp@3
  int v7; // esi@3
  int v8; // [sp+8h] [bp-10h]@3
  int v9; // [sp+Ch] [bp-Ch]@3
  char *v10; // [sp+10h] [bp-8h]@4
  char *v11; // [sp+14h] [bp-4h]@3
  signed int v12; // [sp+1Ch] [bp+4h]@3

  v2 = a1;
  if ( sub_516C10(a1) ) // a1 >> 28 GET LAST 4 BIT (see below)
  {
    printFromPtr((int)aAskingForTileN); //"Asking for tile name with non tile art ID".
    *a2 = 0;
    result = 0;
  }
  else
  {
    v4 = sub_517BC0(a1); // GET_TILE_ID ? (INT32 DATA)
    v12 = sub_517BF0(a1); 
	
    v9 = sub_517C10(v2);
    v8 = sub_517CC0(v2);
    v5 = sub_517DD0(v2);
    v6 = sub_517E60(v2);
    v7 = sub_517EA0(v2);
    result = sub_454CE0(v4, v5, v6, (int)&v11);
    if ( result )
    {
      result = sub_454CE0(v12, v5, v7, (int)&v10);
      if ( result )
        result = sub_454B90(v11, v10, v9, v8, a2);
    }
  }
  return result;
}
//----- (00516C10) --------------------------------------------------------
unsigned int __cdecl sub_516C10(unsigned int a1)
{
  return a1 >> 28;
}

sub_517BC0 ? Возвращает TileID

//----- (00517BC0) --------------------------------------------------------
int __cdecl sub_517BC0(unsigned int a1) // GET_TILE_ID ? (INT32 DATA)
{
  unsigned int v1; // eax@1
  int result; // eax@2

  v1 = sub_516C10(a1);
  if ( v1 )
  {
    if ( v1 == 11 )
      result = (a1 >> 11) & 0x3F;
    else
      result = 0;
  }
  else
  {
    result = (a1 >> 22) & 0x3F;
  }
  return result;
}

sub_517BF0

//----- (00517BF0) --------------------------------------------------------
int __cdecl sub_517BF0(unsigned int a1)
{
  int result; // eax@2

  if ( sub_516C10(a1) )
    result = 0;
  else
    result = (a1 >> 16) & 0x3F;
  return result;
}

sub_517C10

//----- (00517C10) --------------------------------------------------------
int __cdecl sub_517C10(unsigned int a1)
{
  int result; // eax@2
  int v2; // esi@3

  if ( sub_516C10(a1) )
  {
    result = 0;
  }
  else
  {
    v2 = (unsigned __int16)a1 >> 12;
    if ( sub_5194E0(a1) & 1 ) //see bolow
      v2 = dword_59CC70[v2];
    result = v2;
  }
  return result;
}
// 59CC70: using guessed type int dword_59CC70[];

//char_2_array in Crypton spec. 
byte[] dword_59CC70 = { 0x00, 0x01, 0x02, 0x09, 0x04, 0x05, 0x0C, 0x0D, 0x02, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

//----- (005194E0) --------------------------------------------------------
int __cdecl sub_5194E0(unsigned int a1)
{
  unsigned int v1; // eax@1
  int result; // eax@5

  v1 = sub_516C10(a1);
  if ( v1 && v1 != 1 && v1 != 3 && v1 != 10 )
    result = 0;
  else
    result = a1 & 0xF;
  return result;
} 

sub_517CC0

//----- (00517CC0) --------------------------------------------------------
int __cdecl sub_517CC0(unsigned int a1)
{
  int result; // eax@2
  int v2; // esi@3
  int v3; // eax@3

  if ( sub_516C10(a1) )
  {
    result = 0;
  }
  else
  {
    v2 = (a1 >> 9) & 7;
    v3 = sub_517C10(a1); //wtf ? recurse
    if ( dword_59CC70[v3] == dword_59CC30[v3] )
    {
      if ( sub_5194E0(a1) & 1 )
        v2 += 8;
    }
    result = v2;
  }
  return result;
}
// 59CC30: using guessed type int dword_59CC30[];
// 59CC70: using guessed type int dword_59CC70[];

//char_1_array in Crypton spec.
byte[] dword_59CC30 = new byte[] { 0x0, 0x1, 0x8, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x3, 0xA, 0xB, 0x6, 0x7, 0xE, 0xF };

sub_517DD0

//----- (00517DD0) --------------------------------------------------------
int __cdecl sub_517DD0(unsigned int a1)
{
  int result; // eax@2

  if ( sub_516C10(a1) )
  {
    if ( sub_516C10(a1) == 11 )
      result = (a1 >> 25) & 1;
    else
      result = 0;
  }
  else
  {
    result = (unsigned __int8)a1 >> 8;
  }
  return result;
}

sub_517E60

//----- (00517E60) --------------------------------------------------------
int __cdecl sub_517E60(unsigned int a1)
{
  int result; // eax@2

  if ( sub_516C10(a1) )
  {
    if ( sub_516C10(a1) == 11 )
      result = sub_517E10(a1);
    else
      result = 0;
  }
  else
  {
    result = (a1 >> 7) & 1;
  }
  return result;
}

//----- (00517E10) --------------------------------------------------------
int __cdecl sub_517E10(unsigned int a1)
{
  int result; // eax@2

  if ( sub_516C10(a1) == 11 )
    result = (a1 >> 26) & 1;
  else
    result = !sub_516C10(a1) && sub_517E60(a1) && sub_517EA0(a1);
  return result;
}

sub_517EA0

//----- (00517EA0) --------------------------------------------------------
int __cdecl sub_517EA0(unsigned int a1)
{
  int result; // eax@2

  if ( sub_516C10(a1) )
  {
    if ( sub_516C10(a1) == 11 )
      result = sub_517E10(a1);
    else
      result = 0;
  }
  else
  {
    result = (a1 >> 6) & 1;
  }
  return result;
}

sub_454CE0 такая лютая альтернатива sub_454B90

//----- (00454CE0) --------------------------------------------------------
signed int __cdecl sub_454CE0(signed int a1, int a2, int a3, int a4)
{
  signed int result; // eax@4

  if ( a3 )
  {
    if ( a2 )
    {
      if ( a1 < (signed int)dword_5A9D3C )
      {
        *(_DWORD *)a4 = *((_DWORD *)dword_5A9D34 + a1);
        result = 1;
      }
      else
      {
        result = 0;
      }
    }
    else if ( a1 < (signed int)dword_5A9D28 )
    {
      *(_DWORD *)a4 = *((_DWORD *)dword_5A9D24 + a1);
      result = 1;
    }
    else
    {
      result = 0;
    }
  }
  else if ( a2 )
  {
    if ( a1 < (signed int)dword_5A9D38 )
    {
      *(_DWORD *)a4 = *((_DWORD *)dword_5A9D00 + a1);
      result = 1;
    }
    else
    {
      result = 0;
    }
  }
  else if ( a1 < (signed int)dword_5A9D48 )
  {
    *(_DWORD *)a4 = *((_DWORD *)dword_5A9D30 + a1);
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}
LPVOID dword_5A9D00; // idb
int dword_5A9D04;	 // weak
LPVOID dword_5A9D08; // idb
LPVOID dword_5A9D0C; // idb
LPVOID dword_5A9D10; // idb
LPVOID dword_5A9D14; // idb
LPVOID dword_5A9D18; // idb
LPVOID dword_5A9D1C; // idb
int dword_5A9D20;	 // idb
LPVOID dword_5A9D24; // idb
size_t dword_5A9D28; // idb SIZE
LPVOID dword_5A9D2C; // idb
LPVOID dword_5A9D30; // idb
LPVOID dword_5A9D34; // idb
size_t dword_5A9D38; // idb SIZE
size_t dword_5A9D3C; // idb SIZE
LPVOID dword_5A9D40; // idb
LPVOID dword_5A9D44; // idb
size_t dword_5A9D48; // idb SIZE

dword_5A9D34 = malloc(4 * dword_5A9D3C);
dword_5A9D00 = malloc(4 * dword_5A9D38);
dword_5A9D24 = malloc(4 * dword_5A9D28);
dword_5A9D30 = malloc(4 * dword_5A9D48);
dword_5A9D08 = malloc(dword_5A9D3C);
dword_5A9D44 = malloc(dword_5A9D38);
dword_5A9D1C = malloc(dword_5A9D28);
dword_5A9D14 = malloc(dword_5A9D48);
dword_5A9D2C = malloc(4 * dword_5A9D3C);
dword_5A9D10 = malloc(4 * dword_5A9D38);
dword_5A9D40 = malloc(4 * dword_5A9D28);
dword_5A9D0C = malloc(4 * dword_5A9D48);

//where
//----- (00454E90) --------------------------------------------------------
signed int sub_454E90()
{
  dword_5A9D3C = (size_t)sub_4521B0(dword_5A9D20, 0, 99); //count element between 0 and 99
  dword_5A9D38 = (size_t)sub_4521B0(dword_5A9D20, 100, 199);
  dword_5A9D28 = (size_t)sub_4521B0(dword_5A9D20, 200, 299);
  dword_5A9D48 = (size_t)sub_4521B0(dword_5A9D20, 300, 399);
  return 1;
}

Clone this wiki locally