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 


Need help with Lua script

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

Joined: 28 Nov 2024
Posts: 3

PostPosted: Thu Nov 28, 2024 3:17 am    Post subject: Need help with Lua script Reply with quote

I want to write a LUA script to search for groups with 4:0 4:0 w:4 4:120 4:700, then change all occurrences of 120 to 0 in the search results and lock them. Please help me, thank you very much
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Thu Nov 28, 2024 4:32 am    Post subject: Reply with quote

Group scanning, freezing of found addresses and the option to start and end them with a hotkey:

Code:
local resAddrTbl = {}

function FindAndValue(find_this,byt)
local memscan = createMemScan()
local foundlist = createFoundList(memscan)
memscan.firstScan(soExactValue, vtGrouped, rtRounded, find_this, nil, 0, "00007fffffffffff", "+W-C", fsmAligned, "4", false, false, false, false)
memscan.waitTillDone()
foundlist.initialize()

local address = foundlist.Address
 --print(foundlist.Count)
 if foundlist.Count>0 then
  for i = 0, foundlist.Count - 1 do
 --print(address[i].." - "..readInteger(address[i],true).." - "..readInteger(address[i].."+04",true)
 --      .." - "..readInteger(address[i].."+08",true).." - "..readInteger(address[i].."+0C",true).." - "..readInteger(address[i].."+10",true))
   resAddress = address[i].."+"..byt
   table.insert(resAddrTbl, resAddress)

     foundlist.destroy()
     memscan.destroy()
     return resAddrTbl
  end
  else
  foundlist.destroy()
  memscan.destroy()
  --showMessage("Code Not found!")
  return resAddrTbl
 end
end

------bytes:- 0 - 4 - 8 - 12 -- 16
find_this = "4:0 4:0 w:4 4:120 4:700"

------- > freeze ..

aa2 = getFreezeTimer()
timer_setEnabled(aa2, false)
timer_setInterval(aa2, 50)
local frzEnabled = 1

aa2.OnTimer=function()
  if #resAddrTbl==0 then
    FindAndValue(find_this, "0C")  -- byt: 12 = 0C
  end
  if (#resAddrTbl > 0) then
    for l,k in pairs(resAddrTbl) do
     --print(l,k,readInteger(k))
     writeInteger(tostring(k),"0")
    end
  end
end

function frz1()
  if frzEnabled==1 then
    timer_setEnabled(aa2, true)
    frzEnabled=2
  else
    timer_setEnabled(aa2, false)
    frzEnabled=1
  end
end

-- search and freeze (or unfreeze) key: F8
if frzKey1 then frzKey1.Destroy() frzKey1=nil end
frzKey1=createHotkey(frz1, VK_F8)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
mhxppt
How do I cheat?
Reputation: 0

Joined: 28 Nov 2024
Posts: 3

PostPosted: Thu Nov 28, 2024 7:09 pm    Post subject: Reply with quote

Thank you very much for your help, Master. However, after pressing F8 again, it only modifies the first result found. I need to modify all the results, which may be up to 400 entries. Also, I need to use a button to call this code instead of the shortcut key. I hope to get your help again, thank you very much
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Fri Nov 29, 2024 12:33 am    Post subject: Reply with quote

Code:
local resAddrTbl = {}

function FindAndValue(find_this,byt)
local memscan = createMemScan()
local foundlist = createFoundList(memscan)
memscan.firstScan(soExactValue, vtGrouped, rtRounded, find_this, nil, 0, "00007fffffffffff", "+W-C", fsmAligned, "4", false, false, false, false)
memscan.waitTillDone()
foundlist.initialize()

local address = foundlist.Address
 --print(foundlist.Count)
 if foundlist.Count>0 then
  for i = 0, foundlist.Count - 1 do
 --print(address[i].." - "..readInteger(address[i],true).." - "..readInteger(address[i].."+04",true)
 --      .." - "..readInteger(address[i].."+08",true).." - "..readInteger(address[i].."+0C",true).." - "..readInteger(address[i].."+10",true))
   resAddress = address[i].."+"..byt
   table.insert(resAddrTbl, resAddress)
  end
     foundlist.destroy()
     memscan.destroy()
  else
  foundlist.destroy()
  memscan.destroy()
  showMessage("Code Not found!")
 end
 return resAddrTbl
end

------bytes:- 0 - 4 - 8 - 12 -- 16
find_this = "4:0 4:0 w:4 4:120 4:700"

------- > freeze ..

aa2 = getFreezeTimer()
timer_setEnabled(aa2, false)
timer_setInterval(aa2, 50)
local frzEnabled = 1

aa2.OnTimer=function()
  if #resAddrTbl==0 then
    FindAndValue(find_this, "0C")  -- byt: 12 = 0C
  end
  if (#resAddrTbl > 0) then
    for l,k in pairs(resAddrTbl) do
     --print(l,k,readInteger(k))
     writeInteger(tostring(k),"0")
    end
  end
end

function frz1()
  if frzEnabled==1 then
    timer_setEnabled(aa2, true)
    frzEnabled=2
  else
    timer_setEnabled(aa2, false)
    frzEnabled=1
  end
end

UDF1.CEButton1.OnClick=function(sender) -- your form and button name?
frz1()
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
mhxppt
How do I cheat?
Reputation: 0

Joined: 28 Nov 2024
Posts: 3

PostPosted: Sat Nov 30, 2024 2:17 am    Post subject: Reply with quote

It works now, thank you very much for your help, Master
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