From 13be8f3894ea7be5e13ceded413347b2d160bc1c Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 11 Nov 2022 16:21:24 +0100 Subject: [PATCH] Get rid of the runner --- premake5.lua | 17 +---- src/client/component/demonware.cpp | 2 +- src/client/component/exception.cpp | 2 +- src/client/component/splash.cpp | 13 ++-- src/client/component/steam_proxy.cpp | 5 +- src/client/component/updater.cpp | 10 +-- src/client/main.cpp | 28 +++++++- src/client/resource.hpp | 3 +- src/client/resource.rc | 6 -- src/runner/resource.rc | 100 --------------------------- src/runner/runner.cpp | 21 ------ 11 files changed, 39 insertions(+), 168 deletions(-) delete mode 100644 src/runner/resource.rc delete mode 100644 src/runner/runner.cpp diff --git a/premake5.lua b/premake5.lua index cbb1d3c5..4e8ac575 100644 --- a/premake5.lua +++ b/premake5.lua @@ -299,7 +299,7 @@ project "client" resincludedirs {"$(ProjectDir)src"} - dependson {"tlsdll", "runner"} + dependson {"tlsdll"} links {"common"} @@ -324,20 +324,5 @@ project "tlsdll" 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"} - - dependencies.imports() - - group "Dependencies" dependencies.projects() diff --git a/src/client/component/demonware.cpp b/src/client/component/demonware.cpp index 3e31c656..efb5a570 100644 --- a/src/client/component/demonware.cpp +++ b/src/client/component/demonware.cpp @@ -444,7 +444,7 @@ namespace demonware class component final : public component_interface { public: - component() + void pre_load() override { udp_servers.create("stun.us.demonware.net"); udp_servers.create("stun.eu.demonware.net"); diff --git a/src/client/component/exception.cpp b/src/client/component/exception.cpp index eea66cde..a61244b6 100644 --- a/src/client/component/exception.cpp +++ b/src/client/component/exception.cpp @@ -196,7 +196,7 @@ namespace exception class component final : public component_interface { public: - component() + void pre_load() override { main_thread_id = GetCurrentThreadId(); SetUnhandledExceptionFilter(exception_filter); diff --git a/src/client/component/splash.cpp b/src/client/component/splash.cpp index 3affe117..952b4e53 100644 --- a/src/client/component/splash.cpp +++ b/src/client/component/splash.cpp @@ -56,9 +56,10 @@ namespace splash class component final : public component_interface { public: - component() - : image_(load_splash_image()) + void pre_load() override { + this->image_ = load_splash_image(); + enable_dpi_awareness(); window_thread = std::thread([this] { @@ -66,19 +67,15 @@ namespace splash }); } - ~component() + void pre_destroy() override { + destroy_window(); if (window_thread.joinable()) { window_thread.detach(); } } - void pre_destroy() override - { - destroy_window(); - } - void post_unpack() override { destroy_window(); diff --git a/src/client/component/steam_proxy.cpp b/src/client/component/steam_proxy.cpp index 1e8fba81..d060af45 100644 --- a/src/client/component/steam_proxy.cpp +++ b/src/client/component/steam_proxy.cpp @@ -19,8 +19,6 @@ namespace steam_proxy { namespace { - utils::binary_resource runner_file(RUNNER, "boiii-runner.exe"); - utils::nt::library steam_client_module{}; utils::nt::library steam_overlay_module{}; @@ -155,7 +153,8 @@ namespace steam_proxy char our_directory[MAX_PATH] = {0}; GetCurrentDirectoryA(sizeof(our_directory), our_directory); - const auto path = runner_file.get_extracted_file(); + const auto self = utils::nt::library::get_by_address(start_mod_unsafe); + const auto path = self.get_path(); const std::string cmdline = utils::string::va("\"%s\" -proc %d", path.data(), GetCurrentProcessId()); steam::game_id game_id; diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index ced16c06..f381d211 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -130,7 +130,7 @@ namespace updater class component final : public component_interface { public: - component() + void pre_load() override { cleanup_update(); @@ -140,14 +140,6 @@ namespace updater }); } - ~component() override - { - if (this->update_thread_.joinable()) - { - this->update_thread_.detach(); - } - } - void pre_destroy() override { join(); diff --git a/src/client/main.cpp b/src/client/main.cpp index b5838de9..4b1122f6 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -138,14 +138,40 @@ namespace return FARPROC(proc.get_ptr() + proc.get_relative_entry_point()); } + bool handle_process_runner() + { + const auto* const command = "-proc "; + const char* parent_proc = strstr(GetCommandLineA(), command); + + if (!parent_proc) + { + return false; + } + + const auto pid = DWORD(atoi(parent_proc + strlen(command))); + const utils::nt::handle<> process_handle = OpenProcess(SYNCHRONIZE, FALSE, pid); + if (process_handle) + { + WaitForSingleObject(process_handle, INFINITE); + } + + return true; + } + int main() { + if (handle_process_runner()) + { + TerminateProcess(GetCurrentProcess(), 0); + return 0; + } + FARPROC entry_point{}; srand(uint32_t(time(nullptr)) ^ ~(GetTickCount() * GetCurrentProcessId())); { auto premature_shutdown = true; - const auto _ = utils::finally([&premature_shutdown]() + const auto _ = utils::finally([&premature_shutdown] { if (premature_shutdown) { diff --git a/src/client/resource.hpp b/src/client/resource.hpp index d40cdb81..716757fb 100644 --- a/src/client/resource.hpp +++ b/src/client/resource.hpp @@ -12,5 +12,4 @@ #define DW_KEYS 306 #define DW_QOSCONFIG 307 -#define RUNNER 308 -#define TLS_DLL 309 +#define TLS_DLL 308 diff --git a/src/client/resource.rc b/src/client/resource.rc index 62f6c961..92e99f4b 100644 --- a/src/client/resource.rc +++ b/src/client/resource.rc @@ -102,12 +102,6 @@ DW_FASTFILE RCDATA "resources/dw/core_ffotd_tu32_593.ff" DW_KEYS RCDATA "resources/dw/keys.txt" DW_QOSCONFIG RCDATA "resources/dw/qosconfig4.csv" -#ifdef _DEBUG -RUNNER RCDATA "../../build/bin/x64/Debug/runner.exe" -#else -RUNNER RCDATA "../../build/bin/x64/Release/runner.exe" -#endif - #ifdef _DEBUG TLS_DLL RCDATA "../../build/bin/x64/Debug/tlsdll.dll" #else diff --git a/src/runner/resource.rc b/src/runner/resource.rc deleted file mode 100644 index ba86c6f4..00000000 --- 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 b2a7ace2..00000000 --- a/src/runner/runner.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -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))); - const utils::nt::handle<> process_handle = OpenProcess(SYNCHRONIZE, FALSE, pid); - if (process_handle) - { - WaitForSingleObject(process_handle, INFINITE); - return 0; - } - } - - return 1; -}