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 create a variable in Cheat Table Lua Script?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
HSergi
Newbie cheater
Reputation: 0

Joined: 17 Dec 2017
Posts: 22

PostPosted: Fri Jul 17, 2020 9:03 am    Post subject: How to create a variable in Cheat Table Lua Script? Reply with quote

I want to create a float variable inside game's memory from Cheat Table Lua Script and then use it in auto assembler scripts.

I've read quite a few articles on the wiki but still can't make it work.

I tried very different combinations. I'll show just a few:
Code:
variable = 100.0

registerSymbol("variable", variable)
Code:
allocateMemory(variableAddress, 0x4)

writeFloat(variableAddress, 100.0)

registerSymbol("variable", variableAddress)
Code:
allocateMemory(variableAddress, 0x4)

variableAddress= 100.0

registerSymbol("variableAddress");

I tested it by just adding a float value and setting variable in the address field on the Cheat Engine's main screen but it never showed the correct value.

This comes from not understanding how it works.

As I understand I have to allocate memory for a variable in game's memory, use that memory and set my float at that memory address, name that address as I want and then use it in auto assemble scripts.

What throws me off is that there are lua variables, auto assembler variables, labels, symbols, label() function, registerSymbol() function, different functions to allocate memory in Cheat Table Lua Script(allocateMemory()) and auto assembler script(alloc()).

I tried to read Code Injection - Editable values article on the wiki, but they talk about how to make editable values in auto assembler scripts, not in the Cheat Table Lua Script.

Can you guys please point me where I can learn and understand how Cheat Engine, Lua scripts, Auto Assembler scripts and everything works together?
Back to top
View user's profile Send private message Send e-mail
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4695

PostPosted: Fri Jul 17, 2020 11:30 am    Post subject: Reply with quote

celua.txt:
Code:
registerSymbol(symbolname, address, OPTIONAL donotsave): Registers a userdefined symbol...
allocateMemory(size, BaseAddress OPTIONAL, Protection OPTIONAL): Allocates some memory into the target process
To be fair, it's not documented allocateMemory returns the address that was allocated, but that shouldn't be something unexpected either.
Code:
if not getAddressSafe("variableAddress") then
  local addr = allocateMemory(4)
  registerSymbol("variableAddress", addr)
  writeFloat("variableAddress", 100.0)
end

There's probably a better way of doing whatever it is you're actually trying to do.

If you're going to use it in AA scripts, then define it in an AA script.
Code:
[ENABLE]
...
alloc(variableAddress,4)
registersymbol(variableAddress)

variableAddress:
  dd (float)100.0
...
[DISABLE]
unregistersymbol(variableAddress)
dealloc(variableAddress)
...

_________________
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
HSergi
Newbie cheater
Reputation: 0

Joined: 17 Dec 2017
Posts: 22

PostPosted: Fri Jul 17, 2020 11:52 am    Post subject: Reply with quote

ParkourPenguin wrote:
celua.txt:
Code:
registerSymbol(symbolname, address, OPTIONAL donotsave): Registers a userdefined symbol...
allocateMemory(size, BaseAddress OPTIONAL, Protection OPTIONAL): Allocates some memory into the target process
To be fair, it's not documented allocateMemory returns the address that was allocated, but that shouldn't be something unexpected either.
Code:
if not getAddressSafe("variableAddress") then
  local addr = allocateMemory(4)
  registerSymbol("variableAddress", addr)
  writeFloat("variableAddress", 100.0)
end


Thank you, I'll try it out.

ParkourPenguin wrote:

There's probably a better way of doing whatever it is you're actually trying to do.

I have 3 AoB injections and I would like to have one variable to set. After I read your post and just thought about it, I should probably combine these 3 AoB injections into one script because it's one mod which consists of 3 separate AoB injections(that can use one variable in memory).

I also want to make it to survive patches, so I want to dynamically find base address of some other variable in the code section(pattern scan the module and get base address from the opcode of an instruction).

So I was thinking to put my custom variable I create in the Lua Cheat Table Script, register it glocally, add it to the list of variables. And also AoB scan code to to dynamically find base address of in-game variable. And then when I click on the square on the left side to the script, so it quickly enables and disables itself. Well, it'll still have to pattern scan for the injections themselves.

Well, looks like you're right and there is a better way to do it than I originally wanted. I'll see what I can do.

ParkourPenguin wrote:
celua.txt:
If you're going to use it in AA scripts, then define it in an AA script.
Code:
[ENABLE]
...
alloc(variableAddress,4)
registersymbol(variableAddress)

variableAddress:
  dd (float)100.0
...
[DISABLE]
unregistersymbol(variableAddress)
dealloc(variableAddress)
...

Well, yep, the reason I want to register it globally from Lua Cheat Table script is because it executes when I open the table, and I want to use that variable in multiple AoB scripts. Which I can combine into one because it's one mod in different places, as I already mentioned above.

Well, thanks for help, let me go try it.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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