Skip to content

Commit

Permalink
moved the mouse emulation feature for addressing MSFS touch interacti…
Browse files Browse the repository at this point in the history
…on issues from core.dll to hook.dll
  • Loading branch information
opiopan committed Nov 30, 2024
1 parent 831283d commit cdab1af
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 67 deletions.
4 changes: 3 additions & 1 deletion src/core/capturedwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ CapturedWindow::~CapturedWindow(){
void CapturedWindow::attach_window(HWND hwnd){
if (!this->hwnd){
this->hwnd = hwnd;
hookdll_capture(hwnd, omit_system_region);
DWORD option = omit_system_region ? CAPTURE_OPT_HIDE_SYSTEM_REGION : 0;
option |= fix_touch_issue ? CAPTURE_OPT_MODIFY_TOUCH : 0;
hookdll_capture(hwnd, option);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ copy $(SolutionDir)..\modules\vJoySDK\SDK\lib\amd64\vJoyInterface.dll $(TargetDi
<ClInclude Include="mappercore.h" />
<ClInclude Include="mapperplugin.h" />
<ClInclude Include="mobiflight_wasm.h" />
<ClInclude Include="mouseemu.h" />
<ClInclude Include="option.h" />
<ClInclude Include="plugin.h" />
<ClInclude Include="pluginapi.h" />
Expand All @@ -243,6 +242,7 @@ copy $(SolutionDir)..\modules\vJoySDK\SDK\lib\amd64\vJoyInterface.dll $(TargetDi
<ClInclude Include="windowcapture.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\hook\mouseemu.cpp" />
<ClCompile Include="action.cpp" />
<ClCompile Include="builtinDevices\dinputdev.cpp" />
<ClCompile Include="builtinDevices\simhid.cpp" />
Expand All @@ -263,7 +263,6 @@ copy $(SolutionDir)..\modules\vJoySDK\SDK\lib\amd64\vJoyInterface.dll $(TargetDi
<ClCompile Include="keyseq.cpp" />
<ClCompile Include="mappercore.cpp" />
<ClCompile Include="mobiflight_wasm.cpp" />
<ClCompile Include="mouseemu.cpp" />
<ClCompile Include="option.cpp" />
<ClCompile Include="plugin.cpp" />
<ClCompile Include="pluginapi.cpp" />
Expand Down
9 changes: 3 additions & 6 deletions src/core/core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
<ClInclude Include="keyseq.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="mouseemu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="option.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -194,9 +191,6 @@
<ClCompile Include="keyseq.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mouseemu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="option.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -212,6 +206,9 @@
<ClCompile Include="windowcapture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\hook\mouseemu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
8 changes: 5 additions & 3 deletions src/core/simhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "simhost.h"
#include "fs2020.h"
#include "dcs.h"
#include "hookdll.h"

static const char *simtype_dict[] = {"msfs", "dcs"};

Expand Down Expand Up @@ -67,9 +68,10 @@ SimHostManager::SimHostManager(MapperEngine& engine, uint64_t event_changeAircra
}
}
}
mapper_EngineInstance()->getViewportManager()->get_mouse_emulator().set_window_for_recovery(
activeSim < 0 ? 0 : simulators.at(activeSim)->getRepresentativeWindow(),
activeSim < 0 ? mouse_emu::recovery_type::none : simulators.at(activeSim)->getRecoveryType());
auto hwnd = activeSim < 0 ? 0 : simulators.at(activeSim)->getRepresentativeWindow();
auto option = activeSim < 0 ? mouse_emu::recovery_type::none : simulators.at(activeSim)->getRecoveryType();
mapper_EngineInstance()->getViewportManager()->get_mouse_emulator().set_window_for_recovery(hwnd, option);
hookdll_setWindowForRecovery(hwnd, static_cast<DWORD>(option));

lock.unlock();
if (activeSim != oldActiveSim){
Expand Down
34 changes: 3 additions & 31 deletions src/core/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ namespace view_utils{
// Low level mouse hook
// This funciton avoids several problems to use pop out windows of FS2020 with touch display.
// The all mouse messages generated touch action on the captured windows will be droped by
// this hook procedure. On the other hand, new other mouse messages wich can be handled by
// FS2020 correctly will be generated on the other thread instead of the original mouse
// messages.
// this hook procedure. On the other hand, new mouse messages wich can be handled by FS2002
// correctly will be generated by fsmapperhook.dll instead of the original mouse messages.
// The codes which generate new mouse messages are found in src/hook/hookdll.cpp
//============================================================================================
static HHOOK hookHandle = 0;

Expand All @@ -197,34 +197,6 @@ static LRESULT CALLBACK mouseHookProc(int nCode, WPARAM wParam, LPARAM lParam){
View::CapturedWindowAttributes captured_window;
if (the_manager->findCapturedWindow({IntPoint{mouse->pt.x, mouse->pt.y}}, captured_window)){
if ((mouse->dwExtraInfo & touch_mask) == touch_signature && captured_window.need_to_avoid_touch_probrems){
auto now = mouse_emu::clock::now();
if (wParam == WM_LBUTTONDOWN){
mouse_log("down", mouse->pt.x, mouse->pt.y);
if (in_down_state){
auto target_time = last_ops_time + delay_up;
the_manager->get_mouse_emulator().emulate(mouse_emu::event::up, last_down_point.x, last_down_point.y, target_time);
now = max(target_time, now);
}
the_manager->get_mouse_emulator().emulate(mouse_emu::event::move, mouse->pt.x, mouse->pt.y, now);
in_down_state = true;
last_down_point = mouse->pt;
last_ops_time = max(last_ops_time + delay_down, now + delay_down);
the_manager->get_mouse_emulator().emulate(mouse_emu::event::down, mouse->pt.x, mouse->pt.y, last_ops_time);
}else if (wParam == WM_LBUTTONUP){
mouse_log("up", mouse->pt.x, mouse->pt.y);
if (!in_down_state){
last_down_point = mouse->pt;
last_ops_time = last_ops_time + delay_down;
the_manager->get_mouse_emulator().emulate(mouse_emu::event::down, mouse->pt.x, mouse->pt.y, last_ops_time);
}
in_down_state = false;
last_ops_time = max(now + delay_up, last_ops_time + delay_up);
the_manager->get_mouse_emulator().emulate(mouse_emu::event::up, mouse->pt.x, mouse->pt.y, last_ops_time);
}else if (wParam == WM_MOUSEMOVE){
mouse_log("move", mouse->pt.x, mouse->pt.y);
last_ops_time = max(last_ops_time, now);
the_manager->get_mouse_emulator().emulate(mouse_emu::event::move, mouse->pt.x, mouse->pt.y, last_ops_time);
}
return 1;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/hook/hook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)core;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
Expand All @@ -154,7 +154,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)core;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
Expand All @@ -174,10 +174,12 @@
<ItemGroup>
<ClCompile Include="apihook.cpp" />
<ClCompile Include="hookdll.cpp" />
<ClCompile Include="mouseemu.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="apihook.h" />
<ClInclude Include="hookdll.h" />
<ClInclude Include="mouseemu.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/hook/hook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ClCompile Include="apihook.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mouseemu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="apihook.h">
Expand All @@ -32,6 +35,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="mouseemu.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc">
Expand Down
Loading

0 comments on commit cdab1af

Please sign in to comment.