Skip to content

Commit

Permalink
Add IV support
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Nov 19, 2023
1 parent 3537c61 commit ac31e90
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"defines": [
"_DEBUG",
"_DX9_SDK_INSTALLED",
"RUNTIME_CLEO"
"RUNTIME_REDUX",
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe",
Expand Down
1 change: 1 addition & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) {
if (id == HostId::GTA3) gGameVer = eGameVer::III;
if (id == HostId::VC) gGameVer = eGameVer::VC;
if (id == HostId::SA) gGameVer = eGameVer::SA;
if (id == HostId::IV) gGameVer = eGameVer::IV;
if (id == HostId::GTA3_UNREAL) gGameVer = eGameVer::III_DE;
if (id == HostId::VC_UNREAL) gGameVer = eGameVer::VC_DE;
if (id == HostId::SA_UNREAL) gGameVer = eGameVer::SA_DE;
Expand Down
20 changes: 19 additions & 1 deletion src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Hook::SetMouseState(bool state) {
LRESULT Hook::hkWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam);

if (ImGui::GetIO().WantTextInput|| (gGameVer > eGameVer::SA && mouseVisible)) {
if (ImGui::GetIO().WantTextInput || (gGameVer > eGameVer::SA && mouseVisible)) {
#ifndef _WIN64
if (gGameVer == eGameVer::SA) {
reinterpret_cast<void(__cdecl*)()>(0x53F1E0)(); // CPad::ClearKeyboardHistory
Expand Down Expand Up @@ -441,6 +441,20 @@ BOOL CALLBACK Hook::hkShowCursor(bool flag) {
return oShowCursor(flag);
}

void Hook::InputWatcher()
{
while (true)
{
ImGuiIO& io = ImGui::GetIO();
if (io.MouseDrawCursor) {
io.MouseDown[0] = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0;
io.MouseDown[1] = (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0;
io.MouseDown[2] = (GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0;
}
Sleep(1);
}
}

bool Hook::Inject(void *pCallback) {
static bool injected;
if (injected) {
Expand Down Expand Up @@ -505,6 +519,10 @@ bool Hook::Inject(void *pCallback) {
}
}

if (gGameVer == eGameVer::IV) {
CreateThread(nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(InputWatcher), nullptr, 0, nullptr);
}

return injected;
}

Expand Down
3 changes: 3 additions & 0 deletions src/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Hook {
static bool GetDinputDevice(void** pMouse, size_t size);
static HRESULT CALLBACK hkGetDeviceState(IDirectInputDevice8* pThis, DWORD cbData, LPVOID lpvData);

// IV
static void InputWatcher();

public:

Hook() = delete;
Expand Down
2 changes: 1 addition & 1 deletion src/pch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"

eRenderer gRenderer = eRenderer::Unknown;
eGameVer gGameVer;
eGameVer gGameVer = eGameVer::Unknown;
void* gD3DDevice = nullptr;
2 changes: 2 additions & 0 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ enum class eGameVer {
III,
VC,
SA,
IV,
V,
III_DE,
VC_DE,
SA_DE,
Expand Down

0 comments on commit ac31e90

Please sign in to comment.