From 8ef3b2ec5cd6a2c29f9e7d090ea0e9d8af8bb166 Mon Sep 17 00:00:00 2001 From: nastys <@> Date: Sat, 8 Feb 2020 17:12:44 +0100 Subject: [PATCH] Fix FirewallAPI error --- appveyor.yml | 19 ++++++++++++++++--- source-code/dependencies/MemoryModule | 1 - .../source/PD-Loader/PD-Loader.vcxproj | 2 +- source-code/source/PD-Loader/dllmain.cpp | 14 +++++++++++++- source-code/source/PD-Loader/framework.h | 14 ++++++++++++++ source-code/source/PD-Loader/x64.def | 8 ++++++++ 6 files changed, 52 insertions(+), 6 deletions(-) delete mode 160000 source-code/dependencies/MemoryModule diff --git a/appveyor.yml b/appveyor.yml index 39f74b3..98d5aa8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,7 +31,7 @@ after_build: - copy %APPVEYOR_BUILD_FOLDER%\source-code\x64\%CONFIGURATION%\dnsapi.dll %TMP%\update\ + copy %APPVEYOR_BUILD_FOLDER%\source-code\x64\%CONFIGURATION%\dinput8.dll %TMP%\update\ copy %APPVEYOR_BUILD_FOLDER%\source-code\x64\%CONFIGURATION%\*.dva %TMP%\update\plugins\ @@ -57,7 +57,7 @@ after_build: copy %APPVEYOR_BUILD_FOLDER%\source-code\data\plugins\pv_equip\sfx.ini %TMP%\update\plugins\pv_equip\ - copy %APPVEYOR_BUILD_FOLDER%\source-code\x64\%CONFIGURATION%\dnsapi.dll %TMP%\full\ + copy %APPVEYOR_BUILD_FOLDER%\source-code\x64\%CONFIGURATION%\dinput8.dll %TMP%\full\ copy %APPVEYOR_BUILD_FOLDER%\source-code\data\patches\custom_freeplay_text_example.p %TMP%\full\patches\ @@ -77,7 +77,7 @@ after_build: copy %APPVEYOR_BUILD_FOLDER%\source-code\data\plugins\*.* %TMP%\full\plugins\ - copy %APPVEYOR_BUILD_FOLDER%\source-code\data\plugins\*.* %TMP%\full\plugins\pv_equip\ + copy %APPVEYOR_BUILD_FOLDER%\source-code\data\plugins\*.* %TMP%\full\plugins\pv_equip\ copy %APPVEYOR_BUILD_FOLDER%\source-code\data\ram\databank\*.dat %TMP%\full\ram\databank\ @@ -90,5 +90,18 @@ after_build: cd %TMP%\update\ 7z a %APPVEYOR_BUILD_FOLDER%\PD-Loader-%CONFIGURATION%-Update-AppVeyor.zip * + + cd %APPVEYOR_BUILD_FOLDER%\source-code\x64\%CONFIGURATION%\ + + ren dinput8.dll dnsapi.dll + + cd %TMP%\full\ + + 7z a %APPVEYOR_BUILD_FOLDER%\PD-Loader-%CONFIGURATION%-AppVeyor-Vista.zip * + + cd %TMP%\update\ + + 7z a %APPVEYOR_BUILD_FOLDER%\PD-Loader-%CONFIGURATION%-Update-AppVeyor-Vista.zip * + artifacts: - path: PD-Loader-*.zip diff --git a/source-code/dependencies/MemoryModule b/source-code/dependencies/MemoryModule deleted file mode 160000 index 5f83e41..0000000 --- a/source-code/dependencies/MemoryModule +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5f83e41c3a3e7c6e8284a5c1afa5a38790809461 diff --git a/source-code/source/PD-Loader/PD-Loader.vcxproj b/source-code/source/PD-Loader/PD-Loader.vcxproj index eeedf55..8d3fdca 100644 --- a/source-code/source/PD-Loader/PD-Loader.vcxproj +++ b/source-code/source/PD-Loader/PD-Loader.vcxproj @@ -52,7 +52,7 @@ false - dnsapi + dinput8 diff --git a/source-code/source/PD-Loader/dllmain.cpp b/source-code/source/PD-Loader/dllmain.cpp index 93ce721..bc10788 100644 --- a/source-code/source/PD-Loader/dllmain.cpp +++ b/source-code/source/PD-Loader/dllmain.cpp @@ -138,7 +138,10 @@ void LoadOriginalLibrary() auto szSystemPath = SHGetKnownFolderPath(FOLDERID_System, 0, nullptr) + L'\\' + szSelfName; auto szLocalPath = GetModuleFileNameW(hm); szLocalPath = szLocalPath.substr(0, szLocalPath.find_last_of(L"/\\") + 1); - if (iequals(szSelfName, L"dnsapi.dll")) { + if (iequals(szSelfName, L"dinput8.dll")) { + dinput8.LoadOriginalLibrary(LoadLibraryW(szSystemPath)); + } + else if (iequals(szSelfName, L"dnsapi.dll")) { dnsapi.LoadOriginalLibrary(LoadLibraryW(szSystemPath)); } } @@ -577,6 +580,15 @@ bool HookKernel32IAT(HMODULE mod, bool exe) { PIMAGE_IMPORT_BY_NAME import = (PIMAGE_IMPORT_BY_NAME)(hInstance + thunk->u1.AddressOfData); void** p = (void**)(hInstance + (pImports + i)->FirstThunk); + + if (iequals(szSelfName, L"dinput8.dll")) + { + DWORD Protect; + VirtualProtect(&p[j], 4, PAGE_EXECUTE_READWRITE, &Protect); + + if ((IMAGE_ORDINAL(thunk->u1.Ordinal)) == 1) + p[j] = _DirectInput8Create; + } } ++thunk; } diff --git a/source-code/source/PD-Loader/framework.h b/source-code/source/PD-Loader/framework.h index c5697b0..7186119 100644 --- a/source-code/source/PD-Loader/framework.h +++ b/source-code/source/PD-Loader/framework.h @@ -506,6 +506,18 @@ struct dnsapi_dll } } dnsapi; +struct dinput8_dll +{ + HMODULE dll; + FARPROC DirectInput8Create; + + void LoadOriginalLibrary(HMODULE module) + { + dll = module; + shared.LoadOriginalLibrary(dll); + DirectInput8Create = GetProcAddress(dll, "DirectInput8Create"); + } +} dinput8; #pragma runtime_checks( "", off ) @@ -737,6 +749,8 @@ void _Socket_TcpListen() { dnsapi.Socket_TcpListen(); } void _Update_ReplaceAddressRecordsW() { dnsapi.Update_ReplaceAddressRecordsW(); } void _Util_IsIp6Running() { dnsapi.Util_IsIp6Running(); } +typedef HRESULT(*fn_DirectInput8Create)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID* ppvOut, LPUNKNOWN punkOuter); +void _DirectInput8Create() { (fn_DirectInput8Create)dinput8.DirectInput8Create(); } void _DllRegisterServer() { shared.DllRegisterServer(); } void _DllUnregisterServer() { shared.DllUnregisterServer(); } diff --git a/source-code/source/PD-Loader/x64.def b/source-code/source/PD-Loader/x64.def index 832cd66..a7e0df7 100644 --- a/source-code/source/PD-Loader/x64.def +++ b/source-code/source/PD-Loader/x64.def @@ -1,3 +1,11 @@ +LIBRARY "dinput8" +EXPORTS +DirectInput8Create = _DirectInput8Create +DllCanUnloadNow = _DllCanUnloadNow PRIVATE +DllGetClassObject = _DllGetClassObject PRIVATE +DllRegisterServer = _DllRegisterServer PRIVATE +DllUnregisterServer = _DllUnregisterServer PRIVATE + LIBRARY "dnsapi" EXPORTS BreakRecordsIntoBlob = _BreakRecordsIntoBlob