rewrite word select table to support all versions

This commit is contained in:
Martin Michelsen
2023-12-30 00:48:20 -08:00
parent eea12d8d75
commit 818204a93f
22 changed files with 725 additions and 88 deletions
+13 -1
View File
@@ -5,10 +5,12 @@
#include <memory>
#include <phosg/Encoding.hh>
#include <stdexcept>
#include <string>
#include <vector>
#include "Text.hh" // for parray
#include "Compression.hh"
#include "Text.hh"
class PSOEncryption {
public:
@@ -277,6 +279,16 @@ DecryptedPR2 decrypt_pr2_data(const std::string& data) {
return ret;
}
template <bool IsBigEndian>
std::string decrypt_and_decompress_pr2_data(const std::string& data) {
auto decrypted = decrypt_pr2_data<IsBigEndian>(data);
std::string decompressed = prs_decompress(decrypted.compressed_data);
if (decompressed.size() != decrypted.decompressed_size) {
throw std::runtime_error("decompressed size does not match expected size");
}
return decompressed;
}
template <bool IsBigEndian>
std::string encrypt_pr2_data(const std::string& data, size_t decompressed_size, uint32_t seed) {
using U32T = std::conditional_t<IsBigEndian, be_uint32_t, le_uint32_t>;