From 15c08c010154b09b2b0d5d4e8483344f4dfb66c3 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 4 Oct 2023 23:13:13 -0700 Subject: [PATCH] add more info to 6xB4x46 version messages --- src/Episode3/Server.cc | 6 +++++- src/PSOEncryption.cc | 33 +++++++-------------------------- src/PSOEncryption.hh | 12 ++++++++---- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index a45b9423..14ce61f8 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -239,7 +239,11 @@ void Server::send_6xB4x46() const { G_ServerVersionStrings_GC_Ep3_6xB4x46 cmd46; cmd46.version_signature = VERSION_SIGNATURE; cmd46.date_str1 = format_time(this->card_index->definitions_mtime() * 1000000); - cmd46.date_str2 = string_printf("Lobby/%08" PRIX32, l->lobby_id); + if (this->last_chosen_map) { + cmd46.date_str2 = string_printf("Lobby:%08" PRIX32 " Random:%08" PRIX32 "+%08" PRIX32 " Map:%08" PRIX32, l->lobby_id, this->random_crypt->seed(), this->random_crypt->absolute_offset(), this->last_chosen_map->map.map_number.load()); + } else { + cmd46.date_str2 = string_printf("Lobby:%08" PRIX32 " Random:%08" PRIX32 "+%08" PRIX32, l->lobby_id, this->random_crypt->seed(), this->random_crypt->absolute_offset()); + } this->send(cmd46); } diff --git a/src/PSOEncryption.cc b/src/PSOEncryption.cc index ff5baae0..2511c4c1 100644 --- a/src/PSOEncryption.cc +++ b/src/PSOEncryption.cc @@ -23,31 +23,8 @@ PSOLFGEncryption::PSOLFGEncryption( : stream(stream_length, 0), offset(0), end_offset(end_offset), - 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()); -} + initial_seed(seed), + cycles(0) {} uint32_t PSOLFGEncryption::next(bool advance) { if (this->offset == this->end_offset) { @@ -143,7 +120,7 @@ PSOV2Encryption::PSOV2Encryption(uint32_t seed) : PSOLFGEncryption(seed, this->STREAM_LENGTH + 1, this->STREAM_LENGTH) { uint32_t esi, ebx, edi, eax, edx, var1; esi = 1; - ebx = this->seed; + ebx = this->initial_seed; edi = 0x15; this->stream[56] = ebx; this->stream[55] = ebx; @@ -160,6 +137,7 @@ PSOV2Encryption::PSOV2Encryption(uint32_t seed) for (size_t x = 0; x < 5; x++) { this->update_stream(); } + this->cycles = 0; } void PSOV2Encryption::update_stream() { @@ -185,6 +163,7 @@ void PSOV2Encryption::update_stream() { edx--; } this->offset = 1; + this->cycles++; } PSOEncryption::Type PSOV2Encryption::type() const { @@ -222,6 +201,7 @@ PSOV3Encryption::PSOV3Encryption(uint32_t seed) for (size_t x = 0; x < 4; x++) { this->update_stream(); } + this->cycles = 0; } void PSOV3Encryption::update_stream() { @@ -239,6 +219,7 @@ void PSOV3Encryption::update_stream() { } this->offset = 0; + this->cycles++; } PSOEncryption::Type PSOV3Encryption::type() const { diff --git a/src/PSOEncryption.hh b/src/PSOEncryption.hh index 91046148..c07112f4 100644 --- a/src/PSOEncryption.hh +++ b/src/PSOEncryption.hh @@ -39,8 +39,6 @@ protected: class PSOLFGEncryption : public PSOEncryption { public: - explicit PSOLFGEncryption(const std::string& serialized); - 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_minus(void* data, size_t size, bool advance = true); @@ -54,7 +52,12 @@ public: uint32_t next(bool advance = true); - virtual std::string serialize() const; + inline uint32_t seed() const { + return this->initial_seed; + } + uint32_t absolute_offset() const { + return (this->cycles * this->end_offset) + this->offset; + } protected: PSOLFGEncryption(uint32_t seed, size_t stream_length, size_t end_offset); @@ -64,7 +67,8 @@ protected: std::vector stream; size_t offset; size_t end_offset; - uint32_t seed; + uint32_t initial_seed; + size_t cycles; }; class PSOV2Encryption : public PSOLFGEncryption {