Skip to content

Decompiled : map_open procedure

iamkisly edited this page Dec 11, 2016 · 1 revision

###Procedure for reading maps

  1. reading properties file
  2. reading start location
  3. loading mobile objects
  4. loading mobile dynamic objects
  5. load postprocess
  6. load terrain
  7. load jump points

###Export from AdaPro6.8 & HexRays already changed names of procedures

signed int __cdecl sub_46B9A0(char *a1, char *a2, int a3) //int map_open( char* folder, char* ?, IntPrt? destination)
{
  signed int result; // eax@2
  DWORD v4; // eax@3
  int v5; // eax@7
  void *v6; // esi@7
  DWORD v7; // eax@11
  int v8; // eax@12
  int v9; // esi@12
  __int64 v10; // kr08_8@16
  int v11; // eax@18
  DWORD v12; // eax@19
  DWORD v13; // eax@21
  DWORD v14; // eax@24
  DWORD v15; // eax@24
  DWORD v16; // eax@29
  DWORD v17; // eax@32
  DWORD v18; // eax@34
  __int64 v19; // rax@34
  char *v20; // eax@34
  const char *v21; // esi@35
  int v22; // ebp@37
  int v23; // edi@38
  DWORD v24; // eax@43
  DWORD v25; // eax@43
  DWORD v26; // eax@43
  int v27; // [sp+18h] [bp-19Ch]@3		//current_time ?
  int v28; // [sp+1Ch] [bp-198h]@3 		//start_time
  int v29; // [sp+20h] [bp-194h]@9
  __int64 v30; // [sp+28h] [bp-18Ch]@27
  __int64 v31; // [sp+30h] [bp-184h]@27
  int v32; // [sp+38h] [bp-17Ch]@27
  int v33; // [sp+3Ch] [bp-178h]@27
  int v34; // [sp+40h] [bp-174h]@27
  __int64 v35; // [sp+48h] [bp-16Ch]@27
  __int64 v36; // [sp+50h] [bp-164h]@27
  int v37; // [sp+5Ch] [bp-158h]@16
  char v38; // [sp+60h] [bp-154h]@14
  char v39; // [sp+B0h] [bp-104h]@7

  if ( !dword_5AA254 )
    return 0;
	
  printf(aMap_openMap_cl); //map_open: map_close()...
  setTimeToPtr((int)&v27);
  v28 = v27; //start_time = current_time
  sub_46CB70(); //map_close() ?
  v4 = subtractTime(v27); // v4 <- map_close_time
  printf(aDone_TimeMsD, v4); //done.  Time (ms): %d\n
  
  if ( !sub_53E4D0(a1) ) // ExistFolder ?
  {
    printf(aErrorOpeningMa, a1); //Error opening map %s: folder does not exist\n
    return 0;
  }
  sub_53E290((int)a2);	//A2 always set "C://U"
  if ( !a3 ) //A3 always 0
    sub_53E2F0(a2);
	

  printf(aMap_openReadin); //map_open: reading properties file...
  setTimeToPtr((int)&v27);
  sprintf(&v39, aSMap_prp, a1); //%s\\map.prp
  v5 = sub_53A3D0(&v39, aRb); // aRb -> "rb" ? File read biteMode
  v6 = (void *)v5;
  if ( !v5 )
  {
    printf(aErrorOpening_0, &v39); //Error opening map properties file %s\n
    return 0;
  }
  if ( sub_53A670(&v29, 0x18u, 1u, v5) != 1 ) //properties file execution
  {
    printf(aErrorReadingMa, &v39); //Error reading map properties file %s\n
    sub_53A360(v6);
    return 0;
  }
  sub_53A360(v6);
  v7 = subtractTime(v27);
  printf(aDone_TimeMsD, v7); //done.  Time (ms): %d\n
  printf(aMap_openRead_0); //map_open: reading start location...
  setTimeToPtr((int)&v27);
  sprintf(&v39, aSStartloc_txt, a1); //%s\\startloc.txt
  if ( sub_539BB0(&v39, 0) )
  {
    v8 = sub_53A3D0(&v39, aRt);// aRt -> "rt" ? File read textMode
    v9 = v8;
	
    if ( !v8 )
    {
      printf(aErrorOpening_1, &v39); //Error opening map start location (file exists, can't open): %s\n
      return 0;
    }
	// int __cdecl sub_53A570(char *dest, int a2, FILE* a3)
    if ( !sub_53A570(&v38, 80, v8) ) //read x (80 symbols)
    {
      printf(aErrorReading_0, &v39); //Error reading map start location (x) file %s\n
      return 0;
    }
    v10 = _atoi64(&v38);
    v37 = HIDWORD(v10);
	
    if ( !sub_53A570(&v38, 80, v9) ) //read y (80 symbols)
    {
      printf(aErrorReading_1, &v39); //Error reading map start location (y) file %s\n
      return 0;
    }
	
    v11 = _atoi64(&v38);
    *(_DWORD *)qword_5AA248 = v10;
    *(_DWORD *)&qword_5AA248[4] = v37 | v11;
    sub_53A360((LPVOID)v9);
  }
  v12 = subtractTime(v27);
  printf(aDone_TimeMsD, v12);//done.  Time (ms): %d\n
  printf(aMap_openLoadin); //map_open: loading mobile objects...
  setTimeToPtr((int)&v27);
  if ( sub_46D1B0(a1, a2) )
  {
    v13 = subtractTime(v27);
    printf(aDone_TimeMsD, v13);//done.  Time (ms): %d\n
    printf(aMap_openLoad_0); //map_open: loading mobile dynamic objects...
    setTimeToPtr((int)&v27);
    if ( dword_5AA264 || sub_46D8E0((int)a2) )
    {
      v14 = subtractTime(v27);
      printf(aDone_TimeMsD, v14);//done.  Time (ms): %d\n
      printf(aMap_openMap_lo); //map_open: map_load_postprocess()...
      setTimeToPtr((int)&v27);
      sub_46D0F0();
      v15 = subtractTime(v27);
      printf(aDone_TimeMsD, v15);//done.  Time (ms): %d\n
      strcpy((char *)dword_5AA25C, a1);
      strcpy(dword_5AA258, a2);
      sub_53E290((int)dword_5AA258);
      if ( !a3 )
        sub_53E2F0(dword_5AA258);
      printf(aMap_openLoad_1); //map_open: loading terrain...
      setTimeToPtr((int)&v27);
      if ( sub_452C30(dword_5AA25C, (int)dword_5AA258)
        || (v34 = v29,
            v35 = v30 >> 6,
            v36 = v31 >> 6,
            v32 = dword_5AA25C,
            v33 = dword_5AA25C,
            sub_452B10((int)&v32),
            sub_452C30(dword_5AA25C, (int)dword_5AA258)) )
      {
        v16 = subtractTime(v27);
        printf(aDone_TimeMsD, v16);//done.  Time (ms): %d\n
        printf(aMap_openLoad_2); //map_open: loading jump points...
        setTimeToPtr((int)&v27);
        if ( sub_4806F0(dword_5AA25C, (int)dword_5AA258)
          || (v34 = v29,
              v35 = v30 >> 6,
              v36 = v31 >> 6,
              v32 = dword_5AA25C,
              v33 = (int)dword_5AA258,
              sub_4806A0((int)&v32),
              sub_4806F0(dword_5AA25C, (int)dword_5AA258)) )
        {
          v17 = subtractTime(v27);
          printf(aDone_TimeMsD, v17);//done.  Time (ms): %d\n
          printf(aMap_openSector); //map_open: sector blocking...
          setTimeToPtr((int)&v27);
          if ( !sub_418E80(dword_5AA25C, (int)dword_5AA258) )
            sub_418E70();
          v18 = subtractTime(v27);
          printf(aDone_TimeMsD, v18);//done.  Time (ms): %d\n
          printf(aMap_openSettin); //map_open: setting initial map location and state...
          setTimeToPtr((int)&v27);
          sub_41D620(v30, v31);
          sub_4176C0(v30 / 64, v31 / 64);
          sub_418370(a1, a2);
          LODWORD(v19) = sub_41D6D0();
          sub_41CBA0(v19);
          dword_5AA274 = 0;
          v20 = strrchr(a1, 92); // 92 -> '\'
          if ( v20 )
            v21 = v20 + 1; //read from next symbol
          else
            v21 = a1; 
          v22 = 0;
          if ( dword_5AA270 > 0 )
          {
            v23 = 0;
            while ( _strcmpi((const char *)(v23 + dword_5AA268), v21) )
            {
              ++v22;
              v23 += 280;
              if ( v22 >= dword_5AA270 )
                goto LABEL_43;
            }
            dword_5AA274 = v22 + 1;
          }
LABEL_43:
          v24 = subtractTime(v27);
          printf(aDone_TimeMsD, v24);//done.  Time (ms): %d\n
          printf(aMap_openParsin); //map_open: parsing extension file...
          setTimeToPtr((int)&v27);
          sub_46DA60(a1);
          v25 = subtractTime(v27);
          printf(aDone_TimeMsD, v25);//done.  Time (ms): %d\n
          printf(aMap_openMap_di); //map_open: map_disable_objects()...
          setTimeToPtr((int)&v27);
          sub_46DBE0();
          v26 = subtractTime(v27);
          printf(aDone_TimeMsD, v26);//done.  Time (ms): %d\n
          v28 = subtractTime(v28);
          printf(aMap_openDone_T, (double)v28 * 0.001); //map_open(): Done.  Total time: %f seconds.\n
          result = 1;
          dword_5AA260 = 1;
          dword_5AA250 = 0;
        }
        else
        {
          printFromPtr((int)aErrorJumppoint); //Error: jumppoint_open failed even after creating a new file
          sub_46CB70();
          result = 0;
        }
      }
      else
      {
        printFromPtr((int)aErrorTerrain_o); //Error: terrain_open failed even after creating a new terrain
        sub_46CB70();
        result = 0;
      }
    }
    else
    {
      printf(aErrorReadingDy); //Error reading dynamic mobile objects\n
      sub_46CB70();
      result = 0;
    }
  }
  else
  {
    printFromPtr((int)aErrorReadingMo); //Error reading mobile objects
    sub_46CB70();
    result = 0;
  }
  return result;
}

###Functions time counting

//----- (00547D00) --------------------------------------------------------
int __cdecl setTimeToPtr(int a1)
{
  *(_DWORD *)a1 = timeGetTime();
  return 0;
}

//----- (00547D10) --------------------------------------------------------
DWORD __cdecl subtractTime(int a1)
{
  return timeGetTime() - a1;
}