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: 23

Joined: 13 Sep 2011
Posts: 1393

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);

_________________
www.flashacking.net/
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 Visit poster's website
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: 137

Joined: 25 Jan 2006
Posts: 7287
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
Master Cheater
Reputation: 8

Joined: 10 Apr 2015
Posts: 425

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

_________________
I can't do it now because I don't know yet and because You knew it before me. There is heaven above the sky.
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