make encryption objects serializable
This commit is contained in:
@@ -25,6 +25,30 @@ PSOLFGEncryption::PSOLFGEncryption(
|
|||||||
end_offset(end_offset),
|
end_offset(end_offset),
|
||||||
seed(seed) {}
|
seed(seed) {}
|
||||||
|
|
||||||
|
PSOLFGEncryption::PSOLFGEncryption(const std::string& serialized) {
|
||||||
|
StringReader r(serialized);
|
||||||
|
this->offset = r.get_u32l();
|
||||||
|
this->end_offset = r.get_u32l();
|
||||||
|
this->seed = r.get_u32l();
|
||||||
|
size_t num_entries = r.get_u32l();
|
||||||
|
this->stream.reserve(num_entries);
|
||||||
|
while (this->stream.size() < num_entries) {
|
||||||
|
this->stream.emplace_back(r.get_u32l());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PSOLFGEncryption::serialize() const {
|
||||||
|
StringWriter w;
|
||||||
|
w.put_u32l(this->offset);
|
||||||
|
w.put_u32l(this->end_offset);
|
||||||
|
w.put_u32l(this->seed);
|
||||||
|
w.put_u32l(this->stream.size());
|
||||||
|
for (uint32_t x : this->stream) {
|
||||||
|
w.put_u32l(x);
|
||||||
|
}
|
||||||
|
return std::move(w.str());
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t PSOLFGEncryption::next(bool advance) {
|
uint32_t PSOLFGEncryption::next(bool advance) {
|
||||||
if (this->offset == this->end_offset) {
|
if (this->offset == this->end_offset) {
|
||||||
this->update_stream();
|
this->update_stream();
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ protected:
|
|||||||
|
|
||||||
class PSOLFGEncryption : public PSOEncryption {
|
class PSOLFGEncryption : public PSOEncryption {
|
||||||
public:
|
public:
|
||||||
|
explicit PSOLFGEncryption(const std::string& serialized);
|
||||||
|
|
||||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||||
void encrypt_big_endian(void* data, size_t size, bool advance = true);
|
void encrypt_big_endian(void* data, size_t size, bool advance = true);
|
||||||
void encrypt_minus(void* data, size_t size, bool advance = true);
|
void encrypt_minus(void* data, size_t size, bool advance = true);
|
||||||
@@ -52,8 +54,10 @@ public:
|
|||||||
|
|
||||||
uint32_t next(bool advance = true);
|
uint32_t next(bool advance = true);
|
||||||
|
|
||||||
|
virtual std::string serialize() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PSOLFGEncryption(uint32_t seed, size_t stream_length, size_t end_offset);
|
PSOLFGEncryption(uint32_t seed, size_t stream_length, size_t end_offset);
|
||||||
|
|
||||||
virtual void update_stream() = 0;
|
virtual void update_stream() = 0;
|
||||||
|
|
||||||
@@ -66,7 +70,6 @@ protected:
|
|||||||
class PSOV2Encryption : public PSOLFGEncryption {
|
class PSOV2Encryption : public PSOLFGEncryption {
|
||||||
public:
|
public:
|
||||||
explicit PSOV2Encryption(uint32_t seed);
|
explicit PSOV2Encryption(uint32_t seed);
|
||||||
|
|
||||||
virtual Type type() const;
|
virtual Type type() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -78,7 +81,6 @@ protected:
|
|||||||
class PSOV3Encryption : public PSOLFGEncryption {
|
class PSOV3Encryption : public PSOLFGEncryption {
|
||||||
public:
|
public:
|
||||||
explicit PSOV3Encryption(uint32_t key);
|
explicit PSOV3Encryption(uint32_t key);
|
||||||
|
|
||||||
virtual Type type() const;
|
virtual Type type() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user