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 


Anyway to save memory to file in script ?

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

Joined: 05 Jun 2021
Posts: 5

PostPosted: Sat Jun 05, 2021 3:12 pm    Post subject: Anyway to save memory to file in script ? Reply with quote

Hi guys, im working on a game without a save function but it does have a savemap in memory but it moves around so i use CE script AOB function in script and i can write my own save to the game that way but it means constantly updating the script and copying my savemap again into the script everytime i want to do it, so i was wondering if its possible to either,
Use AOB to locate the address then save the memory to a file (its around 2000 bytes) then load it the same way from script at the press of a key
or if it can't be done with CE is there some other way to dump a selected part of the memory from a keypress (but it would also have to locate in memory first where the location is or get it from CE somehow)
Or if anyone else has any idea's on how to make a way of saving for a game that doesn't save anything to the hard drive im welcome to any ideas.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Jun 05, 2021 3:49 pm    Post subject: Reply with quote

You can use lua with "writeRegionToFile" and "readRegionFromFile", check the "celua.txt" file in the CE folder for more info on the functions. But you'll need to run the AA aob script first then the other, or use the lua "AOBScan" or "AOBScanUnique" to find the AOB address.
_________________
Back to top
View user's profile Send private message Visit poster's website
demondwarf
How do I cheat?
Reputation: 0

Joined: 05 Jun 2021
Posts: 5

PostPosted: Sat Jun 05, 2021 4:17 pm    Post subject: Reply with quote

thanks for the fast reply, i will take a good read through this txt file, thanks a lot, not familiar with AA but i can look into that too but trying to do everything with CE if possible since im more familiar with it (although never used LUA in CE, only used Autoassemble, is it simlar ?), but never had to do anything like this (since most games i play can actually just save)
EDIT-Im a idiot, of course AA is AutoAssembler, i feel stupid
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Jun 05, 2021 5:21 pm    Post subject: Reply with quote

AA is exclusive to CE, but lua is a scripting language used for all sorts of things and is a higher level language than AA or ASM. Lua is small and thus a good candidate for embedded scripting support, it's used in some games and even industrial controllers. So you can find a lot about lua online. What's in the "celua.txt" file is what CE adds to lua. You can start here for more info specific to using lua in CE.
_________________
Back to top
View user's profile Send private message Visit poster's website
demondwarf
How do I cheat?
Reputation: 0

Joined: 05 Jun 2021
Posts: 5

PostPosted: Sun Jun 06, 2021 4:29 am    Post subject: Reply with quote

Thanks, i spent the night looking at the celua.txt and learnt a little, managed to figure out the "writeRegionToFile" and "readRegionFromFile" and had a little problem with the Lua AoB command since it printed the address wrong at first but after i figured out what i was doing wrong i managed to muddle my way through and make a save Function,
Thanks a lot "TheyCallMeTim13" you are incredible, couldn't have done this without you.
Is there a commandline version of CE's LUA ? it would be nice if i could run it from a BAT file with the game everytime i play (i can do that with a trainer too but to keep the filesize down too and if i distribute it too it would make things eaiser)
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Jun 06, 2021 8:08 am    Post subject: Reply with quote

Not that I'm aware of, but you can use the table lua script to launch the game then attach to it and inject the save data. Look at "shellExecute" it might help get the results you want.
_________________
Back to top
View user's profile Send private message Visit poster's website
demondwarf
How do I cheat?
Reputation: 0

Joined: 05 Jun 2021
Posts: 5

PostPosted: Sun Jun 06, 2021 4:20 pm    Post subject: Reply with quote

Thanks i will look at shellexecute, but it would still mean's the end user would need CE installed (which i personally don't have a problem with it but a lot of people seem to think its a virus which isn't helped by a lot of virus scanners going berserk everytime a CE trainer is around) but i guess it can't be helped, thanks again for the help (and fast too), If anyone else is attempting this here is the code i used (i hope this helps someone)
For Save
Code:

{$lua}
local save = AOBScan("FC 00 00 00 01 00 00 00 02 00 00 00 04 00 00 00 08 00 00 00 20 00 00 00 10")
if save == nil then return end
for i=0, save.Count-1, 1 do
  writeRegionToFile(os.getenv("USERPROFILE")..'\\Saved Games\\Save1.bin',save[i],9000)
end

And Slightly adjusted for Load
Code:

{$lua}
local Load = AOBScan("FC 00 00 00 01 00 00 00 02 00 00 00 04 00 00 00 08 00 00 00 20 00 00 00 10")
if Load == nil then return end
for i=0, Load.Count-1, 1 do
readRegionFromFile(os.getenv("USERPROFILE")..'\\Saved Games\\Save1.bin',Load[i])
end

Obviously change the AOB scan hex codes to your own, And what this code does is it performs a AoB scan to find the address, if it can't find the address it Ends the script, if it does find the address it loads it as a integer and then Writes 9000 (decimal) from the address found in the AoB scan into the Save1.bin which is saved into the users Saved Games folder. And load does the same but reads from the file instead of writing to it.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Jun 06, 2021 4:42 pm    Post subject: Reply with quote

You might stick this in the scripts, so they only execute when running the script and not after editing. Any lua in an AA script will be run when closing the window to perform a syntax check.
Code:
if syntaxcheck then return end

_________________
Back to top
View user's profile Send private message Visit poster's website
demondwarf
How do I cheat?
Reputation: 0

Joined: 05 Jun 2021
Posts: 5

PostPosted: Sun Jun 06, 2021 5:29 pm    Post subject: Reply with quote

Ah i was wondering about that, i will add that to my script, thanks again, if you see any more mistakes or any way to improve it please let me know.
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