Skip to content

Commit 88457ff

Browse files
SonickidnextgenSonickidnextgen
authored andcommitted
Added code to dynamically link with vJoy; DirectInput support. Static options are available with the preprocessor.
1 parent 7751f41 commit 88457ff

File tree

12 files changed

+673
-222
lines changed

12 files changed

+673
-222
lines changed

IOSync/IOSync.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<ClCompile Include="src\devices\gamepad.cpp" />
3333
<ClCompile Include="src\devices\keyboard.cpp" />
3434
<ClCompile Include="src\devices\native\winnt\Real_XInput_Wrapper.cpp" />
35+
<ClCompile Include="src\devices\native\winnt\vJoyDriver.cpp" />
3536
<ClCompile Include="src\exceptions.cpp" />
3637
<ClCompile Include="src\iosync.cpp" />
3738
<ClCompile Include="src\main.cpp" />

IOSync/IOSync.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
<ClCompile Include="src\devices\native\winnt\Real_XInput_Wrapper.cpp">
9797
<Filter>Source Files\devices\native\winnt</Filter>
9898
</ClCompile>
99+
<ClCompile Include="src\devices\native\winnt\vJoyDriver.cpp">
100+
<Filter>Source Files\devices\native\winnt</Filter>
101+
</ClCompile>
99102
</ItemGroup>
100103
<ItemGroup>
101104
<ClInclude Include="src\networking\address.h">

IOSync/Info.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ImportGroup Label="PropertySheets" />
44
<PropertyGroup Label="UserMacros">
5-
<IOSync_Version>1.0.2</IOSync_Version>
5+
<IOSync_Version>1.0.3</IOSync_Version>
66
</PropertyGroup>
77
<PropertyGroup />
88
<ItemDefinitionGroup />

IOSync/src/devices/gamepad.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,42 +180,19 @@ namespace iosync
180180
#ifdef GAMEPAD_VJOY_ENABLED
181181
vJoy::vJoyDriver::vJoyDriverState gamepad::__winnt__vJoy__init()
182182
{
183-
// Namespace(s):
184-
using namespace vJoy;
185-
186-
vJoyInfo.state = ((vJoyEnabled() == TRUE) ? vJoyDriver::VJOY_ENABLED : vJoyDriver::VJOY_DISABLED);
187-
188-
if (vJoyInfo.state == vJoyDriver::VJOY_ENABLED)
189-
{
190-
WORD DLLVer, driverVer;
191-
192-
if (!DriverMatch(&DLLVer, &driverVer))
193-
{
194-
vJoyInfo.state = vJoyDriver::VJOY_DISABLED;
195-
}
196-
}
197-
198-
return vJoyInfo.state;
183+
// Call the main implementation. (Shared "driver" object)
184+
return vJoyInfo.init();
199185
}
200186

201187
vJoy::vJoyDriver::vJoyDriverState gamepad::__winnt__vJoy__deinit()
202188
{
203-
// Namespace(s):
204-
using namespace vJoy;
205-
206-
if (vJoyInfo.state == vJoyDriver::VJOY_ENABLED)
207-
{
208-
// Nothing so far.
209-
210-
vJoyInfo.state = vJoyDriver::VJOY_DISABLED;
211-
}
212-
213-
return vJoyInfo.state;
189+
// Call the main implementation. (Shared "driver" object)
190+
return vJoyInfo.deinit();
214191
}
215192

216193
VjdStat gamepad::__winnt__vJoy__getStatus(const gamepadID internal_identifier)
217194
{
218-
return GetVJDStatus(__winnt__vJoy__vDevice(internal_identifier));
195+
return vJoy::REAL_VJOY::GetVJDStatus(__winnt__vJoy__vDevice(internal_identifier));
219196
}
220197

221198
LONG gamepad::__winnt__vJoy__capAxis(const UINT vJoyID, const LONG value, const UINT axis, const UINT maximum_value)
@@ -359,7 +336,7 @@ namespace iosync
359336
//cout << "vState.lButtons: " << vState.lButtons << endl;
360337

361338
// Update the vJoy-device.
362-
UpdateVJD(vJoyID, &vState);
339+
vJoy::REAL_VJOY::UpdateVJD(vJoyID, &vState);
363340

364341
return;
365342
}

IOSync/src/devices/gamepad.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,11 @@
1414

1515
// Includes:
1616
#include "../platform.h"
17-
18-
// The 'GAMEPAD_VJOY_ENABLED' preprocessor-variable should
19-
// only ever be defined when 'PLATFORM_WINDOWS' is defined.
20-
// Any other behavior should be considered non-standard.
21-
#ifdef PLATFORM_WINDOWS
22-
// Disable this if needed; toggles optional vJoy support.
23-
#define GAMEPAD_VJOY_ENABLED
24-
25-
#ifdef GAMEPAD_VJOY_ENABLED
26-
#define GAMEPAD_VJOY_SAFE
27-
#endif
28-
#endif
29-
3017
#include "../names.h"
3118

3219
#include "devices.h"
3320

34-
#ifdef GAMEPAD_VJOY_ENABLED
21+
#ifdef PLATFORM_WINDOWS
3522
// vJoy functionality.
3623
#include "native/winnt/vJoyDriver.h"
3724
#endif
@@ -60,10 +47,6 @@
6047
//#pragma comment(lib, "Xinput.lib")
6148
#endif
6249

63-
#ifdef GAMEPAD_VJOY_ENABLED
64-
#pragma comment(lib, "VJOYINTERFACE")
65-
#endif
66-
6750
// Namespace(s):
6851
namespace iosync
6952
{
@@ -157,7 +140,7 @@ namespace iosync
157140
struct gamepadState
158141
{
159142
// Constant variable(s):
160-
#ifdef PLATFORM_WINDOWS
143+
#ifdef GAMEPAD_VJOY_ENABLED
161144
static const DWORD padMask = (XINPUT_GAMEPAD_DPAD_UP|XINPUT_GAMEPAD_DPAD_DOWN|XINPUT_GAMEPAD_DPAD_LEFT|XINPUT_GAMEPAD_DPAD_RIGHT);
162145
static const DWORD faceMask = (XINPUT_GAMEPAD_A|XINPUT_GAMEPAD_B|XINPUT_GAMEPAD_X|XINPUT_GAMEPAD_Y);
163146
#endif

IOSync/src/devices/native/winnt/Real_XInput_Wrapper.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
namespace REAL_XINPUT
3030
{
3131
// Typedefs:
32-
typedef decltype(&XInputEnable) _XInputEnable_t;
33-
typedef decltype(&XInputSetState) _XInputSetState_t;
34-
typedef decltype(&XInputGetState) _XInputGetState_t;
35-
typedef decltype(&XInputGetCapabilities) _XInputGetCapabilities_t;
36-
typedef decltype(&XInputGetBatteryInformation) _XInputGetBatteryInformation_t;
37-
typedef decltype(&XInputGetKeystroke) _XInputGetKeystroke_t;
38-
typedef decltype(&XInputGetAudioDeviceIds) _XInputGetAudioDeviceIds_t;
39-
typedef decltype(&XInputGetState) _XInputGetStateEx_t; // XInputGetStateEx
32+
typedef decltype(&::XInputEnable) _XInputEnable_t;
33+
typedef decltype(&::XInputSetState) _XInputSetState_t;
34+
typedef decltype(&::XInputGetState) _XInputGetState_t;
35+
typedef decltype(&::XInputGetCapabilities) _XInputGetCapabilities_t;
36+
typedef decltype(&::XInputGetBatteryInformation) _XInputGetBatteryInformation_t;
37+
typedef decltype(&::XInputGetKeystroke) _XInputGetKeystroke_t;
38+
typedef decltype(&::XInputGetAudioDeviceIds) _XInputGetAudioDeviceIds_t;
39+
typedef decltype(&::XInputGetState) _XInputGetStateEx_t; // XInputGetStateEx
4040

4141
_XInputEnable_t _XInputEnable;
4242
_XInputSetState_t _XInputSetState;
@@ -80,6 +80,22 @@ namespace REAL_XINPUT
8080
return response;
8181
}
8282

83+
BOOL restoreFunctions()
84+
{
85+
// Set every function-pointer back to 'nullptr':
86+
_XInputEnable = nullptr;
87+
_XInputSetState = nullptr;
88+
_XInputGetState = nullptr;
89+
_XInputGetCapabilities = nullptr;
90+
_XInputGetBatteryInformation = nullptr;
91+
_XInputGetKeystroke = nullptr;
92+
_XInputGetAudioDeviceIds = nullptr;
93+
_XInputGetStateEx = nullptr;
94+
95+
// Return the default response.
96+
return TRUE;
97+
}
98+
8399
VOID linkTo(HMODULE hDLL)
84100
{
85101
using namespace process;

IOSync/src/devices/native/winnt/Real_XInput_Wrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace REAL_XINPUT
4747

4848
process::jumpSegment mapRemoteFunction(LPCSTR name, LPCVOID function, HMODULE hDLL);
4949

50+
// This command restores the internal function-pointers to their original state.
51+
BOOL restoreFunctions();
52+
5053
VOID linkTo(HMODULE hDLL);
5154

5255
// The 'resolveSystemPath' argument specifies if this routine

0 commit comments

Comments
 (0)