2026-03-11 16:50:00 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
2025-07-13 03:25:43 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-08-29 23:35:09 -04:00
|
|
|
|
2015-06-22 20:59:00 -04:00
|
|
|
#include <iostream>
|
2016-04-05 13:29:55 +01:00
|
|
|
#include <memory>
|
2021-12-25 20:27:52 +01:00
|
|
|
#include <regex>
|
2016-09-18 09:38:01 +09:00
|
|
|
#include <string>
|
2026-08-12 18:10:24 +02:00
|
|
|
#include "common/settings_enums.h"
|
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
|
#include <emscripten.h>
|
|
|
|
|
#endif
|
|
|
|
|
#define SDL_MAIN_USE_CALLBACKS 1
|
|
|
|
|
#include <SDL3/SDL_main.h>
|
2015-06-22 20:59:00 -04:00
|
|
|
|
2018-08-15 05:38:37 -04:00
|
|
|
#include <fmt/ostream.h>
|
|
|
|
|
|
2026-03-12 18:29:15 +01:00
|
|
|
#include "common/logging.h"
|
2018-05-23 21:51:49 -04:00
|
|
|
#include "common/scm_rev.h"
|
2021-04-14 16:07:40 -07:00
|
|
|
#include "common/settings.h"
|
2018-05-23 21:51:49 -04:00
|
|
|
#include "common/string_util.h"
|
|
|
|
|
#include "core/core.h"
|
2023-07-02 15:05:35 -04:00
|
|
|
#include "core/core_timing.h"
|
2022-06-16 23:42:39 -04:00
|
|
|
#include "core/cpu_manager.h"
|
2018-09-19 09:09:03 -04:00
|
|
|
#include "core/crypto/key_manager.h"
|
2020-08-27 15:16:47 -04:00
|
|
|
#include "core/file_sys/registered_cache.h"
|
2024-01-16 06:23:01 +01:00
|
|
|
#include "core/file_sys/vfs/vfs_real.h"
|
2024-01-02 18:26:53 -05:00
|
|
|
#include "core/hle/service/am/applet_manager.h"
|
2018-09-19 09:09:03 -04:00
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
2018-05-23 21:51:49 -04:00
|
|
|
#include "core/loader/loader.h"
|
2023-11-12 02:03:01 -05:00
|
|
|
#include "frontend_common/config.h"
|
2020-08-27 15:16:47 -04:00
|
|
|
#include "input_common/main.h"
|
2021-12-25 20:27:52 +01:00
|
|
|
#include "network/network.h"
|
2023-11-12 02:03:01 -05:00
|
|
|
#include "sdl_config.h"
|
2019-01-21 16:38:23 -03:00
|
|
|
#include "video_core/renderer_base.h"
|
2026-05-18 19:07:41 +02:00
|
|
|
#include "yuzu_cmd/emu_window/emu_window_sdl3.h"
|
2026-05-06 03:23:27 +02:00
|
|
|
#ifdef HAS_OPENGL
|
2026-05-18 19:07:41 +02:00
|
|
|
#include "yuzu_cmd/emu_window/emu_window_sdl3_gl.h"
|
2026-05-06 03:23:27 +02:00
|
|
|
#endif
|
2026-05-18 19:07:41 +02:00
|
|
|
#include "yuzu_cmd/emu_window/emu_window_sdl3_null.h"
|
|
|
|
|
#include "yuzu_cmd/emu_window/emu_window_sdl3_vk.h"
|
2015-08-17 18:25:21 -03:00
|
|
|
|
2016-06-08 13:53:41 +08:00
|
|
|
#ifdef _WIN32
|
2017-06-25 02:38:16 +02:00
|
|
|
// windows.h needs to be included before shellapi.h
|
2016-12-03 21:08:02 +01:00
|
|
|
#include <windows.h>
|
2017-06-25 02:38:16 +02:00
|
|
|
#include <shellapi.h>
|
2023-03-01 20:07:59 -05:00
|
|
|
#include "common/windows/timer_resolution.h"
|
2016-06-08 13:53:41 +08:00
|
|
|
#endif
|
|
|
|
|
|
2019-04-15 17:32:47 -04:00
|
|
|
#undef _UNICODE
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-19 20:22:26 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
extern "C" {
|
|
|
|
|
// tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable
|
|
|
|
|
// graphics
|
|
|
|
|
__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
|
|
|
|
|
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-09-18 09:38:01 +09:00
|
|
|
static void PrintHelp(const char* argv0) {
|
|
|
|
|
std::cout << "Usage: " << argv0
|
|
|
|
|
<< " [options] <filename>\n"
|
2023-02-04 11:32:14 -06:00
|
|
|
"-c, --config Load the specified configuration file\n"
|
2018-09-30 14:28:17 -04:00
|
|
|
"-f, --fullscreen Start in fullscreen mode\n"
|
2023-02-04 11:32:14 -06:00
|
|
|
"-g, --game File path of the game to load\n"
|
2016-04-19 02:24:21 +01:00
|
|
|
"-h, --help Display this help and exit\n"
|
2023-02-04 11:32:14 -06:00
|
|
|
"-m, --multiplayer=nick:password@address:port"
|
|
|
|
|
" Nickname, password, address and port for multiplayer\n"
|
2022-03-15 01:05:55 -04:00
|
|
|
"-p, --program Pass following string as arguments to executable\n"
|
2023-02-04 11:32:14 -06:00
|
|
|
"-u, --user Select a specific user profile from 0 to 7\n"
|
2025-07-13 03:25:43 +02:00
|
|
|
"-d, --debug Run the GDB stub on a port from 1 to 65535\n"
|
2023-02-04 11:32:14 -06:00
|
|
|
"-v, --version Output version information and exit\n";
|
2016-04-19 02:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-18 09:38:01 +09:00
|
|
|
static void PrintVersion() {
|
2025-07-19 00:12:21 -04:00
|
|
|
std::cout << "Eden " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl;
|
2015-06-22 20:59:00 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-25 20:27:52 +01:00
|
|
|
static void OnStateChanged(const Network::RoomMember::State& state) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case Network::RoomMember::State::Idle:
|
|
|
|
|
LOG_DEBUG(Network, "Network is idle");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::State::Joining:
|
|
|
|
|
LOG_DEBUG(Network, "Connection sequence to room started");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::State::Joined:
|
|
|
|
|
LOG_DEBUG(Network, "Successfully joined to the room");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::State::Moderator:
|
|
|
|
|
LOG_DEBUG(Network, "Successfully joined the room as a moderator");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OnNetworkError(const Network::RoomMember::Error& error) {
|
|
|
|
|
switch (error) {
|
|
|
|
|
case Network::RoomMember::Error::LostConnection:
|
|
|
|
|
LOG_DEBUG(Network, "Lost connection to the room");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::CouldNotConnect:
|
|
|
|
|
LOG_ERROR(Network, "Error: Could not connect");
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::NameCollision:
|
|
|
|
|
LOG_ERROR(
|
|
|
|
|
Network,
|
|
|
|
|
"You tried to use the same nickname as another user that is connected to the Room");
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
2022-07-30 05:58:23 +02:00
|
|
|
case Network::RoomMember::Error::IpCollision:
|
|
|
|
|
LOG_ERROR(Network, "You tried to use the same fake IP-Address as another user that is "
|
2021-12-25 20:27:52 +01:00
|
|
|
"connected to the Room");
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::WrongPassword:
|
|
|
|
|
LOG_ERROR(Network, "Room replied with: Wrong password");
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::WrongVersion:
|
|
|
|
|
LOG_ERROR(Network,
|
|
|
|
|
"You are using a different version than the room you are trying to connect to");
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::RoomIsFull:
|
|
|
|
|
LOG_ERROR(Network, "The room is full");
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::HostKicked:
|
|
|
|
|
LOG_ERROR(Network, "You have been kicked by the host");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::HostBanned:
|
|
|
|
|
LOG_ERROR(Network, "You have been banned by the host");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::UnknownError:
|
|
|
|
|
LOG_ERROR(Network, "UnknownError");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::PermissionDenied:
|
|
|
|
|
LOG_ERROR(Network, "PermissionDenied");
|
|
|
|
|
break;
|
|
|
|
|
case Network::RoomMember::Error::NoSuchUser:
|
|
|
|
|
LOG_ERROR(Network, "NoSuchUser");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OnMessageReceived(const Network::ChatEntry& msg) {
|
|
|
|
|
std::cout << std::endl << msg.nickname << ": " << msg.message << std::endl << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OnStatusMessageReceived(const Network::StatusMessageEntry& msg) {
|
2025-07-13 03:25:43 +02:00
|
|
|
std::string message = [&]() {
|
|
|
|
|
switch (msg.type) {
|
|
|
|
|
case Network::IdMemberJoin:
|
|
|
|
|
return fmt::format("{} has joined", msg.nickname);
|
|
|
|
|
case Network::IdMemberLeave:
|
|
|
|
|
return fmt::format("{} has left", msg.nickname);
|
|
|
|
|
case Network::IdMemberKicked:
|
|
|
|
|
return fmt::format("{} has been kicked", msg.nickname);
|
|
|
|
|
case Network::IdMemberBanned:
|
|
|
|
|
return fmt::format("{} has been banned", msg.nickname);
|
|
|
|
|
case Network::IdAddressUnbanned:
|
|
|
|
|
return fmt::format("{} has been unbanned", msg.nickname);
|
|
|
|
|
default:
|
|
|
|
|
return std::string{};
|
|
|
|
|
}
|
|
|
|
|
}();
|
2021-12-25 20:27:52 +01:00
|
|
|
if (!message.empty())
|
|
|
|
|
std::cout << std::endl << "* " << message << std::endl << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 18:10:24 +02:00
|
|
|
struct SdlState {
|
|
|
|
|
Core::System system{};
|
|
|
|
|
std::unique_ptr<EmuWindow_SDL3> emu_window;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern "C" SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
|
|
|
|
|
SdlState* state = new SdlState();
|
|
|
|
|
|
2022-12-24 03:39:59 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
|
|
|
|
freopen("CONOUT$", "wb", stdout);
|
|
|
|
|
freopen("CONOUT$", "wb", stderr);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-08-13 18:39:45 +00:00
|
|
|
Common::Log::Initialize();
|
|
|
|
|
Common::Log::SetColorConsoleBackendEnabled(true);
|
2022-03-28 23:14:42 -04:00
|
|
|
Common::Log::Start();
|
2018-07-27 23:55:23 -04:00
|
|
|
|
2015-06-22 20:59:00 -04:00
|
|
|
int option_index = 0;
|
2016-06-08 13:53:41 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
int argc_w;
|
|
|
|
|
auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
|
|
|
|
|
if (argv_w == nullptr) {
|
2018-07-02 10:13:26 -06:00
|
|
|
LOG_CRITICAL(Frontend, "Failed to get command line arguments");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2016-06-08 13:53:41 +08:00
|
|
|
}
|
|
|
|
|
#endif
|
2016-11-04 23:14:38 -04:00
|
|
|
std::string filepath;
|
2025-07-13 03:25:43 +02:00
|
|
|
std::optional<std::string> config_path{};
|
2022-03-15 01:05:55 -04:00
|
|
|
std::string program_args;
|
2025-07-13 03:25:43 +02:00
|
|
|
std::optional<int> selected_user{};
|
|
|
|
|
std::optional<u16> override_gdb_port{};
|
2021-12-25 20:27:52 +01:00
|
|
|
bool use_multiplayer = false;
|
2018-04-21 13:22:34 +05:30
|
|
|
bool fullscreen = false;
|
2026-07-25 22:20:31 +02:00
|
|
|
bool force_null_render = false;
|
|
|
|
|
bool force_single_core = false;
|
2021-12-25 20:27:52 +01:00
|
|
|
std::string nickname{};
|
|
|
|
|
std::string password{};
|
|
|
|
|
std::string address{};
|
2026-03-11 16:50:00 +01:00
|
|
|
std::string input_profile{};
|
2026-07-25 22:20:31 +02:00
|
|
|
std::optional<std::string> log_filter{};
|
2021-12-25 20:27:52 +01:00
|
|
|
u16 port = Network::DefaultRoomPort;
|
2018-04-21 13:22:34 +05:30
|
|
|
|
2016-09-18 18:01:46 -07:00
|
|
|
static struct option long_options[] = {
|
2022-03-15 01:05:55 -04:00
|
|
|
// clang-format off
|
2025-07-13 03:25:43 +02:00
|
|
|
{"debug", no_argument, 0, 'd'},
|
2023-02-04 11:32:14 -06:00
|
|
|
{"config", required_argument, 0, 'c'},
|
2020-12-19 19:19:42 +01:00
|
|
|
{"fullscreen", no_argument, 0, 'f'},
|
|
|
|
|
{"help", no_argument, 0, 'h'},
|
2023-02-04 11:32:14 -06:00
|
|
|
{"game", required_argument, 0, 'g'},
|
|
|
|
|
{"multiplayer", required_argument, 0, 'm'},
|
2020-12-19 19:19:42 +01:00
|
|
|
{"program", optional_argument, 0, 'p'},
|
2023-02-04 11:32:14 -06:00
|
|
|
{"user", required_argument, 0, 'u'},
|
|
|
|
|
{"version", no_argument, 0, 'v'},
|
2026-03-11 16:50:00 +01:00
|
|
|
{"input-profile", no_argument, 0, 'i'},
|
2026-07-25 22:20:31 +02:00
|
|
|
{"null-render", no_argument, 0, 'n'},
|
|
|
|
|
{"singlecore", no_argument, 0, 's'},
|
|
|
|
|
{"filter", no_argument, 0, 'x'},
|
2020-12-19 19:19:42 +01:00
|
|
|
{0, 0, 0, 0},
|
2022-03-15 01:05:55 -04:00
|
|
|
// clang-format on
|
2016-09-18 18:01:46 -07:00
|
|
|
};
|
2015-06-22 20:59:00 -04:00
|
|
|
|
|
|
|
|
while (optind < argc) {
|
2026-03-11 16:50:00 +01:00
|
|
|
int arg = getopt_long(argc, argv, "g:fhvcip::c:u:d:", long_options, &option_index);
|
2015-06-22 20:59:00 -04:00
|
|
|
if (arg != -1) {
|
2025-10-21 21:39:09 +02:00
|
|
|
switch (char(arg)) {
|
2025-07-13 03:25:43 +02:00
|
|
|
case 'd':
|
2025-10-21 21:39:09 +02:00
|
|
|
override_gdb_port = uint16_t(atoi(optarg));
|
2025-07-13 03:25:43 +02:00
|
|
|
break;
|
2023-02-04 11:32:14 -06:00
|
|
|
case 'c':
|
|
|
|
|
config_path = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
fullscreen = true;
|
|
|
|
|
LOG_INFO(Frontend, "Starting in fullscreen mode...");
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
PrintHelp(argv[0]);
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2025-10-21 21:39:09 +02:00
|
|
|
case 'g':
|
|
|
|
|
filepath = std::string(optarg);
|
2023-02-04 11:32:14 -06:00
|
|
|
break;
|
2026-03-11 16:50:00 +01:00
|
|
|
case 'i': {
|
|
|
|
|
input_profile = std::string(optarg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-12-25 20:27:52 +01:00
|
|
|
case 'm': {
|
|
|
|
|
use_multiplayer = true;
|
|
|
|
|
const std::string str_arg(optarg);
|
|
|
|
|
// regex to check if the format is nickname:password@ip:port
|
|
|
|
|
// with optional :password
|
|
|
|
|
const std::regex re("^([^:]+)(?::(.+))?@([^:]+)(?::([0-9]+))?$");
|
|
|
|
|
if (!std::regex_match(str_arg, re)) {
|
|
|
|
|
std::cout << "Wrong format for option --multiplayer\n";
|
|
|
|
|
PrintHelp(argv[0]);
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-12-25 20:27:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::smatch match;
|
|
|
|
|
std::regex_search(str_arg, match, re);
|
|
|
|
|
ASSERT(match.size() == 5);
|
|
|
|
|
nickname = match[1];
|
|
|
|
|
password = match[2];
|
|
|
|
|
address = match[3];
|
2023-09-13 13:36:09 -04:00
|
|
|
if (!match[4].str().empty()) {
|
2026-07-25 22:20:31 +02:00
|
|
|
port = u16(std::strtoul(match[4].str().c_str(), nullptr, 0));
|
2023-09-13 13:36:09 -04:00
|
|
|
}
|
2021-12-25 20:27:52 +01:00
|
|
|
std::regex nickname_re("^[a-zA-Z0-9._\\- ]+$");
|
|
|
|
|
if (!std::regex_match(nickname, nickname_re)) {
|
2026-07-25 22:20:31 +02:00
|
|
|
LOG_ERROR(Frontend, "Nickname is not valid. Must be 4 to 20 alphanumeric characters");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-12-25 20:27:52 +01:00
|
|
|
}
|
|
|
|
|
if (address.empty()) {
|
2026-07-25 22:20:31 +02:00
|
|
|
LOG_ERROR(Frontend, "Address to room must not be empty");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-12-25 20:27:52 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-04 11:32:14 -06:00
|
|
|
case 'p':
|
|
|
|
|
program_args = argv[optind];
|
|
|
|
|
++optind;
|
2018-04-21 13:22:34 +05:30
|
|
|
break;
|
2023-02-04 11:32:14 -06:00
|
|
|
case 'u':
|
|
|
|
|
selected_user = atoi(optarg);
|
2023-05-25 20:07:52 +02:00
|
|
|
break;
|
2016-04-19 02:24:21 +01:00
|
|
|
case 'v':
|
|
|
|
|
PrintVersion();
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2026-07-25 22:20:31 +02:00
|
|
|
case 'n':
|
|
|
|
|
force_null_render = true;
|
|
|
|
|
break;
|
|
|
|
|
case 's':
|
|
|
|
|
force_single_core = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
log_filter = argv[optind];
|
|
|
|
|
++optind;
|
|
|
|
|
break;
|
2015-06-22 20:59:00 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-06-08 13:53:41 +08:00
|
|
|
#ifdef _WIN32
|
2016-11-04 23:14:38 -04:00
|
|
|
filepath = Common::UTF16ToUTF8(argv_w[optind]);
|
2016-06-08 13:53:41 +08:00
|
|
|
#else
|
2016-11-04 23:14:38 -04:00
|
|
|
filepath = argv[optind];
|
2016-06-08 13:53:41 +08:00
|
|
|
#endif
|
2015-06-22 20:59:00 -04:00
|
|
|
optind++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 02:03:01 -05:00
|
|
|
SdlConfig config{config_path};
|
2022-03-15 01:05:55 -04:00
|
|
|
|
2022-06-16 23:07:09 +03:00
|
|
|
// apply the log_filter setting
|
|
|
|
|
// the logger was initialized before and doesn't pick up the filter on its own
|
|
|
|
|
Common::Log::Filter filter;
|
2026-07-25 22:20:31 +02:00
|
|
|
filter.ParseFilterString(log_filter.value_or(Settings::values.log_filter.GetValue()));
|
2022-06-16 23:07:09 +03:00
|
|
|
Common::Log::SetGlobalFilter(filter);
|
|
|
|
|
|
2022-03-15 01:05:55 -04:00
|
|
|
if (!program_args.empty()) {
|
|
|
|
|
Settings::values.program_args = program_args;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 16:50:00 +01:00
|
|
|
if (!input_profile.empty()) {
|
|
|
|
|
auto& players = Settings::values.players.GetValue();
|
|
|
|
|
players[0].profile_name = input_profile;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-04 11:32:14 -06:00
|
|
|
if (selected_user.has_value()) {
|
|
|
|
|
Settings::values.current_user = std::clamp(*selected_user, 0, 7);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-13 03:25:43 +02:00
|
|
|
if (override_gdb_port.has_value()) {
|
|
|
|
|
Settings::values.use_gdbstub = true;
|
|
|
|
|
Settings::values.gdbstub_port = *override_gdb_port;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-25 22:20:31 +02:00
|
|
|
if (force_single_core) {
|
|
|
|
|
Settings::values.use_multi_core = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (force_null_render) {
|
|
|
|
|
Settings::values.renderer_backend = Settings::RendererBackend::Null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 13:53:41 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
LocalFree(argv_w);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-11-04 23:14:38 -04:00
|
|
|
if (filepath.empty()) {
|
2018-07-02 10:13:26 -06:00
|
|
|
LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2014-05-04 15:47:42 -07:00
|
|
|
}
|
2014-05-17 11:59:18 -04:00
|
|
|
|
2026-08-12 18:10:24 +02:00
|
|
|
state->system.Initialize();
|
2022-09-10 01:48:15 -07:00
|
|
|
|
2021-10-14 14:31:28 -04:00
|
|
|
InputCommon::InputSubsystem input_subsystem{};
|
2020-11-27 10:50:48 -05:00
|
|
|
|
2016-04-11 15:20:05 +02:00
|
|
|
// Apply the command line arguments
|
2026-08-12 18:10:24 +02:00
|
|
|
state->system.ApplySettings();
|
2020-02-17 15:35:14 -05:00
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
switch (Settings::values.renderer_backend.GetValue()) {
|
2026-05-06 03:23:27 +02:00
|
|
|
#ifdef HAS_OPENGL
|
2026-01-18 12:33:00 +01:00
|
|
|
case Settings::RendererBackend::OpenGL_GLSL:
|
|
|
|
|
case Settings::RendererBackend::OpenGL_GLASM:
|
|
|
|
|
case Settings::RendererBackend::OpenGL_SPIRV:
|
2026-08-12 18:10:24 +02:00
|
|
|
state->emu_window = std::make_unique<EmuWindow_SDL3_GL>(&input_subsystem, state->system, fullscreen);
|
2020-01-21 16:40:53 -03:00
|
|
|
break;
|
2026-05-06 03:23:27 +02:00
|
|
|
#endif
|
2020-01-21 16:40:53 -03:00
|
|
|
case Settings::RendererBackend::Vulkan:
|
2026-08-12 18:10:24 +02:00
|
|
|
state->emu_window = std::make_unique<EmuWindow_SDL3_VK>(&input_subsystem, state->system, fullscreen);
|
2020-01-21 16:40:53 -03:00
|
|
|
break;
|
2022-11-27 20:37:37 -05:00
|
|
|
case Settings::RendererBackend::Null:
|
2026-08-12 18:10:24 +02:00
|
|
|
state->emu_window = std::make_unique<EmuWindow_SDL3_Null>(&input_subsystem, state->system, fullscreen);
|
2022-11-27 20:37:37 -05:00
|
|
|
break;
|
2026-05-06 03:23:27 +02:00
|
|
|
default:
|
|
|
|
|
LOG_CRITICAL(Frontend, "Invalid renderer backend");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2020-01-21 16:40:53 -03:00
|
|
|
}
|
2014-06-18 18:58:09 -04:00
|
|
|
|
2023-07-02 15:05:35 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
Common::Windows::SetCurrentTimerResolutionToMaximum();
|
2026-08-12 18:10:24 +02:00
|
|
|
state->system.CoreTiming().SetTimerResolutionNs(Common::Windows::GetCurrentTimerResolution());
|
2023-07-02 15:05:35 -04:00
|
|
|
#endif
|
|
|
|
|
|
2026-08-12 18:10:24 +02:00
|
|
|
state->system.SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>());
|
|
|
|
|
state->system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>());
|
|
|
|
|
state->system.GetFileSystemController().CreateFactories(*state->system.GetFilesystem());
|
|
|
|
|
state->system.GetUserChannel().clear();
|
2016-11-26 23:13:40 -05:00
|
|
|
|
2024-01-02 18:26:53 -05:00
|
|
|
Service::AM::FrontendAppletParameters load_parameters{
|
|
|
|
|
.applet_id = Service::AM::AppletId::Application,
|
|
|
|
|
};
|
2026-08-12 18:10:24 +02:00
|
|
|
const Core::SystemResultStatus load_result = state->system.Load(*state->emu_window, filepath, load_parameters);
|
2016-11-04 23:14:38 -04:00
|
|
|
switch (load_result) {
|
2026-08-12 18:10:24 +02:00
|
|
|
case Core::SystemResultStatus::Success:
|
|
|
|
|
break; // Expected case
|
2021-10-14 18:14:40 -04:00
|
|
|
case Core::SystemResultStatus::ErrorGetLoader:
|
2019-05-28 22:10:51 -04:00
|
|
|
LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath);
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-10-14 18:14:40 -04:00
|
|
|
case Core::SystemResultStatus::ErrorLoader:
|
2018-07-02 10:13:26 -06:00
|
|
|
LOG_CRITICAL(Frontend, "Failed to load ROM!");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-10-14 18:14:40 -04:00
|
|
|
case Core::SystemResultStatus::ErrorNotInitialized:
|
2018-07-02 10:13:26 -06:00
|
|
|
LOG_CRITICAL(Frontend, "CPUCore not initialized");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-10-14 18:14:40 -04:00
|
|
|
case Core::SystemResultStatus::ErrorVideoCore:
|
2018-08-03 12:55:58 -04:00
|
|
|
LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2018-08-09 21:06:44 -04:00
|
|
|
default:
|
2026-08-12 18:10:24 +02:00
|
|
|
const u16 loader_id = u16(Core::SystemResultStatus::ErrorLoader);
|
|
|
|
|
const u16 error_id = u16(load_result) - loader_id;
|
|
|
|
|
LOG_CRITICAL(Frontend,
|
|
|
|
|
"While attempting to load the ROM requested, an error occurred. Please "
|
|
|
|
|
"refer to the Eden wiki for more information or the Eden discord for "
|
|
|
|
|
"additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}",
|
|
|
|
|
loader_id, error_id, Loader::ResultStatus(error_id));
|
|
|
|
|
return SDL_APP_FAILURE;
|
2014-03-31 22:25:55 -04:00
|
|
|
}
|
2014-04-07 00:53:47 -04:00
|
|
|
|
2021-12-25 20:27:52 +01:00
|
|
|
if (use_multiplayer) {
|
2025-06-05 18:59:47 +00:00
|
|
|
if (auto member = Network::GetRoomMember().lock()) {
|
2024-01-15 23:26:53 +00:00
|
|
|
member->BindOnChatMessageReceived(OnMessageReceived);
|
2021-12-25 20:27:52 +01:00
|
|
|
member->BindOnStatusMessageReceived(OnStatusMessageReceived);
|
|
|
|
|
member->BindOnStateChanged(OnStateChanged);
|
|
|
|
|
member->BindOnError(OnNetworkError);
|
2026-08-12 18:10:24 +02:00
|
|
|
LOG_DEBUG(Network, "Start connection to {}:{} with nickname {}", address, port, nickname);
|
2022-07-30 05:58:23 +02:00
|
|
|
member->Join(nickname, address.c_str(), port, 0, Network::NoPreferredIP, password);
|
2021-12-25 20:27:52 +01:00
|
|
|
} else {
|
|
|
|
|
LOG_ERROR(Network, "Could not access RoomMember");
|
2026-08-12 18:10:24 +02:00
|
|
|
return SDL_APP_FAILURE;
|
2021-12-25 20:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 20:58:49 -06:00
|
|
|
// Core is loaded, start the GPU (makes the GPU contexts current to this thread)
|
2026-08-12 18:10:24 +02:00
|
|
|
state->system.GPU().Start();
|
|
|
|
|
state->system.GetCpuManager().OnGpuReady();
|
2020-02-17 15:35:14 -05:00
|
|
|
|
2021-05-27 23:29:22 -04:00
|
|
|
if (Settings::values.use_disk_shader_cache.GetValue()) {
|
2026-08-12 18:10:24 +02:00
|
|
|
state->system.Renderer().ReadRasterizer()->LoadDiskResources(
|
|
|
|
|
state->system.GetApplicationProcessProgramID(), std::stop_token{},
|
2021-05-27 23:29:22 -04:00
|
|
|
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
|
|
|
|
|
}
|
2020-03-24 22:57:36 -06:00
|
|
|
|
2026-08-12 18:10:24 +02:00
|
|
|
// don't do anything, SDL3 already exists for us :D
|
|
|
|
|
state->system.RegisterExitCallback([] {});
|
|
|
|
|
void(state->system.Run());
|
|
|
|
|
if (state->system.DebuggerEnabled())
|
|
|
|
|
state->system.InitializeDebugger();
|
|
|
|
|
return SDL_APP_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
extern "C" SDL_AppResult SDL_AppIterate(void *appstate) {
|
|
|
|
|
SdlState *state = (SdlState *)appstate;
|
|
|
|
|
return state->emu_window->IsOpen() ? SDL_APP_CONTINUE : SDL_APP_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
extern "C" SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|
|
|
|
SdlState *state = (SdlState *)appstate;
|
|
|
|
|
state->emu_window->OnEvent(*event);
|
|
|
|
|
return SDL_APP_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
extern "C" void SDL_AppQuit(void *appstate, SDL_AppResult result) {
|
|
|
|
|
SdlState *state = (SdlState *)appstate;
|
|
|
|
|
state->system.DetachDebugger();
|
|
|
|
|
void(state->system.Pause());
|
|
|
|
|
state->system.ShutdownMainProcess();
|
|
|
|
|
delete state;
|
2013-08-29 23:35:09 -04:00
|
|
|
}
|
2025-11-11 06:22:33 +01:00
|
|
|
|
|
|
|
|
#define VMA_IMPLEMENTATION
|
|
|
|
|
#include "video_core/vulkan_common/vma.h"
|