 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
paulce How do I cheat?
Reputation: 0
Joined: 30 Jul 2018 Posts: 5
|
Posted: Mon Jul 30, 2018 5:32 am Post subject: How to auto search and replace a string? |
|
|
Hello, I was hoping if someone can help me out with this. I learned about cheat engine just the other day. What I want to do is change the names of a couple characters in a game one game including Tales of Zestiria. Now, I can get it to change the name and stay that way in the menus and some common dialogue, but the majority of the dialogue will still continue to display the original name because of the new data that is loading which means I would have to manually scan and replace often. How does one make it so Cheat Engine automatically searches and replaces "strings" every certain amount of time. EX: Replace "Alisha" with "Jenna" every 1 second so that it continues to update so all of the dialogue would be reflective of the changed name?
|
|
Back to top |
|
 |
Lynxz Gaming Expert Cheater
Reputation: 4
Joined: 01 Jul 2017 Posts: 208 Location: help
|
Posted: Mon Jul 30, 2018 5:58 am Post subject: Re: How to auto search and replace a string? |
|
|
This is DaSpamer code (https://forum.cheatengine.org/viewtopic.php?t=576390&sid=a51693049e1864d2e6decda893d37add)
you can use this
Code: | function replaceString(string_in,string_out,ignore_length)
if (not ignore_length) then
if (not(string_in and string_out and #string_in >= #string_out)) then
return print("Not recommended to override shorter string with a longer string");
end
end
local bytes_in = {};
local bytes_out = {};
for i=1,(#string_in >= #string_out and #string_in or #string_out) do -- lazy to copy paste same loop for string_out so just looping both and inserting if possible
if (i <= #string_in) then
table.insert(bytes_in,string.format("%x", tonumber(string.byte(string.sub(string_in,i,i)))));
end
if (i <= #string_out) then
-- table.insert(bytes_out,'0x' .. string.format("%x", tonumber(string.byte(string.sub(string_out,i,i)))));
table.insert(bytes_out,tonumber(string.byte(string.sub(string_out,i,i))));
end
end
local object = AOBScan(table.concat(bytes_in," "));
if object then
for entry = 0, object.Count -1 do
writeBytes(object.getString(entry), unpack(bytes_out));
end
object.destroy();
return true
end
return false
end |
This is how to use in button click
Code: |
function ButtonClick(sender)
replaceString("Text to find","Text to replace",true)
end
|
_________________
my english is bad
discord : rynx#9828 |
|
Back to top |
|
 |
paulce How do I cheat?
Reputation: 0
Joined: 30 Jul 2018 Posts: 5
|
Posted: Mon Jul 30, 2018 6:23 am Post subject: |
|
|
Thanks for the code. I can't seem to get it to work in the auto assembly in memory view. It keeps saying instruction cannot be compiled.
|
|
Back to top |
|
 |
Lynxz Gaming Expert Cheater
Reputation: 4
Joined: 01 Jul 2017 Posts: 208 Location: help
|
Posted: Mon Jul 30, 2018 8:15 am Post subject: |
|
|
paulce wrote: | Thanks for the code. I can't seem to get it to work in the auto assembly in memory view. It keeps saying instruction cannot be compiled. |
can you give me the lines error
_________________
my english is bad
discord : rynx#9828 |
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
|
Back to top |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Mon Jul 30, 2018 8:32 am Post subject: |
|
|
likely because it's lua code and you didn't use {$lua} ... {$asm} (and if not you may not know the caveat that it runs before all the asm code).
Though I'm curious why it doesn't use stringToByteTable... eg.
--edit: note untested. so probably typos and other really obviously wrong errors lol
Code: | --[[
--edit: note untested. so probably typos and other really obviously wrong but errors lol
required: instr, outstr
config is a table of optional options :)
optional: ok (ignore length), wide (wide strings), syntaxcheck (only scan for bytes and do length check),
select (nil=first, -1 = all, otherwise index)
size (nil, 1=pre, 2=post, or address)
protectionflags, alignmenttype, alignmentparam (see AOBScan for details)
]]
function replaceString(instr, outstr, config)
if not instr or not outstr or type(instr) ~= 'string' or type(outstr) ~= 'string' then
error('replaceString: need two strings!',2)
end
config = config or {}
if not config.ok and #outstr > #instr then
error('replaceString: new string is longer than original!', 2)
end
local inbytes = (config.wide and wideStringToByteTable or stringToByteTable)(instr)
local inaob = {} -- AOBScan has no overload for byte table...
for _,byte in ipairs(inbytes) do inaob[#inaob+1] = ('%x'):format(byte) end
inaob = table.concat(inaob, ' ')
local protectionflags = config.protectionflags or ''
local alignmenttype = config.alignmenttype or 0
local alignmentparam = config.alignmentparam
local res = AOBScan(inaob, protectionflags, alignmenttype, alignmentparam)
if not res then error('replaceStr: no results found for ' .. instr, 2) end
if syntaxcheck then res.destroy(); return end
local outbytes = (config.wide and wideStringToByteTable or stringToByteTable)(outstr)
local function handlesize(addr)
if config.size == nil then return end
local address = GetAddressSafe(addr)
local size = #outstr * (config.wide and 2 or 1)
if not address then error('replaceString: got invalid address to write size at', 2)
elseif config.size == 1 then writeDword(address-4, size)
elseif config.size == 2 then writeDword(address+size, size)
else writeDword(config.size, size) end
end
if config.select == nil then
writeBytes(res[0], outbytes)
handlesize(res[0])
elseif config.select > -1 then
if res.Count < config.select then error('replaceStr: index out of range! Found results: ' .. res.Count) end
writeBytes(res[config.select], outbytes)
handlesize(res[config.select])
else
for i=0,res.Count-1 do
writeBytes(res[i], outbytes)
handlesize(res[i])
end
end
res.destroy()
end |
P.S. I got totally sidetracked on this adding options and looking up whether you could create local variables from a table like you can with global variables using _G lmao
oh and the likely reason stringToByteTable wasn't used is because there's no overload of AOBScan for it so you need a loop anyway... Oh well, might as well share lol
_________________
|
|
Back to top |
|
 |
paulce How do I cheat?
Reputation: 0
Joined: 30 Jul 2018 Posts: 5
|
Posted: Fri Aug 03, 2018 8:52 pm Post subject: |
|
|
I tried using the DaSpamer code, and put it in the correct place this time. I don't think it is constantly changing the name though. It changed all of the names once, but when new data is loaded it doesn't change the character's name via dialogue unless I run the script manually again.
|
|
Back to top |
|
 |
|
|
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
|
|