From 81d1e7c1133010e6aaadf1f34359c9d87e95b8f8 Mon Sep 17 00:00:00 2001 From: sanasol Date: Tue, 27 Jan 2026 03:00:29 +0100 Subject: [PATCH] Add HYTALE_PATCH_MODE env var to test different string formats HYTALE_PATCH_MODE=utf16le - Use pure UTF-16LE (no length prefix) HYTALE_PATCH_MODE=length-prefixed - Use length-prefixed format (default) This helps debug if the length-prefixed format is causing crashes. Co-Authored-By: Claude Opus 4.5 --- backend/utils/clientPatcher.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/utils/clientPatcher.js b/backend/utils/clientPatcher.js index 8fa9518..33e2df2 100644 --- a/backend/utils/clientPatcher.js +++ b/backend/utils/clientPatcher.js @@ -291,12 +291,29 @@ class ClientPatcher { } // 2. Patch main domain (hytale.com -> mainDomain) + // Try length-prefixed format first, then fall back to pure UTF-16LE console.log(` Patching domain: ${ORIGINAL_DOMAIN} -> ${strategy.mainDomain}`); - const domainResult = this.replaceBytes( - result, - this.stringToLengthPrefixed(ORIGINAL_DOMAIN), - this.stringToLengthPrefixed(strategy.mainDomain) - ); + + // Check for HYTALE_PATCH_MODE env var to test different formats + const patchMode = process.env.HYTALE_PATCH_MODE || 'length-prefixed'; + console.log(` Patch mode: ${patchMode}`); + + let domainResult; + if (patchMode === 'utf16le') { + // Pure UTF-16LE replacement (no length prefix) + const oldUtf16 = this.stringToUtf16LE(ORIGINAL_DOMAIN); + const newUtf16 = this.stringToUtf16LE(strategy.mainDomain); + console.log(` UTF-16LE: old=${oldUtf16.length} bytes, new=${newUtf16.length} bytes`); + domainResult = this.replaceBytes(result, oldUtf16, newUtf16); + } else { + // Length-prefixed format (default) + domainResult = this.replaceBytes( + result, + this.stringToLengthPrefixed(ORIGINAL_DOMAIN), + this.stringToLengthPrefixed(strategy.mainDomain) + ); + } + result = domainResult.buffer; if (domainResult.count > 0) { console.log(` Replaced ${domainResult.count} domain occurrence(s)`);