From d0d71b85575d91c8e72b0dec99f4e167d04cbaa2 Mon Sep 17 00:00:00 2001 From: ZekerZhayard Date: Fri, 8 Aug 2025 23:24:20 +0800 Subject: [PATCH] Support 1.21.8. Split GameProfileLoader and MojangAPILoader. (#343) --- .../fake/FakeSkinManager.java | 6 +- .../loader/GameProfileLoader.java | 112 ++++++++++++++++++ .../loader/MojangAPILoader.java | 49 +------- .../customskinloader/plugin/PluginLoader.java | 2 + Fabric/build.properties | 4 +- Forge/V3/build.properties | 4 +- 6 files changed, 125 insertions(+), 52 deletions(-) create mode 100644 Common/src/main/java/customskinloader/loader/GameProfileLoader.java diff --git a/Common/src/main/java/customskinloader/fake/FakeSkinManager.java b/Common/src/main/java/customskinloader/fake/FakeSkinManager.java index abcf814..631c15e 100644 --- a/Common/src/main/java/customskinloader/fake/FakeSkinManager.java +++ b/Common/src/main/java/customskinloader/fake/FakeSkinManager.java @@ -21,7 +21,7 @@ import com.mojang.authlib.properties.Property; import customskinloader.CustomSkinLoader; import customskinloader.fake.itf.FakeInterfaceManager; import customskinloader.fake.texture.FakeThreadDownloadImageData; -import customskinloader.loader.MojangAPILoader; +import customskinloader.loader.GameProfileLoader; import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; import customskinloader.utils.HttpTextureUtil; @@ -301,7 +301,7 @@ public class FakeSkinManager { public static class FakeCacheKey { public static Object wrapCacheKey(Object cacheKey, GameProfile profile) { if (FakeInterfaceManager.SkinManagerCacheKey_profile(cacheKey) == null) { // 23w42a+ - TextureUtil.AuthlibField.PROPERTY_SIGNATURE.set(FakeInterfaceManager.SkinManagerCacheKey_packedTextures(cacheKey), MojangAPILoader.GSON.toJson(profile, GameProfile.class)); + TextureUtil.AuthlibField.PROPERTY_SIGNATURE.set(FakeInterfaceManager.SkinManagerCacheKey_packedTextures(cacheKey), GameProfileLoader.GSON.toJson(profile, GameProfile.class)); } return cacheKey; } @@ -315,7 +315,7 @@ public class FakeSkinManager { } public static GameProfile unwrapProperty(Property property) { - return MojangAPILoader.GSON.fromJson((String) TextureUtil.AuthlibField.PROPERTY_SIGNATURE.get(property), GameProfile.class); // 23w42a+ + return GameProfileLoader.GSON.fromJson((String) TextureUtil.AuthlibField.PROPERTY_SIGNATURE.get(property), GameProfile.class); // 23w42a+ } public static class IncompletedContainer { diff --git a/Common/src/main/java/customskinloader/loader/GameProfileLoader.java b/Common/src/main/java/customskinloader/loader/GameProfileLoader.java new file mode 100644 index 0000000..b20bdbb --- /dev/null +++ b/Common/src/main/java/customskinloader/loader/GameProfileLoader.java @@ -0,0 +1,112 @@ +package customskinloader.loader; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; +import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; +import com.mojang.util.UUIDTypeAdapter; +import customskinloader.CustomSkinLoader; +import customskinloader.config.SkinSiteProfile; +import customskinloader.plugin.ICustomSkinLoaderPlugin; +import customskinloader.profile.ModelManager0; +import customskinloader.profile.UserProfile; +import customskinloader.utils.TextureUtil; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; + +public class GameProfileLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader { + @Override + public ProfileLoader.IProfileLoader getProfileLoader() { + return this; + } + + @Override + public List getDefaultProfiles() { + return Lists.newArrayList(new ServerGameProfile(this)); + } + + public static class ServerGameProfile implements ICustomSkinLoaderPlugin.IDefaultProfile { + protected final GameProfileLoader loader; + + public ServerGameProfile(GameProfileLoader loader) { + this.loader = loader; + } + + @Override + public String getName() { + return "GameProfile"; + } + + @Override + public int getPriority() { + return 50; + } + + @Override + public void updateSkinSiteProfile(SkinSiteProfile ssp) { + ssp.type = this.loader.getName(); + } + } + + @Override + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { + Map map = getTextures(gameProfile); + if (!map.isEmpty()) { + CustomSkinLoader.logger.info("Default profile will be used."); + return ModelManager0.toUserProfile(map); + } + return null; + } + + @Override + public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) { + return true; + } + + @Override + public String getName() { + return "GameProfile"; + } + + @Override + public void init(SkinSiteProfile ssp) { + + } + + public static final Gson GSON = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); + public static Map getTextures(GameProfile gameProfile) { + if (gameProfile == null) { + return Maps.newHashMap(); + } + Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null); + if (textureProperty == null) { + return Maps.newHashMap(); + } + String value = TextureUtil.AuthlibField.PROPERTY_VALUE.get(textureProperty); + if (StringUtils.isBlank(value)) { + return Maps.newHashMap(); + } + String json = new String(Base64.decodeBase64(value), StandardCharsets.UTF_8); + MinecraftTexturesPayload result = GSON.fromJson(json, MinecraftTexturesPayload.class); + + if (result == null) { + return Maps.newHashMap(); + } + Map textures = TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result); + if (textures == null) { + return Maps.newHashMap(); + } + return textures; + } +} diff --git a/Common/src/main/java/customskinloader/loader/MojangAPILoader.java b/Common/src/main/java/customskinloader/loader/MojangAPILoader.java index 85bca69..3619fe6 100644 --- a/Common/src/main/java/customskinloader/loader/MojangAPILoader.java +++ b/Common/src/main/java/customskinloader/loader/MojangAPILoader.java @@ -1,24 +1,15 @@ package customskinloader.loader; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mojang.authlib.properties.Property; -import com.mojang.authlib.properties.PropertyMap; import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse; -import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; -import com.mojang.util.UUIDTypeAdapter; import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; import customskinloader.plugin.ICustomSkinLoaderPlugin; @@ -26,7 +17,6 @@ import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; import customskinloader.utils.HttpRequestUtil; import customskinloader.utils.TextureUtil; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader { @@ -88,11 +78,6 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I @Override public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) { - Map map = getTextures(gameProfile); - if (!map.isEmpty()) { - CustomSkinLoader.logger.info("Default profile will be used."); - return ModelManager0.toUserProfile(map); - } String username = gameProfile.getName(); GameProfile newGameProfile = loadGameProfileCached(ssp.apiRoot, username); if (newGameProfile == null) { @@ -100,7 +85,7 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I return null; } newGameProfile = fillGameProfile(ssp.sessionRoot, newGameProfile); - map = getTextures(newGameProfile); + Map map = GameProfileLoader.getTextures(newGameProfile); if (!map.isEmpty()) { gameProfile.getProperties().putAll(newGameProfile.getProperties()); return ModelManager0.toUserProfile(map); @@ -109,7 +94,6 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I return null; } - public static final Gson GSON = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); private static final Map gameProfileCache = new ConcurrentHashMap<>(); public static GameProfile loadGameProfileCached(String apiRoot, String username) { @@ -119,12 +103,12 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I //Username -> UUID public static GameProfile loadGameProfile(String apiRoot, String username) { //Doc (https://minecraft.wiki/w/Mojang_API#Query_player_UUIDs_in_batch) - HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft").setCacheTime(600).setPayload(GSON.toJson(Collections.singletonList(username)))); + HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft").setCacheTime(600).setPayload(GameProfileLoader.GSON.toJson(Collections.singletonList(username)))); if (StringUtils.isEmpty(responce.content)) { return null; } - GameProfile[] profiles = GSON.fromJson(responce.content, GameProfile[].class); + GameProfile[] profiles = GameProfileLoader.GSON.fromJson(responce.content, GameProfile[].class); if (profiles.length == 0) { return null; } @@ -160,38 +144,13 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I return profile; } - MinecraftProfilePropertiesResponse propertiesResponce = GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class); + MinecraftProfilePropertiesResponse propertiesResponce = GameProfileLoader.GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class); GameProfile newGameProfile = new GameProfile(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(propertiesResponce), TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME.get(propertiesResponce)); newGameProfile.getProperties().putAll(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(propertiesResponce)); return newGameProfile; } - public static Map getTextures(GameProfile gameProfile) { - if (gameProfile == null) { - return Maps.newHashMap(); - } - Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null); - if (textureProperty == null) { - return Maps.newHashMap(); - } - String value = TextureUtil.AuthlibField.PROPERTY_VALUE.get(textureProperty); - if (StringUtils.isBlank(value)) { - return Maps.newHashMap(); - } - String json = new String(Base64.decodeBase64(value), StandardCharsets.UTF_8); - MinecraftTexturesPayload result = GSON.fromJson(json, MinecraftTexturesPayload.class); - - if (result == null) { - return Maps.newHashMap(); - } - Map textures = TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result); - if (textures == null) { - return Maps.newHashMap(); - } - return textures; - } - @Override public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) { return (!StringUtils.isNoneEmpty(ssp0.apiRoot) || ssp0.apiRoot.equalsIgnoreCase(ssp1.apiRoot)) || (!StringUtils.isNoneEmpty(ssp0.sessionRoot) || ssp0.sessionRoot.equalsIgnoreCase(ssp1.sessionRoot)); diff --git a/Common/src/main/java/customskinloader/plugin/PluginLoader.java b/Common/src/main/java/customskinloader/plugin/PluginLoader.java index 6e7635a..fc6e203 100644 --- a/Common/src/main/java/customskinloader/plugin/PluginLoader.java +++ b/Common/src/main/java/customskinloader/plugin/PluginLoader.java @@ -9,6 +9,7 @@ import java.util.ServiceLoader; import com.google.common.collect.Lists; import customskinloader.CustomSkinLoader; +import customskinloader.loader.GameProfileLoader; import customskinloader.loader.JsonAPILoader; import customskinloader.loader.LegacyLoader; import customskinloader.loader.MojangAPILoader; @@ -17,6 +18,7 @@ import org.apache.commons.io.FileUtils; public class PluginLoader { public static final ICustomSkinLoaderPlugin[] DEFAULT_PLUGINS = new ICustomSkinLoaderPlugin[]{ + new GameProfileLoader(), new MojangAPILoader(), new LegacyLoader(), new JsonAPILoader(new CustomSkinAPI()), diff --git a/Fabric/build.properties b/Fabric/build.properties index ccb9b0e..ec6d759 100644 --- a/Fabric/build.properties +++ b/Fabric/build.properties @@ -1,5 +1,5 @@ -dependencies=Fabric|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6;\ - Quilt|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6 +dependencies=Fabric|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8;\ + Quilt|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8 java_full_versions=8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 #forge gradle needs forge version forge_mc_version=1.12.2 diff --git a/Forge/V3/build.properties b/Forge/V3/build.properties index 9751f62..7ef4d64 100644 --- a/Forge/V3/build.properties +++ b/Forge/V3/build.properties @@ -1,5 +1,5 @@ -dependencies=Forge|1.20.6,1.21,1.21.1,1.21.3,1.21.4,1.21.5,1.21.6;\ - NeoForge|1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6 +dependencies=Forge|1.20.6,1.21,1.21.1,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8;\ + NeoForge|1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8 java_full_versions=17,18,19,20,21,22 #forge gradle needs forge version forge_mc_version=1.12.2