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 


hack works fine in CE but behaves incorrectly in C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
themandem
Cheater
Reputation: 0

Joined: 06 Dec 2019
Posts: 35

PostPosted: Sun Sep 03, 2023 11:14 pm    Post subject: hack works fine in CE but behaves incorrectly in C++ Reply with quote

this comparison at offset 0x440 is what i'm using for a godmode + one hit kill cheat. both godmode and one hit kill work just fine in cheat engine when i create a script. but in visual studio when i make a DLL and inject, the code behavior is incorrect. i cannot for the life of me figure out why its doing that.

Code:
cmp dword ptr [eax+ecx+0x440], 0  ;// isPlayer check
je godmode
cmp byte ptr [ohk_flag], 1
je ohk
jmp code


i debugged the code and when i inject the DLL and activate the cheat, the comparison never even goes past 'je godmode'. I can't post pictures here but, at offset 0x440, the value 0 is for player chars, and the 49152 is for enemy (4 byte). like i said, the godmode + one hit kill works fine when i create script in cheat engine, but for some reason when i make it in a DLL in visual studio, and activate it, it sees both player and enemy values at offset 0x440 as zero. 😵‍💫 thus applying godmode to everyone even enemies, and causing one hit kill to not work at all.

in visual studio, i am not strictly using C++ ... i'm using the inline assembly, which works fine for x86 games which my game is. let me know if anyone got ideas, i'll post my code:

Code:
bool godmode_flag{0};
bool ohk_flag{0};
DWORD JumpBack0{};


Code:
_declspec(naked) void TestHookCode0()  ;// Godmode and One Hit Kill
{
    __asm
    {
    newmem:
        cmp dword ptr[eax + ecx + 0x440], 0  ;// isPlayer check
        je godmode
        cmp byte ptr [ohk_flag], 1
        je ohk
        jmp code

      godmode:
        cmp byte ptr [godmode_flag], 0
        je code

        mov bx, 999
        mov[eax + ecx], bx
        lea ecx, [edi + 04]
        jmp[JumpBack0]

      ohk:
        mov[eax + ecx], 0
        lea ecx, [edi + 04]
        jmp[JumpBack0]

      code:
        mov[eax + ecx], bl
        lea ecx, [edi + 04]
        jmp[JumpBack0]
    }
}


the 'cmp' part is the problem. before you say the comparison is incorrect and to find a different value/offset, i just wanna reiterate, the comparison works fine when i create a script with identical code in cheat engine. only in visual studio, its behaving incorrectly...


Last edited by themandem on Mon Sep 04, 2023 1:20 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25298
Location: The netherlands

PostPosted: Mon Sep 04, 2023 12:24 am    Post subject: Reply with quote

you're sure that the detour code to your function doesn't mangle eax?
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
themandem
Cheater
Reputation: 0

Joined: 06 Dec 2019
Posts: 35

PostPosted: Mon Sep 04, 2023 1:04 am    Post subject: Reply with quote

Dark Byte wrote:
you're sure that the detour code to your function doesn't mangle eax?

i don't think so. i was debugging in CE and MSVS earlier and checked eax behaviour (like the value in eax) from both my cheat engine script and the DLL. eax behaved the same way after i stepped over the cmp dword ptr[eax + ecx + 0x440], 0 line for both hacks.

setting breakpoint on hook, value in eax is 0x3. after i step over the line cmp dword ptr[eax + ecx + 0x440], 0
eax value is still 0x3.

edit: not sure how to fix name mangling but i tried this, however it's still behaving incorrect
Code:
 push eax
 cmp dword ptr[eax + ecx + 0x440], 0  ;// isPlayer check
 pop eax
 je godmode


edit 2: fixed i guess? I found an alternate comparison. still if anyone knows the solution to my initial problem, i'd like to dig deeper and find out why the old cmp wasn't working
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 334
Location: Somewhere....

PostPosted: Thu Sep 07, 2023 7:23 am    Post subject: Reply with quote

-not just eax that is the problem, your address relies on the ecx register as well.
-you have to specify the values of the registers exactly as the game does, if that fuction changes one of them by the point you are executing the cmp instruction, then your address is already mangled.
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 programming 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