From f6c047795d651962374fcb20d37359c763aeb9c8 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 28 Feb 2023 10:45:56 -0400 Subject: PSOV3EncryptionTCP: Add, and fully match `PSOV3EncryptionTCP` That was way easier than I expected, I thought it'd take a lot longer than this. --- context.h | 39 +++++++++++++++++++++++++++------------ include/pso/PSOV3EncryptionTCP.h | 24 ++++++++++++++++++++++++ obj_files.mk | 1 + src/pso/PSOV3EncryptionTCP.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 include/pso/PSOV3EncryptionTCP.h create mode 100644 src/pso/PSOV3EncryptionTCP.cpp diff --git a/context.h b/context.h index 2fcdc7f..52f9bb8 100644 --- a/context.h +++ b/context.h @@ -541,8 +541,34 @@ static inline void operator^=(object_flags &a, object_flags b) { a = a ^ b; }; static inline void operator&=(object_flags &a, object_flags b) { a = a & b; }; static inline void operator|=(object_flags &a, object_flags b) { a = a | b; }; -// pso/TSocket.h +// pso/TPlyGuildCardTag.h // Class defs. + +class TPlyGuildCardTag { + public: + u8 tag0; + u8 tag1; + u16 tag2; + u32 guildcard_number; + TPlyGuildCardTag &operator=(const TPlyGuildCardTag &src); + void bswap(); +} __packed__; + +// pso/PSOV3EncryptionTCP.h +class PSOV3EncryptionTCP : public PSOV3Encryption { +public: + PSOV3EncryptionTCP(); + ~PSOV3EncryptionTCP(); + + void reset(u32 seed); + void encrypt(void *void_data, int size); + + PRIVATE_MEMBER_ACCESSORS(u32, seed); +private: + u32 m_seed; +}; + +// pso/TSocket.h class TSocket : public TObject { private: void set_flags(u8 flags) { @@ -613,17 +639,6 @@ public: PRIVATE_MEMBER_ACCESSORS_FUNC(void, callback, TSocket *socket); }; -// pso/TPlyGuildCardTag.h -class TPlyGuildCardTag { - public: - u8 tag0; - u8 tag1; - u16 tag2; - u32 guildcard_number; - TPlyGuildCardTag &operator=(const TPlyGuildCardTag &src); - void bswap(); -} __packed__; - // pso/THeap.h class THeap { public: diff --git a/include/pso/PSOV3EncryptionTCP.h b/include/pso/PSOV3EncryptionTCP.h new file mode 100644 index 0000000..da3208d --- /dev/null +++ b/include/pso/PSOV3EncryptionTCP.h @@ -0,0 +1,24 @@ +#ifndef PSOV3ENCRYPTIONTCP_H +#define PSOV3ENCRYPTIONTCP_H + +#include +#include +#include +#include +#include +#include + +class PSOV3EncryptionTCP : public PSOV3Encryption { +public: + PSOV3EncryptionTCP(); + ~PSOV3EncryptionTCP(); + + void reset(u32 seed); + void encrypt(void *void_data, int size); + + PRIVATE_MEMBER_ACCESSORS(u32, seed); +private: + u32 m_seed; +}; + +#endif diff --git a/obj_files.mk b/obj_files.mk index 522cf50..1f9de57 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -1,6 +1,7 @@ O_FILES := $(BUILD_DIR)/src/main.o \ $(BUILD_DIR)/src/pso/TPlyGuildCardTag.o \ $(BUILD_DIR)/src/pso/TSocket.o \ + $(BUILD_DIR)/src/pso/PSOV3EncryptionTCP.o \ $(BUILD_DIR)/src/pso/THeap.o \ $(BUILD_DIR)/src/pso/protocol.o \ $(BUILD_DIR)/src/pso/TMainTask.o \ diff --git a/src/pso/PSOV3EncryptionTCP.cpp b/src/pso/PSOV3EncryptionTCP.cpp new file mode 100644 index 0000000..737c510 --- /dev/null +++ b/src/pso/PSOV3EncryptionTCP.cpp @@ -0,0 +1,29 @@ +#include +#include +#include "pso/macros.h" +#include "pso/PSOV3EncryptionTCP.h" +#include "pso/TArray.h" + +void PSOV3EncryptionTCP::encrypt(void *void_data, int size) { + u32 *data = reinterpret_cast(void_data); + size = (size + 3) / 4; + for (int i = 0; i < size; ++i) { + bswap_32(&data[i]); + data[i] ^= next(); + bswap_32(&data[i]); + } +} + +void PSOV3EncryptionTCP::reset(u32 seed) { + m_seed = seed; + init(seed); +} + +PSOV3EncryptionTCP::~PSOV3EncryptionTCP() { + +} + +PSOV3EncryptionTCP::PSOV3EncryptionTCP() : PSOV3Encryption() { + reset(0); +} + -- cgit v1.2.3-13-gbd6f