Backing up memory block

Anything Cheat Engine related, bugs, suggestions, helping others, etc..
Post Reply
User avatar
EyeOfTheMind86
Expert Cheater
Expert Cheater
Posts: 61
Joined: Sun Mar 12, 2017 5:39 pm
Reputation: 33

Backing up memory block

Post by EyeOfTheMind86 »

Hello guys, I came to you with a question.
As part of a character modifier script I'm working on, I would like to backup a good chunk of memory (more than 1000 bytes) and save it to a file (essentially from address A to address B).
I would like to backup this chunk of memory to avoid the necessity of hard resetting the game when the char modifier is disabled, and to be able to restore the original memory structure. Do you guys know if this is possible?
I was trying using readBytes and writeBytes but with no success:

I admit I'm a bit weak in LUA so I apologise, this is what I came up with so far, while experimenting with 2 addresses, but it doesn't do anything, pretty sure my syntax is not correct:
{$lua}
--if syntaxcheck then return end

--local memrec = AddressList.getMemoryRecordByID(1337092678)
savedCloudUnitSOW = 0x0
savedCloudWeaponSOW = 0x0


function backup()
savedCloudUnitSOW = readBytes([[[unit_data_cloud]-2]],1412)
savedCloudWeaponSOW = readBytes([[[weapon_data_cloud]-2]],963)
end

function restore()
if savedCloudUnitSOW~=0x0 and savedCloudWeaponSOW~=0x0 then
writeBytes([[[unit_data_cloud]-2]],savedCloudUnitSOW)
writeBytes([[[weapon_data_cloud]-2]],savedCloudWeaponSOW)
end
end
[ENABLE]
backup()

[DISABLE]
restore()


Any LUA expert who can come to the rescue?

User avatar
EyeOfTheMind86
Expert Cheater
Expert Cheater
Posts: 61
Joined: Sun Mar 12, 2017 5:39 pm
Reputation: 33

Re: Backing up memory block

Post by EyeOfTheMind86 »

Forgot to update here. I actually found a solution but was though ASM (which I prefer anyway).
I didn't need that many bytes after all, but allocating temporary memory and then assigning original values in there, allowed me to back up the array of bytes I wanted to preserve and reset it when needed to restore integrity.
The following is an example written from my phone so I hope is clear enough:

[ENABLE]
alloc(backup,20)
registersymbol(backup)

backup:
ReadMem(original,20)

[DISABLE]
original:
ReadMem(backup,20)

Dealloc(backup)
Unregistersymbol(backup)

Post Reply

Who is online

Users browsing this forum: No registered users