Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[c++] need help with code caving

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
STAB
How do I cheat?
Reputation: 0

Joined: 11 Sep 2015
Posts: 4

PostPosted: Mon May 04, 2020 8:26 am    Post subject: [c++] need help with code caving Reply with quote

hello, im trying to get these zombies base address (from pvz) by hooking this function, but looks like something wrong with my code that causing it to crash but i dont know what it is.
Code:
const int zCount = 1;
uintptr_t basezombie = 0x005318C3; //pos
uintptr_t jmpback = basezombie + 0x6;
Zombies* zombies[zCount]; //one for now
Zombies* zPtr;
bool alreadyThere = false;
__declspec(naked) void hookZombies() {
   __asm {
      fld dword ptr[esi + 0x2C]  //original instruction
      //mov zObj, esi
      //push eax
      mov eax, esi
      mov[zPtr], eax

   }
   if (zPtr == nullptr) {
      goto STOP;
   }

   for (int i = 0; i < zCount; i++) {
      if (zombies[i] == zPtr) {
         if (zombies[i]->health > 1 && zombies[i]->health < 1000) {
            alreadyThere = true;
            break;
         } else
            alreadyThere = false;
      }
      else
         alreadyThere = false;
   }
   
   if (alreadyThere) goto STOP;
   else {
      for (int i = 0; i < zCount; i++) {
         if (zombies[i] == 0) {
            zombies[i] = zPtr;
            break;
         }
      }
   }
STOP:
   __asm {
      //pop eax
      mov eax, [esi + 0x04]      //original instruction
      //jmp[jmpback]
      ret
   }
}

if i just use this
Code:

__asm {
fld dword ptr[esi + 0x2C]  //original instruction
mov eax, [esi + 0x04]     //original instruction
//jmp[jmpback]
ret
}

it works just fine.

maybe thats EDX should've not been 1, idk. please help



dw.PNG
 Description:
causes of crash
 Filesize:  111.65 KB
 Viewed:  1026 Time(s)

dw.PNG


Back to top
View user's profile Send private message
STAB
How do I cheat?
Reputation: 0

Joined: 11 Sep 2015
Posts: 4

PostPosted: Mon May 04, 2020 11:13 pm    Post subject: Reply with quote

nvm, fixed by using different address that accessing the zombies base address
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites