1
0
mirror of synced 2024-11-23 22:41:00 +01:00

steal pipe server from project asakura

This commit is contained in:
doomertheboomer 2023-07-27 14:41:50 +07:00
parent cdcbd2585a
commit 0648ec7ab2
4 changed files with 152 additions and 39 deletions

View File

@ -6,7 +6,8 @@
bool kinectRunning = false;
bool kinectStarted = false;
extern VRFoot VR_FOOTS[2];
VRFoot feet[16];
typedef struct {
union {
@ -158,6 +159,43 @@ inline DWORD scale_double_to_width(double val) {
return static_cast<DWORD>(val * 1696);
}
DWORD depthrushWritePort(HANDLE port, char data[], unsigned length)
{
DWORD numWritten = 0;
OVERLAPPED ol = { 0, 0, 0, 0, NULL };
ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
BOOL status = WriteFile(port, data, length, &numWritten, &ol);
DWORD xferBytes = 0;
if (!status)
{
switch (GetLastError())
{
case ERROR_SUCCESS:
break;
case ERROR_IO_PENDING:
// Wait for 16ms
if (WaitForSingleObject(ol.hEvent, 16) == WAIT_OBJECT_0)
{
status = GetOverlappedResult(port, &ol, &xferBytes, FALSE);
}
else
{
CancelIo(port);
}
break;
}
}
CloseHandle(ol.hEvent);
FlushFileBuffers(port);
return numWritten;
}
void fire_touches(drs_touch_t* events, size_t event_count) {
// check callback first
@ -209,9 +247,107 @@ void fire_touches(drs_touch_t* events, size_t event_count) {
touch_callback(&dev, game_touches.get(), (int)event_count, 0, user_data);
}
VRFoot feet[11];
unsigned long holdcounters[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
unsigned long releasecounters[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
DWORD depthrushTouchThread(HANDLE port)
{
char fileBuf[32];
puts("starting serial touch thread");
DWORD times = 0;
for (;;)
{
DWORD bytesRead = 0;
memset(fileBuf, 0, 32);
OVERLAPPED ol = { 0, 0, 0, 0, NULL };
BOOL ret = 0;
ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
BOOL rfResult = ReadFile(port, fileBuf, 32, &bytesRead, &ol);
DWORD xferBytes = 0;
if (!rfResult)
{
switch (GetLastError())
{
case ERROR_SUCCESS:
break;
case ERROR_IO_PENDING:
// Wait for 16ms
if (WaitForSingleObject(ol.hEvent, 16) == WAIT_OBJECT_0)
{
rfResult = GetOverlappedResult(port, &ol, &xferBytes, FALSE);
}
else
{
CancelIo(port);
}
break;
}
}
CloseHandle(ol.hEvent);
if (xferBytes > 0)
{
printf("IN: xferred %d bytes\n", xferBytes);
}
if (bytesRead > 0)
{
printf("Read %d bytes: ", bytesRead);
for (unsigned x = 0; x < bytesRead; x++)
{
printf("%02X ", fileBuf[x]);
}
printf("\n");
BOOL packetRecognised = FALSE;
if (!packetRecognised)
{
puts("unknown packet, responding with OK");
depthrushWritePort(port, (char*)"1", 1);
}
}
Sleep(16);
}
}
DWORD depthrushNamedPipeServer(LPVOID _)
{
puts("init depthrush pipe server");
HANDLE pipe = CreateNamedPipeW(
L"\\\\.\\pipe\\depthrush-api",
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
255,
255,
25,
NULL
);
if (!pipe)
{
puts("named pipe creation failed!");
return 1;
}
BOOL connected = ConnectNamedPipe(pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
if (connected)
{
puts("client connection established, spawning thread");
DWORD tid = 0;
CreateThread(NULL, 0, depthrushTouchThread, pipe, 0, &tid);
printf("thread spawned, tid=%d\n", tid);
}
return 0;
}
void start_kinect() {
@ -308,6 +444,7 @@ void hookDancepad() {
MH_CreateHookApi(L"TouchSDKDll.dll", "?InitTouch@TouchSDK@@QEAAHPEAU_DeviceInfo@@HP6AXU2@PEBU_TouchPointData@@HHPEBX@ZP6AX1_N3@ZPEAX@Z", TouchSDK_InitTouch, NULL);
MH_EnableHook(MH_ALL_HOOKS);
CreateThread(NULL, 0, depthrushNamedPipeServer, NULL, 0, NULL);
start_kinect();
}

View File

@ -8,10 +8,10 @@ enum DRS_TOUCH_TYPE {
typedef struct drs_touch_t {
int type = DRS_UP;
int id = 0;
double x = 0.0; //x = pixelX/1920
double y = 0.0; //y = pixelY/1920
double width = 1; //width = pixelWidth/1920
double height = 1; //height = pixelHeight/1920
double x = 0.0; // x = pixelX/1920
double y = 0.0; // y = pixelY/1920
double width = 1; // width = pixelWidth/1920
double height = 1; // height = pixelHeight/1920
};
struct VRFoot {
@ -21,20 +21,12 @@ struct VRFoot {
float size_base = 0.05;
float size_scale = 0.1;
float height = 3;
//linalg::aliases::float4 rotation {0, 0, 0, 1};
drs_touch_t event{};
//linalg::aliases::float3 to_world(linalg::aliases::float3 pos);
bool touching = false;
};
//extern char DRS_TAPELED[38 * 49][3];
//extern linalg::aliases::float3 VR_SCALE;
//extern linalg::aliases::float3 VR_OFFSET;
//extern float VR_ROTATION;
//extern VRFoot VR_FOOTS[2];
void fire_touches(drs_touch_t* events, size_t event_count);
void start_kinect();
void hookDancepad();

View File

@ -1,5 +1,6 @@
#pragma once
#include <Windows.h>
#include <Windowsx.h>
#include <libloaderapi.h>
#include <winnt.h>
#include <iostream>

View File

@ -23,30 +23,13 @@ static int returnFalse() {
}
bool init = false;
/*
DWORD WINAPI MainThread(LPVOID lpReserved)
{
bool init_hook = false;
do
{
} while (!init_hook);
return TRUE;
}
*/
BOOL WINAPI DllMain(HMODULE hMod, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hMod);
imageBase = (uintptr_t)GetModuleHandleA(0);
hookDancepad();
DisableThreadLibraryCalls(hMod);
imageBase = (uintptr_t)GetModuleHandleA(0);
break;
}
return TRUE;
hookDancepad(); // drs.cpp
return true;
}