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 


auto Search>Replace when pressing a hotkey

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
aldrinjohnom
Newbie cheater
Reputation: 0

Joined: 03 Jun 2017
Posts: 15

PostPosted: Sat Jun 03, 2017 1:48 pm    Post subject: auto Search>Replace when pressing a hotkey Reply with quote

Hi to you all! I am new here and I desperately created an account because I am having a serious misunderstanding with this script.

---------------

function replace(searchV, replaceV)
if type(searchV) ~= "table" then
searchV = {(assert(tonumber(searchV),"Could not convert first argument to number"))}
end
replaceV = math.floor(replaceV)

for i,v in ipairs(searchV) do
v = math.floor(v)
local res = AOBScan(string.format("%02X %02X %02X %02X", v & 0xff, v>>8 & 0xff, v>>16 & 0xff, v>>24 & 0xff), "+W-C", 1, 4)
if res then
for j=0, res.Count-1, 1 do
writeInteger(res[j], replaceV)
end
res.destroy()
end
end
end
replace({33606, 5606}, 9600006)
createHotkey(replace, VK_INSERT)


----------


I am absolutely dumb because I am just beginning to learn lua scripting. All I wanted to happen is:

1)when "Insert" was pressed
2)auto scan with a 4 byte scanner ; 33606 and 5606
3)replace 33606 and 5606 with 9600006


And I wanted that to happen everytime I press the "Insert" Button. But when I pressed it only "Could not convert first argument to number" was thrown.PLEASE HELP!!!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Sat Jun 03, 2017 2:32 pm    Post subject: Reply with quote

Code:
createHotkey(replace, VK_INSERT)

The first parameter to the createHotkey function is a callable entity that can handle what happens when a hotkey is pressed. That replace function is not meant to handle hotkeys- it's meant to replace values. Pass an anonymous function instead that calls the replace function:
Code:
createHotkey(function(hk) replace({33606,5606},9600006) end, VK_INSERT)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
aldrinjohnom
Newbie cheater
Reputation: 0

Joined: 03 Jun 2017
Posts: 15

PostPosted: Sat Jun 03, 2017 7:54 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Code:
createHotkey(replace, VK_INSERT)

The first parameter to the createHotkey function is a callable entity that can handle what happens when a hotkey is pressed. That replace function is not meant to handle hotkeys- it's meant to replace values. Pass an anonymous function instead that calls the replace function:
Code:
createHotkey(function(hk) replace({33606,5606},9600006) end, VK_INSERT)


Whoa! Thanks a Lot!!! It Worked!!! You are a Lifesaver! Thats Why I love Cheat Engine Community Very Happy We help each other as soon as we can Very Happy. Cheers
Back to top
View user's profile Send private message
aldrinjohnom
Newbie cheater
Reputation: 0

Joined: 03 Jun 2017
Posts: 15

PostPosted: Tue Jun 06, 2017 2:57 am    Post subject: Reply with quote

ParkourPenguin wrote:
Code:
createHotkey(replace, VK_INSERT)

The first parameter to the createHotkey function is a callable entity that can handle what happens when a hotkey is pressed. That replace function is not meant to handle hotkeys- it's meant to replace values. Pass an anonymous function instead that calls the replace function:
Code:
createHotkey(function(hk) replace({33606,5606},9600006) end, VK_INSERT)


Another question, how about a double scan type value?

Because I am having trouble with a double scan type value changine all the values it encountered...

Example:
I am trying to scan a double type value
3.5

It detected almost 200 items... but most of it are 3.58363826 or 3.8393629207

I wanted to make the lua script to only change all values which have a FIXED 3.5 value, not those long decimal values. Can you help me? Or anyone else please?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Tue Jun 06, 2017 10:05 am    Post subject: Reply with quote

If you want it to be exactly 3.5, you can use doubleToByteTable with an AoB scan:
Code:
function byteTableToAOBString(t)
  local ret = {}
  for k,v in ipairs(t) do
    ret[k] = string.format('%02X', v)
  end
  return table.concat(ret,' ')
end

local res = AOBScan(byteTableToAOBString(doubleToByteTable(3.5)), '+W-C', fsmAligned, '4')

if res then
  for i=0, res.Count-1 do
    print(res[i])
  end
else
  print('no results found')
end


However, this will only find values that are exactly 3.5. Values that look like they're 3.5 don't actually have to be 3.5. If you want to include some amount of error, use the memscan class instead and add a few trailing 0s to the search string (e.g. '3.500000'). Use Google for examples.

If you're worried about CE changing unrelated values, look into code injection. It's generally better than scanning for values.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
aldrinjohnom
Newbie cheater
Reputation: 0

Joined: 03 Jun 2017
Posts: 15

PostPosted: Tue Jun 06, 2017 10:46 pm    Post subject: Reply with quote

ParkourPenguin wrote:
If you want it to be exactly 3.5, you can use doubleToByteTable with an AoB scan:
Code:
function byteTableToAOBString(t)
  local ret = {}
  for k,v in ipairs(t) do
    ret[k] = string.format('%02X', v)
  end
  return table.concat(ret,' ')
end

local res = AOBScan(byteTableToAOBString(doubleToByteTable(3.5)), '+W-C', fsmAligned, '4')

if res then
  for i=0, res.Count-1 do
    print(res[i])
  end
else
  print('no results found')
end


However, this will only find values that are exactly 3.5. Values that look like they're 3.5 don't actually have to be 3.5. If you want to include some amount of error, use the memscan class instead and add a few trailing 0s to the search string (e.g. '3.500000'). Use Google for examples.

If you're worried about CE changing unrelated values, look into code injection. It's generally better than scanning for values.


Thank you Smile my problem got fixed by using your doubletobyte table scanning 3.50000 Smile

But one thing got to me as an interest. I just got reading about code injection you mentioned and it is very interesting for dynamic addresses.but I got questions for it.

1)does it need a pointer of the base address? Because I dont have one.
2)if code injection injects your specific code. How does it deal with the dynamic addresses? Will it trigger an autoscan for the values and inject it there? Laughing im just imagining weird thing Laughing



Im starting to become curious and exited about code injection but it seems that I dont understand a thing how to make a script. What is the alternative side of change 4byte(5606,33606)>960006 and double(3.5000)>50 USING Code injection? Can you make a example script for me about the code injection because I wanted to understand it clearly.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Wed Jun 07, 2017 8:30 am    Post subject: Reply with quote

The basic idea of code injection is that you overwrite the game's code with your own code. This allows you to modify the game to do whatever you want (within reason). You can remove the code that subtracts from your health or ammo, make all enemies die with a single attack, fly around the map, etc.

No, you don't need a pointer to create a code injection. You just need an injection point: some place in the code that's suitable to hook.
If code isn't located in a module, people usually find it with an AoB scan.

Do the CE tutorial (help menu in CE) and/or look at guides online (e.g. this topic) for more information. Examples can be found in tables on fearlessrevolution.

PS: I noticed a small memory leak in that code:
Code:
...
if res then
  for i=0, res.Count-1 do
    print(res[i])
  end
  res.destroy()   -- add this
else
  ...

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
aldrinjohnom
Newbie cheater
Reputation: 0

Joined: 03 Jun 2017
Posts: 15

PostPosted: Wed Jun 07, 2017 9:11 am    Post subject: Reply with quote

Ok,I will do Smile Thank You alot for you help Very Happy . I bet will will take some time to beat the CE tutorial xD but I will try to have patience to it Smile. Althrough I still dont understand the basic fundamentals of Lua(especially for me to manipulate AoB tricks) those Forums and Facts might help me understand and create my own scripts. Cheers!
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