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)`);