forked from abort/Rinput-Library
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
113 lines (88 loc) · 3.02 KB
/
main.cpp
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
/*
This version of RInput was forked from abort's v1.31 by Vols and
Jezuz (http://steamcommunity.com/profiles/76561198057348857/), with
a lot of help from BuSheeZy (http://BushGaming.com) and qsxcv
(http://www.overclock.net/u/395745/qsxcv).
------------------------------------------------------------------
Comments from original author, abort (http://blog.digitalise.net/)
------------------------------------------------------------------
RInput allows you to override low definition windows mouse input
with high definition mouse input.
RInput Copyright (C) 2012, J. Dijkstra ([email protected])
This file is part of RInput.
RInput is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RInput is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RInput. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
static HINSTANCE g_hInstance = NULL;
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
// No need for a threaded entry
if (!DisableThreadLibraryCalls(hInstance))
return FALSE;
g_hInstance = hInstance;
break;
case DLL_PROCESS_DETACH:
// Unhook cursor functions and unload from injected process
CRawInput::hookLibrary(false);
CRawInput::unload();
break;
}
return TRUE;
}
// Validate that we are working with at least Windows XP
bool validateVersion()
{
DWORD dwVersion = GetVersion();
double fCompareVersion = LOBYTE(LOWORD(dwVersion)) + 0.1 * HIBYTE(LOWORD(dwVersion));
return (dwVersion && fCompareVersion >= 5.1);
}
extern "C" __declspec(dllexport) void entryPoint()
{
HANDLE hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, "RInputEvent32");
if (!hEvent)
displayError(L"Could not open interprocess communication event.");
WCHAR pwszError[256];
if (!validateVersion())
displayError(L"You must at least have Microsoft Windows XP to use this library.");
if (!CRawInput::initialize(pwszError))
displayError(pwszError);
if (!CRawInput::hookLibrary(true))
displayError(L"Failed to hook Windows API cursor functions.");
// Signal the injector that the injection and hooking are successful
if (!SetEvent(hEvent))
displayError(L"Failed to signal the initialization event.");
CloseHandle(hEvent);
if (!CRawInput::pollInput())
displayError(L"Failed to poll mouse input");
}
void unloadLibrary()
{
__asm
{
push -2
push 0
push g_hInstance
mov eax, TerminateThread
push eax
mov eax, FreeLibrary
jmp eax
}
}
void displayError(WCHAR* pwszError)
{
MessageBoxW(NULL, pwszError, L"Raw Input error!", MB_ICONERROR | MB_OK);
CRawInput::hookLibrary(false);
unloadLibrary();
}