Skip to content

Commit

Permalink
WM_DEVICECHANGE fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Jan 20, 2024
1 parent b89731a commit f121d47
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/msvc_x86.yml
Expand Up @@ -35,8 +35,8 @@ env:
VERINC: ${{ github.event.inputs.version_increment || 'patch' }}

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name != 'workflow_dispatch' }}

permissions:
contents: write
Expand All @@ -55,7 +55,7 @@ jobs:
uses: microsoft/setup-msbuild@main

- name: Auto Increment Version
uses: MCKanpolat/auto-semver-action@v1
uses: MCKanpolat/auto-semver-action@v2
id: versioning
with:
releaseType: ${{ env.VERINC }}
Expand Down
1 change: 1 addition & 0 deletions data/plugins/MaxPayne3.FusionFix.ini
Expand Up @@ -5,6 +5,7 @@ DisableGlobalLeaderboards = 1 // Fixes Hoboken Alleys map crash in coop
OutlinesSizeMultiplier = 1.0f
BorderlessWindowed = 1
LightSyncRGB = 1 // Only Logitech hardware is supported, requires Logitech G HUB app
DisableDeviceChangeEvent = 1 // Fixes an issue when the game randomly enters pause menu
GamepadIcons = 0
; 0 - Xbox 360
; 1 - Xbox One
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -32,7 +32,7 @@ This projects aims to add new features and fix some issues in Max Payne 3. Also
### New menu options

- **BorderlessWindowed**, scroll through **SETTINGS -> GRAPHICS -> FULLSCREEN** to switch between windowed and borderless modes
- **GamepadIcons**, scroll through **SETTINGS -> CONTROLS -> GAMEPAD -> CONFIGURATION** to select various controller icon styles (Xbox 360, Xbox One, PS3, PS4, PS5, Nintendo Switch, Steam Deck)
- **GamepadIcons**, scroll through **SETTINGS -> CONTROLS -> GAMEPAD -> CONFIGURATION** to select various controller icon styles (Xbox 360, Xbox One, PS3, PS4, PS5, Nintendo Switch, Steam Deck, Steam Controller)

### New options

Expand Down
37 changes: 37 additions & 0 deletions source/devicechange.ixx
@@ -0,0 +1,37 @@
module;

#include <common.hxx>

export module devicechange;

import common;
import settings;

class DeviceChange
{
public:
DeviceChange()
{
FusionFix::onInitEvent() += []()
{
// Disable WM_DEVICECHANGE message handler, since it happens randomly for some reason
auto pattern = hook::pattern("74 63 83 E8 18 0F 85 ? ? ? ? E8 ? ? ? ? 84 C0");
static raw_mem pDeviceChangeCheck(pattern.get_first(0), { 0x90, 0x90 }); // nop

static auto DeviceChangeCB = []()
{
if (FusionFixSettings.GetInt("PREF_DEVICECHANGE"))
pDeviceChangeCheck.Write();
else
pDeviceChangeCheck.Restore();
};

DeviceChangeCB();

FusionFix::onIniFileChange() += []()
{
DeviceChangeCB();
};
};
}
} DeviceChange;
1 change: 1 addition & 0 deletions source/settings.ixx
Expand Up @@ -25,6 +25,7 @@ public:
mFusionPrefs["PREF_BORDERLESS"] = std::clamp(iniReader.ReadInteger("MAIN", "BorderlessWindowed", 1), 0, 1);
mFusionPrefs["PREF_LEDILLUMINATION"] = std::clamp(iniReader.ReadInteger("MAIN", "LightSyncRGB", 1), 0, 1);
mFusionPrefs["PREF_BUTTONS"] = std::clamp(iniReader.ReadInteger("MAIN", "GamepadIcons", 0), 0, gLastControllerTextureIndex);
mFusionPrefs["PREF_DEVICECHANGE"] = std::clamp(iniReader.ReadInteger("MAIN", "DisableDeviceChangeEvent", 1), 0, 1);

static std::once_flag flag;
std::call_once(flag, [&]()
Expand Down

0 comments on commit f121d47

Please sign in to comment.