From 9f1605a2e75a7983226ccdbdde736663e38bcdc7 Mon Sep 17 00:00:00 2001 From: Adrian <78108584+AdrianCassar@users.noreply.github.com> Date: Tue, 17 Oct 2023 18:36:51 +0100 Subject: [PATCH] launch module fallback --- src/xenia/emulator.cc | 53 ++++++++++++++++++++++++++----------------- src/xenia/emulator.h | 2 ++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index dc2990ade..da80cd588 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -329,7 +329,10 @@ const std::unique_ptr Emulator::CreateVfsDeviceBasedOnPath( auto parent_path = path.parent_path(); return std::make_unique( mount_path, parent_path, !cvars::allow_game_relative_writes); - } else if (extension == ".7z" || extension == ".zip" || extension == ".rar" || + } else if (extension == ".zar") { + return std::make_unique(mount_path, path); + } + else if (extension == ".7z" || extension == ".zip" || extension == ".rar" || extension == ".tar" || extension == ".gz") { xe::ShowSimpleMessageBox( xe::SimpleMessageBoxType::Error, @@ -422,6 +425,7 @@ X_STATUS Emulator::LaunchPath(const std::filesystem::path& path) { return LaunchXexFile(path); } else if (extension == ".zar") { // Assume a disc image. + MountPath(path, "\\Device\\Cdrom0"); return LaunchDiscArchive(path); } else { // Assume a disc image. @@ -446,35 +450,42 @@ X_STATUS Emulator::LaunchXexFile(const std::filesystem::path& path) { } X_STATUS Emulator::LaunchDiscImage(const std::filesystem::path& path) { - auto module_path(FindLaunchModule()); - return CompleteLaunch(path, module_path); + std::string module_path = FindLaunchModule(); + X_STATUS result = CompleteLaunch(path, module_path); + + if (result == X_STATUS_NOT_FOUND && !cvars::launch_module.empty()) { + return LaunchDefaultModule(path); + } + + return result; } X_STATUS Emulator::LaunchDiscArchive(const std::filesystem::path& path) { - auto mount_path = "\\Device\\Cdrom0"; + std::string module_path = FindLaunchModule(); + X_STATUS result = CompleteLaunch(path, module_path); - // Register the disc image in the virtual filesystem. - auto device = std::make_unique(mount_path, path); - if (!device->Initialize()) { - xe::FatalError("Unable to mount disc image; file not found or corrupt."); - return X_STATUS_NO_SUCH_FILE; - } - if (!file_system_->RegisterDevice(std::move(device))) { - xe::FatalError("Unable to register disc image."); - return X_STATUS_NO_SUCH_FILE; + if (result == X_STATUS_NOT_FOUND && !cvars::launch_module.empty()) { + return LaunchDefaultModule(path); } - // Create symlinks to the device. - file_system_->RegisterSymbolicLink("game:", mount_path); - file_system_->RegisterSymbolicLink("d:", mount_path); - - // Launch the game. - auto module_path(FindLaunchModule()); - return CompleteLaunch(path, module_path); + return result; } X_STATUS Emulator::LaunchStfsContainer(const std::filesystem::path& path) { - auto module_path(FindLaunchModule()); + std::string module_path = FindLaunchModule(); + X_STATUS result = CompleteLaunch(path, module_path); + + if (result == X_STATUS_NOT_FOUND && !cvars::launch_module.empty()) { + return LaunchDefaultModule(path); + } + + return result; +} + +X_STATUS Emulator::LaunchDefaultModule(const std::filesystem::path& path) { + cvars::launch_module = ""; + std::string module_path = FindLaunchModule(); + return CompleteLaunch(path, module_path); } diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index 32070d8a6..2e96f1d5f 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -202,6 +202,8 @@ class Emulator { // Launches a game from an STFS container file. X_STATUS LaunchStfsContainer(const std::filesystem::path& path); + X_STATUS LaunchDefaultModule(const std::filesystem::path& path); + // Extract content of package to content specific directory. X_STATUS InstallContentPackage(const std::filesystem::path& path);