-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNFSU2_FEng.h
123 lines (102 loc) · 4.3 KB
/
NFSU2_FEng.h
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
#pragma once
#include <windows.h>
#include <timeapi.h>
#pragma comment(lib,"winmm.lib")
#define GAME_HWND_ADDR 0x00870990
// Win32 mouse API stuff
RECT windowRect;
bool bMousePressedDown = false;
bool bMousePressedDownOldState = false;
bool bMouse2PressedDown = false;
bool bMouse2PressedDownOldState = false;
bool bMouse3PressedDown = false;
bool bMouse3PressedDownOldState = false;
bool bConfineMouse = false;
int TimeSinceLastMouseMovement = 0;
#define MOUSEHIDE_TIME 5000
#define FEMOUSECURSOR_X_ADDR 0x008763D4
#define FEMOUSECURSOR_Y_ADDR 0x008763D8
#define FEMOUSECURSOR_BUTTONPRESS_ADDR 0x008763F1
#define FEMOUSECURSOR_BUTTONPRESS2_ADDR 0x008763F2
#define FEMOUSECURSOR_BUTTONPRESS3_ADDR 0x008763F3
#define FEMOUSECURSOR_BUTTON2PRESS_ADDR 0x008763F7
#define FEMOUSECURSOR_BUTTON2PRESS2_ADDR 0x008763F8
#define FEMOUSECURSOR_BUTTON2PRESS3_ADDR 0x008763F9
#define FEMOUSECURSOR_BUTTON3PRESS_ADDR 0x008763F4
#define FEMOUSECURSOR_BUTTON3PRESS2_ADDR 0x008763F5
#define FEMOUSECURSOR_BUTTON3PRESS3_ADDR 0x008763F6
#define FEMOUSECURSOR_CARORBIT_X_ADDR 0x008763E4
#define FEMOUSECURSOR_CARORBIT_Y_ADDR 0x008763E8
#define FEMOUSE_MOUSEWHEEL_ADDR 0x008763EC
void UpdateFECursorPos()
{
bool bMouseInGameWindow = false;
POINT MousePos;
GetCursorPos(&MousePos);
GetWindowRect(*(HWND*)GAME_HWND_ADDR, &windowRect);
float ratio = 480.0 / (windowRect.bottom - windowRect.top); // scaling it to 480 height since that's what FE wants
if ((MousePos.x >= windowRect.left) || (MousePos.x <= windowRect.right) && (MousePos.y >= windowRect.top) || (MousePos.y <= windowRect.bottom))
bMouseInGameWindow = true;
MousePos.x = MousePos.x - windowRect.left;
MousePos.y = MousePos.y - windowRect.top;
MousePos.x = (int)((float)(MousePos.x) * ratio);
MousePos.y = (int)((float)(MousePos.y) * ratio);
// car orbiting position calculation - always relative to old
*(int*)FEMOUSECURSOR_CARORBIT_X_ADDR = MousePos.x - *(int*)FEMOUSECURSOR_X_ADDR;
*(int*)FEMOUSECURSOR_CARORBIT_Y_ADDR = MousePos.y - *(int*)FEMOUSECURSOR_Y_ADDR;
if (!bMouseInGameWindow)
SetCursor(LoadCursor(NULL, IDC_ARROW));
// get time since last movement and hide it after a while (unless the cursor is within the game window so we don't hide it)
if ((MousePos.x != *(int*)FEMOUSECURSOR_X_ADDR) || (MousePos.y != *(int*)FEMOUSECURSOR_Y_ADDR))
{
TimeSinceLastMouseMovement = timeGetTime();
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
else
{
if ((TimeSinceLastMouseMovement + MOUSEHIDE_TIME) < timeGetTime())
SetCursor(NULL);
}
*(int*)FEMOUSECURSOR_X_ADDR = MousePos.x;
*(int*)FEMOUSECURSOR_Y_ADDR = MousePos.y;
// track mouse click state - make sure it lasts for exactly 1 tick of a loop, because the game is a little overzelaous with reading this input
if (bMousePressedDown != bMousePressedDownOldState)
{
*(bool*)FEMOUSECURSOR_BUTTONPRESS_ADDR = bMousePressedDown;
*(bool*)FEMOUSECURSOR_BUTTONPRESS2_ADDR = bMousePressedDown;
*(bool*)FEMOUSECURSOR_BUTTONPRESS3_ADDR = !bMousePressedDown;
bMousePressedDownOldState = bMousePressedDown;
}
else
{
//*(bool*)FEMOUSECURSOR_BUTTONPRESS_ADDR = false; // except this one, it's used for car orbiting
*(bool*)FEMOUSECURSOR_BUTTONPRESS2_ADDR = false;
*(bool*)FEMOUSECURSOR_BUTTONPRESS3_ADDR = false;
}
// track mouse click state - make sure it lasts for exactly 1 tick of a loop, because the game is a little overzelaous with reading this input
if (bMouse2PressedDown != bMouse2PressedDownOldState)
{
*(bool*)FEMOUSECURSOR_BUTTON2PRESS_ADDR = bMouse2PressedDown;
*(bool*)FEMOUSECURSOR_BUTTON2PRESS2_ADDR = bMouse2PressedDown;
*(bool*)FEMOUSECURSOR_BUTTON2PRESS3_ADDR = !bMouse2PressedDown;
bMouse2PressedDownOldState = bMouse2PressedDown;
}
else
{
*(bool*)FEMOUSECURSOR_BUTTON2PRESS2_ADDR = false;
*(bool*)FEMOUSECURSOR_BUTTON2PRESS3_ADDR = false;
}
// track mouse click state - make sure it lasts for exactly 1 tick of a loop, because the game is a little overzelaous with reading this input
if (bMouse3PressedDown != bMouse3PressedDownOldState)
{
*(bool*)FEMOUSECURSOR_BUTTON3PRESS_ADDR = bMouse3PressedDown;
*(bool*)FEMOUSECURSOR_BUTTON3PRESS2_ADDR = bMouse3PressedDown;
*(bool*)FEMOUSECURSOR_BUTTON3PRESS3_ADDR = !bMouse3PressedDown;
bMouse3PressedDownOldState = bMouse3PressedDown;
}
else
{
*(bool*)FEMOUSECURSOR_BUTTON3PRESS2_ADDR = false;
*(bool*)FEMOUSECURSOR_BUTTON3PRESS3_ADDR = false;
}
}