Fix some textures not being loaded to due being misaligned base64 data
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package moe.nea.firmament.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
|
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
|
||||||
|
import moe.nea.firmament.util.Base64Util;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(value = YggdrasilMinecraftSessionService.class, remap = false)
|
||||||
|
public class TextureUnpackBase64PadPatch {
|
||||||
|
@ModifyExpressionValue(method = "unpackTextures",
|
||||||
|
remap = false,
|
||||||
|
at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/properties/Property;value()Ljava/lang/String;"))
|
||||||
|
private String base64PadTexture(String original) {
|
||||||
|
if (original.length() % 4 == 0) return original;
|
||||||
|
return Base64Util.INSTANCE.padToValidBase64(original);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/main/kotlin/moe/nea/firmament/util/Base64Util.kt
Normal file
15
src/main/kotlin/moe/nea/firmament/util/Base64Util.kt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package moe.nea.firmament.util
|
||||||
|
|
||||||
|
object Base64Util {
|
||||||
|
fun String.padToValidBase64(): String {
|
||||||
|
val align = this.length % 4
|
||||||
|
if (align == 0) return this
|
||||||
|
return this + "=".repeat(4 - align)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import net.minecraft.component.type.ProfileComponent
|
|||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.item.Items
|
import net.minecraft.item.Items
|
||||||
import moe.nea.firmament.Firmament
|
import moe.nea.firmament.Firmament
|
||||||
|
import moe.nea.firmament.util.Base64Util.padToValidBase64
|
||||||
import moe.nea.firmament.util.assertTrueOr
|
import moe.nea.firmament.util.assertTrueOr
|
||||||
import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
||||||
import moe.nea.firmament.util.json.InstantAsLongSerializer
|
import moe.nea.firmament.util.json.InstantAsLongSerializer
|
||||||
@@ -49,14 +50,11 @@ fun GameProfile.setTextures(textures: MinecraftTexturesPayloadKt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val propertyTextures = "textures"
|
private val propertyTextures = "textures"
|
||||||
fun String.padBase64(): String {
|
|
||||||
return this + "=".repeat((4 - (this.length % 4)) % 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ItemStack.setEncodedSkullOwner(uuid: UUID, encodedData: String) {
|
fun ItemStack.setEncodedSkullOwner(uuid: UUID, encodedData: String) {
|
||||||
assert(this.item == Items.PLAYER_HEAD)
|
assert(this.item == Items.PLAYER_HEAD)
|
||||||
val gameProfile = GameProfile(uuid, "LameGuy123")
|
val gameProfile = GameProfile(uuid, "LameGuy123")
|
||||||
gameProfile.properties.put(propertyTextures, Property(propertyTextures, encodedData.padBase64()))
|
gameProfile.properties.put(propertyTextures, Property(propertyTextures, encodedData.padToValidBase64()))
|
||||||
this.set(DataComponentTypes.PROFILE, ProfileComponent(gameProfile))
|
this.set(DataComponentTypes.PROFILE, ProfileComponent(gameProfile))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user