3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Fix reading of cursed Hypixel block palettes

Fixes #3037
Dieser Commit ist enthalten in:
Nassim Jahnke 2022-07-24 18:42:25 +02:00
Ursprung c8a010c390
Commit c2ee558235
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B

Datei anzeigen

@ -51,7 +51,12 @@ public final class PaletteType1_18 extends Type<DataPalette> {
//TODO Create proper singleton palette Object
palette = new DataPaletteImpl(type.size(), 1);
palette.addId(Type.VAR_INT.readPrimitive(buffer));
Type.VAR_INT.readPrimitive(buffer); // 0 values length
// Just eat it if not 0 - thanks, Hypixel
final int valuesLength = Type.VAR_INT.readPrimitive(buffer);
for (int i = 0; i < valuesLength; i++) {
buffer.readLong();
}
return palette;
}
@ -74,18 +79,17 @@ public final class PaletteType1_18 extends Type<DataPalette> {
// Read values
final int valuesLength = Type.VAR_INT.readPrimitive(buffer);
if (valuesLength > 0) {
final int valuesPerLong = (char) (64 / bitsPerValue);
final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong;
if (valuesLength != expectedLength) {
throw new IllegalStateException("Palette data length (" + valuesLength + ") does not match expected length (" + expectedLength + ")! bitsPerValue=" + bitsPerValue + ", originalBitsPerValue=" + originalBitsPerValue);
}
final long[] values = new long[valuesLength];
for (int i = 0; i < values.length; i++) {
for (int i = 0; i < valuesLength; i++) {
values[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerValue, type.size(), values,
bitsPerValue == globalPaletteBits ? palette::setIdAt : palette::setPaletteIndexAt);
final int valuesPerLong = (char) (64 / bitsPerValue);
final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong;
if (valuesLength == expectedLength) { // Thanks, Hypixel
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerValue, type.size(), values,
bitsPerValue == globalPaletteBits ? palette::setIdAt : palette::setPaletteIndexAt);
}
}
return palette;
}