diff options
author | BobTheBob9 <for.oliver.kirkham@gmail.com> | 2022-09-03 01:20:21 +0100 |
---|---|---|
committer | BobTheBob9 <for.oliver.kirkham@gmail.com> | 2022-09-03 01:20:21 +0100 |
commit | ad8d7bcb8afef94240170606ee1a012441187cc1 (patch) | |
tree | 15a1ee1a5aa2510149e4fdee9bbf42eae63c8e41 | |
parent | 1b891ff2f166a5d00270c1cd00d2606d8cfd114d (diff) | |
parent | a219d385e296e4cc35134dcc8500db1b2bcd6722 (diff) | |
download | NorthstarLauncher-ad8d7bcb8afef94240170606ee1a012441187cc1.tar.gz NorthstarLauncher-ad8d7bcb8afef94240170606ee1a012441187cc1.zip |
Merge branch 'bobs-big-refactor-pr' of https://github.com/R2Northstar/NorthstarLauncher into bobs-big-refactor-pr
-rw-r--r-- | loader_launcher_proxy/dllmain.cpp | 207 | ||||
-rw-r--r-- | loader_launcher_proxy/framework.h | 2 | ||||
-rw-r--r-- | loader_launcher_proxy/pch.h | 2 | ||||
-rw-r--r-- | loader_wsock32_proxy/dllmain.cpp | 59 | ||||
-rw-r--r-- | loader_wsock32_proxy/pch.h | 4 |
5 files changed, 142 insertions, 132 deletions
diff --git a/loader_launcher_proxy/dllmain.cpp b/loader_launcher_proxy/dllmain.cpp index a86dddea..a382bc97 100644 --- a/loader_launcher_proxy/dllmain.cpp +++ b/loader_launcher_proxy/dllmain.cpp @@ -16,31 +16,33 @@ using CreateInterfaceFn = void* (*)(const char* pName, int* pReturnCode); // does not seem to ever be used extern "C" __declspec(dllexport) void* __fastcall CreateInterface(const char* pName, int* pReturnCode) { - //AppSystemCreateInterfaceFn(pName, pReturnCode); - printf("external CreateInterface: name: %s\n", pName); + // AppSystemCreateInterfaceFn(pName, pReturnCode); + printf("external CreateInterface: name: %s\n", pName); - static CreateInterfaceFn launcher_CreateInterface = (CreateInterfaceFn)GetProcAddress(hLauncherModule, "CreateInterface"); - auto res = launcher_CreateInterface(pName, pReturnCode); + static CreateInterfaceFn launcher_CreateInterface = (CreateInterfaceFn)GetProcAddress(hLauncherModule, "CreateInterface"); + auto res = launcher_CreateInterface(pName, pReturnCode); - printf("external CreateInterface: return code: %p\n", res); - return res; + printf("external CreateInterface: return code: %p\n", res); + return res; } bool GetExePathWide(wchar_t* dest, DWORD destSize) { - if (!dest) return NULL; - if (destSize < MAX_PATH) return NULL; + if (!dest) + return NULL; + if (destSize < MAX_PATH) + return NULL; - DWORD length = GetModuleFileNameW(NULL, dest, destSize); - return length && PathRemoveFileSpecW(dest); + DWORD length = GetModuleFileNameW(NULL, dest, destSize); + return length && PathRemoveFileSpecW(dest); } FARPROC GetLauncherMain() { - static FARPROC Launcher_LauncherMain; - if (!Launcher_LauncherMain) - Launcher_LauncherMain = GetProcAddress(hLauncherModule, "LauncherMain"); - return Launcher_LauncherMain; + static FARPROC Launcher_LauncherMain; + if (!Launcher_LauncherMain) + Launcher_LauncherMain = GetProcAddress(hLauncherModule, "LauncherMain"); + return Launcher_LauncherMain; } void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location) @@ -48,7 +50,6 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* char text[4096]; std::string message = std::system_category().message(dwMessageId); sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs", libName, location, dwMessageId, message.c_str()); - if (dwMessageId == 126 && std::filesystem::exists(location)) { sprintf_s( @@ -57,24 +58,20 @@ void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* "found.", text); } - MessageBoxA(GetForegroundWindow(), text, "Northstar Launcher Proxy Error", 0); } -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; } wchar_t exePath[4096]; @@ -82,86 +79,96 @@ wchar_t dllPath[4096]; bool ShouldLoadNorthstar() { - bool loadNorthstar = !strstr(GetCommandLineA(), "-vanilla"); - - if (!loadNorthstar) - return loadNorthstar; - - auto runNorthstarFile = std::ifstream("run_northstar.txt"); - if (runNorthstarFile) - { - std::stringstream runNorthstarFileBuffer; - runNorthstarFileBuffer << runNorthstarFile.rdbuf(); - runNorthstarFile.close(); - if (runNorthstarFileBuffer.str().starts_with("0")) - loadNorthstar = false; - } - return loadNorthstar; + bool loadNorthstar = !strstr(GetCommandLineA(), "-vanilla"); + + if (!loadNorthstar) + return loadNorthstar; + + auto runNorthstarFile = std::ifstream("run_northstar.txt"); + if (runNorthstarFile) + { + std::stringstream runNorthstarFileBuffer; + runNorthstarFileBuffer << runNorthstarFile.rdbuf(); + runNorthstarFile.close(); + if (runNorthstarFileBuffer.str().starts_with("0")) + loadNorthstar = false; + } + return loadNorthstar; } bool LoadNorthstar() { - FARPROC Hook_Init = nullptr; - { - swprintf_s(dllPath, L"%s\\Northstar.dll", exePath); - hHookModule = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); - if (hHookModule) Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar"); - if (!hHookModule || Hook_Init == nullptr) - { - LibraryLoadError(GetLastError(), L"Northstar.dll", dllPath); - return false; - } - } - - ((bool (*)()) Hook_Init)(); - return true; + FARPROC Hook_Init = nullptr; + { + swprintf_s(dllPath, L"%s\\Northstar.dll", exePath); + hHookModule = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + if (hHookModule) + Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar"); + if (!hHookModule || Hook_Init == nullptr) + { + LibraryLoadError(GetLastError(), L"Northstar.dll", dllPath); + return false; + } + } + + ((bool (*)())Hook_Init)(); + return true; } extern "C" __declspec(dllexport) int LauncherMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - { - if (!GetExePathWide(exePath, 4096)) - { - MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Launcher Proxy Error", 0); - return 1; - } - - bool loadNorthstar = ShouldLoadNorthstar(); - - if (loadNorthstar) - { - swprintf_s(dllPath, L"%s\\bin\\x64_retail\\tier0.dll", exePath); - hTier0Module = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); - if (!hTier0Module) - { - LibraryLoadError(GetLastError(), L"tier0.dll", dllPath); - return 1; - } - - if (!LoadNorthstar()) - return 1; - } - //else printf("\n\n WILL !!!NOT!!! LOAD NORTHSTAR\n\n"); - - swprintf_s(dllPath, L"%s\\bin\\x64_retail\\launcher.org.dll", exePath); - hLauncherModule = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); - if (!hLauncherModule) - { - LibraryLoadError(GetLastError(), L"launcher.org.dll", dllPath); - return 1; - } - } - - auto LauncherMain = GetLauncherMain(); - if (!LauncherMain) - MessageBoxA(GetForegroundWindow(), "Failed loading launcher.org.dll.\nThe game cannot continue and has to exit.", "Northstar Launcher Proxy Error", 0); - //auto result = ((__int64(__fastcall*)())LauncherMain)(); - //auto result = ((signed __int64(__fastcall*)(__int64))LauncherMain)(0i64); - return ((int(__fastcall*)(HINSTANCE, HINSTANCE, LPSTR, int))LauncherMain)(hInstance, hPrevInstance, lpCmdLine, nCmdShow); + { + if (!GetExePathWide(exePath, 4096)) + { + MessageBoxA( + GetForegroundWindow(), + "Failed getting game directory.\nThe game cannot continue and has to exit.", + "Northstar Launcher Proxy Error", + 0); + return 1; + } + + bool loadNorthstar = ShouldLoadNorthstar(); + + if (loadNorthstar) + { + swprintf_s(dllPath, L"%s\\bin\\x64_retail\\tier0.dll", exePath); + hTier0Module = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!hTier0Module) + { + LibraryLoadError(GetLastError(), L"tier0.dll", dllPath); + return 1; + } + + if (!LoadNorthstar()) + return 1; + } + // else printf("\n\n WILL !!!NOT!!! LOAD NORTHSTAR\n\n"); + + swprintf_s(dllPath, L"%s\\bin\\x64_retail\\launcher.org.dll", exePath); + hLauncherModule = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!hLauncherModule) + { + LibraryLoadError(GetLastError(), L"launcher.org.dll", dllPath); + return 1; + } + } + + auto LauncherMain = GetLauncherMain(); + if (!LauncherMain) + MessageBoxA( + GetForegroundWindow(), + "Failed loading launcher.org.dll.\nThe game cannot continue and has to exit.", + "Northstar Launcher Proxy Error", + 0); + // auto result = ((__int64(__fastcall*)())LauncherMain)(); + // auto result = ((signed __int64(__fastcall*)(__int64))LauncherMain)(0i64); + return ((int(__fastcall*)(HINSTANCE, HINSTANCE, LPSTR, int))LauncherMain)(hInstance, hPrevInstance, lpCmdLine, nCmdShow); } // doubt that will help us here (in launcher.dll) though -extern "C" { - __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; - __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +extern "C" +{ + __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; + __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; } diff --git a/loader_launcher_proxy/framework.h b/loader_launcher_proxy/framework.h index d2a898df..1800e436 100644 --- a/loader_launcher_proxy/framework.h +++ b/loader_launcher_proxy/framework.h @@ -1,6 +1,6 @@ #pragma once -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define WIN32_EXTRA_LEAN #define VC_EXTRALEAN // Windows Header Files diff --git a/loader_launcher_proxy/pch.h b/loader_launcher_proxy/pch.h index 885d5d62..cc757129 100644 --- a/loader_launcher_proxy/pch.h +++ b/loader_launcher_proxy/pch.h @@ -10,4 +10,4 @@ // add headers that you want to pre-compile here #include "framework.h" -#endif //PCH_H +#endif // PCH_H diff --git a/loader_wsock32_proxy/dllmain.cpp b/loader_wsock32_proxy/dllmain.cpp index e09cd183..7feb278d 100644 --- a/loader_wsock32_proxy/dllmain.cpp +++ b/loader_wsock32_proxy/dllmain.cpp @@ -10,8 +10,10 @@ HINSTANCE hL = 0; bool GetExePathWide(wchar_t* dest, DWORD destSize) { - if (!dest) return NULL; - if (destSize < MAX_PATH) return NULL; + if (!dest) + return NULL; + if (destSize < MAX_PATH) + return NULL; DWORD length = GetModuleFileNameW(NULL, dest, destSize); return length && PathRemoveFileSpecW(dest); @@ -29,7 +31,11 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) if (!GetExePathWide(exePath, 4096)) { - MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Wsock32 Proxy Error", 0); + MessageBoxA( + GetForegroundWindow(), + "Failed getting game directory.\nThe game cannot continue and has to exit.", + "Northstar Wsock32 Proxy Error", + 0); return true; } @@ -59,7 +65,14 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) { if (!std::filesystem::exists(temp_dir)) { - swprintf_s(buffer2, L"Failed copying wsock32.dll from system32 to \"%s\"\n\n%S\n\nFurthermore, we failed copying wsock32.dll into temporary directory at \"%s\"\n\n%S", buffer1, e1.what(), temp_dir.c_str(), e2.what()); + swprintf_s( + buffer2, + L"Failed copying wsock32.dll from system32 to \"%s\"\n\n%S\n\nFurthermore, we failed copying wsock32.dll into " + L"temporary directory at \"%s\"\n\n%S", + buffer1, + e1.what(), + temp_dir.c_str(), + e2.what()); MessageBoxW(GetForegroundWindow(), buffer2, L"Northstar Wsock32 Proxy Error", 0); return false; } @@ -68,7 +81,8 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) } } hL = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH); - if (!hL) { + if (!hL) + { LibraryLoadError(GetLastError(), L"wsock32.org.dll", buffer1); return false; } @@ -104,73 +118,62 @@ extern "C" FARPROC PA = NULL; int RunASM(); - void PROXY_EnumProtocolsA() + void PROXY_EnumProtocolsA() { PA = p[1]; RunASM(); } - - void PROXY_EnumProtocolsW() + void PROXY_EnumProtocolsW() { PA = p[2]; RunASM(); } - - void PROXY_GetAddressByNameA() + void PROXY_GetAddressByNameA() { PA = p[4]; RunASM(); } - - void PROXY_GetAddressByNameW() + void PROXY_GetAddressByNameW() { PA = p[5]; RunASM(); } - - void PROXY_WEP() + void PROXY_WEP() { PA = p[17]; RunASM(); } - - void PROXY_WSARecvEx() + void PROXY_WSARecvEx() { PA = p[30]; RunASM(); } - - void PROXY___WSAFDIsSet() + void PROXY___WSAFDIsSet() { PA = p[36]; RunASM(); } - - void PROXY_getnetbyname() + void PROXY_getnetbyname() { PA = p[45]; RunASM(); } - - void PROXY_getsockopt() + void PROXY_getsockopt() { PA = p[52]; RunASM(); } - - void PROXY_inet_network() + void PROXY_inet_network() { PA = p[56]; RunASM(); } - - void PROXY_s_perror() + void PROXY_s_perror() { PA = p[67]; RunASM(); } - - void PROXY_setsockopt() + void PROXY_setsockopt() { PA = p[72]; RunASM(); diff --git a/loader_wsock32_proxy/pch.h b/loader_wsock32_proxy/pch.h index 0103ff59..6e8873a1 100644 --- a/loader_wsock32_proxy/pch.h +++ b/loader_wsock32_proxy/pch.h @@ -7,10 +7,10 @@ #ifndef PCH_H #define PCH_H -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files #include <windows.h> #include "include/MinHook.h" -#endif //PCH_H +#endif // PCH_H |