From b27cd5e616b5a6cbc0f10bce68a3a15f6662a889 Mon Sep 17 00:00:00 2001 From: Z3r0M3m0ry Date: Wed, 31 Jan 2024 14:06:25 +0800 Subject: [PATCH] Added custom process selection Added custom process selection Remove outdated notice --- README.md | 1 + gui/Menu.cpp | 46 +++++++++++++++++++++++++++++++++++-------- injector/injector.cpp | 27 ++++++++++++++++++++----- injector/injector.hpp | 3 +++ memory/memory.hpp | 26 +++++++++++++++++++----- pch.h | 1 + vars/vars.hpp | 1 + 7 files changed, 87 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5b01a23..04b8486 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,4 @@ ## Update + Compatibility updates, now works on CS2 smoothly... + For legacy CS:GO version, get it from Release v1.0 Executable(For CS:GO) ++ Added custom process selection in v3.0 diff --git a/gui/Menu.cpp b/gui/Menu.cpp index bb681a3..63286dc 100644 --- a/gui/Menu.cpp +++ b/gui/Menu.cpp @@ -17,7 +17,7 @@ bool Menu::initialize() ::RegisterClassEx(&wc); this->hwnd = ::CreateWindow(wc.lpszClassName, _T("Potato Injector"), WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, - 100, 100, 200, 230, NULL, NULL, wc.hInstance, NULL); + 100, 100, 200, 270, NULL, NULL, wc.hInstance, NULL); ::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & WS_CAPTION & ~WS_THICKFRAME); ::SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); @@ -82,11 +82,11 @@ void Menu::loop() static int counter = 0; if (!g_injector->shouldAutoStart) { - ImGui::SetNextWindowSize({ 200, 210 }); + ImGui::SetNextWindowSize({ 200, 250 }); } else { - ImGui::SetNextWindowSize({ 200, 235 }); + ImGui::SetNextWindowSize({ 200, 270 }); } ImGui::SetNextWindowPos({ 0, 0 }); ImGui::Begin("Menu", 0, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); @@ -113,6 +113,24 @@ void Menu::loop() ImGui::Checkbox("Exit", &g_injector->shouldAutoExit); //Whether to auto exit after injection ImGui::SameLine(); ImGui::Checkbox("Start", &g_injector->shouldAutoStart); //Whether to auto start game after patching VAC + ImGui::Checkbox("Custom process", &g_injector->isCustomProcess); // Enable injection for other processes + + static int selectedProcess = 0; + if (g_injector->isCustomProcess) { + std::string procNames = ""; + auto procs = mem::getProcList(); + ::std::vector<::std::wstring> nameArr; + for (const auto& p : procs) + { + for (wchar_t wc : p.second) + procNames += char(wc); + procNames += '\0'; + nameArr.push_back(p.second); + } + if(ImGui::Combo("##Processes", &selectedProcess, procNames.c_str())) + g_injector->customProcessName = nameArr[selectedProcess]; + } + if (g_injector->shouldAutoStart) { std::wstring opts = vars::str_game_launch_opts; @@ -141,19 +159,31 @@ void Menu::loop() } ImGui::Combo("DLLS", &selectedDLL, comboPaths.c_str()); - ImGui::Text("Patch outdated, WOI..."); - ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + //ImGui::Text("Patch outdated, WOI..."); + //ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); if (ImGui::Button("Patch VAC3")) { if(!this->isPatchingVac) std::thread(&Injector::bypassVAC, g_injector.get()).detach(); } - ImGui::PopItemFlag(); + //ImGui::PopItemFlag(); ImGui::SameLine(0.0f, -1.0f); if (ImGui::Button("Inject")) { - if(!this->isInjecting && !paths.empty()) - std::thread(&Injector::inject, g_injector.get(), paths[selectedDLL]).detach(); + if (!this->isInjecting) + { + bool valid = true; + if (g_injector->isCustomProcess) + { + auto pid = mem::getProcID(g_injector->customProcessName); + if (pid == NULL) { + MessageBox(hwnd, L"Custom process not found...", nullptr, 0); + valid = false; + } + } + if (valid && !paths.empty()) + std::thread(&Injector::inject, g_injector.get(), paths[selectedDLL]).detach(); + } } if (this->isPatchingVac) { diff --git a/injector/injector.cpp b/injector/injector.cpp index 84e4fbc..17fb8e5 100644 --- a/injector/injector.cpp +++ b/injector/injector.cpp @@ -68,10 +68,19 @@ bool Injector::inject(std::string dllPath) return false; } - if (!this->map(vars::str_game_process_name.data(), vars::str_game_mod_name.data(), buffer)) - { - g_menu->isInjecting = false; - return false; + if(this->isCustomProcess) { + if (!this->map(customProcessName, customProcessName, buffer)) + { + g_menu->isInjecting = false; + return false; + } + } + else { + if (!this->map(vars::str_game_process_name.data(), vars::str_game_mod_name.data(), buffer)) + { + g_menu->isInjecting = false; + return false; + } } g_menu->isInjecting = false; @@ -109,8 +118,16 @@ bool Injector::map(std::wstring_view procname, std::wstring_view modname, std::v return false; } auto mods = proc.modules().GetAllModules(); + + auto toLower = [](const std::wstring& str) { + std::wstring lowerStr = str; + std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), + [](wchar_t c) { return std::towlower(c); }); + return lowerStr; + }; + for (const auto& mod : mods) { - if (mod.first.first == modname) + if (toLower(mod.first.first) == toLower(modname.data())) { modReady = true; break; diff --git a/injector/injector.hpp b/injector/injector.hpp index 2c4e2f5..51984b9 100644 --- a/injector/injector.hpp +++ b/injector/injector.hpp @@ -20,6 +20,9 @@ class Injector bool shouldAutoExit{ false }; bool shouldAutoStart{ false }; + bool isCustomProcess{ false }; + + ::std::wstring customProcessName{ L"godmode.exe" }; private: static Injector* m_inst; diff --git a/memory/memory.hpp b/memory/memory.hpp index 123b23f..ce828bb 100644 --- a/memory/memory.hpp +++ b/memory/memory.hpp @@ -3,8 +3,21 @@ namespace mem { - inline std::vector> getProcList() { - std::vector> procList; + struct CompareProc { + bool operator()(const std::pair& lhs, const std::pair& rhs) const { + return lhs.second < rhs.second; + } + }; + + inline bool isSystemProcess(const std::wstring& name) { + static const std::set systemProcesses = { + L"System", L"svchost.exe", L"csrss.exe", L"smss.exe", L"wininit.exe", L"services.exe" + }; + return systemProcesses.find(name) != systemProcesses.end(); + } + + inline std::set, CompareProc> getProcList() { + std::set, CompareProc> procList; auto hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); @@ -12,12 +25,15 @@ namespace mem e.dwSize = sizeof(e); if (!Process32First(hSnap, &e)) { + CloseHandle(hSnap); return {}; } - while (Process32Next(hSnap, &e)) { - procList.push_back(std::make_pair(e.th32ProcessID, e.szExeFile)); - } + do { + if (!isSystemProcess(e.szExeFile)) { + procList.insert(std::make_pair(e.th32ProcessID, e.szExeFile)); + } + } while (Process32Next(hSnap, &e)); CloseHandle(hSnap); return procList; diff --git a/pch.h b/pch.h index 7f3fb0c..314d87d 100644 --- a/pch.h +++ b/pch.h @@ -5,6 +5,7 @@ #include #include #include +#include #include diff --git a/vars/vars.hpp b/vars/vars.hpp index fe55452..90c90c3 100644 --- a/vars/vars.hpp +++ b/vars/vars.hpp @@ -8,6 +8,7 @@ namespace vars inline std::wstring_view str_dll_name{ L"cheat.dll" }; inline std::wstring_view str_steam_mod_name{ L"tier0_s.dll" }; inline std::wstring_view str_game_mod_name{ L"matchmaking.dll" }; + inline std::wstring_view str_d3d11_mod_name{ L"d3d11.dll" }; inline uint32_t game_appid{ 730 }; inline std::wstring str_game_launch_opts{ L"-console -worldwide -novid" }; inline std::wstring_view str_dll_dir_path{ L"./dlls" };