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 


Using labels to make different actions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
aikoncwd
Grandmaster Cheater
Reputation: 23

Joined: 21 Dec 2012
Posts: 591
Location: Spain (Barcelona)

PostPosted: Tue Dec 30, 2014 7:05 am    Post subject: Using labels to make different actions Reply with quote

Hi

I'm here again, dealing with another stupid question about autoassembler. I coded a simple EXE to practice. I want to to make a (user-friendly) table with checkboxes to activate different options. I know I can make a trainer but this is not the request, I want to know is this is possible using only tables:

Here is the main script:

Code:
[ENABLE]

aobscanmodule(FindValue,example.exe,89 56 34 C7 45 FC 00 00 00 00)
alloc(newmem,$1000)

label(code)
label(return)

globalalloc(pValue,4)

label(optionAdd)          //var used to determine action
registersymbol(optionAdd)

label(jmpOpt1)            //action when option = 1
label(jmpOpt2)            //action when option = 2

newmem:

optionAdd:
 dd 0                     //Initialize witn no option (0)
                          //Is this declared ok?
code:
  mov [esi+34],edx
  mov [pValue],esi        //store the value and show in the table

  cmp [optionAdd],1
  je jmpOpt1

  cmp [optionAdd],2
  je jmpOpt2

  mov [ebp-04],00000000
  jmp return

jmpOpt1:
  add edx,2
  mov [esi+34],edx
  mov [ebp-04],00000000
  jmp return

jmpOpt2:
  add edx,3
  mov [esi+34],edx
  mov [ebp-04],00000000
  jmp return

FindValue:
  jmp code
  nop
  nop
  nop
  nop
  nop
return:
registersymbol(FindValue)

[DISABLE]

FindValue:
  db 89 56 34 C7 45 FC 00 00 00 00

unregistersymbol(optionAdd)
unregistersymbol(FindValue)
dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: "example.exe"+1C38

"example.exe"+1C1E: 83 E0 01              -  and eax,01
"example.exe"+1C21: 89 45 FC              -  mov [ebp-04],eax
"example.exe"+1C24: 83 E6 FE              -  and esi,-02
"example.exe"+1C27: 56                    -  push esi
"example.exe"+1C28: 89 75 08              -  mov [ebp+08],esi
"example.exe"+1C2B: 8B 0E                 -  mov ecx,[esi]
"example.exe"+1C2D: FF 51 04              -  call dword ptr [ecx+04]
"example.exe"+1C30: 8B 56 34              -  mov edx,[esi+34]
"example.exe"+1C33: 83 EA 01              -  sub edx,01
"example.exe"+1C36: 70 29                 -  jo example.exe+1C61
// ---------- INJECTING HERE ----------
"example.exe"+1C38: 89 56 34              -  mov [esi+34],edx
"example.exe"+1C3B: C7 45 FC 00 00 00 00  -  mov [ebp-04],00000000
// ---------- DONE INJECTING  ----------
"example.exe"+1C42: 8B 45 08              -  mov eax,[ebp+08]
"example.exe"+1C45: 50                    -  push eax
"example.exe"+1C46: 8B 08                 -  mov ecx,[eax]
"example.exe"+1C48: FF 51 08              -  call dword ptr [ecx+08]
"example.exe"+1C4B: 8B 45 FC              -  mov eax,[ebp-04]
"example.exe"+1C4E: 8B 4D EC              -  mov ecx,[ebp-14]
"example.exe"+1C51: 5F                    -  pop edi
"example.exe"+1C52: 5E                    -  pop esi
"example.exe"+1C53: 64 89 0D 00 00 00 00  -  mov fs:[00000000],ecx
"example.exe"+1C5A: 5B                    -  pop ebx
}


As you can see, I create a label named optionAdd, depending on the value of optionAdd (0, 1 or 2), the script will execute different actions. This script is working well and I assume I declared every label in the correct position. Now I have 2 additional scripts:

Option=1 script

Code:
[ENABLE]
optionAdd:
 dd 1
 
[DISABLE]
optionAdd:
 dd 0


Option=2 script

Code:
[ENABLE]
optionAdd:
 dd 2

[DISABLE]
optionAdd:
 dd 0


This scripts are working well, when you click the 1st script, optionAdd is set to 1 and the main script make the correct jump. Same for option=2 script. Now the table looks like this:



My question/problem is: If user click the option=1 script, optionAdd is set to 1 and if user inmediatly click option=2 script the first script remains active (optionAdd is set to 2, this is ok). All I need is how to make the 1st script deactivated when 2nd script is clicked.

Hope I explained well, anyway I can post the table + EXE if you need to see the real example. Also I know I choose a bad injection point because the SUB is executed 2 instructions above, I know but this is only a example.

Thanks! Very Happy

_________________
Hey Hitler
Test here your skill with CheatEngine, I coded a challenge for you. Try to beat it!
HERE
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Dec 30, 2014 7:45 am    Post subject: Reply with quote

change the option scrips to:

option=1:
Code:

[enable]
{$lua}
getAddressList().getMemoryRecordByDescription('Option = 2 (add 2)').Active=false
{$asm}

optionAdd:
 dd 1

[DISABLE]
optionAdd:
 dd 0


option=2:
Code:

[enable]
{$lua}
getAddressList().getMemoryRecordByDescription('Option = 1 (add 1)').Active=false
{$asm}

optionAdd:
 dd 1

[DISABLE]
optionAdd:
 dd 0


I recommend replacing getMemoryRecordByDescription with getMemoryRecordByID(number)
the easiest way to get the ID is copy and paste the entry to notepad and get the ID part out of it. The ID never changes unless you delete the entry and make a new one. That way renaming it won't have an effect

_________________
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
aikoncwd
Grandmaster Cheater
Reputation: 23

Joined: 21 Dec 2012
Posts: 591
Location: Spain (Barcelona)

PostPosted: Tue Dec 30, 2014 7:57 am    Post subject: Reply with quote

@Dark Byte I tested and it worked as expected, I think you know it but you are the boss.

Also this method don't promt the horrible LUA warning at the begginig Very Happy
I added this to the main script in the [DISABLE] saction:

Code:
[DISABLE]

{$lua}
getAddressList().getMemoryRecordByID(4).Active=false
getAddressList().getMemoryRecordByID(5).Active=false
{$asm}

FindValue:
  db 89 56 34 C7 45 FC 00 00 00 00

unregistersymbol(optionAdd)
unregistersymbol(FindValue)
dealloc(newmem)


So the options will be unchecked when the main script is disabled.

One question... at the main script I declared:

Code:
optionAdd:
 dd 0


below to newmem, is this correct?

I think all my questions are now resolved Very Happy

_________________
Hey Hitler
Test here your skill with CheatEngine, I coded a challenge for you. Try to beat it!
HERE
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Dec 30, 2014 8:05 am    Post subject: Reply with quote

optionAdd as a label below newmem is possible.
I would just have done an alloc(optionAdd,4) and placed it at the end though
(and probably decrease the alloc of newmem a bit to make room for it)

_________________
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
aikoncwd
Grandmaster Cheater
Reputation: 23

Joined: 21 Dec 2012
Posts: 591
Location: Spain (Barcelona)

PostPosted: Tue Dec 30, 2014 10:17 am    Post subject: Reply with quote

Dark Byte wrote:
optionAdd as a label below newmem is possible.
I would just have done an alloc(optionAdd,4) and placed it at the end though
(and probably decrease the alloc of newmem a bit to make room for it)


I think I missed something because if I replace

Code:
label(optionAdd)
registersymbol(optionAdd)


With

Code:
alloc(optionAdd,4)


The option=1 script can't be activated, if I use globalalloc(optionAdd,4) I can use the scripts BUT I don't know how and where initialice optionAdd in the script.

For decrease newmen... How can I know the minimun size Im able to allocate?

_________________
Hey Hitler
Test here your skill with CheatEngine, I coded a challenge for you. Try to beat it!
HERE
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Dec 30, 2014 11:36 am    Post subject: Reply with quote

you can register allocs as well
Code:

alloc(optionAdd, 4)
registersymbol(optionAdd)


newmem size of 2048 is usually enough which leaves 2048 bytes for extra allocs

_________________
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
aikoncwd
Grandmaster Cheater
Reputation: 23

Joined: 21 Dec 2012
Posts: 591
Location: Spain (Barcelona)

PostPosted: Tue Dec 30, 2014 11:43 am    Post subject: Reply with quote

Sorry for my continuos questions...
alloc(newmem,$1000) is bigger than alloc(newmem,2048) ? Why? haha

Why you suggested me to change label(optionsAdd) for alloc(optionAdd,4)? It's better? It's faster? It's smaller?

Any difference to use alloc()+registersymbol() instead globalalloc()? I always use globalalloc() but I don't know if this is OK or alloc+register is better.


_________________
Hey Hitler
Test here your skill with CheatEngine, I coded a challenge for you. Try to beat it!
HERE
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Dec 30, 2014 11:59 am    Post subject: Reply with quote

$1000 = 4096

using alloc for optionAdd makes it so that the code gets to the start of the newly allocated block, it's a fraction faster for the cpu to handle it like that

decreasing the size of newmem just makes it fall in the same 4096 range (less memory, although it's still wasting 64KB)

the difference between globalalloc and normal alloc+registersymbol is that if another script calls alloc, it will allocate a new block of memory, while globalalloc will not allocate a new block of memory but uses the previous one

_________________
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
aikoncwd
Grandmaster Cheater
Reputation: 23

Joined: 21 Dec 2012
Posts: 591
Location: Spain (Barcelona)

PostPosted: Tue Dec 30, 2014 1:17 pm    Post subject: Reply with quote

Dark Byte wrote:
$1000 = 4096

using alloc for optionAdd makes it so that the code gets to the start of the newly allocated block, it's a fraction faster for the cpu to handle it like that

decreasing the size of newmem just makes it fall in the same 4096 range (less memory, although it's still wasting 64KB)

the difference between globalalloc and normal alloc+registersymbol is that if another script calls alloc, it will allocate a new block of memory, while globalalloc will not allocate a new block of memory but uses the previous one


Excellent explanation, now I'm starting to understand haha. Why you set alloc(newmem,$1000) on your CE script templates? I'm using the automatic templates for writting autoassembler scripts frmo CE.

I will use globalalloc then, because that not need to be deallocated and sometimes I need to declare the same "label" without allocation a new one.

Thanks!

_________________
Hey Hitler
Test here your skill with CheatEngine, I coded a challenge for you. Try to beat it!
HERE
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Feb 22, 2015 10:19 pm    Post subject: Reply with quote

Is there a way to disable the record that was clicked?

So you activate it, it executes the code, then immediately deactivates?

I tried adding .Active=false but I assume it doesn't enable the checkbox until after the script completes.

I also tried using .Active=true hoping it would toggle it on and the normal click would've turned it off, but that didn't work.

Basically, I'm trying to make a command button instead of a checkbox.

Right now I just have the same code in [ENABLE] and [DISABLE], just curious if I could stop the check joe.

edit: Why is the forum changing the word 'm a r k' into 'j o e' on me? Smile
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Mon Feb 23, 2015 3:36 am    Post subject: Reply with quote

try a timer that disables it 1 ms afterwards

or have the script inside an autoAssemble() command and end the lua section with error()
the lua part will execute, and thus the AA script will run, but because of the error the cheat table entry won't tick

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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