├── Common ├── License.txt └── Logging.h ├── DirectX81SDK └── include │ ├── d3d.h │ ├── d3d8.h │ ├── d3d8caps.h │ ├── d3d8types.h │ ├── ddraw.h │ └── ddrawex.h ├── License.txt ├── README.md ├── bin ├── dinput8.dll └── dinput8_verbose.dll ├── dinput8.sln └── dinput8 ├── AddressLookupTable.h ├── IClassFactory.cpp ├── IClassFactory.h ├── IDirectInput8A.cpp ├── IDirectInput8A.h ├── IDirectInput8W.cpp ├── IDirectInput8W.h ├── IDirectInputDevice8A.cpp ├── IDirectInputDevice8A.h ├── IDirectInputDevice8W.cpp ├── IDirectInputDevice8W.h ├── IDirectInputEffect.cpp ├── IDirectInputEffect.h ├── IDirectInputEnumDevice.cpp ├── IDirectInputEnumDevice.h ├── IDirectInputEnumEffect.cpp ├── IDirectInputEnumEffect.h ├── InterfaceQuery.cpp ├── License.txt ├── dinput8.def ├── dinput8.h ├── dinput8.vcxproj └── dllmain.cpp /Common/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /Common/Logging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Log 7 | { 8 | public: 9 | Log() {} 10 | ~Log() 11 | { 12 | if (LOG.is_open()) 13 | { 14 | LOG << std::endl; 15 | } 16 | } 17 | 18 | template 19 | Log& operator<<(const T& t) 20 | { 21 | if (LOG.is_open()) 22 | { 23 | LOG << t; 24 | } 25 | return *this; 26 | } 27 | private: 28 | static std::ofstream LOG; 29 | }; 30 | 31 | static std::ostream& operator<<(std::ostream& os, const wchar_t* wchr) 32 | { 33 | std::wstring ws(wchr); 34 | return os << std::string(ws.begin(), ws.end()).c_str(); 35 | } 36 | 37 | static void logf(char * fmt, ...) 38 | { 39 | va_list ap; 40 | va_start(ap, fmt); 41 | auto size = vsnprintf(nullptr, 0, fmt, ap); 42 | std::string output(size + 1, '\0'); 43 | vsprintf_s(&output[0], size + 1, fmt, ap); 44 | Log() << output.c_str(); 45 | va_end(ap); 46 | } 47 | 48 | static void logf(wchar_t * fmt, ...) 49 | { 50 | va_list ap; 51 | va_start(ap, fmt); 52 | #pragma warning(suppress: 4996) 53 | auto size = _vsnwprintf(nullptr, 0, fmt, ap); 54 | std::wstring output(size + 1, '\0'); 55 | vswprintf_s(&output[0], size + 1, fmt, ap); 56 | Log() << output.c_str(); 57 | va_end(ap); 58 | } 59 | -------------------------------------------------------------------------------- /DirectX81SDK/include/d3d8caps.h: -------------------------------------------------------------------------------- 1 | /*==========================================================================; 2 | * 3 | * Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | * 5 | * File: d3d8caps.h 6 | * Content: Direct3D capabilities include file 7 | * 8 | ***************************************************************************/ 9 | 10 | #ifndef _D3D8CAPS_H 11 | #define _D3D8CAPS_H 12 | 13 | #ifndef DIRECT3D_VERSION 14 | #define DIRECT3D_VERSION 0x0800 15 | #endif //DIRECT3D_VERSION 16 | 17 | // include this file content only if compiling for DX8 interfaces 18 | #if(DIRECT3D_VERSION >= 0x0800) 19 | 20 | #include 21 | 22 | #pragma region Desktop Family 23 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 24 | 25 | #if defined(_X86_) || defined(_IA64_) 26 | #pragma pack(4) 27 | #endif 28 | 29 | typedef struct _D3DCAPS8 30 | { 31 | /* Device Info */ 32 | D3DDEVTYPE DeviceType; 33 | UINT AdapterOrdinal; 34 | 35 | /* Caps from DX7 Draw */ 36 | DWORD Caps; 37 | DWORD Caps2; 38 | DWORD Caps3; 39 | DWORD PresentationIntervals; 40 | 41 | /* Cursor Caps */ 42 | DWORD CursorCaps; 43 | 44 | /* 3D Device Caps */ 45 | DWORD DevCaps; 46 | 47 | DWORD PrimitiveMiscCaps; 48 | DWORD RasterCaps; 49 | DWORD ZCmpCaps; 50 | DWORD SrcBlendCaps; 51 | DWORD DestBlendCaps; 52 | DWORD AlphaCmpCaps; 53 | DWORD ShadeCaps; 54 | DWORD TextureCaps; 55 | DWORD TextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DTexture8's 56 | DWORD CubeTextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DCubeTexture8's 57 | DWORD VolumeTextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DVolumeTexture8's 58 | DWORD TextureAddressCaps; // D3DPTADDRESSCAPS for IDirect3DTexture8's 59 | DWORD VolumeTextureAddressCaps; // D3DPTADDRESSCAPS for IDirect3DVolumeTexture8's 60 | 61 | DWORD LineCaps; // D3DLINECAPS 62 | 63 | DWORD MaxTextureWidth, MaxTextureHeight; 64 | DWORD MaxVolumeExtent; 65 | 66 | DWORD MaxTextureRepeat; 67 | DWORD MaxTextureAspectRatio; 68 | DWORD MaxAnisotropy; 69 | float MaxVertexW; 70 | 71 | float GuardBandLeft; 72 | float GuardBandTop; 73 | float GuardBandRight; 74 | float GuardBandBottom; 75 | 76 | float ExtentsAdjust; 77 | DWORD StencilCaps; 78 | 79 | DWORD FVFCaps; 80 | DWORD TextureOpCaps; 81 | DWORD MaxTextureBlendStages; 82 | DWORD MaxSimultaneousTextures; 83 | 84 | DWORD VertexProcessingCaps; 85 | DWORD MaxActiveLights; 86 | DWORD MaxUserClipPlanes; 87 | DWORD MaxVertexBlendMatrices; 88 | DWORD MaxVertexBlendMatrixIndex; 89 | 90 | float MaxPointSize; 91 | 92 | DWORD MaxPrimitiveCount; // max number of primitives per DrawPrimitive call 93 | DWORD MaxVertexIndex; 94 | DWORD MaxStreams; 95 | DWORD MaxStreamStride; // max stride for SetStreamSource 96 | 97 | DWORD VertexShaderVersion; 98 | DWORD MaxVertexShaderConst; // number of vertex shader constant registers 99 | 100 | DWORD PixelShaderVersion; 101 | float MaxPixelShaderValue; // max value of pixel shader arithmetic component 102 | 103 | } D3DCAPS8; 104 | 105 | // 106 | // BIT DEFINES FOR D3DCAPS8 DWORD MEMBERS 107 | // 108 | 109 | // 110 | // Caps 111 | // 112 | #define D3DCAPS_READ_SCANLINE 0x00020000L 113 | 114 | // 115 | // Caps2 116 | // 117 | #define D3DCAPS2_NO2DDURING3DSCENE 0x00000002L 118 | #define D3DCAPS2_FULLSCREENGAMMA 0x00020000L 119 | #define D3DCAPS2_CANRENDERWINDOWED 0x00080000L 120 | #define D3DCAPS2_CANCALIBRATEGAMMA 0x00100000L 121 | #define D3DCAPS2_RESERVED 0x02000000L 122 | #define D3DCAPS2_CANMANAGERESOURCE 0x10000000L 123 | #define D3DCAPS2_DYNAMICTEXTURES 0x20000000L 124 | 125 | // 126 | // Caps3 127 | // 128 | #define D3DCAPS3_RESERVED 0x8000001fL 129 | 130 | // Indicates that the device can respect the ALPHABLENDENABLE render state 131 | // when fullscreen while using the FLIP or DISCARD swap effect. 132 | // COPY and COPYVSYNC swap effects work whether or not this flag is set. 133 | #define D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD 0x00000020L 134 | 135 | // 136 | // PresentationIntervals 137 | // 138 | #define D3DPRESENT_INTERVAL_DEFAULT 0x00000000L 139 | #define D3DPRESENT_INTERVAL_ONE 0x00000001L 140 | #define D3DPRESENT_INTERVAL_TWO 0x00000002L 141 | #define D3DPRESENT_INTERVAL_THREE 0x00000004L 142 | #define D3DPRESENT_INTERVAL_FOUR 0x00000008L 143 | #define D3DPRESENT_INTERVAL_IMMEDIATE 0x80000000L 144 | 145 | // 146 | // CursorCaps 147 | // 148 | // Driver supports HW color cursor in at least hi-res modes(height >=400) 149 | #define D3DCURSORCAPS_COLOR 0x00000001L 150 | // Driver supports HW cursor also in low-res modes(height < 400) 151 | #define D3DCURSORCAPS_LOWRES 0x00000002L 152 | 153 | // 154 | // DevCaps 155 | // 156 | #define D3DDEVCAPS_EXECUTESYSTEMMEMORY 0x00000010L /* Device can use execute buffers from system memory */ 157 | #define D3DDEVCAPS_EXECUTEVIDEOMEMORY 0x00000020L /* Device can use execute buffers from video memory */ 158 | #define D3DDEVCAPS_TLVERTEXSYSTEMMEMORY 0x00000040L /* Device can use TL buffers from system memory */ 159 | #define D3DDEVCAPS_TLVERTEXVIDEOMEMORY 0x00000080L /* Device can use TL buffers from video memory */ 160 | #define D3DDEVCAPS_TEXTURESYSTEMMEMORY 0x00000100L /* Device can texture from system memory */ 161 | #define D3DDEVCAPS_TEXTUREVIDEOMEMORY 0x00000200L /* Device can texture from device memory */ 162 | #define D3DDEVCAPS_DRAWPRIMTLVERTEX 0x00000400L /* Device can draw TLVERTEX primitives */ 163 | #define D3DDEVCAPS_CANRENDERAFTERFLIP 0x00000800L /* Device can render without waiting for flip to complete */ 164 | #define D3DDEVCAPS_TEXTURENONLOCALVIDMEM 0x00001000L /* Device can texture from nonlocal video memory */ 165 | #define D3DDEVCAPS_DRAWPRIMITIVES2 0x00002000L /* Device can support DrawPrimitives2 */ 166 | #define D3DDEVCAPS_SEPARATETEXTUREMEMORIES 0x00004000L /* Device is texturing from separate memory pools */ 167 | #define D3DDEVCAPS_DRAWPRIMITIVES2EX 0x00008000L /* Device can support Extended DrawPrimitives2 i.e. DX7 compliant driver*/ 168 | #define D3DDEVCAPS_HWTRANSFORMANDLIGHT 0x00010000L /* Device can support transformation and lighting in hardware and DRAWPRIMITIVES2EX must be also */ 169 | #define D3DDEVCAPS_CANBLTSYSTONONLOCAL 0x00020000L /* Device supports a Tex Blt from system memory to non-local vidmem */ 170 | #define D3DDEVCAPS_HWRASTERIZATION 0x00080000L /* Device has HW acceleration for rasterization */ 171 | #define D3DDEVCAPS_PUREDEVICE 0x00100000L /* Device supports D3DCREATE_PUREDEVICE */ 172 | #define D3DDEVCAPS_QUINTICRTPATCHES 0x00200000L /* Device supports quintic Beziers and BSplines */ 173 | #define D3DDEVCAPS_RTPATCHES 0x00400000L /* Device supports Rect and Tri patches */ 174 | #define D3DDEVCAPS_RTPATCHHANDLEZERO 0x00800000L /* Indicates that RT Patches may be drawn efficiently using handle 0 */ 175 | #define D3DDEVCAPS_NPATCHES 0x01000000L /* Device supports N-Patches */ 176 | 177 | // 178 | // PrimitiveMiscCaps 179 | // 180 | #define D3DPMISCCAPS_MASKZ 0x00000002L 181 | #define D3DPMISCCAPS_LINEPATTERNREP 0x00000004L 182 | #define D3DPMISCCAPS_CULLNONE 0x00000010L 183 | #define D3DPMISCCAPS_CULLCW 0x00000020L 184 | #define D3DPMISCCAPS_CULLCCW 0x00000040L 185 | #define D3DPMISCCAPS_COLORWRITEENABLE 0x00000080L 186 | #define D3DPMISCCAPS_CLIPPLANESCALEDPOINTS 0x00000100L /* Device correctly clips scaled points to clip planes */ 187 | #define D3DPMISCCAPS_CLIPTLVERTS 0x00000200L /* device will clip post-transformed vertex primitives */ 188 | #define D3DPMISCCAPS_TSSARGTEMP 0x00000400L /* device supports D3DTA_TEMP for temporary register */ 189 | #define D3DPMISCCAPS_BLENDOP 0x00000800L /* device supports D3DRS_BLENDOP */ 190 | #define D3DPMISCCAPS_NULLREFERENCE 0x00001000L /* Reference Device that doesnt render */ 191 | 192 | // 193 | // LineCaps 194 | // 195 | #define D3DLINECAPS_TEXTURE 0x00000001L 196 | #define D3DLINECAPS_ZTEST 0x00000002L 197 | #define D3DLINECAPS_BLEND 0x00000004L 198 | #define D3DLINECAPS_ALPHACMP 0x00000008L 199 | #define D3DLINECAPS_FOG 0x00000010L 200 | 201 | // 202 | // RasterCaps 203 | // 204 | #define D3DPRASTERCAPS_DITHER 0x00000001L 205 | #define D3DPRASTERCAPS_PAT 0x00000008L 206 | #define D3DPRASTERCAPS_ZTEST 0x00000010L 207 | #define D3DPRASTERCAPS_FOGVERTEX 0x00000080L 208 | #define D3DPRASTERCAPS_FOGTABLE 0x00000100L 209 | #define D3DPRASTERCAPS_ANTIALIASEDGES 0x00001000L 210 | #define D3DPRASTERCAPS_MIPMAPLODBIAS 0x00002000L 211 | #define D3DPRASTERCAPS_ZBIAS 0x00004000L 212 | #define D3DPRASTERCAPS_ZBUFFERLESSHSR 0x00008000L 213 | #define D3DPRASTERCAPS_FOGRANGE 0x00010000L 214 | #define D3DPRASTERCAPS_ANISOTROPY 0x00020000L 215 | #define D3DPRASTERCAPS_WBUFFER 0x00040000L 216 | #define D3DPRASTERCAPS_WFOG 0x00100000L 217 | #define D3DPRASTERCAPS_ZFOG 0x00200000L 218 | #define D3DPRASTERCAPS_COLORPERSPECTIVE 0x00400000L /* Device iterates colors perspective correct */ 219 | #define D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE 0x00800000L 220 | 221 | // 222 | // ZCmpCaps, AlphaCmpCaps 223 | // 224 | #define D3DPCMPCAPS_NEVER 0x00000001L 225 | #define D3DPCMPCAPS_LESS 0x00000002L 226 | #define D3DPCMPCAPS_EQUAL 0x00000004L 227 | #define D3DPCMPCAPS_LESSEQUAL 0x00000008L 228 | #define D3DPCMPCAPS_GREATER 0x00000010L 229 | #define D3DPCMPCAPS_NOTEQUAL 0x00000020L 230 | #define D3DPCMPCAPS_GREATEREQUAL 0x00000040L 231 | #define D3DPCMPCAPS_ALWAYS 0x00000080L 232 | 233 | // 234 | // SourceBlendCaps, DestBlendCaps 235 | // 236 | #define D3DPBLENDCAPS_ZERO 0x00000001L 237 | #define D3DPBLENDCAPS_ONE 0x00000002L 238 | #define D3DPBLENDCAPS_SRCCOLOR 0x00000004L 239 | #define D3DPBLENDCAPS_INVSRCCOLOR 0x00000008L 240 | #define D3DPBLENDCAPS_SRCALPHA 0x00000010L 241 | #define D3DPBLENDCAPS_INVSRCALPHA 0x00000020L 242 | #define D3DPBLENDCAPS_DESTALPHA 0x00000040L 243 | #define D3DPBLENDCAPS_INVDESTALPHA 0x00000080L 244 | #define D3DPBLENDCAPS_DESTCOLOR 0x00000100L 245 | #define D3DPBLENDCAPS_INVDESTCOLOR 0x00000200L 246 | #define D3DPBLENDCAPS_SRCALPHASAT 0x00000400L 247 | #define D3DPBLENDCAPS_BOTHSRCALPHA 0x00000800L 248 | #define D3DPBLENDCAPS_BOTHINVSRCALPHA 0x00001000L 249 | 250 | // 251 | // ShadeCaps 252 | // 253 | #define D3DPSHADECAPS_COLORGOURAUDRGB 0x00000008L 254 | #define D3DPSHADECAPS_SPECULARGOURAUDRGB 0x00000200L 255 | #define D3DPSHADECAPS_ALPHAGOURAUDBLEND 0x00004000L 256 | #define D3DPSHADECAPS_FOGGOURAUD 0x00080000L 257 | 258 | // 259 | // TextureCaps 260 | // 261 | #define D3DPTEXTURECAPS_PERSPECTIVE 0x00000001L /* Perspective-correct texturing is supported */ 262 | #define D3DPTEXTURECAPS_POW2 0x00000002L /* Power-of-2 texture dimensions are required - applies to non-Cube/Volume textures only. */ 263 | #define D3DPTEXTURECAPS_ALPHA 0x00000004L /* Alpha in texture pixels is supported */ 264 | #define D3DPTEXTURECAPS_SQUAREONLY 0x00000020L /* Only square textures are supported */ 265 | #define D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE 0x00000040L /* Texture indices are not scaled by the texture size prior to interpolation */ 266 | #define D3DPTEXTURECAPS_ALPHAPALETTE 0x00000080L /* Device can draw alpha from texture palettes */ 267 | // Device can use non-POW2 textures if: 268 | // 1) D3DTEXTURE_ADDRESS is set to CLAMP for this texture's stage 269 | // 2) D3DRS_WRAP(N) is zero for this texture's coordinates 270 | // 3) mip mapping is not enabled (use magnification filter only) 271 | #define D3DPTEXTURECAPS_NONPOW2CONDITIONAL 0x00000100L 272 | #define D3DPTEXTURECAPS_PROJECTED 0x00000400L /* Device can do D3DTTFF_PROJECTED */ 273 | #define D3DPTEXTURECAPS_CUBEMAP 0x00000800L /* Device can do cubemap textures */ 274 | #define D3DPTEXTURECAPS_VOLUMEMAP 0x00002000L /* Device can do volume textures */ 275 | #define D3DPTEXTURECAPS_MIPMAP 0x00004000L /* Device can do mipmapped textures */ 276 | #define D3DPTEXTURECAPS_MIPVOLUMEMAP 0x00008000L /* Device can do mipmapped volume textures */ 277 | #define D3DPTEXTURECAPS_MIPCUBEMAP 0x00010000L /* Device can do mipmapped cube maps */ 278 | #define D3DPTEXTURECAPS_CUBEMAP_POW2 0x00020000L /* Device requires that cubemaps be power-of-2 dimension */ 279 | #define D3DPTEXTURECAPS_VOLUMEMAP_POW2 0x00040000L /* Device requires that volume maps be power-of-2 dimension */ 280 | 281 | // 282 | // TextureFilterCaps 283 | // 284 | #define D3DPTFILTERCAPS_MINFPOINT 0x00000100L /* Min Filter */ 285 | #define D3DPTFILTERCAPS_MINFLINEAR 0x00000200L 286 | #define D3DPTFILTERCAPS_MINFANISOTROPIC 0x00000400L 287 | #define D3DPTFILTERCAPS_MIPFPOINT 0x00010000L /* Mip Filter */ 288 | #define D3DPTFILTERCAPS_MIPFLINEAR 0x00020000L 289 | #define D3DPTFILTERCAPS_MAGFPOINT 0x01000000L /* Mag Filter */ 290 | #define D3DPTFILTERCAPS_MAGFLINEAR 0x02000000L 291 | #define D3DPTFILTERCAPS_MAGFANISOTROPIC 0x04000000L 292 | #define D3DPTFILTERCAPS_MAGFAFLATCUBIC 0x08000000L 293 | #define D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC 0x10000000L 294 | 295 | // 296 | // TextureAddressCaps 297 | // 298 | #define D3DPTADDRESSCAPS_WRAP 0x00000001L 299 | #define D3DPTADDRESSCAPS_MIRROR 0x00000002L 300 | #define D3DPTADDRESSCAPS_CLAMP 0x00000004L 301 | #define D3DPTADDRESSCAPS_BORDER 0x00000008L 302 | #define D3DPTADDRESSCAPS_INDEPENDENTUV 0x00000010L 303 | #define D3DPTADDRESSCAPS_MIRRORONCE 0x00000020L 304 | 305 | // 306 | // StencilCaps 307 | // 308 | #define D3DSTENCILCAPS_KEEP 0x00000001L 309 | #define D3DSTENCILCAPS_ZERO 0x00000002L 310 | #define D3DSTENCILCAPS_REPLACE 0x00000004L 311 | #define D3DSTENCILCAPS_INCRSAT 0x00000008L 312 | #define D3DSTENCILCAPS_DECRSAT 0x00000010L 313 | #define D3DSTENCILCAPS_INVERT 0x00000020L 314 | #define D3DSTENCILCAPS_INCR 0x00000040L 315 | #define D3DSTENCILCAPS_DECR 0x00000080L 316 | 317 | // 318 | // TextureOpCaps 319 | // 320 | #define D3DTEXOPCAPS_DISABLE 0x00000001L 321 | #define D3DTEXOPCAPS_SELECTARG1 0x00000002L 322 | #define D3DTEXOPCAPS_SELECTARG2 0x00000004L 323 | #define D3DTEXOPCAPS_MODULATE 0x00000008L 324 | #define D3DTEXOPCAPS_MODULATE2X 0x00000010L 325 | #define D3DTEXOPCAPS_MODULATE4X 0x00000020L 326 | #define D3DTEXOPCAPS_ADD 0x00000040L 327 | #define D3DTEXOPCAPS_ADDSIGNED 0x00000080L 328 | #define D3DTEXOPCAPS_ADDSIGNED2X 0x00000100L 329 | #define D3DTEXOPCAPS_SUBTRACT 0x00000200L 330 | #define D3DTEXOPCAPS_ADDSMOOTH 0x00000400L 331 | #define D3DTEXOPCAPS_BLENDDIFFUSEALPHA 0x00000800L 332 | #define D3DTEXOPCAPS_BLENDTEXTUREALPHA 0x00001000L 333 | #define D3DTEXOPCAPS_BLENDFACTORALPHA 0x00002000L 334 | #define D3DTEXOPCAPS_BLENDTEXTUREALPHAPM 0x00004000L 335 | #define D3DTEXOPCAPS_BLENDCURRENTALPHA 0x00008000L 336 | #define D3DTEXOPCAPS_PREMODULATE 0x00010000L 337 | #define D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR 0x00020000L 338 | #define D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA 0x00040000L 339 | #define D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR 0x00080000L 340 | #define D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA 0x00100000L 341 | #define D3DTEXOPCAPS_BUMPENVMAP 0x00200000L 342 | #define D3DTEXOPCAPS_BUMPENVMAPLUMINANCE 0x00400000L 343 | #define D3DTEXOPCAPS_DOTPRODUCT3 0x00800000L 344 | #define D3DTEXOPCAPS_MULTIPLYADD 0x01000000L 345 | #define D3DTEXOPCAPS_LERP 0x02000000L 346 | 347 | // 348 | // FVFCaps 349 | // 350 | #define D3DFVFCAPS_TEXCOORDCOUNTMASK 0x0000ffffL /* mask for texture coordinate count field */ 351 | #define D3DFVFCAPS_DONOTSTRIPELEMENTS 0x00080000L /* Device prefers that vertex elements not be stripped */ 352 | #define D3DFVFCAPS_PSIZE 0x00100000L /* Device can receive point size */ 353 | 354 | // 355 | // VertexProcessingCaps 356 | // 357 | #define D3DVTXPCAPS_TEXGEN 0x00000001L /* device can do texgen */ 358 | #define D3DVTXPCAPS_MATERIALSOURCE7 0x00000002L /* device can do DX7-level colormaterialsource ops */ 359 | #define D3DVTXPCAPS_DIRECTIONALLIGHTS 0x00000008L /* device can do directional lights */ 360 | #define D3DVTXPCAPS_POSITIONALLIGHTS 0x00000010L /* device can do positional lights (includes point and spot) */ 361 | #define D3DVTXPCAPS_LOCALVIEWER 0x00000020L /* device can do local viewer */ 362 | #define D3DVTXPCAPS_TWEENING 0x00000040L /* device can do vertex tweening */ 363 | #define D3DVTXPCAPS_NO_VSDT_UBYTE4 0x00000080L /* device does not support D3DVSDT_UBYTE4 */ 364 | 365 | #pragma pack() 366 | 367 | #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ 368 | #pragma endregion 369 | 370 | #endif /* (DIRECT3D_VERSION >= 0x0800) */ 371 | #endif /* _D3D8CAPS_H_ */ 372 | 373 | -------------------------------------------------------------------------------- /DirectX81SDK/include/d3d8types.h: -------------------------------------------------------------------------------- 1 | /*==========================================================================; 2 | * 3 | * Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | * 5 | * File: d3d8types.h 6 | * Content: Direct3D capabilities include file 7 | * 8 | ***************************************************************************/ 9 | 10 | #ifndef _D3D8TYPES_H_ 11 | #define _D3D8TYPES_H_ 12 | 13 | #include 14 | 15 | #ifndef DIRECT3D_VERSION 16 | #define DIRECT3D_VERSION 0x0800 17 | #endif //DIRECT3D_VERSION 18 | 19 | // include this file content only if compiling for DX8 interfaces 20 | #if(DIRECT3D_VERSION >= 0x0800) 21 | 22 | #include 23 | 24 | #if _MSC_VER >= 1200 25 | #pragma warning(push) 26 | #endif 27 | #pragma warning(disable:4201) // anonymous unions warning 28 | #if defined(_X86_) || defined(_IA64_) 29 | #pragma pack(4) 30 | #endif 31 | 32 | #pragma region Destop Family 33 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 34 | 35 | // D3DCOLOR is equivalent to D3DFMT_A8R8G8B8 36 | #ifndef D3DCOLOR_DEFINED 37 | typedef DWORD D3DCOLOR; 38 | #define D3DCOLOR_DEFINED 39 | #endif 40 | 41 | // maps unsigned 8 bits/channel to D3DCOLOR 42 | #define D3DCOLOR_ARGB(a,r,g,b) \ 43 | ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) 44 | #define D3DCOLOR_RGBA(r,g,b,a) D3DCOLOR_ARGB(a,r,g,b) 45 | #define D3DCOLOR_XRGB(r,g,b) D3DCOLOR_ARGB(0xff,r,g,b) 46 | 47 | // maps floating point channels (0.f to 1.f range) to D3DCOLOR 48 | #define D3DCOLOR_COLORVALUE(r,g,b,a) \ 49 | D3DCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f)) 50 | 51 | 52 | #ifndef D3DVECTOR_DEFINED 53 | typedef struct _D3DVECTOR { 54 | float x; 55 | float y; 56 | float z; 57 | } D3DVECTOR; 58 | #define D3DVECTOR_DEFINED 59 | #endif 60 | 61 | #ifndef D3DCOLORVALUE_DEFINED 62 | typedef struct _D3DCOLORVALUE { 63 | float r; 64 | float g; 65 | float b; 66 | float a; 67 | } D3DCOLORVALUE; 68 | #define D3DCOLORVALUE_DEFINED 69 | #endif 70 | 71 | #ifndef D3DRECT_DEFINED 72 | typedef struct _D3DRECT { 73 | LONG x1; 74 | LONG y1; 75 | LONG x2; 76 | LONG y2; 77 | } D3DRECT; 78 | #define D3DRECT_DEFINED 79 | #endif 80 | 81 | #ifndef D3DMATRIX_DEFINED 82 | typedef struct _D3DMATRIX { 83 | union { 84 | struct { 85 | float _11, _12, _13, _14; 86 | float _21, _22, _23, _24; 87 | float _31, _32, _33, _34; 88 | float _41, _42, _43, _44; 89 | 90 | }; 91 | float m[4][4]; 92 | }; 93 | } D3DMATRIX; 94 | #define D3DMATRIX_DEFINED 95 | #endif 96 | 97 | typedef struct _D3DVIEWPORT8 { 98 | DWORD X; 99 | DWORD Y; /* Viewport Top left */ 100 | DWORD Width; 101 | DWORD Height; /* Viewport Dimensions */ 102 | float MinZ; /* Min/max of clip Volume */ 103 | float MaxZ; 104 | } D3DVIEWPORT8; 105 | 106 | /* 107 | * Values for clip fields. 108 | */ 109 | 110 | // Max number of user clipping planes, supported in D3D. 111 | #define D3DMAXUSERCLIPPLANES 32 112 | 113 | // These bits could be ORed together to use with D3DRS_CLIPPLANEENABLE 114 | // 115 | #define D3DCLIPPLANE0 (1 << 0) 116 | #define D3DCLIPPLANE1 (1 << 1) 117 | #define D3DCLIPPLANE2 (1 << 2) 118 | #define D3DCLIPPLANE3 (1 << 3) 119 | #define D3DCLIPPLANE4 (1 << 4) 120 | #define D3DCLIPPLANE5 (1 << 5) 121 | 122 | // The following bits are used in the ClipUnion and ClipIntersection 123 | // members of the D3DCLIPSTATUS8 124 | // 125 | 126 | #define D3DCS_LEFT 0x00000001L 127 | #define D3DCS_RIGHT 0x00000002L 128 | #define D3DCS_TOP 0x00000004L 129 | #define D3DCS_BOTTOM 0x00000008L 130 | #define D3DCS_FRONT 0x00000010L 131 | #define D3DCS_BACK 0x00000020L 132 | #define D3DCS_PLANE0 0x00000040L 133 | #define D3DCS_PLANE1 0x00000080L 134 | #define D3DCS_PLANE2 0x00000100L 135 | #define D3DCS_PLANE3 0x00000200L 136 | #define D3DCS_PLANE4 0x00000400L 137 | #define D3DCS_PLANE5 0x00000800L 138 | 139 | #define D3DCS_ALL (D3DCS_LEFT | \ 140 | D3DCS_RIGHT | \ 141 | D3DCS_TOP | \ 142 | D3DCS_BOTTOM | \ 143 | D3DCS_FRONT | \ 144 | D3DCS_BACK | \ 145 | D3DCS_PLANE0 | \ 146 | D3DCS_PLANE1 | \ 147 | D3DCS_PLANE2 | \ 148 | D3DCS_PLANE3 | \ 149 | D3DCS_PLANE4 | \ 150 | D3DCS_PLANE5) 151 | 152 | typedef struct _D3DCLIPSTATUS8 { 153 | DWORD ClipUnion; 154 | DWORD ClipIntersection; 155 | } D3DCLIPSTATUS8; 156 | 157 | typedef struct _D3DMATERIAL8 { 158 | D3DCOLORVALUE Diffuse; /* Diffuse color RGBA */ 159 | D3DCOLORVALUE Ambient; /* Ambient color RGB */ 160 | D3DCOLORVALUE Specular; /* Specular 'shininess' */ 161 | D3DCOLORVALUE Emissive; /* Emissive color RGB */ 162 | float Power; /* Sharpness if specular highlight */ 163 | } D3DMATERIAL8; 164 | 165 | typedef enum _D3DLIGHTTYPE { 166 | D3DLIGHT_POINT = 1, 167 | D3DLIGHT_SPOT = 2, 168 | D3DLIGHT_DIRECTIONAL = 3, 169 | D3DLIGHT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 170 | } D3DLIGHTTYPE; 171 | 172 | typedef struct _D3DLIGHT8 { 173 | D3DLIGHTTYPE Type; /* Type of light source */ 174 | D3DCOLORVALUE Diffuse; /* Diffuse color of light */ 175 | D3DCOLORVALUE Specular; /* Specular color of light */ 176 | D3DCOLORVALUE Ambient; /* Ambient color of light */ 177 | D3DVECTOR Position; /* Position in world space */ 178 | D3DVECTOR Direction; /* Direction in world space */ 179 | float Range; /* Cutoff range */ 180 | float Falloff; /* Falloff */ 181 | float Attenuation0; /* Constant attenuation */ 182 | float Attenuation1; /* Linear attenuation */ 183 | float Attenuation2; /* Quadratic attenuation */ 184 | float Theta; /* Inner angle of spotlight cone */ 185 | float Phi; /* Outer angle of spotlight cone */ 186 | } D3DLIGHT8; 187 | 188 | /* 189 | * Options for clearing 190 | */ 191 | #define D3DCLEAR_TARGET 0x00000001l /* Clear target surface */ 192 | #define D3DCLEAR_ZBUFFER 0x00000002l /* Clear target z buffer */ 193 | #define D3DCLEAR_STENCIL 0x00000004l /* Clear stencil planes */ 194 | 195 | /* 196 | * The following defines the rendering states 197 | */ 198 | 199 | typedef enum _D3DSHADEMODE { 200 | D3DSHADE_FLAT = 1, 201 | D3DSHADE_GOURAUD = 2, 202 | D3DSHADE_PHONG = 3, 203 | D3DSHADE_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 204 | } D3DSHADEMODE; 205 | 206 | typedef enum _D3DFILLMODE { 207 | D3DFILL_POINT = 1, 208 | D3DFILL_WIREFRAME = 2, 209 | D3DFILL_SOLID = 3, 210 | D3DFILL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 211 | } D3DFILLMODE; 212 | 213 | typedef struct _D3DLINEPATTERN { 214 | WORD wRepeatFactor; 215 | WORD wLinePattern; 216 | } D3DLINEPATTERN; 217 | 218 | typedef enum _D3DBLEND { 219 | D3DBLEND_ZERO = 1, 220 | D3DBLEND_ONE = 2, 221 | D3DBLEND_SRCCOLOR = 3, 222 | D3DBLEND_INVSRCCOLOR = 4, 223 | D3DBLEND_SRCALPHA = 5, 224 | D3DBLEND_INVSRCALPHA = 6, 225 | D3DBLEND_DESTALPHA = 7, 226 | D3DBLEND_INVDESTALPHA = 8, 227 | D3DBLEND_DESTCOLOR = 9, 228 | D3DBLEND_INVDESTCOLOR = 10, 229 | D3DBLEND_SRCALPHASAT = 11, 230 | D3DBLEND_BOTHSRCALPHA = 12, 231 | D3DBLEND_BOTHINVSRCALPHA = 13, 232 | D3DBLEND_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 233 | } D3DBLEND; 234 | 235 | typedef enum _D3DBLENDOP { 236 | D3DBLENDOP_ADD = 1, 237 | D3DBLENDOP_SUBTRACT = 2, 238 | D3DBLENDOP_REVSUBTRACT = 3, 239 | D3DBLENDOP_MIN = 4, 240 | D3DBLENDOP_MAX = 5, 241 | D3DBLENDOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 242 | } D3DBLENDOP; 243 | 244 | typedef enum _D3DTEXTUREADDRESS { 245 | D3DTADDRESS_WRAP = 1, 246 | D3DTADDRESS_MIRROR = 2, 247 | D3DTADDRESS_CLAMP = 3, 248 | D3DTADDRESS_BORDER = 4, 249 | D3DTADDRESS_MIRRORONCE = 5, 250 | D3DTADDRESS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 251 | } D3DTEXTUREADDRESS; 252 | 253 | typedef enum _D3DCULL { 254 | D3DCULL_NONE = 1, 255 | D3DCULL_CW = 2, 256 | D3DCULL_CCW = 3, 257 | D3DCULL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 258 | } D3DCULL; 259 | 260 | typedef enum _D3DCMPFUNC { 261 | D3DCMP_NEVER = 1, 262 | D3DCMP_LESS = 2, 263 | D3DCMP_EQUAL = 3, 264 | D3DCMP_LESSEQUAL = 4, 265 | D3DCMP_GREATER = 5, 266 | D3DCMP_NOTEQUAL = 6, 267 | D3DCMP_GREATEREQUAL = 7, 268 | D3DCMP_ALWAYS = 8, 269 | D3DCMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 270 | } D3DCMPFUNC; 271 | 272 | typedef enum _D3DSTENCILOP { 273 | D3DSTENCILOP_KEEP = 1, 274 | D3DSTENCILOP_ZERO = 2, 275 | D3DSTENCILOP_REPLACE = 3, 276 | D3DSTENCILOP_INCRSAT = 4, 277 | D3DSTENCILOP_DECRSAT = 5, 278 | D3DSTENCILOP_INVERT = 6, 279 | D3DSTENCILOP_INCR = 7, 280 | D3DSTENCILOP_DECR = 8, 281 | D3DSTENCILOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 282 | } D3DSTENCILOP; 283 | 284 | typedef enum _D3DFOGMODE { 285 | D3DFOG_NONE = 0, 286 | D3DFOG_EXP = 1, 287 | D3DFOG_EXP2 = 2, 288 | D3DFOG_LINEAR = 3, 289 | D3DFOG_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 290 | } D3DFOGMODE; 291 | 292 | typedef enum _D3DZBUFFERTYPE { 293 | D3DZB_FALSE = 0, 294 | D3DZB_TRUE = 1, // Z buffering 295 | D3DZB_USEW = 2, // W buffering 296 | D3DZB_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 297 | } D3DZBUFFERTYPE; 298 | 299 | // Primitives supported by draw-primitive API 300 | typedef enum _D3DPRIMITIVETYPE { 301 | D3DPT_POINTLIST = 1, 302 | D3DPT_LINELIST = 2, 303 | D3DPT_LINESTRIP = 3, 304 | D3DPT_TRIANGLELIST = 4, 305 | D3DPT_TRIANGLESTRIP = 5, 306 | D3DPT_TRIANGLEFAN = 6, 307 | D3DPT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 308 | } D3DPRIMITIVETYPE; 309 | 310 | typedef enum _D3DTRANSFORMSTATETYPE { 311 | D3DTS_VIEW = 2, 312 | D3DTS_PROJECTION = 3, 313 | D3DTS_TEXTURE0 = 16, 314 | D3DTS_TEXTURE1 = 17, 315 | D3DTS_TEXTURE2 = 18, 316 | D3DTS_TEXTURE3 = 19, 317 | D3DTS_TEXTURE4 = 20, 318 | D3DTS_TEXTURE5 = 21, 319 | D3DTS_TEXTURE6 = 22, 320 | D3DTS_TEXTURE7 = 23, 321 | D3DTS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 322 | } D3DTRANSFORMSTATETYPE; 323 | 324 | #define D3DTS_WORLDMATRIX(index) (D3DTRANSFORMSTATETYPE)(index + 256) 325 | #define D3DTS_WORLD D3DTS_WORLDMATRIX(0) 326 | #define D3DTS_WORLD1 D3DTS_WORLDMATRIX(1) 327 | #define D3DTS_WORLD2 D3DTS_WORLDMATRIX(2) 328 | #define D3DTS_WORLD3 D3DTS_WORLDMATRIX(3) 329 | 330 | typedef enum _D3DRENDERSTATETYPE { 331 | D3DRS_ZENABLE = 7, /* D3DZBUFFERTYPE (or TRUE/FALSE for legacy) */ 332 | D3DRS_FILLMODE = 8, /* D3DFILLMODE */ 333 | D3DRS_SHADEMODE = 9, /* D3DSHADEMODE */ 334 | D3DRS_LINEPATTERN = 10, /* D3DLINEPATTERN */ 335 | D3DRS_ZWRITEENABLE = 14, /* TRUE to enable z writes */ 336 | D3DRS_ALPHATESTENABLE = 15, /* TRUE to enable alpha tests */ 337 | D3DRS_LASTPIXEL = 16, /* TRUE for last-pixel on lines */ 338 | D3DRS_SRCBLEND = 19, /* D3DBLEND */ 339 | D3DRS_DESTBLEND = 20, /* D3DBLEND */ 340 | D3DRS_CULLMODE = 22, /* D3DCULL */ 341 | D3DRS_ZFUNC = 23, /* D3DCMPFUNC */ 342 | D3DRS_ALPHAREF = 24, /* D3DFIXED */ 343 | D3DRS_ALPHAFUNC = 25, /* D3DCMPFUNC */ 344 | D3DRS_DITHERENABLE = 26, /* TRUE to enable dithering */ 345 | D3DRS_ALPHABLENDENABLE = 27, /* TRUE to enable alpha blending */ 346 | D3DRS_FOGENABLE = 28, /* TRUE to enable fog blending */ 347 | D3DRS_SPECULARENABLE = 29, /* TRUE to enable specular */ 348 | D3DRS_ZVISIBLE = 30, /* TRUE to enable z checking */ 349 | D3DRS_FOGCOLOR = 34, /* D3DCOLOR */ 350 | D3DRS_FOGTABLEMODE = 35, /* D3DFOGMODE */ 351 | D3DRS_FOGSTART = 36, /* Fog start (for both vertex and pixel fog) */ 352 | D3DRS_FOGEND = 37, /* Fog end */ 353 | D3DRS_FOGDENSITY = 38, /* Fog density */ 354 | D3DRS_EDGEANTIALIAS = 40, /* TRUE to enable edge antialiasing */ 355 | D3DRS_ZBIAS = 47, /* LONG Z bias */ 356 | D3DRS_RANGEFOGENABLE = 48, /* Enables range-based fog */ 357 | D3DRS_STENCILENABLE = 52, /* BOOL enable/disable stenciling */ 358 | D3DRS_STENCILFAIL = 53, /* D3DSTENCILOP to do if stencil test fails */ 359 | D3DRS_STENCILZFAIL = 54, /* D3DSTENCILOP to do if stencil test passes and Z test fails */ 360 | D3DRS_STENCILPASS = 55, /* D3DSTENCILOP to do if both stencil and Z tests pass */ 361 | D3DRS_STENCILFUNC = 56, /* D3DCMPFUNC fn. Stencil Test passes if ((ref & mask) stencilfn (stencil & mask)) is true */ 362 | D3DRS_STENCILREF = 57, /* Reference value used in stencil test */ 363 | D3DRS_STENCILMASK = 58, /* Mask value used in stencil test */ 364 | D3DRS_STENCILWRITEMASK = 59, /* Write mask applied to values written to stencil buffer */ 365 | D3DRS_TEXTUREFACTOR = 60, /* D3DCOLOR used for multi-texture blend */ 366 | D3DRS_WRAP0 = 128, /* wrap for 1st texture coord. set */ 367 | D3DRS_WRAP1 = 129, /* wrap for 2nd texture coord. set */ 368 | D3DRS_WRAP2 = 130, /* wrap for 3rd texture coord. set */ 369 | D3DRS_WRAP3 = 131, /* wrap for 4th texture coord. set */ 370 | D3DRS_WRAP4 = 132, /* wrap for 5th texture coord. set */ 371 | D3DRS_WRAP5 = 133, /* wrap for 6th texture coord. set */ 372 | D3DRS_WRAP6 = 134, /* wrap for 7th texture coord. set */ 373 | D3DRS_WRAP7 = 135, /* wrap for 8th texture coord. set */ 374 | D3DRS_CLIPPING = 136, 375 | D3DRS_LIGHTING = 137, 376 | D3DRS_AMBIENT = 139, 377 | D3DRS_FOGVERTEXMODE = 140, 378 | D3DRS_COLORVERTEX = 141, 379 | D3DRS_LOCALVIEWER = 142, 380 | D3DRS_NORMALIZENORMALS = 143, 381 | D3DRS_DIFFUSEMATERIALSOURCE = 145, 382 | D3DRS_SPECULARMATERIALSOURCE = 146, 383 | D3DRS_AMBIENTMATERIALSOURCE = 147, 384 | D3DRS_EMISSIVEMATERIALSOURCE = 148, 385 | D3DRS_VERTEXBLEND = 151, 386 | D3DRS_CLIPPLANEENABLE = 152, 387 | D3DRS_SOFTWAREVERTEXPROCESSING = 153, 388 | D3DRS_POINTSIZE = 154, /* float point size */ 389 | D3DRS_POINTSIZE_MIN = 155, /* float point size min threshold */ 390 | D3DRS_POINTSPRITEENABLE = 156, /* BOOL point texture coord control */ 391 | D3DRS_POINTSCALEENABLE = 157, /* BOOL point size scale enable */ 392 | D3DRS_POINTSCALE_A = 158, /* float point attenuation A value */ 393 | D3DRS_POINTSCALE_B = 159, /* float point attenuation B value */ 394 | D3DRS_POINTSCALE_C = 160, /* float point attenuation C value */ 395 | D3DRS_MULTISAMPLEANTIALIAS = 161, // BOOL - set to do FSAA with multisample buffer 396 | D3DRS_MULTISAMPLEMASK = 162, // DWORD - per-sample enable/disable 397 | D3DRS_PATCHEDGESTYLE = 163, // Sets whether patch edges will use float style tessellation 398 | D3DRS_PATCHSEGMENTS = 164, // Number of segments per edge when drawing patches 399 | D3DRS_DEBUGMONITORTOKEN = 165, // DEBUG ONLY - token to debug monitor 400 | D3DRS_POINTSIZE_MAX = 166, /* float point size max threshold */ 401 | D3DRS_INDEXEDVERTEXBLENDENABLE = 167, 402 | D3DRS_COLORWRITEENABLE = 168, // per-channel write enable 403 | D3DRS_TWEENFACTOR = 170, // float tween factor 404 | D3DRS_BLENDOP = 171, // D3DBLENDOP setting 405 | D3DRS_POSITIONORDER = 172, // NPatch position interpolation order. D3DORDER_LINEAR or D3DORDER_CUBIC (default) 406 | D3DRS_NORMALORDER = 173, // NPatch normal interpolation order. D3DORDER_LINEAR (default) or D3DORDER_QUADRATIC 407 | 408 | D3DRS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 409 | } D3DRENDERSTATETYPE; 410 | 411 | // Values for material source 412 | typedef enum _D3DMATERIALCOLORSOURCE 413 | { 414 | D3DMCS_MATERIAL = 0, // Color from material is used 415 | D3DMCS_COLOR1 = 1, // Diffuse vertex color is used 416 | D3DMCS_COLOR2 = 2, // Specular vertex color is used 417 | D3DMCS_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum 418 | } D3DMATERIALCOLORSOURCE; 419 | 420 | // Bias to apply to the texture coordinate set to apply a wrap to. 421 | #define D3DRENDERSTATE_WRAPBIAS 128UL 422 | 423 | /* Flags to construct the WRAP render states */ 424 | #define D3DWRAP_U 0x00000001L 425 | #define D3DWRAP_V 0x00000002L 426 | #define D3DWRAP_W 0x00000004L 427 | 428 | /* Flags to construct the WRAP render states for 1D thru 4D texture coordinates */ 429 | #define D3DWRAPCOORD_0 0x00000001L // same as D3DWRAP_U 430 | #define D3DWRAPCOORD_1 0x00000002L // same as D3DWRAP_V 431 | #define D3DWRAPCOORD_2 0x00000004L // same as D3DWRAP_W 432 | #define D3DWRAPCOORD_3 0x00000008L 433 | 434 | /* Flags to construct D3DRS_COLORWRITEENABLE */ 435 | #define D3DCOLORWRITEENABLE_RED (1L<<0) 436 | #define D3DCOLORWRITEENABLE_GREEN (1L<<1) 437 | #define D3DCOLORWRITEENABLE_BLUE (1L<<2) 438 | #define D3DCOLORWRITEENABLE_ALPHA (1L<<3) 439 | 440 | /* 441 | * State enumerants for per-stage texture processing. 442 | */ 443 | typedef enum _D3DTEXTURESTAGESTATETYPE 444 | { 445 | D3DTSS_COLOROP = 1, /* D3DTEXTUREOP - per-stage blending controls for color channels */ 446 | D3DTSS_COLORARG1 = 2, /* D3DTA_* (texture arg) */ 447 | D3DTSS_COLORARG2 = 3, /* D3DTA_* (texture arg) */ 448 | D3DTSS_ALPHAOP = 4, /* D3DTEXTUREOP - per-stage blending controls for alpha channel */ 449 | D3DTSS_ALPHAARG1 = 5, /* D3DTA_* (texture arg) */ 450 | D3DTSS_ALPHAARG2 = 6, /* D3DTA_* (texture arg) */ 451 | D3DTSS_BUMPENVMAT00 = 7, /* float (bump mapping matrix) */ 452 | D3DTSS_BUMPENVMAT01 = 8, /* float (bump mapping matrix) */ 453 | D3DTSS_BUMPENVMAT10 = 9, /* float (bump mapping matrix) */ 454 | D3DTSS_BUMPENVMAT11 = 10, /* float (bump mapping matrix) */ 455 | D3DTSS_TEXCOORDINDEX = 11, /* identifies which set of texture coordinates index this texture */ 456 | D3DTSS_ADDRESSU = 13, /* D3DTEXTUREADDRESS for U coordinate */ 457 | D3DTSS_ADDRESSV = 14, /* D3DTEXTUREADDRESS for V coordinate */ 458 | D3DTSS_BORDERCOLOR = 15, /* D3DCOLOR */ 459 | D3DTSS_MAGFILTER = 16, /* D3DTEXTUREFILTER filter to use for magnification */ 460 | D3DTSS_MINFILTER = 17, /* D3DTEXTUREFILTER filter to use for minification */ 461 | D3DTSS_MIPFILTER = 18, /* D3DTEXTUREFILTER filter to use between mipmaps during minification */ 462 | D3DTSS_MIPMAPLODBIAS = 19, /* float Mipmap LOD bias */ 463 | D3DTSS_MAXMIPLEVEL = 20, /* DWORD 0..(n-1) LOD index of largest map to use (0 == largest) */ 464 | D3DTSS_MAXANISOTROPY = 21, /* DWORD maximum anisotropy */ 465 | D3DTSS_BUMPENVLSCALE = 22, /* float scale for bump map luminance */ 466 | D3DTSS_BUMPENVLOFFSET = 23, /* float offset for bump map luminance */ 467 | D3DTSS_TEXTURETRANSFORMFLAGS = 24, /* D3DTEXTURETRANSFORMFLAGS controls texture transform */ 468 | D3DTSS_ADDRESSW = 25, /* D3DTEXTUREADDRESS for W coordinate */ 469 | D3DTSS_COLORARG0 = 26, /* D3DTA_* third arg for triadic ops */ 470 | D3DTSS_ALPHAARG0 = 27, /* D3DTA_* third arg for triadic ops */ 471 | D3DTSS_RESULTARG = 28, /* D3DTA_* arg for result (CURRENT or TEMP) */ 472 | D3DTSS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 473 | } D3DTEXTURESTAGESTATETYPE; 474 | 475 | // Values, used with D3DTSS_TEXCOORDINDEX, to specify that the vertex data(position 476 | // and normal in the camera space) should be taken as texture coordinates 477 | // Low 16 bits are used to specify texture coordinate index, to take the WRAP mode from 478 | // 479 | #define D3DTSS_TCI_PASSTHRU 0x00000000 480 | #define D3DTSS_TCI_CAMERASPACENORMAL 0x00010000 481 | #define D3DTSS_TCI_CAMERASPACEPOSITION 0x00020000 482 | #define D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR 0x00030000 483 | 484 | /* 485 | * Enumerations for COLOROP and ALPHAOP texture blending operations set in 486 | * texture processing stage controls in D3DTSS. 487 | */ 488 | typedef enum _D3DTEXTUREOP 489 | { 490 | // Control 491 | D3DTOP_DISABLE = 1, // disables stage 492 | D3DTOP_SELECTARG1 = 2, // the default 493 | D3DTOP_SELECTARG2 = 3, 494 | 495 | // Modulate 496 | D3DTOP_MODULATE = 4, // multiply args together 497 | D3DTOP_MODULATE2X = 5, // multiply and 1 bit 498 | D3DTOP_MODULATE4X = 6, // multiply and 2 bits 499 | 500 | // Add 501 | D3DTOP_ADD = 7, // add arguments together 502 | D3DTOP_ADDSIGNED = 8, // add with -0.5 bias 503 | D3DTOP_ADDSIGNED2X = 9, // as above but left 1 bit 504 | D3DTOP_SUBTRACT = 10, // Arg1 - Arg2, with no saturation 505 | D3DTOP_ADDSMOOTH = 11, // add 2 args, subtract product 506 | // Arg1 + Arg2 - Arg1*Arg2 507 | // = Arg1 + (1-Arg1)*Arg2 508 | 509 | // Linear alpha blend: Arg1*(Alpha) + Arg2*(1-Alpha) 510 | D3DTOP_BLENDDIFFUSEALPHA = 12, // iterated alpha 511 | D3DTOP_BLENDTEXTUREALPHA = 13, // texture alpha 512 | D3DTOP_BLENDFACTORALPHA = 14, // alpha from D3DRS_TEXTUREFACTOR 513 | 514 | // Linear alpha blend with pre-multiplied arg1 input: Arg1 + Arg2*(1-Alpha) 515 | D3DTOP_BLENDTEXTUREALPHAPM = 15, // texture alpha 516 | D3DTOP_BLENDCURRENTALPHA = 16, // by alpha of current color 517 | 518 | // Specular mapping 519 | D3DTOP_PREMODULATE = 17, // modulate with next texture before use 520 | D3DTOP_MODULATEALPHA_ADDCOLOR = 18, // Arg1.RGB + Arg1.A*Arg2.RGB 521 | // COLOROP only 522 | D3DTOP_MODULATECOLOR_ADDALPHA = 19, // Arg1.RGB*Arg2.RGB + Arg1.A 523 | // COLOROP only 524 | D3DTOP_MODULATEINVALPHA_ADDCOLOR = 20, // (1-Arg1.A)*Arg2.RGB + Arg1.RGB 525 | // COLOROP only 526 | D3DTOP_MODULATEINVCOLOR_ADDALPHA = 21, // (1-Arg1.RGB)*Arg2.RGB + Arg1.A 527 | // COLOROP only 528 | 529 | // Bump mapping 530 | D3DTOP_BUMPENVMAP = 22, // per pixel env map perturbation 531 | D3DTOP_BUMPENVMAPLUMINANCE = 23, // with luminance channel 532 | 533 | // This can do either diffuse or specular bump mapping with correct input. 534 | // Performs the function (Arg1.R*Arg2.R + Arg1.G*Arg2.G + Arg1.B*Arg2.B) 535 | // where each component has been scaled and offset to make it signed. 536 | // The result is replicated into all four (including alpha) channels. 537 | // This is a valid COLOROP only. 538 | D3DTOP_DOTPRODUCT3 = 24, 539 | 540 | // Triadic ops 541 | D3DTOP_MULTIPLYADD = 25, // Arg0 + Arg1*Arg2 542 | D3DTOP_LERP = 26, // (Arg0)*Arg1 + (1-Arg0)*Arg2 543 | 544 | D3DTOP_FORCE_DWORD = 0x7fffffff, 545 | } D3DTEXTUREOP; 546 | 547 | /* 548 | * Values for COLORARG0,1,2, ALPHAARG0,1,2, and RESULTARG texture blending 549 | * operations set in texture processing stage controls in D3DRENDERSTATE. 550 | */ 551 | #define D3DTA_SELECTMASK 0x0000000f // mask for arg selector 552 | #define D3DTA_DIFFUSE 0x00000000 // select diffuse color (read only) 553 | #define D3DTA_CURRENT 0x00000001 // select stage destination register (read/write) 554 | #define D3DTA_TEXTURE 0x00000002 // select texture color (read only) 555 | #define D3DTA_TFACTOR 0x00000003 // select D3DRS_TEXTUREFACTOR (read only) 556 | #define D3DTA_SPECULAR 0x00000004 // select specular color (read only) 557 | #define D3DTA_TEMP 0x00000005 // select temporary register color (read/write) 558 | #define D3DTA_COMPLEMENT 0x00000010 // take 1.0 - x (read modifier) 559 | #define D3DTA_ALPHAREPLICATE 0x00000020 // replicate alpha to color components (read modifier) 560 | 561 | // 562 | // Values for D3DTSS_***FILTER texture stage states 563 | // 564 | typedef enum _D3DTEXTUREFILTERTYPE 565 | { 566 | D3DTEXF_NONE = 0, // filtering disabled (valid for mip filter only) 567 | D3DTEXF_POINT = 1, // nearest 568 | D3DTEXF_LINEAR = 2, // linear interpolation 569 | D3DTEXF_ANISOTROPIC = 3, // anisotropic 570 | D3DTEXF_FLATCUBIC = 4, // cubic 571 | D3DTEXF_GAUSSIANCUBIC = 5, // different cubic kernel 572 | D3DTEXF_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum 573 | } D3DTEXTUREFILTERTYPE; 574 | 575 | /* Bits for Flags in ProcessVertices call */ 576 | 577 | #define D3DPV_DONOTCOPYDATA (1 << 0) 578 | 579 | //------------------------------------------------------------------- 580 | 581 | // Flexible vertex format bits 582 | // 583 | #define D3DFVF_RESERVED0 0x001 584 | #define D3DFVF_POSITION_MASK 0x00E 585 | #define D3DFVF_XYZ 0x002 586 | #define D3DFVF_XYZRHW 0x004 587 | #define D3DFVF_XYZB1 0x006 588 | #define D3DFVF_XYZB2 0x008 589 | #define D3DFVF_XYZB3 0x00a 590 | #define D3DFVF_XYZB4 0x00c 591 | #define D3DFVF_XYZB5 0x00e 592 | 593 | #define D3DFVF_NORMAL 0x010 594 | #define D3DFVF_PSIZE 0x020 595 | #define D3DFVF_DIFFUSE 0x040 596 | #define D3DFVF_SPECULAR 0x080 597 | 598 | #define D3DFVF_TEXCOUNT_MASK 0xf00 599 | #define D3DFVF_TEXCOUNT_SHIFT 8 600 | #define D3DFVF_TEX0 0x000 601 | #define D3DFVF_TEX1 0x100 602 | #define D3DFVF_TEX2 0x200 603 | #define D3DFVF_TEX3 0x300 604 | #define D3DFVF_TEX4 0x400 605 | #define D3DFVF_TEX5 0x500 606 | #define D3DFVF_TEX6 0x600 607 | #define D3DFVF_TEX7 0x700 608 | #define D3DFVF_TEX8 0x800 609 | 610 | #define D3DFVF_LASTBETA_UBYTE4 0x1000 611 | 612 | #define D3DFVF_RESERVED2 0xE000 // 4 reserved bits 613 | 614 | //--------------------------------------------------------------------- 615 | // Vertex Shaders 616 | // 617 | 618 | /* 619 | 620 | Vertex Shader Declaration 621 | 622 | The declaration portion of a vertex shader defines the static external 623 | interface of the shader. The information in the declaration includes: 624 | 625 | - Assignments of vertex shader input registers to data streams. These 626 | assignments bind a specific vertex register to a single component within a 627 | vertex stream. A vertex stream element is identified by a byte offset 628 | within the stream and a type. The type specifies the arithmetic data type 629 | plus the dimensionality (1, 2, 3, or 4 values). Stream data which is 630 | less than 4 values are always expanded out to 4 values with zero or more 631 | 0.F values and one 1.F value. 632 | 633 | - Assignment of vertex shader input registers to implicit data from the 634 | primitive tessellator. This controls the loading of vertex data which is 635 | not loaded from a stream, but rather is generated during primitive 636 | tessellation prior to the vertex shader. 637 | 638 | - Loading data into the constant memory at the time a shader is set as the 639 | current shader. Each token specifies values for one or more contiguous 4 640 | DWORD constant registers. This allows the shader to update an arbitrary 641 | subset of the constant memory, overwriting the device state (which 642 | contains the current values of the constant memory). Note that these 643 | values can be subsequently overwritten (between DrawPrimitive calls) 644 | during the time a shader is bound to a device via the 645 | SetVertexShaderConstant method. 646 | 647 | 648 | Declaration arrays are single-dimensional arrays of DWORDs composed of 649 | multiple tokens each of which is one or more DWORDs. The single-DWORD 650 | token value 0xFFFFFFFF is a special token used to indicate the end of the 651 | declaration array. The single DWORD token value 0x00000000 is a NOP token 652 | with is ignored during the declaration parsing. Note that 0x00000000 is a 653 | valid value for DWORDs following the first DWORD for multiple word tokens. 654 | 655 | [31:29] TokenType 656 | 0x0 - NOP (requires all DWORD bits to be zero) 657 | 0x1 - stream selector 658 | 0x2 - stream data definition (map to vertex input memory) 659 | 0x3 - vertex input memory from tessellator 660 | 0x4 - constant memory from shader 661 | 0x5 - extension 662 | 0x6 - reserved 663 | 0x7 - end-of-array (requires all DWORD bits to be 1) 664 | 665 | NOP Token (single DWORD token) 666 | [31:29] 0x0 667 | [28:00] 0x0 668 | 669 | Stream Selector (single DWORD token) 670 | [31:29] 0x1 671 | [28] indicates whether this is a tessellator stream 672 | [27:04] 0x0 673 | [03:00] stream selector (0..15) 674 | 675 | Stream Data Definition (single DWORD token) 676 | Vertex Input Register Load 677 | [31:29] 0x2 678 | [28] 0x0 679 | [27:20] 0x0 680 | [19:16] type (dimensionality and data type) 681 | [15:04] 0x0 682 | [03:00] vertex register address (0..15) 683 | Data Skip (no register load) 684 | [31:29] 0x2 685 | [28] 0x1 686 | [27:20] 0x0 687 | [19:16] count of DWORDS to skip over (0..15) 688 | [15:00] 0x0 689 | Vertex Input Memory from Tessellator Data (single DWORD token) 690 | [31:29] 0x3 691 | [28] indicates whether data is normals or u/v 692 | [27:24] 0x0 693 | [23:20] vertex register address (0..15) 694 | [19:16] type (dimensionality) 695 | [15:04] 0x0 696 | [03:00] vertex register address (0..15) 697 | 698 | Constant Memory from Shader (multiple DWORD token) 699 | [31:29] 0x4 700 | [28:25] count of 4*DWORD constants to load (0..15) 701 | [24:07] 0x0 702 | [06:00] constant memory address (0..95) 703 | 704 | Extension Token (single or multiple DWORD token) 705 | [31:29] 0x5 706 | [28:24] count of additional DWORDs in token (0..31) 707 | [23:00] extension-specific information 708 | 709 | End-of-array token (single DWORD token) 710 | [31:29] 0x7 711 | [28:00] 0x1fffffff 712 | 713 | The stream selector token must be immediately followed by a contiguous set of stream data definition tokens. This token sequence fully defines that stream, including the set of elements within the stream, the order in which the elements appear, the type of each element, and the vertex register into which to load an element. 714 | Streams are allowed to include data which is not loaded into a vertex register, thus allowing data which is not used for this shader to exist in the vertex stream. This skipped data is defined only by a count of DWORDs to skip over, since the type information is irrelevant. 715 | The token sequence: 716 | Stream Select: stream=0 717 | Stream Data Definition (Load): type=FLOAT3; register=3 718 | Stream Data Definition (Load): type=FLOAT3; register=4 719 | Stream Data Definition (Skip): count=2 720 | Stream Data Definition (Load): type=FLOAT2; register=7 721 | 722 | defines stream zero to consist of 4 elements, 3 of which are loaded into registers and the fourth skipped over. Register 3 is loaded with the first three DWORDs in each vertex interpreted as FLOAT data. Register 4 is loaded with the 4th, 5th, and 6th DWORDs interpreted as FLOAT data. The next two DWORDs (7th and 8th) are skipped over and not loaded into any vertex input register. Register 7 is loaded with the 9th and 10th DWORDS interpreted as FLOAT data. 723 | Placing of tokens other than NOPs between the Stream Selector and Stream Data Definition tokens is disallowed. 724 | 725 | */ 726 | 727 | typedef enum _D3DVSD_TOKENTYPE 728 | { 729 | D3DVSD_TOKEN_NOP = 0, // NOP or extension 730 | D3DVSD_TOKEN_STREAM, // stream selector 731 | D3DVSD_TOKEN_STREAMDATA, // stream data definition (map to vertex input memory) 732 | D3DVSD_TOKEN_TESSELLATOR, // vertex input memory from tessellator 733 | D3DVSD_TOKEN_CONSTMEM, // constant memory from shader 734 | D3DVSD_TOKEN_EXT, // extension 735 | D3DVSD_TOKEN_END = 7, // end-of-array (requires all DWORD bits to be 1) 736 | D3DVSD_FORCE_DWORD = 0x7fffffff,// force 32-bit size enum 737 | } D3DVSD_TOKENTYPE; 738 | 739 | #define D3DVSD_TOKENTYPESHIFT 29 740 | #define D3DVSD_TOKENTYPEMASK (7 << D3DVSD_TOKENTYPESHIFT) 741 | 742 | #define D3DVSD_STREAMNUMBERSHIFT 0 743 | #define D3DVSD_STREAMNUMBERMASK (0xF << D3DVSD_STREAMNUMBERSHIFT) 744 | 745 | #define D3DVSD_DATALOADTYPESHIFT 28 746 | #define D3DVSD_DATALOADTYPEMASK (0x1 << D3DVSD_DATALOADTYPESHIFT) 747 | 748 | #define D3DVSD_DATATYPESHIFT 16 749 | #define D3DVSD_DATATYPEMASK (0xF << D3DVSD_DATATYPESHIFT) 750 | 751 | #define D3DVSD_SKIPCOUNTSHIFT 16 752 | #define D3DVSD_SKIPCOUNTMASK (0xF << D3DVSD_SKIPCOUNTSHIFT) 753 | 754 | #define D3DVSD_VERTEXREGSHIFT 0 755 | #define D3DVSD_VERTEXREGMASK (0x1F << D3DVSD_VERTEXREGSHIFT) 756 | 757 | #define D3DVSD_VERTEXREGINSHIFT 20 758 | #define D3DVSD_VERTEXREGINMASK (0xF << D3DVSD_VERTEXREGINSHIFT) 759 | 760 | #define D3DVSD_CONSTCOUNTSHIFT 25 761 | #define D3DVSD_CONSTCOUNTMASK (0xF << D3DVSD_CONSTCOUNTSHIFT) 762 | 763 | #define D3DVSD_CONSTADDRESSSHIFT 0 764 | #define D3DVSD_CONSTADDRESSMASK (0x7F << D3DVSD_CONSTADDRESSSHIFT) 765 | 766 | #define D3DVSD_CONSTRSSHIFT 16 767 | #define D3DVSD_CONSTRSMASK (0x1FFF << D3DVSD_CONSTRSSHIFT) 768 | 769 | #define D3DVSD_EXTCOUNTSHIFT 24 770 | #define D3DVSD_EXTCOUNTMASK (0x1F << D3DVSD_EXTCOUNTSHIFT) 771 | 772 | #define D3DVSD_EXTINFOSHIFT 0 773 | #define D3DVSD_EXTINFOMASK (0xFFFFFF << D3DVSD_EXTINFOSHIFT) 774 | 775 | #define D3DVSD_MAKETOKENTYPE(tokenType) ((tokenType << D3DVSD_TOKENTYPESHIFT) & D3DVSD_TOKENTYPEMASK) 776 | 777 | // macros for generation of CreateVertexShader Declaration token array 778 | 779 | // Set current stream 780 | // _StreamNumber [0..(MaxStreams-1)] stream to get data from 781 | // 782 | #define D3DVSD_STREAM( _StreamNumber ) \ 783 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAM) | (_StreamNumber)) 784 | 785 | // Set tessellator stream 786 | // 787 | #define D3DVSD_STREAMTESSSHIFT 28 788 | #define D3DVSD_STREAMTESSMASK (1 << D3DVSD_STREAMTESSSHIFT) 789 | #define D3DVSD_STREAM_TESS( ) \ 790 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAM) | (D3DVSD_STREAMTESSMASK)) 791 | 792 | // bind single vertex register to vertex element from vertex stream 793 | // 794 | // _VertexRegister [0..15] address of the vertex register 795 | // _Type [D3DVSDT_*] dimensionality and arithmetic data type 796 | 797 | #define D3DVSD_REG( _VertexRegister, _Type ) \ 798 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAMDATA) | \ 799 | ((_Type) << D3DVSD_DATATYPESHIFT) | (_VertexRegister)) 800 | 801 | // Skip _DWORDCount DWORDs in vertex 802 | // 803 | #define D3DVSD_SKIP( _DWORDCount ) \ 804 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAMDATA) | 0x10000000 | \ 805 | ((_DWORDCount) << D3DVSD_SKIPCOUNTSHIFT)) 806 | 807 | // load data into vertex shader constant memory 808 | // 809 | // _ConstantAddress [0..95] - address of constant array to begin filling data 810 | // _Count [0..15] - number of constant vectors to load (4 DWORDs each) 811 | // followed by 4*_Count DWORDS of data 812 | // 813 | #define D3DVSD_CONST( _ConstantAddress, _Count ) \ 814 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_CONSTMEM) | \ 815 | ((_Count) << D3DVSD_CONSTCOUNTSHIFT) | (_ConstantAddress)) 816 | 817 | // enable tessellator generated normals 818 | // 819 | // _VertexRegisterIn [0..15] address of vertex register whose input stream 820 | // will be used in normal computation 821 | // _VertexRegisterOut [0..15] address of vertex register to output the normal to 822 | // 823 | #define D3DVSD_TESSNORMAL( _VertexRegisterIn, _VertexRegisterOut ) \ 824 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_TESSELLATOR) | \ 825 | ((_VertexRegisterIn) << D3DVSD_VERTEXREGINSHIFT) | \ 826 | ((0x02) << D3DVSD_DATATYPESHIFT) | (_VertexRegisterOut)) 827 | 828 | // enable tessellator generated surface parameters 829 | // 830 | // _VertexRegister [0..15] address of vertex register to output parameters 831 | // 832 | #define D3DVSD_TESSUV( _VertexRegister ) \ 833 | (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_TESSELLATOR) | 0x10000000 | \ 834 | ((0x01) << D3DVSD_DATATYPESHIFT) | (_VertexRegister)) 835 | 836 | // Generates END token 837 | // 838 | #define D3DVSD_END() 0xFFFFFFFF 839 | 840 | // Generates NOP token 841 | #define D3DVSD_NOP() 0x00000000 842 | 843 | // bit declarations for _Type fields 844 | #define D3DVSDT_FLOAT1 0x00 // 1D float expanded to (value, 0., 0., 1.) 845 | #define D3DVSDT_FLOAT2 0x01 // 2D float expanded to (value, value, 0., 1.) 846 | #define D3DVSDT_FLOAT3 0x02 // 3D float expanded to (value, value, value, 1.) 847 | #define D3DVSDT_FLOAT4 0x03 // 4D float 848 | #define D3DVSDT_D3DCOLOR 0x04 // 4D packed unsigned bytes mapped to 0. to 1. range 849 | // Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A) 850 | #define D3DVSDT_UBYTE4 0x05 // 4D unsigned byte 851 | #define D3DVSDT_SHORT2 0x06 // 2D signed short expanded to (value, value, 0., 1.) 852 | #define D3DVSDT_SHORT4 0x07 // 4D signed short 853 | 854 | // assignments of vertex input registers for fixed function vertex shader 855 | // 856 | #define D3DVSDE_POSITION 0 857 | #define D3DVSDE_BLENDWEIGHT 1 858 | #define D3DVSDE_BLENDINDICES 2 859 | #define D3DVSDE_NORMAL 3 860 | #define D3DVSDE_PSIZE 4 861 | #define D3DVSDE_DIFFUSE 5 862 | #define D3DVSDE_SPECULAR 6 863 | #define D3DVSDE_TEXCOORD0 7 864 | #define D3DVSDE_TEXCOORD1 8 865 | #define D3DVSDE_TEXCOORD2 9 866 | #define D3DVSDE_TEXCOORD3 10 867 | #define D3DVSDE_TEXCOORD4 11 868 | #define D3DVSDE_TEXCOORD5 12 869 | #define D3DVSDE_TEXCOORD6 13 870 | #define D3DVSDE_TEXCOORD7 14 871 | #define D3DVSDE_POSITION2 15 872 | #define D3DVSDE_NORMAL2 16 873 | 874 | // Maximum supported number of texture coordinate sets 875 | #define D3DDP_MAXTEXCOORD 8 876 | 877 | 878 | // 879 | // Instruction Token Bit Definitions 880 | // 881 | #define D3DSI_OPCODE_MASK 0x0000FFFF 882 | 883 | typedef enum _D3DSHADER_INSTRUCTION_OPCODE_TYPE 884 | { 885 | D3DSIO_NOP = 0, // PS/VS 886 | D3DSIO_MOV , // PS/VS 887 | D3DSIO_ADD , // PS/VS 888 | D3DSIO_SUB , // PS 889 | D3DSIO_MAD , // PS/VS 890 | D3DSIO_MUL , // PS/VS 891 | D3DSIO_RCP , // VS 892 | D3DSIO_RSQ , // VS 893 | D3DSIO_DP3 , // PS/VS 894 | D3DSIO_DP4 , // PS/VS 895 | D3DSIO_MIN , // VS 896 | D3DSIO_MAX , // VS 897 | D3DSIO_SLT , // VS 898 | D3DSIO_SGE , // VS 899 | D3DSIO_EXP , // VS 900 | D3DSIO_LOG , // VS 901 | D3DSIO_LIT , // VS 902 | D3DSIO_DST , // VS 903 | D3DSIO_LRP , // PS 904 | D3DSIO_FRC , // VS 905 | D3DSIO_M4x4 , // VS 906 | D3DSIO_M4x3 , // VS 907 | D3DSIO_M3x4 , // VS 908 | D3DSIO_M3x3 , // VS 909 | D3DSIO_M3x2 , // VS 910 | 911 | D3DSIO_TEXCOORD = 64, // PS 912 | D3DSIO_TEXKILL , // PS 913 | D3DSIO_TEX , // PS 914 | D3DSIO_TEXBEM , // PS 915 | D3DSIO_TEXBEML , // PS 916 | D3DSIO_TEXREG2AR , // PS 917 | D3DSIO_TEXREG2GB , // PS 918 | D3DSIO_TEXM3x2PAD , // PS 919 | D3DSIO_TEXM3x2TEX , // PS 920 | D3DSIO_TEXM3x3PAD , // PS 921 | D3DSIO_TEXM3x3TEX , // PS 922 | D3DSIO_TEXM3x3DIFF , // PS 923 | D3DSIO_TEXM3x3SPEC , // PS 924 | D3DSIO_TEXM3x3VSPEC , // PS 925 | D3DSIO_EXPP , // VS 926 | D3DSIO_LOGP , // VS 927 | D3DSIO_CND , // PS 928 | D3DSIO_DEF , // PS 929 | D3DSIO_TEXREG2RGB , // PS 930 | D3DSIO_TEXDP3TEX , // PS 931 | D3DSIO_TEXM3x2DEPTH , // PS 932 | D3DSIO_TEXDP3 , // PS 933 | D3DSIO_TEXM3x3 , // PS 934 | D3DSIO_TEXDEPTH , // PS 935 | D3DSIO_CMP , // PS 936 | D3DSIO_BEM , // PS 937 | 938 | D3DSIO_PHASE = 0xFFFD, 939 | D3DSIO_COMMENT = 0xFFFE, 940 | D3DSIO_END = 0xFFFF, 941 | 942 | D3DSIO_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum 943 | } D3DSHADER_INSTRUCTION_OPCODE_TYPE; 944 | 945 | // 946 | // Co-Issue Instruction Modifier - if set then this instruction is to be 947 | // issued in parallel with the previous instruction(s) for which this bit 948 | // is not set. 949 | // 950 | #define D3DSI_COISSUE 0x40000000 951 | 952 | // 953 | // Parameter Token Bit Definitions 954 | // 955 | #define D3DSP_REGNUM_MASK 0x00001FFF 956 | 957 | // destination parameter write mask 958 | #define D3DSP_WRITEMASK_0 0x00010000 // Component 0 (X;Red) 959 | #define D3DSP_WRITEMASK_1 0x00020000 // Component 1 (Y;Green) 960 | #define D3DSP_WRITEMASK_2 0x00040000 // Component 2 (Z;Blue) 961 | #define D3DSP_WRITEMASK_3 0x00080000 // Component 3 (W;Alpha) 962 | #define D3DSP_WRITEMASK_ALL 0x000F0000 // All Components 963 | 964 | // destination parameter modifiers 965 | #define D3DSP_DSTMOD_SHIFT 20 966 | #define D3DSP_DSTMOD_MASK 0x00F00000 967 | 968 | typedef enum _D3DSHADER_PARAM_DSTMOD_TYPE 969 | { 970 | D3DSPDM_NONE = 0<>8)&0xFF) 1119 | #define D3DSHADER_VERSION_MINOR(_Version) (((_Version)>>0)&0xFF) 1120 | 1121 | // destination/source parameter register type 1122 | #define D3DSI_COMMENTSIZE_SHIFT 16 1123 | #define D3DSI_COMMENTSIZE_MASK 0x7FFF0000 1124 | #define D3DSHADER_COMMENT(_DWordSize) \ 1125 | ((((_DWordSize)<= 1200 1683 | #pragma warning(pop) 1684 | #else 1685 | #pragma warning(default:4201) 1686 | #endif 1687 | 1688 | #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ 1689 | #pragma endregion 1690 | 1691 | #endif /* (DIRECT3D_VERSION >= 0x0800) */ 1692 | #endif /* _D3D8TYPES(P)_H_ */ 1693 | 1694 | -------------------------------------------------------------------------------- /DirectX81SDK/include/ddrawex.h: -------------------------------------------------------------------------------- 1 | //********************************************************************* 2 | //* Microsoft Windows ** 3 | //* Copyright(c) Microsoft Corp., 1995-1997 ** 4 | //********************************************************************* 5 | // 6 | // DDRAWEX.H 7 | // 8 | // Header file for DirectDrawEx functionality 9 | 10 | #ifndef __DDRAWEXH__ 11 | #define __DDRAWEXH__ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include 18 | 19 | // {4FD2A832-86C8-11d0-8FCA-00C04FD9189D} 20 | DEFINE_GUID(CLSID_DirectDrawFactory, 21 | 0x4fd2a832, 0x86c8, 0x11d0, 0x8f, 0xca, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0x9d); 22 | 23 | DEFINE_GUID(IID_IDirectDrawFactory, 24 | 0x4fd2a833, 0x86c8, 0x11d0, 0x8f, 0xca, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0x9d); 25 | 26 | #ifndef DIRECTDRAW_VERSION 27 | 28 | //Functionality supported by DDrawex but not DX3 29 | #define DDSD_LPSURFACE 0x00000800l 30 | 31 | DEFINE_GUID( IID_IDirectDrawSurface3, 32 | 0xDA044E00,0x69B2,0x11D0,0xA1,0xD5,0x00,0xAA,0x00,0xB8,0xDF,0xBB ); 33 | 34 | typedef struct IDirectDrawSurface3 FAR *LPDIRECTDRAWSURFACE3; 35 | 36 | #undef INTERFACE 37 | #define INTERFACE IDirectDrawSurface3 38 | DECLARE_INTERFACE_( IDirectDrawSurface3, IUnknown ) 39 | { 40 | /*** IUnknown methods ***/ 41 | STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE; 42 | STDMETHOD_(ULONG,AddRef) (THIS) PURE; 43 | STDMETHOD_(ULONG,Release) (THIS) PURE; 44 | /*** IDirectDrawSurface methods ***/ 45 | STDMETHOD(AddAttachedSurface)(THIS_ LPDIRECTDRAWSURFACE3) PURE; 46 | STDMETHOD(AddOverlayDirtyRect)(THIS_ LPRECT) PURE; 47 | STDMETHOD(Blt)(THIS_ LPRECT,LPDIRECTDRAWSURFACE3, LPRECT,DWORD, LPDDBLTFX) PURE; 48 | STDMETHOD(BltBatch)(THIS_ LPDDBLTBATCH, DWORD, DWORD ) PURE; 49 | STDMETHOD(BltFast)(THIS_ DWORD,DWORD,LPDIRECTDRAWSURFACE3, LPRECT,DWORD) PURE; 50 | STDMETHOD(DeleteAttachedSurface)(THIS_ DWORD,LPDIRECTDRAWSURFACE3) PURE; 51 | STDMETHOD(EnumAttachedSurfaces)(THIS_ LPVOID,LPDDENUMSURFACESCALLBACK) PURE; 52 | STDMETHOD(EnumOverlayZOrders)(THIS_ DWORD,LPVOID,LPDDENUMSURFACESCALLBACK) PURE; 53 | STDMETHOD(Flip)(THIS_ LPDIRECTDRAWSURFACE3, DWORD) PURE; 54 | STDMETHOD(GetAttachedSurface)(THIS_ LPDDSCAPS, LPDIRECTDRAWSURFACE3 FAR *) PURE; 55 | STDMETHOD(GetBltStatus)(THIS_ DWORD) PURE; 56 | STDMETHOD(GetCaps)(THIS_ LPDDSCAPS) PURE; 57 | STDMETHOD(GetClipper)(THIS_ LPDIRECTDRAWCLIPPER FAR*) PURE; 58 | STDMETHOD(GetColorKey)(THIS_ DWORD, LPDDCOLORKEY) PURE; 59 | STDMETHOD(GetDC)(THIS_ HDC FAR *) PURE; 60 | STDMETHOD(GetFlipStatus)(THIS_ DWORD) PURE; 61 | STDMETHOD(GetOverlayPosition)(THIS_ LPLONG, LPLONG ) PURE; 62 | STDMETHOD(GetPalette)(THIS_ LPDIRECTDRAWPALETTE FAR*) PURE; 63 | STDMETHOD(GetPixelFormat)(THIS_ LPDDPIXELFORMAT) PURE; 64 | STDMETHOD(GetSurfaceDesc)(THIS_ LPDDSURFACEDESC) PURE; 65 | STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, LPDDSURFACEDESC) PURE; 66 | STDMETHOD(IsLost)(THIS) PURE; 67 | STDMETHOD(Lock)(THIS_ LPRECT,LPDDSURFACEDESC,DWORD,HANDLE) PURE; 68 | STDMETHOD(ReleaseDC)(THIS_ HDC) PURE; 69 | STDMETHOD(Restore)(THIS) PURE; 70 | STDMETHOD(SetClipper)(THIS_ LPDIRECTDRAWCLIPPER) PURE; 71 | STDMETHOD(SetColorKey)(THIS_ DWORD, LPDDCOLORKEY) PURE; 72 | STDMETHOD(SetOverlayPosition)(THIS_ LONG, LONG ) PURE; 73 | STDMETHOD(SetPalette)(THIS_ LPDIRECTDRAWPALETTE) PURE; 74 | STDMETHOD(Unlock)(THIS_ LPVOID) PURE; 75 | STDMETHOD(UpdateOverlay)(THIS_ LPRECT, LPDIRECTDRAWSURFACE3,LPRECT,DWORD, LPDDOVERLAYFX) PURE; 76 | STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD) PURE; 77 | STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE3) PURE; 78 | /*** Added in the v2 interface ***/ 79 | STDMETHOD(GetDDInterface)(THIS_ LPVOID FAR *) PURE; 80 | STDMETHOD(PageLock)(THIS_ DWORD) PURE; 81 | STDMETHOD(PageUnlock)(THIS_ DWORD) PURE; 82 | /*** Added in the v3 interface ***/ 83 | STDMETHOD(SetSurfaceDesc)(THIS_ LPDDSURFACEDESC, DWORD ) PURE; 84 | }; 85 | #endif 86 | 87 | 88 | 89 | 90 | #define DDSCAPS_DATAEXCHANGE (DDSCAPS_SYSTEMMEMORY|DDSCAPS_VIDEOMEMORY) 91 | 92 | #undef INTERFACE 93 | #define INTERFACE IDirectDrawFactory 94 | 95 | DECLARE_INTERFACE_(IDirectDrawFactory, IUnknown) 96 | { 97 | /*** IUnknown methods ***/ 98 | STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE; 99 | STDMETHOD_(ULONG,AddRef) (THIS) PURE; 100 | STDMETHOD_(ULONG,Release) (THIS) PURE; 101 | /*** IDirectDrawFactory methods ***/ 102 | STDMETHOD(CreateDirectDraw) (THIS_ GUID * pGUID, HWND hWnd, DWORD dwCoopLevelFlags, DWORD dwReserved, IUnknown *pUnkOuter, IDirectDraw **ppDirectDraw) PURE; 103 | STDMETHOD(DirectDrawEnumerate) (THIS_ LPDDENUMCALLBACK lpCallback, LPVOID lpContext) PURE; 104 | #ifdef UNICODE 105 | STDMETHOD(DirectDrawEnumerateA) (THIS_ LPDDENUMCALLBACKA lpCallback, LPVOID lpContext) PURE; 106 | #else 107 | STDMETHOD(DirectDrawEnumerateW) (THIS_ LPDDENUMCALLBACKW lpCallback, LPVOID lpContext) PURE; 108 | #endif 109 | }; 110 | 111 | 112 | 113 | // {618F8AD4-8B7A-11d0-8FCC-00C04FD9189D} 114 | DEFINE_GUID(IID_IDirectDraw3, 115 | 0x618f8ad4, 0x8b7a, 0x11d0, 0x8f, 0xcc, 0x0, 0xc0, 0x4f, 0xd9, 0x18, 0x9d); 116 | 117 | typedef struct IDirectDraw3 FAR *LPDIRECTDRAW3; 118 | 119 | #undef INTERFACE 120 | #define INTERFACE IDirectDraw3 121 | 122 | DECLARE_INTERFACE_(IDirectDraw3, IUnknown) 123 | { 124 | /*** IUnknown methods ***/ 125 | STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE; 126 | STDMETHOD_(ULONG,AddRef) (THIS) PURE; 127 | STDMETHOD_(ULONG,Release) (THIS) PURE; 128 | /*** IDirectDraw methods ***/ 129 | STDMETHOD(Compact)(THIS) PURE; 130 | STDMETHOD(CreateClipper)(THIS_ DWORD, LPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) PURE; 131 | STDMETHOD(CreatePalette)(THIS_ DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) PURE; 132 | STDMETHOD(CreateSurface)(THIS_ LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *, IUnknown FAR *) PURE; 133 | STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * ) PURE; 134 | STDMETHOD(EnumDisplayModes)( THIS_ DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ) PURE; 135 | STDMETHOD(EnumSurfaces)(THIS_ DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ) PURE; 136 | STDMETHOD(FlipToGDISurface)(THIS) PURE; 137 | STDMETHOD(GetCaps)( THIS_ LPDDCAPS, LPDDCAPS) PURE; 138 | STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESC) PURE; 139 | STDMETHOD(GetFourCCCodes)(THIS_ LPDWORD, LPDWORD ) PURE; 140 | STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE FAR *) PURE; 141 | STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORD) PURE; 142 | STDMETHOD(GetScanLine)(THIS_ LPDWORD) PURE; 143 | STDMETHOD(GetVerticalBlankStatus)(THIS_ LPBOOL ) PURE; 144 | STDMETHOD(Initialize)(THIS_ GUID FAR *) PURE; 145 | STDMETHOD(RestoreDisplayMode)(THIS) PURE; 146 | STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD) PURE; 147 | STDMETHOD(SetDisplayMode)(THIS_ DWORD, DWORD,DWORD, DWORD, DWORD) PURE; 148 | STDMETHOD(WaitForVerticalBlank)(THIS_ DWORD, HANDLE ) PURE; 149 | /*** Added in the v2 interface ***/ 150 | STDMETHOD(GetAvailableVidMem)(THIS_ LPDDSCAPS, LPDWORD, LPDWORD) PURE; 151 | /*** IDirectDraw3 methods ***/ 152 | STDMETHOD(GetSurfaceFromDC) (THIS_ HDC, IDirectDrawSurface **) PURE; 153 | }; 154 | 155 | #if !defined(__cplusplus) || defined(CINTERFACE) 156 | #define IDirectDraw3_QueryInterface(p, a, b) (p)->lpVtbl->QueryInterface(p, a, b) 157 | #define IDirectDraw3_AddRef(p) (p)->lpVtbl->AddRef(p) 158 | #define IDirectDraw3_Release(p) (p)->lpVtbl->Release(p) 159 | #define IDirectDraw3_Compact(p) (p)->lpVtbl->Compact(p) 160 | #define IDirectDraw3_CreateClipper(p, a, b, c) (p)->lpVtbl->CreateClipper(p, a, b, c) 161 | #define IDirectDraw3_CreatePalette(p, a, b, c, d) (p)->lpVtbl->CreatePalette(p, a, b, c, d) 162 | #define IDirectDraw3_CreateSurface(p, a, b, c) (p)->lpVtbl->CreateSurface(p, a, b, c) 163 | #define IDirectDraw3_DuplicateSurface(p, a, b) (p)->lpVtbl->DuplicateSurface(p, a, b) 164 | #define IDirectDraw3_EnumDisplayModes(p, a, b, c, d) (p)->lpVtbl->EnumDisplayModes(p, a, b, c, d) 165 | #define IDirectDraw3_EnumSurfaces(p, a, b, c, d) (p)->lpVtbl->EnumSurfaces(p, a, b, c, d) 166 | #define IDirectDraw3_FlipToGDISurface(p) (p)->lpVtbl->FlipToGDISurface(p) 167 | #define IDirectDraw3_GetCaps(p, a, b) (p)->lpVtbl->GetCaps(p, a, b) 168 | #define IDirectDraw3_GetDisplayMode(p, a) (p)->lpVtbl->GetDisplayMode(p, a) 169 | #define IDirectDraw3_GetFourCCCodes(p, a, b) (p)->lpVtbl->GetFourCCCodes(p, a, b) 170 | #define IDirectDraw3_GetGDISurface(p, a) (p)->lpVtbl->GetGDISurface(p, a) 171 | #define IDirectDraw3_GetMonitorFrequency(p, a) (p)->lpVtbl->GetMonitorFrequency(p, a) 172 | #define IDirectDraw3_GetScanLine(p, a) (p)->lpVtbl->GetScanLine(p, a) 173 | #define IDirectDraw3_GetVerticalBlankStatus(p, a) (p)->lpVtbl->GetVerticalBlankStatus(p, a) 174 | #define IDirectDraw3_Initialize(p, a) (p)->lpVtbl->Initialize(p, a) 175 | #define IDirectDraw3_RestoreDisplayMode(p) (p)->lpVtbl->RestoreDisplayMode(p) 176 | #define IDirectDraw3_SetCooperativeLevel(p, a, b) (p)->lpVtbl->SetCooperativeLevel(p, a, b) 177 | #define IDirectDraw3_SetDisplayMode(p, a, b, c, d, e) (p)->lpVtbl->SetDisplayMode(p, a, b, c, d, e) 178 | #define IDirectDraw3_WaitForVerticalBlank(p, a, b) (p)->lpVtbl->WaitForVerticalBlank(p, a, b) 179 | #define IDirectDraw3_GetAvailableVidMem(p, a, b, c) (p)->lpVtbl->GetAvailableVidMem(p, a, b, c) 180 | #define IDirectDraw3_GetSurfaceFromDC(p, a, b) (p)->lpVtbl->GetSurfaceFromDC(p, a, b) 181 | #endif 182 | 183 | 184 | 185 | /*=========================================================================== 186 | * 187 | * 188 | * DIRECTDRAWEX RETURN CODES 189 | * 190 | * The return values from DirectDrawEx Commands and Surface that return an 191 | * HRESULT are codes from DirectDrawEx concerning the results of the action 192 | * requested by DirectDrawEx. 193 | * 194 | *==========================================================================*/ 195 | 196 | /* 197 | * An attempt was made to load ddraw.dll 198 | */ 199 | #define DDERR_LOADFAILED MAKE_DDHRESULT( 901 ) 200 | 201 | /* 202 | * Unable to determine module/os version number 203 | */ 204 | #define DDERR_BADVERSIONINFO MAKE_DDHRESULT( 902 ) 205 | 206 | /* 207 | * Unable to determine address of ddraw.dll exported symbol (DirectDrawCreate or 208 | * DirectDrawEnumerate). 209 | */ 210 | #define DDERR_BADPROCADDRESS MAKE_DDHRESULT( 903 ) 211 | 212 | /* 213 | * Legacy usage: do not use QI() to create D3D device objects from surface objects. 214 | * Use IDirect3D2::CreateDevice() 215 | */ 216 | #define DDERR_LEGACYUSAGE MAKE_DDHRESULT( 904 ) 217 | 218 | #ifdef __cplusplus 219 | } 220 | #endif 221 | 222 | 223 | #endif // __DDRAWEXH__ 224 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger, aap 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XDinput 2 | 3 | XInput to DInput translator. THIS IS ALPHA WARE. 4 | 5 | Code is based on https://github.com/elishacloud/DirectX-Wrappers. 6 | 7 | Since some games don't support XInput and the XInput to DInput mapping from windows is 8 | totally useless, another solution is needed. 9 | XInput plus works in principle but it did not work with Scarface The World is Yours 10 | and since it isn't open source, I had to write my own. 11 | 12 | I only tested it with Scarface The World is Yours and only on one machine, 13 | I expect problems with other games or other machines, but at least you have 14 | source code to fix it. 15 | 16 | Also vibration isn't supported yet. 17 | 18 | # Downloads 19 | 20 | Binary files are in the [bin](bin) directory. 21 | The verbose dll will print some stuff that might be helpful if things don't work. 22 | 23 | # How to get Scarface to load this 24 | 25 | First of all, install [SilentPatch](https://github.com/CookiePLMonster/SilentPatchScarface). 26 | It comes with the ultimate asi loader, which allows the game to load dinput8.dll from the game directory 27 | (Normally it doesn't do this because it uses CoCreateInstance, which uses the class registry and loads dinput8.dll from system32). 28 | Then simply put dinput8.dll into the game directory and TURN OFF vibration, it crashes the game for some reason 29 | (and xdinput doesn't support it anyway). 30 | -------------------------------------------------------------------------------- /bin/dinput8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aap/XDinput/cb1ec9876f7a9e705505da9359113182d72de492/bin/dinput8.dll -------------------------------------------------------------------------------- /bin/dinput8_verbose.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aap/XDinput/cb1ec9876f7a9e705505da9359113182d72de492/bin/dinput8_verbose.dll -------------------------------------------------------------------------------- /dinput8.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dinput8", "dinput8\dinput8.vcxproj", "{C68F48DD-0B73-4C69-9CEB-D8F3E1369D97}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C68F48DD-0B73-4C69-9CEB-D8F3E1369D97}.Debug|x86.ActiveCfg = Debug|Win32 15 | {C68F48DD-0B73-4C69-9CEB-D8F3E1369D97}.Debug|x86.Build.0 = Debug|Win32 16 | {C68F48DD-0B73-4C69-9CEB-D8F3E1369D97}.Release|x86.ActiveCfg = Release|Win32 17 | {C68F48DD-0B73-4C69-9CEB-D8F3E1369D97}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /dinput8/AddressLookupTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | constexpr UINT MaxIndex = 6; 7 | 8 | template 9 | class AddressLookupTable 10 | { 11 | public: 12 | explicit AddressLookupTable() {} 13 | ~AddressLookupTable() 14 | { 15 | ConstructorFlag = true; 16 | 17 | for (const auto& cache : g_map) 18 | { 19 | for (const auto& entry : cache) 20 | { 21 | entry.second->DeleteMe(); 22 | } 23 | } 24 | } 25 | 26 | template 27 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 0; }; 28 | template <> 29 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 1; }; 30 | template <> 31 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 2; }; 32 | template <> 33 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 3; }; 34 | template <> 35 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 4; }; 36 | template <> 37 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 5; }; 38 | 39 | template 40 | T *FindAddress(void *Proxy) 41 | { 42 | if (!Proxy) 43 | { 44 | return nullptr; 45 | } 46 | 47 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 48 | auto it = g_map[CacheIndex].find(Proxy); 49 | 50 | if (it != std::end(g_map[CacheIndex])) 51 | { 52 | return static_cast(it->second); 53 | } 54 | 55 | return new T(static_cast(Proxy)); 56 | } 57 | 58 | template 59 | void SaveAddress(T *Wrapper, void *Proxy) 60 | { 61 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 62 | if (Wrapper && Proxy) 63 | { 64 | g_map[CacheIndex][Proxy] = Wrapper; 65 | } 66 | } 67 | 68 | template 69 | void DeleteAddress(T *Wrapper) 70 | { 71 | if (!Wrapper || ConstructorFlag) 72 | { 73 | return; 74 | } 75 | 76 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 77 | auto it = std::find_if(g_map[CacheIndex].begin(), g_map[CacheIndex].end(), 78 | [=](auto Map) -> bool { return Map.second == Wrapper; }); 79 | 80 | if (it != std::end(g_map[CacheIndex])) 81 | { 82 | it = g_map[CacheIndex].erase(it); 83 | } 84 | } 85 | 86 | private: 87 | bool ConstructorFlag = false; 88 | D *unused = nullptr; 89 | std::unordered_map g_map[MaxIndex]; 90 | }; 91 | 92 | class AddressLookupTableObject 93 | { 94 | public: 95 | virtual ~AddressLookupTableObject() { } 96 | 97 | void DeleteMe() 98 | { 99 | delete this; 100 | } 101 | }; 102 | -------------------------------------------------------------------------------- /dinput8/IClassFactory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | /************************/ 20 | /*** IUnknown methods ***/ 21 | /************************/ 22 | 23 | HRESULT m_IClassFactory::QueryInterface(REFIID riid, LPVOID FAR * ppvObj) 24 | { 25 | if ((riid == IID_IClassFactory || riid == IID_IUnknown) && ppvObj) 26 | { 27 | AddRef(); 28 | 29 | *ppvObj = this; 30 | 31 | return S_OK; 32 | } 33 | 34 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 35 | 36 | if (SUCCEEDED(hr)) 37 | { 38 | genericQueryInterface(riid, ppvObj); 39 | } 40 | 41 | return hr; 42 | } 43 | 44 | ULONG m_IClassFactory::AddRef() 45 | { 46 | return ProxyInterface->AddRef(); 47 | } 48 | 49 | ULONG m_IClassFactory::Release() 50 | { 51 | ULONG ref = ProxyInterface->Release(); 52 | 53 | if (ref == 0) 54 | { 55 | delete this; 56 | } 57 | 58 | return ref; 59 | } 60 | 61 | /*****************************/ 62 | /*** IClassFactory methods ***/ 63 | /*****************************/ 64 | 65 | HRESULT m_IClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject) 66 | { 67 | HRESULT hr = ProxyInterface->CreateInstance(pUnkOuter, riid, ppvObject); 68 | 69 | if (SUCCEEDED(hr)) 70 | { 71 | genericQueryInterface(riid, ppvObject); 72 | } 73 | 74 | return hr; 75 | } 76 | 77 | HRESULT m_IClassFactory::LockServer(BOOL fLock) 78 | { 79 | return ProxyInterface->LockServer(fLock); 80 | } 81 | -------------------------------------------------------------------------------- /dinput8/IClassFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | 6 | typedef void(WINAPI *IQueryInterfaceProc)(REFIID, LPVOID *); 7 | 8 | class m_IClassFactory : public IClassFactory 9 | { 10 | private: 11 | IClassFactory *ProxyInterface; 12 | REFIID WrapperID = IID_IClassFactory; 13 | 14 | public: 15 | m_IClassFactory(IClassFactory *aOriginal) : ProxyInterface(aOriginal) {} 16 | ~m_IClassFactory() {} 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj); 20 | STDMETHOD_(ULONG, AddRef) (THIS); 21 | STDMETHOD_(ULONG, Release) (THIS); 22 | 23 | /*** IClassFactory methods ***/ 24 | STDMETHOD(CreateInstance)(IUnknown *pUnkOuter, REFIID riid, void **ppvObject); 25 | STDMETHOD(LockServer)(BOOL fLock); 26 | }; 27 | -------------------------------------------------------------------------------- /dinput8/IDirectInput8A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | HRESULT m_IDirectInput8A::QueryInterface(REFIID riid, LPVOID * ppvObj) 20 | { 21 | if ((riid == IID_IDirectInput8A || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirectInput8A::AddRef() 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirectInput8A::Release() 46 | { 47 | ULONG ref = ProxyInterface->Release(); 48 | 49 | if (ref == 0) 50 | { 51 | delete this; 52 | } 53 | 54 | return ref; 55 | } 56 | 57 | HRESULT m_IDirectInput8A::CreateDevice(REFGUID rguid, LPDIRECTINPUTDEVICE8A *lplpDirectInputDevice, LPUNKNOWN pUnkOuter) 58 | { 59 | HRESULT hr = ProxyInterface->CreateDevice(rguid, lplpDirectInputDevice, pUnkOuter); 60 | 61 | if (SUCCEEDED(hr) && lplpDirectInputDevice) 62 | { 63 | *lplpDirectInputDevice = ProxyAddressLookupTable.FindAddress(*lplpDirectInputDevice); 64 | m_IDirectInputDevice8A *dev = *(m_IDirectInputDevice8A**)lplpDirectInputDevice; 65 | if(rguid == hookedPad.guid) 66 | hookedPad.Init(dev); 67 | } 68 | 69 | return hr; 70 | } 71 | 72 | static LPDIENUMDEVICESCALLBACKA origCB; 73 | BOOL PASCAL MyEnumDevices(LPCDIDEVICEINSTANCEA inst, LPVOID arg) 74 | { 75 | if((inst->dwDevType&0xFF) == DI8DEVTYPE_GAMEPAD){ 76 | #ifdef VERBOSE 77 | printf("seeing gamepad <%s>\n", inst->tszInstanceName); 78 | #endif 79 | if(strcmp(inst->tszInstanceName, "Controller (XBOX 360 For Windows)") == 0 || 80 | strcmp(inst->tszInstanceName, "Controller (Xbox One For Windows)") == 0){ 81 | strncpy(((DIDEVICEINSTANCEA*)inst)->tszInstanceName, "Hackpad", MAX_PATH); 82 | strncpy(((DIDEVICEINSTANCEA*)inst)->tszProductName, "Hackpad", MAX_PATH); 83 | hookedPad.guid = inst->guidInstance; 84 | } 85 | return origCB(inst, arg); 86 | } 87 | return origCB(inst, arg); 88 | } 89 | 90 | HRESULT m_IDirectInput8A::EnumDevices(DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback, LPVOID pvRef, DWORD dwFlags) 91 | { 92 | origCB = lpCallback; 93 | return ProxyInterface->EnumDevices(dwDevType, MyEnumDevices, pvRef, dwFlags); 94 | // return ProxyInterface->EnumDevices(dwDevType, lpCallback, pvRef, dwFlags); 95 | } 96 | 97 | HRESULT m_IDirectInput8A::GetDeviceStatus(REFGUID rguidInstance) 98 | { 99 | return ProxyInterface->GetDeviceStatus(rguidInstance); 100 | } 101 | 102 | HRESULT m_IDirectInput8A::RunControlPanel(HWND hwndOwner, DWORD dwFlags) 103 | { 104 | return ProxyInterface->RunControlPanel(hwndOwner, dwFlags); 105 | } 106 | 107 | HRESULT m_IDirectInput8A::Initialize(HINSTANCE hinst, DWORD dwVersion) 108 | { 109 | return ProxyInterface->Initialize(hinst, dwVersion); 110 | } 111 | 112 | HRESULT m_IDirectInput8A::FindDevice(REFGUID rguidClass, LPCSTR ptszName, LPGUID pguidInstance) 113 | { 114 | return ProxyInterface->FindDevice(rguidClass, ptszName, pguidInstance); 115 | } 116 | 117 | HRESULT m_IDirectInput8A::EnumDevicesBySemantics(LPCSTR ptszUserName, LPDIACTIONFORMATA lpdiActionFormat, LPDIENUMDEVICESBYSEMANTICSCBA lpCallback, LPVOID pvRef, DWORD dwFlags) 118 | { 119 | if (!lpCallback) 120 | { 121 | return E_INVALIDARG; 122 | } 123 | 124 | ENUMDEVICEA CallbackContext; 125 | CallbackContext.pvRef = pvRef; 126 | CallbackContext.lpCallback = lpCallback; 127 | 128 | return ProxyInterface->EnumDevicesBySemantics(ptszUserName, lpdiActionFormat, m_IDirectInputEnumDevice::EnumDeviceCallbackA, &CallbackContext, dwFlags); 129 | } 130 | 131 | HRESULT m_IDirectInput8A::ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK lpdiCallback, LPDICONFIGUREDEVICESPARAMSA lpdiCDParams, DWORD dwFlags, LPVOID pvRefData) 132 | { 133 | return ProxyInterface->ConfigureDevices(lpdiCallback, lpdiCDParams, dwFlags, pvRefData); 134 | } 135 | -------------------------------------------------------------------------------- /dinput8/IDirectInput8A.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInput8A : public IDirectInput8A, public AddressLookupTableObject 4 | { 5 | private: 6 | IDirectInput8A *ProxyInterface; 7 | 8 | public: 9 | m_IDirectInput8A(IDirectInput8A *aOriginal) : ProxyInterface(aOriginal) 10 | { 11 | ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); 12 | } 13 | ~m_IDirectInput8A() 14 | { 15 | ProxyAddressLookupTable.DeleteAddress(this); 16 | } 17 | 18 | IDirectInput8A *GetProxyInterface() { return ProxyInterface; } 19 | 20 | /*** IUnknown methods ***/ 21 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 22 | STDMETHOD_(ULONG, AddRef)(THIS); 23 | STDMETHOD_(ULONG, Release)(THIS); 24 | 25 | /*** IDirectInput8A methods ***/ 26 | STDMETHOD(CreateDevice)(THIS_ REFGUID, LPDIRECTINPUTDEVICE8A *, LPUNKNOWN); 27 | STDMETHOD(EnumDevices)(THIS_ DWORD, LPDIENUMDEVICESCALLBACKA, LPVOID, DWORD); 28 | STDMETHOD(GetDeviceStatus)(THIS_ REFGUID); 29 | STDMETHOD(RunControlPanel)(THIS_ HWND, DWORD); 30 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD); 31 | STDMETHOD(FindDevice)(THIS_ REFGUID, LPCSTR, LPGUID); 32 | STDMETHOD(EnumDevicesBySemantics)(THIS_ LPCSTR, LPDIACTIONFORMATA, LPDIENUMDEVICESBYSEMANTICSCBA, LPVOID, DWORD); 33 | STDMETHOD(ConfigureDevices)(THIS_ LPDICONFIGUREDEVICESCALLBACK, LPDICONFIGUREDEVICESPARAMSA, DWORD, LPVOID); 34 | }; 35 | -------------------------------------------------------------------------------- /dinput8/IDirectInput8W.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | HRESULT m_IDirectInput8W::QueryInterface(REFIID riid, LPVOID * ppvObj) 20 | { 21 | if ((riid == IID_IDirectInput8W || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirectInput8W::AddRef() 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirectInput8W::Release() 46 | { 47 | ULONG ref = ProxyInterface->Release(); 48 | 49 | if (ref == 0) 50 | { 51 | delete this; 52 | } 53 | 54 | return ref; 55 | } 56 | 57 | HRESULT m_IDirectInput8W::CreateDevice(REFGUID rguid, LPDIRECTINPUTDEVICE8W *lplpDirectInputDevice, LPUNKNOWN pUnkOuter) 58 | { 59 | HRESULT hr = ProxyInterface->CreateDevice(rguid, lplpDirectInputDevice, pUnkOuter); 60 | 61 | if (SUCCEEDED(hr) && lplpDirectInputDevice) 62 | { 63 | *lplpDirectInputDevice = ProxyAddressLookupTable.FindAddress(*lplpDirectInputDevice); 64 | } 65 | 66 | return hr; 67 | } 68 | 69 | HRESULT m_IDirectInput8W::EnumDevices(DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback, LPVOID pvRef, DWORD dwFlags) 70 | { 71 | return ProxyInterface->EnumDevices(dwDevType, lpCallback, pvRef, dwFlags); 72 | } 73 | 74 | HRESULT m_IDirectInput8W::GetDeviceStatus(REFGUID rguidInstance) 75 | { 76 | return ProxyInterface->GetDeviceStatus(rguidInstance); 77 | } 78 | 79 | HRESULT m_IDirectInput8W::RunControlPanel(HWND hwndOwner, DWORD dwFlags) 80 | { 81 | return ProxyInterface->RunControlPanel(hwndOwner, dwFlags); 82 | } 83 | 84 | HRESULT m_IDirectInput8W::Initialize(HINSTANCE hinst, DWORD dwVersion) 85 | { 86 | return ProxyInterface->Initialize(hinst, dwVersion); 87 | } 88 | 89 | HRESULT m_IDirectInput8W::FindDevice(REFGUID rguidClass, LPCWSTR ptszName, LPGUID pguidInstance) 90 | { 91 | return ProxyInterface->FindDevice(rguidClass, ptszName, pguidInstance); 92 | } 93 | 94 | HRESULT m_IDirectInput8W::EnumDevicesBySemantics(LPCWSTR ptszUserName, LPDIACTIONFORMATW lpdiActionFormat, LPDIENUMDEVICESBYSEMANTICSCBW lpCallback, LPVOID pvRef, DWORD dwFlags) 95 | { 96 | if (!lpCallback) 97 | { 98 | return E_INVALIDARG; 99 | } 100 | 101 | ENUMDEVICEW CallbackContext; 102 | CallbackContext.pvRef = pvRef; 103 | CallbackContext.lpCallback = lpCallback; 104 | 105 | return ProxyInterface->EnumDevicesBySemantics(ptszUserName, lpdiActionFormat, m_IDirectInputEnumDevice::EnumDeviceCallbackW, &CallbackContext, dwFlags); 106 | } 107 | 108 | HRESULT m_IDirectInput8W::ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK lpdiCallback, LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData) 109 | { 110 | return ProxyInterface->ConfigureDevices(lpdiCallback, lpdiCDParams, dwFlags, pvRefData); 111 | } 112 | -------------------------------------------------------------------------------- /dinput8/IDirectInput8W.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInput8W : public IDirectInput8W, public AddressLookupTableObject 4 | { 5 | private: 6 | IDirectInput8W *ProxyInterface; 7 | 8 | public: 9 | m_IDirectInput8W(IDirectInput8W *aOriginal) : ProxyInterface(aOriginal) 10 | { 11 | ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); 12 | } 13 | ~m_IDirectInput8W() 14 | { 15 | ProxyAddressLookupTable.DeleteAddress(this); 16 | } 17 | 18 | IDirectInput8W *GetProxyInterface() { return ProxyInterface; } 19 | 20 | /*** IUnknown methods ***/ 21 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 22 | STDMETHOD_(ULONG, AddRef)(THIS); 23 | STDMETHOD_(ULONG, Release)(THIS); 24 | 25 | /*** IDirectInput8W methods ***/ 26 | STDMETHOD(CreateDevice)(THIS_ REFGUID, LPDIRECTINPUTDEVICE8W *, LPUNKNOWN); 27 | STDMETHOD(EnumDevices)(THIS_ DWORD, LPDIENUMDEVICESCALLBACKW, LPVOID, DWORD); 28 | STDMETHOD(GetDeviceStatus)(THIS_ REFGUID); 29 | STDMETHOD(RunControlPanel)(THIS_ HWND, DWORD); 30 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD); 31 | STDMETHOD(FindDevice)(THIS_ REFGUID, LPCWSTR, LPGUID); 32 | STDMETHOD(EnumDevicesBySemantics)(THIS_ LPCWSTR, LPDIACTIONFORMATW, LPDIENUMDEVICESBYSEMANTICSCBW, LPVOID, DWORD); 33 | STDMETHOD(ConfigureDevices)(THIS_ LPDICONFIGUREDEVICESCALLBACK, LPDICONFIGUREDEVICESPARAMSW, DWORD, LPVOID); 34 | }; 35 | -------------------------------------------------------------------------------- /dinput8/IDirectInputDevice8A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | #include 19 | 20 | #pragma comment(lib, "dinput8.lib") 21 | #pragma comment(lib, "Xinput9_1_0.lib") 22 | 23 | HookedPad hookedPad; 24 | 25 | 26 | /* 27 | DIDEVICEOBJECTINSTANCEA xinputObjectsDefault[20] = { 28 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_YAxis, 0, 29 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(1) | DIDFT_FFACTUATOR, 30 | DIDOI_POLLED | DIDOI_ASPECTPOSITION | DIDOI_FFACTUATOR, 31 | "Y", 10, 256, 1, 0, 1, 0x31, 0, 0, 0 }, 32 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_XAxis, 4, 33 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(0) | DIDFT_FFACTUATOR, 34 | DIDOI_POLLED | DIDOI_ASPECTPOSITION | DIDOI_FFACTUATOR, 35 | "X", 10, 256, 1, 0, 1, 0x30, 0, 0, 0 }, 36 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_RyAxis, 8, 37 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(4), 38 | DIDOI_ASPECTPOSITION, 39 | "Y Rotation", 0, 0, 2, 0, 1, 0x34, 0, 0, 0 }, 40 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_RxAxis, 0xC, 41 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(3), 42 | DIDOI_ASPECTPOSITION, 43 | "X Rotation", 0, 0, 2, 0, 1, 0x33, 0, 0, 0 }, 44 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_ZAxis, 0x10, 45 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(2), 46 | DIDOI_ASPECTPOSITION, 47 | "Z Axis", 0, 0, 3, 0, 1, 0x32, 0, 0, 0 }, 48 | 49 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x18, 50 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(0) | DIDFT_FFEFFECTTRIGGER, 51 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 52 | "1", 0, 0, 0, 0, 9, 0x1, 0, 0, 0 }, 53 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x19, 54 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(1) | DIDFT_FFEFFECTTRIGGER, 55 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 56 | "2", 0, 0, 0, 0, 9, 0x2, 0, 0, 0 }, 57 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1A, 58 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(2) | DIDFT_FFEFFECTTRIGGER, 59 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 60 | "3", 0, 0, 0, 0, 9, 0x3, 0, 0, 0 }, 61 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1B, 62 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(3) | DIDFT_FFEFFECTTRIGGER, 63 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 64 | "4", 0, 0, 0, 0, 9, 0x4, 0, 0, 0 }, 65 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1C, 66 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(4) | DIDFT_FFEFFECTTRIGGER, 67 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 68 | "5", 0, 0, 0, 0, 9, 0x5, 0, 0, 0 }, 69 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1D, 70 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(5) | DIDFT_FFEFFECTTRIGGER, 71 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 72 | "6", 0, 0, 0, 0, 9, 0x6, 0, 0, 0 }, 73 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1E, 74 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(6) | DIDFT_FFEFFECTTRIGGER, 75 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 76 | "7", 0, 0, 0, 0, 9, 0x7, 0, 0, 0 }, 77 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1F, 78 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(7) | DIDFT_FFEFFECTTRIGGER, 79 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 80 | "8", 0, 0, 0, 0, 9, 0x8, 0, 0, 0 }, 81 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x20, 82 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(8) | DIDFT_FFEFFECTTRIGGER, 83 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 84 | "9", 0, 0, 0, 0, 9, 0x9, 0, 0, 0 }, 85 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x21, 86 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(9) | DIDFT_FFEFFECTTRIGGER, 87 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 88 | "10", 0, 0, 0, 0, 9, 0x10, 0, 0, 0 }, 89 | 90 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_POV, 0x14, 91 | DIDFT_POV, 92 | 0, 93 | "Hat Switch", 0, 0, 0, 0, 1, 0x39, 14, 0, 0 }, 94 | 95 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 96 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(0), 97 | 0, 98 | "Collection 0 - Game Pad", 0, 0, 0, 0, 1, 0x5, 0, 0, 0 }, 99 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 100 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(1), 101 | 0, 102 | "Collection 1", 0, 0, 0, 0, 1, 0, 0, 0, 0 }, 103 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 104 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(2), 105 | 0, 106 | "Collection 2", 0, 0, 0, 0, 1, 0, 0, 0, 0 }, 107 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 108 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(3), 109 | 0, 110 | "Collection 3", 0, 0, 0, 0, 1, 0, 0, 0, 0 }, 111 | 112 | }; 113 | */ 114 | 115 | DIDEVICEOBJECTINSTANCEA xinputObjects[] = { 116 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_XAxis, 0, 117 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(0) | DIDFT_FFACTUATOR, 118 | DIDOI_POLLED | DIDOI_ASPECTPOSITION | DIDOI_FFACTUATOR, 119 | "X", 10, 256, 1, 0, 1, 0x30, 0, 0, 0 }, 120 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_YAxis, 4, 121 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(1) | DIDFT_FFACTUATOR, 122 | DIDOI_POLLED | DIDOI_ASPECTPOSITION | DIDOI_FFACTUATOR, 123 | "Y", 10, 256, 1, 0, 1, 0x31, 0, 0, 0 }, 124 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_RxAxis, 8, 125 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(2), 126 | DIDOI_ASPECTPOSITION, 127 | "X Rotation", 0, 0, 2, 0, 1, 0x33, 0, 0, 0 }, 128 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_RyAxis, 0xC, 129 | DIDFT_ABSAXIS | DIDFT_MAKEINSTANCE(3), 130 | DIDOI_ASPECTPOSITION, 131 | "Y Rotation", 0, 0, 2, 0, 1, 0x34, 0, 0, 0 }, 132 | 133 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x18, 134 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(0) | DIDFT_FFEFFECTTRIGGER, 135 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 136 | "1", 0, 0, 0, 0, 9, 0x1, 0, 0, 0 }, 137 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x19, 138 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(1) | DIDFT_FFEFFECTTRIGGER, 139 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 140 | "2", 0, 0, 0, 0, 9, 0x2, 0, 0, 0 }, 141 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1A, 142 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(2) | DIDFT_FFEFFECTTRIGGER, 143 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 144 | "3", 0, 0, 0, 0, 9, 0x3, 0, 0, 0 }, 145 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1B, 146 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(3) | DIDFT_FFEFFECTTRIGGER, 147 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 148 | "4", 0, 0, 0, 0, 9, 0x4, 0, 0, 0 }, 149 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1C, 150 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(4) | DIDFT_FFEFFECTTRIGGER, 151 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 152 | "5", 0, 0, 0, 0, 9, 0x5, 0, 0, 0 }, 153 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1D, 154 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(5) | DIDFT_FFEFFECTTRIGGER, 155 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 156 | "6", 0, 0, 0, 0, 9, 0x6, 0, 0, 0 }, 157 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1E, 158 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(6) | DIDFT_FFEFFECTTRIGGER, 159 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 160 | "7", 0, 0, 0, 0, 9, 0x7, 0, 0, 0 }, 161 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x1F, 162 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(7) | DIDFT_FFEFFECTTRIGGER, 163 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 164 | "8", 0, 0, 0, 0, 9, 0x8, 0, 0, 0 }, 165 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x20, 166 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(8) | DIDFT_FFEFFECTTRIGGER, 167 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 168 | "9", 0, 0, 0, 0, 9, 0x9, 0, 0, 0 }, 169 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x21, 170 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(9) | DIDFT_FFEFFECTTRIGGER, 171 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 172 | "10", 0, 0, 0, 0, 9, 0xA, 0, 0, 0 }, 173 | 174 | #if 1 175 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x16, 176 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(10) | DIDFT_FFEFFECTTRIGGER, 177 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 178 | "11", 0, 0, 0, 0, 9, 0xB, 0, 0, 0 }, 179 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Button, 0x17, 180 | DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE(11) | DIDFT_FFEFFECTTRIGGER, 181 | DIDOI_POLLED | DIDOI_FFEFFECTTRIGGER, 182 | "12", 0, 0, 0, 0, 9, 0xC, 0, 0, 0 }, 183 | #endif 184 | 185 | 186 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_POV, 0x10, 187 | DIDFT_POV, 188 | 0, 189 | "Hat Switch", 0, 0, 0, 0, 1, 0x39, 14, 0, 0 }, 190 | 191 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 192 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(0), 193 | 0, 194 | "Collection 0 - Game Pad", 0, 0, 0, 0, 1, 0x5, 0, 0, 0 }, 195 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 196 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(1), 197 | 0, 198 | "Collection 1", 0, 0, 0, 0, 1, 0, 0, 0, 0 }, 199 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 200 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(2), 201 | 0, 202 | "Collection 2", 0, 0, 0, 0, 1, 0, 0, 0, 0 }, 203 | { sizeof(DIDEVICEOBJECTINSTANCEA), GUID_Unknown, 0, 204 | DIDFT_COLLECTION | DIDFT_NODATA | DIDFT_MAKEINSTANCE(3), 205 | 0, 206 | "Collection 3", 0, 0, 0, 0, 1, 0, 0, 0, 0 }, 207 | { 0 } 208 | }; 209 | 210 | #define DBTN(data, i) (*(BYTE*)((char*)(data) + format.rgodf[i].dwOfs)) 211 | #define DAXIS(data, i) (*(LONG*)((char*)(data) + format.rgodf[i].dwOfs)) 212 | #define DPOV(data, i) (*(LONG*)((char*)(data) + format.rgodf[i].dwOfs)) // actually same as axis 213 | 214 | void 215 | HookedPad::Init(m_IDirectInputDevice8A *p) 216 | { 217 | int i; 218 | XINPUT_STATE state; 219 | 220 | for(i = 0; i < 20; i++) 221 | buttonIds[i] = -1; 222 | for(i = 0; i < 20; i++) 223 | axisIds[i] = -1; 224 | povId = -1; 225 | 226 | pad = p; 227 | for(i = 0; i < 4; i++) 228 | if(XInputGetState(i, &state) == ERROR_SUCCESS){ 229 | #ifdef VERBOSE 230 | printf("using xinput pad %d\n", i); 231 | #endif 232 | xpadId = i; 233 | return; 234 | } 235 | // fail 236 | pad = NULL; 237 | } 238 | 239 | void HookedPad::X2D(void *ds, XINPUT_STATE *xs) 240 | { 241 | DBTN(ds, buttonIds[0]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_A) ? 0x80 : 0; 242 | DBTN(ds, buttonIds[1]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_B) ? 0x80 : 0; 243 | DBTN(ds, buttonIds[2]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_Y) ? 0x80 : 0; 244 | DBTN(ds, buttonIds[3]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_X) ? 0x80 : 0; 245 | 246 | DBTN(ds, buttonIds[4]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 0x80 : 0; 247 | DBTN(ds, buttonIds[5]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 0x80 : 0; 248 | DBTN(ds, buttonIds[6]) = (xs->Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) ? 0x80 : 0; 249 | DBTN(ds, buttonIds[7]) = (xs->Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) ? 0x80 : 0; 250 | DBTN(ds, buttonIds[8]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_START) ? 0x80 : 0; 251 | DBTN(ds, buttonIds[9]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? 0x80 : 0; 252 | DBTN(ds, buttonIds[10]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? 0x80 : 0; 253 | DBTN(ds, buttonIds[11]) = (xs->Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? 0x80 : 0; 254 | 255 | if(xs->Gamepad.sThumbLX > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE || xs->Gamepad.sThumbLX < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) 256 | DAXIS(ds, axisIds[0]) = xs->Gamepad.sThumbLX + 32768; 257 | else 258 | DAXIS(ds, axisIds[0]) = 32768; 259 | if(xs->Gamepad.sThumbLY > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE || xs->Gamepad.sThumbLY < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) 260 | DAXIS(ds, axisIds[1]) = 32768 - xs->Gamepad.sThumbLY; 261 | else 262 | DAXIS(ds, axisIds[1]) = 32768; 263 | if(xs->Gamepad.sThumbRX > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE || xs->Gamepad.sThumbRX < -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) 264 | DAXIS(ds, axisIds[2]) = xs->Gamepad.sThumbRX + 32768; 265 | else 266 | DAXIS(ds, axisIds[2]) = 32768; 267 | if(xs->Gamepad.sThumbRY > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE || xs->Gamepad.sThumbRY < -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) 268 | DAXIS(ds, axisIds[3]) = 32768 - xs->Gamepad.sThumbRY; 269 | else 270 | DAXIS(ds, axisIds[3]) = 32768; 271 | 272 | #define XINPUT_GAMEPAD_DPAD (XINPUT_GAMEPAD_DPAD_UP|XINPUT_GAMEPAD_DPAD_RIGHT|XINPUT_GAMEPAD_DPAD_DOWN|XINPUT_GAMEPAD_DPAD_LEFT) 273 | int pov = -1; 274 | if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == XINPUT_GAMEPAD_DPAD_UP) 275 | pov = 0; 276 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == (XINPUT_GAMEPAD_DPAD_UP|XINPUT_GAMEPAD_DPAD_RIGHT)) 277 | pov = (1*45)*100; 278 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == XINPUT_GAMEPAD_DPAD_RIGHT) 279 | pov = (2*45)*100; 280 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == (XINPUT_GAMEPAD_DPAD_RIGHT|XINPUT_GAMEPAD_DPAD_DOWN)) 281 | pov = (3*45)*100; 282 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == XINPUT_GAMEPAD_DPAD_DOWN) 283 | pov = (4*45)*100; 284 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == (XINPUT_GAMEPAD_DPAD_DOWN|XINPUT_GAMEPAD_DPAD_LEFT)) 285 | pov = (5*45)*100; 286 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == XINPUT_GAMEPAD_DPAD_LEFT) 287 | pov = (6*45)*100; 288 | else if((xs->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD) == (XINPUT_GAMEPAD_DPAD_LEFT|XINPUT_GAMEPAD_DPAD_UP)) 289 | pov = (7*45)*100; 290 | else 291 | pov = -1; 292 | DPOV(ds, povId) = pov; 293 | } 294 | 295 | void HookedPad::ClearState(void *state) 296 | { 297 | int i; 298 | for(i = 0; i < (int)format.dwNumObjs; i++){ 299 | if(format.rgodf[i].dwType & DIDFT_BUTTON) 300 | DBTN(state, i) = 0; 301 | else if(format.rgodf[i].dwType & DIDFT_AXIS) 302 | DAXIS(state, i) = 32768; 303 | else if(format.rgodf[i].dwType & DIDFT_POV) 304 | DPOV(state, i) = -1; 305 | } 306 | } 307 | 308 | void 309 | HookedPad::QueueData(void) 310 | { 311 | int i; 312 | for(i = 0; i < (int)format.dwNumObjs; i++){ 313 | if(numQueue >= 32) 314 | return; 315 | if(format.rgodf[i].dwType & DIDFT_BUTTON){ 316 | if(DBTN(OldState, i) != DBTN(NewState, i)){ 317 | queueData[numQueue].dwData = DBTN(NewState, i); 318 | queueData[numQueue].dwOfs = format.rgodf[i].dwOfs; 319 | // TODO 320 | queueData[numQueue].dwSequence = 0; 321 | queueData[numQueue].dwTimeStamp = 0; 322 | queueData[numQueue].uAppData = 0; 323 | DBTN(OldState, i) = DBTN(NewState, i); 324 | numQueue++; 325 | } 326 | }else if(format.rgodf[i].dwType & DIDFT_AXIS){ 327 | if(DAXIS(OldState, i) != DAXIS(NewState, i)){ 328 | queueData[numQueue].dwData = DAXIS(NewState, i); 329 | queueData[numQueue].dwOfs = format.rgodf[i].dwOfs; 330 | // TODO 331 | queueData[numQueue].dwSequence = 0; 332 | queueData[numQueue].dwTimeStamp = 0; 333 | queueData[numQueue].uAppData = 0; 334 | DAXIS(OldState, i) = DAXIS(NewState, i); 335 | numQueue++; 336 | } 337 | }else if(format.rgodf[i].dwType & DIDFT_POV){ 338 | if(DPOV(OldState, i) != DPOV(NewState, i)){ 339 | queueData[numQueue].dwData = DPOV(NewState, i); 340 | queueData[numQueue].dwOfs = format.rgodf[i].dwOfs; 341 | // TODO 342 | queueData[numQueue].dwSequence = 0; 343 | queueData[numQueue].dwTimeStamp = 0; 344 | queueData[numQueue].uAppData = 0; 345 | DPOV(OldState, i) = DPOV(NewState, i); 346 | numQueue++; 347 | } 348 | } 349 | } 350 | } 351 | 352 | int 353 | HookedPad::ReadData(DIDEVICEOBJECTDATA *data, bool peek) 354 | { 355 | if(numQueue == 0) 356 | return 0; 357 | 358 | memcpy(data, queueData, sizeof(DIDEVICEOBJECTDATA)); 359 | if(!peek){ 360 | numQueue--; 361 | memmove(queueData, &queueData[1], numQueue*sizeof(DIDEVICEOBJECTDATA)); 362 | } 363 | return 1; 364 | } 365 | 366 | HRESULT HookedPad::EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID pvRef, DWORD dwFlags) 367 | { 368 | DIDEVICEOBJECTINSTANCEA *inst; 369 | for(inst = xinputObjects; inst->dwSize != 0; inst++){ 370 | if(dwFlags == DIDFT_ALL || 371 | (inst->dwFlags & dwFlags) != 0) 372 | lpCallback(inst, pvRef); 373 | } 374 | return DI_OK; 375 | } 376 | 377 | 378 | char *gettypestr(DWORD type) 379 | { 380 | static char buf[1000]; 381 | char *p = buf; 382 | 383 | p[0] = '\0'; 384 | if(type & DIDFT_RELAXIS) p += sprintf(p, " DIDFT_RELAXIS"); 385 | if(type & DIDFT_ABSAXIS) p += sprintf(p, " DIDFT_ABSAXIS"); 386 | if(type & DIDFT_PSHBUTTON) p += sprintf(p, " DIDFT_PSHBUTTON"); 387 | if(type & DIDFT_TGLBUTTON) p += sprintf(p, " DIDFT_TGLBUTTON"); 388 | if(type & DIDFT_POV) p += sprintf(p, " DIDFT_POV"); 389 | if(type & DIDFT_COLLECTION) p += sprintf(p, " DIDFT_COLLECTION"); 390 | if(type & DIDFT_NODATA) p += sprintf(p, " DIDFT_NODATA"); 391 | if(type & DIDFT_FFACTUATOR) p += sprintf(p, " DIDFT_FFACTUATOR"); 392 | if(type & DIDFT_FFEFFECTTRIGGER) p += sprintf(p, " DIDFT_FFEFFECTTRIGGER"); 393 | if(type & DIDFT_VENDORDEFINED) p += sprintf(p, " DIDFT_VENDORDEFINED"); 394 | if(type & DIDFT_ALIAS) p += sprintf(p, " DIDFT_ALIAS"); 395 | if(type & DIDFT_OUTPUT) p += sprintf(p, " DIDFT_OUTPUT"); 396 | p += sprintf(p, " %d", DIDFT_GETINSTANCE(type)); 397 | return buf; 398 | } 399 | 400 | HRESULT HookedPad::SetDataFormat(LPCDIDATAFORMAT lpdf) 401 | { 402 | int i; 403 | 404 | format = *lpdf; 405 | format.rgodf = (DIOBJECTDATAFORMAT*)malloc(sizeof(DIOBJECTDATAFORMAT)*lpdf->dwNumObjs); 406 | memcpy(format.rgodf, lpdf->rgodf, sizeof(DIOBJECTDATAFORMAT)*lpdf->dwNumObjs); 407 | for(i = 0; i < (int)lpdf->dwNumObjs; i++){ 408 | if(lpdf->rgodf[i].dwType & DIDFT_BUTTON) 409 | buttonIds[DIDFT_GETINSTANCE(lpdf->rgodf[i].dwType)] = i; 410 | else if(lpdf->rgodf[i].dwType & DIDFT_AXIS) 411 | axisIds[DIDFT_GETINSTANCE(lpdf->rgodf[i].dwType)] = i; 412 | else if(lpdf->rgodf[i].dwType & DIDFT_POV) 413 | povId = i; 414 | } 415 | 416 | for(i = 0; i < 12; i++) 417 | assert(buttonIds[i] != -1); 418 | for(i = 0; i < 4; i++) 419 | assert(axisIds[i] != -1); 420 | assert(povId != -1); 421 | 422 | OldState = malloc(lpdf->dwDataSize); 423 | NewState = malloc(lpdf->dwDataSize); 424 | memset(OldState, 0, lpdf->dwDataSize); 425 | memset(NewState, 0, lpdf->dwDataSize); 426 | 427 | #ifdef VERBOSE 428 | printf("SetDataFormat %p\n", this); 429 | // printf("%x %X %d %d %d\n", caps.dwFlags, caps.dwDevType, caps.dwAxes, caps.dwButtons, caps.dwPOVs); 430 | printf("%u %u %u %u %u\n", lpdf->dwSize, lpdf->dwObjSize, lpdf->dwFlags, lpdf->dwDataSize, lpdf->dwNumObjs); 431 | for(i = 0; i < (int)lpdf->dwNumObjs; i++){ 432 | printf(" %p %d %X(%s) %d\n", 433 | lpdf->rgodf[i].pguid, 434 | lpdf->rgodf[i].dwOfs, 435 | lpdf->rgodf[i].dwType, gettypestr(lpdf->rgodf[i].dwType), 436 | lpdf->rgodf[i].dwFlags); 437 | } 438 | #endif 439 | 440 | 441 | return pad->ProxyInterface->SetDataFormat(&c_dfDIJoystick); 442 | } 443 | 444 | HRESULT HookedPad::GetDeviceState(DWORD cbData, LPVOID lpvData) 445 | { 446 | XINPUT_STATE xstate; 447 | // printf("Get State\n"); 448 | memset(lpvData, 0, cbData); 449 | ClearState(lpvData); 450 | if(NewState){ 451 | XInputGetState(xpadId, &xstate); 452 | hookedPad.X2D(NewState, &xstate); 453 | memcpy(OldState, NewState, format.dwDataSize); 454 | } 455 | return DI_OK; 456 | } 457 | 458 | HRESULT HookedPad::GetDeviceData(DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags) 459 | { 460 | XINPUT_STATE xstate; 461 | int n, i; 462 | 463 | // get more data 464 | if(memcmp(OldState, NewState, format.dwDataSize) == 0){ 465 | // printf("getting data\n"); 466 | XInputGetState(xpadId, &xstate); 467 | X2D(NewState, &xstate); 468 | } 469 | QueueData(); 470 | 471 | n = *pdwInOut; 472 | *pdwInOut = 0; 473 | for(i = 0; i < n; i++) 474 | if(ReadData(&rgdod[i], dwFlags == DIGDD_PEEK)) 475 | (*pdwInOut)++; 476 | else 477 | break; 478 | // n = *pdwInOut; 479 | // for(i = 0; i < n; i++){ 480 | // printf("getting data %d %X: %X %X\n", n, dwFlags, rgdod[i].dwOfs, rgdod[i].dwData); 481 | // } 482 | return DI_OK; 483 | } 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | HRESULT m_IDirectInputDevice8A::QueryInterface(REFIID riid, LPVOID * ppvObj) 494 | { 495 | if ((riid == IID_IDirectInputDevice8A || riid == IID_IUnknown) && ppvObj) 496 | { 497 | AddRef(); 498 | 499 | *ppvObj = this; 500 | 501 | return S_OK; 502 | } 503 | 504 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 505 | 506 | if (SUCCEEDED(hr)) 507 | { 508 | genericQueryInterface(riid, ppvObj); 509 | } 510 | 511 | return hr; 512 | } 513 | 514 | ULONG m_IDirectInputDevice8A::AddRef() 515 | { 516 | return ProxyInterface->AddRef(); 517 | } 518 | 519 | ULONG m_IDirectInputDevice8A::Release() 520 | { 521 | ULONG ref = ProxyInterface->Release(); 522 | 523 | if (ref == 0) 524 | { 525 | if(hookedPad.pad == this) 526 | hookedPad.pad = NULL; 527 | delete this; 528 | } 529 | 530 | return ref; 531 | } 532 | 533 | HRESULT m_IDirectInputDevice8A::GetCapabilities(LPDIDEVCAPS lpDIDevCaps) 534 | { 535 | HRESULT res; 536 | res = ProxyInterface->GetCapabilities(lpDIDevCaps); 537 | if(hookedPad.pad && hookedPad.pad == this){ 538 | // printf("geting caps: %x %X %d %d %d\n", 539 | // lpDIDevCaps->dwFlags, lpDIDevCaps->dwDevType, 540 | // lpDIDevCaps->dwAxes, lpDIDevCaps->dwButtons, lpDIDevCaps->dwPOVs); 541 | lpDIDevCaps->dwAxes = 4; 542 | lpDIDevCaps->dwButtons = 12; 543 | lpDIDevCaps->dwPOVs = 1; 544 | } 545 | return res; 546 | } 547 | 548 | HRESULT m_IDirectInputDevice8A::EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID pvRef, DWORD dwFlags) 549 | { 550 | if(this == hookedPad.pad){ 551 | return hookedPad.EnumObjects(lpCallback, pvRef, dwFlags); 552 | }else 553 | return ProxyInterface->EnumObjects(lpCallback, pvRef, dwFlags); 554 | } 555 | 556 | HRESULT m_IDirectInputDevice8A::GetProperty(REFGUID rguidProp, LPDIPROPHEADER pdiph) 557 | { 558 | return ProxyInterface->GetProperty(rguidProp, pdiph); 559 | } 560 | 561 | HRESULT m_IDirectInputDevice8A::SetProperty(REFGUID rguidProp, LPCDIPROPHEADER pdiph) 562 | { 563 | return ProxyInterface->SetProperty(rguidProp, pdiph); 564 | } 565 | 566 | HRESULT m_IDirectInputDevice8A::Acquire() 567 | { 568 | return ProxyInterface->Acquire(); 569 | } 570 | 571 | HRESULT m_IDirectInputDevice8A::Unacquire() 572 | { 573 | return ProxyInterface->Unacquire(); 574 | } 575 | 576 | HRESULT m_IDirectInputDevice8A::GetDeviceState(DWORD cbData, LPVOID lpvData) 577 | { 578 | if(this == hookedPad.pad) 579 | return hookedPad.GetDeviceState(cbData, lpvData); 580 | else 581 | return ProxyInterface->GetDeviceState(cbData, lpvData); 582 | } 583 | 584 | HRESULT m_IDirectInputDevice8A::GetDeviceData(DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags) 585 | { 586 | if(this == hookedPad.pad) 587 | return hookedPad.GetDeviceData(cbObjectData, rgdod, pdwInOut, dwFlags); 588 | else 589 | return ProxyInterface->GetDeviceData(cbObjectData, rgdod, pdwInOut, dwFlags); 590 | } 591 | 592 | HRESULT m_IDirectInputDevice8A::SetDataFormat(LPCDIDATAFORMAT lpdf) 593 | { 594 | if(this == hookedPad.pad){ 595 | return hookedPad.SetDataFormat(lpdf); 596 | }else 597 | return ProxyInterface->SetDataFormat(lpdf); 598 | } 599 | 600 | HRESULT m_IDirectInputDevice8A::SetEventNotification(HANDLE hEvent) 601 | { 602 | return ProxyInterface->SetEventNotification(hEvent); 603 | } 604 | 605 | HRESULT m_IDirectInputDevice8A::SetCooperativeLevel(HWND hwnd, DWORD dwFlags) 606 | { 607 | return ProxyInterface->SetCooperativeLevel(hwnd, dwFlags); 608 | } 609 | 610 | HRESULT m_IDirectInputDevice8A::GetObjectInfo(LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow) 611 | { 612 | return ProxyInterface->GetObjectInfo(pdidoi, dwObj, dwHow); 613 | } 614 | 615 | HRESULT m_IDirectInputDevice8A::GetDeviceInfo(LPDIDEVICEINSTANCEA pdidi) 616 | { 617 | return ProxyInterface->GetDeviceInfo(pdidi); 618 | } 619 | 620 | HRESULT m_IDirectInputDevice8A::RunControlPanel(HWND hwndOwner, DWORD dwFlags) 621 | { 622 | return ProxyInterface->RunControlPanel(hwndOwner, dwFlags); 623 | } 624 | 625 | HRESULT m_IDirectInputDevice8A::Initialize(HINSTANCE hinst, DWORD dwVersion, REFGUID rguid) 626 | { 627 | return ProxyInterface->Initialize(hinst, dwVersion, rguid); 628 | } 629 | 630 | HRESULT m_IDirectInputDevice8A::CreateEffect(REFGUID rguid, LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT * ppdeff, LPUNKNOWN punkOuter) 631 | { 632 | HRESULT hr = ProxyInterface->CreateEffect(rguid, lpeff, ppdeff, punkOuter); 633 | 634 | if (SUCCEEDED(hr) && ppdeff) 635 | { 636 | *ppdeff = ProxyAddressLookupTable.FindAddress(*ppdeff); 637 | } 638 | 639 | return hr; 640 | } 641 | 642 | HRESULT m_IDirectInputDevice8A::EnumEffects(LPDIENUMEFFECTSCALLBACKA lpCallback, LPVOID pvRef, DWORD dwEffType) 643 | { 644 | return ProxyInterface->EnumEffects(lpCallback, pvRef, dwEffType); 645 | } 646 | 647 | HRESULT m_IDirectInputDevice8A::GetEffectInfo(LPDIEFFECTINFOA pdei, REFGUID rguid) 648 | { 649 | return ProxyInterface->GetEffectInfo(pdei, rguid); 650 | } 651 | 652 | HRESULT m_IDirectInputDevice8A::GetForceFeedbackState(LPDWORD pdwOut) 653 | { 654 | return ProxyInterface->GetForceFeedbackState(pdwOut); 655 | } 656 | 657 | HRESULT m_IDirectInputDevice8A::SendForceFeedbackCommand(DWORD dwFlags) 658 | { 659 | return ProxyInterface->SendForceFeedbackCommand(dwFlags); 660 | } 661 | 662 | HRESULT m_IDirectInputDevice8A::EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID pvRef, DWORD fl) 663 | { 664 | if (!lpCallback) 665 | { 666 | return E_INVALIDARG; 667 | } 668 | 669 | ENUMEFFECT CallbackContext; 670 | CallbackContext.pvRef = pvRef; 671 | CallbackContext.lpCallback = lpCallback; 672 | 673 | return ProxyInterface->EnumCreatedEffectObjects(m_IDirectInputEnumEffect::EnumEffectCallback, &CallbackContext, fl); 674 | } 675 | 676 | HRESULT m_IDirectInputDevice8A::Escape(LPDIEFFESCAPE pesc) 677 | { 678 | return ProxyInterface->Escape(pesc); 679 | } 680 | 681 | HRESULT m_IDirectInputDevice8A::Poll() 682 | { 683 | return ProxyInterface->Poll(); 684 | } 685 | 686 | HRESULT m_IDirectInputDevice8A::SendDeviceData(DWORD cbObjectData, LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD fl) 687 | { 688 | return ProxyInterface->SendDeviceData(cbObjectData, rgdod, pdwInOut, fl); 689 | } 690 | 691 | HRESULT m_IDirectInputDevice8A::EnumEffectsInFile(LPCSTR lpszFileName, LPDIENUMEFFECTSINFILECALLBACK pec, LPVOID pvRef, DWORD dwFlags) 692 | { 693 | return ProxyInterface->EnumEffectsInFile(lpszFileName, pec, pvRef, dwFlags); 694 | } 695 | 696 | HRESULT m_IDirectInputDevice8A::WriteEffectToFile(LPCSTR lpszFileName, DWORD dwEntries, LPDIFILEEFFECT rgDiFileEft, DWORD dwFlags) 697 | { 698 | return ProxyInterface->WriteEffectToFile(lpszFileName, dwEntries, rgDiFileEft, dwFlags); 699 | } 700 | 701 | HRESULT m_IDirectInputDevice8A::BuildActionMap(LPDIACTIONFORMATA lpdiaf, LPCSTR lpszUserName, DWORD dwFlags) 702 | { 703 | return ProxyInterface->BuildActionMap(lpdiaf, lpszUserName, dwFlags); 704 | } 705 | 706 | HRESULT m_IDirectInputDevice8A::SetActionMap(LPDIACTIONFORMATA lpdiActionFormat, LPCSTR lptszUserName, DWORD dwFlags) 707 | { 708 | return ProxyInterface->SetActionMap(lpdiActionFormat, lptszUserName, dwFlags); 709 | } 710 | 711 | HRESULT m_IDirectInputDevice8A::GetImageInfo(LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader) 712 | { 713 | return ProxyInterface->GetImageInfo(lpdiDevImageInfoHeader); 714 | } 715 | -------------------------------------------------------------------------------- /dinput8/IDirectInputDevice8A.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInputDevice8A : public IDirectInputDevice8A, public AddressLookupTableObject 4 | { 5 | private: 6 | public: 7 | IDirectInputDevice8A *ProxyInterface; 8 | 9 | m_IDirectInputDevice8A(IDirectInputDevice8A *aOriginal) : ProxyInterface(aOriginal) 10 | { 11 | ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); 12 | } 13 | ~m_IDirectInputDevice8A() 14 | { 15 | ProxyAddressLookupTable.DeleteAddress(this); 16 | } 17 | 18 | IDirectInputDevice8A *GetProxyInterface() { return ProxyInterface; } 19 | 20 | /*** IUnknown methods ***/ 21 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 22 | STDMETHOD_(ULONG, AddRef)(THIS); 23 | STDMETHOD_(ULONG, Release)(THIS); 24 | 25 | /*** IDirectInputDevice8A methods ***/ 26 | STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS); 27 | // 0x10 28 | STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA, LPVOID, DWORD); 29 | STDMETHOD(GetProperty)(THIS_ REFGUID, LPDIPROPHEADER); 30 | STDMETHOD(SetProperty)(THIS_ REFGUID, LPCDIPROPHEADER); 31 | STDMETHOD(Acquire)(THIS); 32 | // 0x20 33 | STDMETHOD(Unacquire)(THIS); 34 | STDMETHOD(GetDeviceState)(THIS_ DWORD, LPVOID); 35 | STDMETHOD(GetDeviceData)(THIS_ DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD); 36 | STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT); 37 | // 0x30 38 | STDMETHOD(SetEventNotification)(THIS_ HANDLE); 39 | STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD); 40 | STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA, DWORD, DWORD); 41 | STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA); 42 | // 0x40 43 | STDMETHOD(RunControlPanel)(THIS_ HWND, DWORD); 44 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD, REFGUID); 45 | STDMETHOD(CreateEffect)(THIS_ REFGUID, LPCDIEFFECT, LPDIRECTINPUTEFFECT *, LPUNKNOWN); 46 | STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKA, LPVOID, DWORD); 47 | STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOA, REFGUID); 48 | STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD); 49 | STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD); 50 | STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, LPVOID, DWORD); 51 | STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE); 52 | STDMETHOD(Poll)(THIS); 53 | STDMETHOD(SendDeviceData)(THIS_ DWORD, LPCDIDEVICEOBJECTDATA, LPDWORD, DWORD); 54 | STDMETHOD(EnumEffectsInFile)(THIS_ LPCSTR, LPDIENUMEFFECTSINFILECALLBACK, LPVOID, DWORD); 55 | STDMETHOD(WriteEffectToFile)(THIS_ LPCSTR, DWORD, LPDIFILEEFFECT, DWORD); 56 | STDMETHOD(BuildActionMap)(THIS_ LPDIACTIONFORMATA, LPCSTR, DWORD); 57 | STDMETHOD(SetActionMap)(THIS_ LPDIACTIONFORMATA, LPCSTR, DWORD); 58 | STDMETHOD(GetImageInfo)(THIS_ LPDIDEVICEIMAGEINFOHEADERA); 59 | }; 60 | -------------------------------------------------------------------------------- /dinput8/IDirectInputDevice8W.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | HRESULT m_IDirectInputDevice8W::QueryInterface(REFIID riid, LPVOID* ppvObj) 20 | { 21 | if ((riid == IID_IDirectInputDevice8W || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirectInputDevice8W::AddRef() 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirectInputDevice8W::Release() 46 | { 47 | ULONG ref = ProxyInterface->Release(); 48 | 49 | if (ref == 0) 50 | { 51 | delete this; 52 | } 53 | 54 | return ref; 55 | } 56 | 57 | HRESULT m_IDirectInputDevice8W::GetCapabilities(LPDIDEVCAPS lpDIDevCaps) 58 | { 59 | return ProxyInterface->GetCapabilities(lpDIDevCaps); 60 | } 61 | 62 | HRESULT m_IDirectInputDevice8W::EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID pvRef, DWORD dwFlags) 63 | { 64 | return ProxyInterface->EnumObjects(lpCallback, pvRef, dwFlags); 65 | } 66 | 67 | HRESULT m_IDirectInputDevice8W::GetProperty(REFGUID rguidProp, LPDIPROPHEADER pdiph) 68 | { 69 | return ProxyInterface->GetProperty(rguidProp, pdiph); 70 | } 71 | 72 | HRESULT m_IDirectInputDevice8W::SetProperty(REFGUID rguidProp, LPCDIPROPHEADER pdiph) 73 | { 74 | return ProxyInterface->SetProperty(rguidProp, pdiph); 75 | } 76 | 77 | HRESULT m_IDirectInputDevice8W::Acquire() 78 | { 79 | return ProxyInterface->Acquire(); 80 | } 81 | 82 | HRESULT m_IDirectInputDevice8W::Unacquire() 83 | { 84 | return ProxyInterface->Unacquire(); 85 | } 86 | 87 | HRESULT m_IDirectInputDevice8W::GetDeviceState(DWORD cbData, LPVOID lpvData) 88 | { 89 | return ProxyInterface->GetDeviceState(cbData, lpvData); 90 | } 91 | 92 | HRESULT m_IDirectInputDevice8W::GetDeviceData(DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags) 93 | { 94 | return ProxyInterface->GetDeviceData(cbObjectData, rgdod, pdwInOut, dwFlags); 95 | } 96 | 97 | HRESULT m_IDirectInputDevice8W::SetDataFormat(LPCDIDATAFORMAT lpdf) 98 | { 99 | return ProxyInterface->SetDataFormat(lpdf); 100 | } 101 | 102 | HRESULT m_IDirectInputDevice8W::SetEventNotification(HANDLE hEvent) 103 | { 104 | return ProxyInterface->SetEventNotification(hEvent); 105 | } 106 | 107 | HRESULT m_IDirectInputDevice8W::SetCooperativeLevel(HWND hwnd, DWORD dwFlags) 108 | { 109 | return ProxyInterface->SetCooperativeLevel(hwnd, dwFlags); 110 | } 111 | 112 | HRESULT m_IDirectInputDevice8W::GetObjectInfo(LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow) 113 | { 114 | return ProxyInterface->GetObjectInfo(pdidoi, dwObj, dwHow); 115 | } 116 | 117 | HRESULT m_IDirectInputDevice8W::GetDeviceInfo(LPDIDEVICEINSTANCEW pdidi) 118 | { 119 | return ProxyInterface->GetDeviceInfo(pdidi); 120 | } 121 | 122 | HRESULT m_IDirectInputDevice8W::RunControlPanel(HWND hwndOwner, DWORD dwFlags) 123 | { 124 | return ProxyInterface->RunControlPanel(hwndOwner, dwFlags); 125 | } 126 | 127 | HRESULT m_IDirectInputDevice8W::Initialize(HINSTANCE hinst, DWORD dwVersion, REFGUID rguid) 128 | { 129 | return ProxyInterface->Initialize(hinst, dwVersion, rguid); 130 | } 131 | 132 | HRESULT m_IDirectInputDevice8W::CreateEffect(REFGUID rguid, LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT * ppdeff, LPUNKNOWN punkOuter) 133 | { 134 | HRESULT hr = ProxyInterface->CreateEffect(rguid, lpeff, ppdeff, punkOuter); 135 | 136 | if (SUCCEEDED(hr) && ppdeff) 137 | { 138 | *ppdeff = ProxyAddressLookupTable.FindAddress(*ppdeff); 139 | } 140 | 141 | return hr; 142 | } 143 | 144 | HRESULT m_IDirectInputDevice8W::EnumEffects(LPDIENUMEFFECTSCALLBACKW lpCallback, LPVOID pvRef, DWORD dwEffType) 145 | { 146 | return ProxyInterface->EnumEffects(lpCallback, pvRef, dwEffType); 147 | } 148 | 149 | HRESULT m_IDirectInputDevice8W::GetEffectInfo(LPDIEFFECTINFOW pdei, REFGUID rguid) 150 | { 151 | return ProxyInterface->GetEffectInfo(pdei, rguid); 152 | } 153 | 154 | HRESULT m_IDirectInputDevice8W::GetForceFeedbackState(LPDWORD pdwOut) 155 | { 156 | return ProxyInterface->GetForceFeedbackState(pdwOut); 157 | } 158 | 159 | HRESULT m_IDirectInputDevice8W::SendForceFeedbackCommand(DWORD dwFlags) 160 | { 161 | return ProxyInterface->SendForceFeedbackCommand(dwFlags); 162 | } 163 | 164 | HRESULT m_IDirectInputDevice8W::EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback, LPVOID pvRef, DWORD fl) 165 | { 166 | if (!lpCallback) 167 | { 168 | return E_INVALIDARG; 169 | } 170 | 171 | ENUMEFFECT CallbackContext; 172 | CallbackContext.pvRef = pvRef; 173 | CallbackContext.lpCallback = lpCallback; 174 | 175 | return ProxyInterface->EnumCreatedEffectObjects(m_IDirectInputEnumEffect::EnumEffectCallback, &CallbackContext, fl); 176 | } 177 | 178 | HRESULT m_IDirectInputDevice8W::Escape(LPDIEFFESCAPE pesc) 179 | { 180 | return ProxyInterface->Escape(pesc); 181 | } 182 | 183 | HRESULT m_IDirectInputDevice8W::Poll() 184 | { 185 | return ProxyInterface->Poll(); 186 | } 187 | 188 | HRESULT m_IDirectInputDevice8W::SendDeviceData(DWORD cbObjectData, LPCDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD fl) 189 | { 190 | return ProxyInterface->SendDeviceData(cbObjectData, rgdod, pdwInOut, fl); 191 | } 192 | 193 | HRESULT m_IDirectInputDevice8W::EnumEffectsInFile(LPCWSTR lpszFileName, LPDIENUMEFFECTSINFILECALLBACK pec, LPVOID pvRef, DWORD dwFlags) 194 | { 195 | return ProxyInterface->EnumEffectsInFile(lpszFileName, pec, pvRef, dwFlags); 196 | } 197 | 198 | HRESULT m_IDirectInputDevice8W::WriteEffectToFile(LPCWSTR lpszFileName, DWORD dwEntries, LPDIFILEEFFECT rgDiFileEft, DWORD dwFlags) 199 | { 200 | return ProxyInterface->WriteEffectToFile(lpszFileName, dwEntries, rgDiFileEft, dwFlags); 201 | } 202 | 203 | HRESULT m_IDirectInputDevice8W::BuildActionMap(LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags) 204 | { 205 | return ProxyInterface->BuildActionMap(lpdiaf, lpszUserName, dwFlags); 206 | } 207 | 208 | HRESULT m_IDirectInputDevice8W::SetActionMap(LPDIACTIONFORMATW lpdiActionFormat, LPCWSTR lptszUserName, DWORD dwFlags) 209 | { 210 | return ProxyInterface->SetActionMap(lpdiActionFormat, lptszUserName, dwFlags); 211 | } 212 | 213 | HRESULT m_IDirectInputDevice8W::GetImageInfo(LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) 214 | { 215 | return ProxyInterface->GetImageInfo(lpdiDevImageInfoHeader); 216 | } 217 | -------------------------------------------------------------------------------- /dinput8/IDirectInputDevice8W.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInputDevice8W : public IDirectInputDevice8W, public AddressLookupTableObject 4 | { 5 | private: 6 | IDirectInputDevice8W *ProxyInterface; 7 | 8 | public: 9 | m_IDirectInputDevice8W(IDirectInputDevice8W *aOriginal) : ProxyInterface(aOriginal) 10 | { 11 | ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); 12 | } 13 | ~m_IDirectInputDevice8W() 14 | { 15 | ProxyAddressLookupTable.DeleteAddress(this); 16 | } 17 | 18 | IDirectInputDevice8W *GetProxyInterface() { return ProxyInterface; } 19 | 20 | /*** IUnknown methods ***/ 21 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 22 | STDMETHOD_(ULONG, AddRef)(THIS); 23 | STDMETHOD_(ULONG, Release)(THIS); 24 | 25 | /*** IDirectInputDevice8W methods ***/ 26 | STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS); 27 | STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKW, LPVOID, DWORD); 28 | STDMETHOD(GetProperty)(THIS_ REFGUID, LPDIPROPHEADER); 29 | STDMETHOD(SetProperty)(THIS_ REFGUID, LPCDIPROPHEADER); 30 | STDMETHOD(Acquire)(THIS); 31 | STDMETHOD(Unacquire)(THIS); 32 | STDMETHOD(GetDeviceState)(THIS_ DWORD, LPVOID); 33 | STDMETHOD(GetDeviceData)(THIS_ DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD); 34 | STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT); 35 | STDMETHOD(SetEventNotification)(THIS_ HANDLE); 36 | STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD); 37 | STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEW, DWORD, DWORD); 38 | STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEW); 39 | STDMETHOD(RunControlPanel)(THIS_ HWND, DWORD); 40 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD, REFGUID); 41 | STDMETHOD(CreateEffect)(THIS_ REFGUID, LPCDIEFFECT, LPDIRECTINPUTEFFECT *, LPUNKNOWN); 42 | STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKW, LPVOID, DWORD); 43 | STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOW, REFGUID); 44 | STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD); 45 | STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD); 46 | STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, LPVOID, DWORD); 47 | STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE); 48 | STDMETHOD(Poll)(THIS); 49 | STDMETHOD(SendDeviceData)(THIS_ DWORD, LPCDIDEVICEOBJECTDATA, LPDWORD, DWORD); 50 | STDMETHOD(EnumEffectsInFile)(THIS_ LPCWSTR, LPDIENUMEFFECTSINFILECALLBACK, LPVOID, DWORD); 51 | STDMETHOD(WriteEffectToFile)(THIS_ LPCWSTR, DWORD, LPDIFILEEFFECT, DWORD); 52 | STDMETHOD(BuildActionMap)(THIS_ LPDIACTIONFORMATW, LPCWSTR, DWORD); 53 | STDMETHOD(SetActionMap)(THIS_ LPDIACTIONFORMATW, LPCWSTR, DWORD); 54 | STDMETHOD(GetImageInfo)(THIS_ LPDIDEVICEIMAGEINFOHEADERW); 55 | }; 56 | -------------------------------------------------------------------------------- /dinput8/IDirectInputEffect.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | HRESULT m_IDirectInputEffect::QueryInterface(REFIID riid, LPVOID * ppvObj) 20 | { 21 | if ((riid == IID_IDirectInputEffect || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirectInputEffect::AddRef() 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirectInputEffect::Release() 46 | { 47 | ULONG ref = ProxyInterface->Release(); 48 | 49 | if (ref == 0) 50 | { 51 | delete this; 52 | } 53 | 54 | return ref; 55 | } 56 | 57 | HRESULT m_IDirectInputEffect::Initialize(HINSTANCE hinst, DWORD dwVersion, REFGUID rguid) 58 | { 59 | return ProxyInterface->Initialize(hinst, dwVersion, rguid); 60 | } 61 | 62 | HRESULT m_IDirectInputEffect::GetEffectGuid(LPGUID pguid) 63 | { 64 | return ProxyInterface->GetEffectGuid(pguid); 65 | } 66 | 67 | HRESULT m_IDirectInputEffect::GetParameters(LPDIEFFECT peff, DWORD dwFlags) 68 | { 69 | return ProxyInterface->GetParameters(peff, dwFlags); 70 | } 71 | 72 | HRESULT m_IDirectInputEffect::SetParameters(LPCDIEFFECT peff, DWORD dwFlags) 73 | { 74 | return ProxyInterface->SetParameters(peff, dwFlags); 75 | } 76 | 77 | HRESULT m_IDirectInputEffect::Start(DWORD dwIterations, DWORD dwFlags) 78 | { 79 | return ProxyInterface->Start(dwIterations, dwFlags); 80 | } 81 | 82 | HRESULT m_IDirectInputEffect::Stop() 83 | { 84 | return ProxyInterface->Stop(); 85 | } 86 | 87 | HRESULT m_IDirectInputEffect::GetEffectStatus(LPDWORD pdwFlags) 88 | { 89 | return ProxyInterface->GetEffectStatus(pdwFlags); 90 | } 91 | 92 | HRESULT m_IDirectInputEffect::Download() 93 | { 94 | return ProxyInterface->Download(); 95 | } 96 | 97 | HRESULT m_IDirectInputEffect::Unload() 98 | { 99 | return ProxyInterface->Unload(); 100 | } 101 | 102 | HRESULT m_IDirectInputEffect::Escape(LPDIEFFESCAPE pesc) 103 | { 104 | return ProxyInterface->Escape(pesc); 105 | } 106 | -------------------------------------------------------------------------------- /dinput8/IDirectInputEffect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirectInputEffect : public IDirectInputEffect, public AddressLookupTableObject 4 | { 5 | private: 6 | IDirectInputEffect *ProxyInterface; 7 | 8 | public: 9 | m_IDirectInputEffect(IDirectInputEffect *aOriginal) : ProxyInterface(aOriginal) 10 | { 11 | ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); 12 | } 13 | ~m_IDirectInputEffect() 14 | { 15 | ProxyAddressLookupTable.DeleteAddress(this); 16 | } 17 | 18 | IDirectInputEffect *GetProxyInterface() { return ProxyInterface; } 19 | 20 | /*** IUnknown methods ***/ 21 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); 22 | STDMETHOD_(ULONG, AddRef)(THIS); 23 | STDMETHOD_(ULONG, Release)(THIS); 24 | 25 | /*** IDirectInputEffect methods ***/ 26 | STDMETHOD(Initialize)(THIS_ HINSTANCE, DWORD, REFGUID); 27 | STDMETHOD(GetEffectGuid)(THIS_ LPGUID); 28 | STDMETHOD(GetParameters)(THIS_ LPDIEFFECT, DWORD); 29 | STDMETHOD(SetParameters)(THIS_ LPCDIEFFECT, DWORD); 30 | STDMETHOD(Start)(THIS_ DWORD, DWORD); 31 | STDMETHOD(Stop)(THIS); 32 | STDMETHOD(GetEffectStatus)(THIS_ LPDWORD); 33 | STDMETHOD(Download)(THIS); 34 | STDMETHOD(Unload)(THIS); 35 | STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE); 36 | }; 37 | -------------------------------------------------------------------------------- /dinput8/IDirectInputEnumDevice.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | BOOL CALLBACK m_IDirectInputEnumDevice::EnumDeviceCallbackA(LPCDIDEVICEINSTANCEA lpddi, LPDIRECTINPUTDEVICE8A lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef) 20 | { 21 | ENUMDEVICEA *lpCallbackContext = (ENUMDEVICEA*)pvRef; 22 | 23 | if (lpdid) 24 | { 25 | lpdid = ProxyAddressLookupTable.FindAddress(lpdid); 26 | } 27 | 28 | return lpCallbackContext->lpCallback(lpddi, lpdid, dwFlags, dwRemaining, lpCallbackContext->pvRef); 29 | } 30 | 31 | BOOL CALLBACK m_IDirectInputEnumDevice::EnumDeviceCallbackW(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDEVICE8W lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef) 32 | { 33 | ENUMDEVICEW *lpCallbackContext = (ENUMDEVICEW*)pvRef; 34 | 35 | if (lpdid) 36 | { 37 | lpdid = ProxyAddressLookupTable.FindAddress(lpdid); 38 | } 39 | 40 | return lpCallbackContext->lpCallback(lpddi, lpdid, dwFlags, dwRemaining, lpCallbackContext->pvRef); 41 | } 42 | -------------------------------------------------------------------------------- /dinput8/IDirectInputEnumDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct ENUMDEVICEA 4 | { 5 | LPVOID pvRef; 6 | LPDIENUMDEVICESBYSEMANTICSCBA lpCallback; 7 | }; 8 | 9 | struct ENUMDEVICEW 10 | { 11 | LPVOID pvRef; 12 | LPDIENUMDEVICESBYSEMANTICSCBW lpCallback; 13 | }; 14 | 15 | class m_IDirectInputEnumDevice 16 | { 17 | public: 18 | m_IDirectInputEnumDevice() {} 19 | ~m_IDirectInputEnumDevice() {} 20 | 21 | static BOOL CALLBACK EnumDeviceCallbackA(LPCDIDEVICEINSTANCEA, LPDIRECTINPUTDEVICE8A, DWORD, DWORD, LPVOID); 22 | static BOOL CALLBACK EnumDeviceCallbackW(LPCDIDEVICEINSTANCEW, LPDIRECTINPUTDEVICE8W, DWORD, DWORD, LPVOID); 23 | }; 24 | -------------------------------------------------------------------------------- /dinput8/IDirectInputEnumEffect.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | BOOL CALLBACK m_IDirectInputEnumEffect::EnumEffectCallback(LPDIRECTINPUTEFFECT pdeff, LPVOID pvRef) 20 | { 21 | ENUMEFFECT *lpCallbackContext = (ENUMEFFECT*)pvRef; 22 | 23 | if (pdeff) 24 | { 25 | pdeff = ProxyAddressLookupTable.FindAddress(pdeff); 26 | } 27 | 28 | return lpCallbackContext->lpCallback(pdeff, lpCallbackContext->pvRef); 29 | } 30 | -------------------------------------------------------------------------------- /dinput8/IDirectInputEnumEffect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct ENUMEFFECT 4 | { 5 | LPVOID pvRef; 6 | LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback; 7 | }; 8 | 9 | class m_IDirectInputEnumEffect 10 | { 11 | public: 12 | m_IDirectInputEnumEffect() {} 13 | ~m_IDirectInputEnumEffect() {} 14 | 15 | static BOOL CALLBACK EnumEffectCallback(LPDIRECTINPUTEFFECT, LPVOID); 16 | }; 17 | -------------------------------------------------------------------------------- /dinput8/InterfaceQuery.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | void genericQueryInterface(REFIID riid, LPVOID * ppvObj) 20 | { 21 | if (!ppvObj || !*ppvObj) 22 | { 23 | return; 24 | } 25 | 26 | #define QUERYINTERFACE(x) \ 27 | if (riid == IID_ ## x) \ 28 | { \ 29 | *ppvObj = ProxyAddressLookupTable.FindAddress(*ppvObj); \ 30 | } 31 | 32 | #define CREATEINTERFACE(x) \ 33 | if (riid == IID_ ## x) \ 34 | { \ 35 | *ppvObj = new m_ ## x((x*)*ppvObj); \ 36 | } 37 | 38 | QUERYINTERFACE(IDirectInput8A); 39 | QUERYINTERFACE(IDirectInput8W); 40 | QUERYINTERFACE(IDirectInputDevice8A); 41 | QUERYINTERFACE(IDirectInputDevice8W); 42 | QUERYINTERFACE(IDirectInputEffect); 43 | 44 | CREATEINTERFACE(IClassFactory); 45 | } 46 | -------------------------------------------------------------------------------- /dinput8/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger, aap 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /dinput8/dinput8.def: -------------------------------------------------------------------------------- 1 | LIBRARY dinput8 2 | EXPORTS 3 | 4 | DirectInput8Create @1 5 | DllCanUnloadNow PRIVATE 6 | DllGetClassObject PRIVATE 7 | DllRegisterServer PRIVATE 8 | DllUnregisterServer PRIVATE 9 | GetdfDIJoystick @6 10 | -------------------------------------------------------------------------------- /dinput8/dinput8.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define INITGUID 4 | #define _CRT_SECURE_NO_WARNINGS 5 | 6 | #define DIRECTINPUT_VERSION 0x0800 7 | #include 8 | 9 | class m_IDirectInput8A; 10 | class m_IDirectInput8W; 11 | class m_IDirectInputDevice8A; 12 | class m_IDirectInputDevice8W; 13 | class m_IDirectInputEffect; 14 | 15 | #include "AddressLookupTable.h" 16 | #include "..\Common\Logging.h" 17 | 18 | typedef HRESULT(WINAPI *DirectInput8CreateProc)(HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN); 19 | typedef HRESULT(WINAPI *DllCanUnloadNowProc)(); 20 | typedef HRESULT(WINAPI *DllGetClassObjectProc)(REFCLSID, REFIID, LPVOID *); 21 | typedef HRESULT(WINAPI *DllRegisterServerProc)(); 22 | typedef HRESULT(WINAPI *DllUnregisterServerProc)(); 23 | typedef LPCDIDATAFORMAT(WINAPI *GetdfDIJoystickProc)(); 24 | 25 | void genericQueryInterface(REFIID CalledID, LPVOID * ppvObj); 26 | extern AddressLookupTable ProxyAddressLookupTable; 27 | 28 | #include "IDirectInput8A.h" 29 | #include "IDirectInput8W.h" 30 | #include "IDirectInputDevice8A.h" 31 | #include "IDirectInputDevice8W.h" 32 | #include "IDirectInputEffect.h" 33 | #include "IDirectInputEnumDevice.h" 34 | #include "IDirectInputEnumEffect.h" 35 | #include "IClassFactory.h" 36 | 37 | #include 38 | 39 | #define VERBOSE 40 | 41 | struct HookedPad 42 | { 43 | GUID guid; 44 | m_IDirectInputDevice8A *pad; 45 | DIDATAFORMAT format; 46 | int buttonIds[20]; 47 | int axisIds[20]; 48 | int povId; 49 | void *OldState, *NewState; 50 | int xpadId; 51 | DIDEVICEOBJECTDATA queueData[32]; 52 | int numQueue; 53 | 54 | void Init(m_IDirectInputDevice8A *p); 55 | void X2D(void *ds, XINPUT_STATE *xs); 56 | void ClearState(void *state); 57 | void QueueData(void); 58 | int ReadData(DIDEVICEOBJECTDATA *data, bool peek); 59 | 60 | HRESULT EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID pvRef, DWORD dwFlags); 61 | HRESULT SetDataFormat(LPCDIDATAFORMAT lpdf); 62 | HRESULT GetDeviceState(DWORD cbData, LPVOID lpvData); 63 | HRESULT GetDeviceData(DWORD cbObjectData, LPDIDEVICEOBJECTDATA rgdod, LPDWORD pdwInOut, DWORD dwFlags); 64 | }; 65 | extern HookedPad hookedPad; 66 | -------------------------------------------------------------------------------- /dinput8/dinput8.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {C68F48DD-0B73-4C69-9CEB-D8F3E1369D97} 15 | Win32Proj 16 | dinput8 17 | 8.1 18 | 19 | 20 | 21 | DynamicLibrary 22 | true 23 | Unicode 24 | v140 25 | 26 | 27 | DynamicLibrary 28 | false 29 | Unicode 30 | v140 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Level3 49 | 50 | 51 | Windows 52 | dinput8.def 53 | 54 | 55 | 56 | 57 | Level3 58 | 59 | 60 | 61 | 62 | Windows 63 | dinput8.def 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /dinput8/dllmain.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "dinput8.h" 18 | 19 | std::ofstream Log::LOG("dinput8.log"); 20 | AddressLookupTable ProxyAddressLookupTable = AddressLookupTable(); 21 | 22 | DirectInput8CreateProc m_pDirectInput8Create; 23 | DllCanUnloadNowProc m_pDllCanUnloadNow; 24 | DllGetClassObjectProc m_pDllGetClassObject; 25 | DllRegisterServerProc m_pDllRegisterServer; 26 | DllUnregisterServerProc m_pDllUnregisterServer; 27 | GetdfDIJoystickProc m_pGetdfDIJoystick; 28 | 29 | bool WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) 30 | { 31 | static HMODULE dinput8dll = nullptr; 32 | 33 | switch (dwReason) 34 | { 35 | case DLL_PROCESS_ATTACH: 36 | // Load dll 37 | char path[MAX_PATH]; 38 | GetSystemDirectoryA(path, MAX_PATH); 39 | strcat_s(path, "\\dinput8.dll"); 40 | #ifdef VERBOSE 41 | Log() << "Loading " << path; 42 | #endif 43 | dinput8dll = LoadLibraryA(path); 44 | 45 | #ifdef VERBOSE 46 | AllocConsole(); 47 | freopen("CONIN$", "r", stdin); 48 | freopen("CONOUT$", "w", stdout); 49 | freopen("CONOUT$", "w", stderr); 50 | #endif 51 | 52 | // Get function addresses 53 | m_pDirectInput8Create = (DirectInput8CreateProc)GetProcAddress(dinput8dll, "DirectInput8Create"); 54 | m_pDllCanUnloadNow = (DllCanUnloadNowProc)GetProcAddress(dinput8dll, "DllCanUnloadNow"); 55 | m_pDllGetClassObject = (DllGetClassObjectProc)GetProcAddress(dinput8dll, "DllGetClassObject"); 56 | m_pDllRegisterServer = (DllRegisterServerProc)GetProcAddress(dinput8dll, "DllRegisterServer"); 57 | m_pDllUnregisterServer = (DllUnregisterServerProc)GetProcAddress(dinput8dll, "DllUnregisterServer"); 58 | m_pGetdfDIJoystick = (GetdfDIJoystickProc)GetProcAddress(dinput8dll, "GetdfDIJoystick"); 59 | break; 60 | 61 | case DLL_PROCESS_DETACH: 62 | FreeLibrary(dinput8dll); 63 | break; 64 | } 65 | 66 | return true; 67 | } 68 | 69 | HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID * ppvOut, LPUNKNOWN punkOuter) 70 | { 71 | if (!m_pDirectInput8Create) 72 | { 73 | return E_FAIL; 74 | } 75 | 76 | HRESULT hr = m_pDirectInput8Create(hinst, dwVersion, riidltf, ppvOut, punkOuter); 77 | 78 | if (SUCCEEDED(hr)) 79 | { 80 | genericQueryInterface(riidltf, ppvOut); 81 | } 82 | 83 | return hr; 84 | } 85 | 86 | HRESULT WINAPI DllCanUnloadNow() 87 | { 88 | if (!m_pDllCanUnloadNow) 89 | { 90 | return E_FAIL; 91 | } 92 | 93 | return m_pDllCanUnloadNow(); 94 | } 95 | 96 | HRESULT WINAPI DllGetClassObject(IN REFCLSID rclsid, IN REFIID riid, OUT LPVOID FAR* ppv) 97 | { 98 | if (!m_pDllGetClassObject) 99 | { 100 | return E_FAIL; 101 | } 102 | 103 | HRESULT hr = m_pDllGetClassObject(rclsid, riid, ppv); 104 | 105 | if (SUCCEEDED(hr)) 106 | { 107 | genericQueryInterface(riid, ppv); 108 | } 109 | 110 | return hr; 111 | } 112 | 113 | HRESULT WINAPI DllRegisterServer() 114 | { 115 | if (!m_pDllRegisterServer) 116 | { 117 | return E_FAIL; 118 | } 119 | 120 | return m_pDllRegisterServer(); 121 | } 122 | 123 | HRESULT WINAPI DllUnregisterServer() 124 | { 125 | if (!m_pDllUnregisterServer) 126 | { 127 | return E_FAIL; 128 | } 129 | 130 | return m_pDllUnregisterServer(); 131 | } 132 | 133 | LPCDIDATAFORMAT WINAPI GetdfDIJoystick() 134 | { 135 | if (!m_pGetdfDIJoystick) 136 | { 137 | return nullptr; 138 | } 139 | 140 | return m_pGetdfDIJoystick(); 141 | } 142 | --------------------------------------------------------------------------------