[Emulator] Improvements to launch_data
Added support for autoload titles on boot with: - Specific launch data - Specific xex - Restarting into packages: XamContentLaunchImageFromFileInternal
This commit is contained in:
parent
7e7784347b
commit
6f287a9597
|
@ -34,6 +34,7 @@
|
||||||
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
|
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
|
||||||
#include "xenia/gpu/graphics_system.h"
|
#include "xenia/gpu/graphics_system.h"
|
||||||
#include "xenia/hid/input_system.h"
|
#include "xenia/hid/input_system.h"
|
||||||
|
#include "xenia/kernel/xam/xam_module.h"
|
||||||
#include "xenia/ui/file_picker.h"
|
#include "xenia/ui/file_picker.h"
|
||||||
#include "xenia/ui/graphics_provider.h"
|
#include "xenia/ui/graphics_provider.h"
|
||||||
#include "xenia/ui/imgui_dialog.h"
|
#include "xenia/ui/imgui_dialog.h"
|
||||||
|
@ -1575,6 +1576,12 @@ xe::X_STATUS EmulatorWindow::RunTitle(std::filesystem::path path_to_file) {
|
||||||
"Failed to launch title.\n\nCheck xenia.log for technical details.");
|
"Failed to launch title.\n\nCheck xenia.log for technical details.");
|
||||||
} else {
|
} else {
|
||||||
AddRecentlyLaunchedTitle(path_to_file, emulator_->title_name());
|
AddRecentlyLaunchedTitle(path_to_file, emulator_->title_name());
|
||||||
|
|
||||||
|
auto xam =
|
||||||
|
emulator_->kernel_state()->GetKernelModule<kernel::xam::XamModule>(
|
||||||
|
"xam.xex");
|
||||||
|
|
||||||
|
xam->loader_data().host_path = xe::path_to_utf8(abs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "xenia/config.h"
|
#include "xenia/config.h"
|
||||||
#include "xenia/debug/ui/debug_window.h"
|
#include "xenia/debug/ui/debug_window.h"
|
||||||
#include "xenia/emulator.h"
|
#include "xenia/emulator.h"
|
||||||
|
#include "xenia/kernel/xam/xam_module.h"
|
||||||
#include "xenia/ui/file_picker.h"
|
#include "xenia/ui/file_picker.h"
|
||||||
#include "xenia/ui/window.h"
|
#include "xenia/ui/window.h"
|
||||||
#include "xenia/ui/window_listener.h"
|
#include "xenia/ui/window_listener.h"
|
||||||
|
@ -624,6 +625,20 @@ void EmulatorApp::EmulatorThread() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto xam = emulator_->kernel_state()->GetKernelModule<kernel::xam::XamModule>(
|
||||||
|
"xam.xex");
|
||||||
|
|
||||||
|
if (xam) {
|
||||||
|
xam->LoadLoaderData();
|
||||||
|
|
||||||
|
if (xam->loader_data().launch_data_present) {
|
||||||
|
const std::filesystem::path host_path = xam->loader_data().host_path;
|
||||||
|
app_context().CallInUIThread([this, host_path]() {
|
||||||
|
return emulator_window_->RunTitle(host_path);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now, we're going to use this thread to drive events related to emulation.
|
// Now, we're going to use this thread to drive events related to emulation.
|
||||||
while (!emulator_thread_quit_requested_.load(std::memory_order_relaxed)) {
|
while (!emulator_thread_quit_requested_.load(std::memory_order_relaxed)) {
|
||||||
xe::threading::Wait(emulator_thread_event_.get(), false);
|
xe::threading::Wait(emulator_thread_event_.get(), false);
|
||||||
|
|
|
@ -53,8 +53,8 @@
|
||||||
#include "xenia/vfs/devices/disc_zarchive_device.h"
|
#include "xenia/vfs/devices/disc_zarchive_device.h"
|
||||||
#include "xenia/vfs/devices/host_path_device.h"
|
#include "xenia/vfs/devices/host_path_device.h"
|
||||||
#include "xenia/vfs/devices/null_device.h"
|
#include "xenia/vfs/devices/null_device.h"
|
||||||
#include "xenia/vfs/virtual_file_system.h"
|
|
||||||
#include "xenia/vfs/devices/xcontent_container_device.h"
|
#include "xenia/vfs/devices/xcontent_container_device.h"
|
||||||
|
#include "xenia/vfs/virtual_file_system.h"
|
||||||
|
|
||||||
#if XE_ARCH_AMD64
|
#if XE_ARCH_AMD64
|
||||||
#include "xenia/cpu/backend/x64/x64_backend.h"
|
#include "xenia/cpu/backend/x64/x64_backend.h"
|
||||||
|
@ -294,7 +294,6 @@ X_STATUS Emulator::Setup(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize emulator fallback exception handling last.
|
// Initialize emulator fallback exception handling last.
|
||||||
ExceptionHandler::Install(Emulator::ExceptionCallbackThunk, this);
|
ExceptionHandler::Install(Emulator::ExceptionCallbackThunk, this);
|
||||||
|
|
||||||
|
@ -331,12 +330,12 @@ const std::unique_ptr<vfs::Device> Emulator::CreateVfsDeviceBasedOnPath(
|
||||||
mount_path, parent_path, !cvars::allow_game_relative_writes);
|
mount_path, parent_path, !cvars::allow_game_relative_writes);
|
||||||
} else if (extension == ".zar") {
|
} else if (extension == ".zar") {
|
||||||
return std::make_unique<vfs::DiscZarchiveDevice>(mount_path, path);
|
return std::make_unique<vfs::DiscZarchiveDevice>(mount_path, path);
|
||||||
}
|
} else if (extension == ".7z" || extension == ".zip" || extension == ".rar" ||
|
||||||
else if (extension == ".7z" || extension == ".zip" || extension == ".rar" ||
|
|
||||||
extension == ".tar" || extension == ".gz") {
|
extension == ".tar" || extension == ".gz") {
|
||||||
xe::ShowSimpleMessageBox(
|
xe::ShowSimpleMessageBox(
|
||||||
xe::SimpleMessageBoxType::Error,
|
xe::SimpleMessageBoxType::Error,
|
||||||
fmt::format("Unsupported format!"
|
fmt::format(
|
||||||
|
"Unsupported format!"
|
||||||
"Xenia does not support running software in an archived format."));
|
"Xenia does not support running software in an archived format."));
|
||||||
}
|
}
|
||||||
return std::make_unique<vfs::DiscImageDevice>(mount_path, path);
|
return std::make_unique<vfs::DiscImageDevice>(mount_path, path);
|
||||||
|
@ -399,13 +398,13 @@ X_STATUS Emulator::MountPath(const std::filesystem::path& path,
|
||||||
return X_STATUS_NO_SUCH_FILE;
|
return X_STATUS_NO_SUCH_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_system_->UnregisterSymbolicLink("d:");
|
file_system_->UnregisterSymbolicLink(kDefaultPartitonSymbolicLink);
|
||||||
file_system_->UnregisterSymbolicLink("game:");
|
file_system_->UnregisterSymbolicLink(kDefaultGameSymbolicLink);
|
||||||
file_system_->UnregisterSymbolicLink("plugins:");
|
file_system_->UnregisterSymbolicLink("plugins:");
|
||||||
|
|
||||||
// Create symlinks to the device.
|
// Create symlinks to the device.
|
||||||
file_system_->RegisterSymbolicLink("game:", mount_path);
|
file_system_->RegisterSymbolicLink(kDefaultGameSymbolicLink, mount_path);
|
||||||
file_system_->RegisterSymbolicLink("d:", mount_path);
|
file_system_->RegisterSymbolicLink(kDefaultPartitonSymbolicLink, mount_path);
|
||||||
|
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -763,9 +762,12 @@ bool Emulator::ExceptionCallback(Exception* ex) {
|
||||||
std::string crash_msg;
|
std::string crash_msg;
|
||||||
crash_msg.append("==== CRASH DUMP ====\n");
|
crash_msg.append("==== CRASH DUMP ====\n");
|
||||||
crash_msg.append(fmt::format("Thread ID (Host: 0x{:08X} / Guest: 0x{:08X})\n",
|
crash_msg.append(fmt::format("Thread ID (Host: 0x{:08X} / Guest: 0x{:08X})\n",
|
||||||
current_thread->thread()->system_id(), current_thread->thread_id()));
|
current_thread->thread()->system_id(),
|
||||||
crash_msg.append(fmt::format("Thread Handle: 0x{:08X}\n", current_thread->handle()));
|
current_thread->thread_id()));
|
||||||
crash_msg.append(fmt::format("PC: 0x{:08X}\n",
|
crash_msg.append(
|
||||||
|
fmt::format("Thread Handle: 0x{:08X}\n", current_thread->handle()));
|
||||||
|
crash_msg.append(
|
||||||
|
fmt::format("PC: 0x{:08X}\n",
|
||||||
guest_function->MapMachineCodeToGuestAddress(ex->pc())));
|
guest_function->MapMachineCodeToGuestAddress(ex->pc())));
|
||||||
crash_msg.append("Registers:\n");
|
crash_msg.append("Registers:\n");
|
||||||
for (int i = 0; i < 32; i++) {
|
for (int i = 0; i < 32; i++) {
|
||||||
|
@ -860,6 +862,32 @@ void Emulator::RemoveGameConfigLoadCallback(GameConfigLoadCallback* callback) {
|
||||||
std::string Emulator::FindLaunchModule() {
|
std::string Emulator::FindLaunchModule() {
|
||||||
std::string path("game:\\");
|
std::string path("game:\\");
|
||||||
|
|
||||||
|
auto xam = kernel_state()->GetKernelModule<kernel::xam::XamModule>("xam.xex");
|
||||||
|
|
||||||
|
if (!xam->loader_data().launch_path.empty()) {
|
||||||
|
std::string symbolic_link_path;
|
||||||
|
if (kernel_state_->file_system()->FindSymbolicLink(kDefaultGameSymbolicLink,
|
||||||
|
symbolic_link_path)) {
|
||||||
|
std::filesystem::path file_path = symbolic_link_path;
|
||||||
|
// Remove previous symbolic links.
|
||||||
|
// Some titles can provide root within specific directory.
|
||||||
|
kernel_state_->file_system()->UnregisterSymbolicLink(
|
||||||
|
kDefaultPartitonSymbolicLink);
|
||||||
|
kernel_state_->file_system()->UnregisterSymbolicLink(
|
||||||
|
kDefaultGameSymbolicLink);
|
||||||
|
|
||||||
|
file_path /= std::filesystem::path(xam->loader_data().launch_path);
|
||||||
|
|
||||||
|
kernel_state_->file_system()->RegisterSymbolicLink(
|
||||||
|
kDefaultPartitonSymbolicLink,
|
||||||
|
xe::path_to_utf8(file_path.parent_path()));
|
||||||
|
kernel_state_->file_system()->RegisterSymbolicLink(
|
||||||
|
kDefaultGameSymbolicLink, xe::path_to_utf8(file_path.parent_path()));
|
||||||
|
|
||||||
|
return xe::path_to_utf8(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!cvars::launch_module.empty()) {
|
if (!cvars::launch_module.empty()) {
|
||||||
return path + cvars::launch_module;
|
return path + cvars::launch_module;
|
||||||
}
|
}
|
||||||
|
@ -986,25 +1014,6 @@ X_STATUS Emulator::CompleteLaunch(const std::filesystem::path& path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xam) {
|
|
||||||
const std::filesystem::path launch_data_dir = "launch_data";
|
|
||||||
const std::filesystem::path file_path =
|
|
||||||
launch_data_dir /
|
|
||||||
fmt::format("{:08X}_launch_data.bin", title_id_.value());
|
|
||||||
|
|
||||||
auto file = xe::filesystem::OpenFile(file_path, "rb");
|
|
||||||
if (file) {
|
|
||||||
XELOGI("Found launch_data for {}", title_name_);
|
|
||||||
const uint64_t file_size = std::filesystem::file_size(file_path);
|
|
||||||
xam->loader_data().launch_data_present = true;
|
|
||||||
xam->loader_data().launch_data.resize(file_size);
|
|
||||||
fread(xam->loader_data().launch_data.data(), file_size, 1, file);
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Try and load the resource database (xex only).
|
// Try and load the resource database (xex only).
|
||||||
if (module->title_id()) {
|
if (module->title_id()) {
|
||||||
auto title_id = fmt::format("{:08X}", module->title_id());
|
auto title_id = fmt::format("{:08X}", module->title_id());
|
||||||
|
|
|
@ -52,6 +52,8 @@ class Window;
|
||||||
namespace xe {
|
namespace xe {
|
||||||
|
|
||||||
constexpr fourcc_t kEmulatorSaveSignature = make_fourcc("XSAV");
|
constexpr fourcc_t kEmulatorSaveSignature = make_fourcc("XSAV");
|
||||||
|
static const std::string kDefaultGameSymbolicLink = "GAME:";
|
||||||
|
static const std::string kDefaultPartitonSymbolicLink = "D:";
|
||||||
|
|
||||||
// The main type that runs the whole emulator.
|
// The main type that runs the whole emulator.
|
||||||
// This is responsible for initializing and managing all the various subsystems.
|
// This is responsible for initializing and managing all the various subsystems.
|
||||||
|
|
|
@ -14,10 +14,13 @@
|
||||||
#include "xenia/kernel/user_module.h"
|
#include "xenia/kernel/user_module.h"
|
||||||
#include "xenia/kernel/util/shim_utils.h"
|
#include "xenia/kernel/util/shim_utils.h"
|
||||||
#include "xenia/kernel/xam/xam_content_device.h"
|
#include "xenia/kernel/xam/xam_content_device.h"
|
||||||
|
#include "xenia/kernel/xam/xam_module.h"
|
||||||
#include "xenia/kernel/xam/xam_private.h"
|
#include "xenia/kernel/xam/xam_private.h"
|
||||||
#include "xenia/kernel/xboxkrnl/xboxkrnl_module.h"
|
#include "xenia/kernel/xboxkrnl/xboxkrnl_module.h"
|
||||||
#include "xenia/kernel/xboxkrnl/xboxkrnl_threading.h"
|
#include "xenia/kernel/xboxkrnl/xboxkrnl_threading.h"
|
||||||
#include "xenia/kernel/xenumerator.h"
|
#include "xenia/kernel/xenumerator.h"
|
||||||
|
#include "xenia/ui/imgui_dialog.h"
|
||||||
|
#include "xenia/ui/imgui_drawer.h"
|
||||||
#include "xenia/xbox.h"
|
#include "xenia/xbox.h"
|
||||||
|
|
||||||
DEFINE_int32(
|
DEFINE_int32(
|
||||||
|
@ -498,6 +501,50 @@ dword_result_t XamLoaderGetMediaInfoEx_entry(dword_t unk1, dword_t unk2,
|
||||||
|
|
||||||
DECLARE_XAM_EXPORT1(XamLoaderGetMediaInfoEx, kContent, kStub);
|
DECLARE_XAM_EXPORT1(XamLoaderGetMediaInfoEx, kContent, kStub);
|
||||||
|
|
||||||
|
dword_result_t XamContentLaunchImageFromFileInternal_entry(
|
||||||
|
lpstring_t image_location, lpstring_t xex_name, dword_t unk) {
|
||||||
|
const std::string image_path = image_location;
|
||||||
|
const std::string xex_name_ = xex_name;
|
||||||
|
|
||||||
|
vfs::Entry* entry = kernel_state()->file_system()->ResolvePath(image_path);
|
||||||
|
|
||||||
|
if (!entry) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::filesystem::path host_path =
|
||||||
|
kernel_state()->emulator()->content_root() / entry->name();
|
||||||
|
if (!std::filesystem::exists(host_path)) {
|
||||||
|
vfs::VirtualFileSystem::ExtractContentFile(
|
||||||
|
entry, kernel_state()->emulator()->content_root(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto xam = kernel_state()->GetKernelModule<XamModule>("xam.xex");
|
||||||
|
|
||||||
|
auto& loader_data = xam->loader_data();
|
||||||
|
loader_data.host_path = xe::path_to_utf8(host_path);
|
||||||
|
loader_data.launch_path = xex_name_;
|
||||||
|
|
||||||
|
xam->SaveLoaderData();
|
||||||
|
|
||||||
|
auto display_window = kernel_state()->emulator()->display_window();
|
||||||
|
auto imgui_drawer = kernel_state()->emulator()->imgui_drawer();
|
||||||
|
|
||||||
|
if (display_window && imgui_drawer) {
|
||||||
|
display_window->app_context().CallInUIThreadSynchronous([imgui_drawer]() {
|
||||||
|
xe::ui::ImGuiDialog::ShowMessageBox(
|
||||||
|
imgui_drawer, "Launching new title!",
|
||||||
|
"Launching new title. \nPlease close Xenia and launch it again. Game "
|
||||||
|
"should load automatically.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
kernel_state()->TerminateTitle();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DECLARE_XAM_EXPORT1(XamContentLaunchImageFromFileInternal, kContent, kStub);
|
||||||
|
|
||||||
} // namespace xam
|
} // namespace xam
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
|
@ -291,24 +291,6 @@ dword_result_t XamLoaderSetLaunchData_entry(lpvoid_t data, dword_t size) {
|
||||||
loader_data.launch_data_present = size ? true : false;
|
loader_data.launch_data_present = size ? true : false;
|
||||||
loader_data.launch_data.resize(size);
|
loader_data.launch_data.resize(size);
|
||||||
std::memcpy(loader_data.launch_data.data(), data, size);
|
std::memcpy(loader_data.launch_data.data(), data, size);
|
||||||
|
|
||||||
// Because we have no way to restart game while it is working. Remove as soon
|
|
||||||
// as possible.
|
|
||||||
const std::filesystem::path launch_data_dir = "launch_data";
|
|
||||||
|
|
||||||
std::filesystem::path file_path =
|
|
||||||
launch_data_dir /
|
|
||||||
fmt::format("{:08X}_launch_data.bin", kernel_state()->title_id());
|
|
||||||
|
|
||||||
if (!std::filesystem::exists(launch_data_dir)) {
|
|
||||||
std::filesystem::create_directories(launch_data_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto file = xe::filesystem::OpenFile(file_path, "wb+");
|
|
||||||
if (file) {
|
|
||||||
fwrite(loader_data.launch_data.data(), size, 1, file);
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DECLARE_XAM_EXPORT1(XamLoaderSetLaunchData, kNone, kSketchy);
|
DECLARE_XAM_EXPORT1(XamLoaderSetLaunchData, kNone, kSketchy);
|
||||||
|
@ -357,15 +339,12 @@ void XamLoaderLaunchTitle_entry(lpstring_t raw_name_ptr, dword_t flags) {
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
loader_data.launch_path = "game:\\default.xex";
|
loader_data.launch_path = "game:\\default.xex";
|
||||||
} else {
|
} else {
|
||||||
if (xe::utf8::find_name_from_guest_path(path) == path) {
|
loader_data.launch_path = xe::path_to_utf8(path);
|
||||||
path = xe::utf8::join_guest_paths(
|
loader_data.launch_data_present = true;
|
||||||
xe::utf8::find_base_guest_path(
|
|
||||||
kernel_state()->GetExecutableModule()->path()),
|
|
||||||
path);
|
|
||||||
}
|
|
||||||
loader_data.launch_path = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xam->SaveLoaderData();
|
||||||
|
|
||||||
if (loader_data.launch_data_present) {
|
if (loader_data.launch_data_present) {
|
||||||
auto display_window = kernel_state()->emulator()->display_window();
|
auto display_window = kernel_state()->emulator()->display_window();
|
||||||
auto imgui_drawer = kernel_state()->emulator()->imgui_drawer();
|
auto imgui_drawer = kernel_state()->emulator()->imgui_drawer();
|
||||||
|
@ -375,8 +354,8 @@ void XamLoaderLaunchTitle_entry(lpstring_t raw_name_ptr, dword_t flags) {
|
||||||
[imgui_drawer]() {
|
[imgui_drawer]() {
|
||||||
xe::ui::ImGuiDialog::ShowMessageBox(
|
xe::ui::ImGuiDialog::ShowMessageBox(
|
||||||
imgui_drawer, "Title was restarted",
|
imgui_drawer, "Title was restarted",
|
||||||
"Title closed with new launch data. \nPlease close Xenia and "
|
"Title closed with new launch data. \nPlease restart Xenia. "
|
||||||
"start title again.");
|
"Game will be loaded automatically.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,82 @@ void XamModule::RegisterExportTable(xe::cpu::ExportResolver* export_resolver) {
|
||||||
|
|
||||||
XamModule::~XamModule() {}
|
XamModule::~XamModule() {}
|
||||||
|
|
||||||
|
void XamModule::LoadLoaderData() {
|
||||||
|
FILE* file = xe::filesystem::OpenFile(kXamModuleLoaderDataFileName, "rb");
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
loader_data_.launch_data_present = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loader_data_.launch_data_present = true;
|
||||||
|
|
||||||
|
auto string_read = [file]() {
|
||||||
|
uint16_t string_size = 0;
|
||||||
|
fread(&string_size, sizeof(string_size), 1, file);
|
||||||
|
|
||||||
|
std::string result_string;
|
||||||
|
result_string.resize(string_size);
|
||||||
|
fread(result_string.data(), string_size, 1, file);
|
||||||
|
return result_string;
|
||||||
|
};
|
||||||
|
|
||||||
|
loader_data_.host_path = string_read();
|
||||||
|
loader_data_.launch_path = string_read();
|
||||||
|
|
||||||
|
fread(&loader_data_.launch_flags, sizeof(loader_data_.launch_flags), 1, file);
|
||||||
|
|
||||||
|
uint16_t launch_data_size = 0;
|
||||||
|
fread(&launch_data_size, sizeof(launch_data_size), 1, file);
|
||||||
|
|
||||||
|
if (launch_data_size > 0) {
|
||||||
|
loader_data_.launch_data.resize(launch_data_size);
|
||||||
|
fread(loader_data_.launch_data.data(), launch_data_size, 1, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
// We read launch data. Let's remove it till next request.
|
||||||
|
std::filesystem::remove(kXamModuleLoaderDataFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XamModule::SaveLoaderData() {
|
||||||
|
FILE* file = xe::filesystem::OpenFile(kXamModuleLoaderDataFileName, "wb");
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path host_path = loader_data_.host_path;
|
||||||
|
if (host_path.extension() == ".xex") {
|
||||||
|
host_path.remove_filename();
|
||||||
|
host_path = host_path / loader_data_.launch_path;
|
||||||
|
loader_data_.launch_path = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string host_path_as_string = xe::path_to_utf8(host_path);
|
||||||
|
const uint16_t host_path_length =
|
||||||
|
static_cast<uint16_t>(host_path_as_string.size());
|
||||||
|
|
||||||
|
fwrite(&host_path_length, sizeof(host_path_length), 1, file);
|
||||||
|
fwrite(host_path_as_string.c_str(), host_path_length, 1, file);
|
||||||
|
|
||||||
|
const uint16_t launch_path_length =
|
||||||
|
static_cast<uint16_t>(loader_data_.launch_path.size());
|
||||||
|
fwrite(&launch_path_length, sizeof(launch_path_length), 1, file);
|
||||||
|
fwrite(loader_data_.launch_path.c_str(), launch_path_length, 1, file);
|
||||||
|
|
||||||
|
fwrite(&loader_data_.launch_flags, sizeof(loader_data_.launch_flags), 1,
|
||||||
|
file);
|
||||||
|
|
||||||
|
const uint16_t launch_data_size =
|
||||||
|
static_cast<uint16_t>(loader_data_.launch_data.size());
|
||||||
|
fwrite(&launch_data_size, sizeof(launch_data_size), 1, file);
|
||||||
|
|
||||||
|
fwrite(loader_data_.launch_data.data(), launch_data_size, 1, file);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xam
|
} // namespace xam
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
|
@ -23,6 +23,8 @@ namespace xam {
|
||||||
|
|
||||||
bool xeXamIsUIActive();
|
bool xeXamIsUIActive();
|
||||||
|
|
||||||
|
static const std::string kXamModuleLoaderDataFileName = "launch_data.bin";
|
||||||
|
|
||||||
class XamModule : public KernelModule {
|
class XamModule : public KernelModule {
|
||||||
public:
|
public:
|
||||||
XamModule(Emulator* emulator, KernelState* kernel_state);
|
XamModule(Emulator* emulator, KernelState* kernel_state);
|
||||||
|
@ -32,11 +34,17 @@ class XamModule : public KernelModule {
|
||||||
|
|
||||||
struct LoaderData {
|
struct LoaderData {
|
||||||
bool launch_data_present = false;
|
bool launch_data_present = false;
|
||||||
std::vector<uint8_t> launch_data;
|
std::string host_path; // Full host path to next title to load
|
||||||
|
std::string
|
||||||
|
launch_path; // Full guest path to next xex. might be default.xex
|
||||||
|
|
||||||
uint32_t launch_flags = 0;
|
uint32_t launch_flags = 0;
|
||||||
std::string launch_path; // Full path to next xex
|
std::vector<uint8_t> launch_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void LoadLoaderData();
|
||||||
|
void SaveLoaderData();
|
||||||
|
|
||||||
const LoaderData& loader_data() const { return loader_data_; }
|
const LoaderData& loader_data() const { return loader_data_; }
|
||||||
LoaderData& loader_data() { return loader_data_; }
|
LoaderData& loader_data() { return loader_data_; }
|
||||||
|
|
||||||
|
|
|
@ -329,44 +329,40 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
X_STATUS VirtualFileSystem::ExtractContentFiles(
|
X_STATUS VirtualFileSystem::ExtractContentFile(Entry* entry,
|
||||||
Device* device, std::filesystem::path base_path) {
|
std::filesystem::path base_path,
|
||||||
// Run through all the files, breadth-first style.
|
bool extract_to_root) {
|
||||||
std::queue<vfs::Entry*> queue;
|
|
||||||
auto root = device->ResolvePath("/");
|
|
||||||
queue.push(root);
|
|
||||||
|
|
||||||
// Allocate a buffer when needed.
|
// Allocate a buffer when needed.
|
||||||
size_t buffer_size = 0;
|
size_t buffer_size = 0;
|
||||||
uint8_t* buffer = nullptr;
|
uint8_t* buffer = nullptr;
|
||||||
|
|
||||||
while (!queue.empty()) {
|
XELOGI("Extracting file: {}", entry->path());
|
||||||
auto entry = queue.front();
|
|
||||||
queue.pop();
|
auto dest_name = base_path / xe::to_path(entry->path());
|
||||||
for (auto& entry : entry->children()) {
|
|
||||||
queue.push(entry.get());
|
if (extract_to_root) {
|
||||||
|
dest_name = base_path / xe::to_path(entry->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
XELOGI("Extracting file: {}", entry->path());
|
|
||||||
auto dest_name = base_path / xe::to_path(entry->path());
|
|
||||||
if (entry->attributes() & kFileAttributeDirectory) {
|
if (entry->attributes() & kFileAttributeDirectory) {
|
||||||
std::error_code error_code;
|
std::error_code error_code;
|
||||||
std::filesystem::create_directories(dest_name, error_code);
|
std::filesystem::create_directories(dest_name, error_code);
|
||||||
if (error_code) {
|
if (error_code) {
|
||||||
return error_code.value();
|
return error_code.value();
|
||||||
}
|
}
|
||||||
continue;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs::File* in_file = nullptr;
|
vfs::File* in_file = nullptr;
|
||||||
if (entry->Open(FileAccess::kFileReadData, &in_file) != X_STATUS_SUCCESS) {
|
X_STATUS result = entry->Open(FileAccess::kFileReadData, &in_file);
|
||||||
continue;
|
if (result != X_STATUS_SUCCESS) {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file = xe::filesystem::OpenFile(dest_name, "wb");
|
auto file = xe::filesystem::OpenFile(dest_name, "wb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
in_file->Destroy();
|
in_file->Destroy();
|
||||||
continue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry->can_map()) {
|
if (entry->can_map()) {
|
||||||
|
@ -393,12 +389,29 @@ X_STATUS VirtualFileSystem::ExtractContentFiles(
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
in_file->Destroy();
|
in_file->Destroy();
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
X_STATUS VirtualFileSystem::ExtractContentFiles(
|
||||||
|
Device* device, std::filesystem::path base_path) {
|
||||||
|
// Run through all the files, breadth-first style.
|
||||||
|
std::queue<vfs::Entry*> queue;
|
||||||
|
auto root = device->ResolvePath("/");
|
||||||
|
queue.push(root);
|
||||||
|
|
||||||
|
while (!queue.empty()) {
|
||||||
|
auto entry = queue.front();
|
||||||
|
queue.pop();
|
||||||
|
for (auto& entry : entry->children()) {
|
||||||
|
queue.push(entry.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
ExtractContentFile(entry, base_path);
|
||||||
|
}
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,9 @@ class VirtualFileSystem {
|
||||||
bool is_non_directory, File** out_file,
|
bool is_non_directory, File** out_file,
|
||||||
FileAction* out_action);
|
FileAction* out_action);
|
||||||
|
|
||||||
|
static X_STATUS ExtractContentFile(Entry* entry,
|
||||||
|
std::filesystem::path base_path,
|
||||||
|
bool extract_to_root = false);
|
||||||
static X_STATUS ExtractContentFiles(Device* device,
|
static X_STATUS ExtractContentFiles(Device* device,
|
||||||
std::filesystem::path base_path);
|
std::filesystem::path base_path);
|
||||||
static void ExtractContentHeader(Device* device,
|
static void ExtractContentHeader(Device* device,
|
||||||
|
|
Loading…
Reference in New Issue