Skip to content

Commit 8f05561

Browse files
RutreD4z0t
authored andcommitted
Add the ability to bind the side mouse buttons (FAForever#96)
Supports the buttons that are identified with `XButton1` and `XButton2`
1 parent acd3ed3 commit 8f05561

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ These don't matter except for other assembly patches
104104
- section/xact_3d_fix.cpp
105105
- Improvements to lua messages
106106
- hooks/LuaMessages.cpp
107+
- Adds the ability to bind the side mouse buttons (XButton1 and XButton2)
108+
- hooks/OnWindowMessage.cpp
109+
- section/OnWindowMessage.cpp
107110

108111
## Gameplay
109112
- Change tick intel update interval from every 30 ticks to every 1 tick

hooks/OnWindowMessage.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "../define.h"
2+
asm(".section h0; .set h0,0x00430C0E;"
3+
"call " QU(OnWindowMessage) ";");

section/OnWindowMessage.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "include/global.h"
2+
3+
struct KeyEventInfo
4+
{
5+
unsigned long repeatCount : 16;
6+
unsigned long scanCode : 8;
7+
unsigned long isExtended : 1;
8+
unsigned long reserved : 4;
9+
unsigned long contextCode : 1;
10+
unsigned long previousState : 1;
11+
unsigned long transitionState : 1;
12+
13+
inline unsigned long ToULong() const
14+
{
15+
return repeatCount |
16+
(scanCode << 16) |
17+
(isExtended << 24) |
18+
(reserved << 25) |
19+
(contextCode << 29) |
20+
(previousState << 30) |
21+
(transitionState << 31);
22+
}
23+
};
24+
static_assert(sizeof(KeyEventInfo) == 4);
25+
26+
int __thiscall wxWindow__MSWWindowProc(void *this_, unsigned int uMsg, unsigned int wParam, unsigned long lParam) asm("0x0096D110");
27+
28+
int __thiscall OnWindowMessage(void *this_, unsigned int uMsg, unsigned int wParam, unsigned long lParam)
29+
{
30+
switch (uMsg)
31+
{
32+
case 0x020B: /*WM_XBUTTONDOWN*/
33+
uMsg = 0x0100; /*WM_KEYDOWN*/
34+
wParam = (((wParam) >> 16) & 0xFFFF) + 4; // VK_XBUTTON(1 or 2)
35+
lParam = KeyEventInfo{
36+
.repeatCount = 1,
37+
.scanCode = 0xFF,
38+
.isExtended = 0,
39+
.reserved = 0,
40+
.contextCode = 0,
41+
.previousState = 0,
42+
.transitionState = 0}
43+
.ToULong();
44+
break;
45+
case 0x020C: /*WM_XBUTTONUP*/
46+
uMsg = 0x0101; /*WM_KEYUP*/
47+
wParam = (((wParam) >> 16) & 0xFFFF) + 4; // VK_XBUTTON(1 or 2)
48+
lParam = KeyEventInfo{
49+
.repeatCount = 1,
50+
.scanCode = 0xFF,
51+
.isExtended = 0,
52+
.reserved = 0,
53+
.contextCode = 0,
54+
.previousState = 1,
55+
.transitionState = 1}
56+
.ToULong();
57+
break;
58+
default:
59+
break;
60+
}
61+
return wxWindow__MSWWindowProc(this_, uMsg, wParam, lParam);
62+
}

0 commit comments

Comments
 (0)