[Kernel/VFS] Write more fields in STFS headers when creating

This commit is contained in:
emoose 2020-01-11 18:40:40 +00:00 committed by illusion
parent 72daead6af
commit 833e36e051
2 changed files with 52 additions and 10 deletions

View File

@ -13,6 +13,7 @@
#include "xenia/base/filesystem.h" #include "xenia/base/filesystem.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include "xenia/emulator.h"
#include "xenia/kernel/kernel_state.h" #include "xenia/kernel/kernel_state.h"
#include "xenia/kernel/user_module.h" #include "xenia/kernel/user_module.h"
#include "xenia/kernel/xam/content_package.h" #include "xenia/kernel/xam/content_package.h"
@ -194,16 +195,42 @@ X_RESULT ContentManager::CreateContent(std::string root_name,
return X_ERROR_FUNCTION_FAILED; // failed to create headers file :( return X_ERROR_FUNCTION_FAILED; // failed to create headers file :(
} }
// Set headers using data from XCONTENT_DATA // Setup package headers!
vfs::StfsHeader* header = new vfs::StfsHeader(); {
// TODO: set title_id, title_name & publisher from XDBF info // TODO: set publisher from XDBF info (but most saves don't have this set?)
header->metadata.content_type = (xe::vfs::XContentType)data.content_type;
header->metadata.set_display_name(data.display_name, // Set header defaults...
(XLanguage)cvars::user_language); vfs::StfsHeader* header = new vfs::StfsHeader();
// TODO: set display name locale that's currently in use header->set_defaults();
fwrite(header, sizeof(vfs::StfsHeader), 1, file);
fclose(file); // Try copying execution info from XEX opt headers
delete header; auto exe_module = kernel_state_->GetExecutableModule();
if (exe_module) {
xex2_opt_execution_info* exec_info = 0;
exe_module->GetOptHeader(XEX_HEADER_EXECUTION_INFO, &exec_info);
if (exec_info) {
memcpy(&header->metadata.execution_info, exec_info,
sizeof(xex2_opt_execution_info));
}
}
// Copy game title in the games default language
// TODO: should this get the title in the users chosen lang instead?
header->metadata.set_title_name(kernel_state_->emulator()->game_title());
// TODO:
// Set package profile id (should be the offline XUID, 0xE0....)
// header->metadata.profile_id = kernel_state_->user_profile()->xuid();
// Now copy data from XCONTENT_DATA into package headers
header->metadata.content_type = (xe::vfs::XContentType)data.content_type;
header->metadata.set_display_name(data.display_name,
(XLanguage)cvars::user_language);
fwrite(header, sizeof(vfs::StfsHeader), 1, file);
fclose(file);
delete header;
}
if (!package->Mount(root_name)) { if (!package->Mount(root_name)) {
return X_ERROR_DEVICE_NOT_CONNECTED; return X_ERROR_DEVICE_NOT_CONNECTED;

View File

@ -381,6 +381,21 @@ struct StfsHeader {
XContentMetadata metadata; XContentMetadata metadata;
XContentInstaller installer; XContentInstaller installer;
uint8_t padding[0x2F2]; uint8_t padding[0x2F2];
void set_defaults() {
memset(this, 0, sizeof(StfsHeader));
header.magic = xe::vfs::XContentPackageType::kPackageTypeCon;
header.licenses[0].licensee_id =
-1; // X360 gamesaves seem to set licenses like this
header.header_size = 0x971A;
metadata.metadata_version = 2;
memcpy(metadata.console_id, "XENIA", 5);
// Saves always have this set? How do titles choose this?
metadata.flags.bits.device_transfer = true;
}
}; };
static_assert_size(StfsHeader, 0xB000); static_assert_size(StfsHeader, 0xB000);
#pragma pack(pop) #pragma pack(pop)