forked from alterware/iw6-mod
Compare commits
2 Commits
(de)compre
...
fallback_l
Author | SHA1 | Date | |
---|---|---|---|
2516a48fc1 | |||
1db89c64c6 |
@ -4,6 +4,7 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include "utils/command_line.hpp"
|
||||
#include <utils/flags.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
@ -167,8 +168,23 @@ FARPROC load_binary(const launcher::mode mode)
|
||||
std::string data;
|
||||
if (!utils::io::read_file(binary, &data))
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Failed to read game binary! Please select the correct path in the launcher settings.");
|
||||
// Check the first argument to see if the current directory needs to changed
|
||||
// Required when the game is used to open a file (like a demo file)
|
||||
const auto& args = utils::command_line::get_args();
|
||||
if (!args.empty())
|
||||
{
|
||||
const auto& binary_dir = args.front();
|
||||
if (binary_dir.filename().string().ends_with("iw6-mod.exe"))
|
||||
{
|
||||
std::filesystem::current_path(binary_dir.parent_path());
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils::io::read_file(binary, &data))
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Failed to read game binary! Please select the correct path in the launcher settings.");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef INJECT_HOST_AS_LIB
|
||||
|
35
src/common/utils/command_line.cpp
Normal file
35
src/common/utils/command_line.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "command_line.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
#include <shellapi.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
|
||||
namespace utils::command_line
|
||||
{
|
||||
template <typename type, typename deleter>
|
||||
constexpr std::unique_ptr<type, deleter> make_unique_ptr(type* ptr, deleter&& del)
|
||||
{
|
||||
return std::unique_ptr<type, deleter&&>(ptr, std::forward<deleter>(del));
|
||||
}
|
||||
|
||||
const std::vector<std::filesystem::path>& get_args()
|
||||
{
|
||||
static const auto args = []()
|
||||
{
|
||||
auto argc = 0;
|
||||
const auto cmd_line = winrt::check_pointer(::GetCommandLineW());
|
||||
const auto up = make_unique_ptr(winrt::check_pointer(::CommandLineToArgvW(cmd_line, &argc)), ::LocalFree);
|
||||
const auto argv = up.get();
|
||||
|
||||
std::vector<std::filesystem::path> vec(argc);
|
||||
std::transform(argv, argv + argc, vec.begin(), [](const auto* path)
|
||||
{
|
||||
return std::filesystem::path(path);
|
||||
});
|
||||
|
||||
return vec;
|
||||
}();
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
9
src/common/utils/command_line.hpp
Normal file
9
src/common/utils/command_line.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
|
||||
namespace utils::command_line
|
||||
{
|
||||
[[nodiscard]] const std::vector<std::filesystem::path>& get_args();
|
||||
}
|
Reference in New Issue
Block a user