diff --git a/src/xenia/patcher/patch_db.cc b/src/xenia/patcher/patch_db.cc index 20f1e5831..188c9ae54 100644 --- a/src/xenia/patcher/patch_db.cc +++ b/src/xenia/patcher/patch_db.cc @@ -120,15 +120,34 @@ bool PatchDB::ReadPatchData( size_t alloc_size = (size_t)data_type.second.size; switch (data_type.second.type) { + case PatchDataType::be8: { + uint16_t value = *patch_data_table->get_as("value"); + patch_data.push_back({address, PatchDataValue(alloc_size, value)}); + break; + } + case PatchDataType::be16: { + uint16_t value = *patch_data_table->get_as("value"); + patch_data.push_back( + {address, PatchDataValue(alloc_size, xe::byte_swap(value))}); + break; + } + case PatchDataType::be32: { + uint32_t value = *patch_data_table->get_as("value"); + patch_data.push_back( + {address, PatchDataValue(alloc_size, xe::byte_swap(value))}); + break; + } case PatchDataType::f64: { double val = *patch_data_table->get_as("value"); uint64_t value = *reinterpret_cast(&val); - patch_data.push_back({address, PatchDataValue(alloc_size, value)}); + patch_data.push_back( + {address, PatchDataValue(alloc_size, xe::byte_swap(value))}); break; } case PatchDataType::f32: { float value = float(*patch_data_table->get_as("value")); - patch_data.push_back({address, PatchDataValue(alloc_size, value)}); + patch_data.push_back( + {address, PatchDataValue(alloc_size, xe::byte_swap(value))}); break; } case PatchDataType::string: { @@ -157,7 +176,8 @@ bool PatchDB::ReadPatchData( } default: { uint64_t value = *patch_data_table->get_as("value"); - patch_data.push_back({address, PatchDataValue(alloc_size, value)}); + patch_data.push_back( + {address, PatchDataValue(alloc_size, xe::byte_swap(value))}); break; } } diff --git a/src/xenia/patcher/patch_db.h b/src/xenia/patcher/patch_db.h index e2baf4675..e4250e01e 100644 --- a/src/xenia/patcher/patch_db.h +++ b/src/xenia/patcher/patch_db.h @@ -21,6 +21,24 @@ struct PatchDataValue { const size_t alloc_size_; const uint8_t* patch_data_ptr_; + PatchDataValue(const size_t alloc_size, const uint8_t value) + : alloc_size_(alloc_size) { + patch_data_ptr_ = new uint8_t[alloc_size_]; + memcpy((void*)patch_data_ptr_, &value, alloc_size); + }; + + PatchDataValue(const size_t alloc_size, const uint16_t value) + : alloc_size_(alloc_size) { + patch_data_ptr_ = new uint8_t[alloc_size_]; + memcpy((void*)patch_data_ptr_, &value, alloc_size); + }; + + PatchDataValue(const size_t alloc_size, const uint32_t value) + : alloc_size_(alloc_size) { + patch_data_ptr_ = new uint8_t[alloc_size_]; + memcpy((void*)patch_data_ptr_, &value, alloc_size); + }; + PatchDataValue(const size_t alloc_size, const uint64_t value) : alloc_size_(alloc_size) { patch_data_ptr_ = new uint8_t[alloc_size_]; diff --git a/src/xenia/patcher/patcher.cc b/src/xenia/patcher/patcher.cc index b35e92534..43b2d54ba 100644 --- a/src/xenia/patcher/patcher.cc +++ b/src/xenia/patcher/patcher.cc @@ -51,9 +51,9 @@ void Patcher::ApplyPatch(Memory* memory, const PatchInfoEntry* patch) { (uint32_t)patch_data_entry.new_data_.alloc_size_, kMemoryProtectRead | kMemoryProtectWrite); - xe::copy_and_swap(address, - (uint8_t*)patch_data_entry.new_data_.patch_data_ptr_, - patch_data_entry.new_data_.alloc_size_); + + memcpy(address, patch_data_entry.new_data_.patch_data_ptr_, + patch_data_entry.new_data_.alloc_size_); // Restore previous protection heap->Protect(patch_data_entry.memory_address_,