beginnings of kinect support. uses sdk v1.7
This commit is contained in:
parent
0648ec7ab2
commit
f90e39bc33
@ -79,12 +79,12 @@
|
||||
<IncludePath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LibraryPath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files\Microsoft SDKs\Kinect\v1.7\lib\amd64;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>C:\Program Files\Microsoft SDKs\Kinect\v1.7\inc;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LibraryPath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files\Microsoft SDKs\Kinect\v1.7\lib\amd64;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>C:\Program Files\Microsoft SDKs\Kinect\v1.7\inc;C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -111,7 +111,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;Ws2_32.lib;Kinect10.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@ -149,7 +149,7 @@
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>d3d11.lib;dxgi.lib;Ws2_32.lib;Kinect10.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -159,43 +159,6 @@ 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
|
||||
@ -247,122 +210,76 @@ void fire_touches(drs_touch_t* events, size_t event_count) {
|
||||
touch_callback(&dev, game_touches.get(), (int)event_count, 0, user_data);
|
||||
}
|
||||
|
||||
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!");
|
||||
void pollKinect() {
|
||||
std::thread t([] {
|
||||
// initialize Kinect
|
||||
HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
|
||||
if (FAILED(hr)) {
|
||||
std::cout << "Failed to initialize Kinect." << std::endl;
|
||||
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);
|
||||
// open the skeleton stream
|
||||
HANDLE skeletonStream = nullptr;
|
||||
hr = NuiSkeletonTrackingEnable(nullptr, 0);
|
||||
if (FAILED(hr)) {
|
||||
std::cout << "Failed to open the skeleton stream." << std::endl;
|
||||
NuiShutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// main loop to read and process skeleton data
|
||||
NUI_SKELETON_FRAME skeletonFrame = { 0 };
|
||||
while (true) {
|
||||
// get the latest skeleton frame
|
||||
hr = NuiSkeletonGetNextFrame(0, &skeletonFrame);
|
||||
if (FAILED(hr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process each tracked skeleton
|
||||
for (int i = 0; i < NUI_SKELETON_COUNT; ++i) {
|
||||
if (skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED) {
|
||||
// get the position of both legs
|
||||
Vector4 leftLegPos = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_LEFT];
|
||||
Vector4 rightLegPos = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_RIGHT];
|
||||
|
||||
// print the coordinates of both legs
|
||||
std::cout << "Left Leg: X = " << leftLegPos.x << ", Y = " << leftLegPos.y << ", Z = " << leftLegPos.z << std::endl;
|
||||
std::cout << "Right Leg: X = " << rightLegPos.x << ", Y = " << rightLegPos.y << ", Z = " << rightLegPos.z << std::endl;
|
||||
|
||||
feet[1].event.x = leftLegPos.x;
|
||||
feet[1].event.y = 0.5;
|
||||
feet[2].event.x = rightLegPos.x;
|
||||
feet[2].event.y = 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up and exit
|
||||
NuiSkeletonTrackingDisable();
|
||||
NuiShutdown();
|
||||
return 0;
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
|
||||
void start_kinect() {
|
||||
void startInputSpam() {
|
||||
|
||||
if (kinectRunning) return;
|
||||
if (!kinectStarted) {
|
||||
kinectStarted = true;
|
||||
std::thread t([] {
|
||||
puts("starting kinect thread");
|
||||
|
||||
// temporarily hardcode both kinect feet to touching at size 0.1
|
||||
feet[1].touching = true;
|
||||
|
||||
feet[2].touching = true;
|
||||
|
||||
// main loop
|
||||
while (true) {
|
||||
|
||||
|
||||
// debug shift control to touch entire pad
|
||||
if (GetKeyState(VK_SHIFT) & 0x8000)
|
||||
{
|
||||
// hardcode debug foot details
|
||||
feet[0].id = 0;
|
||||
feet[0].index = 0;
|
||||
|
||||
@ -412,6 +329,101 @@ void start_kinect() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// left foot
|
||||
if (feet[1].touching)
|
||||
{
|
||||
feet[1].id = 1;
|
||||
feet[1].index = 1;
|
||||
feet[1].event.id = feet[1].id;
|
||||
feet[1].event.width = 0.1;
|
||||
feet[1].event.height = feet[1].event.width;
|
||||
// check previous event
|
||||
switch (feet[1].event.type) {
|
||||
case DRS_UP:
|
||||
|
||||
// generate down event
|
||||
feet[1].event.type = DRS_DOWN;
|
||||
break;
|
||||
|
||||
case DRS_DOWN:
|
||||
case DRS_MOVE:
|
||||
|
||||
// generate move event
|
||||
feet[1].event.type = DRS_MOVE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// send event
|
||||
fire_touches(&feet[1].event, 1);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
|
||||
switch (feet[1].event.type) {
|
||||
case DRS_DOWN:
|
||||
case DRS_MOVE:
|
||||
|
||||
// generate up event
|
||||
feet[1].event.type = DRS_UP;
|
||||
fire_touches(&feet[1].event, 1);
|
||||
break;
|
||||
|
||||
case DRS_UP:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// right foot
|
||||
if (feet[2].touching)
|
||||
{
|
||||
feet[2].id = 2;
|
||||
feet[2].index = 2;
|
||||
feet[2].event.id = feet[2].id;
|
||||
feet[2].event.width = 0.1;
|
||||
feet[2].event.height = feet[2].event.width;
|
||||
// check previous event
|
||||
switch (feet[2].event.type) {
|
||||
case DRS_UP:
|
||||
|
||||
// generate down event
|
||||
feet[2].event.type = DRS_DOWN;
|
||||
break;
|
||||
|
||||
case DRS_DOWN:
|
||||
case DRS_MOVE:
|
||||
|
||||
// generate move event
|
||||
feet[2].event.type = DRS_MOVE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// send event
|
||||
fire_touches(&feet[2].event, 1);
|
||||
continue;
|
||||
}
|
||||
else { // levitating
|
||||
|
||||
switch (feet[2].event.type) {
|
||||
case DRS_DOWN:
|
||||
case DRS_MOVE:
|
||||
|
||||
// generate up event
|
||||
feet[2].event.type = DRS_UP;
|
||||
fire_touches(&feet[2].event, 1);
|
||||
break;
|
||||
|
||||
case DRS_UP:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// slow down
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
@ -420,7 +432,6 @@ void start_kinect() {
|
||||
return nullptr;
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -444,7 +455,8 @@ 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();
|
||||
|
||||
startInputSpam(); // spams input to the game
|
||||
pollKinect();
|
||||
}
|
@ -27,6 +27,4 @@ struct VRFoot {
|
||||
|
||||
void fire_touches(drs_touch_t* events, size_t event_count);
|
||||
|
||||
void start_kinect();
|
||||
|
||||
void hookDancepad();
|
@ -4,6 +4,7 @@
|
||||
#include <libloaderapi.h>
|
||||
#include <winnt.h>
|
||||
#include <iostream>
|
||||
#include <NuiApi.h>
|
||||
#include "kiero/kiero.h"
|
||||
#include "kiero/minhook/include/MinHook.h"
|
||||
#include "kiero/injector/injector.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user