Skip to content
Open
27 changes: 25 additions & 2 deletions src/ProtoInput/ProtoInputHooks/FakeCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ FakeCursor FakeCursor::state{};
int FakeCursor::Showmessage = 0;
bool FakeCursor::DrawFakeCursorFix;

int monitorscale; //100 //125 //150 //200 //300 //400

//now scales if scale changes on HwndSelector::UpdateWindowBounds()
int cursorWidth = 40; //was constant originally
int cursorHeight = 40;//was constant originally

void FakeCursor::setmonitorscale(int scale)
{
if (FakeCursor::DrawFakeCursorFix || scale < 25) //another type of scaling there
return;

cursorWidth = 0;
cursorHeight = 0;
//25 scale = 10.
// 40 size on 100% scale // 80 size on 200
while (scale >= 25)
{
scale -= 25;
cursorWidth += 10;
cursorHeight += 10;
}
}

LRESULT WINAPI FakeCursorWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Expand Down Expand Up @@ -355,7 +377,7 @@ void FakeCursor::DrawPointsandMessages() //only on Xtranslate
}
void FakeCursor::DrawCursor()
{

POINT pos = { FakeMouseKeyboard::GetMouseState().x,FakeMouseKeyboard::GetMouseState().y };

if (XinputHook::TranslateMKBtoXinput)
Expand Down Expand Up @@ -605,6 +627,7 @@ void FakeCursor::StartInternal()
if (!RegisterClass(&wc))
{
fprintf(stderr, "Failed to open fake cursor window\n");
MessageBoxA(NULL, "FakeCursor failed RegisterClass. Cursor drawing not possible", "Protoinput Error", MB_OK);
}
else
{
Expand All @@ -625,7 +648,7 @@ void FakeCursor::StartInternal()

// ShowWindow(pointerWindow, SW_SHOWDEFAULT);
// UpdateWindow(pointerWindow);
EnableDisableFakeCursor(drawingEnabled);
//EnableDisableFakeCursor(drawingEnabled);

// Over every screen
EnumDisplayMonitors(nullptr, nullptr, &EnumWindowsProc, 0);
Expand Down
6 changes: 4 additions & 2 deletions src/ProtoInput/ProtoInputHooks/FakeCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ namespace Proto
// DrawFakeCursorFix. cursor offset scan and cursor size fix
int cursoroffsetx, cursoroffsety;
int offsetSET = 0; //0:sizing 1:scanning 2:done, only drawing until cursor change, or nochange
int cursorWidth = 40; //was constant
int cursorHeight = 40;//was constant
bool nochange = false; //if normal offset was found at first then assume all cursors got same offset
HCURSOR oldhCursor = NULL;
POINT OldTestpos = { 0,0 };
Expand Down Expand Up @@ -57,12 +55,16 @@ namespace Proto
public:
static FakeCursor state;
static bool DrawFakeCursorFix;
static void setmonitorscale(int scale);

void StartInternal();

void StartDrawLoopInternal();
void UpdatePointerWindowLoopInternal(); // Checks the selected window dimensions.
void GetWindowDimensions(HWND hWnd); // For pointerWindow

static int Showmessage;

static bool& GetToggleVisilbityShorcutEnabled()
{
return state.toggleVisilbityShorcutEnabled;
Expand Down
6 changes: 2 additions & 4 deletions src/ProtoInput/ProtoInputHooks/FakeMouseKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Proto

FakeMouseState FakeMouseKeyboard::mouseState{};
FakeKeyboardState FakeMouseKeyboard::keyboardState{};
bool FakeMouseKeyboard::CallgameWindowLLKBHooks = false;
bool FakeMouseKeyboard::CallgameWindowLLMouseHooks = false;
bool FakeMouseKeyboard::PutMouseInsideWindow = false;
bool FakeMouseKeyboard::DefaultTopLeftMouseBounds = false;
bool FakeMouseKeyboard::DefaultBottomRightMouseBounds = false;
Expand Down Expand Up @@ -90,7 +88,7 @@ void FakeMouseKeyboard::AddMouseDelta(int dx, int dy)
}
}

if (FakeMouseKeyboard::CallgameWindowLLMouseHooks && SetWindowsHookHook::gameshookcallLLMouse != nullptr) //directly call HHOOK callback in game?
if (SetWindowsHookHook::LLMousehooked && SetWindowsHookHook::gameshookcallLLMouse != nullptr) //directly call HHOOK callback in game?
{
SetWindowsHookHook::FireFakeLLMouseMove(mouseState.x, mouseState.y);
}
Expand Down Expand Up @@ -210,7 +208,7 @@ void FakeMouseKeyboard::ReceivedKeyPressOrRelease(int vkey, bool pressed)
keyboardState.asyncKeysState[vkey] = true;
}

if (FakeMouseKeyboard::CallgameWindowLLKBHooks && SetWindowsHookHook::gameshookcallLLKB != nullptr) //directly call HHOOK callback in game?
if (SetWindowsHookHook::LLKBhooked && SetWindowsHookHook::gameshookcallLLKB != nullptr) //directly call HHOOK callback in game?
{
SetWindowsHookHook::FireFakeLLKeyboardEvent(vkey, pressed);
}
Expand Down
3 changes: 0 additions & 3 deletions src/ProtoInput/ProtoInputHooks/FakeMouseKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class FakeMouseKeyboard
static void AddMouseDelta(int dx, int dy);
static void SetMousePos(int x, int y);

static bool CallgameWindowLLKBHooks;
static bool CallgameWindowLLMouseHooks;

static void SetClipCursor(int clientLeft, int clientTop, int clientRight, int clientBottom);
static void RemoveClipCursor();

Expand Down
38 changes: 33 additions & 5 deletions src/ProtoInput/ProtoInputHooks/FocusMessageLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <cstdio>
#include "HwndSelector.h"
#include "GetKeyboardStateHook.h"
#include "SetWindowsHookHook.h"

namespace Proto
{
Expand All @@ -27,11 +28,38 @@ DWORD WINAPI LoopThread(LPVOID lpParameter)
const HWND hwnd = (HWND)HwndSelector::GetSelectedHwnd();
if (hwnd != nullptr)
{
if (FocusMessageLoop::messagesToSend.wm_activate) PostMessageW(hwnd, WM_ACTIVATE, WA_CLICKACTIVE, 0);
if (FocusMessageLoop::messagesToSend.wm_activateapp) PostMessageW(hwnd, WM_ACTIVATEAPP, TRUE, 0);
if (FocusMessageLoop::messagesToSend.wm_ncactivate) PostMessageW(hwnd, WM_NCACTIVATE, TRUE, 0);
if (FocusMessageLoop::messagesToSend.wm_setfocus) PostMessageW(hwnd, WM_SETFOCUS, 0, 0);
if (FocusMessageLoop::messagesToSend.wm_mouseactivate) PostMessageW(hwnd, WM_MOUSEACTIVATE, HwndSelector::GetSelectedHwnd(), 1);
if (FocusMessageLoop::messagesToSend.wm_activate)
{
PostMessageW(hwnd, WM_ACTIVATE, WA_CLICKACTIVE, 0);
if (SetWindowsHookHook::Messagehooked && SetWindowsHookHook::gameshookcallMessage != nullptr)
SetWindowsHookHook::FireFakeGetMessage(WM_ACTIVATE, WA_CLICKACTIVE, 0);
}
if (FocusMessageLoop::messagesToSend.wm_activateapp)
{
PostMessageW(hwnd, WM_ACTIVATEAPP, TRUE, 0);
if (SetWindowsHookHook::Messagehooked && SetWindowsHookHook::gameshookcallMessage != nullptr)
SetWindowsHookHook::FireFakeGetMessage(WM_ACTIVATEAPP, TRUE, 0);
}
if (FocusMessageLoop::messagesToSend.wm_ncactivate)
{
PostMessageW(hwnd, WM_NCACTIVATE, TRUE, 0);
if (SetWindowsHookHook::Messagehooked && SetWindowsHookHook::gameshookcallMessage != nullptr)
SetWindowsHookHook::FireFakeGetMessage(WM_NCACTIVATE, TRUE, 0);
}

if (FocusMessageLoop::messagesToSend.wm_setfocus)
{
PostMessageW(hwnd, WM_SETFOCUS, 0, 0);
if (SetWindowsHookHook::Messagehooked && SetWindowsHookHook::gameshookcallMessage != nullptr)
SetWindowsHookHook::FireFakeGetMessage(WM_SETFOCUS, 0, 0);
}

if (FocusMessageLoop::messagesToSend.wm_mouseactivate)
{
PostMessageW(hwnd, WM_MOUSEACTIVATE, HwndSelector::GetSelectedHwnd(), 1);
if (SetWindowsHookHook::Messagehooked && SetWindowsHookHook::gameshookcallMessage != nullptr)
SetWindowsHookHook::FireFakeGetMessage(WM_MOUSEACTIVATE, HwndSelector::GetSelectedHwnd(), 1);
}

Sleep(FocusMessageLoop::sleepMilliseconds);
}
Expand Down
14 changes: 8 additions & 6 deletions src/ProtoInput/ProtoInputHooks/GetCursorPosHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ BOOL WINAPI Hook_GetCursorPos(LPPOINT lpPoint)
{
if (lpPoint)
{
if (!XinputHook::TranslateMKBtoXinput)
if (XinputHook::TranslateMKBtoXinput)
{
const auto& state = FakeMouseKeyboard::GetMouseState();
lpPoint->x = state.x;
lpPoint->y = state.y;
lpPoint->x = SetCursorPosHook::mousesethere.x;
lpPoint->y = SetCursorPosHook::mousesethere.y;

}
else
{
lpPoint->x = SetCursorPosHook::mousesethere.x;
lpPoint->y = SetCursorPosHook::mousesethere.y;
const auto& state = FakeMouseKeyboard::GetMouseState();
lpPoint->x = state.x;
lpPoint->y = state.y;
}

//any scaling?
Expand All @@ -31,6 +32,7 @@ BOOL WINAPI Hook_GetCursorPos(LPPOINT lpPoint)
lpPoint->x = clientPos.x;
lpPoint->y = clientPos.y;
ClientToScreen((HWND)HwndSelector::GetSelectedHwnd(), lpPoint);

}

return true;
Expand Down
42 changes: 22 additions & 20 deletions src/ProtoInput/ProtoInputHooks/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ void RawInputMenu()
ImGui::Checkbox("Send mouse wheel messages", &RawInput::rawInputState.sendMouseWheelMessages);
ImGui::Checkbox("Send keyboard button messages", &RawInput::rawInputState.sendKeyboardPressMessages);
ImGui::Checkbox("Send mouse double click messages", &RawInput::rawInputState.sendMouseDblClkMessages);
ImGui::Checkbox("Send Messages to Subwindows", &RawInput::MessageAllWindows);

ImGui::Separator();

Expand Down Expand Up @@ -924,21 +925,21 @@ static void InfoMenu()

void RenderImgui()
{
// ImGui::ShowDemoWindow();
// return;
// ImGui::ShowDemoWindow();
// return;
const auto displaySize = ImGui::GetIO().DisplaySize;

ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(displaySize.x, displaySize.y), ImGuiCond_Always);

if (ImGui::Begin("Main", nullptr,
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoCollapse |
//ImGuiWindowFlags_NoBackground |
// ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoBringToFrontOnFocus
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoCollapse |
//ImGuiWindowFlags_NoBackground |
// ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoBringToFrontOnFocus
))
{

Expand All @@ -951,7 +952,7 @@ void RenderImgui()
ImGui::Begin("Hooks/Filter", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar);
const auto hooksWindowSize = ImVec2(ImGui::GetWindowSize().x, mainWindowSize.y);
ImGui::SetWindowSize(hooksWindowSize);

if (ImGui::BeginTabBar("Tabs"))
{
if (ImGui::BeginTabItem("Hooks"))
Expand All @@ -960,7 +961,7 @@ void RenderImgui()
ImGui::EndTabItem();
}
if (RawInput::TranslateXinputtoMKB || XinputHook::TranslateMKBtoXinput)
{
{
if (ImGui::BeginTabItem("Translation options"))
{
XTranslateMenu();
Expand All @@ -978,13 +979,13 @@ void RenderImgui()
{
ImGui::PushID(1337);
ImGui::PushStyleColor(ImGuiCol_Text,
(ImVec4)ImColor::HSV(35.0f / 255.0f, 0.9f, 0.9f)
(ImVec4)ImColor::HSV(35.0f / 255.0f, 0.9f, 0.9f)
);
ImGui::TextWrapped("Warning: Message Filter hook is disabled.\nMessage filtering/blocking will not work!");
ImGui::PopStyleColor(1);
ImGui::PopID();
}

MessageFilterHook::FilterGui();

ImGui::EndTabItem();
Expand All @@ -995,13 +996,13 @@ void RenderImgui()
{
ImGui::PushID(1337);
ImGui::PushStyleColor(ImGuiCol_Text,
(ImVec4)ImColor::HSV(35.0f / 255.0f, 0.9f, 0.9f)
(ImVec4)ImColor::HSV(35.0f / 255.0f, 0.9f, 0.9f)
);
ImGui::TextWrapped("Warning: Message Filter hook is disabled.\nMessage filtering/blocking will not work!");
ImGui::PopStyleColor(1);
ImGui::PopID();
}

MessageList::ShowUI();
ImGui::EndTabItem();
}
Expand All @@ -1011,14 +1012,14 @@ void RenderImgui()
}
ImGui::EndTabBar();
}

ImGui::End();


ImGui::SetNextWindowPos(ImVec2(hooksWindowSize.x, 0), ImGuiCond_Always);
ImGui::SetNextWindowSizeConstraints(ImVec2(200, displaySize.y), ImVec2(displaySize.x - 200, displaySize.y));
ImGui::SetNextWindowSize(ImVec2(displaySize.x - hooksWindowSize.x, 0.0f), ImGuiCond_Always);

ImGui::Begin("Other", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
const auto otherWindowSize = ImVec2(ImGui::GetWindowSize().x, mainWindowSize.y);
ImGui::SetWindowSize(otherWindowSize);
Expand All @@ -1028,12 +1029,12 @@ void RenderImgui()
{
InfoMenu();
}

if (ImGui::CollapsingHeader("Controls", ImGuiTreeNodeFlags_DefaultOpen)) // ImGuiTreeNodeFlags_Leaf
{
ControlsMenu();
}

if (ImGui::CollapsingHeader("Raw Input", ImGuiTreeNodeFlags_DefaultOpen))
{
RawInputMenu();
Expand All @@ -1053,6 +1054,7 @@ void RenderImgui()

}
ImGui::End();

}
DWORD WINAPI GuiThread(LPVOID lpParameter)
{
Expand Down
Loading