Repository navigation
Expand file tree
/
Copy pathcpu-patch.c
More file actions
127 lines (105 loc) · 2.65 KB
/
Copy pathcpu-patch.c
File metadata and controls
127 lines (105 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <windows.h>
#define hwndApp (*(HWND*)(0x699600))
#define gbRemoteOn (*(int*)(0x69954C))
#define insideProcessMessage (*(int*)(0x6995B8))
static inline void VideoNextFrame()
{
((void (* __fastcall)(void))0x5976E0)();
}
static inline void PollSound()
{
((void (* __fastcall)(void))0x4ED490)();
}
void __fastcall Process1WindowsMessage()
{
struct tagMSG Msg;
BOOL anyMessage = FALSE;
insideProcessMessage = 1;
while (1)
{
while (PeekMessageA(&Msg, 0, 0, 0, 1u))
{
anyMessage = TRUE;
TranslateMessage(&Msg);
DispatchMessageA(&Msg);
}
if (!IsIconic(hwndApp) || gbRemoteOn)
break;
do
{
if (GetMessageA(&Msg, 0, 0, 0))
{
anyMessage = TRUE;
TranslateMessage(&Msg);
DispatchMessageA(&Msg);
}
}
while (IsIconic(hwndApp) && !gbRemoteOn);
}
if (!anyMessage)
MsgWaitForMultipleObjectsEx(0, nullptr, 1, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
VideoNextFrame();
insideProcessMessage = 0;
}
static void PumpGameMessages(DWORD timeout_ms)
{
MSG msg;
while (PeekMessageA(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
if (IsIconic(hwndApp) && !gbRemoteOn)
{
while (IsIconic(hwndApp) && !gbRemoteOn)
{
if (GetMessageA(&msg, nullptr, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
}
return;
}
if (timeout_ms > 0)
{
MsgWaitForMultipleObjectsEx(
0, // no handles
nullptr,
timeout_ms, // wait this long
QS_ALLINPUT, // wake on any message
MWMO_INPUTAVAILABLE
);
}
while (PeekMessageA(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
}
void __fastcall GameTime__Delay(DWORD time)
{
DWORD sum = time + timeGetTime();
while ((int)(timeGetTime() - sum) < 0)
{
insideProcessMessage = 1;
DWORD remaining = sum - timeGetTime();
PumpGameMessages(remaining);
VideoNextFrame();
insideProcessMessage = 0;
PollSound();
}
}
void __fastcall GameTime__DelayTil(DWORD time)
{
DWORD t = time;
while ((int)(timeGetTime() - t) < 0)
{
insideProcessMessage = 1;
DWORD remaining = t - timeGetTime();
PumpGameMessages(remaining);
VideoNextFrame();
insideProcessMessage = 0;
PollSound();
}
}