@@ -6,9 +6,22 @@ static DWORD WINAPI My_timeGetTime(VOID)
6
6
return timeGetTime () - timeOffset ;
7
7
}
8
8
9
+ static int usePerformanceCounter ;
10
+
11
+ static LARGE_INTEGER countFrequency ;
12
+ static BOOL WINAPI My_QueryPerformanceFrequency (LARGE_INTEGER * lpFrequency )
13
+ {
14
+ * lpFrequency = countFrequency ;
15
+ return TRUE;
16
+ }
17
+
9
18
static LARGE_INTEGER countOffset ;
10
19
static BOOL WINAPI My_QueryPerformanceCounter (LARGE_INTEGER * lpPerformanceCount )
11
20
{
21
+ if (!usePerformanceCounter ) {
22
+ lpPerformanceCount -> QuadPart = My_timeGetTime ();
23
+ return TRUE;
24
+ }
12
25
BOOL ret = QueryPerformanceCounter (lpPerformanceCount );
13
26
if (ret ) {
14
27
lpPerformanceCount -> QuadPart -= countOffset .QuadPart ;
@@ -18,16 +31,27 @@ static BOOL WINAPI My_QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount)
18
31
19
32
MAKE_PATCHSET (relativetimer )
20
33
{
21
- // set offsets
34
+ TIMECAPS tc ;
35
+ if (timeGetDevCaps (& tc , sizeof (tc )) == TIMERR_NOERROR ) {
36
+ timeBeginPeriod (tc .wPeriodMin );
37
+ }
22
38
timeOffset = timeGetTime ();
23
- if (!QueryPerformanceCounter (& countOffset )) {
24
- countOffset .QuadPart = 0 ;
39
+
40
+ if (QueryPerformanceFrequency (& countFrequency ) && QueryPerformanceCounter (& countOffset )) {
41
+ usePerformanceCounter = 1 ;
42
+ } else {
43
+ usePerformanceCounter = 0 ;
44
+ countFrequency .QuadPart = 1000 ;
25
45
}
26
46
27
47
// hook timeGetTime
28
48
make_pointer (0x005581C8 , My_timeGetTime );
29
49
make_pointer (gboffset + 0x100D61F4 , My_timeGetTime );
30
50
31
51
// hook QueryPerformanceCounter
52
+ make_pointer (gboffset + 0x100D6084 , My_QueryPerformanceFrequency );
32
53
make_pointer (gboffset + 0x100D6080 , My_QueryPerformanceCounter );
54
+
55
+ double highFactor = 4294967296.0 ;
56
+ memcpy_to_process (gboffset + 0x100D6B20 , & highFactor , sizeof (highFactor ));
33
57
}
0 commit comments