Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit d38193f

Browse files
committed
First commit.
1 parent 9f34b16 commit d38193f

File tree

5 files changed

+273
-0
lines changed

5 files changed

+273
-0
lines changed

dinput8_nojoy/dinput8_nojoy.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "dinput8_nojoy.hpp"
2+
3+
typedef HRESULT (WINAPI *DirectInput8Create_t)(HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN);
4+
typedef HRESULT (WINAPI *EnumDevices_t)(LPDIRECTINPUT8, DWORD, LPDIENUMDEVICESCALLBACK, LPVOID, DWORD);
5+
6+
HMODULE dinput8;
7+
DirectInput8Create_t DirectInput8Create_orig;
8+
EnumDevices_t EnumDevices_orig;
9+
LPDIENUMDEVICESCALLBACK EnumDevices_callback_orig;
10+
11+
BOOL WINAPI DllMain(
12+
HINSTANCE inst,
13+
unsigned long reason,
14+
void* info
15+
) {
16+
switch (reason) {
17+
case DLL_PROCESS_ATTACH: {
18+
dinput8 = LoadLibrary(LR"(C:\Windows\System32\dinput8.dll)");
19+
DirectInput8Create_orig = reinterpret_cast<DirectInput8Create_t>(GetProcAddress(dinput8, "DirectInput8Create"));
20+
} break;
21+
case DLL_PROCESS_DETACH: {
22+
FreeLibrary(dinput8);
23+
} break;
24+
}
25+
26+
return TRUE;
27+
}
28+
29+
BOOL WINAPI EnumDevices_callback_hook(LPCDIDEVICEINSTANCE device, LPVOID data) {
30+
auto type = device->dwDevType & 0x1F;
31+
if (type == DI8DEVTYPE_MOUSE || type == DI8DEVTYPE_KEYBOARD) {
32+
return EnumDevices_callback_orig(device, data);
33+
} else {
34+
return DIENUM_CONTINUE;
35+
}
36+
}
37+
38+
HRESULT WINAPI EnumDevices_hook(
39+
LPDIRECTINPUT8 iface,
40+
DWORD type,
41+
LPDIENUMDEVICESCALLBACK callback,
42+
LPVOID data,
43+
DWORD flags) {
44+
EnumDevices_callback_orig = callback;
45+
return EnumDevices_orig(iface, type, EnumDevices_callback_hook, data, flags);
46+
}
47+
48+
extern "C" long WINAPI DirectInput8Create_hook(
49+
HINSTANCE inst,
50+
DWORD ver,
51+
REFIID id,
52+
LPVOID* iface,
53+
LPUNKNOWN aggreg) {
54+
auto retval = DirectInput8Create_orig(inst, ver, id, iface, aggreg);
55+
56+
auto idinput8 = reinterpret_cast<IDirectInput8*>(*iface);
57+
auto& EnumDevices_vtable = idinput8->lpVtbl->EnumDevices;
58+
59+
if (EnumDevices_vtable != EnumDevices_hook) {
60+
EnumDevices_orig = EnumDevices_vtable;
61+
EnumDevices_vtable = EnumDevices_hook;
62+
}
63+
64+
return retval;
65+
}

dinput8_nojoy/dinput8_nojoy.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LIBRARY dinput8
2+
EXPORTS
3+
DirectInput8Create = _DirectInput8Create_hook@20 @1

dinput8_nojoy/dinput8_nojoy.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#define DIRECTINPUT_VERSION 0x0800
4+
#define CINTERFACE
5+
#include <dinput.h>
6+
7+
extern "C" HRESULT WINAPI DirectInput8Create_hook(HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN);
8+
HRESULT WINAPI EnumDevices_hook(LPDIRECTINPUT8, DWORD, LPDIENUMDEVICESCALLBACK, LPVOID, DWORD);
9+
BOOL WINAPI EnumDevices_callback_hook(LPCDIDEVICEINSTANCE, LPVOID);

dinput8_nojoy/dinput8_nojoy.vcxproj

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{5232A0A8-E3F2-4166-B28E-DD69B96243F3}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>dinput8_nojoy</RootNamespace>
25+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>DynamicLibrary</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v140</PlatformToolset>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>DynamicLibrary</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v140</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>DynamicLibrary</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v140</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>DynamicLibrary</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v140</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<LinkIncremental>true</LinkIncremental>
74+
<TargetName>dinput8</TargetName>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77+
<LinkIncremental>true</LinkIncremental>
78+
<TargetName>dinput8</TargetName>
79+
</PropertyGroup>
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
81+
<LinkIncremental>false</LinkIncremental>
82+
<TargetName>dinput8</TargetName>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
85+
<LinkIncremental>false</LinkIncremental>
86+
<TargetName>dinput8</TargetName>
87+
</PropertyGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
89+
<ClCompile>
90+
<PrecompiledHeader>
91+
</PrecompiledHeader>
92+
<WarningLevel>Level3</WarningLevel>
93+
<Optimization>Disabled</Optimization>
94+
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DINPUT8_NOJOY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
95+
</ClCompile>
96+
<Link>
97+
<SubSystem>Windows</SubSystem>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
<ModuleDefinitionFile>dinput8_nojoy.def</ModuleDefinitionFile>
100+
</Link>
101+
</ItemDefinitionGroup>
102+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
103+
<ClCompile>
104+
<PrecompiledHeader>
105+
</PrecompiledHeader>
106+
<WarningLevel>Level3</WarningLevel>
107+
<Optimization>Disabled</Optimization>
108+
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;DINPUT8_NOJOY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109+
</ClCompile>
110+
<Link>
111+
<SubSystem>Windows</SubSystem>
112+
<GenerateDebugInformation>true</GenerateDebugInformation>
113+
<ModuleDefinitionFile>dinput8_nojoy.def</ModuleDefinitionFile>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
117+
<ClCompile>
118+
<WarningLevel>Level3</WarningLevel>
119+
<PrecompiledHeader>
120+
</PrecompiledHeader>
121+
<Optimization>MaxSpeed</Optimization>
122+
<FunctionLevelLinking>true</FunctionLevelLinking>
123+
<IntrinsicFunctions>true</IntrinsicFunctions>
124+
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DINPUT8_NOJOY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
</ClCompile>
126+
<Link>
127+
<SubSystem>Windows</SubSystem>
128+
<GenerateDebugInformation>true</GenerateDebugInformation>
129+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
130+
<OptimizeReferences>true</OptimizeReferences>
131+
<ModuleDefinitionFile>dinput8_nojoy.def</ModuleDefinitionFile>
132+
</Link>
133+
</ItemDefinitionGroup>
134+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
135+
<ClCompile>
136+
<WarningLevel>Level3</WarningLevel>
137+
<PrecompiledHeader>
138+
</PrecompiledHeader>
139+
<Optimization>MaxSpeed</Optimization>
140+
<FunctionLevelLinking>true</FunctionLevelLinking>
141+
<IntrinsicFunctions>true</IntrinsicFunctions>
142+
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;DINPUT8_NOJOY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
143+
</ClCompile>
144+
<Link>
145+
<SubSystem>Windows</SubSystem>
146+
<GenerateDebugInformation>true</GenerateDebugInformation>
147+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
148+
<OptimizeReferences>true</OptimizeReferences>
149+
<ModuleDefinitionFile>dinput8_nojoy.def</ModuleDefinitionFile>
150+
</Link>
151+
</ItemDefinitionGroup>
152+
<ItemGroup>
153+
<None Include="dinput8_nojoy.def" />
154+
</ItemGroup>
155+
<ItemGroup>
156+
<ClCompile Include="dinput8_nojoy.cpp" />
157+
</ItemGroup>
158+
<ItemGroup>
159+
<ClInclude Include="dinput8_nojoy.hpp" />
160+
</ItemGroup>
161+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
162+
<ImportGroup Label="ExtensionTargets">
163+
</ImportGroup>
164+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<None Include="dinput8_nojoy.def">
19+
<Filter>Source Files</Filter>
20+
</None>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="dinput8_nojoy.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
<ItemGroup>
28+
<ClInclude Include="dinput8_nojoy.hpp">
29+
<Filter>Header Files</Filter>
30+
</ClInclude>
31+
</ItemGroup>
32+
</Project>

0 commit comments

Comments
 (0)