Merge branch 'master' into ipconfig-delete-testing

This commit is contained in:
dmr authored and GitHub committed 2022-12-06 08:36:24 +07:00
commit 3fc0892945
4 files changed
+85 -74

No files matched your search

+9 -33
View File
@@ -156,56 +156,31 @@ static HWND mt6Hwnd;
typedef BOOL (WINAPI* ShowWindow_t)(HWND, int);
static ShowWindow_t pShowWindow;
// Hello Win32 my old friend...
typedef LRESULT (WINAPI* WindowProcedure_t)(HWND, UINT, WPARAM, LPARAM);
static WindowProcedure_t pMaxituneWndProc;
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)
{
if (!gotWindowSize)
{
displaySizeX = GetSystemMetrics(SM_CXSCREEN);
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);
mt6SetDisplayParams(hwnd);
gotWindowSize = TRUE;
}
if (msg == WM_LBUTTONDOWN ||
msg == WM_LBUTTONUP)
{
unsigned short mx = GET_X_LPARAM(lParam);
unsigned short my = GET_Y_LPARAM(lParam);
mt6SetTouchData(lParam, msg == WM_LBUTTONDOWN, false);
return 0;
}
//unsigned short trueMy = 768 - my;
float scaledMx = static_cast<float>(mx) / 1360.f;
float scaledMy = static_cast<float>(my) / 768.f;
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);
if (msg == WM_POINTERDOWN ||
msg == WM_POINTERUP)
{
mt6SetTouchData(lParam, msg == WM_POINTERDOWN, true);
return 0;
}
@@ -233,6 +208,7 @@ extern int* ffbOffset2;
extern int* ffbOffset3;
extern int* ffbOffset4;
static __int64(__fastcall* g_origMileageFix)(__int64);
static __int64 __fastcall MileageFix(__int64 a1)
+8 -32
View File
@@ -439,50 +439,26 @@ typedef LRESULT(WINAPI* WindowProcedure_t)(HWND, UINT, WPARAM, LPARAM);
static WindowProcedure_t pMaxituneWndProc;
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)
{
if (!gotWindowSize)
{
displaySizeX = GetSystemMetrics(SM_CXSCREEN);
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);
mt6SetDisplayParams(hwnd);
gotWindowSize = TRUE;
}
if (msg == WM_LBUTTONDOWN ||
msg == WM_LBUTTONUP)
{
unsigned short mx = GET_X_LPARAM(lParam);
unsigned short my = GET_Y_LPARAM(lParam);
mt6SetTouchData(lParam, msg == WM_LBUTTONDOWN, false);
return 0;
}
//unsigned short trueMy = 768 - my;
float scaledMx = static_cast<float>(mx) / 1360.f;
float scaledMy = static_cast<float>(my) / 768.f;
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);
if (msg == WM_POINTERDOWN ||
msg == WM_POINTERUP)
{
mt6SetTouchData(lParam, msg == WM_POINTERDOWN, true);
return 0;
}
+66 -8
View File
@@ -1,4 +1,6 @@
#include "MT6.h"
#include "MinHook.h"
#include <Windowsx.h>
#include <vector>
#define TS_PIPE_TIMEOUT 16
@@ -24,12 +26,51 @@ volatile unsigned short touchy = 0;
volatile BOOL touchpressed = 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)
{
touchx = x;
touchy = y;
unsigned short mx;
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;
}
}
@@ -156,9 +197,9 @@ DWORD mt6SerialTouchThread(HANDLE port)
memset(touchResp, 0, 5);
touchResp[0] = (char)0b11000000;
touchResp[1] = (touchx & 0b01111111);
touchResp[2] = ((touchx >> 8) & 0b01111111);
touchResp[2] = ((touchx >> 7) & 0b01111111);
touchResp[3] = (touchy & 0b01111111);
touchResp[4] = ((touchy >> 8) & 0b01111111);
touchResp[4] = ((touchy >> 7) & 0b01111111);
mt6WritePort(port, touchResp, 5);
}
else
@@ -169,9 +210,9 @@ DWORD mt6SerialTouchThread(HANDLE port)
memset(touchResp, 0, 5);
touchResp[0] = (char)0b10000000;
touchResp[1] = (touchx & 0b01111111);
touchResp[2] = ((touchx >> 8) & 0b01111111);
touchResp[2] = ((touchx >> 7) & 0b01111111);
touchResp[3] = (touchy & 0b01111111);
touchResp[4] = ((touchy >> 8) & 0b01111111);
touchResp[4] = ((touchy >> 7) & 0b01111111);
mt6WritePort(port, touchResp, 5);
touchlift = false;
}
@@ -208,7 +249,7 @@ DWORD mt6SerialNamedPipeServer(LPVOID _)
if (connected)
{
puts("client connection established, spawning thread");
DWORD tid = 0;
CreateThread(NULL, 0, mt6SerialTouchThread, pipe, 0, &tid);
printf("thread spawned, tid=%d\n", tid);
@@ -217,8 +258,25 @@ DWORD mt6SerialNamedPipeServer(LPVOID _)
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()
{
// 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
CreateThread(NULL, 0, mt6SerialNamedPipeServer, NULL, 0, NULL);
Sleep(20);
+2 -1
View File
@@ -3,5 +3,6 @@
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();