Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

CPlayer__OnLoadPlayer

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
I'm trying to manipulate this function, but in order to do that all the rest functions needs to be correct.
the problem is that the function is huge, and because of this it gets very confusing.

Code:
int __fastcall CPlayer__OnLoadPlayer(int *a2, int __edx)
{
  int v1; // edx@1
  signed int result; // eax@2
  int v3; // edx@4
  int v4; // edx@5
  int v5; // eax@5
  int v6; // eax@5
  int v7; // eax@5
  int v8; // eax@5
  int v9; // eax@5
  int v10; // eax@5
  int v11; // eax@5
  int v12; // eax@5
  int v13; // eax@5
  int v14; // eax@5
  int v15; // eax@5
  int v16; // eax@5
  int v17; // eax@5
  int v18; // eax@5
  int v19; // eax@5
  int v20; // eax@5
  int v21; // eax@5
  int v22; // eax@5
  int v23; // eax@6
  int v24; // eax@18
  int v25; // edx@19
  int v26; // ecx@21
  int v27; // eax@39
  int v28; // edx@41
  int v29; // ecx@44
  int v30; // eax@46
  int v31; // edx@54
  int v32; // ecx@56
  int v33; // eax@59
  int v34; // edx@61
  int v35; // eax@83
  int v36; // eax@88
  int v37; // ecx@112
  int v38; // edx@113
  int v39; // edx@117
  int v40; // edx@119
  int v41; // edx@120
  int v42; // eax@120
  int v43; // edx@122
  int v44; // [sp+0h] [bp-B0h]@104
  int v45; // [sp+4h] [bp-ACh]@97
  int v46; // [sp+8h] [bp-A8h]@21
  int v47; // [sp+Ch] [bp-A4h]@1
  int v48; // [sp+10h] [bp-A0h]@103
  int v49; // [sp+14h] [bp-9Ch]@96
  char v50; // [sp+24h] [bp-8Ch]@83
  char v51; // [sp+2Ch] [bp-84h]@83
  __int32 v52; // [sp+4Ch] [bp-64h]@110
  int v53; // [sp+50h] [bp-60h]@110
  int ii; // [sp+54h] [bp-5Ch]@108
  int v55; // [sp+58h] [bp-58h]@106
  int n; // [sp+5Ch] [bp-54h]@101
  int v57; // [sp+60h] [bp-50h]@99
  int m; // [sp+64h] [bp-4Ch]@94
  char v59; // [sp+68h] [bp-48h]@88
  char v60; // [sp+6Ch] [bp-44h]@88
  int v61; // [sp+70h] [bp-40h]@88
  int v62; // [sp+74h] [bp-3Ch]@88
  int v63; // [sp+78h] [bp-38h]@88
  int l; // [sp+7Ch] [bp-34h]@86
  int v65; // [sp+80h] [bp-30h]@83
  int k; // [sp+84h] [bp-2Ch]@81
  int v67; // [sp+88h] [bp-28h]@16
  int j; // [sp+8Ch] [bp-24h]@13
  int i; // [sp+90h] [bp-20h]@8
  unsigned __int8 v70; // [sp+96h] [bp-1Ah]@10
  unsigned __int8 v71; // [sp+97h] [bp-19h]@10
  int v72; // [sp+98h] [bp-18h]@5
  int v73; // [sp+9Ch] [bp-14h]@7
  int v74; // [sp+A0h] [bp-10h]@3
  int v75; // [sp+A4h] [bp-Ch]@7
  int v76; // [sp+A8h] [bp-8h]@7
  int v77; // [sp+ACh] [bp-4h]@113
  int arg0; // [sp+B8h] [bp+8h]@0


  v47 = (int)a2;
  Server::CChar::Lock((int)a2);
  if ( Server::CPlayer::CPlayer__IsPBit(v47, 4) )
  {
    Server::CChar::Unlock(v47, v1);
    result = 0;
  }
  else
  {
    v74 = Server::sub::sub_418960(arg0, v47 + 456);
    if ( *(DWORD *)(v47 + 456) == 1 )
    {
      Server::CPlayer::Write((void*)v47, 67, (const char*)"b");
	  //Server::CPlayer::Write(this->thispointer, 68,"bs",18,message);
      Server::CChar::Unlock(v47, v3);
      result = 0;
    }
    else
    {
      v5 = Server::sub::sub_497620(v74, v47 + 32);
      v6 = Server::sub::sub_418960(v5, v47 + 460);
      v7 = Server::sub::sub_418960(v6, v47 + 464);
      v8 = Server::sub::sub_418960(v7, v47 + 60);
      v9 = Server::sub::sub_418980(v8, v47 + 468);
      v10 = Server::sub::sub_47A220(v9, v47 + 472);
      v11 = Server::sub::sub_47A240(v10, v47 + 480);
      v12 = Server::sub::sub_418960(v11, v47 + 536);
      v13 = Server::sub::sub_418960(v12, v47 + 64);
      v14 = Server::sub::sub_418960(v13, v47 + 68);
      v15 = Server::sub::sub_418960(v14, v47 + 72);
      v16 = Server::sub::sub_418960(v15, v47 + 76);
      v17 = Server::sub::sub_418960(v16, v47 + 80);
      v18 = Server::sub::sub_418980(v17, v47 + 272);
      v19 = Server::sub::sub_418980(v18, v47 + 276);
      v20 = Server::sub::sub_418980(v19, v47 + 544);
      v21 = Server::sub::sub_418980(v20, v47 + 548);
      v22 = Server::sub::sub_418960(v21, v47 + 552);
      v74 = Server::sub::sub_418960(v22, v47 + 316);
      v74 = Server::sub::sub_47A240(v74, (int)&v72);
      if ( v72 >= 0 )
      {
        v74 = Server::sub::sub_47A240(v74, (int)&v73);
        v74 = Server::sub::sub_47A240(v74, v47 + 340);
        v74 = Server::sub::sub_418960(v74, v47 + 556);
        v74 = Server::sub::sub_418960(v74, v47 + 560);
        v74 = Server::sub::sub_418960(v74, v47 + 572);
        v74 = Server::sub::sub_47A240(v74, v47 + 580);
        Server::CChar::CChar__SetXY(v47, (int)&v72);
        (*(void (__thiscall **)(int))(*(DWORD *)v47 + 84))(v47);
        Server::sub::sub_47F680(v47 + 624, v47);
        v76 = 0;
        v75 = v74;
        v74 = Server::sub::sub_418960(v74, (int)&v76);
        if ( v76 )
        {
          for ( i = 0; i < v76; ++i )
          {
            v74 = Server::sub::sub_418960(v74, (int)&v71);
            v74 = Server::sub::sub_418960(v74, (int)&v70);
            Server::sub::sub_47F6B0(v47 + 624, v71, v70);
          }
          Server::sub::sub_47FC00((void *)(v47 + 624));
          Server::CPlayer::Write((void*)v47, 16, (const char*)"m");
        }
        v74 = Server::sub::sub_418960(v74, (int)&v76);
        if ( v76 )
        {
          Server::CIOCriticalSection::CIOCriticalSection__Enter((int)v47 + 1020);
          for ( j = 0; j < v76; ++j )
          {
            v67 = Server::sub::sub_426060(*(DWORD *)(v47 + 452), &v74);
            if ( v67 )
            {
              if ( Server::CItem::IsState(v67, 1) )
              {
                v24 = *(DWORD *)(v67 + 48);
                if ( v24 & 0x7FF00 )
                {
                  v25 = *(DWORD *)(v67 + 48);
                  if ( v25 & 0x100000 )
                    Server::CChar::AddGState(v47, -2147483648);
                  v26 = *(DWORD *)(v67 + 48);
                  v46 = v26 & 0x7FF00;
                  if ( (v26 & 0x7FF00u) > 0x2000 )
                  {
                    if ( (unsigned int)v46 > 0x10000 )
                    {
                      if ( v46 == 131072 )
                      {
                        Server::CChar::AddGState(v47, 536870912);
                        (*(void (__cdecl **)(int, signed int, signed int, signed int, signed int))(*(DWORD *)v47 + 92))(
                          v47,
                          27,
                          1,
                          50,
                          50);
                        (*(void (__cdecl **)(int, signed int, signed int, signed int, signed int))(*(DWORD *)v47 + 92))(
                          v47,
                          28,
                          1,
                          50,
                          50);
                      }
                      else
                      {
                        if ( v46 == 262144 )
                        {
                          Server::CChar::AddGState(v47, 1073741824);
                          (*(void (__cdecl **)(int, signed int, signed int, signed int))(*(DWORD *)v47 + 92))(
                            v47,
                            5,
                            1,
                            50);
                          (*(void (__cdecl **)(int, signed int, signed int, signed int))(*(DWORD *)v47 + 92))(
                            v47,
                            6,
                            1,
                            50);
                          (*(void (__cdecl **)(int, DWORD, signed int, signed int))(*(DWORD *)v47 + 92))(v47, 0, 1, 6);
                          (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 92))(
                            v47,
                            2,
                            1,
                            6);
                          (*(void (__cdecl **)(DWORD, signed int, DWORD, DWORD))(*(DWORD *)v47 + 92))(v47, 4, 1, 6);
                          (*(void (__cdecl **)(int, signed int, signed int, signed int))(*(DWORD *)v47 + 92))(
                            v47,
                            3,
                            1,
                            10);
                          (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 92))(
                            v47,
                            1,
                            1,
                            10);
                        }
                      }
                    }
                    else
                    {
                      switch ( v46 )
                      {
                        case 65536:
                          Server::CChar::AddGState(v47, 268435456);
                          v33 = *(DWORD *)(v67 + 48);
                          if ( v33 & 0x80000 )
                          {
                            (*(void (__cdecl **)(int, signed int, DWORD, signed int))(*(DWORD *)v47 + 96))(
                              v47,
                              5,
                              0,
                              5);
                            (*(void (__cdecl **)(int, signed int, signed int, signed int))(*(DWORD *)v47 + 96))(
                              v47,
                              6,
                              1,
                              10);
                          }
                          else
                          {
                            v34 = *(DWORD *)(v67 + 48);
                            if ( v34 & 0x100000 )
                            {
                              (*(void (__cdecl **)(int, signed int, DWORD, signed int))(*(DWORD *)v47 + 96))(
                                v47,
                                5,
                                0,
                                10);
                              (*(void (__cdecl **)(int, signed int, signed int, signed int))(*(DWORD *)v47 + 96))(
                                v47,
                                6,
                                1,
                                20);
                            }
                          }
                          break;
                        case 16384:
                          Server::CChar::AddGState(v47, 67108864);
                          break;
                        case 32768:
                          Server::CChar::AddGState(v47, 134217728);
                          v31 = *(DWORD *)(v67 + 48);
                          if ( v31 & 0x80000 )
                          {
                            (*(void (__cdecl **)(DWORD, DWORD, signed int, DWORD))(*(DWORD *)v47 + 96))(
                              v47,
                              5,
                              1,
                              10);
                            (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 96))(
                              v47,
                              6,
                              0,
                              5);
                          }
                          else
                          {
                            v32 = *(DWORD *)(v67 + 48);
                            if ( v32 & 0x100000 )
                            {
                              (*(void (__cdecl **)(DWORD, DWORD, DWORD, signed int))(*(DWORD *)v47 + 96))(
                                v47,
                                5,
                                1,
                                20);
                              (*(void (__cdecl **)(DWORD, DWORD, DWORD, DWORD))(*(DWORD *)v47 + 96))(v47, 6, 0, 10);
                            }
                          }
                          break;
                      }
                    }
                  }
                  else
                  {
                    if ( v46 == 8192 )
                    {
                      Server::CChar::AddGState(v47, 33554432);
                    }
                    else
                    {
                      if ( (unsigned int)v46 > 0x400 )
                      {
                        if ( v46 == 2048 )
                        {
                          Server::CChar::AddGState(v47, 8388608);
                        }
                        else
                        {
                          if ( v46 == 4096 )
                            Server::CChar::AddGState(v47, 16777216);
                        }
                      }
                      else
                      {
                        switch ( v46 )
                        {
                          case 1024:
                            Server::CChar::AddGState(v47, 4194304);
                            break;
                          case 256:
                            Server::CChar::AddGState(v47, 1048576);
                            v27 = *(DWORD *)(v67 + 48);
                            if ( v27 & 0x80000 )
                            {
                              (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                v47,
                                5,
                                1,
                                20);
                              (*(void (__cdecl **)(DWORD, DWORD, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                v47,
                                0,
                                1,
                                2);
                              (*(void (__cdecl **)(int, signed int, signed int, signed int))(*(DWORD *)v47 + 92))(
                                v47,
                                2,
                                1,
                                2);
                              (*(void (__cdecl **)(DWORD, signed int, DWORD, DWORD))(*(DWORD *)v47 + 92))(
                                v47,
                                4,
                                1,
                                2);
                            }
                            else
                            {
                              v28 = *(DWORD *)(v67 + 48);
                              if ( v28 & 0x100000 )
                              {
                                (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                  v47,
                                  5,
                                  1,
                                  50);
                                (*(void (__cdecl **)(DWORD, DWORD, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                  v47,
                                  0,
                                  1,
                                  3);
                                (*(void (__cdecl **)(DWORD, DWORD, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                  v47,
                                  2,
                                  1,
                                  3);
                                (*(void (__cdecl **)(DWORD, DWORD, DWORD, DWORD))(*(DWORD *)v47 + 92))(
                                  v47,
                                  4,
                                  1,
                                  3);
                              }
                            }
                            break;
                          case 512:
                            Server::CChar::AddGState(v47, 2097152);
                            v29 = *(DWORD *)(v67 + 48);
                            if ( v29 & 0x80000 )
                            {
                              (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                v47,
                                6,
                                1,
                                20);
                              (*(void (__cdecl **)(DWORD, signed int, DWORD, DWORD))(*(DWORD *)v47 + 92))(
                                v47,
                                3,
                                1,
                                2);
                              (*(void (__cdecl **)(DWORD, signed int, DWORD, DWORD))(*(DWORD *)v47 + 92))(
                                v47,
                                1,
                                1,
                                2);
                            }
                            else
                            {
                              v30 = *(DWORD *)(v67 + 48);
                              if ( v30 & 0x100000 )
                              {
                                (*(void (__cdecl **)(DWORD, DWORD, DWORD, DWORD))(*(DWORD *)v47 + 92))(
                                  v47,
                                  6,
                                  1,
                                  50);
                                (*(void (__cdecl **)(DWORD, signed int, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                  v47,
                                  3,
                                  1,
                                  5);
                                (*(void (__cdecl **)(DWORD, DWORD, DWORD, signed int))(*(DWORD *)v47 + 92))(
                                  v47,
                                  1,
                                  1,
                                  5);
                              }
                            }
                            break;
                        }
                      }
                    }
                  }
                }
              }
              if ( (*(int (__thiscall **)(int, int))(*(DWORD *)v67 + 148))(v67, v67) || *(DWORD *)(v67 + 52) <= 1 )
              {
                if ( Server::CPlayer::IntoInven(v67) )
                {
                  if ( (*(int (__thiscall **)(int))(*(DWORD *)v67 + 164))(v67) )
                  {
                    *(DWORD *)(v47 + 1096) = v67;
                    if ( *(DWORD *)(*(DWORD *)(v47 + 1096) + 52) < 0 )
                    {
                      Server::Console::WriteRed(
                        "m_pMoney->m_nNum <0 :  UID(%d) PID(%d) IID(%d) Num(%d) ",
                        *(DWORD *)(v47 + 448),
                        *(DWORD *)(v47 + 452),
                        *(DWORD *)(v67 + 36),
                        *(DWORD *)(*(DWORD *)(v47 + 1096) + 52));
                      Server::CDBSocket::CDBSocket__Write(8, (unsigned int)"ddwdb");
                      *(DWORD *)(*(DWORD *)(v47 + 1096) + 52) = 1;
                    }
                  }
                  else
                  {
                    if ( (*(int (__thiscall **)(int))(*(DWORD *)v67 + 196))(v67) )
                      ++*(DWORD *)(v47 + 1104);
                  }
                }
                else
                {
                  Server::Console::WriteRed("CPlayer::OnLoadPlayer() Item insert error. (IID:%d)", *(DWORD *)(v67 + 36));
                  Server::CBase::CBase__Delete((void *)v67);
                }
              }
              else
              {
                Server::Console::WriteRed(
                  "CPlayer::OnLoadPlayer() Ãi+--",
                  v47 + 32,
                  *(DWORD *)(v47 + 452),
                  *(DWORD *)(v47 + 448),
                  *(DWORD *)(*(DWORD *)(v67 + 40) + 64),
                  *(DWORD *)(v67 + 52));
                Server::CBase::CBase__Delete((void *)v67);
              }
            }
          }
          Server::CIOCriticalSection::CIOCriticalSection__Leave(v47 + 1020);
        }
        v74 = Server::sub::sub_418960(v74, (int)&v76);
        if ( v76 )
        {
			Server::CIOCriticalSection::CIOCriticalSection__Enter(v47 + 1020);
          for ( k = 0; k < v76; ++k )
          {
            v65 = v74;
            v35 = Server::sub::sub_472830((int)&v51, v74 + 2, (const void *)v74);
            Server::sub::sub_470890((v47 + 1128), (int)&v50, v35);
            v74 += 26;
          }
		  Server::CIOCriticalSection::CIOCriticalSection__Leave(v47 + 1020);
        }
        v75 = v74;
        v74 = Server::sub::sub_418960(v74, (int)&v76);
        if ( v76 )
        {
          for ( l = 0; l < v76; ++l )
          {
            v61 = 0;
            v62 = 0;
            v63 = 0;
            v74 = Server::sub::sub_418980(v74, (int)&v61);
            v74 = Server::sub::sub_418960(v74, (int)&v62);
            v74 = Server::sub::sub_418960(v74, (int)&v63);
            v36 = Server::sub::sub_472860((int)&v61, (int)&v62);
            if ( !v60 )
              Server::Console::WriteRed("CPlayer::OnLoadPlayer() Duplicate Quest. (PID:%d, Quest:%d)", *(DWORD *)(v47 + 452), v61);
          }
          Server::CPlayer::Write((void*)v47, 87, (const char*)"m");
        }
        if ( Server::CPlayer::dword_4E1178() & 4 )
        {
          v74 = Server::sub::sub_418960(v74, (int)&v76);
          if ( v76 )
          {
            for ( m = 0; m < v76; ++m )
            {
              v49 = Server::CIOObject::CObject__GetPointer(0x10u);
              if ( v49 )
                v45 = Server::sub::sub_457E30(v49);
              else
                v45 = 0;
              v57 = v45;
              v74 = Server::sub::sub_418960(v74, v45 + 4);
              v74 = Server::sub::sub_47A240(v74, v57 + 8);
              Server::CPlayer::EventInsert(v47, v57);
            }
          }
        }
        v74 = Server::sub::sub_418960(v74, (int)&v76);
        if ( v76 )
        {
          for ( n = 0; n < v76; ++n )
          {
            v48 = Server::CIOObject::CObject__GetPointer(0x30u);
            if ( v48 )
              v44 = Server::sub::sub_457E60(v48);
            else
              v44 = 0;
            v55 = v44;
            v74 = Server::sub::sub_418960(v74, v44);
            v74 = Server::sub::sub_497620(v74, v55 + 8);
            v74 = Server::sub::sub_47A240(v74, v55 + 4);
            v74 = Server::sub::sub_47A240(v74, v55 + 40);
            v74 = Server::sub::sub_418960(v74, v55 + 28);
            v74 = Server::sub::sub_418960(v74, v55 + 32);
            Server::CPlayer::CPlayer__MLMLoad(v47, v55);
          }
        }
        v74 = Server::sub::sub_418960(v74, (int)&v76);
        if ( v76 )
        {
          for ( ii = 0; ii < v76; ++ii )
          {
            v53 = 0;
            v52 = 0;
            v74 = Server::sub::sub_418960(v74, (int)&v53);
            v74 = Server::sub::sub_47A240(v74, (int)&v52);
            Server::CChar::CChar__SetBuff(v47, v53, v52);
          }
        }
        if ( Server::CPlayer::IsPCBang(v47) )
        {
          v37 = *(DWORD *)(v47 + 308);
          *(DWORD *)(v47 + 304) |= 1u;
          *(DWORD *)(v47 + 308) = v37;
        }
        v74 = Server::sub::sub_47A240(v74, (int)&v77);
        if ( v77
          && (Server::CChar::CChar__Unlock(v47, v38), Server::CGuild::CGuild__Load(v77, v74, 0), Server::CChar::CChar__Lock(v47), Server::CPlayer::CPlayer__IsPBit(v47, 4)) )
        {
          Server::CChar::CChar__Unlock(v47, v38);
          result = 0;
        }
        else
        {
          if ( *(DWORD *)(v47 + 480)
            && (Server::CChar::CChar__Unlock(v47, v38), Server::CGuild::CGuild__Login(v47), Server::CChar::CChar__Lock(v47), Server::CPlayer::CPlayer__IsPBit(v47, 4)) )
          {
            Server::CChar::CChar__Unlock(v47, v39);
            result = 0;
          }
          else
          {
            if ( Server::CGuild::CGuild__IsWarringPeriod()
              && (Server::CChar::CChar__Unlock(v47, v40),
                  v42 = Server::CPlayer::CPlayer__GetGID(v47),
                  Server::CGuild::CGuild__LoginCastle(v47, v42),
                  Server::CChar::CChar__Lock(v47),
                  Server::CPlayer::CPlayer__IsPBit(v47, 4)) )
            {
              Server::CChar::CChar__Unlock(v47, v41);
              result = 0;
            }
            else
            {
              Server::sub::sub_496CD0();
              if ( Server::CPlayer::CPlayer___Create(v47) )
              {
                Server::CChar::CChar__Unlock(v47, v43);
                result = 1;
              }
              else
              {
                Server::CChar::CChar__Unlock(v47, v43);
                result = 0;
              }
            }
          }
        }
      }
      else
      {
        Server::CChar::CChar__Unlock(v47, v4);
        v23 = Server::sub::sub_422B30("CPlayer::OnLoadPlayer PID(%d) X(%d) Y(%d) \n", *(DWORD *)(v47 + 452));
        Server::sub::sub_422D80(v23);
        result = 0;
      }
    }
  return result;
}
}


Here is what I've managed so far, but it crashes the mainsvr.
I'm very aware that Ida may show invalid args and commands, but that's why I'm turning to you guys now.

Any idéas?
 
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
You need to make a decision, do you want to rewrite the whole function (i recommend that for small functions) or do you want to modify it at a certain place without touching the rest of the function (i recommend that for big functions, but this is a little bit more complicated). So for sure it is possible to rewrite CPlayer__OnLoadPlayer, but i would only change it partly if you have only a small change to make. So what do you want to edit?
 
Upvote 0

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
Mainly I would like to teleport a player on login, but so far I couldn't even figure out how to change a small part of a function, without writing the entire function first.
 
Upvote 0
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
Okay so basicly you dont want to edit something, you want to add something : ) Therefore i would use an Caller Hook also called Intercept (this is not the same as Detour Hook or Kealy call it API Hook).
So whats the trick, okay you hook a function call inside a function, but only this single call, not every call to this function, so you dont Hook the Function Address itself, you hook into the Caller Address.
In your case, you need the Player Pointer for teleporting, so every function call with a playerpointer can be used so lets say we use:

Code:
  int v77; // [sp+ACh] [bp-4h]@113
  int arg0; // [sp+B8h] [bp+8h]@0


  v47 = (int)a2;
[B]  Server::CChar::Lock((int)a2);[/B]
  if ( Server::CPlayer::CPlayer__IsPBit(v47, 4) )
  {
    Server::CChar::Unlock(v47, v1);
    result = 0;

So Server::CChar::Lock normally have the address 0x00412E90, but in this case we hook the caller and this address is 0x00456C55.

Code:
IMemory *memory = new IMemory;
memory->Hook(0x00456C55,Teleport_OnLoadPlayer);
delete memory;

void __fastcall Teleport_OnLoadPlayer(void* Playerpointer, void *_edx)
{
// Here comes your Teleport Function or what every you want to do else : )
Server::CChar::Lock(Playerpointer);
}
 
Upvote 0

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
Code:
1>------ Build started: Project: addon (Visual Studio 2010), Configuration: Release Win32 ------
1>  Core.cpp
1>     Creating library \\Server\dlls\addon.lib and object \\Server\dlls\addon.exp
1>Core.obj : error LNK2001: unresolved external symbol "public: void __thiscall IMemory::Hook(unsigned long,void *,unsigned char,unsigned int,bool)" (?Hook@IMemory@@QAEXKPAXEI_N@Z)
1>\\Server\dlls\addon.dll : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 
Last edited:
Upvote 0
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
Code:
1>------ Build started: Project: addon (Visual Studio 2010), Configuration: Release Win32 ------
1>  Core.cpp
1>     Creating library \\Server\dlls\addon.lib and object \\Server\dlls\addon.exp
1>Core.obj : error LNK2001: unresolved external symbol "public: void __thiscall IMemory::Hook(unsigned long,void *,unsigned char,unsigned int,bool)" (?Hook@IMemory@@QAEXKPAXEI_N@Z)
1>\\Server\dlls\addon.dll : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========

So your Linker seeks for the Function Member Hook of IMemory and fails.
I would say you dont have this Class (IMemory is out of Kealys Source Code).
And try to understand the errors and the source code, c&p is not advisable.
If you have any questions, just ask : )
 
Upvote 0

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
I've defined this, and then got that error.
Code:
#ifndef __IMemory_H
#define __IMemory_H


#include <map>




class IMemory
{
	public:
		enum _INSTRUCTIONS
		{
			_I_NOP = 0x90,
			_I_CALL = 0xe8,
			_I_JMP = 0xe9,
			_I_JMP_SHORT = 0xeb,
			_I_JE_SHORT = 0x74,
			_I_JNZ_SHORT = 0x75,
			//_I_PUSH = 0x68,
		};


		void Copy(void *Source, void *Destination, size_t Size);


		void Fill(unsigned long Destination, unsigned char Fill, size_t Size, bool Recoverable = true);
		void Fill(void *Destination, unsigned char Fill, size_t Size, bool Recoverable = true);


		void Set(unsigned long Destination, unsigned char *Data, size_t Size, bool Recoverable = true);
		void Set(void *Destination, unsigned char *Data, size_t Size, bool Recoverable = true);
		void Set(unsigned long Destination, const char *Data, size_t Size, bool Recoverable = true);
		void Set(void *Destination, const char *Data, size_t Size, bool Recoverable = true);


		void Hook(void *Address, void *Destination, unsigned char Instruction = _I_CALL, size_t Size = 5, bool Recoverable = true);
		void Hook(unsigned long Address, void *Destination, unsigned char Instruction = _I_CALL, size_t Size = 5, bool Recoverable = true);
		void Hook(unsigned long Address[], size_t Count, void *Destination, unsigned char Instruction = _I_CALL, size_t Size = 5, bool Recoverable = true);
		void Hook(void *Address, unsigned long Destination, unsigned char Instruction = _I_CALL, size_t Size = 5, bool Recoverable = true);
		void Hook(unsigned long Address, unsigned long Destination, unsigned char Instruction = _I_CALL, size_t Size = 5, bool Recoverable = true);
		void Hook(unsigned long Address[], size_t Count, unsigned long Destination, unsigned char Instruction = _I_CALL, size_t Size = 5, bool Recoverable = true);


		void HookAPI(void *Address, unsigned long Destination);
		void HookAPI(unsigned long Address, unsigned long Destination);
		void HookAPI(void *Address, void *Destination);
		void HookAPI(unsigned long Address, void *Destination);


		void Restore(void *Address);
		void Restore(unsigned long Address);
		void Restore(unsigned long Address[], size_t Count);
		
		void Restore(unsigned long Address, void *Destination); // API Hook restore
};


#endif
 
Upvote 0
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
However this Linker Problem, is a C++/Visual Studio Problem no Kal Problem, so this kind of problems have nothing todo with kal itself : )
I also got many of this Problems and even if someone would fix it for you now (for example with teamviewer), it wouldnt help you. You need to get into these kind of Problems with the C++ Language itself and with the Compiler + Linker. Try to figure out how to solve Linker Problems and try to understand why they occur there are also many many Stackoverflow Hints. This is the way i took and this is the way i recommend. Learning by doing, try and fail. Otherwise you may stuck at a Level: c&p -> tv -> c&p -> tv -> c&p -> tv -> finished but dont know why it works and thats very bad. Enough Information is out there, i did it, many other people did so, you can do so!
I can give you another example wich is basicly very similar. I started to learn chess. At first i watched many Chess Videos and tried todo what other People said, even tried to play what the Chess Engine "told" me, but this didnt improved my Chess i stucked at the same Level. Then i buyed a proper Chess Board and began to solve Chess Puzzles from Chess Books and found out solutions for myself, trying to understand Position/Tactics and Strategy for myself and finally i got better.
 
Upvote 0

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
I'm fully aware that this is a coding issue.

I've already tried everything I could think of, comparing my project with kealy's project, but I still can't figure out what I'm doing wrong.
So right now I feel like I'm stuck in the corner with no idéas left. I have no clue where to look next.
 
Upvote 0
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
maybe Darn, Akamaru or TheDragon or ... could say something to this, how did you proceeded with such Problems?
How did you got into this matter? ( i study computer science this could be my reason, but doesnt fit for everyone )
 
Upvote 0
Banned
Banned
Joined
Jul 8, 2007
Messages
1,628
Reaction score
1,619
I know this is possible going to sound really stupid and I'll prob get flamed for this, But have you tried attatching Ollybg to see where it crashes in the main server? might pin point where the error is a little better.
 
Upvote 0

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
I started from scratch, and now I managed to compile it on first try without errors.
But now there is a new problem.

The player doesn't teleport on login.
Code:
void __fastcall Teleport_OnLoadPlayer(int *Playerpointer, int __edx)
{
    KPlayer *player = new KPlayer(Playerpointer);
    player->Teleport(0, 257491, 258584);
Server::CChar::Lock((int)Playerpointer);
}

Code:
void KPlayer::Teleport(int map, int x, int y)
{
    __asm mov eax,[ecx]
    __asm push eax
    int* coord = new int[2];
    __asm pop eax
    __asm push 0
    __asm push 0
    __asm mov edi, [coord]
    __asm mov ecx, [ebp+12] 
    __asm mov [edi], ecx
    __asm mov ecx, [ebp+16] 
    __asm mov [edi+4], ecx
    __asm push edi
    __asm mov edx, [ebp+8]
    __asm push edx
    __asm mov edx, 0x0045CC90
    __asm mov ecx, eax
    __asm call edx
}

Is this "HookAPI" supposed to call my function whenever the function on the address is executed?



EDIT: problem solved, thanks to r3vo.
 
Last edited:
Upvote 0
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
"EDIT: problem solved, thanks to r3vo."

Maybe you can explain to everyone what the problem was, it could be useful for other members to understand : )
 
Upvote 0

ToF

Master Summoner
Joined
Jun 12, 2007
Messages
513
Reaction score
170
This method was the first thing I tried before attempting to rewrite the entire function.
But it failed, but back then I did not use SetMap/X/Y/Z and SaveAllProperty.
I was attempting to do it by simply using "player->Teleport(0,123,123);"

It seems that I was not far off from the start, but everything is not that obvious, at least not for everyone.
This is the solution I am using now.
Code:
void __fastcall OnLoadPlayer(void *Player,void *edx,int Value)
{
	KPlayer *player = new KPlayer(Player);
	Server::CPlayer::OnLoadPlayer(Player,Value);
	int asd = player->GetGid();
	if(asd == 517)
	{
	player->SetMap(0);
	player->SetXCoord(257491);
	player->SetYCoord(258584);
	player->SetZCoord(16168);
	Server::CPlayer::SaveAllProperty((int)Player,0);
	player->Teleport(0,0,0); 
	}
	delete player;
}
 
Upvote 0
Elite Diviner
Joined
Feb 8, 2012
Messages
439
Reaction score
867
Okay this is the API Hook way, but keep in mind this do not always work sometimes you are forced to use another way, the Intercept way for example
 
Upvote 0
Back
Top