diff --git a/premake5.lua b/premake5.lua index 548b531..a70a1fa 100644 --- a/premake5.lua +++ b/premake5.lua @@ -296,20 +296,6 @@ resincludedirs {"$(ProjectDir)src"} dependencies.imports() -project "runner" -kind "WindowedApp" -language "C++" - -files {"./src/runner/**.rc", "./src/runner/**.hpp", "./src/runner/**.cpp", "./src/runner/resources/**.*"} - -includedirs {"./src/runner", "./src/common", "%{prj.location}/src"} - -resincludedirs {"$(ProjectDir)src"} - -links {"common"} - -dependencies.imports() - project "client" kind "ConsoleApp" language "C++" @@ -327,7 +313,7 @@ includedirs {"./src/client", "./src/common", "%{prj.location}/src"} resincludedirs {"$(ProjectDir)src"} -dependson {"tlsdll", "runner"} +dependson {"tlsdll"} links {"common"} @@ -370,22 +356,6 @@ links {"common"} resincludedirs {"$(ProjectDir)src"} -project "runner" -kind "WindowedApp" -language "C++" - -files {"./src/runner/**.rc", "./src/runner/**.hpp", "./src/runner/**.cpp", "./src/runner/resources/**.*"} - -includedirs {"./src/runner", "./src/common", "%{prj.location}/src"} - -links {"common"} - -resincludedirs {"$(ProjectDir)src"} - -links {"common"} - -dependencies.imports() - group "Dependencies" dependencies.projects() diff --git a/src/client/component/steam_proxy.cpp b/src/client/component/steam_proxy.cpp index dd61af4..f10fd5b 100644 --- a/src/client/component/steam_proxy.cpp +++ b/src/client/component/steam_proxy.cpp @@ -18,8 +18,6 @@ namespace steam_proxy { namespace { - utils::binary_resource runner_file(RUNNER, "runner.exe"); - utils::nt::library steam_client_module_{}; #ifdef LOAD_STEAM_OVERLAY utils::nt::library steam_overlay_module_{}; @@ -84,8 +82,7 @@ namespace steam_proxy steam_pipe_ = steam_client_module_.invoke("Steam_CreateSteamPipe"); global_user_ = steam_client_module_.invoke( "Steam_ConnectToGlobalUser", steam_pipe_); - client_user_ = client_engine_.invoke(8, steam_pipe_, global_user_); - // GetIClientUser + client_user_ = client_engine_.invoke(8, steam_pipe_, global_user_); // GetIClientUser client_utils_ = client_engine_.invoke(14, steam_pipe_); // GetIClientUtils } @@ -147,36 +144,23 @@ namespace steam_proxy client_utils_.invoke("SetAppIDForCurrentPipe", app_id, false); - char our_directory[MAX_PATH] = { 0 }; - GetCurrentDirectoryA(sizeof(our_directory), our_directory); - - const auto path = runner_file.get_extracted_file(); - const std::string cmdline = utils::string::va("\"%s\" -proc %d", path.data(), GetCurrentProcessId()); - - steam::game_id game_id; - game_id.raw.type = 1; // k_EGameIDTypeGameMod - game_id.raw.app_id = app_id & 0xFFFFFF; - - const auto* mod_id = "iw7"; - game_id.raw.mod_id = *reinterpret_cast(mod_id) | 0x80000000; - - client_user_.invoke("SpawnProcess", path.data(), cmdline.data(), our_directory, - &game_id.bits, title.data(), 0, 0, 0); - return ownership_state::success; } ownership_state start_mod(const std::string& title, const size_t app_id) { - __try + try { return start_mod_unsafe(title, app_id); } - __except (EXCEPTION_EXECUTE_HANDLER) + catch (const std::exception& e) { do_cleanup(); - return ownership_state::error; + printf("Steam: %s\n", e.what()); + MessageBoxA(GetForegroundWindow(), e.what(), "Error", MB_ICONERROR); + TerminateProcess(GetCurrentProcess(), 1234); } + return ownership_state::error; } } @@ -218,8 +202,9 @@ namespace steam_proxy break; } } - catch (std::exception& e) + catch (const std::exception& e) { + do_cleanup(); printf("Steam: %s\n", e.what()); MessageBoxA(GetForegroundWindow(), e.what(), "Error", MB_ICONERROR); TerminateProcess(GetCurrentProcess(), 1234); diff --git a/src/client/resource.hpp b/src/client/resource.hpp index 0ed778c..34c576e 100644 --- a/src/client/resource.hpp +++ b/src/client/resource.hpp @@ -9,7 +9,6 @@ #define DW_PLAYLISTS 303 #define TLS_DLL 304 -#define RUNNER 305 #define ICON_IMAGE 306 diff --git a/src/client/resource.rc b/src/client/resource.rc index e8f0b2a..5764a97 100644 --- a/src/client/resource.rc +++ b/src/client/resource.rc @@ -107,12 +107,6 @@ TLS_DLL RCDATA "../../build/bin/x64/Debug/tlsdll.dll" TLS_DLL RCDATA "../../build/bin/x64/Release/tlsdll.dll" #endif -#ifdef _DEBUG -RUNNER RCDATA "../../build/bin/x64/Debug/runner.exe" -#else -RUNNER RCDATA "../../build/bin/x64/Release/runner.exe" -#endif - ICON_IMAGE RCDATA "resources/icon.png" #endif // English (United States) resources diff --git a/src/runner/debugger.cpp b/src/runner/debugger.cpp deleted file mode 100644 index d58149b..0000000 --- a/src/runner/debugger.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -#include -#include "debugger.hpp" - -namespace -{ - bool acquire_debug_privilege() - { - TOKEN_PRIVILEGES token_privileges; - ZeroMemory(&token_privileges, sizeof(token_privileges)); - token_privileges.PrivilegeCount = 1; - - HANDLE token; - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)) - { - return false; - } - - if (!LookupPrivilegeValue(nullptr, SE_DEBUG_NAME, &token_privileges.Privileges[0].Luid)) - { - CloseHandle(token); - return false; - } - - token_privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - - DWORD size; - if (!AdjustTokenPrivileges(token, FALSE, &token_privileges, 0, nullptr, &size)) - { - CloseHandle(token); - return false; - } - - return CloseHandle(token) != FALSE; - } -} - -debugger::debugger(const unsigned long process_id, const bool start) -{ - if (!start) - { - return; - } - - this->runner_ = std::thread([this, process_id]() - { - this->terminate_ = false; - this->run(process_id); - }); -} - -debugger::~debugger() -{ - this->terminate_ = true; - if (this->runner_.joinable()) - { - this->runner_.join(); - } -} - -void debugger::run(const unsigned long process_id) const -{ - acquire_debug_privilege(); - if (!DebugActiveProcess(process_id)) - { - return; - } - - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); - - DEBUG_EVENT event; - while (!this->terminate_ && WaitForDebugEvent(&event,INFINITE)) - { - if (event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) - { - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_EXCEPTION_NOT_HANDLED); - continue; - } - - if (event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) - { - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - break; - } - -#ifdef DEV_BUILD - if (event.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT) - { - OutputDebugStringA("Debugger attached!\n"); - } -#endif - - ContinueDebugEvent(event.dwProcessId, event.dwThreadId, DBG_CONTINUE); - } -} diff --git a/src/runner/debugger.hpp b/src/runner/debugger.hpp deleted file mode 100644 index 99d1073..0000000 --- a/src/runner/debugger.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include - -class debugger -{ -public: - debugger(unsigned long process_id, bool start); - ~debugger(); - -private: - volatile bool terminate_ = false; - std::thread runner_; - - void run(unsigned long process_id) const; -}; diff --git a/src/runner/resource.rc b/src/runner/resource.rc deleted file mode 100644 index ba86c6f..0000000 --- a/src/runner/resource.rc +++ /dev/null @@ -1,100 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#pragma code_page(65001) - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "windows.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "#include ""windows.h""\r\n" - "\0" -END - -2 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,0 - PRODUCTVERSION 1,0,0,0 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x40004L - FILETYPE VFT_DLL - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "CompanyName", "X Labs" - VALUE "FileDescription", "Steam mod runner" - VALUE "FileVersion", "1.0.0.0" - VALUE "InternalName", "Runner" - VALUE "LegalCopyright", "All rights reserved." - VALUE "OriginalFilename", "runner.exe" - VALUE "ProductName", "runner" - VALUE "ProductVersion", "1.0.0.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -///////////////////////////////////////////////////////////////////////////// -// -// Binary Data -// - -102 ICON "../client/resources/icon.ico" - -#endif // English (United States) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/src/runner/runner.cpp b/src/runner/runner.cpp deleted file mode 100644 index 01c32d2..0000000 --- a/src/runner/runner.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -#include -#include - -#include "debugger.hpp" - -int __stdcall WinMain(HINSTANCE, HINSTANCE, PSTR, int) -{ - const auto* const command = "-proc "; - const char* parent_proc = strstr(GetCommandLineA(), command); - - if (parent_proc) - { - const auto pid = DWORD(atoi(parent_proc + strlen(command))); - auto* const process_handle = OpenProcess(SYNCHRONIZE, FALSE, pid); - if (process_handle) - { - //debugger _(pid, strstr(GetCommandLineA(), "-debug ") != nullptr); - WaitForSingleObject(process_handle, INFINITE); - CloseHandle(process_handle); - return 0; - } - } - - return 1; -}