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 


[Script] Smart AOBSwap

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

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sat Feb 01, 2014 2:23 pm    Post subject: [Script] Smart AOBSwap Reply with quote

Hey guys,
Someone requested some bit more complicated and effective AOBSwap function.

So I've wrote this function.
Hope this would help.
(Added examples at the bottom of the script).
Code:
function AOBSwap(Search, Replace, Index, ActiveHack, RegisterAsAddress, RegisteredAddressName, ReturnTable)
   -- Search(string) = The AoB we will look for
   -- Replace(string) = the AoB we will replace with
   -- Index(number/nil) = Change a specific index counting from 0+ or keep as nil (nil replaces all)
   -- ActiveHack(true/false) = If false the AOBSwap function will not replace the bytes, useful if you enable ReturnTable, and then for each entry and entry do table[n].enable() or table[n].disable();
   -- RegisterAsAddress(true/false) = Register address as a symbol
   -- RegisteredAddressName(string) = how to call the address if RegisterAsAddress is true, if theres no specific index, each address and address will be registered as RegisteredAddressName+1.
   --      For example RegisteredAddressName, RegisteredAddressName1, RegisteredAddressName2,RegisteredAddressName3 .. RegisteredAddressNameN
   -- ReturnTable(true/false) = Parses up everything, adds an enable and disable function for each address and address that was found
   --
   --
   local AoBLength;
   local Table;
   local AddressCount = '';
   if (ReturnTable) then
      Table = {};
      AoBLength = string.gsub(Search, ' ', ''):len();
   end
   if (not Index) then
      AddressCount = 1;
   end
   local ScanAoB = AOBScan(Search);
   if (ScanAoB) then
      local count = stringlist_getCount(ScanAoB);
      if (Index) then
         if (Index > count) then
            Index = count;
         end
      end
      if (count) then
         for i = 1, count do
            if (Index) then
               i = Index;
            end
            local address = stringlist_getString(ScanAoB,i-1);
            local symbol;
            --
            if (RegisterAsAddress and RegisterAsAddress~= '') then
               unregisterSymbol(RegisteredAddressName .. AddressCount);
               registerSymbol(RegisteredAddressName .. (AddressCount or ''), address);
               symbol = RegisteredAddressName .. AddressCount;
               if (not Index) then
                  AddressCount = AddressCount + 1;
               end
            end
            --
            local original_AoB ;
            if (ReturnTable and AoBLength) then
               original_AoB = '';
               local ReadBytes = readBytes(address, (AoBLength / 2),true);
               for _,String in pairs(ReadBytes) do
                  local Hex = string.format("%x",String);
                  if (Hex:len()==1) then
                     Hex = '0' .. Hex;
                  end
                  original_AoB = original_AoB .. ' ' .. Hex;
               end
            end
            --
            if (ActiveHack) then
               for i = 1, string.len(Replace), 3 do
                  local z = string.sub(Replace, i, i+2);
                  local x, y = string.find(z, "%?+");
                  if (x == nil) then
                     autoAssemble(address .. "+" .. (string.format("%x",(i-1)/3)) .. ':\ndb' .. z);
                  end
               end
            end
            if (Table and ReturnTable and AoBLength) then
               Table[#Table+1] = {
                                    address = address;
                                    symbol = symbol;
                                    originalaob = original_AoB;
                                    enable = function ()
                                                for i = 1, string.len(Replace), 3 do
                                                   local z = string.sub(Replace, i, i+2);
                                                   local x, y = string.find(z, "%?+");
                                                   if (x == nil) then
                                                      autoAssemble(address .. "+" .. (string.format("%x",(i-1)/3)) .. ':\ndb' .. z);
                                                   end
                                                end
                                             end;
                                    disable =    function ()
                                                   autoAssemble(address .. ':\ndb ' .. original_AoB);
                                                end;
                                 };
            local TableIndex = Table[#Table];
            TableIndex.remove =   function ()
                                       TableIndex.disable();
                                       for k,v in pairs(TableIndex) do
                                          TableIndex[k] = nil;
                                       end
                                       TableIndex = nil;
                                    end;
            Table[symbol] = TableIndex;
            end
            if (Index and i == Index) then
               break;
            end
         end
      end
      object_destroy(ScanAoB);
   end
   if (Table and ReturnTable) then
      return Table;
   end
end
t = AOBSwap('00 01 03 68 00 21 03 69','00 02 03', nil, false, true, 'Address', true)
-- 1st parameter : 00 01 03 68 00 21 03 69 = AoB we search for
-- 2nd parameter : 00 02 03 = AoB we replace with
-- 3rd parameter : nil = Index, specific index if you wish to activate a single hack
-- 4th parameter : false = activate hack or not automatically, we didn't want to activate it so we set to false.
-- 5th parameter : true = register each address and address with a specific symbol (it will unregister if the the specific symbol is taken already..)
-- 6th parameter : how would we want to define our symbol.. Address1, Address2 .. AddressN
-- 7th parameter : this is very useful:
--                     returns a table that contains all addresses, entry and entry contains the following:
--                        t[1].address = returns the address (for example 0028978F)
--                        t[1].symbol = returns the symbol of the address if any (for example Address1)
--                        t[1].originalaob = returns the original aob of the address (00 01 03 68 00 21 03 69), useful when using wildcards and wishing to disable (same about the disable and enable function).
--                        t[1].enable() = activates the hack
--                        t[1].disable() = deactivates the hacks (writes back the original bytes of THAT specific address, no wildcards and such..).
--                      t[1].remove() = removes the whole objects of that entry (address,symbol, originalaob,enable(),disable() and remove() will not take any affect anymore), it also disables the hacks.
print(#t) -- prints how much entries in the t table (like how much aobs were found) in my case 1572.
t[1].enable() -- will activate first hack of the very first address.
print(t[1].symbol); --> 'Address1'
print(t[2].symbol); --> 'Address2'

-- You may also access the address this way. (as long as they're stored in that table).
print(t['Address1'].address)

_________________
I'm rusty and getting older, help me re-learn lua.


Last edited by daspamer on Sat Feb 01, 2014 4:50 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Keule
Cheater
Reputation: 0

Joined: 08 Aug 2012
Posts: 25

PostPosted: Sat Feb 01, 2014 3:15 pm    Post subject: Reply with quote

This is really awesome, great Job man!

Now its easier to exchange AoB's like never before Smile
Thank you so much, this is 200% what ive ever needed ! Smile
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sat Feb 01, 2014 3:42 pm    Post subject: Reply with quote

Keule wrote:
This is really awesome, great Job man!

Now its easier to exchange AoB's like never before Smile
Thank you so much, this is 200% what ive ever needed ! Smile

You're welcome Smile.

Any questions or issues please post here Smile.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
gamers01
Cheater
Reputation: 0

Joined: 27 Sep 2013
Posts: 45

PostPosted: Sat Feb 01, 2014 3:54 pm    Post subject: Reply with quote

Bro do u have 4 byte replacer Smile like string replacer which u give me I want same but for 4 byte
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sat Feb 01, 2014 3:58 pm    Post subject: Reply with quote

gamers01 wrote:
Bro do u have 4 byte replacer Smile like string replacer which u give me I want same but for 4 byte

I believe it was posted somewhere before, try to look for it.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
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