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 


How to inject two pieces of code onto the same address?

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

Joined: 22 Aug 2017
Posts: 4

PostPosted: Tue Aug 22, 2017 3:46 pm    Post subject: How to inject two pieces of code onto the same address? Reply with quote

I'm currently hacking a game that uses the same code for enemy cooldown and my own cooldown. Like this:
Code:

//fld something
fadd dword ptr [ecx+08]
fstp dword ptr [ecx+08]

the value of ecx determines which cooldown to control.

I want to have two pieces of code that A will reduce my own CD and B will put enemy permanently on cooldown, each with a separate enable/disable control. However, as you can see, though writing each of the scripts is easy, just compare the value of ecx to a given value, they cannot be enabled at the same time because both are rewriting the same code address.

My question is, is there any way to make this work? E.g. is it possible to make the originalcode part dynamically generated? Sorry if there're some functions in CE that I haven't realized, I'm still quite new to this. And thanks for your help.

On a side note, directly locking the value at [ecx+08] will not work because the game somehow requires it to be reset to 0 when cooldown is complete.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Aug 22, 2017 6:14 pm    Post subject: Reply with quote

Post both scripts. Then we will help you combining them into one script.

The piece of code you found is a "shared code", it's a common thing. In many games we have to combine "God Mode" and "One Hit Kill" scripts into one script.

_________________
Back to top
View user's profile Send private message MSN Messenger
zypA13510
How do I cheat?
Reputation: 0

Joined: 22 Aug 2017
Posts: 4

PostPosted: Tue Aug 22, 2017 7:27 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
Post both scripts. Then we will help you combining them into one script.

The piece of code you found is a "shared code", it's a common thing. In many games we have to combine "God Mode" and "One Hit Kill" scripts into one script.


I know how to code, but the question is how to give "god mode" and "one hit kill" each a switch? The code is actually quite long due to multi-level pointers and having to enumerate through all my skills. But I guess maybe you can give me an example using this simplified version?

Code:

[ENABLE]
alloc(newmem,2048)
label(code)
label(return)

newmem:
code:
mov eax,0000ABCD //assume 0000ABCD is mine, 0001BCDE is enemy
cmp ecx,eax
jnz enemy
//code for my CD
fadd dword ptr [ecx+0C] //cooldown max stored here in ecx+0C
fstp dword ptr [ecx+08]
jmp return
enemy:
//code for enemy CD
fstp dword ptr [ecx+08] //no fadd so they never get CD
jmp return

"Game.exe"+123456:
jmp newmem
nop
return:

[DISABLE]
dealloc(newmem)
"Game.exe"+123456:
fadd dword ptr [ecx+08]
fstp dword ptr [ecx+08]


The issue for the code above is that, if you enable "god mode" you are also enabling "one hit kill", which is not what I wanted. So what's your solution to give them individual switch?

btw. what'd happen when I use a label without explicitly declaring them with label() statement? like the enemy: in the example above? In practice I found it working without having to include label(). That left me wonder what does label() do exactly?
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1587

PostPosted: Tue Aug 22, 2017 9:22 pm    Post subject: Reply with quote

zypA13510 wrote:
The issue for the code above is that, if you enable "god mode" you are also enabling "one hit kill", which is not what I wanted.

simple, create a switch/key for K.O. cheat.

zypA13510 wrote:
btw. what'd happen when I use a label without explicitly declaring them with label() statement? like the enemy: in the example above? In practice I found it working without having to include label(). That left me wonder what does label() do exactly?

CE internally knows that everything ends with a colon : means a label, so whether you declared and used the keyword label or not it will work.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote:
i am a sweetheart.
Back to top
View user's profile Send private message Visit poster's website
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Tue Aug 22, 2017 11:59 pm    Post subject: Reply with quote

May try like this pseudocode:
Code:


modifyrate:
dd (float)10,(float)100,(float)0.01,(float)1
// playerRate, AllyRate, EnemyRate, NormalRate

label(rateSet)
code:
  push  eax
    testIfPlayer()  /// ie: cmp ecx,0000ABCD
    jne @f /// try next test
    mov eax,0
    jmp  rateSet
@@:
    testIfAlly()  /// ie: cmp ecx,000666
    jne @f /// try next test
    mov eax,1
    jmp  rateSet
@@:
    testIfEnemy()  /// ie: cmp ecx,0001BCDE
    jne @f /// try next test, but it is last one
    mov eax,2
    jmp  rateSet
@@: /// isNormal
    mov eax,3
//  jmp  rateSet
rateSet:
    ///  assume there is a cooldown addition value in fpu stack top
    fmul dword ptr[eax*4+modifyrate]  /// change the addition by a factor

    fadd dword ptr [ecx+0C] //cooldown max stored here in ecx+0C   
    fstp dword ptr [ecx+08]
  pop   eax


note:
jmp @f means jump forwardly to first next label, named (eg. rateSet: ) or unnamed ( @@: )
There is also jmp @b means jump backwardly to last prev label

It only change where the modifyRate and not duplicating multiuple fadd...etc. may let code a bit more structural and easier to follow. It is like a nested if-then-else in lua emulating switch-cases in c (?).

In godmode/onehitkill case, suppose the original code is like this:
Code:

  fld   dword ptr[entity hp]// original hp
  fsub  dword ptr[normalDamgeAmount]// damage amount
  fstp  dword ptr[entity hp]// update decreased hp


It can be modify as

Code:

modifyDamage:
dd (float)0.0,(float)66e6
/// godmode, ohk

label(damageSet)
code:
  push  eax

    lea  eax,[normalDamgeAmount]  /// default to no change of damage
   
    testIfPlayer()  /// ie: cmp ecx,0000ABCD
    jne @f /// try next test
    cmp  byte ptr[bGodMode],0
    je  @f  /// skip if GodMode off
    mov eax,modifyDamage   /// point to 0.0 damage
    jmp  damageSet  //// read as {{ if isPlayer and isGodMode then use GodMode DamageAmount }}
@@:
    testIfEnemy()  /// ie: cmp ecx,0001BCDE
    jne @f /// try next test, but it is last one, which use no change
    cmp  byte ptr[bOneHitKill],0
    je  @f  /// skip if ohk off
    mov eax,modifyDamage+4 /// point to 66e6 damage
//  jmp  damageSet//// read as {{ if isEnemy and isOneHitKill then use OneHitKill DamageAmount }}

damageSet:
  fld   dword ptr[entity hp]// original hp
  fsub  dword ptr[eax]// damage amount in eax address
  fstp  dword ptr[entity hp]// update decreased hp
  pop   eax


NOTE:
1.depend on the test, sometime "jne" means a truth value (eg. in bGodmode test), sometime "je" means a truth value (eg. in ecx compare with player or enemy)
2.Try to understand the code instead of copy and paste.

---
It is better to use the switch
Code:

{$strict}

to force explicitly declare label, so that typo error etc can be catch.
Many reported errors are better than a silent one.

_________________
- Retarded.
Back to top
View user's profile Send private message
zypA13510
How do I cheat?
Reputation: 0

Joined: 22 Aug 2017
Posts: 4

PostPosted: Wed Aug 23, 2017 3:23 pm    Post subject: Reply with quote

panraven wrote:
It only change where the modifyRate and not duplicating multiuple fadd...etc. may let code a bit more structural and easier to follow. It is like a nested if-then-else in lua emulating switch-cases in c (?).

Thank you. I read your code, but I still don't see how will this help? I mean, yeah, you used an if-elseif structure. But once this code is executed(injected), how can I turn off one of the cheats (e.g. give enemy normal CD rate but still reducing my own CD time), via control/checkbox in CE? What I need are two switches(not the switch in switch-case), each responsible for the activation/deactivation of one cheat, how can I do that? Is there any way to change modifyRate in your code that I do not know?

OldCheatEngineUser wrote:
zypA13510 wrote:
The issue for the code above is that, if you enable "god mode" you are also enabling "one hit kill", which is not what I wanted.

simple, create a switch/key for K.O. cheat.

um, how? Can you give me an example, or maybe a link to a tutorial about this? Point me in the right direction please, thanks.
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Wed Aug 23, 2017 4:48 pm    Post subject: Reply with quote

I dont know if you missed this in panraven's example, but:

Code:
modifyDamage:
dd (float)0.0,(float)66e6

and

cmp  byte ptr[bGodMode],0

or

cmp  byte ptr[bOneHitKill],0


these are the separate variables and the switch.

All you need to do is create the variable and store it in your table

for example add this in the enable of a parent script to panraven's great example
Code:

alloc(bGodMode,$8)
bGodMode:
dq 0
registersymbol(bGodMode)


and this in the disable of the same script

Code:
dealloc(bGodMode)
unregistersymbol(bGodMode)


you can now add the address bGodMode to your table and it will act as a variable (or make a script which sets and unsets the value as a toggle)

Please note that I used quadword instead of byte, it doesnt matter (unless you are tight on available space) as long as your table uses 0 = off and anything = on

Also, don't forget to do this for all of the variables and/or the damage values...

One last thing, you were borderline rude to panraven who gave you a very good example with some explanation because you didn't understand the meaning of the underlying assembly. Please just ask for more help understanding what has been provided to you instead of coupling the request for help with anything that may be aggressive/rude. The community here is exceptional at helping out, so don't alienate yourself!
Back to top
View user's profile Send private message
zypA13510
How do I cheat?
Reputation: 0

Joined: 22 Aug 2017
Posts: 4

PostPosted: Wed Aug 23, 2017 8:49 pm    Post subject: Reply with quote

cooleko wrote:
I dont know if you missed this in panraven's example

Yes, I did miss that part, sorry. I followed the jne route and forget about the other part. My bad Sad. I can see how this functions now.

cooleko wrote:
One last thing, you were borderline rude to panraven who gave you a very good example with some explanation because you didn't understand the meaning of the underlying assembly.
I majored in CS so of course I do understand assembly. But I don't use them as part of my work. And I'm sorry if my post feels rude to you, I'm not trying to, I did say "Thank you" at the beginning of my reply. Maybe it's because I'm not natively English, if this caused any misunderstanding I'm sorry. And thank you for pointing out what I missed.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Thu Aug 24, 2017 12:33 am    Post subject: Reply with quote

Thanks cooleko.
Sorry for late response I was stuck in workplace without internet during a typhoon.
May be I'm not native English speaking too, I don't feel zypA13510 rude.
Anyway I'm glad the reply make some sense.

_________________
- Retarded.
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