diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ed41732..20b86e02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,10 @@ add_compile_definitions( _CRT_SECURE_NO_WARNINGS ) +if (WIN32) + add_subdirectory(win32) +endif() + add_subdirectory(cli) find_package(CURL REQUIRED) # used for web requests. @@ -120,7 +124,7 @@ if (NOT APPLE) endif() if (WIN32) - set_target_properties(Millennium PROPERTIES OUTPUT_NAME "user32") + set_target_properties(Millennium PROPERTIES OUTPUT_NAME "millennium") set_target_properties(Millennium PROPERTIES PREFIX "") set_target_properties(Millennium PROPERTIES NO_EXPORT TRUE) endif() diff --git a/scripts/version.rc b/scripts/version.rc index 512e0e51..b0dd4a3e 100644 --- a/scripts/version.rc +++ b/scripts/version.rc @@ -5,8 +5,8 @@ #define VER_COMPANYNAME_STR "Steam Homebrew\0" #define VER_FILEDESCRIPTION_STR "A plugin loader for the modern Steam Client\0" -#define VER_INTERNALNAME_STR "user32.dll\0" -#define VER_ORIGINALFILENAME_STR "user32.dll\0" +#define VER_INTERNALNAME_STR "millennium.dll\0" +#define VER_ORIGINALFILENAME_STR "millennium.dll\0" #define VER_LEGALCOPYRIGHT_STR "Steam Homebrew 2024\0" #define VER_LEGALTRADEMARKS1_STR "All Rights Reserved\0" #define VER_LEGALTRADEMARKS2_STR "\0" diff --git a/src/main.cc b/src/main.cc index e03fa583..d9851276 100644 --- a/src/main.cc +++ b/src/main.cc @@ -80,8 +80,6 @@ const static void EntryMain() backendThread.join(); frontendThreads.join(); - - // std::this_thread::sleep_for(std::chrono::milliseconds(10000)); } #ifdef _WIN32 @@ -98,7 +96,7 @@ int __stdcall DllMain(void*, unsigned long fdwReason, void*) } case DLL_PROCESS_DETACH: { - Logger.PrintMessage(" MAIN ", "Shutting down Millennium...", COL_MAGENTA); + Logger.Log("Shutting down Millennium..."); std::exit(EXIT_SUCCESS); g_threadTerminateFlag->flag.store(true); Sockets::Shutdown(); diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt new file mode 100644 index 00000000..78eaf421 --- /dev/null +++ b/win32/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) + +# Set the project name +project(ShimDll) + +# Specify the C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +if (WIN32 AND NOT GITHUB_ACTION_BUILD) + # debug output paths + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "C:/Program Files (x86)/Steam") + set(LIBRARY_OUTPUT_DIRECTORY "C:/Program Files (x86)/Steam") +elseif(UNIX AND NOT GITHUB_ACTION_BUILD) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$ENV{HOME}/.millennium/") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$ENV{HOME}/.millennium/") +endif() + +# Add the executable +add_library(ShimDll SHARED main.cc) + +set_target_properties(ShimDll PROPERTIES OUTPUT_NAME "user32") +set_target_properties(ShimDll PROPERTIES PREFIX "") +set_target_properties(ShimDll PROPERTIES NO_EXPORT TRUE) + diff --git a/win32/main.cc b/win32/main.cc new file mode 100644 index 00000000..b5be2584 --- /dev/null +++ b/win32/main.cc @@ -0,0 +1,40 @@ +#include + +const void ShutdownShim(HINSTANCE hinstDLL) +{ + // Unload current module + FreeLibraryAndExitThread(hinstDLL, 0); +} + +const void LoadMillennium(HINSTANCE hinstDLL) +{ + HMODULE hMillennium = LoadLibrary(TEXT("millennium.dll")); + if (hMillennium == nullptr) { + MessageBoxA(nullptr, "Failed to load millennium.dll", "Error", MB_ICONERROR); + return; // Exit with error code + } + + CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)ShutdownShim, hinstDLL, 0, nullptr); +} + +BOOL WINAPI DllMain( + HINSTANCE hinstDLL, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID lpvReserved ) // reserved +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + { + LoadMillennium(hinstDLL); + break; + } + case DLL_PROCESS_DETACH: + { + // ShutdownShim(); + break; + } + } + + return true; +} \ No newline at end of file