Skip to content

Commit

Permalink
Create extra buffer for device data
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jun 24, 2024
1 parent c576256 commit 954949d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 69
#define BUILD_NUMBER 70
25 changes: 14 additions & 11 deletions IDirectInputDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,21 @@ HRESULT m_IDirectInputDeviceX::GetDeviceData(DWORD cbObjectData, LPDIDEVICEOBJEC
// Check the size of the array
if (*pdwInOut > pdod.size())
{
pdod.resize(*pdwInOut);

Logging::LogDebug() << __FUNCTION__ << " Update dod memory! " << *pdwInOut;
pdod.resize((*pdwInOut / 100 + 1) * 100); // Increase buffer by factors of 100
}

HRESULT hr = ProxyInterface->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), &pdod[0], pdwInOut, dwFlags);

// Copy array
if (SUCCEEDED(hr))
{
for (UINT x = 0; x < *pdwInOut; x++)
if (cbObjectData == sizeof(DIDEVICEOBJECTDATA_DX3))
{
CopyDeviceData((DIDEVICEOBJECTDATA_DX3*)rgdod, pdod.data(), *pdwInOut);
}
else
{
CopyMemory((void*)((DWORD)rgdod + (cbObjectData * x)), &pdod[x], cbObjectData);
CopyDeviceData((DIDEVICEOBJECTDATA*)rgdod, pdod.data(), *pdwInOut);
}
}

Expand Down Expand Up @@ -814,16 +816,17 @@ HRESULT m_IDirectInputDeviceX::SendDeviceData(DWORD cbObjectData, LPCDIDEVICEOBJ
// Check the size of the array
if (*pdwInOut > pdod.size())
{
pdod.resize(*pdwInOut);

Logging::LogDebug() << __FUNCTION__ << " Update dod memory! " << *pdwInOut;
pdod.resize((*pdwInOut / 100 + 1) * 100); // Increase buffer by factors of 100
}

// Copy array
ZeroMemory(&pdod[0], sizeof(DIDEVICEOBJECTDATA) * pdod.size());
for (UINT x = 0; x < *pdwInOut; x++)
if (cbObjectData == sizeof(DIDEVICEOBJECTDATA_DX3))
{
CopyDeviceData(pdod.data(), (DIDEVICEOBJECTDATA_DX3*)rgdod, *pdwInOut);
}
else
{
CopyMemory(&pdod[x], (void*)((DWORD)rgdod + (cbObjectData * x)), cbObjectData);
CopyDeviceData(pdod.data(), (DIDEVICEOBJECTDATA*)rgdod, *pdwInOut);
}

HRESULT hr = ProxyInterface->SendDeviceData(sizeof(DIDEVICEOBJECTDATA), &pdod[0], pdwInOut, fl);
Expand Down
21 changes: 21 additions & 0 deletions IDirectInputDeviceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ class m_IDirectInputDeviceX : public AddressLookupTableDinputObject
void InitializeEnumObjectData();
void SetEnumObjectDataFromFormat(LPCDIDATAFORMAT lpdf);

template <class T>
inline void CopyDeviceData(T* DestDod, DIDEVICEOBJECTDATA* SrcDod, DWORD dwNumRecords)
{
for (UINT x = 0; x < dwNumRecords; x++)
{
*DestDod = *(T*)SrcDod;
SrcDod = (DIDEVICEOBJECTDATA*)((DWORD)SrcDod + sizeof(DIDEVICEOBJECTDATA));
DestDod = (T*)((DWORD)DestDod + sizeof(T));
}
}
inline void CopyDeviceData(DIDEVICEOBJECTDATA* DestDod, DIDEVICEOBJECTDATA_DX3* SrcDod, DWORD dwNumRecords)
{
for (UINT x = 0; x < dwNumRecords; x++)
{
*(DIDEVICEOBJECTDATA_DX3*)DestDod = *SrcDod;
DestDod->uAppData = NULL;
SrcDod = (DIDEVICEOBJECTDATA_DX3*)((DWORD)SrcDod + sizeof(DIDEVICEOBJECTDATA_DX3));
DestDod = (DIDEVICEOBJECTDATA*)((DWORD)DestDod + sizeof(DIDEVICEOBJECTDATA));
}
}

// Wrapper interface functions
inline REFIID GetWrapperType(DWORD DirectXVersion)
{
Expand Down

0 comments on commit 954949d

Please sign in to comment.