Merge branch 'develop' into develop

This commit is contained in:
Louve 2024-05-14 22:08:21 +02:00 committed by GitHub
commit bb7d38ffc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 10 deletions

View File

@ -244,12 +244,12 @@ namespace Components
return; return;
} }
auto workingDir = std::filesystem::current_path().string(); const std::filesystem::path workingDir = std::filesystem::current_path();
const std::string binary = *Game::sys_exitCmdLine; const std::wstring binary = Utils::String::Convert(*Game::sys_exitCmdLine);
const std::string command = binary == "iw4x-sp.exe" ? "iw4x-sp" : "iw4x"; const std::wstring commandLine = std::format(L"\"{}\" iw4x --pass \"{}\"", (workingDir / binary).wstring(), Utils::GetLaunchParameters());
SetEnvironmentVariableA("MW2_INSTALL", workingDir.data()); SetEnvironmentVariableA("MW2_INSTALL", workingDir.string().data());
Utils::Library::LaunchProcess(binary, std::format("{} --pass \"{}\"", command, GetCommandLineA()), workingDir); Utils::Library::LaunchProcess(binary, commandLine, workingDir);
} }
__declspec(naked) void QuickPatch::SND_GetAliasOffset_Stub() __declspec(naked) void QuickPatch::SND_GetAliasOffset_Stub()

View File

@ -102,17 +102,17 @@ namespace Utils
this->module_ = nullptr; this->module_ = nullptr;
} }
void Library::LaunchProcess(const std::string& process, const std::string& commandLine, const std::string& currentDir) void Library::LaunchProcess(const std::wstring& process, const std::wstring& commandLine, const std::filesystem::path& currentDir)
{ {
STARTUPINFOA startupInfo; STARTUPINFOW startupInfo;
PROCESS_INFORMATION processInfo; PROCESS_INFORMATION processInfo;
ZeroMemory(&startupInfo, sizeof(startupInfo)); ZeroMemory(&startupInfo, sizeof(startupInfo));
ZeroMemory(&processInfo, sizeof(processInfo)); ZeroMemory(&processInfo, sizeof(processInfo));
startupInfo.cb = sizeof(startupInfo); startupInfo.cb = sizeof(startupInfo);
CreateProcessA(process.data(), const_cast<char*>(commandLine.data()), nullptr, CreateProcessW(process.data(), const_cast<wchar_t*>(commandLine.data()), nullptr,
nullptr, false, NULL, nullptr, currentDir.data(), nullptr, false, NULL, nullptr, currentDir.wstring().data(),
&startupInfo, &processInfo); &startupInfo, &processInfo);
if (processInfo.hThread && processInfo.hThread != INVALID_HANDLE_VALUE) if (processInfo.hThread && processInfo.hThread != INVALID_HANDLE_VALUE)

View File

@ -65,7 +65,7 @@ namespace Utils
return T(); return T();
} }
static void LaunchProcess(const std::string& process, const std::string& commandLine, const std::string& currentDir); static void LaunchProcess(const std::wstring& process, const std::wstring& commandLine, const std::filesystem::path& currentDir);
private: private:
HMODULE module_; HMODULE module_;

View File

@ -163,6 +163,28 @@ namespace Utils
} }
} }
std::wstring GetLaunchParameters()
{
std::wstring args;
int numArgs;
auto* const argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
if (argv)
{
for (auto i = 1; i < numArgs; ++i)
{
std::wstring arg(argv[i]);
args.append(arg);
args.append(L" ");
}
LocalFree(argv);
}
return args;
}
HMODULE GetNTDLL() HMODULE GetNTDLL()
{ {
return GetModuleHandleA("ntdll.dll"); return GetModuleHandleA("ntdll.dll");

View File

@ -24,6 +24,8 @@ namespace Utils
void OpenUrl(const std::string& url); void OpenUrl(const std::string& url);
std::wstring GetLaunchParameters();
bool HasIntersection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2); bool HasIntersection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2);
template <typename T> template <typename T>