Skip to content

Fix weapon zoom behavior #2769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Client/core/CKeyBinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,12 +1092,8 @@ void CKeyBinds::CallGTAControlBind(CGTAControlBind* pBind, bool bState)
// If its keydown, or there isnt another bind for this control down
if (bState || !GetMultiGTAControlState(pBind))
{
// HACK: Are we're trying to ZOOM IN or ZOOM OUT using the mouse wheel?
bool bZoomWheel = m_bMouseWheel && (pBind->control->action == ZOOM_IN || pBind->control->action == ZOOM_OUT);

// If this control is enabled
// HACK: Prevent the game from using the mouse wheel to zoom *again* (it still does this itself)
if (pBind->control->bEnabled && !bZoomWheel)
if (pBind->control->bEnabled)
{
pBind->control->bState = bState;
}
Expand Down
27 changes: 27 additions & 0 deletions Client/core/DXHook/CProxyDirectInputDevice8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CProxyDirectInputDevice8::CProxyDirectInputDevice8(IDirectInputDevice8A* pDevice
// Initialize our device member variable.
m_pDevice = pDevice;
m_bDropDataIfInputGoesToGUI = true;
m_bIsMouse = false;

// Don't block joystick if GUI wants input (so same as XInput joystick)
DIDEVICEINSTANCE didi;
Expand All @@ -31,13 +32,21 @@ CProxyDirectInputDevice8::CProxyDirectInputDevice8(IDirectInputDevice8A* pDevice
uint uiHid = (didi.dwDevType >> 16) & 0xff;

if (uiType == DI8DEVTYPE_GAMEPAD || uiType == DI8DEVTYPE_JOYSTICK)
{
m_bDropDataIfInputGoesToGUI = false;
}
else if (uiType == DI8DEVTYPE_MOUSE)
{
m_bIsMouse = true;
}

WriteDebugEvent(SString(" CProxyDirectInputDevice8 Device:%08x Type:0x%x SubType:0x%x HID:0x%x ProductName:%s", pDevice, uiType, uiSubType, uiHid,
didi.tszProductName));
}
else
{
WriteDebugEvent(SString(" CProxyDirectInputDevice8 GetDeviceInfo failed:%08x", hResult));
}
}

CProxyDirectInputDevice8::~CProxyDirectInputDevice8()
Expand Down Expand Up @@ -124,6 +133,24 @@ HRESULT CProxyDirectInputDevice8::GetDeviceState(DWORD a, LPVOID b)
}
}

// HACK: Don't pass scroll wheel data to the game as it interfers with MTA key bindings
// Without this, zoom in/out with scroll wheel still happens when not bound to
// mouse wheel in MTA but bound in single player.
// A better option could be to instead give this data only when we want it (bound
// in MTA and when scrolling) to retain the proper smooth zoom, but it would require
// forcing the game to use this data even when not bound in single player.
if (m_bIsMouse)
{
hResult = m_pDevice->GetDeviceState(a, b);

DIMOUSESTATE2* mouseState = reinterpret_cast<DIMOUSESTATE2*>(b);
mouseState->lZ = 0;

m_pDevice->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), NULL, &dwNumItems, 0);

return hResult;
}

return m_pDevice->GetDeviceState(a, b);
}

Expand Down
1 change: 1 addition & 0 deletions Client/core/DXHook/CProxyDirectInputDevice8.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ class CProxyDirectInputDevice8 : public IDirectInputDevice8A

IDirectInputDevice8A* m_pDevice;
bool m_bDropDataIfInputGoesToGUI;
bool m_bIsMouse;
};