Support for patch types:
- float - double - string - u16string - byte_array Plus some smaller changes
This commit is contained in:
@@ -16,16 +16,46 @@
|
||||
|
||||
namespace xe {
|
||||
namespace patcher {
|
||||
struct PatchDataEntry {
|
||||
const uint8_t alloc_size_;
|
||||
const uint32_t memory_address_;
|
||||
const uint64_t new_value_;
|
||||
|
||||
PatchDataEntry(const uint8_t alloc_size, const uint32_t memory_address,
|
||||
const uint64_t new_value)
|
||||
: alloc_size_(alloc_size),
|
||||
memory_address_(memory_address),
|
||||
new_value_(new_value){};
|
||||
struct PatchDataValue {
|
||||
const size_t alloc_size_;
|
||||
const uint8_t* patch_data_ptr_;
|
||||
|
||||
PatchDataValue(const size_t alloc_size, const uint64_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 float 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 std::vector<uint8_t> value)
|
||||
: alloc_size_(alloc_size) {
|
||||
patch_data_ptr_ = new uint8_t[alloc_size_];
|
||||
memcpy((void*)patch_data_ptr_, value.data(), alloc_size);
|
||||
};
|
||||
|
||||
PatchDataValue(const std::string value) : alloc_size_(value.size()) {
|
||||
patch_data_ptr_ = new uint8_t[alloc_size_];
|
||||
memcpy((void*)patch_data_ptr_, value.c_str(), alloc_size_);
|
||||
};
|
||||
|
||||
PatchDataValue(const std::u16string value) : alloc_size_(value.size() * 2) {
|
||||
patch_data_ptr_ = new uint8_t[alloc_size_];
|
||||
memcpy((void*)patch_data_ptr_, value.c_str(), alloc_size_);
|
||||
};
|
||||
};
|
||||
|
||||
struct PatchDataEntry {
|
||||
const uint32_t memory_address_;
|
||||
const PatchDataValue new_data_;
|
||||
|
||||
PatchDataEntry(const uint32_t memory_address, const PatchDataValue new_data)
|
||||
: memory_address_(memory_address), new_data_(new_data){};
|
||||
};
|
||||
|
||||
struct PatchInfoEntry {
|
||||
@@ -44,6 +74,25 @@ struct PatchFileEntry {
|
||||
std::vector<PatchInfoEntry> patch_info;
|
||||
};
|
||||
|
||||
enum class PatchDataType {
|
||||
be8,
|
||||
be16,
|
||||
be32,
|
||||
be64,
|
||||
f32,
|
||||
f64,
|
||||
string,
|
||||
u16string,
|
||||
byte_array
|
||||
};
|
||||
|
||||
struct PatchData {
|
||||
uint8_t size;
|
||||
PatchDataType type;
|
||||
|
||||
PatchData(uint8_t size_, PatchDataType type_) : size(size_), type(type_){};
|
||||
};
|
||||
|
||||
class PatchDB {
|
||||
public:
|
||||
PatchDB(const std::filesystem::path patches_root);
|
||||
@@ -52,9 +101,9 @@ class PatchDB {
|
||||
void LoadPatches();
|
||||
|
||||
PatchFileEntry ReadPatchFile(const std::filesystem::path& file_path);
|
||||
std::vector<PatchDataEntry>* ReadPatchData(
|
||||
const std::string size_type,
|
||||
const std::shared_ptr<cpptoml::table>& patch_table);
|
||||
bool ReadPatchData(std::vector<PatchDataEntry>& patch_data,
|
||||
const std::pair<std::string, PatchData> data_type,
|
||||
const std::shared_ptr<cpptoml::table>& patch_table);
|
||||
|
||||
std::vector<PatchFileEntry> GetTitlePatches(uint32_t title_id,
|
||||
const uint64_t hash);
|
||||
@@ -64,12 +113,16 @@ class PatchDB {
|
||||
std::vector<PatchFileEntry> loaded_patches;
|
||||
std::filesystem::path patches_root_;
|
||||
|
||||
uint8_t GetAllocSize(const std::string provided_size);
|
||||
|
||||
const std::map<std::string, size_t> patch_data_types_size = {
|
||||
{"f64", sizeof(uint64_t)}, {"f32", sizeof(uint32_t)},
|
||||
{"be64", sizeof(uint64_t)}, {"be32", sizeof(uint32_t)},
|
||||
{"be16", sizeof(uint16_t)}, {"be8", sizeof(uint8_t)}};
|
||||
const std::map<std::string, PatchData> patch_data_types_size = {
|
||||
{"string", PatchData(0, PatchDataType::string)},
|
||||
{"u16string", PatchData(0, PatchDataType::u16string)},
|
||||
{"array", PatchData(0, PatchDataType::byte_array)},
|
||||
{"f64", PatchData(sizeof(uint64_t), PatchDataType::f64)},
|
||||
{"f32", PatchData(sizeof(uint32_t), PatchDataType::f32)},
|
||||
{"be64", PatchData(sizeof(uint64_t), PatchDataType::be64)},
|
||||
{"be32", PatchData(sizeof(uint32_t), PatchDataType::be32)},
|
||||
{"be16", PatchData(sizeof(uint16_t), PatchDataType::be16)},
|
||||
{"be8", PatchData(sizeof(uint8_t), PatchDataType::be8)}};
|
||||
};
|
||||
|
||||
} // namespace patcher
|
||||
|
||||
Reference in New Issue
Block a user