Skip to content

Commit

Permalink
Added custom process selection
Browse files Browse the repository at this point in the history
Added custom process selection
Remove outdated notice
  • Loading branch information
leo4048111 committed Jan 31, 2024
1 parent 9d78605 commit b27cd5e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 38 additions & 8 deletions gui/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
27 changes: 22 additions & 5 deletions injector/injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions injector/injector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 21 additions & 5 deletions memory/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@

namespace mem
{
inline std::vector<std::pair<std::uint32_t, std::wstring>> getProcList() {
std::vector<std::pair<std::uint32_t, std::wstring>> procList;
struct CompareProc {
bool operator()(const std::pair<std::uint32_t, std::wstring>& lhs, const std::pair<std::uint32_t, std::wstring>& rhs) const {
return lhs.second < rhs.second;
}
};

inline bool isSystemProcess(const std::wstring& name) {
static const std::set<std::wstring> 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<std::pair<std::uint32_t, std::wstring>, CompareProc> getProcList() {
std::set<std::pair<std::uint32_t, std::wstring>, CompareProc> procList;

auto hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

PROCESSENTRY32 e;
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;
Expand Down
1 change: 1 addition & 0 deletions pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fstream>
#include <filesystem>
#include <thread>
#include <cwctype>

#include <windows.h>

Expand Down
1 change: 1 addition & 0 deletions vars/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down

0 comments on commit b27cd5e

Please sign in to comment.