Skip to content

Commit

Permalink
Moves issue-#305 to Init.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Mar 9, 2022
1 parent d8369a6 commit 7912edd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 60 deletions.
60 changes: 0 additions & 60 deletions src/bugfix/bugfix_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,71 +43,12 @@
#include "theme.h"
#include "dropship.h"
#include "msgbox.h"
#include "command.h"
#include "debughandler.h"

#include "hooker.h"
#include "hooker_macros.h"


/**
* #issue-305
*
* Fixes bug where the sidebar mouse wheel scrolling "error" sound
* can be heard at the main menu.
*
* @author: CCHyper
*/
DECLARE_PATCH(_Main_Window_Procedure_Scroll_Sidebar_Check_Patch)
{
GET_STACK_STATIC(UINT, wParam, esp, 0x14);
static bool _mouse_wheel_scolling;

/**
* The code before this patch checks for WM_MOUSEWHEEL.
*/

/**
* We are not currently playing a scenario, no need to execute this command.
*/
if (!bool_007E4040 && !bool_007E48FC) {
goto message_handler;
}

/**
* Are we currently executing a scroll command? This is required because
* the Main_Window_Procedure function runs at a Windows level.
*/
if (_mouse_wheel_scolling) {
goto message_handler;
}

_mouse_wheel_scolling = true;

/**
* Execute the command based on the direction of the mouse wheel.
*/
if ((wParam & 0x80000000) == 0) {
CommandClass::Activate_From_Name("SidebarUp");
} else {
CommandClass::Activate_From_Name("SidebarDown");
}

_mouse_wheel_scolling = false;

executed:
JMP_REG(eax, 0x00685F9C);

message_handler:
JMP_REG(ecx, 0x00685FA0);
}

static void _Scroll_Sidebar_InGame_Check_Patch()
{
Patch_Jump(0x00685F69, &_Main_Window_Procedure_Scroll_Sidebar_Check_Patch);
}


/**
* #issue-8
*
Expand Down Expand Up @@ -437,5 +378,4 @@ void BugFix_Hooks()
_Dont_Stretch_Main_Menu_Video_Patch();
_Scale_Movies_By_Ratio_Patch();
_MultiMission_Constructor_MaxPlayers_Typo_Patch();
_Scroll_Sidebar_InGame_Check_Patch();
}
56 changes: 56 additions & 0 deletions src/extensions/init/initext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "newmenu.h"
#include "addon.h"
#include "theme.h"
#include "command.h"
#include "fatal.h"
#include "asserthandler.h"
#include "debughandler.h"
Expand All @@ -44,6 +45,59 @@
#include "hooker_macros.h"


/**
* #issue-305
*
* Fixes bug where the sidebar mouse wheel scrolling "error" sound
* can be heard at the main menu.
*
* @author: CCHyper
*/
DECLARE_PATCH(_Main_Window_Procedure_Scroll_Sidebar_Check_Patch)
{
GET_STACK_STATIC(UINT, wParam, esp, 0x14);
static bool _mouse_wheel_scolling;

/**
* The code before this patch checks for WM_MOUSEWHEEL.
*/

/**
* We are not currently playing a scenario, no need to execute this command.
*/
if (!bool_007E4040 && !bool_007E48FC) {
goto message_handler;
}

/**
* Are we currently executing a scroll command? This is required because
* the Main_Window_Procedure function runs at a Windows level.
*/
if (_mouse_wheel_scolling) {
goto message_handler;
}

_mouse_wheel_scolling = true;

/**
* Execute the command based on the direction of the mouse wheel.
*/
if ((wParam & 0x80000000) == 0) {
CommandClass::Activate_From_Name("SidebarUp");
} else {
CommandClass::Activate_From_Name("SidebarDown");
}

_mouse_wheel_scolling = false;

executed:
JMP_REG(eax, 0x00685F9C);

message_handler:
JMP_REG(ecx, 0x00685FA0);
}


/**
* Reimplemention of Init_Secondary_Mixfiles()
*
Expand Down Expand Up @@ -563,4 +617,6 @@ void GameInit_Hooks()
Patch_Call(0x004E2991, &Addon_Enabled);
Patch_Call(0x004E86F5, &Addon_Enabled);
Patch_Call(0x004E8735, &Addon_Enabled);

Patch_Jump(0x00685F69, &_Main_Window_Procedure_Scroll_Sidebar_Check_Patch);
}

0 comments on commit 7912edd

Please sign in to comment.