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 


Manipulating string / text

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Jan 13, 2017 10:11 am    Post subject: Manipulating string / text Reply with quote

Hi,

Code:
str = "AA BB CC"
a = string.format("Set to : "..str.." / ")
print(a)

-- result : Set to : AA BB CC/


I want get result as : Set to : AA / Set to : BB / Set to : CC

Already search for some samples but not found or can't understand the logic.
Hope any lua masters should give solution.

Thanks
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Fri Jan 13, 2017 11:19 am    Post subject: Reply with quote

Code:
input = {"AA","BB","CC","DD","whatever","ole","42"}

output = "Set to : "..table.concat(input," / Set to : ")
print(output)

>Set to : AA / Set to : BB / Set to : CC / Set to : DD / Set to : whatever / Set to : ole / Set to : 42




Or
Code:
input = "AA BB CC DD whatever ole 42"

tbl={}
input:gsub("[^%s]+", function (c) tbl[1+#tbl]=c end)
output = "Set to : "..table.concat(tbl," / Set to : ")

print(output)

>Set to : AA / Set to : BB / Set to : CC / Set to : DD / Set to : whatever / Set to : ole / Set to : 42

_________________
Back to top
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Fri Jan 13, 2017 11:25 am    Post subject: Reply with quote

Code:

print( (str:gsub("%w+","Set to : %1 / ")) )

The extra () is to limit 1 gsub's return value, since gsub also return number of match in second return value.

EDIt:
oops, not notice the missing last \ until saw mgr.inz.Player answer.

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Jan 13, 2017 10:07 pm    Post subject: Reply with quote

Thank mgr.inz.Player and panraven

Try in game :

Code:
AOB_s = "24 01 62 07 12 0d 00 00 c1 24 64"
input = "24 25 62 07 12 0d 00 00 C1 24 64"

tbl={}
input:gsub("[^%s]+", function (c) tbl[1+#tbl]=c end)
AOB_r = "0x"..table.concat(tbl,", 0x")
print(AOB_r)
-- result : 0x24, 0x45, 0x62, 0x07, 0x12, 0x0d, 0x00, 0x00, 0xC1, 0x24, 0x64

s = AOBScan(AOB_s, "+W*X-C")

if (s == nil) then
 showMessage("AOB not found")
else
 lngt = s.getCount()
   for x=0, lngt-1, 1 do

    writeBytes(s[x], AOB_r)  --- game stuck

 -- writeBytes(s[x], 0x24, 0x25, 0x62, 0x07, 0x12, 0x0d, 0x00, 0x00, 0xC1, 0x24, 0x64)  -- Hack work
   end
 showMessage("Hack enabled...")
 s.Destroy()
 s = nil
end


1. Any other hint to fix game stuck while using AOB_r as script above?

2. Is this function below will replacing all AOB found ?



Code:
search = "24 01 62 07 12 0d 00 00 c1 24 64"
change = "24 25 62 07 12 0d 00 00 C1 24 64"


function DEC_HEX(IN)
   local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
    if IN<1 then
      OUT=0
      return OUT
   end
   while IN>0 do
      I=I+1
      IN,D=math.floor(IN/B),math.fmod(IN,B)+1
      OUT=string.sub(K,D,D)..OUT
   end
   return OUT
end

function scan(enter, exit)
     aobs = AOBScan(search, "+W")
     if(aobs == nil) then
      scanCheck=false
    else
       j = stringlist_getCount(aobs)
      for i = 1, j do
          address=stringlist_getString(aobs,i-1)
          for i = 1, string.len(change), 3 do
             z = string.sub(change, i, i+2)
             x, y = string.find(z, "%?+")
              if (x == nil) then
                script=[[
                ]]..address.."+"..(DEC_HEX((i-1)/3))..[[:
                db ]]..z..[[
                ]]
                autoAssemble(script)
             end
          end
       end
      object_destroy(aobs);
      aobs=nil
      scanCheck=true
   end
end



3. How to make this code as a general function ?

Code:
input = "24 25 62 07 12 0d 00 00 C1 24 64"

tbl={}
input:gsub("[^%s]+", function (c) tbl[1+#tbl]=c end)
output = "0x"..table.concat(tbl,", 0x")
print(output)


Thanks a ton...
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Fri Jan 13, 2017 11:32 pm    Post subject: This post has 1 review(s) Reply with quote

writeBytes with STRING type of 2nd and up parameter is undocumented, better avoid,
eg your input string in 1st part cannot convert to ONE (from decimal not hex format) number or sequence of numbers,
but writeBytes still write 1 byte of value 0 in memory to cause crash.

May try autoAssemble alone , which better use with string input (instead of byte table or number) , and support wildcards naturally (ce 6.5+), eg:

Code:

function multiAOBPatch(from,to,protect)
  local good,aob = 0,AOBScan(from,protect) -- default scan all memory region
  if aob then
    for i=0,aob.Count-1 do
      if autoAssemble(aob[i]..":\ndb "..to)then good=good+1 end
    end
    aob.Destroy()
  end
  return good
end

return number of 'good' replace, 0 if not found or write any aob.

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Jan 13, 2017 11:37 pm    Post subject: Reply with quote

What, my script isn't good enough for you? Smile
http://forum.cheatengine.org/viewtopic.php?p=5620925

writeBytes() takes a table of bytes or a variable number of arguments representing each byte.
You are attempting to send it a string.
You should instead convert your existing table values into numbers and then pass them.
Code:
tbl[1+#tbl]=tonumber(c,16)
...
writeBytes(s[x], tbl)
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Jan 14, 2017 1:09 am    Post subject: Reply with quote

I see :

I just test logic "writeBytes with STRING type" to check it work or not and also how effect give if use.

Panraven :
So, parameter is undocumented, better avoid

Code:
function multiAOBPatch(from,to,protect)
  local good,aob = 0,AOBScan(from,protect) -- default scan all memory region
  if aob then
    for i=0,aob.Count-1 do
      if autoAssemble(aob[i]..":\ndb "..to)then good=good+1 end
    end
    aob.Destroy()
  end
  return good
end


What use for "protect" in the function ?


Zanzer :
your script : http://forum.cheatengine.org/viewtopic.php?p=5620925
Very good and no issue when used in AA script, but in case I don't want use AA script (for my project), that is why I try some manipulating AOB (in string) to put it into a AOB scan replace function.

Actually my project shall be like this :

User input via text boxes...

CEEdit1 ---> get AOB (for scan) input ---- put to var (eq. aobS)
CEEdit2 ---> get AOB (for replace) input ---- put to var (eq.aobR)

then use AOB scan replace function or under a button click to process scan and replace AOB by aob's variables got from user input as above.

I can use AOBSwap function (usually peoples use outside there) or use autoAssemble(script) inside lua to handle this, but I just want make sure,
is AOBSwap function or autoAssemble(script) will replace all aob's found and also support wildcards in aob ?.

Thanks
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Sat Jan 14, 2017 1:36 am    Post subject: Reply with quote

The proctect is the "+W*X-C" thing which tell AOBScan what kind of memory region to scan.
eg,
if it is known the aob is for native x86 code, may use "+X" for faster scan;
if it is for bytecode, omitted it to scan all memory region.

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Jan 14, 2017 3:02 am    Post subject: Reply with quote

This tested in game and work properly :


Code:
function multiAOBPatch(from,to,protect)
  local good,aob = 0,AOBScan(from,protect) -- default scan all memory region
  if (aob == nil) then
   showMessage("AOB not found..")
  else
--  if aob then
    for i=0,aob.Count-1 do
      if autoAssemble(aob[i]..":\ndb "..to)then good=good+1 end
    end
    showMessage("AOB Found and replaced")
    aob.Destroy()
  end
  return good
end

--from = "24 01 62 07 12 0d 00 00 c1 24 64"
--to = "24 25 62 07 12 0d 00 00 c1 24 64"

aob_s = UDF1.CEEdit1.Text
aob_r = UDF1.CEEdit2.Text
from = tostring(aob_s)
to = tostring(aob_r)


function hackIt()
print(from)
print(to)
multiAOBPatch(from,to,"+W*X-C")
end

UDF1.CEButton1.onClick = hackIt
UDF1.show()


Thank so much panraven
Just make sure, multiAOBPatch(from,to,protect) function will replacing all AOB's found, right ?

I think yes because this " for i=0,aob.Count-1 do"...

Regards
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