From 129361836f9043348f17e1a3fd3db0b60579db0b Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Thu, 20 Apr 2023 10:31:32 +0300 Subject: [PATCH] Add op_get_mouse_buttons --- src/mouse.cc | 17 +++++++++++------ src/mouse.h | 1 + src/sfall_opcodes.cc | 9 +++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mouse.cc b/src/mouse.cc index 09e4334..6e8a8bb 100644 --- a/src/mouse.cc +++ b/src/mouse.cc @@ -54,7 +54,7 @@ static unsigned char* _mouse_fptr = NULL; static double gMouseSensitivity = 1.0; // 0x51E2AC -static int gMouseButtonsState = 0; +static int last_buttons = 0; // 0x6AC790 static bool gCursorIsHidden; @@ -415,7 +415,7 @@ void _mouse_info() } x = 0; y = 0; - buttons = gMouseButtonsState; + buttons = last_buttons; } _mouse_simulate_input(x, y, buttons); @@ -447,7 +447,7 @@ void _mouse_simulate_input(int delta_x, int delta_y, int buttons) return; } - if (delta_x || delta_y || buttons != gMouseButtonsState) { + if (delta_x || delta_y || buttons != last_buttons) { if (gVcrState == 0) { if (_vcr_buffer_index == VCR_BUFFER_CAPACITY - 1) { vcrDump(); @@ -464,13 +464,13 @@ void _mouse_simulate_input(int delta_x, int delta_y, int buttons) _vcr_buffer_index++; } } else { - if (gMouseButtonsState == 0) { + if (last_buttons == 0) { if (!_mouse_idling) { _mouse_idle_start_time = getTicks(); _mouse_idling = 1; } - gMouseButtonsState = 0; + last_buttons = 0; _raw_buttons = 0; gMouseEvent = 0; @@ -479,7 +479,7 @@ void _mouse_simulate_input(int delta_x, int delta_y, int buttons) } _mouse_idling = 0; - gMouseButtonsState = buttons; + last_buttons = buttons; previousEvent = gMouseEvent; gMouseEvent = 0; @@ -703,4 +703,9 @@ void convertMouseWheelToArrowKey(int* keyCodePtr) } } +int mouse_get_last_buttons() +{ + return last_buttons; +} + } // namespace fallout diff --git a/src/mouse.h b/src/mouse.h index 6b091c5..667250f 100644 --- a/src/mouse.h +++ b/src/mouse.h @@ -52,6 +52,7 @@ void mouseGetPositionInWindow(int win, int* x, int* y); bool mouseHitTestInWindow(int win, int left, int top, int right, int bottom); void mouseGetWheel(int* x, int* y); void convertMouseWheelToArrowKey(int* keyCodePtr); +int mouse_get_last_buttons(); } // namespace fallout diff --git a/src/sfall_opcodes.cc b/src/sfall_opcodes.cc index f918d79..d21acb6 100644 --- a/src/sfall_opcodes.cc +++ b/src/sfall_opcodes.cc @@ -396,6 +396,14 @@ static void opGetMouseY(Program* program) programStackPushInteger(program, y); } +// get_mouse_buttons +static void op_get_mouse_buttons(Program* program) +{ + // CE: Implementation is slightly different - it does not handle middle + // mouse button. + programStackPushInteger(program, mouse_get_last_buttons()); +} + // get_screen_width static void opGetScreenWidth(Program* program) { @@ -540,6 +548,7 @@ void sfallOpcodesInit() interpreterRegisterOpcode(0x821A, opSetWeaponAmmoCount); interpreterRegisterOpcode(0x821C, opGetMouseX); interpreterRegisterOpcode(0x821D, opGetMouseY); + interpreterRegisterOpcode(0x821E, op_get_mouse_buttons); interpreterRegisterOpcode(0x8220, opGetScreenWidth); interpreterRegisterOpcode(0x8221, opGetScreenHeight); interpreterRegisterOpcode(0x8237, opParseInt);