| View previous topic :: View next topic |
| Author |
Message |
peddroelm Advanced Cheater
Reputation: 0
Joined: 03 Oct 2014 Posts: 84
|
Posted: Fri Mar 11, 2016 1:07 am Post subject: How to access/print OS time with millisecond precision ? |
|
|
I'm trying to measure very precise time difference between a write breakpoint activation.
os.Time is useless (not enough precision)
I need something like this "..Gets the number of milliseconds that have elapsed since Windows was started.."
EDIT1
[os.clock] - gets the approximate number of seconds of CPU time used by the program. This function is implemented in terms of the ANSI C clock [1] function, and the precise meaning of this value is implementation specific. For example, on Linux, clock gives "CPU time" [2][3], which only counts the time in which the process is actively using the CPU and does not count time executing other processes or waiting for I/O. CPU time may be less than the real time ("wall clock time"). On Windows, clock counts real (wall clock) time since the start of the process [4]. On Windows and Linux, the resolution on clock is on the order of milliseconds, which is more precise than the time function, but on other systems it may be only one second resolution. The clock value will also wrap around on overflow, depending on the size of the data type used to represent clock_t. Sometimes this function is more useful than os.time for benchmarking: local clock = os.clock; local t1 = clock(); dosomething(); local dt = clock() - t1 . |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 472
Joined: 09 May 2003 Posts: 25867 Location: The netherlands
|
Posted: Fri Mar 11, 2016 2:44 am Post subject: |
|
|
ce's Lua function getTickCount() returns the number of milliseconds since the system was turned on _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping
Last edited by Dark Byte on Fri Mar 11, 2016 3:29 am; edited 1 time in total |
|
| Back to top |
|
 |
hhhuut Grandmaster Cheater
Reputation: 6
Joined: 08 Feb 2015 Posts: 607
|
Posted: Fri Mar 11, 2016 3:27 am Post subject: |
|
|
| QueryPerformanceCounter would also be an option ... |
|
| Back to top |
|
 |
peddroelm Advanced Cheater
Reputation: 0
Joined: 03 Oct 2014 Posts: 84
|
Posted: Fri Mar 11, 2016 6:09 am Post subject: |
|
|
"
What's the difference between clock(), gettickcount(), QueryPerformanceCounter() and QueryPerformanceFrequency()?
..No, they don't have millisecond precision. clock and GetTickCount have between 4 and 15 millisecond precision on most systems. QueryPerformanceCounter has a precision in the microsecond to nanosecond range.
clock is a wrapper around GetTickCount if you're using Microsoft's C runtime library, which, if you're using an MS compiler, you probably are. GetTickCount returns a value in milliseconds, but it doesn't increase by one millisecond after one millisecond has elapsed. It is only incremented when a system clock interrupt occurs, which is every four to 15 milliseconds - normally it's about 15ms, but it can be changed by applications. This affects the whole computer: it affects thread scheduling, and the overhead of more frequent interrupts also leaves less CPU time for actually running program code, so don't do it unless you really need it. If your computer is ticking more frequently than 15ms, some other application has modified the tick interrupt frequency.
QueryPerformanceCounter uses whatever high-resolution timers are available on the system. In the past, it was usually based on the processor's internal count of clock cycles, so would count at 2-3GHz, or about 0.5ns. Unfortunately some processors varied the rate that the counter would tick at when in low-power states, and in multi-CPU systems (i.e. with multiple processor sockets) you'd get problems if the CPUs weren't all the same speed. Windows now uses other more reliable sources, but they aren't quite as high resolution as the processor. QueryPerformanceFrequency tells you how many ticks occur in one second. To get milliseconds, multiply the difference of QPC samples by 1000, and divide by the result of QueryPerformanceFrequency... "
EDIT1
os.clock(), gettickcount() print/compile
how do I use QueryPerformanceCounter ? attempt to call a nil value (global 'QueryPerformanceCounter')
Last edited by peddroelm on Fri Mar 11, 2016 6:34 am; edited 1 time in total |
|
| Back to top |
|
 |
hhhuut Grandmaster Cheater
Reputation: 6
Joined: 08 Feb 2015 Posts: 607
|
Posted: Fri Mar 11, 2016 6:22 am Post subject: |
|
|
| peddroelm wrote: | | QueryPerformanceCounter has a precision in the microsecond to nanosecond range. |
So what's the problem with that, if the other methods are not precise enough for your purpose? |
|
| Back to top |
|
 |
peddroelm Advanced Cheater
Reputation: 0
Joined: 03 Oct 2014 Posts: 84
|
Posted: Fri Mar 11, 2016 6:34 am Post subject: |
|
|
os.clock(), gettickcount() print/compile
how do I use QueryPerformanceCounter ? attempt to call a nil value (global 'QueryPerformanceCounter')
EDIT1
maybe here ?
https://github.com/bananu7/Contrlua/blob/master/HiResTimer.lua
require"alien"
--
-- get the kernel dll
--
local kernel32=alien.load("kernel32.dll")
--
-- get dll functions
--
local QueryPerformanceCounter=kernel32.QueryPerformanceCounter
...
EDIT 2
 |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 472
Joined: 09 May 2003 Posts: 25867 Location: The netherlands
|
Posted: Fri Mar 11, 2016 7:49 am Post subject: |
|
|
assuming ce 6.5 and 64-bit
| Code: |
if qpccallerRegistered~=true then
qpccallerRegistered=autoAssemble([[
alloc(qpccaller, 1024)
registersymbol(qpccaller)
qpccaller:
sub rsp,30
lea rcx,[rsp+28]
mov [rcx],0
call QueryPerformanceCounter
mov rax,[rsp+28]
add rsp,30
ret
]], true)
end
return executeCodeLocal("qpccaller")
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
peddroelm Advanced Cheater
Reputation: 0
Joined: 03 Oct 2014 Posts: 84
|
Posted: Fri Mar 11, 2016 7:58 am Post subject: |
|
|
the above code works (time) (will still have to figure out how integrate with the rest of the would be script)
separate question since I cannot bump the other thread
| Code: | -- comment
if (isDebugging~=nil) and (addressBP1~=nil) then
debug_removeBreakpoint(addressBP1)
isDebugging=nil
address=nil
end
addressBP1=0x24D996F4
function debugger_onBreakpointBP1()
print(500-readFloat(addressBP1))
writeFloat(addressBP1, 500.0) -- NO VISIBLE EFFECT ? (I don't heal during breakpoint and quickly die )
debug_continueFromBreakpoint(co_run)
return 1
end
debug_setBreakpoint(addressBP1, 4, bptWrite,debugger_onBreakpointBP1())
isDebugging=true |
above ~ works - will trigger when I take damage but apparently the writeFloat(addressBP1, 500.0) doesn't work. Since the breakpoint doesn't heal me, I quickly run out of HP and "die" .[/code] |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 472
Joined: 09 May 2003 Posts: 25867 Location: The netherlands
|
Posted: Fri Mar 11, 2016 8:04 am Post subject: |
|
|
does changing it manually back to 500, and then take 1 hp damage, change it to 499 or a lower value ?
if a lower value then the value you found is only a visual/temporary unrelated address . _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
peddroelm Advanced Cheater
Reputation: 0
Joined: 03 Oct 2014 Posts: 84
|
Posted: Fri Mar 11, 2016 8:09 am Post subject: |
|
|
| Dark Byte wrote: | does changing it manually back to 500, and then take 1 hp damage, change it to 499 or a lower value ?
if a lower value then the value you found is only a visual/temporary unrelated address . |
it is the right address. changing it in the main window works
Here is the equivalent in MHS Breakpoint script I'm trying to achieve
| Code: | void On_BP_2(LPVOID lpvAddress, LPPROC_INFO_MHS lpProcInfo)
{
extern float f3Value = { "", 0x3BEF02F4};
//Damage + heal + timestamp
DWORD Timestamp;
PrintF ("+%u ms |Health Damage %f" , Time()-Timestamp, 500-f3Value);
Timestamp = Time();
f3Value = 500;
} |
EDIT1
restarted game/CE - this time I think it heals but it doesn't continue after the breakpoint. Game freezes each time I get hit until I hit execute ..
EDIT2
IS IT POSSIBLE THAT writeFloat(addressBP1, 500.0) FROM WITHIN THE BREAKPOINT FUNCTION TRIGGERS THE BREAKPOINT ?
should still print 0 0 0 0 0 0 0 .. each time it trips itself.
Why doesn't debug_continueFromBreakpoint(co_run) work ? ( |
|
| Back to top |
|
 |
|