diff --git a/main/chatparser.js b/main/chatparser.js index e9a3a94..0b6dcbd 100644 --- a/main/chatparser.js +++ b/main/chatparser.js @@ -225,14 +225,15 @@ function parseMinecraftMessage(component) { if (comp.with) { const withArgs = comp.with.map(arg => extractText(arg)); let usedReplacements = 0; - translateString = translateString.replace(/thing__placeholder__/g, 'default_thing__placeholder__'); + translateString = translateString.replace(/%s/g, (match, offset, string) => { if (offset > 0 && string[offset - 1] === '%') { return 's'; } - + if (usedReplacements < withArgs.length) { + if (translateString.length + formatfunction(comp, withArgs[usedReplacements]).length > 2048) return 'Translate Crash'; // Prevent translate crash return `thing__placeholder__${usedReplacements++}`; } @@ -251,11 +252,12 @@ function parseMinecraftMessage(component) { if (stringindex > 0 && string[stringindex - 1] === '%') { return match; } - + if (translateString.length + formatfunction(comp, withArgs[argIndex]).length > 2048) return 'Translate Crash'; // Prevent translate crash return `thing__placeholder__${argIndex}`; }); for (let i = 0; i < withArgs.length; i++) { + if (translateString.length + formatfunction(comp, withArgs[i]).length > 2048) return 'Translate Crash'; // Prevent translate crash translateString = translateString.replace(new RegExp(`thing__placeholder__${i}`, 'g'), (match) => { const formattedArg = formatfunction(comp, withArgs[i]); return formattedArg; @@ -318,6 +320,7 @@ function parseMinecraftMessageNoColor(component) { } if (usedReplacements < withArgs.length) { + if (translateString.length + withArgs[usedReplacements].length > 2048) return 'Translate Crash'; // Prevent translate crash return `thing__placeholder__${usedReplacements++}`; } @@ -336,11 +339,13 @@ function parseMinecraftMessageNoColor(component) { if (stringindex > 0 && string[stringindex - 1] === '%') { return match; } - + + if (translateString.length + withArgs[argIndex].length > 2048) return 'Translate Crash'; // Prevent translate crash return `thing__placeholder__${argIndex}`; }); for (let i = 0; i < withArgs.length; i++) { + if (translateString.length + withArgs[i].length > 2048) return 'Translate Crash'; // Prevent translate crash translateString = translateString.replace(new RegExp(`thing__placeholder__${i}`, 'g'), (match) => { const formattedArg = withArgs[i]; return formattedArg;