From 2a6fdb1c7296e158d97e2dda5042feb282c5678a Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Fri, 8 Jan 2021 03:07:45 +0600 Subject: [PATCH] Bug fixes & new stuff 1. Fixed issue with radio scroll #45 2. Fixed crash with renderhook 3. Refactored code 4. Added option to control neon pulsing 5. Fixed a issue with huge crosshair when huge dmg is enabled --- .vscode/settings.json | 8 ++- CMakeLists.txt | 3 +- src/Animation.cpp | 4 +- src/Animation.h | 6 +- src/CheatMenu.h | 6 +- src/Hook.cpp | 27 +++++--- src/MenuInfo.h | 2 +- src/NeonAPI.cpp | 28 ++++++--- src/NeonAPI.h | 3 + src/Ui.cpp | 9 +-- src/Util.cpp | 8 +-- src/Vehicle.cpp | 5 ++ src/Weapon.cpp | 2 +- src/pch.cpp | 2 +- src/pch.h | 7 +-- src/tests/CMakeLists.txt | 129 +++++++++++++++++++++++++++++++++++++++ src/tests/Test.cpp | 23 +++++++ 17 files changed, 227 insertions(+), 45 deletions(-) create mode 100644 src/tests/CMakeLists.txt create mode 100644 src/tests/Test.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json index f87950c..fd72e66 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -67,7 +67,13 @@ "*.def": "cpp", "atomic": "cpp", "compare": "cpp", - "concepts": "cpp" + "concepts": "cpp", + "charconv": "cpp", + "condition_variable": "cpp", + "mutex": "cpp", + "optional": "cpp", + "shared_mutex": "cpp", + "thread": "cpp" }, "C_Cpp.errorSquiggles": "Enabled", "C_Cpp.intelliSenseEngineFallback": "Enabled" diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c85106..6ef97ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19 FATAL_ERROR) +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(PROJECT_NAME CheatMenu) project(${PROJECT_NAME} CXX) @@ -16,6 +16,7 @@ set(DIRECTX9_SDK_DIR $ENV{DIRECTX9_SDK_DIR}) # Required projects ################################################################################ add_subdirectory(src/vendor) +add_subdirectory(src/tests) ################################################################################ # Source groups diff --git a/src/Animation.cpp b/src/Animation.cpp index b550e9f..7da422a 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -58,7 +58,7 @@ void Animation::Main() if (ImGui::BeginChild("Anims Child")) { ImGui::Spacing(); - Ui::DrawJSON(json, search_categories, selected_item, filter, &PlayAnimation, &RemoveEntry); + Ui::DrawJSON(json, search_categories, selected_item, filter, &PlayAnimation, &RemoveAnimation); ImGui::EndChild(); } ImGui::EndTabItem(); @@ -132,7 +132,7 @@ void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& Command(ifp.c_str()); } -void Animation::RemoveEntry(std::string& ifp, std::string& anim, std::string& ifp_repeat) +void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string& ifp_repeat) { flog << ifp << std::endl; if (ifp == "Custom") diff --git a/src/Animation.h b/src/Animation.h index 740e7a9..d3ff851 100644 --- a/src/Animation.h +++ b/src/Animation.h @@ -10,16 +10,16 @@ private: static std::vector search_categories; static std::string selected_item; - static char ifp_buffer[INPUT_BUFFER_SIZE]; static char anim_buffer[INPUT_BUFFER_SIZE]; + static char ifp_buffer[INPUT_BUFFER_SIZE]; protected: Animation(); ~Animation() {}; + public: static void Main(); static void PlayAnimation(std::string& rootkey, std::string& anim, std::string& ifp); - - static void RemoveEntry(std::string& rootkey, std::string& anim, std::string& ifp); + static void RemoveAnimation(std::string& rootkey, std::string& anim, std::string& ifp); }; diff --git a/src/CheatMenu.h b/src/CheatMenu.h index 7cf57e6..078cd33 100644 --- a/src/CheatMenu.h +++ b/src/CheatMenu.h @@ -1,7 +1,9 @@ /* Required: - Visual Studio 2015.3 (v140) + DirectX 9 SDK Plugin SDK + Visual Studio 2019 (v142) + Windows SDK */ #pragma once @@ -50,7 +52,7 @@ public: } /* - WndProc is extremely buggy without SilentPatch + Mouse is extremely buggy without SilentPatch Should have a better fix for this but everyone should have SilentPatch installed so mehh... */ diff --git a/src/Hook.cpp b/src/Hook.cpp index cdbc6f6..8965e7b 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -17,6 +17,14 @@ LRESULT Hook::InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam { ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); + if (Hook::show_mouse) + { + patch::Nop(0x4EB9F4, 5); // disable radio scroll + Call<0x541BD0>(); // CPad::ClearMouseHistory + } + else + patch::SetRaw(0x4EB9F4, (void*)"\xE8\x67\xFC\xFF\xFF", 5); // enable radio scroll + if (ImGui::GetIO().WantTextInput) { Call<0x53F1E0>(); // CPad::ClearKeyboardHistory @@ -24,7 +32,6 @@ LRESULT Hook::InputProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam } else return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam); - } HRESULT Hook::ResetDx9(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS * pPresentationParameters) @@ -97,9 +104,11 @@ HRESULT Hook::PresentDx11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl if (Globals::init_done) { - HRESULT hr = pSwapChain->Present(1, 0); - if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) - ImGui_ImplDX11_InvalidateDeviceObjects(); + if (mouse_visibility != show_mouse) + { + Hook::ShowMouse(show_mouse); + mouse_visibility = show_mouse; + } // Change font size if the game resolution changes if (Globals::font_screen_size.x != screen::GetScreenWidth() @@ -135,13 +144,13 @@ HRESULT Hook::PresentDx11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Fl DXGI_SWAP_CHAIN_DESC desc; pSwapChain->GetDesc(&desc); - pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&Globals::device11); + pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&Globals::device); ID3D11DeviceContext* context; - Globals::device11->GetImmediateContext(&context); + reinterpret_cast(Globals::device)->GetImmediateContext(&context); ImGui::CreateContext(); ImGui_ImplWin32_Init(desc.OutputWindow); - ImGui_ImplDX11_Init(Globals::device11, context); + ImGui_ImplDX11_Init(reinterpret_cast(Globals::device), context); ImGui_ImplWin32_EnableDpiAwareness(); io.IniFilename = NULL; @@ -163,6 +172,7 @@ void Hook::ShowMouse(bool state) patch::SetUChar(0x6194A0, 0xC3); patch::Nop(0x53F417, 5); // don't call CPad__getMouseState patch::SetRaw(0x53F41F, (void*)"\x33\xC0\x0F\x84", 4); // disable camera mouse movement + //patch::Nop(0x4EB9F4, 5); // disable radio scroll } else { @@ -171,6 +181,7 @@ void Hook::ShowMouse(bool state) patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4); // xor eax, eax -> test eax, eax , enable camera mouse movement // jz loc_53F526 -> jl loc_53F526 patch::SetUChar(0x6194A0, 0xE9); // jmp setup + //patch::SetRaw(0x4EB9F4, (void*)"\xE8\x67\xFC\xFF\xFF", 5); // enable radio scroll } ImGui::GetIO().MouseDrawCursor = state; @@ -206,8 +217,6 @@ Hook::Hook() Globals::renderer = Render_DirectX11; flog << "Successfully hooked dx11 device." << std::endl; } - - flog << "Successfully hooked dx11 device." << std::endl; } else { diff --git a/src/MenuInfo.h b/src/MenuInfo.h index 0a0e3b3..fe7eee5 100644 --- a/src/MenuInfo.h +++ b/src/MenuInfo.h @@ -1,5 +1,5 @@ #pragma once #define MENU_NAME "Cheat Menu" #define MENU_VERSION "2.5-beta" -#define BUILD_NUMBER "20210103" +#define BUILD_NUMBER "20210108" #define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")" \ No newline at end of file diff --git a/src/NeonAPI.cpp b/src/NeonAPI.cpp index ecf3988..befe74b 100644 --- a/src/NeonAPI.cpp +++ b/src/NeonAPI.cpp @@ -30,17 +30,19 @@ NeonAPI::NeonAPI() { data->timer = CTimer::m_snTimeInMilliseconds; - if (data->val < 0.0f) + if (data->pulsing) + { + if (data->val < 0.0f) data->increment = true; - if (data->val > 0.3f) - data->increment = false; - - if (data->increment) - data->val += 0.1f; - else - data->val -= 0.1f; + if (data->val > 0.3f) + data->increment = false; + if (data->increment) + data->val += 0.1f; + else + data->val -= 0.1f; + } } } }; @@ -56,6 +58,16 @@ bool NeonAPI::IsNeonInstalled(CVehicle *pVeh) return VehNeon.Get(pVeh).neon_installed; } +bool NeonAPI::IsPulsingEnabled(CVehicle *pVeh) +{ + return VehNeon.Get(pVeh).pulsing; +} + +void NeonAPI::SetPulsing(CVehicle *pVeh, bool state) +{ + VehNeon.Get(pVeh).pulsing = state; +} + void NeonAPI::InstallNeon(CVehicle *pVeh, int red, int green, int blue) { CRGBA &color = VehNeon.Get(pVeh).color; diff --git a/src/NeonAPI.h b/src/NeonAPI.h index e29b922..e35c609 100644 --- a/src/NeonAPI.h +++ b/src/NeonAPI.h @@ -12,6 +12,7 @@ private: float val; uint timer; bool increment; + bool pulsing; NeonData(CVehicle *pVeh) { @@ -29,6 +30,8 @@ public: ~NeonAPI(); static void InstallNeon(CVehicle *veh, int red, int green, int blue); static bool IsNeonInstalled(CVehicle *veh); + static bool IsPulsingEnabled(CVehicle *veh); + static void SetPulsing(CVehicle *veh, bool state); static void RemoveNeon(CVehicle *veh); }; diff --git a/src/Ui.cpp b/src/Ui.cpp index 2563264..d91d503 100644 --- a/src/Ui.cpp +++ b/src/Ui.cpp @@ -493,14 +493,7 @@ void Ui::DrawImages(std::vector> &img_vec, ImV && (verify_func == nullptr || verify_func(text)) ) { - void *texture = nullptr; - - if (Globals::renderer == Render_DirectX9) - texture = img_vec[i]->texture9; - else // consider 11 - texture = img_vec[i]->texture11; - - if (ImGui::ImageButton(texture, image_size, ImVec2(0, 0), ImVec2(1, 1), 1, ImVec4(1, 1, 1, 1), ImVec4(1, 1, 1, 1))) + if (ImGui::ImageButton(img_vec[i]->texture, image_size, ImVec2(0, 0), ImVec2(1, 1), 1, ImVec4(1, 1, 1, 1), ImVec4(1, 1, 1, 1))) on_left_click(text); if (ImGui::IsItemClicked(1) && on_right_click != nullptr) diff --git a/src/Util.cpp b/src/Util.cpp index 53e00b9..46f3488 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -33,11 +33,11 @@ void Util::LoadTexturesInDirRecursive(const char *path, const char *file_ext,std store_vec.push_back(std::make_unique()); HRESULT hr = -1; if (Globals::renderer == Render_DirectX9) - hr = D3DXCreateTextureFromFileA(GetD3DDevice(), p.path().string().c_str(), &store_vec.back().get()->texture9); + hr = D3DXCreateTextureFromFileA(GetD3DDevice(), p.path().string().c_str(), reinterpret_cast(&store_vec.back().get()->texture)); if (Globals::renderer == Render_DirectX11) { - if (LoadTextureFromFileDx11(p.path().string().c_str(), &store_vec.back().get()->texture11)) + if (LoadTextureFromFileDx11(p.path().string().c_str(), reinterpret_cast(&store_vec.back().get()->texture))) hr = S_OK; } @@ -89,7 +89,7 @@ bool Util::LoadTextureFromFileDx11(const char* filename, ID3D11ShaderResourceVie subResource.SysMemPitch = desc.Width * 4; subResource.SysMemSlicePitch = 0; - Globals::device11->CreateTexture2D(&desc, &subResource, &pTexture); + reinterpret_cast(Globals::device)->CreateTexture2D(&desc, &subResource, &pTexture); // Create texture view D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; @@ -98,7 +98,7 @@ bool Util::LoadTextureFromFileDx11(const char* filename, ID3D11ShaderResourceVie srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = desc.MipLevels; srvDesc.Texture2D.MostDetailedMip = 0; - Globals::device11->CreateShaderResourceView(pTexture, &srvDesc, out_srv); + reinterpret_cast(Globals::device)->CreateShaderResourceView(pTexture, &srvDesc, out_srv); pTexture->Release(); stbi_image_free(image_data); diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index 91279f8..9779872 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -1043,6 +1043,11 @@ void Vehicle::Main() ImGui::Spacing(); ImGui::Columns(2, NULL, false); + + bool pulsing = NeonAPI::IsPulsingEnabled(veh); + if (Ui::CheckboxWithHint("Pulsing neons", &pulsing)) + NeonAPI::SetPulsing(veh,pulsing); + Ui::CheckboxWithHint("Rainbow neons", &neon::rainbow, "Rainbow effect to neon lights"); ImGui::NextColumn(); Ui::CheckboxWithHint("Traffic neons", &neon::traffic, "Adds neon lights to traffic vehicles.\n\ diff --git a/src/Weapon.cpp b/src/Weapon.cpp index a06022c..51cea82 100644 --- a/src/Weapon.cpp +++ b/src/Weapon.cpp @@ -66,7 +66,7 @@ Weapon::Weapon() CWeaponInfo *pweapon_info = CWeaponInfo::GetWeaponInfo(weapon_type, player->GetWeaponSkill(weapon_type)); if (huge_damage) - pweapon_info->m_nDamage = 5000; + pweapon_info->m_nDamage = 1000; if (long_range) { diff --git a/src/pch.cpp b/src/pch.cpp index a02df6e..ab92b9c 100644 --- a/src/pch.cpp +++ b/src/pch.cpp @@ -7,8 +7,8 @@ ImVec2 Globals::font_screen_size = ImVec2(-1, -1); bool Globals::show_menu = false; bool Globals::init_done = false; Renderer Globals::renderer = Render_Unknown; -ID3D11Device *Globals::device11 = nullptr; bool Globals::gsync_time = false; +void *Globals::device = nullptr; std::ofstream flog = std::ofstream("CheatMenu.log"); CJson config = CJson("config"); diff --git a/src/pch.h b/src/pch.h index 19fd3f0..7f9f2ac 100644 --- a/src/pch.h +++ b/src/pch.h @@ -49,7 +49,7 @@ #include "extensions/ScriptCommands.h" #include "extensions/Screen.h" #include "eVehicleClass.h" -#include "extensions\Paths.h" +#include "extensions/Paths.h" #include "vendor/imgui/imgui.h" #include "vendor/imgui/imgui_internal.h" @@ -86,16 +86,15 @@ struct Globals static bool show_menu; static bool init_done; static Renderer renderer; - static ID3D11Device* device11; static bool gsync_time; + static void* device; }; struct TextureStructure { std::string file_name; std::string category_name; - PDIRECT3DTEXTURE9 texture9; - ID3D11ShaderResourceView* texture11; + void *texture = nullptr; }; extern CJson config; diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..24b3221 --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,129 @@ +################################################################################ +# Build Test.asi +# A testing plugin for the menu, recompiling the whole menu is tedious +################################################################################ + +cmake_minimum_required(VERSION 3.0) +project(Test) + +################################################################################ +# Target +################################################################################ +add_library(${PROJECT_NAME} SHARED "Test.cpp") + +string(CONCAT "MSVC_RUNTIME_LIBRARY_STR" + $<$: + MultiThreaded + > + $<$: + MultiThreadedDebug + > +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${GTA_SA_DIR}/$<0:>/" + SUFFIX ".asi" + MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR} +) + +################################################################################ +# Include directories +################################################################################ +include_directories( + "${PLUGIN_SDK_DIR}/plugin_sa" + "${PLUGIN_SDK_DIR}/plugin_sa/game_sa" + "${PLUGIN_SDK_DIR}/shared" + "${PLUGIN_SDK_DIR}/shared/game" + "${DIRECTX9_SDK_DIR}/include" +) + +################################################################################ +# Compile definitions +################################################################################ +target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_NDEBUG" + ">" + "$<$:" + "_DEBUG" + ">" + "_CRT_SECURE_NO_WARNINGS;" + "_CRT_NON_CONFORMING_SWPRINTFS;" + "GTASA;" + "GTAGAME_NAME=\"San Andreas\";" + "GTAGAME_ABBR=\"SA\";" + "GTAGAME_ABBRLOW=\"sa\";" + "GTAGAME_PROTAGONISTNAME=\"CJ\";" + "GTAGAME_CITYNAME=\"San Andreas\";" + "_LA_SUPPORT;" + "_DX9_SDK_INSTALLED;" + "PLUGIN_SGV_10US;" + "_MBCS" +) + +################################################################################ +# Compile and link options +################################################################################ +target_compile_options(${PROJECT_NAME} PRIVATE + $<$: + /O2; + /Oi; + /Gy + > + $<$: + /Od + /DEBUG:FULL + > + /std:c++latest; + /sdl-; + /W3; + ${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT}; + ${DEFAULT_CXX_EXCEPTION_HANDLING} + /w44005 +) +string(CONCAT FILE_CL_OPTIONS + "/Y-" +) +target_link_options(${PROJECT_NAME} PRIVATE + $<$: + /OPT:REF; + /LTCG; + /OPT:ICF; + > + $<$: + /DEBUG:FULL; + /SAFESEH:NO; + > + /SUBSYSTEM:WINDOWS +) + +################################################################################ +# Pre build events +################################################################################ +add_custom_command( + TARGET ${PROJECT_NAME} + PRE_BUILD + COMMAND taskkill /f /fi "imagename eq gta_sa.exe" +) + +################################################################################ +# Dependencies +################################################################################ +target_link_libraries(${PROJECT_NAME} PUBLIC +optimized plugin +debug plugin_d +) + +target_link_directories(${PROJECT_NAME} PUBLIC +"$ENV{PLUGIN_SDK_DIR}/output/lib/" +"$<$:" + "vendor/Release/" +">" +"$<$:" + "vendor/Debug/" +">") + +target_link_libraries(${PROJECT_NAME} PUBLIC + optimized plugin + debug plugin_d +) \ No newline at end of file diff --git a/src/tests/Test.cpp b/src/tests/Test.cpp new file mode 100644 index 0000000..68cd27d --- /dev/null +++ b/src/tests/Test.cpp @@ -0,0 +1,23 @@ +#include "plugin.h" + +using namespace plugin; + +class Test +{ +public: + Test() + { + Events::processScriptsEvent += [] + { + if(KeyPressed(VK_UP)) + { + patch::Nop(0x4EB9F4, 5); // disable + } + if(KeyPressed(VK_DOWN)) + { + patch::SetRaw(0x4EB9F4, (void*)"\xE8\x67\xFC\xFF\xFF", 5); // enable + } + }; + } +} test; +