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 


Enable/Disable Section help

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

Joined: 22 Dec 2011
Posts: 51

PostPosted: Sat Jun 28, 2014 5:25 am    Post subject: Enable/Disable Section help Reply with quote

Hi,

I tried looking around for something that relates to what I'm trying to do, but can't find a specific thread for it. There is a script I currently use with aobscan that takes several seconds to activate. Sometimes I want to disable it and enable it again after modifying a number in it, or just disable it.

Below is the original script which will set a fixed number of items when I'm stacking them.
Code:
[enable]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)
label(placeitems)
registersymbol(placeitems)
aobscan(aob1,03 CE 89 48 04)

newmem:

mov [rax+04],#20

originalcode:
add ecx,esi
//mov [rax+04],ecx

exit:
jmp returnhere

aob1:
placeitems:
jmp newmem
returnhere:

[disable]
dealloc(newmem)
placeitems:
db 03 CE 89 48 04
unregistersymbol(placeitems)


See how I have #20 moving into [rax+04]. Sometimes I want to change that number, but it's annoying with waiting several seconds for it to activate again. I decided to try and write the below script to do the following:

-Enable/disable section for quick disabling without turning off the script
-Make it possible to modify the number to move into [rax+04] without having to deactivate the script
-Make it so the number to move into [rax+04] is a minimum value instead: ex: It won't "mov" 20 into [rax+04] if the value of [rax+04] is above 20

There are problems with this script. Not sure if I'm missing something small, or if it's completely wrong. I will try to clarify further if this is confusing.

Code:
[enable]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

label(placeitems)
label(EnablePI)
label(MinItems)

registersymbol(placeitems)
registersymbol(EnablePI)
registersymbol(MinItems)

aobscan(aob1,03 CE 89 48 04)

//=========================================
// Code
newmem:
cmp dword ptr [EnablePI],0
je originalcode

cmp [rax+04],[MinItems]
jge originalcode
mov [rax+04],[MinItems]
jmp returnhere

originalcode:
add ecx,esi
mov [rax+04],ecx
jmp returnhere

exit:
jmp returnhere

aob1:
placeitems:
jmp newmem
returnhere:

//=========================================
// Variables
EnablePI:
dd 1
MinItems:
dd #20
//=========================================

[disable]
dealloc(newmem)
placeitems:
db 03 CE 89 48 04
unregistersymbol(placeitems)
unregistersymbol(EnablePI)
unregistersymbol(MinItems)


Any help is appreciated!
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Sat Jun 28, 2014 6:28 am    Post subject: Reply with quote

Quote:
-Enable/disable section for quick disabling without turning off the script
-Make it possible to modify the number to move into [rax+04] without having to deactivate the script
-Make it so the number to move into [rax+04] is a minimum value instead: ex: It won't "mov" 20 into [rax+04] if the value of [rax+04] is above 20


For #1: Store the rax+4 value in a memory address somewhere when you activate the script then simply change that value instead of enabling/disabling the script for changes. Kind of like how activate trainer option functions.

For #2:
cmp [rax+04],[MinItems]
jge originalcode
mov [rax+04],[MinItems]
jmp returnhere

The above will skip even if rax has 20 value. IF you don't want that just change it to jg and it should only skip when the value is above 20.



PS: i am half-baked so apologies if i missed something but that should be it.

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Classicus
Advanced Cheater
Reputation: 0

Joined: 22 Dec 2011
Posts: 51

PostPosted: Sat Jun 28, 2014 9:54 am    Post subject: Reply with quote

STN wrote:

For #1: Store the rax+4 value in a memory address somewhere when you activate the script then simply change that value instead of enabling/disabling the script for changes. Kind of like how activate trainer option functions.

For #2:
cmp [rax+04],[MinItems]
jge originalcode
mov [rax+04],[MinItems]
jmp returnhere

The above will skip even if rax has 20 value. IF you don't want that just change it to jg and it should only skip when the value is above 20.



PS: i am half-baked so apologies if i missed something but that should be it.


Thanks for the reply! For your reply to #1:
I'm still picking up assembly and I'm completely new to storing anything from a script in a memory address. How can I go about writing rax+4 into a memory address?

Reply to #2:
This piece of the code itself is broken. The first part, "cmp [rax+04],[MinItems]", can't be compiled and the script won't activate with that. Not really sure how to write it so it can recognize what I am trying to say. I think I might have to use a push/pop, and use the pushed memory to move [MinItems] into it, which at that point I can use that pushed memory to cmp without any issues. But I've never done anything like this before and I could be completely wrong about it. If not, I'm not sure how to write it.

Still learning assembly and this is a new step forward for me. I'm pretty sure this can be done, but I'm lost on how to go about it. Maybe knowing how to write rax+4 into a memory address is a start.
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Sat Jun 28, 2014 11:15 am    Post subject: Reply with quote

You can't generally move memory directly from one location to another. You've got to use intermediate registers. So, move from MinItems to a register and then compare. mov rbx,[minitems]... cmp rbx,[rax+4]... etc
_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on...
Back to top
View user's profile Send private message
Amami De Kaito
Expert Cheater
Reputation: 5

Joined: 06 Feb 2013
Posts: 110
Location: 3/44

PostPosted: Sat Jun 28, 2014 8:06 pm    Post subject: Reply with quote

Example

Code:
[enable]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

label(placeitems)
label(EnablePI)
label(MinItems)

registersymbol(placeitems)
registersymbol(EnablePI)
registersymbol(MinItems)

aobscan(aob1,03 CE 89 48 04)

//=========================================
// Code
newmem:
cmp dword ptr [EnablePI],0
je originalcode

mov ecx,[MinItems] // Get adress into value for ecx
cmp [rax+04],ecx
jge originalcode
mov [rax+04],ecx
jmp returnhere

originalcode:
add ecx,esi
//mov [rax+04],ecx
jmp returnhere

exit:
jmp returnhere

// Variables
EnablePI:
dd 1
MinItems:
dd #20

aob1:
placeitems:
jmp newmem
returnhere:

[disable]
dealloc(newmem)
placeitems:
db 03 CE 89 48 04
unregistersymbol(placeitems)
unregistersymbol(EnablePI)
unregistersymbol(MinItems)
Back to top
View user's profile Send private message Send e-mail
Classicus
Advanced Cheater
Reputation: 0

Joined: 22 Dec 2011
Posts: 51

PostPosted: Sat Jun 28, 2014 9:26 pm    Post subject: Reply with quote

Thanks for the replies everyone! I finally got it working nicely using the below script. I also added an extra section because of how the game acts when stacking items. When I use jg original code, it will keep items at 20 no matter how much I stack, which is useful sometimes. With jge original code, it will move the stack to 20 if its less than that, then continue to build normally [21, 22, 23, etc...] which is useful in other cases.

justa_dude, I took your advice with using rbx which made everything work perfectly. I have to do more reading on registers and intermediate registers. I didn't know you can add a register that was not originally in the code.

Amami De Kaito, thanks for that script! I got it working with your script, but it didn't act exactly how I wanted it to because of the original code not being used "//mov [rax+04],ecx ". It was good for having fixed items though, but I also wanted to have it increase normally if the minimum is 20. I tried removing the //, but then it acted a bit strange I think because ecx was being modified in newmem. So I combined this with what justa_dude mentioned about adding an intermediate register and everything worked out perfectly.


Code:
[enable]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

label(placeitems)
label(EnablePI)
label(MinItems)
label(newcode)
label(newcode2)

registersymbol(placeitems)
registersymbol(EnablePI)
registersymbol(MinItems)
registersymbol(newcode)
registersymbol(newcode2)

aobscan(aob1,03 CE 89 48 04)

// Code
newmem:
cmp dword ptr [EnablePI],0
je originalcode
cmp dword ptr [EnablePI],1
je newcode
cmp dword ptr [EnablePI],2
je newcode2

newcode:
mov rbx,[MinItems]
cmp [rax+04],rbx
jg originalcode
mov [rax+04],rbx
jmp returnhere

newcode2:
mov rbx,[MinItems]
cmp [rax+04],rbx
jge originalcode
mov [rax+04],rbx
jmp returnhere

originalcode:
add ecx,esi
mov [rax+04],ecx
jmp returnhere

exit:
jmp returnhere

// Variables
EnablePI:
dd 2
MinItems:
dd #20


aob1:
placeitems:
jmp newmem
returnhere:


[disable]
dealloc(newmem)
placeitems:
db 03 CE 89 48 04
unregistersymbol(placeitems)
unregistersymbol(EnablePI)
unregistersymbol(MinItems)
unregistersymbol(newcode)
unregistersymbol(newcode2)


edit: Actually, I modified newcode since the purpose of that is to set a fixed number and keep it regardless of how much I'm stacking. That piece of the code is now:
Code:
newcode:
mov rbx,[MinItems]
mov [rax+04],rbx
jmp returnhere


I can probably move [MinItems] directly into rax+4, but left it this way in case I decide to do something with this piece of the code later which might require the intermediate register.
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Sun Jun 29, 2014 2:33 am    Post subject: Reply with quote

Classicus wrote:

Reply to #2:
This piece of the code itself is broken. The first part, "cmp [rax+04],[MinItems]", can't be compiled and the script won't activate with that. Not really sure how to write it so it can recognize what I am trying to say. I think I might have to use a push/pop, and use the pushed memory to move [MinItems] into it, which at that point I can use that pushed memory to cmp without any issues. But I've never done anything like this before and I could be completely wrong about it. If not, I'm not sure how to write it.

Still learning assembly and this is a new step forward for me. I'm pretty sure this can be done, but I'm lost on how to go about it. Maybe knowing how to write rax+4 into a memory address is a start.


Ugh..yes i totally missed that part. Yeah you can't do that as justdude told you. Anyway, good to hear you got it working in the end, i noticed a small thing that you should take care of in your code and most importantly learn.

newcode:
mov rbx,[MinItems]
mov [rax+04],rbx
jmp returnhere

You are lucky rbx isn't used for something critical by game or you will be having a nasty crash with that code. You need to save the value of rbx or any register you change the value of and then restore it when you are done like this
newcode:
push rbx
mov rbx,[MinItems]
mov [rax+04],rbx
pop rbx
jmp returnhere

in the places where you used a cmp, make sure you place the pop where it will have a chance to be executed however the outcome of cmp maybe so in your code, i would push here

newmem:
push rbx

and pop at the very end

exit:
pop rbx
jmp returnhere

and make all your jmp returnhere to jmp exit so the pop gets executed.

Seems like you don't need to for this injection as you have luckily picked up a spot where rbx value isn't crucial (it seems, few hours into game it may glitch or even crash) but you need to learn this and so does Amami De Kaito who surprisingly has done the same mistake (a bad teacher is worse than ...ah fuck it can't remember the quote) but you get it.

Edit: so your final code would be

[enable]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

label(placeitems)
label(EnablePI)
label(MinItems)
label(newcode)
label(newcode2)

registersymbol(placeitems)
registersymbol(EnablePI)
registersymbol(MinItems)
registersymbol(newcode)
registersymbol(newcode2)

aobscan(aob1,03 CE 89 48 04)

// Code
newmem:
push rbx
cmp dword ptr [EnablePI],0
je originalcode
cmp dword ptr [EnablePI],1
je newcode
cmp dword ptr [EnablePI],2
je newcode2

newcode:
mov rbx,[MinItems]
cmp [rax+04],rbx
jg originalcode
mov [rax+04],rbx
jmp exit

newcode2:
mov rbx,[MinItems]
cmp [rax+04],rbx
jge originalcode
mov [rax+04],rbx
jmp exit

originalcode:
add ecx,esi
mov [rax+04],ecx
jmp exit

exit:
pop rbx
jmp returnhere

// Variables
EnablePI:
dd 2
MinItems:
dd #20


aob1:
placeitems:
jmp newmem
returnhere:


[disable]
dealloc(newmem)
placeitems:
db 03 CE 89 48 04
unregistersymbol(placeitems)
unregistersymbol(EnablePI)
unregistersymbol(MinItems)
unregistersymbol(newcode)
unregistersymbol(newcode2)

Hopefully i haven't missed something again as that would be embarrassing this time around

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Classicus
Advanced Cheater
Reputation: 0

Joined: 22 Dec 2011
Posts: 51

PostPosted: Sun Jun 29, 2014 7:55 am    Post subject: Reply with quote

Thanks for the reply STN! I'd like to give rep to all of you for being so helpful but I don't have that capability yet. I was wondering about using push/pop because I saw that used in a similar script for another game concerning gold.

I was wondering in cases like this script I have here, how do I know which register to use. There are many different registers and I'm not sure if there are recommended registers, or maybe use anything not currently being used in the script. I'm guessing with push/pop, I can basically pick any register not currently being used in this script and it won't conflict with anything else in the game?
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Sun Jun 29, 2014 10:41 pm    Post subject: Reply with quote

Classicus wrote:
Thanks for the reply STN! I'd like to give rep to all of you for being so helpful but I don't have that capability yet. I was wondering about using push/pop because I saw that used in a similar script for another game concerning gold.

I was wondering in cases like this script I have here, how do I know which register to use. There are many different registers and I'm not sure if there are recommended registers, or maybe use anything not currently being used in the script. I'm guessing with push/pop, I can basically pick any register not currently being used in this script and it won't conflict with anything else in the game?


You can use any or a combination of general purpose registers (eax,ebx,ecx,edx) or even edi on occasions as long as they are not used by the part of the instruction you're modifying or close to that instruction.
Other registers are special purpose register and you can modify them but they store data critical to execution of the program (e.g eip/esp etc) and if you don't know what you're doing you can crash the program with them.

And yes you can use any general purpose register as long as you push/pop correctly so as to not mess up the values when they are needed.

Some people just go for the lazy approach and just pushad/popad, what this does is save all registers/restore all so they can modify any without the worry of messing up the wrong register.

You should also remember pushfd/popfd...these are valuable in times when you think you might mess up one of the EFLAGS values (zf,cf etc).

Hope this helps

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Classicus
Advanced Cheater
Reputation: 0

Joined: 22 Dec 2011
Posts: 51

PostPosted: Mon Jun 30, 2014 12:25 am    Post subject: Reply with quote

STN wrote:

You can use any or a combination of general purpose registers (eax,ebx,ecx,edx) or even edi on occasions as long as they are not used by the part of the instruction you're modifying or close to that instruction.
Other registers are special purpose register and you can modify them but they store data critical to execution of the program (e.g eip/esp etc) and if you don't know what you're doing you can crash the program with them.

And yes you can use any general purpose register as long as you push/pop correctly so as to not mess up the values when they are needed.

Some people just go for the lazy approach and just pushad/popad, what this does is save all registers/restore all so they can modify any without the worry of messing up the wrong register.

You should also remember pushfd/popfd...these are valuable in times when you think you might mess up one of the EFLAGS values (zf,cf etc).

Hope this helps


This is very helpful! Thanks for the extra info. It will definitely come in handy many times.
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