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 


Use Assembler to inc,dec,set values without starting from 0.

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

Joined: 17 Feb 2021
Posts: 29

PostPosted: Sun Dec 26, 2021 9:37 pm    Post subject: Use Assembler to inc,dec,set values without starting from 0. Reply with quote

I'm using a script together with an labeled address to set values within the script manually, but unfortunately every time I inject the code it will always start from zero. Is there a way to read the address first, record the current value in the labeled address and then start from a specific point instead of zero? My item ingame is currently 42 (value), I want to read this value and send it to the labeled address avoiding it from starting with zero.

Here's my code:

Code:
//Set item on slot (select to activate)

define(address,"ResidentEvil3.exe"+DF2AE)
define(bytes,8B 14 81 89 56 42)

[ENABLE]

assert(address,bytes)
alloc(newmem,$100)

label(code)
label(return)

label(Agamemnon)
registersymbol(Agamemnon)

newmem:

code:
  push bx
  mov bl,[Agamemnon]
  mov [ecx+eax*4],bl
  pop bx
  mov [esi+42],edx
  jmp return

Agamemnon:
//I want to read the address's value I'm about to modify and then copy it's value to the "Agamemnon" address (it's located in the address list)

address:
  jmp newmem
  nop
return:

[DISABLE]
unregistersymbol(Agamemnon)
address:
  db bytes
dealloc(newmem)
[/code]
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4707

PostPosted: Mon Dec 27, 2021 2:27 am    Post subject: Reply with quote

Fatamorgen wrote:
Is there a way to read the address first
What's "the address"?
If it's some memory record in your cheat table, you can use Lua to get it.
Code:
...
Agamemnon:
{$lua}
if syntaxcheck then return 'db 0' end

local value = tonumber(AddressList.getMemoryRecordByDescription'My current item'.Value)

return ('db %X'):format(value)
{$asm}
...

Also, you should be pushing/popping ebx.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Fatamorgen
Cheater
Reputation: 0

Joined: 17 Feb 2021
Posts: 29

PostPosted: Mon Dec 27, 2021 1:02 pm    Post subject: RE:ParkourPenguin Reply with quote

The addresses linked with
Quote:
"ResidentEvil3.exe"+DF2AE
which is every item I select in Jill's inventory. This address ("ResidentEvil3.exe"+DF2AE) is related to every item and I've obtained it by finding what accessed it.

Code:
code:
  push bx
  mov bl,[Agamemnon]
  mov [ecx+eax*4],bl    //(original mov dx,[ecx+eax*4]) I want to copy the value of the address that access this and then send to Agamemnon
  pop bx
  mov [esi+42],edx
  jmp return


Let's say I have a Green Herb in any slot of Jill's inventory (I believe it doesn't matter since the address of the script is related to every item in the inventory) the value (ID) of Green Herbs is 0x32. I want to copy 0x32 to Agamemnom before starting to use the hotkeys to increase or decrease the value manually. That way it will act like a checkpoint and will avoid the item from being zeroed everytime I inject the code.

As for pushing and popping EBX I thought E stands for extendable (32-bit) and the memory I'm working with interacts only with 8-bit addresses (the itens within the game store values in 8-bit only), so I don't know if is there a problem if I choose 16-bit instead of 32. Since I'm not computer science literate I think I need a little explanation on this matter Laughing .

Thanks for the info, Penguin. The lua script you provided will work perfectly in another code I have here.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4707

PostPosted: Mon Dec 27, 2021 2:14 pm    Post subject: Reply with quote

Operating on the lower 8 or 16 bits of 32-bit registers doesn't zero the upper bits of memory like it does with 64-bit registers. This can create false dependencies that make the code run slower than it should.
In general, you should prefer working on 32-bit values whenever you can. pushing/popping part of the 32-bit register will usually be slower than pushing/popping the entire 32-bit register.
This is certainly a premature optimization you're never going to notice, so feel free to ignore this.

At that injection point, there might be a register that's not in use by the game. e.g. if ebx is written to before being read from, then there's no need to back it up.

If it's a static address, you can read from it directly:
Code:
...
Agamemnon:
  readmem("ResidentEvil3.exe"+DF2AE, 1)
...

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Fatamorgen
Cheater
Reputation: 0

Joined: 17 Feb 2021
Posts: 29

PostPosted: Mon Dec 27, 2021 4:20 pm    Post subject: RE:RE:RE:Penguin Reply with quote

I see.
I'll try looking for a register that's currently not in use then.
Is there a way to use readmem to copy the value only once? MOV constantly injects the value. Is there a command that I can use to inject only once and then stop?

I tried to look for other MOV commands but there's lack of info on them in the wiki. Most pages don't exist. CMP together with a near jump works on this occasion?

Thanks for the quick explanation on 32-bits registers.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4707

PostPosted: Mon Dec 27, 2021 7:09 pm    Post subject: Reply with quote

readmem only reads from the address once when the script is enabled.
MOV doesn't "inject" anything- it just moves data from the source (second operand) to the destination (first operand).
If you want the game to only run your injected code once, you can add a flag and test/set it to make sure it only runs once.

Also, in your previous comment:
Fatamorgen wrote:
Code:
mov [ecx+eax*4],bl    //(original mov dx,[ecx+eax*4]) I want to copy the value of the address that access this and then send to Agamemnon
Several problems here:
  • The original code is accessing a 16-bit value, not an 8-bit value. This might be fine.
  • The original code is writing to the dx register. edx later gets written to [esi+42]. In your code, you aren't modifying the dx register at all. Are you absolutely certain whatever value was in dx is safe to write to [esi+42]?
  • That comment makes me think you intend to read from [ecx+eax*4] and write to Agamemnon, but your code is doing the opposite (reading from Agamemnon and writing to [ecx+eax*4]).

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Fatamorgen
Cheater
Reputation: 0

Joined: 17 Feb 2021
Posts: 29

PostPosted: Mon Dec 27, 2021 8:56 pm    Post subject: RE:RE:RE:RE:Penguin Reply with quote

Quote:
That comment makes me think you intend to read from [ecx+eax*4] and write to Agamemnon, but your code is doing the opposite (reading from Agamemnon and writing to [ecx+eax*4]).


That's exactly what I want to do Very Happy .

I want to read from [ecx+eax*4] first and then write to Agamemnon. The actual code is doing the opposite as you stated. It will only read from Agamemnon and write to [ecx+eax*4].

I want to read from [ecx+eax*4] first, write to Agamemnon and then read Agamemnon again to write on [ecx+eax*4] (if it's possible). This way I wouldn't start with zero but have a starting point based on the item ID/value I want to change.

Sorry my bad speech/comment. I'm not too good when formulating a specific and precise point.[/quote]
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4707

PostPosted: Mon Dec 27, 2021 10:24 pm    Post subject: Reply with quote

Fatamorgen wrote:
I want to read from [ecx+eax*4] first, write to Agamemnon and then read Agamemnon again to write on [ecx+eax*4] (if it's possible).
The second part of that does nothing. If the first part reads from [ecx+eax*4] and writes to Agamemnon, then at that point [ecx+eax*4] and Agamemnon clearly hold the same value.
example Lua code:
Code:
a = 7
b = a
-- at this point a and b are the same value
assert(a == b)
-- the following assignment does nothing since they're already equal
a = b

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Fatamorgen
Cheater
Reputation: 0

Joined: 17 Feb 2021
Posts: 29

PostPosted: Tue Dec 28, 2021 6:46 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Fatamorgen wrote:
I want to read from [ecx+eax*4] first, write to Agamemnon and then read Agamemnon again to write on [ecx+eax*4] (if it's possible).
The second part of that does nothing. If the first part reads from [ecx+eax*4] and writes to Agamemnon, then at that point [ecx+eax*4] and Agamemnon clearly hold the same value.
example Lua code:
Code:
a = 7
b = a
-- at this point a and b are the same value
assert(a == b)
-- the following assignment does nothing since they're already equal
a = b


I see. In this case I would be stuck and the code doesn't do much. Thanks for the explanation, Penguin.
Back to top
View user's profile Send private message
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