9 Commits
Author SHA1 Message Date
doomertheboomer 78b5d26604 add a bunch of QoL 2024-06-13 21:33:27 +07:00
dmr c46a004f3a Merge pull request #1 from doomertheboomer/wip
Add calibration for better experience
2023-07-28 19:43:16 +07:00
doomertheboomer 48e641ec3c update readme 2023-07-28 19:42:14 +07:00
doomertheboomer 256161d1a9 add calibration to the game 2023-07-28 19:37:33 +07:00
doomertheboomer 40fc590106 add calibration saving 2023-07-28 19:13:32 +07:00
doomertheboomer f01375f720 fix preview code, calibration code was fine 2023-07-28 18:07:12 +07:00
doomertheboomer 76e688b6b2 write preview code, calibration code is flawed for now 2023-07-28 17:56:16 +07:00
doomertheboomer 423ef98ec9 write calibration code 2023-07-28 16:55:31 +07:00
doomertheboomer e05f137eee create configuration program 2023-07-28 14:51:42 +07:00
20 changed files with 2513 additions and 225 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
.vs/
x64/
depthrush/x64/
Release/
depthrush/Release/
depthrush/x64/
depthrush/Release/
depthrushConfig/x64/
depthrushConfig/Release/
+2 -1
View File
@@ -3,4 +3,5 @@ Work in progress Kinect driver for Dancerush Stardom.
## Installation
1. Patch SpiceTools to disable all DRS pad hooks.
2. Copy `depthrush.dll` to the same folder as spice64 and use spicecfg to inject depthrush.
2. Copy all three of the files from to the same folder as spice64 and use spicecfg to inject `depthrush.dll`.
3. **IMPORTANT:** Open `depthrushConfig.exe` and calibrate your Kinect environment! Otherwise it won't work well with the game.
+10
View File
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.2.32616.157
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "depthrush", "depthrush\depthrush.vcxproj", "{04B17470-CB82-4724-904B-25445926AB86}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "depthrushConfig", "depthrushConfig\depthrushConfig.vcxproj", "{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -21,6 +23,14 @@ Global
{04B17470-CB82-4724-904B-25445926AB86}.Release|x64.Build.0 = Release|x64
{04B17470-CB82-4724-904B-25445926AB86}.Release|x86.ActiveCfg = Release|Win32
{04B17470-CB82-4724-904B-25445926AB86}.Release|x86.Build.0 = Release|Win32
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Debug|x64.ActiveCfg = Debug|x64
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Debug|x64.Build.0 = Debug|x64
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Debug|x86.ActiveCfg = Debug|Win32
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Debug|x86.Build.0 = Debug|Win32
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Release|x64.ActiveCfg = Release|x64
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Release|x64.Build.0 = Release|x64
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Release|x86.ActiveCfg = Release|Win32
{AF89F70A-7F60-4B1C-9532-CE7BBD02EA56}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+2 -1
View File
@@ -136,7 +136,7 @@
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>false</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<SDLCheck>false</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -171,6 +171,7 @@
<ItemGroup>
<ClInclude Include="drs.h" />
<ClInclude Include="includes.h" />
<ClInclude Include="ini.h" />
<ClInclude Include="kiero\injector\assembly.hpp" />
<ClInclude Include="kiero\injector\calling.hpp" />
<ClInclude Include="kiero\injector\gvm\gvm.hpp" />
+3
View File
@@ -103,6 +103,9 @@
<ClInclude Include="drs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ini.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="kiero\minhook\dll_resources\MinHook.def">
+405 -207
View File
@@ -5,6 +5,14 @@
bool kinectRunning = false;
bool kinectStarted = false;
bool threadsCreated = false;
bool mainInitialized = false;
bool isDown = false;
bool isJump = false;
bool downHack = true;
bool jumpHack = true;
VRFoot feet[16];
@@ -52,7 +60,51 @@ void (*touch_callback)(
const void *user_data);
std::uint8_t* PatternScan(void* module, const char* signature)
{
static auto pattern_to_byte = [](const char* pattern) {
auto bytes = std::vector<int>{};
auto start = const_cast<char*>(pattern);
auto end = const_cast<char*>(pattern) + strlen(pattern);
for (auto current = start; current < end; ++current) {
if (*current == '?') {
++current;
if (*current == '?')
++current;
bytes.push_back(-1);
}
else {
bytes.push_back(strtoul(current, &current, 16));
}
}
return bytes;
};
auto dosHeader = (PIMAGE_DOS_HEADER)module;
auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew);
auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage;
auto patternBytes = pattern_to_byte(signature);
auto scanBytes = reinterpret_cast<std::uint8_t*>(module);
auto s = patternBytes.size();
auto d = patternBytes.data();
for (auto i = 0ul; i < sizeOfImage - s; ++i) {
bool found = true;
for (auto j = 0ul; j < s; ++j) {
if (scanBytes[i + j] != d[j] && d[j] != -1) {
found = false;
break;
}
}
if (found) {
return &scanBytes[i];
}
}
return nullptr;
}
void* TouchSDK_Constructor(void* in) {
@@ -210,247 +262,393 @@ void fire_touches(drs_touch_t* events, size_t event_count) {
touch_callback(&dev, game_touches.get(), (int)event_count, 0, user_data);
}
void pollKinect() {
DWORD pollKinect(LPVOID _) {
/*
std::thread t([] {
// initialize Kinect
HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
});
t.detach();
*/
// initialize Kinect
HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
if (FAILED(hr)) {
std::cout << "Failed to initialize Kinect." << std::endl;
return 1;
}
// 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;
}
// load config from ini
std::cout << "Loading calibration from depthrush.ini\n";
mINI::INIFile file("depthrush.ini");
mINI::INIStructure ini;
file.read(ini);
std::string& readValue = ini["calibration"]["xGrad"];
float xGrad = std::stof(readValue);
readValue = ini["calibration"]["xOffset"];
float xOffset = std::stof(readValue);
readValue = ini["calibration"]["yGrad"];
float yGrad = std::stof(readValue);
readValue = ini["calibration"]["yOffset"];
float yOffset = std::stof(readValue);
readValue = ini["calibration"]["zGrad"];
float zGrad = std::stof(readValue);
readValue = ini["calibration"]["zOffset"];
float zOffset = std::stof(readValue);
readValue = ini["calibration"]["errorMargin"];
float errorMargin = std::stof(readValue); // stepping error margin
readValue = ini["calibration"]["jumpHeight"];
float jumpHeight = std::stof(readValue); // jumping error margin
// main loop to read and process skeleton data
NUI_SKELETON_FRAME skeletonFrame = { 0 };
// for down & jumps
float joints[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
float prevJoints[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
float highestDown = 0;
std::chrono::steady_clock::time_point jumpTime;
std::chrono::steady_clock::time_point landTime;
while (true) {
// get the latest skeleton frame
hr = NuiSkeletonGetNextFrame(0, &skeletonFrame);
if (FAILED(hr)) {
std::cout << "Failed to initialize Kinect." << std::endl;
return 1;
continue;
}
// 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;
}
// 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];
// main loop to read and process skeleton data
NUI_SKELETON_FRAME skeletonFrame = { 0 };
float errorMargin = 0.02;
while (true) {
// get the latest skeleton frame
hr = NuiSkeletonGetNextFrame(0, &skeletonFrame);
if (FAILED(hr)) {
continue;
}
// clamp
feet[1].event.x = std::clamp((xGrad * leftLegPos.x + xOffset), 0.0f, 1.0f);
feet[1].event.y = std::clamp((zGrad * leftLegPos.z + zOffset), 0.0f, 1.0f);
feet[2].event.x = std::clamp((xGrad * rightLegPos.x + xOffset), 0.0f, 1.0f);
feet[2].event.y = std::clamp((zGrad * rightLegPos.z + zOffset), 0.0f, 1.0f);
// 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];
// Fix feet height
float fixedLeft = leftLegPos.y - (yGrad * leftLegPos.z + yOffset);
float fixedRight = rightLegPos.y - (yGrad * rightLegPos.z + yOffset);
// 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;
// check for stepping
if (leftLegPos.y > (rightLegPos.y + errorMargin)) {
// check for stepping if not jumping
if (isJump == false) {
if (fixedLeft > (fixedRight + errorMargin)) {
feet[2].touching = true;
feet[1].touching = false;
// std::cout << "right step\n";
}
else if (rightLegPos.y > (leftLegPos.y + errorMargin)) {
else if (fixedRight > (fixedLeft + errorMargin)) {
feet[1].touching = true;
feet[2].touching = false;
// std::cout << "left step \n";
}
else {
feet[1].touching = true;
feet[2].touching = true;
// std::cout << "both step\n";
}
}
// y axis tracking (jump and down)
for (int j = 0; j < 20; j++) { // get current coords
joints[j] = skeletonFrame.SkeletonData[i].SkeletonPositions[j].y;
}
// get highest down value
for (int j = 0; j < 20; j++) {
if (joints[j] - prevJoints[j] < highestDown) {
highestDown = joints[j];
}
}
// down handling
if (highestDown < -0.2) {
isDown = true;
}
else {
isDown = false;
}
// jump handling
if (fixedLeft > jumpHeight && fixedRight > jumpHeight && isJump == false) {
jumpTime = std::chrono::high_resolution_clock::now();
isJump = true;
}
if (isJump) {
landTime = std::chrono::high_resolution_clock::now();
feet[1].touching = false;
feet[2].touching = false;
// jump for 180ms
if (std::chrono::duration_cast<std::chrono::milliseconds>(landTime - jumpTime).count() > 180) {
isJump = false;
}
}
// save current coords as previous coord
for (int j = 0; j < 20; j++) {
prevJoints[j] = skeletonFrame.SkeletonData[i].SkeletonPositions[j].y;
}
highestDown = 0;
}
}
}
// Clean up and exit
NuiSkeletonTrackingDisable();
NuiShutdown();
return 0;
});
t.detach();
// Clean up and exit
NuiSkeletonTrackingDisable();
NuiShutdown();
return 0;
}
void startInputSpam() {
DWORD startInputSpam(LPVOID _) {
/*
std::thread t([] {
puts("starting kinect thread");
// temporarily hardcode both kinect feet to touching at size 0.1
feet[1].touching = true;
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;
feet[2].touching = true;
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;
// hardcode debug foot details
feet[0].id = 0;
feet[0].index = 0;
// update event details
feet[0].event.id = feet[0].id;
feet[0].event.x = 0.5;
feet[0].event.y = 0.5;
feet[0].event.width = 1;
feet[0].event.height = feet[0].event.width;
// main loop
while (true) {
// debug shift control to touch entire pad
if (GetKeyState(VK_SHIFT) & 0x8000)
{
// check previous event
switch (feet[0].event.type) {
case DRS_UP:
// generate down event
feet[0].event.type = DRS_DOWN;
break;
case DRS_DOWN:
case DRS_MOVE:
// generate move event
feet[0].event.type = DRS_MOVE;
break;
default:
break;
}
// send event
fire_touches(&feet[0].event, 1);
}
else {
switch (feet[0].event.type) {
case DRS_DOWN:
case DRS_MOVE:
// generate up event
feet[0].event.type = DRS_UP;
fire_touches(&feet[0].event, 1);
break;
case DRS_UP:
default:
break;
}
}
if (feet[1].touching) // check if foot1 touch
{
// 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
//puts("foot1 is moving");
feet[1].event.type = DRS_MOVE;
break;
default:
break;
}
// send event
fire_touches(&feet[1].event, 1);
}
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;
}
}
if (feet[2].touching) // check if foot2 touch
{
// 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);
}
else {
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));
}
kinectStarted = false;
return nullptr;
});
t.detach();
*/
puts("starting input spam thread");
// temporarily hardcode both kinect feet to touching at size 0.1
feet[1].touching = true;
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;
feet[2].touching = true;
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;
// hardcode debug foot details
feet[0].id = 0;
feet[0].index = 0;
// update event details
feet[0].event.id = feet[0].id;
feet[0].event.x = 0.5;
feet[0].event.y = 0.5;
feet[0].event.width = 1;
feet[0].event.height = feet[0].event.width;
// main loop
while (true) {
// debug shift control to touch entire pad
if (GetKeyState(VK_SHIFT) & 0x8000)
{
// check previous event
switch (feet[0].event.type) {
case DRS_UP:
// generate down event
feet[0].event.type = DRS_DOWN;
break;
case DRS_DOWN:
case DRS_MOVE:
// generate move event
feet[0].event.type = DRS_MOVE;
break;
default:
break;
}
// send event
fire_touches(&feet[0].event, 1);
}
else {
switch (feet[0].event.type) {
case DRS_DOWN:
case DRS_MOVE:
// generate up event
feet[0].event.type = DRS_UP;
fire_touches(&feet[0].event, 1);
break;
case DRS_UP:
default:
break;
}
}
if (feet[1].touching) // check if foot1 touch
{
// 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
//puts("foot1 is moving");
feet[1].event.type = DRS_MOVE;
break;
default:
break;
}
// send event
fire_touches(&feet[1].event, 1);
}
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;
}
}
if (feet[2].touching) // check if foot2 touch
{
// 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);
}
else {
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));
}
kinectStarted = false;
return 0;
}
typedef __int64(__fastcall* PinitializeJudgementMemory)(float a1, float a2, char a3, __int64 a4, __int64 a5, char a6, float* a7);
static PinitializeJudgementMemory Orig_initializeJudgementMemory;
__int64 __fastcall Hook_initializeJudgementMemory(float a1, float a2, char a3, __int64 a4, __int64 a5, char a6, float* a7) {
// a4 is a1 + 168 usually
__int64 tmp = a4;
uintptr_t ptr = (uintptr_t)tmp - 16;
int noteType = *(int*)ptr;
float tMinus = fabs(a2 - a1);
if (noteType == 3) {
if (tMinus <= 150 && isDown && downHack) { // 150ms timing window for downs
std::cout << "Hitting down!\n";
return 5;
}
}
if (noteType == 4) {
if (tMinus <= 200 && isJump && jumpHack) { // 200ms timing window for jump
std::cout << "Hitting jump!\n";
return 5;
}
}
return Orig_initializeJudgementMemory(a1, a2, a3, a4, a5, a6, a7);
}
void hookDancepad() {
MH_Initialize();
MH_CreateHookApi(L"TouchSDKDll.dll", "??0TouchSDK@@QEAA@XZ", TouchSDK_Constructor, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SendData@TouchSDK@@QEAA_NU_DeviceInfo@@QEAEH1HH@Z", TouchSDK_SendData, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SetSignalInit@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_SetSignalInit, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetYLedTotal@TouchSDK@@QEAAHU_DeviceInfo@@H@Z", TouchSDK_GetYLedTotal, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetXLedTotal@TouchSDK@@QEAAHU_DeviceInfo@@H@Z", TouchSDK_GetXLedTotal, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableTouch@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableTouch, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableDrag@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableDrag, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableWheel@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableWheel, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableRightClick@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableRightClick, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SetMultiTouchMode@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_SetMultiTouchMode, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?EnableTouchWidthData@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_EnableTouchWidthData, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?EnableRawData@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_EnableRawData, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SetAllEnable@TouchSDK@@QEAA_NU_DeviceInfo@@_NH@Z", TouchSDK_SetAllEnable, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetTouchDeviceCount@TouchSDK@@QEAAHXZ", TouchSDK_GetTouchDeviceCount, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetTouchSDKVersion@TouchSDK@@QEAAIXZ", TouchSDK_GetTouchSDKVersion, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?InitTouch@TouchSDK@@QEAAHPEAU_DeviceInfo@@HP6AXU2@PEBU_TouchPointData@@HHPEBX@ZP6AX1_N3@ZPEAX@Z", TouchSDK_InitTouch, NULL);
if (!mainInitialized) {
MH_Initialize();
MH_EnableHook(MH_ALL_HOOKS);
// Pad hooks
MH_CreateHookApi(L"TouchSDKDll.dll", "??0TouchSDK@@QEAA@XZ", TouchSDK_Constructor, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SendData@TouchSDK@@QEAA_NU_DeviceInfo@@QEAEH1HH@Z", TouchSDK_SendData, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SetSignalInit@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_SetSignalInit, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetYLedTotal@TouchSDK@@QEAAHU_DeviceInfo@@H@Z", TouchSDK_GetYLedTotal, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetXLedTotal@TouchSDK@@QEAAHU_DeviceInfo@@H@Z", TouchSDK_GetXLedTotal, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableTouch@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableTouch, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableDrag@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableDrag, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableWheel@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableWheel, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?DisableRightClick@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_DisableRightClick, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SetMultiTouchMode@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_SetMultiTouchMode, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?EnableTouchWidthData@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_EnableTouchWidthData, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?EnableRawData@TouchSDK@@QEAA_NU_DeviceInfo@@H@Z", TouchSDK_EnableRawData, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?SetAllEnable@TouchSDK@@QEAA_NU_DeviceInfo@@_NH@Z", TouchSDK_SetAllEnable, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetTouchDeviceCount@TouchSDK@@QEAAHXZ", TouchSDK_GetTouchDeviceCount, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?GetTouchSDKVersion@TouchSDK@@QEAAIXZ", TouchSDK_GetTouchSDKVersion, NULL);
MH_CreateHookApi(L"TouchSDKDll.dll", "?InitTouch@TouchSDK@@QEAAHPEAU_DeviceInfo@@HP6AXU2@PEBU_TouchPointData@@HHPEBX@ZP6AX1_N3@ZPEAX@Z", TouchSDK_InitTouch, NULL);
std::cout << "Loading settings from depthrush.ini\n";
mINI::INIFile file("depthrush.ini");
mINI::INIStructure ini;
file.read(ini);
std::string& readValue = ini["hacks"]["downHack"];
downHack = !strcmp(readValue.c_str(), "1");
std::string& readValue2 = ini["hacks"]["jumpHack"];
jumpHack = !strcmp(readValue2.c_str(), "1");
// Game hooks
// uintptr_t imageBase = 0x180000000;
// HOOK(0x1806D5180, initializeJudgementMemory);
if (downHack == true || jumpHack == true) {
// if hacks are enabled
std::cout << "Hacks enabled, hooking!\n";
auto pointer = PatternScan((void*)0x180000000, "40 53 48 83 EC 20 48 8B 05 ? ? ? ? 48 33 C4 48 89 44 24 18 48 8B 5C 24 60 0F 28 E0 0F 28 D9");
HOOK(pointer, initializeJudgementMemory);
}
MH_EnableHook(MH_ALL_HOOKS);
mainInitialized = true;
}
if (threadsCreated == false) {
CreateThread(NULL, 0, startInputSpam, NULL, 0, NULL);
CreateThread(NULL, 0, pollKinect, NULL, 0, NULL);
threadsCreated = true;
}
/*
startInputSpam(); // spams input to the game
pollKinect();
*/
return;
}
+22 -1
View File
@@ -5,11 +5,32 @@
#include <winnt.h>
#include <iostream>
#include <NuiApi.h>
#include <stdint.h>
#include <algorithm>
#include "kiero/kiero.h"
#include "kiero/minhook/include/MinHook.h"
#include "kiero/injector/injector.hpp"
#include "kiero/injector/calling.hpp"
#include "d3d9.h"
#include "ini.h"
#include "drs.h"
typedef LRESULT(CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
typedef uintptr_t PTR;
typedef uintptr_t PTR;
#define HOOK(addr, detour) MH_CreateHook((LPVOID)(addr), \
Hook_##detour, \
reinterpret_cast<LPVOID*>(&Orig_##detour))
inline void safeJMP(injector::memory_pointer_tr at, injector::memory_pointer_raw dest, bool vp = true)
{
MH_Initialize();
MH_CreateHook((void*)at.as_int(), (void*)dest.as_int(), nullptr);
MH_EnableHook((void*)at.as_int());
}
inline void safeUNJMP(injector::memory_pointer_tr pTarget) {
MH_DisableHook((void*)pTarget.as_int());
MH_RemoveHook((void*)pTarget.as_int());
}
+789
View File
@@ -0,0 +1,789 @@
/*
* The MIT License (MIT)
* Copyright (c) 2018 Danijel Durakovic
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
///////////////////////////////////////////////////////////////////////////////
//
// /mINI/ v0.9.14
// An INI file reader and writer for the modern age.
//
///////////////////////////////////////////////////////////////////////////////
//
// A tiny utility library for manipulating INI files with a straightforward
// API and a minimal footprint. It conforms to the (somewhat) standard INI
// format - sections and keys are case insensitive and all leading and
// trailing whitespace is ignored. Comments are lines that begin with a
// semicolon. Trailing comments are allowed on section lines.
//
// Files are read on demand, upon which data is kept in memory and the file
// is closed. This utility supports lazy writing, which only writes changes
// and updates to a file and preserves custom formatting and comments. A lazy
// write invoked by a write() call will read the output file, find what
// changes have been made and update the file accordingly. If you only need to
// generate files, use generate() instead. Section and key order is preserved
// on read, write and insert.
//
///////////////////////////////////////////////////////////////////////////////
//
// /* BASIC USAGE EXAMPLE: */
//
// /* read from file */
// mINI::INIFile file("myfile.ini");
// mINI::INIStructure ini;
// file.read(ini);
//
// /* read value; gets a reference to actual value in the structure.
// if key or section don't exist, a new empty value will be created */
// std::string& value = ini["section"]["key"];
//
// /* read value safely; gets a copy of value in the structure.
// does not alter the structure */
// std::string value = ini.get("section").get("key");
//
// /* set or update values */
// ini["section"]["key"] = "value";
//
// /* set multiple values */
// ini["section2"].set({
// {"key1", "value1"},
// {"key2", "value2"}
// });
//
// /* write updates back to file, preserving comments and formatting */
// file.write(ini);
//
// /* or generate a file (overwrites the original) */
// file.generate(ini);
//
///////////////////////////////////////////////////////////////////////////////
//
// Long live the INI file!!!
//
///////////////////////////////////////////////////////////////////////////////
#ifndef MINI_INI_H_
#define MINI_INI_H_
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <vector>
#include <memory>
#include <fstream>
#include <sys/stat.h>
#include <cctype>
namespace mINI
{
namespace INIStringUtil
{
const char* const whitespaceDelimiters = " \t\n\r\f\v";
inline void trim(std::string& str)
{
str.erase(str.find_last_not_of(whitespaceDelimiters) + 1);
str.erase(0, str.find_first_not_of(whitespaceDelimiters));
}
#ifndef MINI_CASE_SENSITIVE
inline void toLower(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), [](const char c) {
return static_cast<char>(std::tolower(c));
});
}
#endif
inline void replace(std::string& str, std::string const& a, std::string const& b)
{
if (!a.empty())
{
std::size_t pos = 0;
while ((pos = str.find(a, pos)) != std::string::npos)
{
str.replace(pos, a.size(), b);
pos += b.size();
}
}
}
#ifdef _WIN32
const char* const endl = "\r\n";
#else
const char* const endl = "\n";
#endif
}
template<typename T>
class INIMap
{
private:
using T_DataIndexMap = std::unordered_map<std::string, std::size_t>;
using T_DataItem = std::pair<std::string, T>;
using T_DataContainer = std::vector<T_DataItem>;
using T_MultiArgs = typename std::vector<std::pair<std::string, T>>;
T_DataIndexMap dataIndexMap;
T_DataContainer data;
inline std::size_t setEmpty(std::string& key)
{
std::size_t index = data.size();
dataIndexMap[key] = index;
data.emplace_back(key, T());
return index;
}
public:
using const_iterator = typename T_DataContainer::const_iterator;
INIMap() { }
INIMap(INIMap const& other)
{
std::size_t data_size = other.data.size();
for (std::size_t i = 0; i < data_size; ++i)
{
auto const& key = other.data[i].first;
auto const& obj = other.data[i].second;
data.emplace_back(key, obj);
}
dataIndexMap = T_DataIndexMap(other.dataIndexMap);
}
T& operator[](std::string key)
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
bool hasIt = (it != dataIndexMap.end());
std::size_t index = (hasIt) ? it->second : setEmpty(key);
return data[index].second;
}
T get(std::string key) const
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it == dataIndexMap.end())
{
return T();
}
return T(data[it->second].second);
}
bool has(std::string key) const
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
return (dataIndexMap.count(key) == 1);
}
void set(std::string key, T obj)
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it != dataIndexMap.end())
{
data[it->second].second = obj;
}
else
{
dataIndexMap[key] = data.size();
data.emplace_back(key, obj);
}
}
void set(T_MultiArgs const& multiArgs)
{
for (auto const& it : multiArgs)
{
auto const& key = it.first;
auto const& obj = it.second;
set(key, obj);
}
}
bool remove(std::string key)
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it != dataIndexMap.end())
{
std::size_t index = it->second;
data.erase(data.begin() + index);
dataIndexMap.erase(it);
for (auto& it2 : dataIndexMap)
{
auto& vi = it2.second;
if (vi > index)
{
vi--;
}
}
return true;
}
return false;
}
void clear()
{
data.clear();
dataIndexMap.clear();
}
std::size_t size() const
{
return data.size();
}
const_iterator begin() const { return data.begin(); }
const_iterator end() const { return data.end(); }
};
using INIStructure = INIMap<INIMap<std::string>>;
namespace INIParser
{
using T_ParseValues = std::pair<std::string, std::string>;
enum class PDataType : char
{
PDATA_NONE,
PDATA_COMMENT,
PDATA_SECTION,
PDATA_KEYVALUE,
PDATA_UNKNOWN
};
inline PDataType parseLine(std::string line, T_ParseValues& parseData)
{
parseData.first.clear();
parseData.second.clear();
INIStringUtil::trim(line);
if (line.empty())
{
return PDataType::PDATA_NONE;
}
char firstCharacter = line[0];
if (firstCharacter == ';')
{
return PDataType::PDATA_COMMENT;
}
if (firstCharacter == '[')
{
auto commentAt = line.find_first_of(';');
if (commentAt != std::string::npos)
{
line = line.substr(0, commentAt);
}
auto closingBracketAt = line.find_last_of(']');
if (closingBracketAt != std::string::npos)
{
auto section = line.substr(1, closingBracketAt - 1);
INIStringUtil::trim(section);
parseData.first = section;
return PDataType::PDATA_SECTION;
}
}
auto lineNorm = line;
INIStringUtil::replace(lineNorm, "\\=", " ");
auto equalsAt = lineNorm.find_first_of('=');
if (equalsAt != std::string::npos)
{
auto key = line.substr(0, equalsAt);
INIStringUtil::trim(key);
INIStringUtil::replace(key, "\\=", "=");
auto value = line.substr(equalsAt + 1);
INIStringUtil::trim(value);
parseData.first = key;
parseData.second = value;
return PDataType::PDATA_KEYVALUE;
}
return PDataType::PDATA_UNKNOWN;
}
}
class INIReader
{
public:
using T_LineData = std::vector<std::string>;
using T_LineDataPtr = std::shared_ptr<T_LineData>;
bool isBOM = false;
private:
std::ifstream fileReadStream;
T_LineDataPtr lineData;
T_LineData readFile()
{
fileReadStream.seekg(0, std::ios::end);
const std::size_t fileSize = static_cast<std::size_t>(fileReadStream.tellg());
fileReadStream.seekg(0, std::ios::beg);
if (fileSize >= 3) {
const char header[3] = {
static_cast<char>(fileReadStream.get()),
static_cast<char>(fileReadStream.get()),
static_cast<char>(fileReadStream.get())
};
isBOM = (
header[0] == static_cast<char>(0xEF) &&
header[1] == static_cast<char>(0xBB) &&
header[2] == static_cast<char>(0xBF)
);
}
else {
isBOM = false;
}
std::string fileContents;
fileContents.resize(fileSize);
fileReadStream.seekg(isBOM ? 3 : 0, std::ios::beg);
fileReadStream.read(&fileContents[0], fileSize);
fileReadStream.close();
T_LineData output;
if (fileSize == 0)
{
return output;
}
std::string buffer;
buffer.reserve(50);
for (std::size_t i = 0; i < fileSize; ++i)
{
char& c = fileContents[i];
if (c == '\n')
{
output.emplace_back(buffer);
buffer.clear();
continue;
}
if (c != '\0' && c != '\r')
{
buffer += c;
}
}
output.emplace_back(buffer);
return output;
}
public:
INIReader(std::string const& filename, bool keepLineData = false)
{
fileReadStream.open(filename, std::ios::in | std::ios::binary);
if (keepLineData)
{
lineData = std::make_shared<T_LineData>();
}
}
~INIReader() { }
bool operator>>(INIStructure& data)
{
if (!fileReadStream.is_open())
{
return false;
}
T_LineData fileLines = readFile();
std::string section;
bool inSection = false;
INIParser::T_ParseValues parseData;
for (auto const& line : fileLines)
{
auto parseResult = INIParser::parseLine(line, parseData);
if (parseResult == INIParser::PDataType::PDATA_SECTION)
{
inSection = true;
data[section = parseData.first];
}
else if (inSection && parseResult == INIParser::PDataType::PDATA_KEYVALUE)
{
auto const& key = parseData.first;
auto const& value = parseData.second;
data[section][key] = value;
}
if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN)
{
if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection)
{
continue;
}
lineData->emplace_back(line);
}
}
return true;
}
T_LineDataPtr getLines()
{
return lineData;
}
};
class INIGenerator
{
private:
std::ofstream fileWriteStream;
public:
bool prettyPrint = false;
INIGenerator(std::string const& filename)
{
fileWriteStream.open(filename, std::ios::out | std::ios::binary);
}
~INIGenerator() { }
bool operator<<(INIStructure const& data)
{
if (!fileWriteStream.is_open())
{
return false;
}
if (!data.size())
{
return true;
}
auto it = data.begin();
for (;;)
{
auto const& section = it->first;
auto const& collection = it->second;
fileWriteStream
<< "["
<< section
<< "]";
if (collection.size())
{
fileWriteStream << INIStringUtil::endl;
auto it2 = collection.begin();
for (;;)
{
auto key = it2->first;
INIStringUtil::replace(key, "=", "\\=");
auto value = it2->second;
INIStringUtil::trim(value);
fileWriteStream
<< key
<< ((prettyPrint) ? " = " : "=")
<< value;
if (++it2 == collection.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
}
}
if (++it == data.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
if (prettyPrint)
{
fileWriteStream << INIStringUtil::endl;
}
}
return true;
}
};
class INIWriter
{
private:
using T_LineData = std::vector<std::string>;
using T_LineDataPtr = std::shared_ptr<T_LineData>;
std::string filename;
T_LineData getLazyOutput(T_LineDataPtr const& lineData, INIStructure& data, INIStructure& original)
{
T_LineData output;
INIParser::T_ParseValues parseData;
std::string sectionCurrent;
bool parsingSection = false;
bool continueToNextSection = false;
bool discardNextEmpty = false;
bool writeNewKeys = false;
std::size_t lastKeyLine = 0;
for (auto line = lineData->begin(); line != lineData->end(); ++line)
{
if (!writeNewKeys)
{
auto parseResult = INIParser::parseLine(*line, parseData);
if (parseResult == INIParser::PDataType::PDATA_SECTION)
{
if (parsingSection)
{
writeNewKeys = true;
parsingSection = false;
--line;
continue;
}
sectionCurrent = parseData.first;
if (data.has(sectionCurrent))
{
parsingSection = true;
continueToNextSection = false;
discardNextEmpty = false;
output.emplace_back(*line);
lastKeyLine = output.size();
}
else
{
continueToNextSection = true;
discardNextEmpty = true;
continue;
}
}
else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE)
{
if (continueToNextSection)
{
continue;
}
if (data.has(sectionCurrent))
{
auto& collection = data[sectionCurrent];
auto const& key = parseData.first;
auto const& value = parseData.second;
if (collection.has(key))
{
auto outputValue = collection[key];
if (value == outputValue)
{
output.emplace_back(*line);
}
else
{
INIStringUtil::trim(outputValue);
auto lineNorm = *line;
INIStringUtil::replace(lineNorm, "\\=", " ");
auto equalsAt = lineNorm.find_first_of('=');
auto valueAt = lineNorm.find_first_not_of(
INIStringUtil::whitespaceDelimiters,
equalsAt + 1
);
std::string outputLine = line->substr(0, valueAt);
if (prettyPrint && equalsAt + 1 == valueAt)
{
outputLine += " ";
}
outputLine += outputValue;
output.emplace_back(outputLine);
}
lastKeyLine = output.size();
}
}
}
else
{
if (discardNextEmpty && line->empty())
{
discardNextEmpty = false;
}
else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN)
{
output.emplace_back(*line);
}
}
}
if (writeNewKeys || std::next(line) == lineData->end())
{
T_LineData linesToAdd;
if (data.has(sectionCurrent) && original.has(sectionCurrent))
{
auto const& collection = data[sectionCurrent];
auto const& collectionOriginal = original[sectionCurrent];
for (auto const& it : collection)
{
auto key = it.first;
if (collectionOriginal.has(key))
{
continue;
}
auto value = it.second;
INIStringUtil::replace(key, "=", "\\=");
INIStringUtil::trim(value);
linesToAdd.emplace_back(
key + ((prettyPrint) ? " = " : "=") + value
);
}
}
if (!linesToAdd.empty())
{
output.insert(
output.begin() + lastKeyLine,
linesToAdd.begin(),
linesToAdd.end()
);
}
if (writeNewKeys)
{
writeNewKeys = false;
--line;
}
}
}
for (auto const& it : data)
{
auto const& section = it.first;
if (original.has(section))
{
continue;
}
if (prettyPrint && output.size() > 0 && !output.back().empty())
{
output.emplace_back();
}
output.emplace_back("[" + section + "]");
auto const& collection = it.second;
for (auto const& it2 : collection)
{
auto key = it2.first;
auto value = it2.second;
INIStringUtil::replace(key, "=", "\\=");
INIStringUtil::trim(value);
output.emplace_back(
key + ((prettyPrint) ? " = " : "=") + value
);
}
}
return output;
}
public:
bool prettyPrint = false;
INIWriter(std::string const& filename)
: filename(filename)
{
}
~INIWriter() { }
bool operator<<(INIStructure& data)
{
struct stat buf;
bool fileExists = (stat(filename.c_str(), &buf) == 0);
if (!fileExists)
{
INIGenerator generator(filename);
generator.prettyPrint = prettyPrint;
return generator << data;
}
INIStructure originalData;
T_LineDataPtr lineData;
bool readSuccess = false;
bool fileIsBOM = false;
{
INIReader reader(filename, true);
if ((readSuccess = reader >> originalData))
{
lineData = reader.getLines();
fileIsBOM = reader.isBOM;
}
}
if (!readSuccess)
{
return false;
}
T_LineData output = getLazyOutput(lineData, data, originalData);
std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary);
if (fileWriteStream.is_open())
{
if (fileIsBOM) {
const char utf8_BOM[3] = {
static_cast<char>(0xEF),
static_cast<char>(0xBB),
static_cast<char>(0xBF)
};
fileWriteStream.write(utf8_BOM, 3);
}
if (output.size())
{
auto line = output.begin();
for (;;)
{
fileWriteStream << *line;
if (++line == output.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
}
}
return true;
}
return false;
}
};
class INIFile
{
private:
std::string filename;
public:
INIFile(std::string const& filename)
: filename(filename)
{ }
~INIFile() { }
bool read(INIStructure& data) const
{
if (data.size())
{
data.clear();
}
if (filename.empty())
{
return false;
}
INIReader reader(filename);
return reader >> data;
}
bool generate(INIStructure const& data, bool pretty = false) const
{
if (filename.empty())
{
return false;
}
INIGenerator generator(filename);
generator.prettyPrint = pretty;
return generator << data;
}
bool write(INIStructure& data, bool pretty = false) const
{
if (filename.empty())
{
return false;
}
INIWriter writer(filename);
writer.prettyPrint = pretty;
return writer << data;
}
};
}
#endif // MINI_INI_H_
-1
View File
@@ -656,6 +656,5 @@ inline memory_pointer_aslr aslr_ptr(T p)
} // namespace
-12
View File
@@ -2,17 +2,6 @@
static uintptr_t imageBase;
inline void safeJMP(injector::memory_pointer_tr at, injector::memory_pointer_raw dest, bool vp = true)
{
MH_Initialize();
MH_CreateHook((void*)at.as_int(), (void*)dest.as_int(), nullptr);
MH_EnableHook((void*)at.as_int());
}
inline void safeUNJMP(injector::memory_pointer_tr pTarget) {
MH_DisableHook((void*)pTarget.as_int());
MH_RemoveHook((void*)pTarget.as_int());
}
static int returnTrue() {
return 1;
@@ -24,7 +13,6 @@ static int returnFalse() {
BOOL WINAPI DllMain(HMODULE hMod, DWORD dwReason, LPVOID lpReserved)
{
DisableThreadLibraryCalls(hMod);
+126
View File
@@ -0,0 +1,126 @@
#include "includes.h"
Vector4 leftLegPos = { 1.5F, 1.5F, 1.5F, 1.5F };
Vector4 rightLegPos = { 1.5F, 1.5F, 1.5F, 1.5F };
bool kinectScanning = true;
int calibration() {
// initialize Kinect
HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
if (FAILED(hr)) {
std::cout << "Failed to initialize Kinect." << std::endl;
return 1;
}
// 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;
}
// start calibration application
std::thread calibrateMenu([] {
std::cout << "Starting calibration... Make sure your kinect is pointed straight ahead at you!\n";
// X calibration
std::cout << "Please place your left foot on the left side of the pad for 5 seconds.\n";
Sleep(5000);
float xMin = leftLegPos.x;
std::cout << "Left side recorded.\n";
std::cout << "Please place your right foot on the right side of the pad for 5 seconds.\n";
Sleep(5000);
float xMax = rightLegPos.x;
std::cout << "Right side recorded.\n";
float xGrad = (1 - 0) / (xMax - xMin);
float xOffset = -(xGrad * xMin);
// Y and Z calibration
// Z calibration
std::cout << "Please place your left foot at the front of the pad for 5 seconds.\n";
Sleep(5000);
float zMin = leftLegPos.z;
float yMin = leftLegPos.y;
std::cout << "Front recorded.\n";
std::cout << "Please place your left foot at the back of the pad for 5 seconds.\n";
Sleep(5000);
float zMax = leftLegPos.z;
float yMax = leftLegPos.y;
std::cout << "Back recorded.\n";
float zGrad = (1 - 0) / (zMax - zMin);
float zOffset = -(zGrad * zMin);
//Y calibration
float yGrad = (yMax - yMin) / (zMax - zMin);
float yOffset = (yMin - yGrad * zMin);
// Clean up and proceed to kinect test
kinectScanning = false;
std::cout << "Saving the following values to depthrush.ini...\n";
std::cout << std::to_string(xGrad) << " ";
std::cout << std::to_string(xOffset) << " ";
std::cout << std::to_string(yGrad) << " ";
std::cout << std::to_string(yOffset) << " ";
std::cout << std::to_string(zGrad) << " ";
std::cout << std::to_string(zOffset) << "\n";
// Save values
mINI::INIFile file("depthrush.ini");
mINI::INIStructure ini;
// Read the existing contents of the file
if (file.read(ini)) {
std::cout << "Existing file loaded.\n";
}
else {
std::cout << "File does not exist or failed to load, creating new.\n";
}
// Update the structure with new values
ini["calibration"]["xGrad"] = std::to_string(xGrad);
ini["calibration"]["xOffset"] = std::to_string(xOffset);
ini["calibration"]["yGrad"] = std::to_string(yGrad);
ini["calibration"]["yOffset"] = std::to_string(yOffset);
ini["calibration"]["zGrad"] = std::to_string(zGrad);
ini["calibration"]["zOffset"] = std::to_string(zOffset);
// Write the updated structure back to the file
file.write(ini);
std::cout << "Save complete.\n";
std::cout << "Proceeding to Kinect Preview..\n";
kinectTest(xGrad, xOffset, yGrad, yOffset, zGrad, zOffset);
});
calibrateMenu.detach();
// main loop to read and process skeleton data
NUI_SKELETON_FRAME skeletonFrame = { 0 };
while (kinectScanning) {
// 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
leftLegPos = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_LEFT];
rightLegPos = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_RIGHT];
}
}
}
// Clean up and exit
NuiSkeletonTrackingDisable();
NuiShutdown();
std::this_thread::sleep_for(std::chrono::hours(1000));
return 0;
}
+2
View File
@@ -0,0 +1,2 @@
#pragma once
int calibration();
+40
View File
@@ -0,0 +1,40 @@
#include "includes.h"
int main()
{
// load config from ini
mINI::INIFile file("depthrush.ini");
mINI::INIStructure ini;
file.read(ini);
std::string& readValue = ini["calibration"]["xGrad"];
float xGrad = std::stof(readValue);
readValue = ini["calibration"]["xOffset"];
float xOffset = std::stof(readValue);
readValue = ini["calibration"]["yGrad"];
float yGrad = std::stof(readValue);
readValue = ini["calibration"]["yOffset"];
float yOffset = std::stof(readValue);
readValue = ini["calibration"]["zGrad"];
float zGrad = std::stof(readValue);
readValue = ini["calibration"]["zOffset"];
float zOffset = std::stof(readValue);
int choice = 0;
std::cout << "Depthrush test application\n";
std::cout << "1. Calibrate Kinect\n";
std::cout << "2. Preview Kinect\n";
std::cout << "Enter a choice (1,2): ";
std::cin >> choice;
if (choice == 1) {
calibration();
return 0;
}
else if (choice == 2) {
kinectTest(xGrad, xOffset, yGrad, yOffset, zGrad, zOffset);
return 0;
}
else {
std::cout << "Invalid option!";
}
return 0;
}
+148
View File
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{af89f70a-7f60-4b1c-9532-ce7bbd02ea56}</ProjectGuid>
<RootNamespace>depthrushConfig</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>C:\Program Files\Microsoft SDKs\Kinect\v1.7\inc;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files\Microsoft SDKs\Kinect\v1.7\lib\amd64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Kinect10.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="calibration.cpp" />
<ClCompile Include="depthrushConfig.cpp" />
<ClCompile Include="kinectTest.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="calibration.h" />
<ClInclude Include="includes.h" />
<ClInclude Include="ini.h" />
<ClInclude Include="kinectTest.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="depthrushConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="calibration.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="kinectTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="includes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="calibration.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="kinectTest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ini.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include <Windows.h>
#include <NuiApi.h>
#include <iostream>
#include <thread>
#include <string>
#include "ini.h"
#include "calibration.h"
#include "kinectTest.h"
+789
View File
@@ -0,0 +1,789 @@
/*
* The MIT License (MIT)
* Copyright (c) 2018 Danijel Durakovic
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
///////////////////////////////////////////////////////////////////////////////
//
// /mINI/ v0.9.14
// An INI file reader and writer for the modern age.
//
///////////////////////////////////////////////////////////////////////////////
//
// A tiny utility library for manipulating INI files with a straightforward
// API and a minimal footprint. It conforms to the (somewhat) standard INI
// format - sections and keys are case insensitive and all leading and
// trailing whitespace is ignored. Comments are lines that begin with a
// semicolon. Trailing comments are allowed on section lines.
//
// Files are read on demand, upon which data is kept in memory and the file
// is closed. This utility supports lazy writing, which only writes changes
// and updates to a file and preserves custom formatting and comments. A lazy
// write invoked by a write() call will read the output file, find what
// changes have been made and update the file accordingly. If you only need to
// generate files, use generate() instead. Section and key order is preserved
// on read, write and insert.
//
///////////////////////////////////////////////////////////////////////////////
//
// /* BASIC USAGE EXAMPLE: */
//
// /* read from file */
// mINI::INIFile file("myfile.ini");
// mINI::INIStructure ini;
// file.read(ini);
//
// /* read value; gets a reference to actual value in the structure.
// if key or section don't exist, a new empty value will be created */
// std::string& value = ini["section"]["key"];
//
// /* read value safely; gets a copy of value in the structure.
// does not alter the structure */
// std::string value = ini.get("section").get("key");
//
// /* set or update values */
// ini["section"]["key"] = "value";
//
// /* set multiple values */
// ini["section2"].set({
// {"key1", "value1"},
// {"key2", "value2"}
// });
//
// /* write updates back to file, preserving comments and formatting */
// file.write(ini);
//
// /* or generate a file (overwrites the original) */
// file.generate(ini);
//
///////////////////////////////////////////////////////////////////////////////
//
// Long live the INI file!!!
//
///////////////////////////////////////////////////////////////////////////////
#ifndef MINI_INI_H_
#define MINI_INI_H_
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <vector>
#include <memory>
#include <fstream>
#include <sys/stat.h>
#include <cctype>
namespace mINI
{
namespace INIStringUtil
{
const char* const whitespaceDelimiters = " \t\n\r\f\v";
inline void trim(std::string& str)
{
str.erase(str.find_last_not_of(whitespaceDelimiters) + 1);
str.erase(0, str.find_first_not_of(whitespaceDelimiters));
}
#ifndef MINI_CASE_SENSITIVE
inline void toLower(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), [](const char c) {
return static_cast<char>(std::tolower(c));
});
}
#endif
inline void replace(std::string& str, std::string const& a, std::string const& b)
{
if (!a.empty())
{
std::size_t pos = 0;
while ((pos = str.find(a, pos)) != std::string::npos)
{
str.replace(pos, a.size(), b);
pos += b.size();
}
}
}
#ifdef _WIN32
const char* const endl = "\r\n";
#else
const char* const endl = "\n";
#endif
}
template<typename T>
class INIMap
{
private:
using T_DataIndexMap = std::unordered_map<std::string, std::size_t>;
using T_DataItem = std::pair<std::string, T>;
using T_DataContainer = std::vector<T_DataItem>;
using T_MultiArgs = typename std::vector<std::pair<std::string, T>>;
T_DataIndexMap dataIndexMap;
T_DataContainer data;
inline std::size_t setEmpty(std::string& key)
{
std::size_t index = data.size();
dataIndexMap[key] = index;
data.emplace_back(key, T());
return index;
}
public:
using const_iterator = typename T_DataContainer::const_iterator;
INIMap() { }
INIMap(INIMap const& other)
{
std::size_t data_size = other.data.size();
for (std::size_t i = 0; i < data_size; ++i)
{
auto const& key = other.data[i].first;
auto const& obj = other.data[i].second;
data.emplace_back(key, obj);
}
dataIndexMap = T_DataIndexMap(other.dataIndexMap);
}
T& operator[](std::string key)
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
bool hasIt = (it != dataIndexMap.end());
std::size_t index = (hasIt) ? it->second : setEmpty(key);
return data[index].second;
}
T get(std::string key) const
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it == dataIndexMap.end())
{
return T();
}
return T(data[it->second].second);
}
bool has(std::string key) const
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
return (dataIndexMap.count(key) == 1);
}
void set(std::string key, T obj)
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it != dataIndexMap.end())
{
data[it->second].second = obj;
}
else
{
dataIndexMap[key] = data.size();
data.emplace_back(key, obj);
}
}
void set(T_MultiArgs const& multiArgs)
{
for (auto const& it : multiArgs)
{
auto const& key = it.first;
auto const& obj = it.second;
set(key, obj);
}
}
bool remove(std::string key)
{
INIStringUtil::trim(key);
#ifndef MINI_CASE_SENSITIVE
INIStringUtil::toLower(key);
#endif
auto it = dataIndexMap.find(key);
if (it != dataIndexMap.end())
{
std::size_t index = it->second;
data.erase(data.begin() + index);
dataIndexMap.erase(it);
for (auto& it2 : dataIndexMap)
{
auto& vi = it2.second;
if (vi > index)
{
vi--;
}
}
return true;
}
return false;
}
void clear()
{
data.clear();
dataIndexMap.clear();
}
std::size_t size() const
{
return data.size();
}
const_iterator begin() const { return data.begin(); }
const_iterator end() const { return data.end(); }
};
using INIStructure = INIMap<INIMap<std::string>>;
namespace INIParser
{
using T_ParseValues = std::pair<std::string, std::string>;
enum class PDataType : char
{
PDATA_NONE,
PDATA_COMMENT,
PDATA_SECTION,
PDATA_KEYVALUE,
PDATA_UNKNOWN
};
inline PDataType parseLine(std::string line, T_ParseValues& parseData)
{
parseData.first.clear();
parseData.second.clear();
INIStringUtil::trim(line);
if (line.empty())
{
return PDataType::PDATA_NONE;
}
char firstCharacter = line[0];
if (firstCharacter == ';')
{
return PDataType::PDATA_COMMENT;
}
if (firstCharacter == '[')
{
auto commentAt = line.find_first_of(';');
if (commentAt != std::string::npos)
{
line = line.substr(0, commentAt);
}
auto closingBracketAt = line.find_last_of(']');
if (closingBracketAt != std::string::npos)
{
auto section = line.substr(1, closingBracketAt - 1);
INIStringUtil::trim(section);
parseData.first = section;
return PDataType::PDATA_SECTION;
}
}
auto lineNorm = line;
INIStringUtil::replace(lineNorm, "\\=", " ");
auto equalsAt = lineNorm.find_first_of('=');
if (equalsAt != std::string::npos)
{
auto key = line.substr(0, equalsAt);
INIStringUtil::trim(key);
INIStringUtil::replace(key, "\\=", "=");
auto value = line.substr(equalsAt + 1);
INIStringUtil::trim(value);
parseData.first = key;
parseData.second = value;
return PDataType::PDATA_KEYVALUE;
}
return PDataType::PDATA_UNKNOWN;
}
}
class INIReader
{
public:
using T_LineData = std::vector<std::string>;
using T_LineDataPtr = std::shared_ptr<T_LineData>;
bool isBOM = false;
private:
std::ifstream fileReadStream;
T_LineDataPtr lineData;
T_LineData readFile()
{
fileReadStream.seekg(0, std::ios::end);
const std::size_t fileSize = static_cast<std::size_t>(fileReadStream.tellg());
fileReadStream.seekg(0, std::ios::beg);
if (fileSize >= 3) {
const char header[3] = {
static_cast<char>(fileReadStream.get()),
static_cast<char>(fileReadStream.get()),
static_cast<char>(fileReadStream.get())
};
isBOM = (
header[0] == static_cast<char>(0xEF) &&
header[1] == static_cast<char>(0xBB) &&
header[2] == static_cast<char>(0xBF)
);
}
else {
isBOM = false;
}
std::string fileContents;
fileContents.resize(fileSize);
fileReadStream.seekg(isBOM ? 3 : 0, std::ios::beg);
fileReadStream.read(&fileContents[0], fileSize);
fileReadStream.close();
T_LineData output;
if (fileSize == 0)
{
return output;
}
std::string buffer;
buffer.reserve(50);
for (std::size_t i = 0; i < fileSize; ++i)
{
char& c = fileContents[i];
if (c == '\n')
{
output.emplace_back(buffer);
buffer.clear();
continue;
}
if (c != '\0' && c != '\r')
{
buffer += c;
}
}
output.emplace_back(buffer);
return output;
}
public:
INIReader(std::string const& filename, bool keepLineData = false)
{
fileReadStream.open(filename, std::ios::in | std::ios::binary);
if (keepLineData)
{
lineData = std::make_shared<T_LineData>();
}
}
~INIReader() { }
bool operator>>(INIStructure& data)
{
if (!fileReadStream.is_open())
{
return false;
}
T_LineData fileLines = readFile();
std::string section;
bool inSection = false;
INIParser::T_ParseValues parseData;
for (auto const& line : fileLines)
{
auto parseResult = INIParser::parseLine(line, parseData);
if (parseResult == INIParser::PDataType::PDATA_SECTION)
{
inSection = true;
data[section = parseData.first];
}
else if (inSection && parseResult == INIParser::PDataType::PDATA_KEYVALUE)
{
auto const& key = parseData.first;
auto const& value = parseData.second;
data[section][key] = value;
}
if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN)
{
if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection)
{
continue;
}
lineData->emplace_back(line);
}
}
return true;
}
T_LineDataPtr getLines()
{
return lineData;
}
};
class INIGenerator
{
private:
std::ofstream fileWriteStream;
public:
bool prettyPrint = false;
INIGenerator(std::string const& filename)
{
fileWriteStream.open(filename, std::ios::out | std::ios::binary);
}
~INIGenerator() { }
bool operator<<(INIStructure const& data)
{
if (!fileWriteStream.is_open())
{
return false;
}
if (!data.size())
{
return true;
}
auto it = data.begin();
for (;;)
{
auto const& section = it->first;
auto const& collection = it->second;
fileWriteStream
<< "["
<< section
<< "]";
if (collection.size())
{
fileWriteStream << INIStringUtil::endl;
auto it2 = collection.begin();
for (;;)
{
auto key = it2->first;
INIStringUtil::replace(key, "=", "\\=");
auto value = it2->second;
INIStringUtil::trim(value);
fileWriteStream
<< key
<< ((prettyPrint) ? " = " : "=")
<< value;
if (++it2 == collection.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
}
}
if (++it == data.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
if (prettyPrint)
{
fileWriteStream << INIStringUtil::endl;
}
}
return true;
}
};
class INIWriter
{
private:
using T_LineData = std::vector<std::string>;
using T_LineDataPtr = std::shared_ptr<T_LineData>;
std::string filename;
T_LineData getLazyOutput(T_LineDataPtr const& lineData, INIStructure& data, INIStructure& original)
{
T_LineData output;
INIParser::T_ParseValues parseData;
std::string sectionCurrent;
bool parsingSection = false;
bool continueToNextSection = false;
bool discardNextEmpty = false;
bool writeNewKeys = false;
std::size_t lastKeyLine = 0;
for (auto line = lineData->begin(); line != lineData->end(); ++line)
{
if (!writeNewKeys)
{
auto parseResult = INIParser::parseLine(*line, parseData);
if (parseResult == INIParser::PDataType::PDATA_SECTION)
{
if (parsingSection)
{
writeNewKeys = true;
parsingSection = false;
--line;
continue;
}
sectionCurrent = parseData.first;
if (data.has(sectionCurrent))
{
parsingSection = true;
continueToNextSection = false;
discardNextEmpty = false;
output.emplace_back(*line);
lastKeyLine = output.size();
}
else
{
continueToNextSection = true;
discardNextEmpty = true;
continue;
}
}
else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE)
{
if (continueToNextSection)
{
continue;
}
if (data.has(sectionCurrent))
{
auto& collection = data[sectionCurrent];
auto const& key = parseData.first;
auto const& value = parseData.second;
if (collection.has(key))
{
auto outputValue = collection[key];
if (value == outputValue)
{
output.emplace_back(*line);
}
else
{
INIStringUtil::trim(outputValue);
auto lineNorm = *line;
INIStringUtil::replace(lineNorm, "\\=", " ");
auto equalsAt = lineNorm.find_first_of('=');
auto valueAt = lineNorm.find_first_not_of(
INIStringUtil::whitespaceDelimiters,
equalsAt + 1
);
std::string outputLine = line->substr(0, valueAt);
if (prettyPrint && equalsAt + 1 == valueAt)
{
outputLine += " ";
}
outputLine += outputValue;
output.emplace_back(outputLine);
}
lastKeyLine = output.size();
}
}
}
else
{
if (discardNextEmpty && line->empty())
{
discardNextEmpty = false;
}
else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN)
{
output.emplace_back(*line);
}
}
}
if (writeNewKeys || std::next(line) == lineData->end())
{
T_LineData linesToAdd;
if (data.has(sectionCurrent) && original.has(sectionCurrent))
{
auto const& collection = data[sectionCurrent];
auto const& collectionOriginal = original[sectionCurrent];
for (auto const& it : collection)
{
auto key = it.first;
if (collectionOriginal.has(key))
{
continue;
}
auto value = it.second;
INIStringUtil::replace(key, "=", "\\=");
INIStringUtil::trim(value);
linesToAdd.emplace_back(
key + ((prettyPrint) ? " = " : "=") + value
);
}
}
if (!linesToAdd.empty())
{
output.insert(
output.begin() + lastKeyLine,
linesToAdd.begin(),
linesToAdd.end()
);
}
if (writeNewKeys)
{
writeNewKeys = false;
--line;
}
}
}
for (auto const& it : data)
{
auto const& section = it.first;
if (original.has(section))
{
continue;
}
if (prettyPrint && output.size() > 0 && !output.back().empty())
{
output.emplace_back();
}
output.emplace_back("[" + section + "]");
auto const& collection = it.second;
for (auto const& it2 : collection)
{
auto key = it2.first;
auto value = it2.second;
INIStringUtil::replace(key, "=", "\\=");
INIStringUtil::trim(value);
output.emplace_back(
key + ((prettyPrint) ? " = " : "=") + value
);
}
}
return output;
}
public:
bool prettyPrint = false;
INIWriter(std::string const& filename)
: filename(filename)
{
}
~INIWriter() { }
bool operator<<(INIStructure& data)
{
struct stat buf;
bool fileExists = (stat(filename.c_str(), &buf) == 0);
if (!fileExists)
{
INIGenerator generator(filename);
generator.prettyPrint = prettyPrint;
return generator << data;
}
INIStructure originalData;
T_LineDataPtr lineData;
bool readSuccess = false;
bool fileIsBOM = false;
{
INIReader reader(filename, true);
if ((readSuccess = reader >> originalData))
{
lineData = reader.getLines();
fileIsBOM = reader.isBOM;
}
}
if (!readSuccess)
{
return false;
}
T_LineData output = getLazyOutput(lineData, data, originalData);
std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary);
if (fileWriteStream.is_open())
{
if (fileIsBOM) {
const char utf8_BOM[3] = {
static_cast<char>(0xEF),
static_cast<char>(0xBB),
static_cast<char>(0xBF)
};
fileWriteStream.write(utf8_BOM, 3);
}
if (output.size())
{
auto line = output.begin();
for (;;)
{
fileWriteStream << *line;
if (++line == output.end())
{
break;
}
fileWriteStream << INIStringUtil::endl;
}
}
return true;
}
return false;
}
};
class INIFile
{
private:
std::string filename;
public:
INIFile(std::string const& filename)
: filename(filename)
{ }
~INIFile() { }
bool read(INIStructure& data) const
{
if (data.size())
{
data.clear();
}
if (filename.empty())
{
return false;
}
INIReader reader(filename);
return reader >> data;
}
bool generate(INIStructure const& data, bool pretty = false) const
{
if (filename.empty())
{
return false;
}
INIGenerator generator(filename);
generator.prettyPrint = pretty;
return generator << data;
}
bool write(INIStructure& data, bool pretty = false) const
{
if (filename.empty())
{
return false;
}
INIWriter writer(filename);
writer.prettyPrint = pretty;
return writer << data;
}
};
}
#endif // MINI_INI_H_
+112
View File
@@ -0,0 +1,112 @@
#include "includes.h"
Vector4 leftLegPosPreview = { 1.5F, 1.5F, 1.5F, 1.5F };
Vector4 rightLegPosPreview = { 1.5F, 1.5F, 1.5F, 1.5F };
int kinectTest(float xGrad, float xOffset, float yGrad, float yOffset, float zGrad, float zOffset) {
//std::cout << "Kinect Preview\n";
//std::cin >> xGrad;
//std::cin >> xOffset;
// Wait 10 secs for kinect shutdown
// Sleep(10000);
// initialize Kinect
HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
if (FAILED(hr)) {
std::cout << "Failed to initialize Kinect." << std::endl;
return 1;
}
// 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 };
CONSOLE_SCREEN_BUFFER_INFO csbi;
int width = 0;
float drsLeft = 0;
float drsRight = 0;
int toolLeft = 0;
int toolRight = 0;
int toolWidth = 0;
bool leftTouch = false;
bool rightTouch = false;
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
leftLegPosPreview = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_LEFT];
rightLegPosPreview = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_RIGHT];
}
}
// keep updating screen width for fancy
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
width = (int)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
// fetch calibrated feet
drsLeft = xGrad * leftLegPosPreview.x + xOffset;
drsRight = xGrad * rightLegPosPreview.x + xOffset;
// translate to console window width
toolLeft = width * drsLeft;
toolRight = width * drsRight;
toolWidth = width * 0.05;
// foot lifting detection
// see how far foot currently is from known ground value
float fixedLeft = leftLegPosPreview.y - (yGrad * leftLegPosPreview.z + yOffset);
float fixedRight = rightLegPosPreview.y - (yGrad * rightLegPosPreview.z + yOffset);
// check for stepping
float errorMargin = 0.05;
if (fixedLeft > (fixedRight + errorMargin)) {
rightTouch = true;
leftTouch = false;
// std::cout << "right step\n";
}
else if (fixedRight > (fixedLeft + errorMargin)) {
leftTouch = true;
rightTouch = false;
// std::cout << "left step \n";
}
else {
leftTouch = true;
rightTouch = true;
// std::cout << "both step\n";
}
// print feet
for (int i = 0; i < width; i++) {
if ((i <= (toolLeft + toolWidth)) && (i >= (toolLeft - toolWidth)) && leftTouch) {
std::cout << "L";
}
else if ((i <= (toolRight + toolWidth)) && (i >= (toolRight - toolWidth)) && rightTouch) {
std::cout << "R";
}
else {
std::cout << " ";
}
}
// std::cout << std::to_string(fixedLeft) << " " << std::to_string(fixedRight) << std::endl;
}
// Clean up and exit
NuiSkeletonTrackingDisable();
NuiShutdown();
return 0;
}
+2
View File
@@ -0,0 +1,2 @@
#pragma once
int kinectTest(float xGrad, float xOffset, float yGrad, float yOffset, float zGrad, float zOffset);