panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Tue Sep 20, 2016 11:48 pm Post subject: Timer Action On Address Collection |
|
|
The attached ct contained a function, inspired by this post http://forum.cheatengine.org/viewtopic.php?t=594793 .
Quote: |
...
Try make a lua timer function,
1.the OnTimer function check a list of address,
1.1 if each addr is readable and somehow checked it is a valid address (eg. if it is a float value health address, check with float value between 0.01 and 99999 etc),
1.2.do something on individual address, (eg.check if its float value below 50 then add 100 float to the address),
1.3.otherwise remove this addr from the address list.
...
|
The function TimerActionOnAddressCollection is defined as
Code: |
TimerActionOnAddressCollection( id, interval, action)
-- id : a non empty string, used to retrieve the action object associated to the id ;
-- interval: the internal timer Interval number, if omitted when defining the action function, it will be default to 100 ms;
-- action: the defined function to be act on each address in the collected address list,
-- signature : function(addr,...)
1st parameter is necessary address, it will be a number type inside the action function. See example in test script. If this action function explicitly return true, the addr address 1st parameter value will be removed from the address collection. Use this to remove invalid address.
alternative form:
TimerActionOnAddressCollection( id, true)
return the id associated action object if defined, return nil if not defined.
TimerActionOnAddressCollection( id, false)
destroy the internal timer and remove the association between the id and the action function.
|
Example in test scrtipt:
remove association for id 'Up' and 'Dn'
Code: |
TimerActionOnAddressCollection('Up',false) -- remove old definition
TimerActionOnAddressCollection('Dn',false)
|
Defined the action to be associated to 'Up' and 'Dn',
'Dn' action is decrease the address integer value by 1 per 100ms,
'Up' action is to add the address integer value 0x90 if it is below 0x90, so up the value to 0x90+0x90=0x120.
Code: |
local Up = TimerActionOnAddressCollection('Up',function(addr,keep) -- define action
if not keep and math.floor(addr/4) % 2 ~= 0 then return true end -- test to active remove invalid address
local n = readInteger(addr)
if n<0x90 then writeInteger(addr,n+0x90) end
end)
local Dn = TimerActionOnAddressCollection('Dn',function(addr,keep)
if not keep and math.floor(addr/4) % 2 ~= 0 then return true end
local n = readInteger(addr)
if n>0 then writeInteger(addr,n-1) end
end)
|
Manipulate the action object:
Get the action object
Code: |
local Up = TimerActionOnAddressCollection('Up',true)
local Dn = TimerActionOnAddressCollection('Dn',true)
|
The action object can be treat as a timer (but it is in 'table' type, not 'userdata'), so it can be Stop/Resume the timer like :
Code: |
if Up then Up.Enabled = not Up.Enabled end
if Dn then Dn.Enabled = not Dn.Enabled end
|
It has to be check if it is 'nil' to prevent error.
To add an address into the address collection, use the object as a function and address to be added as 1st parameter:
Code: |
if Up and Dn and Up:alive() and Dn:alive() and readInteger'__' then
local b = GetAddress'__+10'
for i=0,15 do
Up(i*4+b)
Dn(i*4+b)
end
end
|
Other api for the action object, 'Up' as example instance of an action object:
Code: |
Up:alive() - check if the timer is still there, should not be use if return false.
Up:Destroy() -- destroy timer and the action object
Up.timer -- the timer
Up.ID -- the associated id
Up.interval -- the initial set timer interval, use Up.Interval = 500 to change the timer Interval (capital 'I'), or Up.timer.Interval = 500
Up, action object instance, itself is a table, its key is address number collected.
|
bye~ _________________
- Retarded. |
|