Initial re-upload of spice2x-24-08-24
This commit is contained in:
152
games/ftt/ftt.cpp
Normal file
152
games/ftt/ftt.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#include "ftt.h"
|
||||
#include "nui.h"
|
||||
|
||||
#include "launcher/launcher.h"
|
||||
#include "util/detour.h"
|
||||
#include "util/libutils.h"
|
||||
#include "util/logging.h"
|
||||
#include "util/sigscan.h"
|
||||
#include "util/memutils.h"
|
||||
|
||||
typedef HRESULT (WINAPI *NuiGetSensorCount_t)(int *pCount);
|
||||
typedef HRESULT (WINAPI *NuiCreateSensorByIndex_t)(int index, INuiSensor **ppNuiSensor);
|
||||
|
||||
static NuiGetSensorCount_t NuiGetSensorCount_orig = nullptr;
|
||||
static NuiCreateSensorByIndex_t NuiCreateSensorByIndex_orig = nullptr;
|
||||
|
||||
static VTBL_TYPE(INuiSensor, NuiInitialize) INuiSensor_NuiInitialize_orig = nullptr;
|
||||
static VTBL_TYPE(INuiSensor, NuiImageStreamOpen) INuiSensor_NuiImageStreamOpen_orig = nullptr;
|
||||
|
||||
static HRESULT __stdcall INuiSensor_NuiInitialize_hook(INuiSensor *This, DWORD dwFlags) {
|
||||
log_misc("ftt", "INuiSensor::NuiInitialize hook hit (dwFlags: {})", dwFlags);
|
||||
|
||||
// call original function
|
||||
HRESULT ret = INuiSensor_NuiInitialize_orig(This, dwFlags);
|
||||
|
||||
// check return value
|
||||
if (FAILED(ret)) {
|
||||
log_warning("ftt", "INuiSensor::NuiInitialize failed, hr={}", FMT_HRESULT(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static HRESULT __stdcall INuiSensor_NuiImageStreamOpen_hook(
|
||||
INuiSensor *This,
|
||||
NUI_IMAGE_TYPE eImageType,
|
||||
NUI_IMAGE_RESOLUTION eResolution,
|
||||
DWORD dwImageFrameFlags,
|
||||
DWORD dwFrameLimit,
|
||||
HANDLE hNextFrameEvent,
|
||||
HANDLE *phStreamHandle) {
|
||||
log_misc("ftt", "INuiSensor::NuiImageStreamOpen hook hit");
|
||||
|
||||
// fix unsupported flag
|
||||
if (eImageType == NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX) {
|
||||
dwImageFrameFlags = 0;
|
||||
}
|
||||
|
||||
// call original function
|
||||
HRESULT ret = INuiSensor_NuiImageStreamOpen_orig(This, eImageType, eResolution, dwImageFrameFlags, dwFrameLimit, hNextFrameEvent, phStreamHandle);
|
||||
|
||||
// check return value
|
||||
if (FAILED(ret)) {
|
||||
log_warning("ftt", "INuiSensor::NuiImageStreamOpen failed, hr={}", FMT_HRESULT(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI NuiGetSensorCount_hook(int *pCount) {
|
||||
log_misc("ftt", "NuiGetSensorCount hook hit");
|
||||
|
||||
// call original function
|
||||
HRESULT ret = NuiGetSensorCount_orig(pCount);
|
||||
|
||||
// check return value
|
||||
if (FAILED(ret)) {
|
||||
log_warning("ftt", "NuiGetSensorCount failed, hr={}", FMT_HRESULT(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (pCount == nullptr) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
log_info("ftt", "found {} Kinect sensors", *pCount);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI NuiCreateSensorByIndex_hook(int index, INuiSensor **ppNuiSensor) {
|
||||
log_misc("ftt", "NuiCreateSensorByIndex hook hit");
|
||||
|
||||
// call original function
|
||||
HRESULT ret = NuiCreateSensorByIndex_orig(index, ppNuiSensor);
|
||||
|
||||
// check return value
|
||||
if (FAILED(ret)) {
|
||||
log_warning("ftt", "NuiCreateSensorByIndex failed, hr={}", FMT_HRESULT(ret));
|
||||
return ret;
|
||||
}
|
||||
if (ppNuiSensor == nullptr) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// save original functions
|
||||
INuiSensor *pNuiSensor = *ppNuiSensor;
|
||||
if (INuiSensor_NuiInitialize_orig == nullptr) {
|
||||
INuiSensor_NuiInitialize_orig = pNuiSensor->lpVtbl->NuiInitialize;
|
||||
}
|
||||
if (INuiSensor_NuiImageStreamOpen_orig == nullptr) {
|
||||
INuiSensor_NuiImageStreamOpen_orig = pNuiSensor->lpVtbl->NuiImageStreamOpen;
|
||||
}
|
||||
|
||||
// unlock interface
|
||||
memutils::VProtectGuard pNuiSensor_guard(pNuiSensor->lpVtbl);
|
||||
|
||||
// hook interface
|
||||
pNuiSensor->lpVtbl->NuiInitialize = INuiSensor_NuiInitialize_hook;
|
||||
pNuiSensor->lpVtbl->NuiImageStreamOpen = INuiSensor_NuiImageStreamOpen_hook;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace games::ftt {
|
||||
|
||||
FTTGame::FTTGame() : Game("FutureTomTom") {
|
||||
}
|
||||
|
||||
void FTTGame::attach() {
|
||||
Game::attach();
|
||||
|
||||
// load main game module so patches work
|
||||
auto game_dll = libutils::load_library(MODULE_PATH / "gamemmd.dll");
|
||||
|
||||
// patch kinect to always poll
|
||||
if (!replace_pattern(game_dll,
|
||||
"78??837B340775??488BCBE8",
|
||||
"????????????9090????????",
|
||||
0,
|
||||
0))
|
||||
{
|
||||
log_warning("ftt", "kinect polling patch failed");
|
||||
}
|
||||
|
||||
// patch kinect to not time out
|
||||
if (!replace_pattern(game_dll,
|
||||
"3D3075000072??C74334060000004883C420",
|
||||
"??????????????90909090909090????????",
|
||||
0,
|
||||
0))
|
||||
{
|
||||
log_warning("ftt", "kinect timeout patch failed");
|
||||
}
|
||||
|
||||
// hook Kinect calls
|
||||
NuiGetSensorCount_orig = (NuiGetSensorCount_t) detour::iat_ordinal(
|
||||
"Kinect10.dll", 5, (void *) NuiGetSensorCount_hook, game_dll);
|
||||
NuiCreateSensorByIndex_orig = (NuiCreateSensorByIndex_t) detour::iat_ordinal(
|
||||
"Kinect10.dll", 6, (void *) NuiCreateSensorByIndex_hook, game_dll);
|
||||
}
|
||||
}
|
||||
12
games/ftt/ftt.h
Normal file
12
games/ftt/ftt.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "games/game.h"
|
||||
|
||||
namespace games::ftt {
|
||||
|
||||
class FTTGame : public games::Game {
|
||||
public:
|
||||
FTTGame();
|
||||
virtual void attach() override;
|
||||
};
|
||||
}
|
||||
65
games/ftt/io.cpp
Normal file
65
games/ftt/io.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "io.h"
|
||||
|
||||
std::vector<Button> &games::ftt::get_buttons() {
|
||||
static std::vector<Button> buttons;
|
||||
|
||||
if (buttons.empty()) {
|
||||
buttons = GameAPI::Buttons::getButtons("FutureTomTom");
|
||||
|
||||
GameAPI::Buttons::sortButtons(
|
||||
&buttons,
|
||||
"Service",
|
||||
"Test",
|
||||
"Pad 1",
|
||||
"Pad 2",
|
||||
"Pad 3",
|
||||
"Pad 4"
|
||||
);
|
||||
}
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
std::vector<Analog> &games::ftt::get_analogs() {
|
||||
static std::vector<Analog> analogs;
|
||||
|
||||
if (analogs.empty()) {
|
||||
analogs = GameAPI::Analogs::getAnalogs("FutureTomTom");
|
||||
|
||||
GameAPI::Analogs::sortAnalogs(
|
||||
&analogs,
|
||||
"Pad 1",
|
||||
"Pad 2",
|
||||
"Pad 3",
|
||||
"Pad 4"
|
||||
);
|
||||
}
|
||||
|
||||
return analogs;
|
||||
}
|
||||
|
||||
std::vector<Light> &games::ftt::get_lights() {
|
||||
static std::vector<Light> lights;
|
||||
|
||||
if (lights.empty()) {
|
||||
lights = GameAPI::Lights::getLights("FutureTomTom");
|
||||
|
||||
GameAPI::Lights::sortLights(
|
||||
&lights,
|
||||
"Pad 1 Red",
|
||||
"Pad 1 Green",
|
||||
"Pad 1 Blue",
|
||||
"Pad 2 Red",
|
||||
"Pad 2 Green",
|
||||
"Pad 2 Blue",
|
||||
"Pad 3 Red",
|
||||
"Pad 3 Green",
|
||||
"Pad 3 Blue",
|
||||
"Pad 4 Red",
|
||||
"Pad 4 Green",
|
||||
"Pad 4 Blue"
|
||||
);
|
||||
}
|
||||
|
||||
return lights;
|
||||
}
|
||||
52
games/ftt/io.h
Normal file
52
games/ftt/io.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "cfg/api.h"
|
||||
|
||||
namespace games::ftt {
|
||||
|
||||
// all buttons in correct order
|
||||
namespace Buttons {
|
||||
enum {
|
||||
Service,
|
||||
Test,
|
||||
Pad1,
|
||||
Pad2,
|
||||
Pad3,
|
||||
Pad4,
|
||||
};
|
||||
}
|
||||
|
||||
// all analogs in correct order
|
||||
namespace Analogs {
|
||||
enum {
|
||||
Pad1,
|
||||
Pad2,
|
||||
Pad3,
|
||||
Pad4,
|
||||
};
|
||||
}
|
||||
|
||||
// all lights in correct order
|
||||
namespace Lights {
|
||||
enum {
|
||||
Pad1_R,
|
||||
Pad1_G,
|
||||
Pad1_B,
|
||||
Pad2_R,
|
||||
Pad2_G,
|
||||
Pad2_B,
|
||||
Pad3_R,
|
||||
Pad3_G,
|
||||
Pad3_B,
|
||||
Pad4_R,
|
||||
Pad4_G,
|
||||
Pad4_B,
|
||||
};
|
||||
}
|
||||
|
||||
// getters
|
||||
std::vector<Button> &get_buttons();
|
||||
std::vector<Analog> &get_analogs();
|
||||
std::vector<Light> &get_lights();
|
||||
}
|
||||
183
games/ftt/nui.h
Normal file
183
games/ftt/nui.h
Normal file
@@ -0,0 +1,183 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <unknwn.h>
|
||||
|
||||
enum NUI_IMAGE_TYPE {
|
||||
NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX = 0x0,
|
||||
NUI_IMAGE_TYPE_COLOR = 0x1,
|
||||
NUI_IMAGE_TYPE_COLOR_YUV = 0x2,
|
||||
NUI_IMAGE_TYPE_COLOR_RAW_YUV = 0x3,
|
||||
NUI_IMAGE_TYPE_DEPTH = 0x4,
|
||||
NUI_IMAGE_TYPE_COLOR_INFRARED = 0x5,
|
||||
NUI_IMAGE_TYPE_COLOR_RAW_BAYER = 0x6,
|
||||
};
|
||||
|
||||
enum NUI_IMAGE_RESOLUTION {
|
||||
NUI_IMAGE_RESOLUTION_80x60 = 0x0,
|
||||
NUI_IMAGE_RESOLUTION_320x240 = 0x1,
|
||||
NUI_IMAGE_RESOLUTION_640x480 = 0x2,
|
||||
NUI_IMAGE_RESOLUTION_1280x960 = 0x3,
|
||||
NUI_IMAGE_RESOLUTION_INVALID = 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
#pragma pack(push, 8)
|
||||
struct INuiSensor {
|
||||
struct INuiSensorVtbl *lpVtbl;
|
||||
};
|
||||
|
||||
struct INuiSensorVtbl {
|
||||
HRESULT (__stdcall *QueryInterface)(IUnknown *This, const IID *const riid, void **ppvObject);
|
||||
ULONG (__stdcall *AddRef)(IUnknown *This);
|
||||
ULONG (__stdcall *Release)(IUnknown *This);
|
||||
|
||||
HRESULT (__stdcall *NuiInitialize)(
|
||||
INuiSensor *This,
|
||||
DWORD dwFlags);
|
||||
|
||||
void (__stdcall *NuiShutdown)(INuiSensor *This);
|
||||
|
||||
HRESULT (__stdcall *NuiSetFrameEndEvent)(
|
||||
INuiSensor *This,
|
||||
HANDLE hEvent,
|
||||
DWORD dwFrameEventFlag);
|
||||
|
||||
HRESULT (__stdcall *NuiImageStreamOpen)(
|
||||
INuiSensor *This,
|
||||
NUI_IMAGE_TYPE eImageType,
|
||||
NUI_IMAGE_RESOLUTION eResolution,
|
||||
DWORD dwImageFrameFlags,
|
||||
DWORD dwFrameLimit,
|
||||
HANDLE hNextFrameEvent,
|
||||
HANDLE *phStreamHandle);
|
||||
|
||||
HRESULT (__stdcall *NuiImageStreamSetImageFrameFlags)(
|
||||
INuiSensor *This,
|
||||
HANDLE hStream,
|
||||
DWORD dwImageFrameFlags);
|
||||
|
||||
HRESULT (__stdcall *NuiImageStreamGetImageFrameFlags)(
|
||||
INuiSensor *This,
|
||||
HANDLE hStream,
|
||||
DWORD *pdwImageFrameFlags);
|
||||
|
||||
HRESULT (__stdcall *NuiImageStreamGetNextFrame)(
|
||||
INuiSensor *This,
|
||||
HANDLE hStream,
|
||||
DWORD dwMillisecondsToWait,
|
||||
void *pImageFrame);
|
||||
|
||||
HRESULT (__stdcall *NuiImageStreamReleaseFrame)(
|
||||
INuiSensor *This,
|
||||
HANDLE hStream,
|
||||
void *pImageFrame);
|
||||
|
||||
HRESULT (__stdcall *NuiImageGetColorPixelCoordinatesFromDepthPixel)(
|
||||
INuiSensor *This,
|
||||
DWORD eColorResolution,
|
||||
const void *pcViewArea,
|
||||
LONG lDepthX,
|
||||
LONG lDepthY,
|
||||
USHORT usDepthValue,
|
||||
LONG *plColorX,
|
||||
LONG *plColorY);
|
||||
|
||||
HRESULT (__stdcall *NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution)(
|
||||
INuiSensor *This,
|
||||
DWORD eColorResolution,
|
||||
DWORD eDepthResolution,
|
||||
const void *pcViewArea,
|
||||
LONG lDepthX,
|
||||
LONG lDepthY,
|
||||
USHORT usDepthValue,
|
||||
LONG *plColorX,
|
||||
LONG *plColorY);
|
||||
|
||||
HRESULT (__stdcall *NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution)(
|
||||
INuiSensor *This,
|
||||
DWORD eColorResolution,
|
||||
DWORD eDepthResolution,
|
||||
DWORD cDepthValues,
|
||||
USHORT *pDepthValues,
|
||||
DWORD cColorCoordinates,
|
||||
LONG *pColorCoordinates);
|
||||
|
||||
HRESULT (__stdcall *NuiCameraElevationSetAngle)(
|
||||
INuiSensor *This,
|
||||
LONG lAngleDegrees);
|
||||
|
||||
HRESULT (__stdcall *NuiCameraElevationGetAngle)(
|
||||
INuiSensor *This,
|
||||
LONG *plAngleDegrees);
|
||||
|
||||
HRESULT (__stdcall *NuiSkeletonTrackingEnable)(
|
||||
INuiSensor *This,
|
||||
HANDLE hNextFrameEvent,
|
||||
DWORD dwFlags);
|
||||
|
||||
HRESULT (__stdcall *NuiSkeletonTrackingDisable)(
|
||||
INuiSensor *This);
|
||||
|
||||
HRESULT (__stdcall *NuiSkeletonSetTrackedSkeletons)(
|
||||
INuiSensor *This,
|
||||
DWORD *TrackingIDs);
|
||||
|
||||
HRESULT (__stdcall *NuiSkeletonGetNextFrame)(
|
||||
INuiSensor *This,
|
||||
DWORD dwMillisecondsToWait,
|
||||
void *pSkeletonFrame);
|
||||
|
||||
HRESULT (__stdcall *NuiTransformSmooth)(
|
||||
INuiSensor *This,
|
||||
void *pSkeletonFrame,
|
||||
const void *pSmoothingParams);
|
||||
|
||||
HRESULT (__stdcall *NuiGetAudioSource)(
|
||||
INuiSensor *This,
|
||||
void **ppDmo);
|
||||
|
||||
int (__stdcall *NuiInstanceIndex)(
|
||||
INuiSensor *This);
|
||||
|
||||
BSTR (__stdcall *NuiDeviceConnectionId)(
|
||||
INuiSensor *This);
|
||||
|
||||
BSTR (__stdcall *NuiUniqueId)(
|
||||
INuiSensor *This);
|
||||
|
||||
BSTR (__stdcall *NuiAudioArrayId)(
|
||||
INuiSensor *This);
|
||||
|
||||
HRESULT (__stdcall *NuiStatus)(
|
||||
INuiSensor *This);
|
||||
|
||||
DWORD (__stdcall *NuiInitializationFlags)(
|
||||
INuiSensor *This);
|
||||
|
||||
HRESULT (__stdcall *NuiGetCoordinateMapper)(
|
||||
INuiSensor *This,
|
||||
void **pMapping);
|
||||
|
||||
HRESULT (__stdcall *NuiImageFrameGetDepthImagePixelFrameTexture)(
|
||||
INuiSensor *This,
|
||||
HANDLE hStream,
|
||||
void *pImageFrame,
|
||||
BOOL *pNearMode,
|
||||
void **ppFrameTexture);
|
||||
|
||||
HRESULT (__stdcall *NuiGetColorCameraSettings)(
|
||||
INuiSensor *This,
|
||||
void **pCameraSettings);
|
||||
|
||||
BOOL (__stdcall *NuiGetForceInfraredEmitterOff)(
|
||||
INuiSensor *This);
|
||||
|
||||
HRESULT (__stdcall *NuiSetForceInfraredEmitterOff)(
|
||||
INuiSensor *This,
|
||||
BOOL fForceInfraredEmitterOff);
|
||||
|
||||
HRESULT (__stdcall *NuiAccelerometerGetCurrentReading)(
|
||||
INuiSensor *This,
|
||||
void *pReading);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
Reference in New Issue
Block a user