impr: Switch to custom std::expected implementation
This commit is contained in:
parent
a719627be6
commit
363b07fc0c
2
lib/external/libwolv
vendored
2
lib/external/libwolv
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d902b5597735ed91e9626598304853774adee5ef
|
Subproject commit 7e306b0e0ab13989949b1d240df78b3c989e7fdf
|
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <expected>
|
|
||||||
|
#include <wolv/utils/expected.hpp>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ namespace hex {
|
|||||||
MissingEOF
|
MissingEOF
|
||||||
};
|
};
|
||||||
|
|
||||||
std::expected<std::vector<u8>, IPSError> generateIPSPatch(const Patches &patches);
|
wolv::util::Expected<std::vector<u8>, IPSError> generateIPSPatch(const Patches &patches);
|
||||||
std::expected<std::vector<u8>, IPSError> generateIPS32Patch(const Patches &patches);
|
wolv::util::Expected<std::vector<u8>, IPSError> generateIPS32Patch(const Patches &patches);
|
||||||
|
|
||||||
std::expected<Patches, IPSError> loadIPSPatch(const std::vector<u8> &ipsPatch);
|
wolv::util::Expected<Patches, IPSError> loadIPSPatch(const std::vector<u8> &ipsPatch);
|
||||||
std::expected<Patches, IPSError> loadIPS32Patch(const std::vector<u8> &ipsPatch);
|
wolv::util::Expected<Patches, IPSError> loadIPS32Patch(const std::vector<u8> &ipsPatch);
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ namespace hex {
|
|||||||
std::memcpy((&buffer.back() - sizeof(T)) + 1, &bytes, sizeof(T));
|
std::memcpy((&buffer.back() - sizeof(T)) + 1, &bytes, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<std::vector<u8>, IPSError> generateIPSPatch(const Patches &patches) {
|
wolv::util::Expected<std::vector<u8>, IPSError> generateIPSPatch(const Patches &patches) {
|
||||||
std::vector<u8> result;
|
std::vector<u8> result;
|
||||||
|
|
||||||
pushStringBack(result, "PATCH");
|
pushStringBack(result, "PATCH");
|
||||||
@ -43,9 +43,9 @@ namespace hex {
|
|||||||
bytes.push_back(values[i]);
|
bytes.push_back(values[i]);
|
||||||
|
|
||||||
if (bytes.size() > 0xFFFF)
|
if (bytes.size() > 0xFFFF)
|
||||||
return std::unexpected(IPSError::PatchTooLarge);
|
return wolv::util::Unexpected(IPSError::PatchTooLarge);
|
||||||
if (startAddress > 0xFFFF'FFFF)
|
if (startAddress > 0xFFFF'FFFF)
|
||||||
return std::unexpected(IPSError::AddressOutOfRange);
|
return wolv::util::Unexpected(IPSError::AddressOutOfRange);
|
||||||
|
|
||||||
u32 address = startAddress.value();
|
u32 address = startAddress.value();
|
||||||
auto addressBytes = reinterpret_cast<u8 *>(&address);
|
auto addressBytes = reinterpret_cast<u8 *>(&address);
|
||||||
@ -68,7 +68,7 @@ namespace hex {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<std::vector<u8>, IPSError> generateIPS32Patch(const Patches &patches) {
|
wolv::util::Expected<std::vector<u8>, IPSError> generateIPS32Patch(const Patches &patches) {
|
||||||
std::vector<u8> result;
|
std::vector<u8> result;
|
||||||
|
|
||||||
pushStringBack(result, "IPS32");
|
pushStringBack(result, "IPS32");
|
||||||
@ -93,9 +93,9 @@ namespace hex {
|
|||||||
bytes.push_back(values[i]);
|
bytes.push_back(values[i]);
|
||||||
|
|
||||||
if (bytes.size() > 0xFFFF)
|
if (bytes.size() > 0xFFFF)
|
||||||
return std::unexpected(IPSError::PatchTooLarge);
|
return wolv::util::Unexpected(IPSError::PatchTooLarge);
|
||||||
if (startAddress > 0xFFFF'FFFF)
|
if (startAddress > 0xFFFF'FFFF)
|
||||||
return std::unexpected(IPSError::AddressOutOfRange);
|
return wolv::util::Unexpected(IPSError::AddressOutOfRange);
|
||||||
|
|
||||||
u32 address = startAddress.value();
|
u32 address = startAddress.value();
|
||||||
auto addressBytes = reinterpret_cast<u8 *>(&address);
|
auto addressBytes = reinterpret_cast<u8 *>(&address);
|
||||||
@ -119,12 +119,12 @@ namespace hex {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<Patches, IPSError> loadIPSPatch(const std::vector<u8> &ipsPatch) {
|
wolv::util::Expected<Patches, IPSError> loadIPSPatch(const std::vector<u8> &ipsPatch) {
|
||||||
if (ipsPatch.size() < (5 + 3))
|
if (ipsPatch.size() < (5 + 3))
|
||||||
return std::unexpected(IPSError::InvalidPatchHeader);
|
return wolv::util::Unexpected(IPSError::InvalidPatchHeader);
|
||||||
|
|
||||||
if (std::memcmp(ipsPatch.data(), "PATCH", 5) != 0)
|
if (std::memcmp(ipsPatch.data(), "PATCH", 5) != 0)
|
||||||
return std::unexpected(IPSError::InvalidPatchHeader);
|
return wolv::util::Unexpected(IPSError::InvalidPatchHeader);
|
||||||
|
|
||||||
Patches result;
|
Patches result;
|
||||||
bool foundEOF = false;
|
bool foundEOF = false;
|
||||||
@ -139,7 +139,7 @@ namespace hex {
|
|||||||
// Handle normal record
|
// Handle normal record
|
||||||
if (size > 0x0000) {
|
if (size > 0x0000) {
|
||||||
if (ipsOffset + size > ipsPatch.size() - 3)
|
if (ipsOffset + size > ipsPatch.size() - 3)
|
||||||
return std::unexpected(IPSError::InvalidPatchFormat);
|
return wolv::util::Unexpected(IPSError::InvalidPatchFormat);
|
||||||
|
|
||||||
for (u16 i = 0; i < size; i++)
|
for (u16 i = 0; i < size; i++)
|
||||||
result[offset + i] = ipsPatch[ipsOffset + i];
|
result[offset + i] = ipsPatch[ipsOffset + i];
|
||||||
@ -148,7 +148,7 @@ namespace hex {
|
|||||||
// Handle RLE record
|
// Handle RLE record
|
||||||
else {
|
else {
|
||||||
if (ipsOffset + 3 > ipsPatch.size() - 3)
|
if (ipsOffset + 3 > ipsPatch.size() - 3)
|
||||||
return std::unexpected(IPSError::InvalidPatchFormat);
|
return wolv::util::Unexpected(IPSError::InvalidPatchFormat);
|
||||||
|
|
||||||
u16 rleSize = ipsPatch[ipsOffset + 0] | (ipsPatch[ipsOffset + 1] << 8);
|
u16 rleSize = ipsPatch[ipsOffset + 0] | (ipsPatch[ipsOffset + 1] << 8);
|
||||||
|
|
||||||
@ -167,15 +167,15 @@ namespace hex {
|
|||||||
if (foundEOF)
|
if (foundEOF)
|
||||||
return result;
|
return result;
|
||||||
else
|
else
|
||||||
return std::unexpected(IPSError::MissingEOF);
|
return wolv::util::Unexpected(IPSError::MissingEOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<Patches, IPSError> loadIPS32Patch(const std::vector<u8> &ipsPatch) {
|
wolv::util::Expected<Patches, IPSError> loadIPS32Patch(const std::vector<u8> &ipsPatch) {
|
||||||
if (ipsPatch.size() < (5 + 4))
|
if (ipsPatch.size() < (5 + 4))
|
||||||
return std::unexpected(IPSError::InvalidPatchHeader);
|
return wolv::util::Unexpected(IPSError::InvalidPatchHeader);
|
||||||
|
|
||||||
if (std::memcmp(ipsPatch.data(), "IPS32", 5) != 0)
|
if (std::memcmp(ipsPatch.data(), "IPS32", 5) != 0)
|
||||||
return std::unexpected(IPSError::InvalidPatchHeader);
|
return wolv::util::Unexpected(IPSError::InvalidPatchHeader);
|
||||||
|
|
||||||
Patches result;
|
Patches result;
|
||||||
bool foundEEOF = false;
|
bool foundEEOF = false;
|
||||||
@ -190,7 +190,7 @@ namespace hex {
|
|||||||
// Handle normal record
|
// Handle normal record
|
||||||
if (size > 0x0000) {
|
if (size > 0x0000) {
|
||||||
if (ipsOffset + size > ipsPatch.size() - 3)
|
if (ipsOffset + size > ipsPatch.size() - 3)
|
||||||
return std::unexpected(IPSError::InvalidPatchFormat);
|
return wolv::util::Unexpected(IPSError::InvalidPatchFormat);
|
||||||
|
|
||||||
for (u16 i = 0; i < size; i++)
|
for (u16 i = 0; i < size; i++)
|
||||||
result[offset + i] = ipsPatch[ipsOffset + i];
|
result[offset + i] = ipsPatch[ipsOffset + i];
|
||||||
@ -199,7 +199,7 @@ namespace hex {
|
|||||||
// Handle RLE record
|
// Handle RLE record
|
||||||
else {
|
else {
|
||||||
if (ipsOffset + 3 > ipsPatch.size() - 3)
|
if (ipsOffset + 3 > ipsPatch.size() - 3)
|
||||||
return std::unexpected(IPSError::InvalidPatchFormat);
|
return wolv::util::Unexpected(IPSError::InvalidPatchFormat);
|
||||||
|
|
||||||
u16 rleSize = ipsPatch[ipsOffset + 0] | (ipsPatch[ipsOffset + 1] << 8);
|
u16 rleSize = ipsPatch[ipsOffset + 0] | (ipsPatch[ipsOffset + 1] << 8);
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ namespace hex {
|
|||||||
if (foundEEOF)
|
if (foundEEOF)
|
||||||
return result;
|
return result;
|
||||||
else
|
else
|
||||||
return std::unexpected(IPSError::MissingEOF);
|
return wolv::util::Unexpected(IPSError::MissingEOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user