Skip to content

Commit

Permalink
Return an effect class even on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jun 26, 2024
1 parent cf97428 commit 9235e08
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 72
#define BUILD_NUMBER 73
12 changes: 9 additions & 3 deletions IDirectInputDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,20 @@ HRESULT m_IDirectInputDeviceX::CreateEffect(REFGUID rguid, LPCDIEFFECT lpeff, LP

if (SUCCEEDED(hr) && ppdeff)
{
m_IDirectInputEffect* DIEffect = new m_IDirectInputEffect((IDirectInputEffect*)*ppdeff);
DIEffect->SetVersion(diVersion);
m_IDirectInputEffect* pEffect = new m_IDirectInputEffect((IDirectInputEffect*)*ppdeff);
pEffect->SetVersion(diVersion);

*ppdeff = DIEffect;
*ppdeff = pEffect;
}
else
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") Failed! hr: " << (DIERR)hr;

m_IDirectInputEffect* pEffect = new m_IDirectInputEffect(nullptr);
effects.push_back(pEffect);

// Return an effect class even on failure becasue some games don't check for failure
*ppdeff = pEffect;
}

return hr;
Expand Down
8 changes: 8 additions & 0 deletions IDirectInputDeviceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class m_IDirectInputDeviceX : public AddressLookupTableDinputObject
void *WrapperInterface2;
void *WrapperInterface7;

// Vector to store instances of m_IDirectInputEffect
std::vector<m_IDirectInputEffect> effects;

// For CooperativeLevel
bool CanAquireDevice = false;

Expand Down Expand Up @@ -155,6 +158,11 @@ class m_IDirectInputDeviceX : public AddressLookupTableDinputObject
((m_IDirectInput7W*)WrapperInterface7)->DeleteMe();
}

for (auto& entry : effects)
{
entry.DeleteMe();
}

// Delete Critical Section
DeleteCriticalSection(&dics);
}
Expand Down
83 changes: 83 additions & 0 deletions IDirectInputEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,54 @@ HRESULT m_IDirectInputEffect::QueryInterface(REFIID riid, LPVOID * ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
if (!ppvObj)
{
return E_POINTER;
}
*ppvObj = nullptr;

if (riid == WrapperID || riid == IID_IUnknown)
{
*ppvObj = this;

AddRef();

return DI_OK;
}
return E_POINTER;
}

return ProxyQueryInterface(ProxyInterface, riid, ppvObj, WrapperID, WrapperInterface);
}

ULONG m_IDirectInputEffect::AddRef()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return InterlockedIncrement(&Ref);
}

return ProxyInterface->AddRef();
}

ULONG m_IDirectInputEffect::Release()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
if (InterlockedCompareExchange(&Ref, 0, 0) == 0)
{
return 0;
}

return InterlockedDecrement(&Ref);
}

ULONG ref = ProxyInterface->Release();

if (ref == 0)
Expand All @@ -48,6 +82,11 @@ HRESULT m_IDirectInputEffect::Initialize(HINSTANCE hinst, DWORD dwVersion, REFGU
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_INCOMPLETEEFFECT;
}

HRESULT hr = hresValidInstanceAndVersion(hinst, dwVersion);
if (SUCCEEDED(hr))
{
Expand All @@ -66,13 +105,23 @@ HRESULT m_IDirectInputEffect::GetEffectGuid(LPGUID pguid)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

return ProxyInterface->GetEffectGuid(pguid);
}

HRESULT m_IDirectInputEffect::GetParameters(LPDIEFFECT lpeff, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

if (!lpeff || !lpeff->dwSize)
{
return DIERR_INVALIDPARAM;
Expand All @@ -95,6 +144,11 @@ HRESULT m_IDirectInputEffect::SetParameters(LPCDIEFFECT lpeff, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") Trying! " << Logging::hex(dwFlags);

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

#ifdef _DEBUG
GUID guid;
GetEffectGuid(&guid);
Expand Down Expand Up @@ -123,6 +177,10 @@ HRESULT m_IDirectInputEffect::Start(DWORD dwIterations, DWORD dwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") Trying! " << dwIterations << " " << Logging::hex(dwFlags);

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

HRESULT hr = ProxyInterface->Start(dwIterations, dwFlags);

Expand All @@ -138,33 +196,58 @@ HRESULT m_IDirectInputEffect::Stop()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

return ProxyInterface->Stop();
}

HRESULT m_IDirectInputEffect::GetEffectStatus(LPDWORD pdwFlags)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

return ProxyInterface->GetEffectStatus(pdwFlags);
}

HRESULT m_IDirectInputEffect::Download()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

return ProxyInterface->Download();
}

HRESULT m_IDirectInputEffect::Unload()
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

return ProxyInterface->Unload();
}

HRESULT m_IDirectInputEffect::Escape(LPDIEFFESCAPE pesc)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterface)
{
return DIERR_NOTINITIALIZED;
}

return ProxyInterface->Escape(pesc);
}
1 change: 1 addition & 0 deletions IDirectInputEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class m_IDirectInputEffect : public IDirectInputEffect, public AddressLookupTabl
IDirectInputEffect *ProxyInterface;
m_IDirectInputEffect *WrapperInterface;
REFIID WrapperID = IID_IDirectInputEffect;
ULONG Ref = 1;

// Requested DirectInput version - used to alter behaviour by requested version
DWORD diVersion = 0;
Expand Down

0 comments on commit 9235e08

Please sign in to comment.