mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
Added non-GUI related upgrades to SDL version
This commit is contained in:
parent
35d17ed179
commit
1cada3948d
80
src/main.cpp
80
src/main.cpp
@ -1,6 +1,11 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "functional"
|
||||||
|
#include "iostream"
|
||||||
|
#include "string"
|
||||||
|
#include "unordered_map"
|
||||||
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "common/memory_patcher.h"
|
#include "common/memory_patcher.h"
|
||||||
#include "emulator.h"
|
#include "emulator.h"
|
||||||
@ -14,26 +19,77 @@ int main(int argc, char* argv[]) {
|
|||||||
SetConsoleOutputCP(CP_UTF8);
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool has_game_argument = false;
|
||||||
|
std::string game_path;
|
||||||
|
|
||||||
|
// Map of argument strings to lambda functions
|
||||||
|
std::unordered_map<std::string, std::function<void(int&)>> arg_map = {
|
||||||
|
{"-h",
|
||||||
|
[&](int&) {
|
||||||
|
std::cout << "Usage: shadps4 [options] <elf or eboot.bin path>\n"
|
||||||
|
"Options:\n"
|
||||||
|
" -g, --game <path|ID> Specify game path to launch\n"
|
||||||
|
" -p, --patch <patch_file> Apply specified patch file\n"
|
||||||
|
" -h, --help Display this help message\n";
|
||||||
|
exit(0);
|
||||||
|
}},
|
||||||
|
{"--help", [&](int& i) { arg_map["-h"](i); }},
|
||||||
|
|
||||||
|
{"-g",
|
||||||
|
[&](int& i) {
|
||||||
|
if (i + 1 < argc) {
|
||||||
|
game_path = argv[++i];
|
||||||
|
has_game_argument = true;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error: Missing argument for -g/--game\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
{"--game", [&](int& i) { arg_map["-g"](i); }},
|
||||||
|
|
||||||
|
{"-p",
|
||||||
|
[&](int& i) {
|
||||||
|
if (i + 1 < argc) {
|
||||||
|
MemoryPatcher::patchFile = argv[++i];
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error: Missing argument for -p/--patch\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
{"--patch", [&](int& i) { arg_map["-p"](i); }},
|
||||||
|
};
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
|
int dummy = 0; // one does not simply pass 0 directly
|
||||||
return -1;
|
arg_map.at("-h")(dummy);
|
||||||
}
|
|
||||||
// check if eboot file exists
|
|
||||||
if (!std::filesystem::exists(argv[1])) {
|
|
||||||
fmt::print("Eboot.bin file not found\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++) {
|
// Parse command-line arguments using the map
|
||||||
std::string curArg = argv[i];
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (curArg == "-p") {
|
std::string cur_arg = argv[i];
|
||||||
std::string patchFile = argv[i + 1];
|
auto it = arg_map.find(cur_arg);
|
||||||
MemoryPatcher::patchFile = patchFile;
|
if (it != arg_map.end()) {
|
||||||
|
it->second(i); // Call the associated lambda function
|
||||||
|
} else if (i == argc - 1 && !has_game_argument) {
|
||||||
|
// Assume the last argument is the game file if not specified via -g/--game
|
||||||
|
game_path = argv[i];
|
||||||
|
has_game_argument = true;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Unknown argument: " << cur_arg << "\n";
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the game path or ID exists
|
||||||
|
if (!has_game_argument || !std::filesystem::exists(game_path)) {
|
||||||
|
std::cerr << "Error: Game file not found\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the emulator with the specified game
|
||||||
Core::Emulator emulator;
|
Core::Emulator emulator;
|
||||||
emulator.Run(argv[1]);
|
emulator.Run(game_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ int main(int argc, char* argv[]) {
|
|||||||
std::cout << "Usage: emulator [options]\n"
|
std::cout << "Usage: emulator [options]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" No arguments: Opens the GUI.\n"
|
" No arguments: Opens the GUI.\n"
|
||||||
" -g, --game <path|ID> Specify game path or ID to launch\n"
|
" -g, --game <path|ID> Specify <eboot.bin or elf path> or <game ID (CUSAXXXXX)> to launch\n"
|
||||||
" -p, --patch <patch_file> Apply specified patch file\n"
|
" -p, --patch <patch_file> Apply specified patch file\n"
|
||||||
" -s, --show-gui Show the GUI\n"
|
" -s, --show-gui Show the GUI\n"
|
||||||
" -h, --help Display this help message\n";
|
" -h, --help Display this help message\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user