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 


Array of Bytes (AOB) Scan and Replace All

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Zanzer
I post too much
Reputation: 122

Joined: 09 Jun 2013
Posts: 3279

PostPosted: Wed Oct 07, 2015 6:30 pm    Post subject: Array of Bytes (AOB) Scan and Replace All This post has 1 review(s) Reply with quote

The following script will scan for the provided array of bytes.
Once found, the script will overwrite the bytes with the ones provided.
You can use '??' as a wildcard within the search and replace to ignore those bytes.
For the replace, this means the original bytes in those locations will not change.
The script will replace the bytes at each address in which the pattern matched.
Simply give the cheat a unique name and provide it with the pattern and replacement bytes.
Code:
{$lua}
if syntaxcheck then return end
cheat_name = "MyCheat"
[ENABLE]
local pattern = "48 83 EC 28 E8 ?? ?? ?? ?? 48 83 C4 28"
local replace = "?? ?? ?? ?? 90 90 90 90 90 ?? ?? ?? ??"
-- edit the name of the cheat
-- edit the pattern to search
-- edit the replacement bytes
-- use ?? to ignore the bytes
-- do not edit the code below
local scans = AOBScan(pattern)
if scans == nil then
  showMessage("Unable to find pattern:\n"..pattern)
else
  local saved = {}
  local length = (#replace + 1) / 3
  for i = 0, scans.Count - 1 do
    local backup = readBytes(scans[i], length, true)
    local bytes = {}
    for hex in string.gmatch(replace, "%S+") do
      local size = #bytes + 1
      if hex == "??" then
        bytes[size] = backup[size]
      else
        bytes[size] = tonumber(hex, 16)
      end
    end
    saved[i] = backup
    writeBytes(scans[i], bytes)
  end
  _G[cheat_name] = {
    ["scans"] = scans,
    ["saved"] = saved
  }
end
[DISABLE]
local vars = _G[cheat_name]
if vars ~= nil then
  local scans = vars.scans
  local saved = vars.saved
  for i = 0, scans.Count - 1 do
    writeBytes(scans[i], saved[i])
  end
  scans.Destroy()
  vars.scans = nil
  vars.saved = nil
  vars = nil
  _G[cheat_name] = nil
end


Last edited by Zanzer on Tue Jul 12, 2016 7:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
mausi125
Advanced Cheater
Reputation: 1

Joined: 05 Jun 2014
Posts: 86

PostPosted: Thu Oct 08, 2015 2:17 am    Post subject: Reply with quote

Thank you for your best script zanzer.

Last edited by mausi125 on Thu Oct 08, 2015 9:03 am; edited 1 time in total
Back to top
View user's profile Send private message
ta_trainer
Advanced Cheater
Reputation: 0

Joined: 24 Dec 2006
Posts: 76

PostPosted: Thu Oct 08, 2015 7:25 am    Post subject: Reply with quote

Thank you. can have some good use for it.
Back to top
View user's profile Send private message
sulo0625
How do I cheat?
Reputation: 0

Joined: 19 Apr 2018
Posts: 1

PostPosted: Thu Apr 19, 2018 6:28 am    Post subject: Reply with quote

thank you for your script zanzer. But i have a question. how to use this script for multiple pattern only one replace?
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 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