Skip to content

Commit

Permalink
Hook DBGHELP instead of DINPUT8
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirius902 committed Nov 17, 2021
1 parent 111827b commit 56930e8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
mkdir build && cd build
cmake ..
cmake --build . --config Release
- name: Upload DINPUT8
- name: Upload DBGHELP
uses: actions/upload-artifact@v2
with:
name: DINPUT8
name: DBGHELP
path: |
build/Release/DINPUT8.dll
build/Release/DBGHELP.dll
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
cmake --build . --config Release
- name: Compress Artifacts
run: |
7z a DINPUT8.zip ./build/Release/DINPUT8.dll
7z a DBGHELP.zip ./build/Release/DBGHELP.dll
- name: Automatic Release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
draft: true
files: |
DINPUT8.zip
DBGHELP.zip
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ target_link_libraries(LuaBackendLIB PUBLIC lua54.lib PUBLIC discord-rpc.lib)

target_compile_definitions(LuaBackendLIB PRIVATE -DUNICODE -D_UNICODE)

# DINPUT8
# DBGHELP

add_library(DINPUT8 SHARED LuaBackendDLL/main_dll.cpp)
add_library(DBGHELP SHARED LuaBackendDLL/main_dll.cpp)

target_compile_definitions(DINPUT8 PRIVATE -DUNICODE -D_UNICODE)
target_compile_definitions(DBGHELP PRIVATE -DUNICODE -D_UNICODE)

target_link_libraries(DINPUT8 LuaBackendLIB)
target_link_libraries(DBGHELP LuaBackendLIB)
6 changes: 3 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Installing LuaBackend Hook

### Internal LuaBackend Hook [DLL]
- Download ``DINPUT8.zip`` from the Releases tab.
- Extract ``DINPUT8.dll`` from ``DINPUT8.zip`` to the directory Kingdom Hearts 1.5+2.5 is installed which should be `KH_1.5_2.5`.
- Download ``DBGHELP.zip`` from the Releases tab.
- Extract ``DBGHELP.dll`` from ``DBGHELP.zip`` to the directory Kingdom Hearts 1.5+2.5 is installed which should be `KH_1.5_2.5`.
- Place your scripts in a folder named `scripts/[gameid]` in the `KINGDOM HEARTS HD 1.5+2.5 ReMIX` folder in your Documents folder.
- For Kingdom Hearts Final Mix the folder will be `scripts/kh1`.
- For Kingdom Hearts Re: Chain of Memories the folder will be `scripts/recom`.
- For Kingdom Hearts II Final Mix the folder will be `scripts/kh2`.
- For Kingdom Hearts Birth by Sleep Final Mix the folder will be `scripts/bbs`.
- The installation is now finished. LuaBackend will be automatically started with the game and can be easily uninstalled
by simply removing the ``DINPUT8.dll``. To verify it is installed correctly, you can open the LuaBackend console using
by simply removing the ``DBGHELP.dll``. To verify it is installed correctly, you can open the LuaBackend console using
the F2 key on the keyboard in game.
35 changes: 26 additions & 9 deletions LuaBackendDLL/main_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ const std::unordered_map<std::string_view, GameInfo> gameInfos{

namespace fs = std::filesystem;

using DirectInput8CreateProc = HRESULT(WINAPI*)(HINSTANCE hinst, DWORD dwVersion, LPCVOID riidltf, LPVOID* ppvOut, LPVOID punkOuter);
using MiniDumpWriteDumpProc = BOOL(WINAPI*)(
HANDLE hProcess,
DWORD ProcessId,
HANDLE hFile,
DWORD DumpType,
PVOID ExceptionParam,
PVOID UserStreamParam,
PVOID CallbackParam
);

using GameFrameProc = std::uint64_t(__cdecl*)(void* rcx);

DirectInput8CreateProc createProc = nullptr;
MiniDumpWriteDumpProc writeDumpProc = nullptr;

GameFrameProc* frameProcPtr = nullptr;
GameFrameProc frameProc = nullptr;
Expand Down Expand Up @@ -344,15 +353,15 @@ DWORD WINAPI entry(LPVOID lpParameter) {
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
static HMODULE dinput8 = nullptr;
static HMODULE dbgHelp = nullptr;

switch (fdwReason) {
case DLL_PROCESS_ATTACH: {
char dllPath[MAX_PATH];
GetSystemDirectoryA(dllPath, MAX_PATH);
std::strcat(dllPath, "\\DINPUT8.dll");
dinput8 = LoadLibraryA(dllPath);
createProc = (DirectInput8CreateProc)GetProcAddress(dinput8, "DirectInput8Create");
std::strcat(dllPath, "\\DBGHELP.dll");
dbgHelp = LoadLibraryA(dllPath);
writeDumpProc = (MiniDumpWriteDumpProc)GetProcAddress(dbgHelp, "MiniDumpWriteDump");

if (CreateThread(nullptr, 0, entry, nullptr, 0, nullptr) == nullptr) {
return FALSE;
Expand All @@ -361,7 +370,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
break;
}
case DLL_PROCESS_DETACH: {
FreeLibrary(dinput8);
FreeLibrary(dbgHelp);
break;
}
default:
Expand All @@ -371,6 +380,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
return TRUE;
}

extern "C" __declspec(dllexport) HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, LPCVOID riidltf, LPVOID* ppvOut, LPVOID punkOuter) {
return createProc(hinst, dwVersion, riidltf, ppvOut, punkOuter);
extern "C" __declspec(dllexport) BOOL WINAPI MiniDumpWriteDump(
HANDLE hProcess,
DWORD ProcessId,
HANDLE hFile,
DWORD DumpType,
PVOID ExceptionParam,
PVOID UserStreamParam,
PVOID CallbackParam
) {
return writeDumpProc(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam);
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Supports the PC Global versions of:

Installation instructions are in [INSTALL.md](INSTALL.md).

## Why is the dll file named DINPUT8?
## Why is the dll file named DBGHELP?
This is so that LuaBackend Hook can hook into the game without requiring an EXE patch, but still
be able to launch automatically with the game.

0 comments on commit 56930e8

Please sign in to comment.