Autem Expert Cheater
Reputation: 1
Joined: 30 Jan 2023 Posts: 155
|
Posted: Tue Jun 04, 2024 3:29 pm Post subject: Lua scripts to scan/replace strings can't find UTF-16 result |
|
|
After doing some searching on this I have been testing 3 different "replace strings" scripts and the first 2 seem to work identically in that they're always missing UTF-16 results. How can I get either of these first 2 to also include UTF-16?
There is also a 3rd script I am pasting below that DOES find UTF-16 results but won't work for strings/text. It only works for numbers replacement.
If any of these three can be made to search text strings and also include utf-16, I am all set. Would very much appreciate some help with this, thanks!
First script (doesn't find UTF-16):
| Code: | [ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$lua}
if syntaxcheck then return end
function Textswap()
local txt2scn = 'OLDTEXT'
local txt2chg = 'NewText'
--convert to hex string
local searchTable = {}
for i=1,txt2scn:len() do
searchTable[i]=string.format('%X',txt2scn:byte(i))
end
local searchHexString = table.concat(searchTable)
local aobs2 = AOBScan(searchHexString)
if(aobs2 ~= nil) then
for i=0,stringlist_getCount(aobs2)-1 do
local address=stringlist_getString(aobs2,i)
writeString('0x'..address,change2)
end
object_destroy(aobs2);
aobs2=nil
end
beep()
print('Done')
end
[DISABLE]
|
Second script (doesn't find UTF-16):
| Code: | [ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$lua}
if syntaxcheck then return end
function byteTableToAobString(t)
for k,v in ipairs(t) do
t[k] = ('%02X'):format(v)
end
return table.concat(t, ' ')
end
function TextToAobs(text)
newvalue = (text) --:lower()
--print(newvalue)
if not newvalue then return end
newvalue = stringToByteTable(newvalue)
newvalue = byteTableToAobString(newvalue)
print(newvalue)
return newvalue
end
print(TextToAobs("Zar"))
function multiReplace(from,to)
local good,aob = 0,AOBScan(tostring(from),"+W*XC")
if (aob == nil) then
showMessage("Code not found..")
else
aobCnt=strings_getCount(aob) - 1
for i=0, aobCnt do
if autoAssemble (aob[i]..":\ndb "..tostring(to)) then good=good+1
end
end
end
aob.Destroy()
showMessage("Replace code: " .. good)
return good
end
multiReplace(TextToAobs("OLDTEXT"),TextToAobs("NewText"))
[DISABLE]
|
Third script DOES find utf-16 results but it will not work unless the search and replace values are just numbers. Is there a way to get this script to also support searching and replacing text?
| Code: | [ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$lua}
if syntaxcheck then return end
function ChangeValues(v, v2)
local MemScan = createMemScan()
MemScan.firstScan(soExactValue, vtString, nil, v, nil, '0', '7fffffffffff', '+W*C*X', fsmNotAligned, '0', false, false, false, false)
MemScan.waitTillDone()
local Results = createFoundList(MemScan)
Results.initialize()
for i=0,Results.Count-1 do
print('replacing', Results[i], v)
writeString(Results[i],v2,false)
end
MemScan.destroy()
Results.destroy()
--Next we make sure utf-16 widechar is also found below
local MemScan = createMemScan()
MemScan.firstScan(soExactValue, vtString, nil, v, nil, '0', '7fffffffffff', '+W*C*X', fsmNotAligned, '0', false, false, true, false)
MemScan.waitTillDone()
local Results = createFoundList(MemScan)
Results.initialize()
for i=0,Results.Count-1 do
print('replacing', Results[i], v)
writeString(Results[i],v2,true)
end
MemScan.destroy()
Results.destroy()
end
ChangeValues(OLDTEXT, NewText) --Doesn't work as is for text strings, but will work for number values
[DISABLE]
|
|
|