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)