Skip to content

Commit

Permalink
Add the ability to bind the side mouse buttons (FAForever#96)
Browse files Browse the repository at this point in the history
Supports the buttons that are identified with `XButton1` and `XButton2`
  • Loading branch information
RutreD authored and 4z0t committed Nov 11, 2024
1 parent acd3ed3 commit 8f05561
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ These don't matter except for other assembly patches
- section/xact_3d_fix.cpp
- Improvements to lua messages
- hooks/LuaMessages.cpp
- Adds the ability to bind the side mouse buttons (XButton1 and XButton2)
- hooks/OnWindowMessage.cpp
- section/OnWindowMessage.cpp

## Gameplay
- Change tick intel update interval from every 30 ticks to every 1 tick
Expand Down
3 changes: 3 additions & 0 deletions hooks/OnWindowMessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "../define.h"
asm(".section h0; .set h0,0x00430C0E;"
"call " QU(OnWindowMessage) ";");
62 changes: 62 additions & 0 deletions section/OnWindowMessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "include/global.h"

struct KeyEventInfo
{
unsigned long repeatCount : 16;
unsigned long scanCode : 8;
unsigned long isExtended : 1;
unsigned long reserved : 4;
unsigned long contextCode : 1;
unsigned long previousState : 1;
unsigned long transitionState : 1;

inline unsigned long ToULong() const
{
return repeatCount |
(scanCode << 16) |
(isExtended << 24) |
(reserved << 25) |
(contextCode << 29) |
(previousState << 30) |
(transitionState << 31);
}
};
static_assert(sizeof(KeyEventInfo) == 4);

int __thiscall wxWindow__MSWWindowProc(void *this_, unsigned int uMsg, unsigned int wParam, unsigned long lParam) asm("0x0096D110");

int __thiscall OnWindowMessage(void *this_, unsigned int uMsg, unsigned int wParam, unsigned long lParam)
{
switch (uMsg)
{
case 0x020B: /*WM_XBUTTONDOWN*/
uMsg = 0x0100; /*WM_KEYDOWN*/
wParam = (((wParam) >> 16) & 0xFFFF) + 4; // VK_XBUTTON(1 or 2)
lParam = KeyEventInfo{
.repeatCount = 1,
.scanCode = 0xFF,
.isExtended = 0,
.reserved = 0,
.contextCode = 0,
.previousState = 0,
.transitionState = 0}
.ToULong();
break;
case 0x020C: /*WM_XBUTTONUP*/
uMsg = 0x0101; /*WM_KEYUP*/
wParam = (((wParam) >> 16) & 0xFFFF) + 4; // VK_XBUTTON(1 or 2)
lParam = KeyEventInfo{
.repeatCount = 1,
.scanCode = 0xFF,
.isExtended = 0,
.reserved = 0,
.contextCode = 0,
.previousState = 1,
.transitionState = 1}
.ToULong();
break;
default:
break;
}
return wxWindow__MSWWindowProc(this_, uMsg, wParam, lParam);
}

0 comments on commit 8f05561

Please sign in to comment.