From 38c3db1afbc727f067cfaa9e19fc28e560f0c6a5 Mon Sep 17 00:00:00 2001 From: gibbed Date: Sat, 1 May 2021 17:05:14 -0500 Subject: [PATCH] [CPU/Kernel] Transparently byteswap xex2_version. --- src/xenia/cpu/xex_module.cc | 13 ++---- src/xenia/kernel/user_module.cc | 6 +-- src/xenia/kernel/util/xex2_info.h | 76 +++++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index ec85bc18e..a9a1fd83c 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -449,14 +449,9 @@ int XexModule::ApplyPatch(XexModule* module) { } } - // byteswap versions because of bitfields... xex2_version source_ver, target_ver; - source_ver.value = - xe::byte_swap(patch_header->source_version.value); - - target_ver.value = - xe::byte_swap(patch_header->target_version.value); - + source_ver = patch_header->source_version(); + target_ver = patch_header->target_version(); XELOGI( "XEX patch applied successfully: base version: {}.{}.{}.{}, new " "version: {}.{}.{}.{}", @@ -1112,8 +1107,8 @@ bool XexModule::SetupLibraryImports(const std::string_view name, ImportLibrary library_info; library_info.name = base_name; library_info.id = library->id; - library_info.version.value = library->version.value; - library_info.min_version.value = library->version_min.value; + library_info.version.value = library->version().value; + library_info.min_version.value = library->version_min().value; // Imports are stored as {import descriptor, thunk addr, import desc, ...} // Even thunks have an import descriptor (albeit unused/useless) diff --git a/src/xenia/kernel/user_module.cc b/src/xenia/kernel/user_module.cc index f3b8aef43..dc007991b 100644 --- a/src/xenia/kernel/user_module.cc +++ b/src/xenia/kernel/user_module.cc @@ -511,11 +511,9 @@ void UserModule::Dump() { sb.AppendFormat(" {} - {} imports\n", name, (uint16_t)library->count); - // Manually byteswap these because of the bitfields. xex2_version version, version_min; - version.value = xe::byte_swap(library->version.value); - version_min.value = - xe::byte_swap(library->version_min.value); + version = library->version(); + version_min = library->version_min(); sb.AppendFormat(" Version: {}.{}.{}.{}\n", version.major, version.minor, version.build, version.qfe); sb.AppendFormat(" Min Version: {}.{}.{}.{}\n", version_min.major, diff --git a/src/xenia/kernel/util/xex2_info.h b/src/xenia/kernel/util/xex2_info.h index 6203b18f2..a5b5e5a33 100644 --- a/src/xenia/kernel/util/xex2_info.h +++ b/src/xenia/kernel/util/xex2_info.h @@ -372,7 +372,7 @@ struct xex2_opt_file_format_info { }; union xex2_version { - xe::be value; + uint32_t value; struct { uint32_t major : 4; uint32_t minor : 4; @@ -446,8 +446,8 @@ struct xex2_delta_patch { struct xex2_opt_delta_patch_descriptor { xe::be size; // 0x0 - xex2_version target_version; // 0x4 - xex2_version source_version; // 0x8 + xe::be target_version_value; // 0x4 + xe::be source_version_value; // 0x8 uint8_t digest_source[0x14]; // 0xC uint8_t image_key_source[0x10]; // 0x20 xe::be size_of_target_headers; // 0x30 @@ -458,18 +458,44 @@ struct xex2_opt_delta_patch_descriptor { xe::be delta_image_source_size; // 0x44 xe::be delta_image_target_offset; // 0x48 xex2_delta_patch info; // 0x4C + + xex2_version target_version() const { + return xex2_version{target_version_value}; + } + + void set_target_version(xex2_version version) { + target_version_value = version.value; + } + + xex2_version source_version() const { + return xex2_version{source_version_value}; + } + + void set_source_version(xex2_version version) { + source_version_value = version.value; + } }; struct xex2_opt_execution_info { - xe::be media_id; // 0x0 - xe::be version; // 0x4 - xe::be base_version; // 0x8 - xe::be title_id; // 0xC - uint8_t platform; // 0x10 - uint8_t executable_table; // 0x11 - uint8_t disc_number; // 0x12 - uint8_t disc_count; // 0x13 - xe::be savegame_id; // 0x14 + xe::be media_id; // 0x0 + xe::be version_value; // 0x4 + xe::be base_version_value; // 0x8 + xe::be title_id; // 0xC + uint8_t platform; // 0x10 + uint8_t executable_table; // 0x11 + uint8_t disc_number; // 0x12 + uint8_t disc_count; // 0x13 + xe::be savegame_id; // 0x14 + + xex2_version version() const { return xex2_version{version_value}; } + + void set_version(xex2_version version) { version_value = version.value; } + + xex2_version base_version() const { return xex2_version{base_version_value}; } + + void set_base_version(xex2_version version) { + base_version_value = version.value; + } }; static_assert_size(xex2_opt_execution_info, 0x18); @@ -483,14 +509,24 @@ struct xex2_opt_import_libraries { }; struct xex2_import_library { - xe::be size; // 0x0 - char next_import_digest[0x14]; // 0x4 - xe::be id; // 0x18 - xex2_version version; // 0x1C - xex2_version version_min; // 0x20 - xe::be name_index; // 0x24 - xe::be count; // 0x26 - xe::be import_table[1]; // 0x28 + xe::be size; // 0x0 + char next_import_digest[0x14]; // 0x4 + xe::be id; // 0x18 + xe::be version_value; // 0x1C + xe::be version_min_value; // 0x20 + xe::be name_index; // 0x24 + xe::be count; // 0x26 + xe::be import_table[1]; // 0x28 + + xex2_version version() const { return xex2_version{version_value}; } + + void set_version(xex2_version version) { version_value = version.value; } + + xex2_version version_min() const { return xex2_version{version_min_value}; } + + void set_version_min(xex2_version version) { + version_min_value = version.value; + } }; struct xex2_opt_header {