diff --git a/Common/Logger.h b/Common/Logger.h index eec5e88..051ebd5 100644 --- a/Common/Logger.h +++ b/Common/Logger.h @@ -6,14 +6,16 @@ #include #include -#include "NonCopyable.h" #include "StringUtil.h" #include "WinUtil.h" #ifndef LOGGER_DISABLE -class Logger : NonCopyable +class Logger { public: + Logger(const Logger&) = delete; + const Logger& operator=(Logger& other) = delete; + Logger() : m_systime(), m_console(INVALID_HANDLE_VALUE), m_file(INVALID_HANDLE_VALUE) {} Logger::~Logger() diff --git a/Common/NonCopyable.h b/Common/NonCopyable.h deleted file mode 100644 index c982f70..0000000 --- a/Common/NonCopyable.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -// An inheritable class to disallow the copy constructor and operator= functions -class NonCopyable -{ -protected: - NonCopyable() {} - ~NonCopyable() {} -private: - NonCopyable( const NonCopyable& ); - const NonCopyable& operator=( NonCopyable& other ); -}; diff --git a/MinHook/build/VC15/libMinHook.vcxproj b/MinHook/build/VC15/libMinHook.vcxproj index 064a357..e4e953f 100644 --- a/MinHook/build/VC15/libMinHook.vcxproj +++ b/MinHook/build/VC15/libMinHook.vcxproj @@ -22,30 +22,30 @@ {F142A341-5EE0-442D-A15F-98AE9B48DBAE} libMinHook Win32Proj - 10.0.16299.0 + 10.0 StaticLibrary Unicode true - v141 + v142 StaticLibrary Unicode - v141 + v142 StaticLibrary Unicode true - v141 + v142 StaticLibrary Unicode - v141 + v142 @@ -83,12 +83,8 @@ Disabled %(AdditionalIncludeDirectories) WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) - false - EnableFastChecks - MultiThreadedDebug Level3 None - NoExtensions @@ -122,6 +118,7 @@ AnySuitable CompileAsC true + MultiThreaded diff --git a/d3d9ex.sln b/d3d9ex.sln index a61343b..df545f5 100644 --- a/d3d9ex.sln +++ b/d3d9ex.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2036 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29215.179 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OneTweakNG", "d3d9ex\d3d9ex.vcxproj", "{6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}" EndProject @@ -9,7 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5DB3A8 ProjectSection(SolutionItems) = preProject Common\Defines.h = Common\Defines.h Common\Logger.h = Common\Logger.h - Common\NonCopyable.h = Common\NonCopyable.h Common\SimpleIni.h = Common\SimpleIni.h Common\StringUtil.h = Common\StringUtil.h Common\Timer.h = Common\Timer.h @@ -30,7 +29,8 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Debug|Win32.ActiveCfg = Debug|Win32 {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Debug|Win32.Build.0 = Debug|Win32 - {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Debug|x64.ActiveCfg = Debug|Win32 + {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Debug|x64.ActiveCfg = Debug|x64 + {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Debug|x64.Build.0 = Debug|x64 {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Release|Win32.ActiveCfg = Release|Win32 {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Release|Win32.Build.0 = Release|Win32 {6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}.Release|x64.ActiveCfg = Release|x64 diff --git a/d3d9ex/AutoFix.cpp b/d3d9ex/AutoFix.cpp index bb96f3c..80c2d4c 100644 --- a/d3d9ex/AutoFix.cpp +++ b/d3d9ex/AutoFix.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "Context.h" +#include "IDirect3DVertexBuffer9.h" void MainContext::EnableAutoFix() { @@ -65,15 +66,26 @@ bool MainContext::ApplyBehaviorFlagsFix(DWORD* flags) return false; } -bool MainContext::ApplyVertexBufferFix(UINT& Length, DWORD& Usage, DWORD& FVF, D3DPOOL& Pool) +HRESULT APIENTRY MainContext::ApplyVertexBufferFix(IDirect3DDevice9 *pIDirect3DDevice9, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) { - if (autofix == AutoFixes::NONE) return false; + if (autofix == AutoFixes::NONE) return pIDirect3DDevice9->CreateVertexBuffer(Length,Usage,FVF,Pool,ppVertexBuffer,pSharedHandle); // Final Fantasy XIII if (autofix == FINAL_FANTASY_XIII) { - if (Length == 358400 && FVF == 0 && Pool == D3DPOOL_MANAGED) { Usage = D3DUSAGE_DYNAMIC; Pool = D3DPOOL_SYSTEMMEM; } - return true; + if (Length == 358400 && FVF == 0 && Pool == D3DPOOL_MANAGED) { + Usage = D3DUSAGE_DYNAMIC; Pool = D3DPOOL_SYSTEMMEM; + + //IDirect3DVertexBuffer9* buffer = nullptr; + //HRESULT hr = pIDirect3DDevice9->CreateVertexBuffer(Length, Usage, FVF, Pool, &buffer, NULL); + //if (FAILED(hr)) + //{ + // return pIDirect3DDevice9->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); + //} + + //if(ppVertexBuffer) *ppVertexBuffer = new hkIDirect3DVertexBuffer9(pIDirect3DDevice9, buffer); + //return hr; + } } - return false; + return pIDirect3DDevice9->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); } \ No newline at end of file diff --git a/d3d9ex/Context.cpp b/d3d9ex/Context.cpp index 218bdff..039c554 100644 --- a/d3d9ex/Context.cpp +++ b/d3d9ex/Context.cpp @@ -37,7 +37,7 @@ Config::Config() #undef SETTING } -MainContext::MainContext() +MainContext::MainContext() : oldWndProc(nullptr) { LogFile("OneTweakNG.log"); @@ -170,7 +170,7 @@ bool MainContext::CheckWindow(HWND hWnd) void MainContext::ApplyWndProc(HWND hWnd) { - if (config.GetAlwaysActive()) + if (config.GetAlwaysActive() || config.GetHideCursor()) { context.oldWndProc = (WNDPROC)context.TrueSetWindowLongA(hWnd, GWLP_WNDPROC, (LONG_PTR)context.WindowProc); } @@ -218,7 +218,8 @@ LRESULT CALLBACK MainContext::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP if (context.config.GetAlwaysActive()) return TRUE; - while (::ShowCursor(TRUE) < 0); + if (!context.config.GetForceHideCursor()) + while (::ShowCursor(TRUE) < 0); break; } @@ -227,6 +228,10 @@ LRESULT CALLBACK MainContext::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP return TRUE; } + + if (context.config.GetForceHideCursor()) + while (::ShowCursor(FALSE) >= 0); + return CallWindowProc(context.oldWndProc, hWnd, uMsg, wParam, lParam); } diff --git a/d3d9ex/Context.h b/d3d9ex/Context.h index 464efea..42965b9 100644 --- a/d3d9ex/Context.h +++ b/d3d9ex/Context.h @@ -10,9 +10,12 @@ struct hkIDirect3D9; static const char* inifilename = "OneTweakNG.ini"; #define CONFIG_VERSION 3 -class Config : NonCopyable +class Config { public: + Config(const Config&) = delete; + const Config& operator=(Config& other) = delete; + Config(); #define SETTING(_type, _func, _var, _section, _defaultval) \ @@ -26,8 +29,11 @@ public: public: type(callconv* True##name)(__VA_ARGS__); \ private: static type callconv Hook##name(__VA_ARGS__); -class MainContext : NonCopyable +class MainContext { + MainContext(const MainContext&) = delete; + const MainContext& operator=(MainContext& other) = delete; + DECLARE_HOOK(IDirect3D9*, WINAPI, Direct3DCreate9, UINT SDKVersion); DECLARE_HOOK(LONG, WINAPI, SetWindowLongA, HWND hWnd, int nIndex, LONG dwNewLong); DECLARE_HOOK(LONG, WINAPI, SetWindowLongW, HWND hWnd, int nIndex, LONG dwNewLong); @@ -42,7 +48,7 @@ public: bool ApplyPresentationParameters(D3DPRESENT_PARAMETERS* pPresentationParameters); bool ApplyBehaviorFlagsFix(DWORD* flags); - bool ApplyVertexBufferFix(UINT& Length, DWORD& Usage, DWORD& FVF, D3DPOOL& Pool); + HRESULT APIENTRY ApplyVertexBufferFix(IDirect3DDevice9* pIDirect3DDevice9, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle); bool BehaviorFlagsToString(DWORD BehaviorFlags, std::string* BehaviorFlagsString); bool CheckWindow(HWND hWnd); diff --git a/d3d9ex/IDirect3D9.cpp b/d3d9ex/IDirect3D9.cpp index f04e21a..75e90ab 100644 --- a/d3d9ex/IDirect3D9.cpp +++ b/d3d9ex/IDirect3D9.cpp @@ -9,31 +9,35 @@ #define IDirect3D9_PrintLog(format, ...) //PrintLog(format, __VA_ARGS__); -hkIDirect3D9::hkIDirect3D9(IDirect3D9 *pIDirect3D9) { - PrintLog(__FUNCTION__); - m_pWrapped = pIDirect3D9; -} - -hkIDirect3D9::~hkIDirect3D9() -{ - PrintLog(__FUNCTION__); -} - HRESULT APIENTRY hkIDirect3D9::QueryInterface(REFIID riid, void** ppvObj) { PrintLog(__FUNCTION__); - return m_pWrapped->QueryInterface(riid, ppvObj); + if (ppvObj == nullptr) return E_POINTER; + + if (riid == __uuidof(IUnknown) || + riid == __uuidof(IDirect3D9)) + { + *ppvObj = static_cast(this); + AddRef(); + return S_OK; + } + + *ppvObj = nullptr; + return E_NOINTERFACE; } ULONG APIENTRY hkIDirect3D9::AddRef() { PrintLog(__FUNCTION__); - return m_pWrapped->AddRef(); + return _InterlockedIncrement(&m_refCount); } ULONG APIENTRY hkIDirect3D9::Release() { - ULONG ref_count = m_pWrapped->Release(); - PrintLog(__FUNCTION__ " return = %lu", ref_count); - if (ref_count == 0) delete this; - return ref_count; + PrintLog(__FUNCTION__); + const LONG ref = _InterlockedDecrement(&m_refCount); + if (ref == 0) + { + delete this; + } + return ref; } HRESULT APIENTRY hkIDirect3D9::RegisterSoftwareDevice(void* pInitializeFunction) { @@ -131,18 +135,22 @@ HRESULT APIENTRY hkIDirect3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, if (hFocusWindow == NULL) hFocusWindow = pPresentationParameters->hDeviceWindow; context.ApplyPresentationParameters(pPresentationParameters); - HRESULT hr = m_pWrapped->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); - if (SUCCEEDED(hr) && ppReturnedDeviceInterface && *ppReturnedDeviceInterface) - { - hkIDirect3DDevice9* pIDirect3DDevice9 = new hkIDirect3DDevice9(*ppReturnedDeviceInterface); - *ppReturnedDeviceInterface = pIDirect3DDevice9; - } - if (OriginalBehaviorFlags != BehaviorFlags) { std::string BehaviorFlagsString; context.BehaviorFlagsToString(BehaviorFlags, &BehaviorFlagsString); PrintLog("BehaviorFlags changed: %08X %s", BehaviorFlags, BehaviorFlagsString.c_str()); } + + IDirect3DDevice9* device = nullptr; + HRESULT hr = m_pWrapped->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, &device); + if (FAILED(hr)) + { + PrintLog("CreateDevice fail with HRESULT: %08X", hr); + *ppReturnedDeviceInterface = nullptr; + return hr; + } + + *ppReturnedDeviceInterface = new hkIDirect3DDevice9(device); return hr; } diff --git a/d3d9ex/IDirect3D9.h b/d3d9ex/IDirect3D9.h index e115a17..66c9f60 100644 --- a/d3d9ex/IDirect3D9.h +++ b/d3d9ex/IDirect3D9.h @@ -4,13 +4,8 @@ #include "d3d9.h" #include "IDirect3DDevice9.h" -interface hkIDirect3D9 : public IDirect3D9 { - IDirect3D9* m_pWrapped; - +interface hkIDirect3D9 final : public IDirect3D9 { public: - hkIDirect3D9(IDirect3D9 *pIDirect3D9); - ~hkIDirect3D9(); - // original interface STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj); STDMETHOD_(ULONG, AddRef)(); @@ -29,5 +24,21 @@ public: STDMETHOD(GetDeviceCaps)(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps); STDMETHOD_(HMONITOR, GetAdapterMonitor)(UINT Adapter); STDMETHOD(CreateDevice)(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface); + +public: + hkIDirect3D9(IDirect3D9 *pIDirect3D9) + : m_pWrapped(pIDirect3D9) + { + } + +private: + ~hkIDirect3D9() + { + m_pWrapped->Release(); + } + + LONG m_refCount = 1; + IDirect3D9 *m_pWrapped; }; + diff --git a/d3d9ex/IDirect3DDevice9.cpp b/d3d9ex/IDirect3DDevice9.cpp index 5e78c17..e13c993 100644 --- a/d3d9ex/IDirect3DDevice9.cpp +++ b/d3d9ex/IDirect3DDevice9.cpp @@ -11,31 +11,34 @@ #define IDirect3DDevice9_PrintLog(...) //PrintLog(format, __VA_ARGS__); -hkIDirect3DDevice9::hkIDirect3DDevice9(IDirect3DDevice9 *pIDirect3DDevice9) { - PrintLog(__FUNCTION__); - m_pWrapped = pIDirect3DDevice9; -} - -hkIDirect3DDevice9::~hkIDirect3DDevice9() -{ - PrintLog(__FUNCTION__); -} - HRESULT APIENTRY hkIDirect3DDevice9::QueryInterface(REFIID riid, void** ppvObj) { IDirect3DDevice9_PrintLog(__FUNCTION__); - return m_pWrapped->QueryInterface(riid, ppvObj); + if (ppvObj == nullptr) return E_POINTER; + + if (riid == __uuidof(IUnknown) || + riid == __uuidof(IDirect3DDevice9)) + { + *ppvObj = static_cast(this); + AddRef(); + return S_OK; + } + + *ppvObj = nullptr; + return E_NOINTERFACE; } ULONG APIENTRY hkIDirect3DDevice9::AddRef() { IDirect3DDevice9_PrintLog(__FUNCTION__); - return m_pWrapped->AddRef(); + return _InterlockedIncrement(&m_refCount); } ULONG APIENTRY hkIDirect3DDevice9::Release() { - ULONG ref_count = m_pWrapped->Release(); - PrintLog(__FUNCTION__ " return = %lu", ref_count); - if (ref_count == 0) delete this; - return ref_count; + const LONG ref = _InterlockedDecrement(&m_refCount); + if (ref == 0) + { + delete this; + } + return ref; } HRESULT APIENTRY hkIDirect3DDevice9::TestCooperativeLevel() { @@ -178,8 +181,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::CreateCubeTexture(UINT EdgeLength, UINT Lev HRESULT APIENTRY hkIDirect3DDevice9::CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) { //PrintLog("hkIDirect3DDevice9::CreateVertexBuffer %08u %x %x %x %p %p", Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); - context.ApplyVertexBufferFix(Length, Usage, FVF, Pool); - return m_pWrapped->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); + return context.ApplyVertexBufferFix(m_pWrapped, Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); } HRESULT APIENTRY hkIDirect3DDevice9::CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) { diff --git a/d3d9ex/IDirect3DDevice9.h b/d3d9ex/IDirect3DDevice9.h index e8dfbe0..86cc02a 100644 --- a/d3d9ex/IDirect3DDevice9.h +++ b/d3d9ex/IDirect3DDevice9.h @@ -4,13 +4,8 @@ #pragma once #include "d3d9.h" -interface hkIDirect3DDevice9 : public IDirect3DDevice9 { - IDirect3DDevice9* m_pWrapped; - +interface hkIDirect3DDevice9 final : public IDirect3DDevice9 { public: - hkIDirect3DDevice9(IDirect3DDevice9 *pIDirect3DDevice9); - ~hkIDirect3DDevice9(); - // original interface STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj); STDMETHOD_(ULONG, AddRef)(); @@ -131,5 +126,20 @@ public: STDMETHOD(DrawTriPatch)(UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo); STDMETHOD(DeletePatch)(UINT Handle); STDMETHOD(CreateQuery)(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery); + + public: + hkIDirect3DDevice9(IDirect3DDevice9 *pIDirect3DDevice9) + : m_pWrapped(pIDirect3DDevice9) + { + } + +private: + ~hkIDirect3DDevice9() + { + m_pWrapped->Release(); + } + + LONG m_refCount = 1; + IDirect3DDevice9* m_pWrapped; }; diff --git a/d3d9ex/IDirect3DVertexBuffer9.cpp b/d3d9ex/IDirect3DVertexBuffer9.cpp new file mode 100644 index 0000000..b7c34f9 --- /dev/null +++ b/d3d9ex/IDirect3DVertexBuffer9.cpp @@ -0,0 +1,102 @@ +// wrapper for IDirect3DVertexBuffer9 in d3d9.h +// generated using wrapper_gen.rb + +#include "stdafx.h" +#include "Context.h" + +#include "IDirect3D9.h" +#include "IDirect3DDevice9.h" +#include "IDirect3DVertexBuffer9.h" + +#define IDirect3DVertexBuffer9_PrintLog(format, ...) //PrintLog(format, __VA_ARGS__); + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::QueryInterface(REFIID riid, void** ppvObj) { + if (ppvObj == nullptr) return E_POINTER; + + if (riid == __uuidof(IUnknown) || + riid == __uuidof(IDirect3DResource9) || + riid == __uuidof(IDirect3DVertexBuffer9)) + { + *ppvObj = static_cast(this); + AddRef(); + return S_OK; + } + + *ppvObj = nullptr; + return E_NOINTERFACE; +} + +ULONG APIENTRY hkIDirect3DVertexBuffer9::AddRef() { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return _InterlockedIncrement(&m_refCount); +} + +ULONG APIENTRY hkIDirect3DVertexBuffer9::Release() { + const LONG ref = _InterlockedDecrement(&m_refCount); + if (ref == 0) + { + delete this; + } + return ref; +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::GetDevice(IDirect3DDevice9** ppDevice) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + + if (ppDevice == nullptr) + return D3DERR_INVALIDCALL; + + m_pIDirect3DDevice9->AddRef(); + *ppDevice = m_pIDirect3DDevice9; + return D3D_OK; +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::SetPrivateData(REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->SetPrivateData(refguid, pData, SizeOfData, Flags); +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->GetPrivateData(refguid, pData, pSizeOfData); +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::FreePrivateData(REFGUID refguid) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->FreePrivateData(refguid); +} + +DWORD APIENTRY hkIDirect3DVertexBuffer9::SetPriority(DWORD PriorityNew) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->SetPriority(PriorityNew); +} + +DWORD APIENTRY hkIDirect3DVertexBuffer9::GetPriority() { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->GetPriority(); +} + +void APIENTRY hkIDirect3DVertexBuffer9::PreLoad() { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->PreLoad(); +} + +D3DRESOURCETYPE APIENTRY hkIDirect3DVertexBuffer9::GetType() { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->GetType(); +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::Lock(UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->Lock(OffsetToLock, SizeToLock, ppbData, Flags); +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::Unlock() { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->Unlock(); +} + +HRESULT APIENTRY hkIDirect3DVertexBuffer9::GetDesc(D3DVERTEXBUFFER_DESC *pDesc) { + IDirect3DVertexBuffer9_PrintLog(__FUNCTION__); + return m_pWrapped->GetDesc(pDesc); +} diff --git a/d3d9ex/IDirect3DVertexBuffer9.h b/d3d9ex/IDirect3DVertexBuffer9.h new file mode 100644 index 0000000..03e16d2 --- /dev/null +++ b/d3d9ex/IDirect3DVertexBuffer9.h @@ -0,0 +1,40 @@ +// wrapper for IDirect3DVertexBuffer9 in d3d9.h +// generated using wrapper_gen.rb + +#pragma once +#include "d3d9.h" + +interface hkIDirect3DVertexBuffer9 final : public IDirect3DVertexBuffer9 { +public: + // original interface + STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj); + STDMETHOD_(ULONG, AddRef)(); + STDMETHOD_(ULONG, Release)(); + STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice); + STDMETHOD(SetPrivateData)(REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); + STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData); + STDMETHOD(FreePrivateData)(REFGUID refguid); + STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew); + STDMETHOD_(DWORD, GetPriority)(); + STDMETHOD_(void, PreLoad)(); + STDMETHOD_(D3DRESOURCETYPE, GetType)(); + STDMETHOD(Lock)(UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags); + STDMETHOD(Unlock)(); + STDMETHOD(GetDesc)(D3DVERTEXBUFFER_DESC *pDesc); + +public: + hkIDirect3DVertexBuffer9(IDirect3DDevice9* pIDirect3DDevice9, IDirect3DVertexBuffer9* pIDirect3DVertexBuffer9) + : m_pWrapped(pIDirect3DVertexBuffer9), m_pIDirect3DDevice9(pIDirect3DDevice9) + {} + +private: + ~hkIDirect3DVertexBuffer9() + { + m_pWrapped->Release(); + } + + LONG m_refCount = 1; + IDirect3DVertexBuffer9 *m_pWrapped; + IDirect3DDevice9* m_pIDirect3DDevice9; +}; + diff --git a/d3d9ex/Settings.h b/d3d9ex/Settings.h index f41037a..b30bbbb 100644 --- a/d3d9ex/Settings.h +++ b/d3d9ex/Settings.h @@ -5,6 +5,7 @@ SETTING(bool, BoolValue, AlwaysActive, Options, false); SETTING(bool, BoolValue, AutoFix, Options, true); SETTING(u32, LongValue, Multisample, Options, 0); SETTING(bool, BoolValue, HideCursor, Options, false); +SETTING(bool, BoolValue, ForceHideCursor, Options, false); SETTING(u32, LongValue, BehaviorFlags, Options, 0); SETTING(bool, BoolValue, Adapter, Adapter, false); diff --git a/d3d9ex/Wrapper.h b/d3d9ex/Wrapper.h index bcad082..cba6379 100644 --- a/d3d9ex/Wrapper.h +++ b/d3d9ex/Wrapper.h @@ -4,12 +4,16 @@ #include "d3d9.h" #include "dinput.h" +#include "xinput.h" template -class WrapperBase : NonCopyable +class WrapperBase { public: - WrapperBase() {} + WrapperBase(const WrapperBase&) = delete; + const WrapperBase& operator=(WrapperBase& other) = delete; + + WrapperBase(): m_module(nullptr) {} ~WrapperBase() { @@ -161,3 +165,96 @@ extern "C" return DINPUT8DLL::Get().DirectInput8Create(hinst, dwVersion, riidltf, ppvOut, punkOuter); } } + +class XINPUTDLL : public WrapperBase +{ +public: + + // XInput 1.3 and older functions + DWORD(WINAPI* XInputGetState)(DWORD dwUserIndex, XINPUT_STATE* pState); + DWORD(WINAPI* XInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration); + DWORD(WINAPI* XInputGetCapabilities)(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); + VOID(WINAPI* XInputEnable)(BOOL enable); + DWORD(WINAPI* XInputGetDSoundAudioDeviceGuids)(DWORD dwUserIndex, GUID* pDSoundRenderGuid, GUID* pDSoundCaptureGuid); + DWORD(WINAPI* XInputGetBatteryInformation)(DWORD dwUserIndex, BYTE devType, XINPUT_BATTERY_INFORMATION* pBatteryInformation); + DWORD(WINAPI* XInputGetKeystroke)(DWORD dwUserIndex, DWORD dwReserved, PXINPUT_KEYSTROKE pKeystroke); + + // XInput 1.3 undocumented functions + DWORD(WINAPI* XInputGetStateEx)(DWORD dwUserIndex, XINPUT_STATE *pState); // 100 + DWORD(WINAPI* XInputWaitForGuideButton)(DWORD dwUserIndex, DWORD dwFlag, LPVOID pVoid); // 101 + DWORD(WINAPI* XInputCancelGuideButtonWait)(DWORD dwUserIndex); // 102 + DWORD(WINAPI* XInputPowerOffController)(DWORD dwUserIndex); // 103 + + // XInput 1.4 functions + DWORD(WINAPI* XInputGetAudioDeviceIds)(DWORD dwUserIndex, LPWSTR pRenderDeviceId, UINT* pRenderCount, LPWSTR pCaptureDeviceId, UINT* pCaptureCount); + + // XInput 1.4 undocumented functionss + DWORD(WINAPI* XInputGetBaseBusInformation)(DWORD dwUserIndex, struct XINPUT_BUSINFO* pBusinfo); // 104 + DWORD(WINAPI* XInputGetCapabilitiesEx)(DWORD unk1, DWORD dwUserIndex, DWORD dwFlags, struct XINPUT_CAPABILITIESEX* pCapabilitiesEx); // 108 + + XINPUTDLL() + { + WrapperLoad("xinput1_3.dll"); + + // XInput 1.3 and older functions + StoreAddress(&XInputGetState, "XInputGetState"); + StoreAddress(&XInputSetState, "XInputSetState"); + StoreAddress(&XInputGetCapabilities, "XInputGetCapabilities"); + StoreAddress(&XInputEnable, "XInputEnable"); + StoreAddress(&XInputGetDSoundAudioDeviceGuids, "XInputGetDSoundAudioDeviceGuids"); + StoreAddress(&XInputGetBatteryInformation, "XInputGetBatteryInformation"); + StoreAddress(&XInputGetKeystroke, "XInputGetKeystroke"); + + // XInput 1.3 undocumented functions + StoreAddress(&XInputGetStateEx, (const char*)100); + StoreAddress(&XInputWaitForGuideButton, (const char*)101); + StoreAddress(&XInputCancelGuideButtonWait, (const char*)102); + StoreAddress(&XInputPowerOffController, (const char*)103); + + // XInput 1.4 functions + StoreAddress(&XInputGetAudioDeviceIds, "XInputGetAudioDeviceIds"); + + // XInput 1.4 undocumented functionss + StoreAddress(&XInputGetBaseBusInformation, (const char*)104); + StoreAddress(&XInputGetCapabilitiesEx, (const char*)108); + } +}; + +extern "C" +{ + // XInput 1.3 and older functions + DWORD WINAPI _XInputGetState(DWORD dwUserIndex, XINPUT_STATE* pState) + { + return XINPUTDLL::Get().XInputGetState(dwUserIndex, pState); + } + + DWORD WINAPI _XInputSetState(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration) + { + return XINPUTDLL::Get().XInputSetState(dwUserIndex, pVibration); + } + + DWORD WINAPI _XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities) + { + return XINPUTDLL::Get().XInputGetCapabilities(dwUserIndex, dwFlags, pCapabilities); + } + + VOID WINAPI _XInputEnable(BOOL enable) + { + return XINPUTDLL::Get().XInputEnable(enable); + } + + DWORD WINAPI _XInputGetDSoundAudioDeviceGuids(DWORD dwUserIndex, GUID* pDSoundRenderGuid, GUID* pDSoundCaptureGuid) + { + return XINPUTDLL::Get().XInputGetDSoundAudioDeviceGuids(dwUserIndex, pDSoundRenderGuid, pDSoundCaptureGuid); + } + + DWORD WINAPI _XInputGetBatteryInformation(DWORD dwUserIndex, BYTE devType, XINPUT_BATTERY_INFORMATION* pBatteryInformation) + { + return XINPUTDLL::Get().XInputGetBatteryInformation(dwUserIndex, devType, pBatteryInformation); + } + + DWORD WINAPI _XInputGetKeystroke(DWORD dwUserIndex, DWORD dwReserved, PXINPUT_KEYSTROKE pKeystroke) + { + return XINPUTDLL::Get().XInputGetKeystroke(dwUserIndex, dwReserved, pKeystroke); + } +} diff --git a/d3d9ex/d3d9ex.vcxproj b/d3d9ex/d3d9ex.vcxproj index 48488e1..ca2cc31 100644 --- a/d3d9ex/d3d9ex.vcxproj +++ b/d3d9ex/d3d9ex.vcxproj @@ -23,19 +23,19 @@ Win32Proj d3d9ex OneTweakNG - 10.0.16299.0 + 10.0 DynamicLibrary true - v141 + v142 Unicode DynamicLibrary true - v141 + v142 Unicode @@ -44,7 +44,7 @@ true MultiByte true - v141 + v142 DynamicLibrary @@ -52,7 +52,7 @@ true MultiByte true - v141 + v142 @@ -72,8 +72,8 @@ true - d3d9 - $(SolutionDir)\Common;$(SolutionDir)\MinHook\include;$(IncludePath) + dinput8 + $(SolutionDir)\Common;$(SolutionDir)\MinHook\include;$(DXSDK_DIR)\Include;$(IncludePath) true @@ -83,12 +83,12 @@ false dinput8 - $(SolutionDir)\Common;$(SolutionDir)\MinHook\include;$(IncludePath) + $(SolutionDir)\Common;$(SolutionDir)\MinHook\include;$(DXSDK_DIR)\Include;$(IncludePath) false dinput8 - $(SolutionDir)\Common;$(SolutionDir)\MinHook\include;$(IncludePath) + $(SolutionDir)\Common;$(SolutionDir)\MinHook\include;$(DXSDK_DIR)\Include;$(IncludePath) @@ -129,6 +129,7 @@ true MaxSpeed true + MultiThreaded Windows @@ -163,6 +164,7 @@ + @@ -189,6 +191,7 @@ + Create Create diff --git a/d3d9ex/d3d9ex.vcxproj.filters b/d3d9ex/d3d9ex.vcxproj.filters index 7dc38cd..0fb9bd9 100644 --- a/d3d9ex/d3d9ex.vcxproj.filters +++ b/d3d9ex/d3d9ex.vcxproj.filters @@ -39,6 +39,9 @@ Header Files + + Header Files + @@ -59,6 +62,9 @@ Source Files + + Source Files + diff --git a/d3d9ex/exports.def b/d3d9ex/exports.def index 71076b9..0b170ae 100644 --- a/d3d9ex/exports.def +++ b/d3d9ex/exports.def @@ -13,3 +13,10 @@ D3DPERF_SetRegion=_D3DPERF_SetRegion @26 DirectInput8Create=_DirectInput8Create +XInputGetState=_XInputGetState @2 +XInputSetState=_XInputSetState @3 +XInputGetCapabilities=_XInputGetCapabilities @4 +XInputEnable=_XInputEnable @5 +XInputGetDSoundAudioDeviceGuids=_XInputGetDSoundAudioDeviceGuids @6 +XInputGetBatteryInformation=_XInputGetBatteryInformation @7 +XInputGetKeystroke=_XInputGetKeystroke @8