From 46add5fb74eeeb76ff3c99d28dfb1442a1cb2914 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Fri, 1 Apr 2022 21:24:42 -0700 Subject: [PATCH] fix PSO PC encryption --- src/PSOEncryption.cc | 6 ++---- src/PSOEncryption.hh | 14 +++++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/PSOEncryption.cc b/src/PSOEncryption.cc index f41f3a47..21ef2cce 100644 --- a/src/PSOEncryption.cc +++ b/src/PSOEncryption.cc @@ -30,8 +30,7 @@ void PSOPCEncryption::update_stream() { eax = edi; while (edx > 0) { esi = this->stream[eax + 0x1F]; - ebp = this->stream[eax]; - ebp = ebp - esi; + ebp = this->stream[eax] - esi; this->stream[eax] = ebp; eax++; edx--; @@ -41,8 +40,7 @@ void PSOPCEncryption::update_stream() { eax = edi; while (edx > 0) { esi = this->stream[eax - 0x18]; - ebp = this->stream[eax]; - ebp = ebp - esi; + ebp = this->stream[eax] - esi; this->stream[eax] = ebp; eax++; edx--; diff --git a/src/PSOEncryption.hh b/src/PSOEncryption.hh index 003d8844..89accd5d 100644 --- a/src/PSOEncryption.hh +++ b/src/PSOEncryption.hh @@ -8,7 +8,7 @@ -#define PC_STREAM_LENGTH 57 +#define PC_STREAM_LENGTH 56 #define GC_STREAM_LENGTH 521 #define BB_STREAM_LENGTH 1042 @@ -18,6 +18,14 @@ public: virtual void encrypt(void* data, size_t size, bool advance = true) = 0; virtual void decrypt(void* data, size_t size, bool advance = true); + + inline void encrypt(std::string& data, bool advance = true) { + this->encrypt(data.data(), data.size(), advance); + } + inline void decrypt(std::string& data, bool advance = true) { + this->decrypt(data.data(), data.size(), advance); + } + virtual void skip(size_t size) = 0; protected: @@ -35,8 +43,8 @@ protected: void update_stream(); uint32_t next(bool advance = true); - uint32_t stream[PC_STREAM_LENGTH]; - uint16_t offset; + uint32_t stream[PC_STREAM_LENGTH + 1]; + uint8_t offset; }; class PSOGCEncryption : public PSOEncryption {