Fix sliceAtEOF() bug causing short ANSI's to get borked when e.g. display achievements

This commit is contained in:
Bryan Ashby 2020-05-13 20:19:45 -06:00
parent fd6bb47427
commit b7cac2d38f
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
1 changed files with 9 additions and 2 deletions

View File

@ -49,7 +49,7 @@ function getFontNameFromSAUCE(sauce) {
function sliceAtEOF(data, eofMarker) { function sliceAtEOF(data, eofMarker) {
let eof = data.length; let eof = data.length;
const stopPos = Math.max(data.length - (256), 0); // 256 = 2 * sizeof(SAUCE) const stopPos = Math.max(data.length - 256, 0); // 256 = 2 * sizeof(SAUCE)
for(let i = eof - 1; i > stopPos; i--) { for(let i = eof - 1; i > stopPos; i--) {
if(eofMarker === data[i]) { if(eofMarker === data[i]) {
@ -57,9 +57,16 @@ function sliceAtEOF(data, eofMarker) {
break; break;
} }
} }
if(eof === data.length || eof < 128) {
if (eof === data.length) {
return data; // nothing to do
}
// try to prevent goofs
if (eof < 128 && 'SAUCE00' !== data.slice(eof + 1, eof + 8).toString()) {
return data; return data;
} }
return data.slice(0, eof); return data.slice(0, eof);
} }