| View previous topic :: View next topic |
| Author |
Message |
Flux. Advanced Cheater
Reputation: 0
Joined: 10 Nov 2016 Posts: 88 Location: Another World - N5X2 106311411+2123518
|
Posted: Mon Feb 24, 2020 1:35 pm Post subject: Check if a value is increased by exactly xx amount |
|
|
Hello,
After some more help with lua.
What i want to do is - check if a value is increased by exactly xx amount.
So i can use
local z = getAddressList().getMemoryRecordByDescription("test") for the value,
and a timer to keep checking for a change.
But stuck on the function part, how to check if the z value is increased by exactly 100 ? and if it is then do something.
Any help appreciated.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4716
|
Posted: Mon Feb 24, 2020 1:54 pm Post subject: |
|
|
| Code: | local memrec = AddressList.getMemoryRecordByDescription('test')
local oldval = tonumber(memrec.Value)
timer.OnTimer = function()
local newval = tonumber(memrec.Value)
if newval - oldval == 100 then
-- code
end
oldval = newval
end
|
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Flux. Advanced Cheater
Reputation: 0
Joined: 10 Nov 2016 Posts: 88 Location: Another World - N5X2 106311411+2123518
|
Posted: Mon Feb 24, 2020 3:30 pm Post subject: |
|
|
Hello ParkourPenguin.
Thank you for the reply,
I have just tried your script, and its works pretty well, it doesn't grab the value every time, but most of the time it does.
Here is a full script for anyone who may need it.
| Code: | {$lua}
[ENABLE]
local memrec = AddressList.getMemoryRecordByDescription("test")
local oldval = tonumber(memrec.Value)
timer = createTimer(nil)
timer.setInterval = 100
timer.OnTimer = function()
local newval = tonumber(memrec.Value)
if newval - oldval == 100 then
print('success')
end
oldval = newval
end
[DISABLE]
timer_setEnabled(timer, false) |
Thanks again, much appreciated.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4716
|
Posted: Mon Feb 24, 2020 4:22 pm Post subject: |
|
|
setInterval is a function, not a property, and most of those old underscore function calls should be replaced now.
| Code: | timer.Interval = 100
...
timer.Enabled = false |
If it still doesn't catch everything, use a lower interval on the timer or a breakpoint instead of a timer.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Flux. Advanced Cheater
Reputation: 0
Joined: 10 Nov 2016 Posts: 88 Location: Another World - N5X2 106311411+2123518
|
Posted: Tue Feb 25, 2020 4:31 am Post subject: |
|
|
Hello ParkourPenguin,
Thank you for the info about the timer.
After some testing this morning, a new problem has arisen -
For instance the value on my cheat table shows in hex 0100, (2 bytes)
in the script if i use this 0x100 or 256 as the value it does not work, but simply using 100 does,
Shouldn't it accept 0x100 in the script instead of 100, its a little confusing.
Anyway the problem is once the value reaches 9999 and changes to A000,
the arithmetic breaks and lua throws errors every interval,
is there a fix for using when hex values populate the address ?
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4716
|
Posted: Tue Feb 25, 2020 11:07 am Post subject: |
|
|
What do you mean by "use 0x100"? Are you setting the value of the memory record to that? If so, the Value property is a string, not a number. CE parses that string using other properties of the memory record (i.e. show as hex) to write the correct value to the address. So, if you're showing it as hex and you want to write 0x100 to the address, do this:
| Code: | | memrec.Value = '100' |
It probably breaks because tonumber is translating a hex string as if it were in base 10 and/or you're trying to do arithmetic on a string. Do this instead:
| Code: | local v = tonumber(memrec.Value, memrec.ShowAsHex and 16 or 10)
-- do arithmetic on v
v = v + 10
memrec.Value = (memrec.ShowAsHex and '%X' or '%d'):format(v) | If you want more specific help, post the code and I can tell you what's wrong.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Flux. Advanced Cheater
Reputation: 0
Joined: 10 Nov 2016 Posts: 88 Location: Another World - N5X2 106311411+2123518
|
Posted: Tue Feb 25, 2020 12:38 pm Post subject: |
|
|
Hello ParkourPenguin,
Thanks or explaining, that make sense now, as for the script i am obviously doing something wrong,
after adding the code you posted it now constantly prints 10, here is the modified script - | Code: | {$lua}
[ENABLE]
local memrec = AddressList.getMemoryRecordByDescription("test")
local v = tonumber(memrec.Value, memrec.ShowAsHex and 16 or 10)
v = v + 10
memrec.Value = (memrec.ShowAsHex and '%X' or '%d'):format(v)
local oldval = v
timer = createTimer(nil)
timer.Interval = 1000
timer.OnTimer = function()
print(oldval)
local newval = v
print(newval)
if (newval - oldval == 100) then
print('success')
end
oldval = newval
end
[DISABLE]
timer.Enabled = false |
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4716
|
|
| Back to top |
|
 |
Flux. Advanced Cheater
Reputation: 0
Joined: 10 Nov 2016 Posts: 88 Location: Another World - N5X2 106311411+2123518
|
Posted: Tue Feb 25, 2020 2:31 pm Post subject: |
|
|
Hello ParkourPenguin,
this script does indeed work, thank you for that, much appreciated.
The values that are printed are now in dec , and using 0x100 in the script works fine, i have also just changed the timer interval which also works a little better.
what are the advantages of using a breakpoint instead of a timer, if its worth doing could you give an example.
Many thanks for the help with table.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4716
|
Posted: Tue Feb 25, 2020 5:26 pm Post subject: |
|
|
To print numbers in hex:
| Code: | | print(('%X'):format(255)) |
The timer checks it periodically. If the game writes to the value faster than the timer checks the value, it might not work.
Breakpoints will trigger every time the value is written to. It's guaranteed to catch every write to the address (more or less). However, the number of hardware breakpoints is limited, but this shouldn't be a problem if you're not monitoring a bunch of addresses at once.
| Code: | {$lua}
if syntaxcheck then return end
local memrec = AddressList.getMemoryRecordByDescription("test")
[ENABLE]
local oldval = tonumber(memrec.Value, memrec.ShowAsHex and 16 or 10)
local size_lookup = {
[vtByte] = 1,
[vtWord] = 2,
[vtDword] = 4,
[vtQword] = 8
}
debug_setBreakpoint(memrec.Address, assert(size_lookup[memrec.Type],'Unsupported type'),
bptWrite, bpmDebugRegister, function()
print(('%X'):format(oldval))
local newval = tonumber(memrec.Value, memrec.ShowAsHex and 16 or 10)
print(('%X'):format(newval))
if (newval - oldval == 100) then
print('success')
end
oldval = newval
debug_continueFromBreakpoint(co_run)
return 0
end)
[DISABLE]
debug_removeBreakpoint(memrec.Address)
| (the if syntaxcheck... line at the top is important for Lua in AA scripts)
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Flux. Advanced Cheater
Reputation: 0
Joined: 10 Nov 2016 Posts: 88 Location: Another World - N5X2 106311411+2123518
|
Posted: Wed Feb 26, 2020 11:26 am Post subject: |
|
|
Thank you ParkourPenguin.
Going to give this a good testing now, thank you for all the help.
|
|
| Back to top |
|
 |
|