[Patcher] Fixed issue with incorrect patches endianness
This commit is contained in:
parent
0de0f40fb5
commit
25f3e16baa
|
@ -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<uint8_t>("value");
|
||||
patch_data.push_back({address, PatchDataValue(alloc_size, value)});
|
||||
break;
|
||||
}
|
||||
case PatchDataType::be16: {
|
||||
uint16_t value = *patch_data_table->get_as<uint16_t>("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<uint32_t>("value");
|
||||
patch_data.push_back(
|
||||
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
|
||||
break;
|
||||
}
|
||||
case PatchDataType::f64: {
|
||||
double val = *patch_data_table->get_as<double>("value");
|
||||
uint64_t value = *reinterpret_cast<uint64_t*>(&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<double>("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<uint64_t>("value");
|
||||
patch_data.push_back({address, PatchDataValue(alloc_size, value)});
|
||||
patch_data.push_back(
|
||||
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_];
|
||||
|
|
|
@ -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_,
|
||||
|
|
Loading…
Reference in New Issue