diff --git a/AddressLookupTable.h b/AddressLookupTable.h index 304b22c..4bfc754 100644 --- a/AddressLookupTable.h +++ b/AddressLookupTable.h @@ -4,7 +4,7 @@ #include #include "dinputto8.h" -constexpr UINT MaxIndex = 14; +constexpr UINT MaxIndex = 16; template class AddressLookupTableDinput @@ -14,9 +14,9 @@ class AddressLookupTableDinput ~AddressLookupTableDinput() { ConstructorFlag = true; - for (const auto& cache : g_map) + for (const auto& x : { 13, 14, 15 }) { - for (const auto& entry : cache) + for (const auto& entry : g_map[x]) { entry.second->DeleteMe(); } @@ -65,6 +65,10 @@ class AddressLookupTableDinput struct AddressCacheIndex { static constexpr UINT CacheIndex = 12; }; template <> struct AddressCacheIndex { static constexpr UINT CacheIndex = 13; }; + template <> + struct AddressCacheIndex { static constexpr UINT CacheIndex = 14; }; + template <> + struct AddressCacheIndex { static constexpr UINT CacheIndex = 15; }; template T *FindAddress(void *Proxy, DWORD Version, DWORD Type) @@ -85,7 +89,7 @@ class AddressLookupTableDinput return nullptr; } } - case UNICODE: + case UNICODE_CHARSET: { switch (Version) { @@ -118,11 +122,10 @@ class AddressLookupTableDinput if (it != std::end(g_map[CacheIndex])) { Logging::LogDebug() << __FUNCTION__ << " Found device address!"; - (static_cast(it->second))->GetWrapperInterface()->IncRef(); return static_cast(it->second); } - return new T(static_cast(Proxy)); + return nullptr; } template diff --git a/BuildNo.rc b/BuildNo.rc index 5859b6a..7e3df24 100644 --- a/BuildNo.rc +++ b/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 38 +#define BUILD_NUMBER 39 diff --git a/IDirectInputDeviceX.cpp b/IDirectInputDeviceX.cpp index e75dd7f..cf00ce2 100644 --- a/IDirectInputDeviceX.cpp +++ b/IDirectInputDeviceX.cpp @@ -29,29 +29,40 @@ HRESULT m_IDirectInputDeviceX::QueryInterface(REFIID riid, LPVOID* ppvObj) { Logging::LogDebug() << __FUNCTION__ << "(" << this << ")"; - return ProxyQueryInterface(ProxyInterface, riid, ppvObj, WrapperID, WrapperInterface); + return ProxyQueryInterface(ProxyInterface, riid, ppvObj, WrapperID, GetWrapperInterface(dinputto8::GetGUIDVersion(riid))); +} + +LPVOID m_IDirectInputDeviceX::GetWrapperInterface(DWORD DirectXVersion) +{ + switch (DirectXVersion) + { + case 1: + return WrapperInterface; + case 2: + return WrapperInterface2; + case 7: + return WrapperInterface7; + default: + return nullptr; + } } ULONG m_IDirectInputDeviceX::AddRef() { Logging::LogDebug() << __FUNCTION__ << "(" << this << ")"; - ProxyInterface->AddRef(); - - return InterlockedIncrement(&RefCount); + return ProxyInterface->AddRef(); } ULONG m_IDirectInputDeviceX::Release() { Logging::LogDebug() << __FUNCTION__ << "(" << this << ")"; - ProxyInterface->Release(); - - ULONG ref = InterlockedDecrement(&RefCount); + ULONG ref = ProxyInterface->Release(); if (ref == 0) { - WrapperInterface->DeleteMe(); + delete this; } return ref; @@ -319,7 +330,7 @@ HRESULT m_IDirectInputDeviceX::CreateEffect(REFGUID rguid, LPCDIEFFECT lpeff, LP if (SUCCEEDED(hr) && ppdeff) { - *ppdeff = ProxyAddressLookupTable.FindAddress(*ppdeff); + *ppdeff = new m_IDirectInputEffect((IDirectInputEffect*)*ppdeff); } return hr; diff --git a/IDirectInputDeviceX.h b/IDirectInputDeviceX.h index 46b4526..55bb301 100644 --- a/IDirectInputDeviceX.h +++ b/IDirectInputDeviceX.h @@ -1,14 +1,16 @@ #pragma once -class m_IDirectInputDeviceX +class m_IDirectInputDeviceX : public AddressLookupTableDinputObject { private: IDirectInputDevice8W *ProxyInterface; - m_IDirectInputDevice7W *WrapperInterface; - DWORD DirectXVersion; REFIID WrapperID; DWORD StringType; - ULONG RefCount = 1; + + // Version Interfaces + void *WrapperInterface; + void *WrapperInterface2; + void *WrapperInterface7; // For CooperativeLevel bool CanAquireDevice = false; @@ -27,21 +29,49 @@ class m_IDirectInputDeviceX std::vector rgodf; public: - m_IDirectInputDeviceX(IDirectInputDevice8W *aOriginal, DWORD Version, REFIID riid, m_IDirectInputDevice7W *Interface) : ProxyInterface(aOriginal), DirectXVersion(Version), WrapperID(riid), WrapperInterface(Interface) + m_IDirectInputDeviceX(IDirectInputDevice8W *aOriginal, REFIID riid) : ProxyInterface(aOriginal), WrapperID(riid), StringType(GetStringType(riid)) { - StringType = GetStringType(WrapperID); + LOG_LIMIT(3, "Creating device " << __FUNCTION__ << "(" << this << ")" << " converting device from v" << dinputto8::GetGUIDVersion(riid) << " to v8 using " << ((StringType == ANSI_CHARSET) ? "ANSI" : "UNICODE")); - LOG_LIMIT(3, "Creating device " << __FUNCTION__ << "(" << this << ")" << " converting device from v" << Version << " to v8 using " << ((StringType == DEFAULT_CHARSET) ? "UNICODE" : "ANSI")); + if (StringType == ANSI_CHARSET) + { + WrapperInterface = new m_IDirectInputDeviceA((LPDIRECTINPUTDEVICEA)ProxyInterface, this); + WrapperInterface2 = new m_IDirectInputDevice2A((LPDIRECTINPUTDEVICE2A)ProxyInterface, this); + WrapperInterface7 = new m_IDirectInputDevice7A((LPDIRECTINPUTDEVICE7A)ProxyInterface, this); + } + else + { + WrapperInterface = new m_IDirectInputDeviceW((LPDIRECTINPUTDEVICEW)ProxyInterface, this); + WrapperInterface2 = new m_IDirectInputDevice2W((LPDIRECTINPUTDEVICE2W)ProxyInterface, this); + WrapperInterface7 = new m_IDirectInputDevice7W((LPDIRECTINPUTDEVICE7W)ProxyInterface, this); + } // Initialize Critical Section InitializeCriticalSection(&dics); + + ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); } ~m_IDirectInputDeviceX() { LOG_LIMIT(3, __FUNCTION__ << "(" << this << ")" << " deleting device!"); + if (StringType == ANSI_CHARSET) + { + ((m_IDirectInputA*)WrapperInterface)->DeleteMe(); + ((m_IDirectInput2A*)WrapperInterface2)->DeleteMe(); + ((m_IDirectInput7A*)WrapperInterface7)->DeleteMe(); + } + else + { + ((m_IDirectInputW*)WrapperInterface)->DeleteMe(); + ((m_IDirectInput2W*)WrapperInterface2)->DeleteMe(); + ((m_IDirectInput7W*)WrapperInterface7)->DeleteMe(); + } + // Delete Critical Section DeleteCriticalSection(&dics); + + ProxyAddressLookupTable.DeleteAddress(this); } /*** IUnknown methods ***/ @@ -89,7 +119,7 @@ class m_IDirectInputDeviceX STDMETHOD(WriteEffectToFileW)(THIS_ LPCWSTR, DWORD, LPDIFILEEFFECT, DWORD); // Helper functions - void IncRef() { InterlockedIncrement(&RefCount); } + LPVOID GetWrapperInterface(DWORD DXVersion); IDirectInputDevice8A *GetProxyInterfaceA() { return (IDirectInputDevice8A*)ProxyInterface; } IDirectInputDevice8W *GetProxyInterfaceW() { return ProxyInterface; } }; diff --git a/IDirectInputEffect.h b/IDirectInputEffect.h index 520bc2e..8a7b2dd 100644 --- a/IDirectInputEffect.h +++ b/IDirectInputEffect.h @@ -10,13 +10,13 @@ class m_IDirectInputEffect : public IDirectInputEffect, public AddressLookupTabl public: m_IDirectInputEffect(IDirectInputEffect *aOriginal) : ProxyInterface(aOriginal), WrapperInterface(this) { - ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); - LOG_LIMIT(3, "Creating device " << __FUNCTION__ << "(" << this << ")"); + + ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); } ~m_IDirectInputEffect() { - Logging::LogDebug() << __FUNCTION__ << "(" << this << ")" << " deleting device!"; + LOG_LIMIT(3, __FUNCTION__ << "(" << this << ")" << " deleting device!"); ProxyAddressLookupTable.DeleteAddress(this); } diff --git a/IDirectInputX.cpp b/IDirectInputX.cpp index 631e048..c97c450 100644 --- a/IDirectInputX.cpp +++ b/IDirectInputX.cpp @@ -20,29 +20,40 @@ HRESULT m_IDirectInputX::QueryInterface(REFIID riid, LPVOID * ppvObj) { Logging::LogDebug() << __FUNCTION__ << "(" << this << ")"; - return ProxyQueryInterface(ProxyInterface, riid, ppvObj, WrapperID, WrapperInterface); + return ProxyQueryInterface(ProxyInterface, riid, ppvObj, WrapperID, GetWrapperInterface(dinputto8::GetGUIDVersion(riid))); +} + +LPVOID m_IDirectInputX::GetWrapperInterface(DWORD DirectXVersion) +{ + switch (DirectXVersion) + { + case 1: + return WrapperInterface; + case 2: + return WrapperInterface2; + case 7: + return WrapperInterface7; + default: + return nullptr; + } } ULONG m_IDirectInputX::AddRef() { Logging::LogDebug() << __FUNCTION__ << "(" << this << ")"; - ProxyInterface->AddRef(); - - return InterlockedIncrement(&RefCount); + return ProxyInterface->AddRef(); } ULONG m_IDirectInputX::Release() { Logging::LogDebug() << __FUNCTION__ << "(" << this << ")"; - ProxyInterface->Release(); - - ULONG ref = InterlockedDecrement(&RefCount); + ULONG ref = ProxyInterface->Release(); if (ref == 0) { - WrapperInterface->DeleteMe(); + delete this; } return ref; @@ -123,7 +134,9 @@ HRESULT m_IDirectInputX::CreateDeviceExA(REFGUID rguid, REFIID riid, LPDIRECTINP if (SUCCEEDED(hr) && ppvObj) { - genericQueryInterface(riid, (LPVOID *)ppvObj); + m_IDirectInputDeviceX *DIDevice = new m_IDirectInputDeviceX((IDirectInputDevice8W*)*ppvObj, riid); + + *ppvObj = (LPDIRECTINPUTDEVICE8A)DIDevice->GetWrapperInterface(dinputto8::GetGUIDVersion(riid)); } return hr; @@ -137,7 +150,9 @@ HRESULT m_IDirectInputX::CreateDeviceExW(REFGUID rguid, REFIID riid, LPDIRECTINP if (SUCCEEDED(hr) && ppvObj) { - genericQueryInterface(riid, (LPVOID *)ppvObj); + m_IDirectInputDeviceX *DIDevice = new m_IDirectInputDeviceX((IDirectInputDevice8W*)*ppvObj, riid); + + *ppvObj = (LPDIRECTINPUTDEVICE8W)DIDevice->GetWrapperInterface(dinputto8::GetGUIDVersion(riid)); } return hr; diff --git a/IDirectInputX.h b/IDirectInputX.h index edf111d..fb385fe 100644 --- a/IDirectInputX.h +++ b/IDirectInputX.h @@ -1,25 +1,55 @@ #pragma once -class m_IDirectInputX +class m_IDirectInputX : public AddressLookupTableDinputObject { private: IDirectInput8W *ProxyInterface; - m_IDirectInput7W *WrapperInterface; - DWORD DirectXVersion; REFIID WrapperID; DWORD StringType; - ULONG RefCount = 1; + + // Version Interfaces + void *WrapperInterface; + void *WrapperInterface2; + void *WrapperInterface7; public: - m_IDirectInputX(IDirectInput8W *aOriginal, DWORD Version, REFIID riid, m_IDirectInput7W *Interface) : ProxyInterface(aOriginal), DirectXVersion(Version), WrapperID(riid), WrapperInterface(Interface) + m_IDirectInputX(IDirectInput8W *aOriginal, REFIID riid) : ProxyInterface(aOriginal), WrapperID(riid), StringType(GetStringType(riid)) { - StringType = GetStringType(WrapperID); + LOG_LIMIT(3, "Creating device " << __FUNCTION__ << "(" << this << ")" << " converting device from v" << dinputto8::GetGUIDVersion(riid) << " to v8 using " << ((StringType == ANSI_CHARSET) ? "ANSI" : "UNICODE")); + + if (StringType == ANSI_CHARSET) + { + WrapperInterface = new m_IDirectInputA((LPDIRECTINPUTA)ProxyInterface, this); + WrapperInterface2 = new m_IDirectInput2A((LPDIRECTINPUT2A)ProxyInterface, this); + WrapperInterface7 = new m_IDirectInput7A((LPDIRECTINPUT7A)ProxyInterface, this); + } + else + { + WrapperInterface = new m_IDirectInputW((LPDIRECTINPUTW)ProxyInterface, this); + WrapperInterface2 = new m_IDirectInput2W((LPDIRECTINPUT2W)ProxyInterface, this); + WrapperInterface7 = new m_IDirectInput7W((LPDIRECTINPUT7W)ProxyInterface, this); + } - LOG_LIMIT(3, "Creating device " << __FUNCTION__ << "(" << this << ")" << " converting device from v" << Version << " to v8 using " << ((StringType == DEFAULT_CHARSET) ? "UNICODE" : "ANSI")); + ProxyAddressLookupTable.SaveAddress(this, ProxyInterface); } ~m_IDirectInputX() { LOG_LIMIT(3, __FUNCTION__ << "(" << this << ")" << " deleting device!"); + + if (StringType == ANSI_CHARSET) + { + ((m_IDirectInputA*)WrapperInterface)->DeleteMe(); + ((m_IDirectInput2A*)WrapperInterface2)->DeleteMe(); + ((m_IDirectInput7A*)WrapperInterface7)->DeleteMe(); + } + else + { + ((m_IDirectInputW*)WrapperInterface)->DeleteMe(); + ((m_IDirectInput2W*)WrapperInterface2)->DeleteMe(); + ((m_IDirectInput7W*)WrapperInterface7)->DeleteMe(); + } + + ProxyAddressLookupTable.DeleteAddress(this); } /*** IUnknown methods ***/ @@ -43,7 +73,7 @@ class m_IDirectInputX STDMETHOD(CreateDeviceExW)(THIS_ REFGUID, REFIID, LPDIRECTINPUTDEVICE8W *, LPUNKNOWN); // Helper functions - void IncRef() { InterlockedIncrement(&RefCount); } + LPVOID GetWrapperInterface(DWORD DXVersion); IDirectInput8A *GetProxyInterfaceA() { return (IDirectInput8A*)ProxyInterface; } IDirectInput8W *GetProxyInterfaceW() { return ProxyInterface; } }; diff --git a/InterfaceQuery.cpp b/InterfaceQuery.cpp index f44206d..2038091 100644 --- a/InterfaceQuery.cpp +++ b/InterfaceQuery.cpp @@ -21,43 +21,28 @@ DWORD dinputto8::GetStringType(REFIID riid) return (riid == IID_IDirectInputA || riid == IID_IDirectInput2A || riid == IID_IDirectInput7A || riid == IID_IDirectInputDeviceA || riid == IID_IDirectInputDevice2A || riid == IID_IDirectInputDevice7A) ? ANSI_CHARSET : (riid == IID_IDirectInputW || riid == IID_IDirectInput2W || riid == IID_IDirectInput7W || - riid == IID_IDirectInputDeviceW || riid == IID_IDirectInputDevice2W || riid == IID_IDirectInputDevice7W) ? DEFAULT_CHARSET : DIERR_UNSUPPORTED; + riid == IID_IDirectInputDeviceW || riid == IID_IDirectInputDevice2W || riid == IID_IDirectInputDevice7W) ? UNICODE_CHARSET : DIERR_UNSUPPORTED; } -REFCLSID dinputto8::ConvertREFCLSID(REFCLSID rclsid) +DWORD dinputto8::GetGUIDVersion(REFIID riid) { - if (rclsid == CLSID_DirectInput) - { - return CLSID_DirectInput8; - } - if (rclsid == CLSID_DirectInputDevice) - { - return CLSID_DirectInputDevice8; - } + return (riid == IID_IDirectInputA || riid == IID_IDirectInputW || riid == IID_IDirectInputDeviceA || riid == IID_IDirectInputDeviceW) ? 1 : + (riid == IID_IDirectInput2A || riid == IID_IDirectInput2W || riid == IID_IDirectInputDevice2A || riid == IID_IDirectInputDevice2W) ? 2 : + (riid == IID_IDirectInput7A || riid == IID_IDirectInput7W || riid == IID_IDirectInputDevice7A || riid == IID_IDirectInputDevice7W) ? 7 : 0; +} - return rclsid; +REFCLSID dinputto8::ConvertREFCLSID(REFCLSID rclsid) +{ + return (rclsid == CLSID_DirectInput) ? CLSID_DirectInput8 : + (rclsid == CLSID_DirectInputDevice) ? CLSID_DirectInputDevice8 : rclsid; } REFIID dinputto8::ConvertREFIID(REFIID riid) { - if (riid == IID_IDirectInputA || riid == IID_IDirectInput2A || riid == IID_IDirectInput7A) - { - return IID_IDirectInput8A; - } - else if (riid == IID_IDirectInputW || riid == IID_IDirectInput2W || riid == IID_IDirectInput7W) - { - return IID_IDirectInput8W; - } - else if (riid == IID_IDirectInputDeviceA || riid == IID_IDirectInputDevice2A || riid == IID_IDirectInputDevice7A) - { - return IID_IDirectInputDevice8A; - } - else if (riid == IID_IDirectInputDeviceW || riid == IID_IDirectInputDevice2W || riid == IID_IDirectInputDevice7W) - { - return IID_IDirectInputDevice8W; - } - - return riid; + return (riid == IID_IDirectInputA || riid == IID_IDirectInput2A || riid == IID_IDirectInput7A) ? IID_IDirectInput8A : + (riid == IID_IDirectInputW || riid == IID_IDirectInput2W || riid == IID_IDirectInput7W) ? IID_IDirectInput8W : + (riid == IID_IDirectInputDeviceA || riid == IID_IDirectInputDevice2A || riid == IID_IDirectInputDevice7A) ? IID_IDirectInputDevice8A : + (riid == IID_IDirectInputDeviceW || riid == IID_IDirectInputDevice2W || riid == IID_IDirectInputDevice7W) ? IID_IDirectInputDevice8W : riid; } HRESULT dinputto8::ProxyQueryInterface(LPVOID ProxyInterface, REFIID riid, LPVOID * ppvObj, REFIID WrapperID, LPVOID WrapperInterface) @@ -90,24 +75,56 @@ void WINAPI dinputto8::genericQueryInterface(REFIID riid, LPVOID * ppvObj) return; } -#define QUERYINTERFACE(x) \ +#define QUERYINTERFACEDI(x) \ + if (riid == IID_ ## x) \ + { \ + Logging::LogDebug() << "Getting device for: m_" ## #x; \ + m_IDirectInputX *Interface = (m_IDirectInputX*)ProxyAddressLookupTable.FindAddress(*ppvObj); \ + if (Interface) \ + { \ + *ppvObj = Interface; \ + } \ + else \ + { \ + Interface = new m_IDirectInputX((IDirectInput8W*)*ppvObj, riid); \ + *ppvObj = Interface->GetWrapperInterface(dinputto8::GetGUIDVersion(riid)); \ + } \ + } + + QUERYINTERFACEDI(IDirectInputA); + QUERYINTERFACEDI(IDirectInputW); + QUERYINTERFACEDI(IDirectInput2A); + QUERYINTERFACEDI(IDirectInput2W); + QUERYINTERFACEDI(IDirectInput7A); + QUERYINTERFACEDI(IDirectInput7W); + +#define QUERYINTERFACEDID(x) \ if (riid == IID_ ## x) \ + { \ + Logging::LogDebug() << "Getting device for: m_" ## #x; \ + m_IDirectInputDeviceX *Interface = (m_IDirectInputDeviceX*)ProxyAddressLookupTable.FindAddress(*ppvObj); \ + if (Interface) \ + { \ + *ppvObj = Interface; \ + } \ + else \ { \ - Logging::LogDebug() << "Getting device for: m_" ## #x; \ - *ppvObj = ProxyAddressLookupTable.FindAddress(*ppvObj); \ - } - - QUERYINTERFACE(IDirectInputA); - QUERYINTERFACE(IDirectInputW); - QUERYINTERFACE(IDirectInput2A); - QUERYINTERFACE(IDirectInput2W); - QUERYINTERFACE(IDirectInput7A); - QUERYINTERFACE(IDirectInput7W); - QUERYINTERFACE(IDirectInputDeviceA); - QUERYINTERFACE(IDirectInputDeviceW); - QUERYINTERFACE(IDirectInputDevice2A); - QUERYINTERFACE(IDirectInputDevice2W); - QUERYINTERFACE(IDirectInputDevice7A); - QUERYINTERFACE(IDirectInputDevice7W); - QUERYINTERFACE(IDirectInputEffect); + Interface = new m_IDirectInputDeviceX((IDirectInputDevice8W*)*ppvObj, riid); \ + *ppvObj = Interface->GetWrapperInterface(dinputto8::GetGUIDVersion(riid)); \ + } \ + } + + QUERYINTERFACEDID(IDirectInputDeviceA); + QUERYINTERFACEDID(IDirectInputDeviceW); + QUERYINTERFACEDID(IDirectInputDevice2A); + QUERYINTERFACEDID(IDirectInputDevice2W); + QUERYINTERFACEDID(IDirectInputDevice7A); + QUERYINTERFACEDID(IDirectInputDevice7W); + + if (riid == IID_IDirectInputEffect) + { + Logging::LogDebug() << "Getting device for: m_IDirectInputEffect"; + m_IDirectInputEffect *Interface = ProxyAddressLookupTable.FindAddress(*ppvObj); + *ppvObj = (Interface) ? Interface : new m_IDirectInputEffect((IDirectInputEffect*)*ppvObj); + } } diff --git a/Versions/IDirectInput2A.h b/Versions/IDirectInput2A.h index 89bcd1e..23bca16 100644 --- a/Versions/IDirectInput2A.h +++ b/Versions/IDirectInput2A.h @@ -3,14 +3,14 @@ class m_IDirectInput2A : public IDirectInput2A, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputX *ProxyInterface; IDirectInput2A *RealInterface; REFIID WrapperID = IID_IDirectInput2A; + const DWORD DirectXVersion = 2; public: - m_IDirectInput2A(IDirectInput2A *aOriginal) : RealInterface(aOriginal) + m_IDirectInput2A(IDirectInput2A *aOriginal, m_IDirectInputX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInput8W*)RealInterface, 2, WrapperID, (m_IDirectInput7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInput2A() @@ -21,7 +21,7 @@ class m_IDirectInput2A : public IDirectInput2A, public AddressLookupTableDinputO DWORD GetDirectXVersion() { return 2; } REFIID GetWrapperType() { return WrapperID; } IDirectInput2A *GetProxyInterface() { return RealInterface; } - m_IDirectInputX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInput2W.h b/Versions/IDirectInput2W.h index db45a31..35dc5f0 100644 --- a/Versions/IDirectInput2W.h +++ b/Versions/IDirectInput2W.h @@ -3,14 +3,14 @@ class m_IDirectInput2W : public IDirectInput2W, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputX *ProxyInterface; IDirectInput2W *RealInterface; REFIID WrapperID = IID_IDirectInput2W; + const DWORD DirectXVersion = 2; public: - m_IDirectInput2W(IDirectInput2W *aOriginal) : RealInterface(aOriginal) + m_IDirectInput2W(IDirectInput2W *aOriginal, m_IDirectInputX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInput8W*)RealInterface, 2, WrapperID, (m_IDirectInput7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInput2W() @@ -21,7 +21,7 @@ class m_IDirectInput2W : public IDirectInput2W, public AddressLookupTableDinputO DWORD GetDirectXVersion() { return 2; } REFIID GetWrapperType() { return WrapperID; } IDirectInput2W *GetProxyInterface() { return RealInterface; } - m_IDirectInputX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInput7A.h b/Versions/IDirectInput7A.h index a97cdb1..f116d4e 100644 --- a/Versions/IDirectInput7A.h +++ b/Versions/IDirectInput7A.h @@ -3,14 +3,14 @@ class m_IDirectInput7A : public IDirectInput7A, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputX *ProxyInterface; IDirectInput7A *RealInterface; REFIID WrapperID = IID_IDirectInput7A; + const DWORD DirectXVersion = 7; public: - m_IDirectInput7A(IDirectInput7A *aOriginal) : RealInterface(aOriginal) + m_IDirectInput7A(IDirectInput7A *aOriginal, m_IDirectInputX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInput8W*)RealInterface, 7, WrapperID, (m_IDirectInput7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInput7A() @@ -21,7 +21,7 @@ class m_IDirectInput7A : public IDirectInput7A, public AddressLookupTableDinputO DWORD GetDirectXVersion() { return 7; } REFIID GetWrapperType() { return WrapperID; } IDirectInput7A *GetProxyInterface() { return RealInterface; } - m_IDirectInputX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInput7W.h b/Versions/IDirectInput7W.h index f5d6e66..6f94d41 100644 --- a/Versions/IDirectInput7W.h +++ b/Versions/IDirectInput7W.h @@ -3,14 +3,14 @@ class m_IDirectInput7W : public IDirectInput7W, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputX *ProxyInterface; IDirectInput7W *RealInterface; REFIID WrapperID = IID_IDirectInput7W; + const DWORD DirectXVersion = 7; public: - m_IDirectInput7W(IDirectInput7W *aOriginal) : RealInterface(aOriginal) + m_IDirectInput7W(IDirectInput7W *aOriginal, m_IDirectInputX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInput8W*)RealInterface, 7, WrapperID, (m_IDirectInput7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInput7W() @@ -21,7 +21,7 @@ class m_IDirectInput7W : public IDirectInput7W, public AddressLookupTableDinputO DWORD GetDirectXVersion() { return 7; } REFIID GetWrapperType() { return WrapperID; } IDirectInput7W *GetProxyInterface() { return RealInterface; } - m_IDirectInputX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputA.h b/Versions/IDirectInputA.h index 704e695..28093dd 100644 --- a/Versions/IDirectInputA.h +++ b/Versions/IDirectInputA.h @@ -3,14 +3,14 @@ class m_IDirectInputA : public IDirectInputA, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputX *ProxyInterface; IDirectInputA *RealInterface; REFIID WrapperID = IID_IDirectInputA; + const DWORD DirectXVersion = 1; public: - m_IDirectInputA(IDirectInputA *aOriginal) : RealInterface(aOriginal) + m_IDirectInputA(IDirectInputA *aOriginal, m_IDirectInputX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInput8W*)RealInterface, 1, WrapperID, (m_IDirectInput7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputA() @@ -21,7 +21,7 @@ class m_IDirectInputA : public IDirectInputA, public AddressLookupTableDinputObj DWORD GetDirectXVersion() { return 1; } REFIID GetWrapperType() { return WrapperID; } IDirectInputA *GetProxyInterface() { return RealInterface; } - m_IDirectInputX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputDevice2A.h b/Versions/IDirectInputDevice2A.h index c3bd48e..4e2d8d3 100644 --- a/Versions/IDirectInputDevice2A.h +++ b/Versions/IDirectInputDevice2A.h @@ -3,14 +3,14 @@ class m_IDirectInputDevice2A : public IDirectInputDevice2A, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputDeviceX *ProxyInterface; IDirectInputDevice2A *RealInterface; REFIID WrapperID = IID_IDirectInputDevice2A; + const DWORD DirectXVersion = 2; public: - m_IDirectInputDevice2A(IDirectInputDevice2A *aOriginal) : RealInterface(aOriginal) + m_IDirectInputDevice2A(IDirectInputDevice2A *aOriginal, m_IDirectInputDeviceX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInputDevice8W*)RealInterface, 2, WrapperID, (m_IDirectInputDevice7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputDevice2A() @@ -21,7 +21,7 @@ class m_IDirectInputDevice2A : public IDirectInputDevice2A, public AddressLookup DWORD GetDirectXVersion() { return 2; } REFIID GetWrapperType() { return WrapperID; } IDirectInputDevice2A *GetProxyInterface() { return RealInterface; } - m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputDevice2W.h b/Versions/IDirectInputDevice2W.h index 9a2bdf6..9c74647 100644 --- a/Versions/IDirectInputDevice2W.h +++ b/Versions/IDirectInputDevice2W.h @@ -3,14 +3,14 @@ class m_IDirectInputDevice2W : public IDirectInputDevice2W, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputDeviceX *ProxyInterface; IDirectInputDevice2W *RealInterface; REFIID WrapperID = IID_IDirectInputDevice2W; + const DWORD DirectXVersion = 2; public: - m_IDirectInputDevice2W(IDirectInputDevice2W *aOriginal) : RealInterface(aOriginal) + m_IDirectInputDevice2W(IDirectInputDevice2W *aOriginal, m_IDirectInputDeviceX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInputDevice8W*)RealInterface, 2, WrapperID, (m_IDirectInputDevice7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputDevice2W() @@ -21,7 +21,7 @@ class m_IDirectInputDevice2W : public IDirectInputDevice2W, public AddressLookup DWORD GetDirectXVersion() { return 2; } REFIID GetWrapperType() { return WrapperID; } IDirectInputDevice2W *GetProxyInterface() { return RealInterface; } - m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputDevice7A.h b/Versions/IDirectInputDevice7A.h index 3c28b47..57a2bec 100644 --- a/Versions/IDirectInputDevice7A.h +++ b/Versions/IDirectInputDevice7A.h @@ -3,14 +3,14 @@ class m_IDirectInputDevice7A : public IDirectInputDevice7A, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputDeviceX *ProxyInterface; IDirectInputDevice7A *RealInterface; REFIID WrapperID = IID_IDirectInputDevice7A; + const DWORD DirectXVersion = 7; public: - m_IDirectInputDevice7A(IDirectInputDevice7A *aOriginal) : RealInterface(aOriginal) + m_IDirectInputDevice7A(IDirectInputDevice7A *aOriginal, m_IDirectInputDeviceX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInputDevice8W*)RealInterface, 7, WrapperID, (m_IDirectInputDevice7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputDevice7A() @@ -21,7 +21,7 @@ class m_IDirectInputDevice7A : public IDirectInputDevice7A, public AddressLookup DWORD GetDirectXVersion() { return 7; } REFIID GetWrapperType() { return WrapperID; } IDirectInputDevice7A *GetProxyInterface() { return RealInterface; } - m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputDevice7W.h b/Versions/IDirectInputDevice7W.h index 76980cb..31094ca 100644 --- a/Versions/IDirectInputDevice7W.h +++ b/Versions/IDirectInputDevice7W.h @@ -3,14 +3,14 @@ class m_IDirectInputDevice7W : public IDirectInputDevice7W, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputDeviceX *ProxyInterface; IDirectInputDevice7W *RealInterface; REFIID WrapperID = IID_IDirectInputDevice7W; + const DWORD DirectXVersion = 7; public: - m_IDirectInputDevice7W(IDirectInputDevice7W *aOriginal) : RealInterface(aOriginal) + m_IDirectInputDevice7W(IDirectInputDevice7W *aOriginal, m_IDirectInputDeviceX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInputDevice8W*)RealInterface, 7, WrapperID, (m_IDirectInputDevice7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputDevice7W() @@ -21,7 +21,7 @@ class m_IDirectInputDevice7W : public IDirectInputDevice7W, public AddressLookup DWORD GetDirectXVersion() { return 7; } REFIID GetWrapperType() { return WrapperID; } IDirectInputDevice7W *GetProxyInterface() { return RealInterface; } - m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputDeviceA.h b/Versions/IDirectInputDeviceA.h index 6060075..d7a1c38 100644 --- a/Versions/IDirectInputDeviceA.h +++ b/Versions/IDirectInputDeviceA.h @@ -3,14 +3,14 @@ class m_IDirectInputDeviceA : public IDirectInputDeviceA, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputDeviceX *ProxyInterface; IDirectInputDeviceA *RealInterface; REFIID WrapperID = IID_IDirectInputDeviceA; + const DWORD DirectXVersion = 1; public: - m_IDirectInputDeviceA(IDirectInputDeviceA *aOriginal) : RealInterface(aOriginal) + m_IDirectInputDeviceA(IDirectInputDeviceA *aOriginal, m_IDirectInputDeviceX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInputDevice8W*)RealInterface, 1, WrapperID, (m_IDirectInputDevice7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputDeviceA() @@ -21,7 +21,7 @@ class m_IDirectInputDeviceA : public IDirectInputDeviceA, public AddressLookupTa DWORD GetDirectXVersion() { return 1; } REFIID GetWrapperType() { return WrapperID; } IDirectInputDeviceA *GetProxyInterface() { return RealInterface; } - m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputDeviceW.h b/Versions/IDirectInputDeviceW.h index 9970373..49c244f 100644 --- a/Versions/IDirectInputDeviceW.h +++ b/Versions/IDirectInputDeviceW.h @@ -3,14 +3,14 @@ class m_IDirectInputDeviceW : public IDirectInputDeviceW, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputDeviceX *ProxyInterface; IDirectInputDeviceW *RealInterface; REFIID WrapperID = IID_IDirectInputDeviceW; + const DWORD DirectXVersion = 1; public: - m_IDirectInputDeviceW(IDirectInputDeviceW *aOriginal) : RealInterface(aOriginal) + m_IDirectInputDeviceW(IDirectInputDeviceW *aOriginal, m_IDirectInputDeviceX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInputDevice8W*)RealInterface, 1, WrapperID, (m_IDirectInputDevice7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputDeviceW() @@ -21,7 +21,7 @@ class m_IDirectInputDeviceW : public IDirectInputDeviceW, public AddressLookupTa DWORD GetDirectXVersion() { return 1; } REFIID GetWrapperType() { return WrapperID; } IDirectInputDeviceW *GetProxyInterface() { return RealInterface; } - m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputDeviceX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/Versions/IDirectInputW.h b/Versions/IDirectInputW.h index 04462d4..29cbf3b 100644 --- a/Versions/IDirectInputW.h +++ b/Versions/IDirectInputW.h @@ -3,14 +3,14 @@ class m_IDirectInputW : public IDirectInputW, public AddressLookupTableDinputObject { private: - std::unique_ptr ProxyInterface; + m_IDirectInputX *ProxyInterface; IDirectInputW *RealInterface; REFIID WrapperID = IID_IDirectInputW; + const DWORD DirectXVersion = 1; public: - m_IDirectInputW(IDirectInputW *aOriginal) : RealInterface(aOriginal) + m_IDirectInputW(IDirectInputW *aOriginal, m_IDirectInputX *Interface) : RealInterface(aOriginal), ProxyInterface(Interface) { - ProxyInterface = std::make_unique((IDirectInput8W*)RealInterface, 1, WrapperID, (m_IDirectInput7W*)this); ProxyAddressLookupTable.SaveAddress(this, RealInterface); } ~m_IDirectInputW() @@ -21,7 +21,7 @@ class m_IDirectInputW : public IDirectInputW, public AddressLookupTableDinputObj DWORD GetDirectXVersion() { return 1; } REFIID GetWrapperType() { return WrapperID; } IDirectInputW *GetProxyInterface() { return RealInterface; } - m_IDirectInputX *GetWrapperInterface() { return ProxyInterface.get(); } + m_IDirectInputX *GetWrapperInterface() { return ProxyInterface; } /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj); diff --git a/dinputto8.cpp b/dinputto8.cpp index 4ed969d..377097a 100644 --- a/dinputto8.cpp +++ b/dinputto8.cpp @@ -100,7 +100,10 @@ HRESULT WINAPI DirectInputCreateEx(HINSTANCE hinst, DWORD dwVersion, REFIID riid if (SUCCEEDED(hr) && lplpDD) { diVersion = dwVersion; - genericQueryInterface(riid, lplpDD); + + m_IDirectInputX *Interface = new m_IDirectInputX((IDirectInput8W*)*lplpDD, riid); + + *lplpDD = Interface->GetWrapperInterface(dinputto8::GetGUIDVersion(riid)); } return hr; diff --git a/dinputto8.h b/dinputto8.h index fd261ab..b6e6671 100644 --- a/dinputto8.h +++ b/dinputto8.h @@ -3,6 +3,7 @@ #define INITGUID #define DIRECTINPUT_VERSION 0x0800 +#define UNICODE_CHARSET DEFAULT_CHARSET #include #include "ditypes.h" @@ -36,6 +37,7 @@ typedef HRESULT(WINAPI *DllUnregisterServerProc)(); namespace dinputto8 { DWORD GetStringType(REFIID riid); + DWORD GetGUIDVersion(REFIID riid); REFCLSID ConvertREFCLSID(REFCLSID rclsid); REFIID ConvertREFIID(REFIID riid); HRESULT ProxyQueryInterface(LPVOID ProxyInterface, REFIID riid, LPVOID * ppvObj, REFIID WrapperID, LPVOID WrapperInterface);