Merge pull request #8 from EmiMidnight/master
improve and refactor wmmt touch emu
This commit is contained in:
commit
41f5e6de06
@ -167,56 +167,31 @@ static HWND mt6Hwnd;
|
|||||||
typedef BOOL (WINAPI* ShowWindow_t)(HWND, int);
|
typedef BOOL (WINAPI* ShowWindow_t)(HWND, int);
|
||||||
static ShowWindow_t pShowWindow;
|
static ShowWindow_t pShowWindow;
|
||||||
|
|
||||||
|
|
||||||
// Hello Win32 my old friend...
|
// Hello Win32 my old friend...
|
||||||
typedef LRESULT (WINAPI* WindowProcedure_t)(HWND, UINT, WPARAM, LPARAM);
|
typedef LRESULT (WINAPI* WindowProcedure_t)(HWND, UINT, WPARAM, LPARAM);
|
||||||
static WindowProcedure_t pMaxituneWndProc;
|
static WindowProcedure_t pMaxituneWndProc;
|
||||||
|
|
||||||
static BOOL gotWindowSize = FALSE;
|
static BOOL gotWindowSize = FALSE;
|
||||||
static unsigned displaySizeX = 0;
|
|
||||||
static unsigned displaySizeY = 0;
|
|
||||||
static float scaleFactorX = 0.0f;
|
|
||||||
static float scaleFactorY = 0.0f;
|
|
||||||
|
|
||||||
static LRESULT Hook_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
static LRESULT Hook_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (!gotWindowSize)
|
if (!gotWindowSize)
|
||||||
{
|
{
|
||||||
displaySizeX = GetSystemMetrics(SM_CXSCREEN);
|
mt6SetDisplayParams(hwnd);
|
||||||
displaySizeY = GetSystemMetrics(SM_CYSCREEN);
|
|
||||||
scaleFactorX = static_cast<float>(displaySizeX) / 1360.0f;
|
|
||||||
scaleFactorY = static_cast<float>(displaySizeY) / 768.0f;
|
|
||||||
printf("display is %dx%d (scale factor of %f, %f)\n", displaySizeX, displaySizeY, scaleFactorX, scaleFactorY);
|
|
||||||
gotWindowSize = TRUE;
|
gotWindowSize = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == WM_LBUTTONDOWN ||
|
if (msg == WM_LBUTTONDOWN ||
|
||||||
msg == WM_LBUTTONUP)
|
msg == WM_LBUTTONUP)
|
||||||
{
|
{
|
||||||
unsigned short mx = GET_X_LPARAM(lParam);
|
mt6SetTouchData(lParam, msg == WM_LBUTTONDOWN, false);
|
||||||
unsigned short my = GET_Y_LPARAM(lParam);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//unsigned short trueMy = 768 - my;
|
if (msg == WM_POINTERDOWN ||
|
||||||
|
msg == WM_POINTERUP)
|
||||||
float scaledMx = static_cast<float>(mx) / 1360.f;
|
{
|
||||||
float scaledMy = static_cast<float>(my) / 768.f;
|
mt6SetTouchData(lParam, msg == WM_POINTERDOWN, true);
|
||||||
|
|
||||||
scaledMy = 1.0f - scaledMy;
|
|
||||||
|
|
||||||
scaledMx *= scaleFactorX;
|
|
||||||
scaledMy *= scaleFactorY;
|
|
||||||
|
|
||||||
unsigned short trueMx = static_cast<int>(scaledMx * 16383.0f);
|
|
||||||
unsigned short trueMy = static_cast<int>(scaledMy * 16383.0f);
|
|
||||||
trueMy += 9500; // Cheap hack, todo do the math better!!
|
|
||||||
|
|
||||||
//mx *= (16383 / 1360);
|
|
||||||
//trueMy *= (16383 / 1360);
|
|
||||||
|
|
||||||
printf("%d %d\n", trueMx, trueMy);
|
|
||||||
mt6SetTouchParams(trueMx, trueMy, msg == WM_LBUTTONDOWN);
|
|
||||||
|
|
||||||
printf("MOUSE %s (%d, %d)\n", msg == WM_LBUTTONDOWN ? "DOWN" : "UP ", mx, my);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,9 +227,6 @@ static WsaStringToAddressA_t gWsaStringToAddressA;
|
|||||||
//#define ROUTER_IP "192.168.100.1"
|
//#define ROUTER_IP "192.168.100.1"
|
||||||
#define LOCALHOST "127.0.0.1"
|
#define LOCALHOST "127.0.0.1"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static INT WSAAPI Hook_WsaStringToAddressA(
|
static INT WSAAPI Hook_WsaStringToAddressA(
|
||||||
_In_ LPSTR AddressString,
|
_In_ LPSTR AddressString,
|
||||||
_In_ INT AddressFamily,
|
_In_ INT AddressFamily,
|
||||||
@ -527,7 +499,6 @@ static InitFunction Wmmt6Func([]()
|
|||||||
MH_CreateHookApi(L"kernel32", "OutputDebugStringA", Hook_OutputDebugStringA, NULL);
|
MH_CreateHookApi(L"kernel32", "OutputDebugStringA", Hook_OutputDebugStringA, NULL);
|
||||||
// CreateFile* hooks are in the JVS FILE
|
// CreateFile* hooks are in the JVS FILE
|
||||||
|
|
||||||
|
|
||||||
// Network hooks
|
// Network hooks
|
||||||
MH_CreateHookApi(L"Ws2_32", "WSAStringToAddressA", Hook_WsaStringToAddressA, reinterpret_cast<LPVOID*>(&gWsaStringToAddressA));
|
MH_CreateHookApi(L"Ws2_32", "WSAStringToAddressA", Hook_WsaStringToAddressA, reinterpret_cast<LPVOID*>(&gWsaStringToAddressA));
|
||||||
MH_CreateHookApi(L"Ws2_32", "getaddrinfo", Hook_getaddrinfo, reinterpret_cast<LPVOID*>(&ggetaddrinfo));
|
MH_CreateHookApi(L"Ws2_32", "getaddrinfo", Hook_getaddrinfo, reinterpret_cast<LPVOID*>(&ggetaddrinfo));
|
||||||
|
@ -450,50 +450,26 @@ typedef LRESULT(WINAPI* WindowProcedure_t)(HWND, UINT, WPARAM, LPARAM);
|
|||||||
static WindowProcedure_t pMaxituneWndProc;
|
static WindowProcedure_t pMaxituneWndProc;
|
||||||
|
|
||||||
static BOOL gotWindowSize = FALSE;
|
static BOOL gotWindowSize = FALSE;
|
||||||
static unsigned displaySizeX = 0;
|
|
||||||
static unsigned displaySizeY = 0;
|
|
||||||
static float scaleFactorX = 0.0f;
|
|
||||||
static float scaleFactorY = 0.0f;
|
|
||||||
|
|
||||||
static LRESULT Hook_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
static LRESULT Hook_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (!gotWindowSize)
|
if (!gotWindowSize)
|
||||||
{
|
{
|
||||||
displaySizeX = GetSystemMetrics(SM_CXSCREEN);
|
mt6SetDisplayParams(hwnd);
|
||||||
displaySizeY = GetSystemMetrics(SM_CYSCREEN);
|
|
||||||
scaleFactorX = static_cast<float>(displaySizeX) / 1360.0f;
|
|
||||||
scaleFactorY = static_cast<float>(displaySizeY) / 768.0f;
|
|
||||||
printf("display is %dx%d (scale factor of %f, %f)\n", displaySizeX, displaySizeY, scaleFactorX, scaleFactorY);
|
|
||||||
gotWindowSize = TRUE;
|
gotWindowSize = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == WM_LBUTTONDOWN ||
|
if (msg == WM_LBUTTONDOWN ||
|
||||||
msg == WM_LBUTTONUP)
|
msg == WM_LBUTTONUP)
|
||||||
{
|
{
|
||||||
unsigned short mx = GET_X_LPARAM(lParam);
|
mt6SetTouchData(lParam, msg == WM_LBUTTONDOWN, false);
|
||||||
unsigned short my = GET_Y_LPARAM(lParam);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//unsigned short trueMy = 768 - my;
|
if (msg == WM_POINTERDOWN ||
|
||||||
|
msg == WM_POINTERUP)
|
||||||
float scaledMx = static_cast<float>(mx) / 1360.f;
|
{
|
||||||
float scaledMy = static_cast<float>(my) / 768.f;
|
mt6SetTouchData(lParam, msg == WM_POINTERDOWN, true);
|
||||||
|
|
||||||
scaledMy = 1.0f - scaledMy;
|
|
||||||
|
|
||||||
scaledMx *= scaleFactorX;
|
|
||||||
scaledMy *= scaleFactorY;
|
|
||||||
|
|
||||||
unsigned short trueMx = static_cast<int>(scaledMx * 16383.0f);
|
|
||||||
unsigned short trueMy = static_cast<int>(scaledMy * 16383.0f);
|
|
||||||
trueMy += 9500; // Cheap hack, todo do the math better!!
|
|
||||||
|
|
||||||
//mx *= (16383 / 1360);
|
|
||||||
//trueMy *= (16383 / 1360);
|
|
||||||
|
|
||||||
printf("%d %d\n", trueMx, trueMy);
|
|
||||||
mt6SetTouchParams(trueMx, trueMy, msg == WM_LBUTTONDOWN);
|
|
||||||
|
|
||||||
printf("MOUSE %s (%d, %d)\n", msg == WM_LBUTTONDOWN ? "DOWN" : "UP ", mx, my);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "MT6.h"
|
#include "MT6.h"
|
||||||
|
#include "MinHook.h"
|
||||||
|
#include <Windowsx.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define TS_PIPE_TIMEOUT 16
|
#define TS_PIPE_TIMEOUT 16
|
||||||
@ -24,12 +26,51 @@ volatile unsigned short touchy = 0;
|
|||||||
volatile BOOL touchpressed = FALSE;
|
volatile BOOL touchpressed = FALSE;
|
||||||
volatile BOOL touchlift = FALSE;
|
volatile BOOL touchlift = FALSE;
|
||||||
|
|
||||||
void mt6SetTouchParams(unsigned short x, unsigned short y, BOOL down)
|
static unsigned displaySizeX = 0;
|
||||||
|
static unsigned displaySizeY = 0;
|
||||||
|
static float scaleFactorX = 0.0f;
|
||||||
|
static float scaleFactorY = 0.0f;
|
||||||
|
|
||||||
|
static HWND gameWindow;
|
||||||
|
|
||||||
|
typedef INT(WINAPI* GetSystemMetrics_t)(int);
|
||||||
|
static GetSystemMetrics_t pGetSystemMetrics;
|
||||||
|
|
||||||
|
// Telling wangan that the system res is 1360x768, aka stock game res
|
||||||
|
// This makes scaling the touch input across resolutions a breeze
|
||||||
|
int WINAPI hook_GetSystemMetrics(int nIndex)
|
||||||
|
{
|
||||||
|
if (nIndex == 0) {
|
||||||
|
return 1360;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nIndex == 1) {
|
||||||
|
return 768;
|
||||||
|
}
|
||||||
|
return pGetSystemMetrics(nIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mt6SetTouchData(LPARAM lParam, BOOL down, BOOL isTouchScreen)
|
||||||
{
|
{
|
||||||
if (bHasBooted)
|
if (bHasBooted)
|
||||||
{
|
{
|
||||||
touchx = x;
|
unsigned short mx;
|
||||||
touchy = y;
|
unsigned short my;
|
||||||
|
if (isTouchScreen) {
|
||||||
|
POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
||||||
|
ScreenToClient(gameWindow, &point);
|
||||||
|
mx = point.x;
|
||||||
|
my = point.y;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mx = GET_X_LPARAM(lParam);
|
||||||
|
my = GET_Y_LPARAM(lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Touchscreen y coordinates are inverted
|
||||||
|
my = displaySizeY - my;
|
||||||
|
touchx = static_cast<int>(mx * scaleFactorX);
|
||||||
|
touchy = static_cast<int>(my * scaleFactorY);
|
||||||
touchpressed = down;
|
touchpressed = down;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,9 +197,9 @@ DWORD mt6SerialTouchThread(HANDLE port)
|
|||||||
memset(touchResp, 0, 5);
|
memset(touchResp, 0, 5);
|
||||||
touchResp[0] = (char)0b11000000;
|
touchResp[0] = (char)0b11000000;
|
||||||
touchResp[1] = (touchx & 0b01111111);
|
touchResp[1] = (touchx & 0b01111111);
|
||||||
touchResp[2] = ((touchx >> 8) & 0b01111111);
|
touchResp[2] = ((touchx >> 7) & 0b01111111);
|
||||||
touchResp[3] = (touchy & 0b01111111);
|
touchResp[3] = (touchy & 0b01111111);
|
||||||
touchResp[4] = ((touchy >> 8) & 0b01111111);
|
touchResp[4] = ((touchy >> 7) & 0b01111111);
|
||||||
mt6WritePort(port, touchResp, 5);
|
mt6WritePort(port, touchResp, 5);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -169,9 +210,9 @@ DWORD mt6SerialTouchThread(HANDLE port)
|
|||||||
memset(touchResp, 0, 5);
|
memset(touchResp, 0, 5);
|
||||||
touchResp[0] = (char)0b10000000;
|
touchResp[0] = (char)0b10000000;
|
||||||
touchResp[1] = (touchx & 0b01111111);
|
touchResp[1] = (touchx & 0b01111111);
|
||||||
touchResp[2] = ((touchx >> 8) & 0b01111111);
|
touchResp[2] = ((touchx >> 7) & 0b01111111);
|
||||||
touchResp[3] = (touchy & 0b01111111);
|
touchResp[3] = (touchy & 0b01111111);
|
||||||
touchResp[4] = ((touchy >> 8) & 0b01111111);
|
touchResp[4] = ((touchy >> 7) & 0b01111111);
|
||||||
mt6WritePort(port, touchResp, 5);
|
mt6WritePort(port, touchResp, 5);
|
||||||
touchlift = false;
|
touchlift = false;
|
||||||
}
|
}
|
||||||
@ -217,8 +258,25 @@ DWORD mt6SerialNamedPipeServer(LPVOID _)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mt6SetDisplayParams(HWND hwnd) {
|
||||||
|
RECT rect;
|
||||||
|
GetClientRect(hwnd, &rect);
|
||||||
|
displaySizeX = rect.right;
|
||||||
|
displaySizeY = rect.bottom;
|
||||||
|
scaleFactorX = (float)16383 / displaySizeX;
|
||||||
|
scaleFactorY = (float)16383 / displaySizeY;
|
||||||
|
RegisterTouchWindow(hwnd, 0);
|
||||||
|
gameWindow = hwnd;
|
||||||
|
printf("display is %dx%d (scale factor of %f, %f)\n", displaySizeX, displaySizeY, scaleFactorX, scaleFactorY);
|
||||||
|
}
|
||||||
|
|
||||||
void mt6SerialTouchInit()
|
void mt6SerialTouchInit()
|
||||||
{
|
{
|
||||||
|
// System metrics hook to decouple game res from touchscreen res
|
||||||
|
MH_Initialize();
|
||||||
|
MH_CreateHookApi(L"user32", "GetSystemMetrics", hook_GetSystemMetrics, reinterpret_cast<LPVOID*>(&pGetSystemMetrics));
|
||||||
|
MH_EnableHook(MH_ALL_HOOKS);
|
||||||
|
|
||||||
// This is on another thread so we can wait a bit to make sure the pipe server is actually init'd
|
// This is on another thread so we can wait a bit to make sure the pipe server is actually init'd
|
||||||
CreateThread(NULL, 0, mt6SerialNamedPipeServer, NULL, 0, NULL);
|
CreateThread(NULL, 0, mt6SerialNamedPipeServer, NULL, 0, NULL);
|
||||||
Sleep(20);
|
Sleep(20);
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
|
|
||||||
static HANDLE touchDevice;
|
static HANDLE touchDevice;
|
||||||
|
|
||||||
void mt6SetTouchParams(unsigned short x, unsigned short y, BOOL down);
|
void mt6SetTouchData(LPARAM lParam, BOOL down, BOOL isTouchScreen);
|
||||||
|
void mt6SetDisplayParams(HWND hwnd);
|
||||||
void mt6SerialTouchInit();
|
void mt6SerialTouchInit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user