diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 9f25679..aa1153d 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -10,7 +10,7 @@ "defines": [ "_DEBUG", "_DX9_SDK_INSTALLED", - "RUNTIME_REDUX", + "RUNTIME_CLEO", ], "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", diff --git a/examples/cleo5/imgui_test.cs b/examples/cleo5/imgui_test.cs index 6eed7c7..94d48c8 100644 Binary files a/examples/cleo5/imgui_test.cs and b/examples/cleo5/imgui_test.cs differ diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 46a829c..eb11b09 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -1,14 +1,62 @@ #include "pch.h" -#include #include "opcodemgr.h" #include "hook.h" #include "wrapper.hpp" -#ifdef RUNTIME_CLEO -#include "MinHook.h" -#include "injector.hpp" +#include +#include + +HINSTANCE gDllHandle; + +DWORD GetProcessIdFromModule(HMODULE hModule) { + DWORD processId = 0; + HANDLE hProcess = NULL; + MODULEINFO moduleInfo; + + hProcess = GetCurrentProcess(); + if (hProcess != NULL) { + if (GetModuleInformation(hProcess, hModule, &moduleInfo, sizeof(moduleInfo))) { + processId = GetProcessId(hProcess); + } + CloseHandle(hProcess); + } + + return processId; +} + +BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { + DWORD processId = 0; + GetWindowThreadProcessId(hwnd, &processId); + + if (processId == static_cast(lParam)) { + return FALSE; // Stop + } + return TRUE; // Continue +} + +bool HasGameLaunched(HMODULE hModule, int maxRetries, int sleepDuration) { + DWORD processId = GetProcessIdFromModule(hModule); + if (processId == 0) { + MessageBox(NULL, "Failed to get process ID", "ImGuiRedux", MB_ICONERROR); + return false; + } + + int retries = 0; + while (retries < maxRetries) { + Sleep(sleepDuration); + if (!EnumWindows(EnumWindowsProc, static_cast(processId))) { + return true; + } + retries++; + } + MessageBox(NULL, "Failed to detect game window.", "ImGuiRedux", MB_ICONERROR); + return false; +} +void ImGuiThread(void* param) { + if (!HasGameLaunched(gDllHandle, 30, 5000)) { + return; + } -void f_GTA_SPCheck() { std::string moduleName = "SilentPatchSA.asi"; if (gGameVer == eGameVer::VC) { moduleName = "SilentPatchVC.asi"; @@ -23,29 +71,6 @@ void f_GTA_SPCheck() { }; return; } -} -#endif - -void ImGuiThread(void* param) { - -#ifdef RUNTIME_CLEO - /* - Need SP for mouse fixes - Only need for classics - TODO: Get the mouse patches from MTA later - */ - if (gGameVer <= eGameVer::SA) { - MH_Initialize(); - uint32_t addr = (gGameVer == eGameVer::SA) ? 0x5BF3A1 : - ((gGameVer == eGameVer::VC) ? 0x4A5B6B : 0x48D52F); - - void *ptr = NULL; - MH_CreateHook((void*)addr, f_GTA_SPCheck, &ptr); - MH_EnableHook(ptr); - } -#endif - - Sleep(5000); if (!Hook::Inject(&ScriptExData::DrawFrames)) { MessageBox(HWND_DESKTOP, "Failed to inject dxhook..", "ImGuiRedux", MB_ICONERROR); @@ -63,14 +88,11 @@ void __stdcall _wrapper(DWORD saveSlot) { BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) { if (nReason == DLL_PROCESS_ATTACH) { #ifdef RUNTIME_CLEO - auto gvm = injector::game_version_manager(); - gvm.Detect(); - - if (gvm.GetMajorVersion() == 1 && gvm.GetMinorVersion() == 0) { - if (gvm.IsIII()) gGameVer = eGameVer::III; - if (gvm.IsVC()) gGameVer = eGameVer::VC; - if (gvm.IsSA()) gGameVer = eGameVer::SA; + CLEO::eGameVersion ver = CLEO::CLEO_GetGameVersion(); + if (ver != CLEO::eGameVersion::GV_US10) { + MessageBox(HWND_DESKTOP, "Unknown game/ version detected. gta_sa.exe v1.0 US required!", "ImGuiRedux", MB_ICONERROR); } + gGameVer = eGameVer::SA; #else if (GetModuleHandle("ImGuiCleoWin32.cleo")) { Log("ImGuiReduxWin32: ImGuiCleoWin32 detected. Closing..."); diff --git a/src/hook.cpp b/src/hook.cpp index 1c4f509..8e3fad3 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -77,7 +77,8 @@ void Hook::ProcessFrame(void* ptr) { // Scale the menu if game resolution changed static int height, width, RsGlobal; -#ifdef RUNTIME_CLEO + +#ifndef _WIN64 if (gGameVer == eGameVer::III) { RsGlobal = 0x8F4360; width = injector::ReadMemory(RsGlobal + 4, 0); // width @@ -96,12 +97,13 @@ void Hook::ProcessFrame(void* ptr) { width = rect.right - rect.left; height = rect.bottom - rect.top; } -#else +#else RECT rect; GetWindowRect(hwnd, &rect); width = rect.right - rect.left; height = rect.bottom - rect.top; #endif + static ImVec2 fScreenSize = ImVec2(-1, -1); if (fScreenSize.x != width && fScreenSize.y != height) { if (gRenderer == eRenderer::Dx9) { @@ -170,7 +172,7 @@ void Hook::ProcessFrame(void* ptr) { } if (gGameVer == eGameVer::SA) { - injector::MakeNOP(0x00531155, 5); // shift trigger fix + injector::MakeNOP(0x531155, 5); // shift trigger fix } if (gRenderer == eRenderer::Dx9) { diff --git a/src/opcodemgr.cpp b/src/opcodemgr.cpp index b9c2a5c..b23353a 100644 --- a/src/opcodemgr.cpp +++ b/src/opcodemgr.cpp @@ -43,33 +43,6 @@ static RTN_TYPE RUNTIME_API ImGuiEnd(RUNTIME_CONTEXT ctx) { return RTN_CONTINUE; } -// static RTN_TYPE RUNTIME_API ImGuiBegin(RUNTIME_CONTEXT ctx) { -// char label[RUNTIME_STR_LEN]; - -// wGetStringWithFrame(ctx, label, RUNTIME_STR_LEN); -// bool openFlag = wGetBoolParam(ctx); -// bool noTitleBar = wGetBoolParam(ctx); -// bool noResize = wGetBoolParam(ctx); -// bool noMove = wGetBoolParam(ctx); -// bool autoResize = wGetBoolParam(ctx); - -// ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse; -// if (noTitleBar) flags |= ImGuiWindowFlags_NoTitleBar; -// if (noResize) flags |= ImGuiWindowFlags_NoResize; -// if (noMove) flags |= ImGuiWindowFlags_NoMove; -// if (autoResize) flags |= ImGuiWindowFlags_AlwaysAutoResize; - -// ScriptExData* data = ScriptExData::Get(); -// data->imgui += [=]() { -// bool isOpen = openFlag; -// ImGui::Begin(label, &isOpen, flags); -// data->SetData(label, 0, isOpen); -// }; -// data->imgui.lastScriptCall = time(NULL); -// wSetIntParam(ctx, data->GetData(label, 0, true)); -// return RTN_CONTINUE; -// } - static RTN_TYPE RUNTIME_API ImGuiButton(RUNTIME_CONTEXT ctx) { char buf[RUNTIME_STR_LEN]; ImVec2 size; @@ -314,14 +287,12 @@ static RTN_TYPE RUNTIME_API ImGuiGetFramerate(RUNTIME_CONTEXT ctx) { } static RTN_TYPE RUNTIME_API ImGuiGetVersion(RUNTIME_CONTEXT ctx) { - char* buf = const_cast(ImGui::GetVersion()); - unsigned char len = static_cast(strlen(buf)); - wSetStringParam(ctx, buf); + wSetIntParam(ctx, IMGUI_VERSION_NUM); return RTN_CONTINUE; } static RTN_TYPE RUNTIME_API ImGuiGetPluginVersion(RUNTIME_CONTEXT ctx) { - wSetFloatParam(ctx, IMGUI_REDUX_VERSION); + wSetIntParam(ctx, IMGUI_REDUX_VERSION_NUM); return RTN_CONTINUE; } @@ -551,8 +522,8 @@ static RTN_TYPE RUNTIME_API ImGuiGetDisplaySize(RUNTIME_CONTEXT ctx) { RECT rect; GetClientRect(GetForegroundWindow(), &rect); - wSetFloatParam(ctx, rect.right - rect.left); - wSetFloatParam(ctx, rect.bottom - rect.top); + wSetFloatParam(ctx, float(rect.right - rect.left)); + wSetFloatParam(ctx, float(rect.bottom - rect.top)); return RTN_CONTINUE; } diff --git a/src/pch.h b/src/pch.h index 9aa0f80..959c6e2 100644 --- a/src/pch.h +++ b/src/pch.h @@ -1,6 +1,7 @@ #pragma once #define _CRT_SECURE_NO_WARNINGS -#define IMGUI_REDUX_VERSION 2.0f +#define IMGUI_REDUX_VERSION 3.0f +#define IMGUI_REDUX_VERSION_NUM 30000 #include "imgui.h" #include "imgui_stdlib.h" #include "scriptextender.hpp" diff --git a/src/scriptextender.hpp b/src/scriptextender.hpp index eb93d7a..966f5ea 100644 --- a/src/scriptextender.hpp +++ b/src/scriptextender.hpp @@ -84,6 +84,8 @@ class ScriptExData case 2: // SA scriptsPaused = *(bool*)0xB7CB49; break; + default: + break; } if (curTime-lastScriptCall > 2 || scriptsPaused) { diff --git a/tools/Debug.bat b/tools/Debug.bat index 4e0aa7d..776705c 100644 --- a/tools/Debug.bat +++ b/tools/Debug.bat @@ -5,14 +5,7 @@ echo -------------------------------------------------- echo[ call "tools\Setup.bat" MsBuild ImGuiRedux.sln /property:Configuration=Debug /t:ImGuiRedux /property:Platform=Win32 -<<<<<<< HEAD del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.cleo" /Q del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.pdb" /Q xcopy /s "bin\ImGuiReduxWin32.cleo" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y xcopy /s "bin\ImGuiReduxWin32.pdb" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -======= -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.cleo" /Q -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.pdb" /Q -xcopy /s "bin\ImGuiReduxWin32.cleo" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -xcopy /s "bin\ImGuiReduxWin32.pdb" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81 diff --git a/tools/Debug64.bat b/tools/Debug64.bat index 14a650e..469d80d 100644 --- a/tools/Debug64.bat +++ b/tools/Debug64.bat @@ -5,14 +5,7 @@ echo -------------------------------------------------- echo[ call "tools\Setup.bat" MsBuild ImGuiRedux.sln /property:Configuration=Release /t:ImGuiRedux /property:Platform=Win64 -<<<<<<< HEAD del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin64.cleo" /Q del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin64.pdb" /Q xcopy /s "bin\ImGuiReduxWin64.cleo" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y xcopy /s "bin\ImGuiReduxWin64.pdb" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -======= -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin64.cleo" /Q -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin64.pdb" /Q -xcopy /s "bin\ImGuiReduxWin64.cleo" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -xcopy /s "bin\ImGuiReduxWin64.pdb" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81 diff --git a/tools/DebugCleo.bat b/tools/DebugCleo.bat index f4f2b80..c5c9cd5 100644 --- a/tools/DebugCleo.bat +++ b/tools/DebugCleo.bat @@ -5,14 +5,7 @@ echo -------------------------------------------------- echo[ call "tools\Setup.bat" MsBuild ImGuiRedux.sln /property:Configuration=DebugCleo /t:ImGuiRedux /property:Platform=Win32 -<<<<<<< HEAD del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiCleoWin32.cleo" /Q del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiCleoWin32.pdb" /Q xcopy /s "bin\ImGuiCleoWin32.cleo" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y xcopy /s "bin\ImGuiCleoWin32.pdb" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -======= -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiCleoWin32.cleo" /Q -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiCleoWin32.pdb" /Q -xcopy /s "bin\ImGuiCleoWin32.cleo" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -xcopy /s "bin\ImGuiCleoWin32.pdb" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81 diff --git a/tools/Release.bat b/tools/Release.bat index 7f6298a..5c82e12 100644 --- a/tools/Release.bat +++ b/tools/Release.bat @@ -5,10 +5,5 @@ echo -------------------------------------------------- echo[ call "tools\Setup.bat" MsBuild ImGuiRedux.sln /property:Configuration=Release /t:ImGuiRedux /property:Platform=Win32 -<<<<<<< HEAD del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.cleo" /Q xcopy /s "bin\ImGuiReduxWin32.cleo" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -======= -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.cleo" /Q -xcopy /s "bin\ImGuiReduxWin32.cleo" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81 diff --git a/tools/Release64.bat b/tools/Release64.bat index d055848..a926dc2 100644 --- a/tools/Release64.bat +++ b/tools/Release64.bat @@ -5,10 +5,5 @@ echo -------------------------------------------------- echo[ call "tools\Setup.bat" MsBuild ImGuiRedux.sln /property:Configuration=Release /t:ImGuiRedux /property:Platform=Win64 -<<<<<<< HEAD del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin64.cleo" /Q xcopy /s "bin\ImGuiReduxWin64.cleo" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -======= -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin64.cleo" /Q -xcopy /s "bin\ImGuiReduxWin64.cleo" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81 diff --git a/tools/ReleaseCleo.bat b/tools/ReleaseCleo.bat index 641d717..49cd68b 100644 --- a/tools/ReleaseCleo.bat +++ b/tools/ReleaseCleo.bat @@ -5,10 +5,5 @@ echo -------------------------------------------------- echo[ call "tools\Setup.bat" MsBuild ImGuiRedux.sln /property:Configuration=ReleaseCleo /t:ImGuiRedux /property:Platform=Win32 -<<<<<<< HEAD del "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.cleo" /Q xcopy /s "bin\ImGuiReduxWin32.cleo" "%GTA_SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y -======= -del "%SA_DIR%\cleo\CLEO_PLUGINS\ImGuiReduxWin32.cleo" /Q -xcopy /s "bin\ImGuiReduxWin32.cleo" "%SA_DIR%\cleo\CLEO_PLUGINS\" /K /D /H /Y ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81 diff --git a/tools/Setup.bat b/tools/Setup.bat index db65436..f05d24e 100644 --- a/tools/Setup.bat +++ b/tools/Setup.bat @@ -1,5 +1,4 @@ @echo off -<<<<<<< HEAD set "projectdir=%CD%" set "PLUGIN_NAME="GrinchTrainer"" @@ -46,10 +45,3 @@ premake5.exe vs2022 :run_dev cd "%projectdir%\build" call %vs_path%"\Common7\Tools\VsDevCmd.bat" -======= -rem Set game paths below -cd tools -premake5.exe vs2022 -cd ../build -call "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat" ->>>>>>> d1a2aba3c3bc211b773c9c44dee2eeb385378b81