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 


String Find And Replace FUNCTION

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
alphanote
How do I cheat?
Reputation: 0

Joined: 16 Sep 2014
Posts: 7

PostPosted: Mon Sep 22, 2014 12:40 pm    Post subject: String Find And Replace FUNCTION Reply with quote

I need a function that you can call, that finds and replaces string.
Ex;
FindAndReplaceString("text to find","text to replace with")

Please, I've been looking for hours and hours, days and days.
I need it so bad for my trainer!
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Sep 22, 2014 2:14 pm    Post subject: Reply with quote

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
-- replaceString(String to find(string), string to replace with(string), ignore replace string length(true/false))
-- returns true/false as result
replaceString("Hi","Hey",true);

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
alphanote
How do I cheat?
Reputation: 0

Joined: 16 Sep 2014
Posts: 7

PostPosted: Mon Sep 22, 2014 2:28 pm    Post subject: OMG Reply with quote

TY!!
Back to top
View user's profile Send private message
alphanote2
How do I cheat?
Reputation: 0

Joined: 23 Sep 2014
Posts: 6

PostPosted: Wed Sep 24, 2014 7:22 am    Post subject: qq Reply with quote

Does not work.

It just crashes my game.

I want a large string to change to a smaller string.
Back to top
View user's profile Send private message
sodahead0
How do I cheat?
Reputation: 0

Joined: 17 Apr 2017
Posts: 1

PostPosted: Mon Apr 17, 2017 12:45 pm    Post subject: There's a way without scripting Reply with quote

Change your string to an array of byte. Just use this link cryptii,com/text/hexadecimal. Then copy-paste the two string to notepad. So if you want a larger string to a smaller string, Ex. you want 57 AD 4A 67 0C 57 to be 56 BC 89. You see that the first one has 6 bytes, but the second one has 3 bytes. So if a string has 9 characters, but you want 6 characters, you have to add three 00's to the replacement AOB. Only thing I don't know is how to change a smaller string to a larger string, because that always messes up the game.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Mon Apr 17, 2017 5:57 pm    Post subject: Reply with quote

Lua has 'string.gsub' built into it for string replacements. Check the Lua documentation for info on how to use it.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Apr 17, 2017 7:59 pm    Post subject: Reply with quote

Code:
function Textswap()
  local txt2scn = 'bla bla bla'
  local txt2chg = 'i am not bla bla bla'
   --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

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
nebusk
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 07 Jun 2019
Posts: 10

PostPosted: Fri Jun 07, 2019 10:08 pm    Post subject: please help me Reply with quote

i am currently making a trainer but the problem is, i want my editbox/textbox/trackbar (any of those) to change a number inside one of my script that is currently on cheat table, but i havent seen any post related to me if anyone has the solve please reply back would be a big help,


Screenshot (1870).png
 Description:
As you can see at top left corner where it says 8575 thats the number i want to edit using one of those editbox/textbox/trackbar

but i am lacking in experience so if you know how to solve it please reply
 Filesize:  58.23 KB
 Viewed:  8346 Time(s)

Screenshot (1870).png


Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Fri Jun 07, 2019 10:23 pm    Post subject: Reply with quote

https://forum.cheatengine.org/viewtopic.php?t=610209
Code:
function getStrBoundByHeadTail(s,h,t, excludeHT)
  local h1,h2 = s:find(h) -- return beginning and ending index of h if found
  local t1,t2 = s:find(t) -- ditto for t
  if h1 and t1 and h1~='' and t1~='' then -- find both
    local hh = excludeHT and h2+1 or h1 -- ending+1 or beginning index of h
    local tt = excludeHT and t1-1 or t2 -- beginning-1 or ending index of t
    return s:sub(hh,tt)
  end
  if not t1 then return s:gsub(h,t) end
end

local s='1@2@3@4@5@6@7@8'

print(getStrBoundByHeadTail(s,'1@','@8'))
--1@2@3@4@5@6@7@8

print(getStrBoundByHeadTail(s,'1@','@8',0))
--2@3@4@5@6@7

print(getStrBoundByHeadTail(s,'@','-'))
--1-2-3-4-5-6-7-8 7
[/quote]
Back to top
View user's profile Send private message
nebusk
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 07 Jun 2019
Posts: 10

PostPosted: Fri Jun 07, 2019 10:29 pm    Post subject: .lua Reply with quote

function getStrBoundByHeadTail(s,h,t, excludeHT)
local h1,h2 = s:find(h) -- return beginning and ending index of h if found
local t1,t2 = s:find(t) -- ditto for t
if h1 and t1 and h1~='' and t1~='' then -- find both
local hh = excludeHT and h2+1 or h1 -- ending+1 or beginning index of h
local tt = excludeHT and t1-1 or t2 -- beginning-1 or ending index of t
return s:sub(hh,tt)
end
if not t1 then return s:gsub(h,t) end
end

local s='1@2@3@4@5@6@7@8'

print(getStrBoundByHeadTail(s,'1@','@8'))
--1@2@3@4@5@6@7@8

print(getStrBoundByHeadTail(s,'1@','@8',0))
--2@3@4@5@6@7

print(getStrBoundByHeadTail(s,'@','-'))
--1-2-3-4-5-6-7-8 7



can you tell me where i put those? and which are they for? editbox/textbox/trackbar
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Jun 07, 2019 11:42 pm    Post subject: Re: please help me Reply with quote

nebusk wrote:
i am currently making a trainer but the problem is, i want my editbox/textbox/trackbar (any of those) to change a number inside one of my script that is currently on cheat table, but i havent seen any post related to me if anyone has the solve please reply back would be a big help,


Is this a spam?. Found the same topic in another post,

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
nebusk
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 07 Jun 2019
Posts: 10

PostPosted: Fri Jun 07, 2019 11:49 pm    Post subject: n Reply with quote

This is not a spam, i can send u the full cetrainer and maybe you can make it work add me on discord Angelo#0963 or email me ordinarydark1 gm ail com
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Jun 08, 2019 3:14 am    Post subject: Reply with quote

Code:
 f = createForm()
 e = createEdit(f)
 t = createToggleBox(f)
 t.top = e.top + e.height + 10
 t.Caption = 'Change'

 function changevalue()
  local al = AddressList or getAddressList()
  local mr1 = al.getMemoryRecordByDescription("MyHack")  -- your hack description on cheat table
  local myvalue = e.Text
  local mr2 = tonumber(myvalue)  -- if the hack value is a number
  if not mr1 or not mr2 then error("Memrecs do not exist!!!") end
  if (checkbox_getState(t) == 1) then
   mr1.Value = mr2
   mr1.Active = true
   t.caption = 'ON'
  else
   mr1.Active = false
   t.caption = 'OFF'
  end
 end

 f.show()
 t.onChange = changevalue

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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