From 8335c06d5122cddf359fcb9ab9c1dbaace4828ce Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Fri, 30 Oct 2026 01:44:36 +0000 Subject: [PATCH] Decompile fn_04842 (XorWithKey16) Batch #4178 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_04842 XorWithKey16: logic confirmed by peer review Peer-reviewed-by: superintelligence, KWDev, Gravity Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Archive/GPak.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/Archive/GPak.cpp b/Source/Archive/GPak.cpp index 5cd49b7c..ba98288b 100644 --- a/Source/Archive/GPak.cpp +++ b/Source/Archive/GPak.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -114,6 +115,25 @@ namespace { } } +// OFFSET: 0x00644260 +// FUNCTION: fn_04842 +void XorWithKey16(const std::uint8_t* key, const std::uint8_t* input, std::size_t length, std::uint8_t* output) { + const __m128i mask = _mm_loadu_si128(reinterpret_cast(key)); + if (length >= 16) { + std::size_t blocks = length >> 4; + do { + _mm_storeu_si128(reinterpret_cast<__m128i*>(output), _mm_xor_si128(_mm_loadu_si128(reinterpret_cast(input)), mask)); + input += 16; + output += 16; + } while (--blocks != 0); + } + + const std::size_t remainder = length & 0xF; + for (std::size_t i = 0; i < remainder; ++i) { + output[i] = input[i] ^ key[i]; + } +} + // OFFSET: 0x00654410 // FUNCTION: fn_04984 int sub_654410() {