From 0ffa9ef1373ef89975c72177a96d7e3f2f3f91bb Mon Sep 17 00:00:00 2001 From: ZekerZhayard Date: Tue, 12 Dec 2023 00:04:05 +0800 Subject: [PATCH] 23w42a (#281) --- .../com/mojang/authlib/SignatureState.java | 7 + .../minecraft/MinecraftProfileTextures.java | 9 ++ .../customskinloader/CustomSkinLoader.java | 12 +- .../customskinloader/fake/FakeCapeBuffer.java | 20 --- .../fake/FakeMinecraftProfileTexture.java | 30 ++-- .../fake/FakeSkinManager.java | 129 +++++++++--------- .../fake/itf/FakeInterfaceManager.java | 7 +- .../fake/itf/IFakeSkinManagerCacheKey.java | 12 ++ .../itf/IFakeThreadDownloadImageData.java | 12 -- .../loader/MojangAPILoader.java | 15 +- .../java/customskinloader/log/LogManager.java | 2 +- .../profile/DynamicSkullManager.java | 2 +- .../profile/ProfileCache.java | 8 +- .../customskinloader/profile/UserProfile.java | 34 +++++ .../customskinloader/utils/TextureUtil.java | 50 +++++-- Fabric/Fabric.tsrg | 4 +- Fabric/build.properties | 2 +- Fabric/mixin.tsrg | 2 +- .../fabric/MixinConfigPlugin.java | 2 +- .../mixin/MixinSkinManager$1.java | 30 +++- .../mixin/MixinSkinManager$CacheKey.java | 10 ++ .../mixin/MixinSkinManager$TextureCache.java | 14 -- .../mixin/MixinSkinManager.java | 29 +--- .../resources/mixins.customskinloader.json | 1 + Forge/Active/Forge.tsrg | 4 +- Forge/Active/build.properties | 2 +- .../Active/src/main/resources/transformers.js | 43 +++--- .../java/customskinloader/forge/ForgeMod.java | 24 +--- .../forge/loader/LaunchWrapper.java | 1 - .../FakeInterfacesTransformer.java | 22 --- .../transformer/SkinManagerTransformer.java | 20 --- .../Legacy/src/main/resources/transformers.js | 13 -- build.gradle | 1 + 33 files changed, 283 insertions(+), 290 deletions(-) create mode 100644 Common/src/main/java/com/mojang/authlib/SignatureState.java create mode 100644 Common/src/main/java/com/mojang/authlib/minecraft/MinecraftProfileTextures.java create mode 100644 Common/src/main/java/customskinloader/fake/itf/IFakeSkinManagerCacheKey.java delete mode 100644 Common/src/main/java/customskinloader/fake/itf/IFakeThreadDownloadImageData.java create mode 100644 Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$CacheKey.java diff --git a/Common/src/main/java/com/mojang/authlib/SignatureState.java b/Common/src/main/java/com/mojang/authlib/SignatureState.java new file mode 100644 index 00000000..8cde735c --- /dev/null +++ b/Common/src/main/java/com/mojang/authlib/SignatureState.java @@ -0,0 +1,7 @@ +package com.mojang.authlib; + +public enum SignatureState { + UNSIGNED, + INVALID, + SIGNED +} diff --git a/Common/src/main/java/com/mojang/authlib/minecraft/MinecraftProfileTextures.java b/Common/src/main/java/com/mojang/authlib/minecraft/MinecraftProfileTextures.java new file mode 100644 index 00000000..89d8b38d --- /dev/null +++ b/Common/src/main/java/com/mojang/authlib/minecraft/MinecraftProfileTextures.java @@ -0,0 +1,9 @@ +package com.mojang.authlib.minecraft; + +import com.mojang.authlib.SignatureState; + +public class MinecraftProfileTextures { + public MinecraftProfileTextures(MinecraftProfileTexture skin, MinecraftProfileTexture cape, MinecraftProfileTexture elytra, SignatureState signatureState) { + + } +} diff --git a/Common/src/main/java/customskinloader/CustomSkinLoader.java b/Common/src/main/java/customskinloader/CustomSkinLoader.java index 21bcc2fd..b2a1d455 100644 --- a/Common/src/main/java/customskinloader/CustomSkinLoader.java +++ b/Common/src/main/java/customskinloader/CustomSkinLoader.java @@ -70,24 +70,24 @@ public static void loadProfileTextures(Runnable runnable) { THREAD_POOL.execute(runnable); } - public static Object loadProfileLazily(GameProfile gameProfile, Function, ?> function) { + public static Object loadProfileLazily(GameProfile gameProfile, Function function) { String username = gameProfile.getName(); String credential = MinecraftUtil.getCredential(gameProfile); // Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713 if (username == null) { logger.warning("Could not load profile: username is null."); - return function.apply(Maps.newHashMap()); + return function.apply(null); } String tempName = Thread.currentThread().getName(); Thread.currentThread().setName(username); // Change Thread Name if (profileCache.isLoading(credential)) { profileCache.putLoader(credential, function); Thread.currentThread().setName(tempName); - return function.apply(Maps.newHashMap()); + return function.apply(null); } Object result = function.apply(loadProfile(gameProfile)); Thread.currentThread().setName(tempName); - Function, ?> func = profileCache.getLastLoader(credential); + Function func = profileCache.getLastLoader(credential); if (func != null) { result = loadProfileLazily(gameProfile, func); } @@ -95,7 +95,7 @@ public static Object loadProfileLazily(GameProfile gameProfile, Function loadProfile(GameProfile gameProfile) { + public static UserProfile loadProfile(GameProfile gameProfile) { String credential = MinecraftUtil.getCredential(gameProfile); UserProfile profile; if (profileCache.isReady(credential)) { @@ -113,7 +113,7 @@ public static Map loadPro profileCache.setLoading(credential, true); profile = loadProfile0(gameProfile, false); } - return ModelManager0.fromUserProfile(profile); + return profile; } //Core diff --git a/Common/src/main/java/customskinloader/fake/FakeCapeBuffer.java b/Common/src/main/java/customskinloader/fake/FakeCapeBuffer.java index 3bf31962..c6261b65 100644 --- a/Common/src/main/java/customskinloader/fake/FakeCapeBuffer.java +++ b/Common/src/main/java/customskinloader/fake/FakeCapeBuffer.java @@ -7,9 +7,7 @@ import java.util.function.Predicate; import customskinloader.fake.itf.FakeInterfaceManager; -import customskinloader.fake.texture.FakeBufferedImage; import customskinloader.fake.texture.FakeImage; -import customskinloader.utils.MinecraftUtil; import net.minecraft.client.Minecraft; import net.minecraft.util.ResourceLocation; @@ -38,13 +36,8 @@ private static FakeImage loadElytra(FakeImage originalImage) { private int loaded = 0; private double ratioX = -1; private double ratioY = -1; - private final ResourceLocation location; private String type = null; - public FakeCapeBuffer(ResourceLocation location) { - this.location = location; - } - @Override public FakeImage parseUserSkin(FakeImage image) { if (image == null) return null; @@ -74,9 +67,6 @@ public FakeImage parseUserSkin(FakeImage image) { if ("cape".equals(this.type)) { this.image = resetImageFormat(this.image, 0, 0, 22, 17); this.attachElytra(elytraImage); - if (this.image instanceof FakeBufferedImage) { // before 1.12.2 - this.refreshTexture((FakeBufferedImage) this.image); - } } } return this.image; @@ -156,16 +146,6 @@ private R withElytraPixels(BiPredicate predicate, R return return defaultReturnValue; } - // TextureID won't be regenerated when changing resource packs before 1.12.2 - private void refreshTexture(FakeBufferedImage image) { - Object textureObj = MinecraftUtil.getTextureManager().getTexture(this.location); - if (textureObj != null) { - // NOTICE: OptiFine modified the upload process of the texture from ThreadDownloadImageData - // Therefore, it may not be correct to simply copy the vanilla behavior - FakeInterfaceManager.ThreadDownloadImageData_resetNewBufferedImage(textureObj, image.getImage()); - } - } - // Some cape image doesn't support alpha channel, so reset image format to ARGB private static FakeImage resetImageFormat(FakeImage image, int startX, int startY, int endX, int endY) { if (image != null) { diff --git a/Common/src/main/java/customskinloader/fake/FakeMinecraftProfileTexture.java b/Common/src/main/java/customskinloader/fake/FakeMinecraftProfileTexture.java index 6fc25ba8..1423bb49 100644 --- a/Common/src/main/java/customskinloader/fake/FakeMinecraftProfileTexture.java +++ b/Common/src/main/java/customskinloader/fake/FakeMinecraftProfileTexture.java @@ -2,15 +2,16 @@ import java.io.File; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import customskinloader.utils.HttpTextureUtil; -import net.minecraft.util.ResourceLocation; public class FakeMinecraftProfileTexture extends MinecraftProfileTexture { + private final static Map MODEL_CACHE = new ConcurrentHashMap<>(); + private final HttpTextureUtil.HttpTextureInfo info; private final Map metadata; - private ResourceLocation resourceLocation; public FakeMinecraftProfileTexture(String url, Map metadata) { super(url, metadata); @@ -18,22 +19,27 @@ public FakeMinecraftProfileTexture(String url, Map metadata) { this.metadata = metadata; } - public void setResourceLocation(ResourceLocation resourceLocation) { - this.resourceLocation = resourceLocation; - } - - public ResourceLocation getResourceLocation() { - return this.resourceLocation; - } - @Override public String getUrl() { return this.info.url; } - public void setModule(String module) { + @Override + public String getMetadata(final String key) { + String value = super.getMetadata(key); + if ("model".equals(key) && "auto".equals(value)) { + String model = MODEL_CACHE.get(this.getHash()); + if (model != null) { + return model; + } + } + return value; + } + + public void setModel(String model) { if (this.metadata != null) { - this.metadata.put("module", module); + MODEL_CACHE.put(this.getHash(), model); + this.metadata.put("model", model); } } diff --git a/Common/src/main/java/customskinloader/fake/FakeSkinManager.java b/Common/src/main/java/customskinloader/fake/FakeSkinManager.java index c0fbe22d..3bd903d7 100644 --- a/Common/src/main/java/customskinloader/fake/FakeSkinManager.java +++ b/Common/src/main/java/customskinloader/fake/FakeSkinManager.java @@ -4,30 +4,30 @@ import java.io.File; import java.nio.file.Path; import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.SignatureState; import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTextures; import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.properties.Property; import customskinloader.CustomSkinLoader; +import customskinloader.fake.itf.IFakeSkinManagerCacheKey; +import customskinloader.loader.MojangAPILoader; +import customskinloader.profile.ModelManager0; +import customskinloader.profile.UserProfile; import customskinloader.utils.HttpTextureUtil; +import customskinloader.utils.TextureUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IImageBuffer; import net.minecraft.client.renderer.texture.NativeImage; import net.minecraft.client.resources.SkinManager; -import net.minecraft.util.ResourceLocation; public class FakeSkinManager { - private final static Map MODEL_CACHE = new ConcurrentHashMap<>(); - /** * Invoked from {@link SkinManager(net.minecraft.client.renderer.texture.TextureManager, File, MinecraftSessionService)} */ @@ -53,28 +53,8 @@ public static void setSkinCacheDir(Path skinCacheDirectory) { /** * Invoked from {@link SkinManager#getOrLoad(GameProfile)} */ - public static Object loadCache(LoadingCache loadingCache, Object cacheKey) throws Exception { - return cacheLoader.load(cacheKey); - } - - /** - * Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager.SkinAvailableCallback)} - */ - public static ResourceLocation setResourceLocation(ResourceLocation resourceLocation, MinecraftProfileTexture profileTexture) { - if (profileTexture instanceof FakeMinecraftProfileTexture) { - ((FakeMinecraftProfileTexture) profileTexture).setResourceLocation(resourceLocation); - } - return resourceLocation; - } - - /** - * Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager.SkinAvailableCallback)} - *

- * {@code skinAvailableCallback.skinAvailable(textureType, resourcelocation, profileTexture);} -> {@code skinAvailableCallback.skinAvailable(textureType, resourcelocation, this.fakeManager.getModelCache(profileTexture, resourcelocation));} - *

- */ - public static MinecraftProfileTexture getModelCache(MinecraftProfileTexture profileTexture, ResourceLocation location) { - return MODEL_CACHE.getOrDefault(location, profileTexture); + public static Object loadCache(LoadingCache loadingCache, Object cacheKey, GameProfile profile) throws Exception { + return cacheLoader.load(FakeCacheKey.wrapCacheKey(cacheKey, profile)); } /** @@ -84,14 +64,11 @@ public static Object[] createThreadDownloadImageData(ImmutableList list, Object[] params = list.toArray(); if (profileTexture instanceof FakeMinecraftProfileTexture && params.length > 1) { FakeMinecraftProfileTexture fakeProfileTexture = (FakeMinecraftProfileTexture) profileTexture; - ResourceLocation resourcelocation = fakeProfileTexture.getResourceLocation(); - if (fakeProfileTexture.getResourceLocation() != null) { - params[0] = fakeProfileTexture.getCacheFile(); - if (params[params.length - 2] instanceof Boolean) { - params[params.length - 2] = true; - } - params[params.length - 1] = new BaseBuffer((Runnable) params[params.length - 1], textureType, resourcelocation, fakeProfileTexture); + params[0] = fakeProfileTexture.getCacheFile(); + if (params[params.length - 2] instanceof Boolean) { + params[params.length - 2] = true; } + params[params.length - 1] = new BaseBuffer((Runnable) params[params.length - 1], textureType, fakeProfileTexture); } return params; } @@ -101,11 +78,9 @@ public static Object[] createThreadDownloadImageData(ImmutableList list, /** * Invoked from {@link SkinManager#loadProfileTextures(GameProfile, SkinManager.SkinAvailableCallback, boolean)} */ - @SuppressWarnings({ "rawtypes", "unchecked" }) public static void loadProfileTextures(Runnable runnable, GameProfile profile) { - CustomSkinLoader.loadProfileTextures(() -> CustomSkinLoader.loadProfileLazily(profile, m -> { - // This is a hack. - ((Multimap) profile.getProperties()).put(KEY, m); + CustomSkinLoader.loadProfileTextures(() -> CustomSkinLoader.loadProfileLazily(profile, p -> { + profile.getProperties().putAll(KEY, p.toProperties()); runnable.run(); return null; })); @@ -113,16 +88,16 @@ public static void loadProfileTextures(Runnable runnable, GameProfile profile) { /** * 23w31a+ - * Invoked from net.minecraft.client.resources.SkinManager$1#load(net.minecraft.client.resources.SkinManager$CacheKey, GameProfile) + * Invoked from net.minecraft.client.resources.SkinManager$1#load(net.minecraft.client.resources.SkinManager$CacheKey) */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public static Object[] loadProfileTextures(ImmutableList list, GameProfile profile) { + public static Object[] loadProfileTextures(ImmutableList list, Object cacheKey) { Object[] params = list.toArray(); + GameProfile profile = FakeCacheKey.unwrapCacheKey(cacheKey); if (!profile.getProperties().containsKey(SKULL_KEY)) { final Supplier supplier = (Supplier) params[0]; - params[0] = (Supplier) () -> CustomSkinLoader.loadProfileLazily(profile, m -> { - // This is a hack. - ((Multimap) profile.getProperties()).put(KEY, m); + params[0] = (Supplier) () -> CustomSkinLoader.loadProfileLazily(profile, p -> { + profile.getProperties().putAll(KEY, p.toProperties()); + FakeCacheKey.wrapCacheKey(cacheKey, profile); return supplier.get(); }); params[1] = CustomSkinLoader.THREAD_POOL; @@ -135,10 +110,8 @@ public static Object[] loadProfileTextures(ImmutableList list, GameProfi /** * Invoked from {@link SkinManager#lambda$loadProfileTextures$1(GameProfile, boolean, SkinAvailableCallback)} */ - @SuppressWarnings({ "rawtypes", "unchecked" }) public static Map getUserProfile(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) { - // This is a hack. - return (Map) ((Optional) profile.getProperties().removeAll(KEY).stream().findFirst()).orElse(Maps.newHashMap()); + return ModelManager0.fromUserProfile(UserProfile.fromProperties(profile.getProperties().values())); } /** @@ -163,8 +136,12 @@ public static void setSkullType(GameProfile profile) { profile.getProperties().put(SKULL_KEY, new Property(SKULL_KEY, "true")); } + public static Map loadSkinFromCache(GameProfile profile) { + return CustomSkinLoader.loadProfileFromCache(profile); + } + /** - * 23w31a+ + * 23w31a ~ 23w41a * Invoked from net.minecraft.client.resources.SkinManager$1#lambda$load$0(GameProfile) */ public static Map loadSkinFromCache(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) { @@ -176,8 +153,12 @@ public static Map loadSki } } - public static Map loadSkinFromCache(GameProfile profile) { - return CustomSkinLoader.loadProfileFromCache(profile); + /** + * 23w42a+ + * Invoked from net.minecraft.client.resources.SkinManager$1#lambda$load$0(SkinManager.CacheKey, MinecraftSessionService) + */ + public static Object loadSkinFromCache(MinecraftSessionService sessionService, Property property) { + return FakeCacheKey.createMinecraftProfileTextures(loadSkinFromCache(sessionService, FakeCacheKey.unwrapProperty(property), false)); } private static boolean shouldJudgeType(MinecraftProfileTexture texture) { @@ -188,18 +169,16 @@ private static class BaseBuffer implements IImageBuffer { private IImageBuffer buffer; private final Runnable callback; - private final ResourceLocation location; private final FakeMinecraftProfileTexture texture; - public BaseBuffer(Runnable callback, MinecraftProfileTexture.Type type, ResourceLocation location, FakeMinecraftProfileTexture texture) { + public BaseBuffer(Runnable callback, MinecraftProfileTexture.Type type, FakeMinecraftProfileTexture texture) { + this.callback = callback; + this.texture = texture; + switch (type) { case SKIN: this.buffer = new FakeSkinBuffer(); break; - case CAPE: this.buffer = new FakeCapeBuffer(location); break; + case CAPE: this.buffer = new FakeCapeBuffer(); break; } - - this.callback = callback; - this.location = location; - this.texture = texture; } @Override @@ -219,8 +198,7 @@ public void skinAvailable() { if (shouldJudgeType(texture) && buffer instanceof FakeSkinBuffer) { //Auto judge skin type String type = ((FakeSkinBuffer) buffer).judgeType(); - texture.setModule(type); - MODEL_CACHE.put(location, texture); + texture.setModel(type); } } @@ -229,4 +207,33 @@ public void skinAvailable() { } } } + + public static class FakeCacheKey { + public static Object wrapCacheKey(Object cacheKey, GameProfile profile) { + IFakeSkinManagerCacheKey fakeCacheKey = (IFakeSkinManagerCacheKey) cacheKey; + if (fakeCacheKey.profile() != null) { + return cacheKey; // 23w31a ~ 23w41a + } else { + TextureUtil.AuthlibField.PROPERTY_SIGNATURE.set(fakeCacheKey.packedTextures(), MojangAPILoader.GSON.toJson(profile, GameProfile.class)); + return fakeCacheKey; // 23w42a+ + } + } + + public static GameProfile unwrapCacheKey(Object cacheKey) { + IFakeSkinManagerCacheKey fakeCacheKey = (IFakeSkinManagerCacheKey) cacheKey; + if (fakeCacheKey.profile() != null) { + return fakeCacheKey.profile(); // 23w31a ~ 23w41a + } else { + return unwrapProperty(fakeCacheKey.packedTextures()); // 23w42a+ + } + } + + public static GameProfile unwrapProperty(Property property) { + return MojangAPILoader.GSON.fromJson((String) TextureUtil.AuthlibField.PROPERTY_SIGNATURE.get(property), GameProfile.class); // 23w42a+ + } + + public static Object createMinecraftProfileTextures(Map textures) { + return new MinecraftProfileTextures(textures.get(MinecraftProfileTexture.Type.SKIN), textures.get(MinecraftProfileTexture.Type.CAPE), textures.get(MinecraftProfileTexture.Type.ELYTRA), SignatureState.SIGNED); + } + } } diff --git a/Common/src/main/java/customskinloader/fake/itf/FakeInterfaceManager.java b/Common/src/main/java/customskinloader/fake/itf/FakeInterfaceManager.java index ca0fefb1..945c9a3a 100644 --- a/Common/src/main/java/customskinloader/fake/itf/FakeInterfaceManager.java +++ b/Common/src/main/java/customskinloader/fake/itf/FakeInterfaceManager.java @@ -5,7 +5,6 @@ import java.io.InputStream; import java.util.Optional; -import net.minecraft.client.Minecraft; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; import net.minecraft.util.ResourceLocation; @@ -19,11 +18,7 @@ public static Optional IResourceManager_getResource(Object resourceMa return ((IFakeIResourceManager) resourceManager).getResource(location); } - public static IResourceManager Minecraft_getResourceManager(Minecraft minecraft) { + public static IResourceManager Minecraft_getResourceManager(Object minecraft) { return (IResourceManager) ((IFakeMinecraft) minecraft).func_195551_G(); } - - public static void ThreadDownloadImageData_resetNewBufferedImage(Object threadDownloadImageData, BufferedImage image) { - ((IFakeThreadDownloadImageData) threadDownloadImageData).resetNewBufferedImage(image); - } } diff --git a/Common/src/main/java/customskinloader/fake/itf/IFakeSkinManagerCacheKey.java b/Common/src/main/java/customskinloader/fake/itf/IFakeSkinManagerCacheKey.java new file mode 100644 index 00000000..dbdcecc7 --- /dev/null +++ b/Common/src/main/java/customskinloader/fake/itf/IFakeSkinManagerCacheKey.java @@ -0,0 +1,12 @@ +package customskinloader.fake.itf; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; + +public interface IFakeSkinManagerCacheKey { + default GameProfile profile() { + return null; + } + + Property packedTextures(); +} diff --git a/Common/src/main/java/customskinloader/fake/itf/IFakeThreadDownloadImageData.java b/Common/src/main/java/customskinloader/fake/itf/IFakeThreadDownloadImageData.java deleted file mode 100644 index a5685e7e..00000000 --- a/Common/src/main/java/customskinloader/fake/itf/IFakeThreadDownloadImageData.java +++ /dev/null @@ -1,12 +0,0 @@ -package customskinloader.fake.itf; - -import java.awt.image.BufferedImage; - -// This interface is only available before 1.12.2 -public interface IFakeThreadDownloadImageData { - /** - * Reset {@link net.minecraft.client.renderer.ThreadDownloadImageData#bufferedImage} and - * {@link net.minecraft.client.renderer.ThreadDownloadImageData#textureUploaded} to false to refresh texture. - */ - void resetNewBufferedImage(BufferedImage image); -} diff --git a/Common/src/main/java/customskinloader/loader/MojangAPILoader.java b/Common/src/main/java/customskinloader/loader/MojangAPILoader.java index 97c6ae36..1a8d1144 100644 --- a/Common/src/main/java/customskinloader/loader/MojangAPILoader.java +++ b/Common/src/main/java/customskinloader/loader/MojangAPILoader.java @@ -109,6 +109,7 @@ public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) { 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) { @@ -118,14 +119,12 @@ public static GameProfile loadGameProfileCached(String apiRoot, String username) //Username -> UUID public static GameProfile loadGameProfile(String apiRoot, String username) { //Doc (https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs) - Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); - - 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(GSON.toJson(Collections.singletonList(username)))); if (StringUtils.isEmpty(responce.content)) { return null; } - GameProfile[] profiles = gson.fromJson(responce.content, GameProfile[].class); + GameProfile[] profiles = GSON.fromJson(responce.content, GameProfile[].class); if (profiles.length == 0) { return null; } @@ -161,8 +160,7 @@ public static GameProfile fillGameProfile(String sessionRoot, GameProfile profil return profile; } - Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); - MinecraftProfilePropertiesResponse propertiesResponce = gson.fromJson(responce.content, MinecraftProfilePropertiesResponse.class); + MinecraftProfilePropertiesResponse propertiesResponce = 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)); @@ -177,13 +175,12 @@ public static Map getText if (textureProperty == null) { return Maps.newHashMap(); } - String value = TextureUtil.AuthlibField.PROPERTY_VALUE_FIELD.get(textureProperty); + 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); - Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); - MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class); + MinecraftTexturesPayload result = GSON.fromJson(json, MinecraftTexturesPayload.class); if (result == null || TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result) == null) { return Maps.newHashMap(); diff --git a/Common/src/main/java/customskinloader/log/LogManager.java b/Common/src/main/java/customskinloader/log/LogManager.java index dbf373d0..ebf1943b 100644 --- a/Common/src/main/java/customskinloader/log/LogManager.java +++ b/Common/src/main/java/customskinloader/log/LogManager.java @@ -29,7 +29,7 @@ public static void setLogFile(Path logFile) { } //Set new writer Files.createDirectories(logFile.getParent()); - logWriter = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE); + logWriter = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); loggers.forEach((k, v) -> v.setWriter(logWriter)); } catch (Exception e) { e.printStackTrace(); diff --git a/Common/src/main/java/customskinloader/profile/DynamicSkullManager.java b/Common/src/main/java/customskinloader/profile/DynamicSkullManager.java index ae2e46e8..ce689fe7 100644 --- a/Common/src/main/java/customskinloader/profile/DynamicSkullManager.java +++ b/Common/src/main/java/customskinloader/profile/DynamicSkullManager.java @@ -49,7 +49,7 @@ private void parseGameProfile(GameProfile profile) { staticTextures.put(profile, Maps.newHashMap()); return; } - String value = TextureUtil.AuthlibField.PROPERTY_VALUE_FIELD.get(textureProperty); + String value = TextureUtil.AuthlibField.PROPERTY_VALUE.get(textureProperty); if (StringUtils.isBlank(value)) { staticTextures.put(profile, Maps.newHashMap()); return; diff --git a/Common/src/main/java/customskinloader/profile/ProfileCache.java b/Common/src/main/java/customskinloader/profile/ProfileCache.java index 5e45806e..88573a3e 100644 --- a/Common/src/main/java/customskinloader/profile/ProfileCache.java +++ b/Common/src/main/java/customskinloader/profile/ProfileCache.java @@ -17,7 +17,7 @@ public class ProfileCache { private Map cachedProfiles = new ConcurrentHashMap<>(); private Map localProfiles = new ConcurrentHashMap<>(); - private Map, ?>>> profileLoaders = new ConcurrentHashMap<>(); + private Map>> profileLoaders = new ConcurrentHashMap<>(); @SuppressWarnings("ResultOfMethodCallIgnored") public ProfileCache(){ @@ -52,8 +52,8 @@ public UserProfile getLocalProfile(String username){ return localProfiles.get(username.toLowerCase()); return loadLocalProfile(username); } - public Function, ?> getLastLoader(String username) { - Deque, ?>> deque = this.profileLoaders.get(username); + public Function getLastLoader(String username) { + Deque> deque = this.profileLoaders.get(username); if (deque != null) { return deque.pollLast(); } @@ -74,7 +74,7 @@ public void updateCache(String username,UserProfile profile,boolean saveLocalPro return; saveLocalProfile(username,profile); } - public void putLoader(String username, Function, ?> loader) { + public void putLoader(String username, Function loader) { this.profileLoaders.putIfAbsent(username, new ConcurrentLinkedDeque<>()); this.profileLoaders.get(username).offerLast(loader); } diff --git a/Common/src/main/java/customskinloader/profile/UserProfile.java b/Common/src/main/java/customskinloader/profile/UserProfile.java index 5ddbd789..831d9171 100644 --- a/Common/src/main/java/customskinloader/profile/UserProfile.java +++ b/Common/src/main/java/customskinloader/profile/UserProfile.java @@ -1,5 +1,11 @@ package customskinloader.profile; +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.Lists; +import com.mojang.authlib.properties.Property; +import customskinloader.utils.TextureUtil; import org.apache.commons.lang3.StringUtils; import customskinloader.profile.ModelManager0.Model; @@ -69,6 +75,34 @@ public String toString(long expiry){ (StringUtils.isBlank(elytraUrl)?" ":" , ElytraUrl: "+elytraUrl)+ (expiry==0?"":(" , Expiry: "+expiry))+")"; } + + public List toProperties() { + return Lists.newArrayList( + new Property("skinUrl" , nullToValue(this.skinUrl )), + new Property("model" , nullToValue(this.model )), + new Property("capeUrl" , nullToValue(this.capeUrl )), + new Property("elytraUrl", nullToValue(this.elytraUrl)) + ); + } + + public static UserProfile fromProperties(Collection properties) { + UserProfile profile = new UserProfile(); + if (properties != null) { + for (Property property : properties) { + switch ((String) TextureUtil.AuthlibField.PROPERTY_NAME.get(property)) { + case "skinUrl" : profile.skinUrl = nullToValue(TextureUtil.AuthlibField.PROPERTY_VALUE.get(property)); break; + case "model" : profile.model = nullToValue(TextureUtil.AuthlibField.PROPERTY_VALUE.get(property)); break; + case "capeUrl" : profile.capeUrl = nullToValue(TextureUtil.AuthlibField.PROPERTY_VALUE.get(property)); break; + case "elytraUrl": profile.elytraUrl = nullToValue(TextureUtil.AuthlibField.PROPERTY_VALUE.get(property)); break; + } + } + } + return profile; + } + + private static String nullToValue(String value) { + return value == null ? "null" : value.equals("null") ? null : value; + } /** * Check if the instance is empty. diff --git a/Common/src/main/java/customskinloader/utils/TextureUtil.java b/Common/src/main/java/customskinloader/utils/TextureUtil.java index 694bd286..80d83530 100644 --- a/Common/src/main/java/customskinloader/utils/TextureUtil.java +++ b/Common/src/main/java/customskinloader/utils/TextureUtil.java @@ -1,15 +1,21 @@ package customskinloader.utils; import java.io.File; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; +import java.util.Map; import java.util.UUID; +import java.util.function.Supplier; 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 customskinloader.CustomSkinLoader; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; +import sun.misc.Unsafe; public class TextureUtil { /** @@ -36,31 +42,53 @@ public static String parseBase64Texture(String base64) { } } + private final static MethodHandles.Lookup IMPL_LOOKUP = ((Supplier) () -> { + try { + Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafeField.setAccessible(true); + Unsafe theUnsafe = (Unsafe) theUnsafeField.get(null); + Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); + return (MethodHandles.Lookup) theUnsafe.getObject(theUnsafe.staticFieldBase(implLookupField), theUnsafe.staticFieldOffset(implLookupField)); + } catch (Throwable t) { + throw new RuntimeException(t); + } + }).get(); // Some of the classes in Authlib used after Minecraft 23w31a were changed to record classes, // resulting in changes to method names, so reflection is used here to be compatible with these changes. public enum AuthlibField { - PROPERTY_VALUE_FIELD(Property.class, "value"), - MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID(MinecraftProfilePropertiesResponse.class, "id"), - MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME(MinecraftProfilePropertiesResponse.class, "name"), - MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES(MinecraftProfilePropertiesResponse.class, "properties"), - MINECRAFT_TEXTURES_PAYLOAD_TEXTURES(MinecraftTexturesPayload.class, "textures"); + PROPERTY_NAME(Property.class, "name", String.class), + PROPERTY_VALUE(Property.class, "value", String.class), + PROPERTY_SIGNATURE(Property.class, "signature", String.class), + MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID(MinecraftProfilePropertiesResponse.class, "id", UUID.class), + MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME(MinecraftProfilePropertiesResponse.class, "name", String.class), + MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES(MinecraftProfilePropertiesResponse.class, "properties", PropertyMap.class), + MINECRAFT_TEXTURES_PAYLOAD_TEXTURES(MinecraftTexturesPayload.class, "textures", Map.class); - private final Field field; + private final MethodHandle getter; + private final MethodHandle setter; - AuthlibField(Class clazz, String name) { + AuthlibField(Class clazz, String name, Class returnType) { try { - this.field = clazz.getDeclaredField(name); - this.field.setAccessible(true); + this.getter = IMPL_LOOKUP.findGetter(clazz, name, returnType); + this.setter = IMPL_LOOKUP.findSetter(clazz, name, returnType); } catch (Throwable t) { throw new RuntimeException(t); } } @SuppressWarnings("unchecked") - public T get(Object o) { + public R get(Object o) { + try { + return (R) this.getter.invokeWithArguments(o); + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + + public void set(Object o, Object value) { try { - return (T) this.field.get(o); + this.setter.invokeWithArguments(o, value); } catch (Throwable t) { throw new RuntimeException(t); } diff --git a/Fabric/Fabric.tsrg b/Fabric/Fabric.tsrg index 210853ba..c7eed777 100644 --- a/Fabric/Fabric.tsrg +++ b/Fabric/Fabric.tsrg @@ -7,6 +7,9 @@ customskinloader/fake/itf/IFakeIResourceManager customskinloader/fake/itf/IFakeI getResource (Lnet/minecraft/util/ResourceLocation;)Ljava/util/Optional; method_14486 customskinloader/fake/itf/IFakeMinecraft customskinloader/fake/itf/IFakeMinecraft func_195551_G ()Lnet/minecraft/resources/IResourceManager; method_1478 +customskinloader/fake/itf/IFakeSkinManagerCacheKey customskinloader/fake/itf/IFakeSkinManagerCacheKey + profile ()Lcom/mojang/authlib/GameProfile; comp_1631 + packedTextures ()Lcom/mojang/authlib/properties/Property; comp_2011 net/minecraft/client/Minecraft net/minecraft/class_310 gameDir field_1697 getCurrentServerData ()Lnet/minecraft/client/multiplayer/ServerData; method_1558 @@ -51,7 +54,6 @@ net/minecraft/client/resources/SkinManager net/minecraft/class_1071 loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;)Lnet/minecraft/util/ResourceLocation; method_4656 net/minecraft/client/resources/SkinManager$1 net/minecraft/class_1071$1 net/minecraft/client/resources/SkinManager$CacheKey net/minecraft/class_1071$class_8686 - profile ()Lcom/mojang/authlib/GameProfile; comp_1631 net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072 skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V onSkinTextureAvailable net/minecraft/client/resources/SkinManager$TextureCache net/minecraft/class_1071$class_8687 diff --git a/Fabric/build.properties b/Fabric/build.properties index bedbd542..2da78ad1 100644 --- a/Fabric/build.properties +++ b/Fabric/build.properties @@ -1,5 +1,5 @@ minecraft_version=1.14 -minecraft_full_versions=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 +minecraft_full_versions=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 java_full_versions=8,9,10,11,12,13,14,15,16,17,18,19,20,21 #forge gradle needs forge version forge_mc_version=1.12.2 diff --git a/Fabric/mixin.tsrg b/Fabric/mixin.tsrg index bf14199a..aee3c90c 100644 --- a/Fabric/mixin.tsrg +++ b/Fabric/mixin.tsrg @@ -35,10 +35,10 @@ net/minecraft/client/resources/SkinManager net/minecraft/class_1071 loadSkinFromCache (Lcom/mojang/authlib/GameProfile;)Ljava/util/Map; method_4654 net/minecraft/client/resources/SkinManager$1 net/minecraft/class_1071$1 lambda$load$0 (Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/client/resources/SkinManager$TextureInfo; method_52867 + lambda$load$0 (Lnet/minecraft/client/resources/SkinManager$CacheKey;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)Lcom/mojang/authlib/minecraft/MinecraftProfileTextures; method_54647 load (Lnet/minecraft/client/resources/SkinManager$CacheKey;)Ljava/util/concurrent/CompletableFuture; method_52868 net/minecraft/client/resources/SkinManager$CacheKey net/minecraft/class_1071$class_8686 net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072 - skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V onSkinTextureAvailable net/minecraft/client/resources/SkinManager$TextureCache net/minecraft/class_1071$class_8687 type field_45641 registerTexture (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture; method_52873 diff --git a/Fabric/src/main/java/customskinloader/fabric/MixinConfigPlugin.java b/Fabric/src/main/java/customskinloader/fabric/MixinConfigPlugin.java index 997eabaa..d3e93e54 100644 --- a/Fabric/src/main/java/customskinloader/fabric/MixinConfigPlugin.java +++ b/Fabric/src/main/java/customskinloader/fabric/MixinConfigPlugin.java @@ -61,7 +61,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { result = this.world_version >= 2210 && this.protocol_version >= 558; // 19w41a+ } else if (mixinClassName.endsWith(".MixinSkinManager$V1")) { result = this.world_version <= 3465 && (this.protocol_version <= 763 || (this.protocol_version >= 801 && this.protocol_version <= 803) || (this.protocol_version >= 0x40000001 && this.protocol_version <= 0x4000008E)); // 18w43b ~ 1.20.1 - } else if (mixinClassName.endsWith(".MixinSkinManager$V2") || mixinClassName.endsWith(".MixinSkinManager$1") || mixinClassName.endsWith(".MixinSkinManager$TextureCache")) { + } else if (mixinClassName.endsWith(".MixinSkinManager$V2") || mixinClassName.endsWith(".MixinSkinManager$1") || mixinClassName.endsWith(".MixinSkinManager$CacheKey") || mixinClassName.endsWith(".MixinSkinManager$TextureCache")) { result = this.world_version >= 3567 && ((this.protocol_version > 763 && this.protocol_version < 801) || (this.protocol_version > 803 && this.protocol_version < 0x40000001) || this.protocol_version >= 0x40000090); // 23w31a+ } else if (mixinClassName.endsWith(".MixinThreadDownloadImageData$V1")) { result = (this.world_version >= 2205 && this.world_version <= 2722) && ((this.protocol_version >= 554 && this.protocol_version <= 754) || (this.protocol_version >= 801 && this.protocol_version <= 803) || (this.protocol_version >= 0x40000001 && this.protocol_version <= 0x40000022)); // 19w38a ~ 1.17-rc1 diff --git a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$1.java b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$1.java index 89964dae..5a9ac595 100644 --- a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$1.java +++ b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$1.java @@ -6,11 +6,14 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftSessionService; +import com.mojang.authlib.properties.Property; import customskinloader.fake.FakeSkinManager; import net.minecraft.client.resources.SkinManager; import net.minecraft.client.resources.SkinManager$1; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; +import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @@ -30,9 +33,15 @@ private void modifyArgs_load(Args args, SkinManager.CacheKey cacheKey) { for (int i = 0; i < argsArr.length; i++) { argsArr[i] = args.get(i); } - args.setAll(FakeSkinManager.loadProfileTextures(ImmutableList.copyOf(argsArr), cacheKey.profile())); + args.setAll(FakeSkinManager.loadProfileTextures(ImmutableList.copyOf(argsArr), cacheKey)); } + // 23w31a ~ 23w41a + @Group( + name = "lambda$load$0", + min = 1, + max = 1 + ) @Redirect( method = "Lnet/minecraft/client/resources/SkinManager$1;lambda$load$0(Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/client/resources/SkinManager$TextureInfo;", at = @At( @@ -44,4 +53,23 @@ private void modifyArgs_load(Args args, SkinManager.CacheKey cacheKey) { private static Map redirect_lambda$load$0(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) { return FakeSkinManager.loadSkinFromCache(sessionService, profile, requireSecure); } + + // 23w42a+ + @Coerce + @Group( + name = "lambda$load$0", + min = 1, + max = 1 + ) + @Redirect( + method = "Lnet/minecraft/client/resources/SkinManager$1;lambda$load$0(Lnet/minecraft/client/resources/SkinManager$CacheKey;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)Lcom/mojang/authlib/minecraft/MinecraftProfileTextures;", + at = @At( + value = "INVOKE", + target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;unpackTextures(Lcom/mojang/authlib/properties/Property;)Lcom/mojang/authlib/minecraft/MinecraftProfileTextures;", + remap = false + ) + ) + private static Object redirect_lambda$load$0(MinecraftSessionService sessionService, Property property) { + return FakeSkinManager.loadSkinFromCache(sessionService, property); + } } diff --git a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$CacheKey.java b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$CacheKey.java new file mode 100644 index 00000000..3fa7a39f --- /dev/null +++ b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$CacheKey.java @@ -0,0 +1,10 @@ +package customskinloader.mixin; + +import customskinloader.fake.itf.IFakeSkinManagerCacheKey; +import net.minecraft.client.resources.SkinManager; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(SkinManager.CacheKey.class) +public abstract class MixinSkinManager$CacheKey implements IFakeSkinManagerCacheKey { + +} diff --git a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$TextureCache.java b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$TextureCache.java index d935808d..4a9abdb6 100644 --- a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$TextureCache.java +++ b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager$TextureCache.java @@ -4,12 +4,10 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture; import customskinloader.fake.FakeSkinManager; import net.minecraft.client.resources.SkinManager; -import net.minecraft.util.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(SkinManager.TextureCache.class) @@ -17,18 +15,6 @@ public abstract class MixinSkinManager$TextureCache { @Shadow private MinecraftProfileTexture.Type type; - @ModifyVariable( - method = "Lnet/minecraft/client/resources/SkinManager$TextureCache;registerTexture(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture;", - at = @At( - value = "STORE", - ordinal = 0 - ), - ordinal = 0 - ) - private ResourceLocation modifyVariable_registerTexture(ResourceLocation resourceLocation, MinecraftProfileTexture profileTexture) { - return FakeSkinManager.setResourceLocation(resourceLocation, profileTexture); - } - @ModifyArgs( method = "Lnet/minecraft/client/resources/SkinManager$TextureCache;registerTexture(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture;", at = @At( diff --git a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager.java b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager.java index 4e6a21cc..cdcf91cd 100644 --- a/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager.java +++ b/Fabric/src/main/java/customskinloader/mixin/MixinSkinManager.java @@ -16,14 +16,12 @@ import customskinloader.fake.FakeSkinManager; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.SkinManager; -import net.minecraft.util.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -42,29 +40,6 @@ private void inject_init(TextureManager textureManagerInstance, File skinCacheDi FakeSkinManager.setSkinCacheDir(skinCacheDirectory); } - @ModifyVariable( - method = "Lnet/minecraft/client/resources/SkinManager;loadSkin(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", - at = @At( - value = "STORE", - ordinal = 0 - ), - ordinal = 0 - ) - private ResourceLocation modifyVariable_loadSkin(ResourceLocation resourceLocation, MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType, SkinManager.SkinAvailableCallback skinAvailableCallback) { - return FakeSkinManager.setResourceLocation(resourceLocation, profileTexture); - } - - @ModifyArg( - method = "Lnet/minecraft/client/resources/SkinManager;loadSkin(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;skinAvailable(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V" - ) - ) - private MinecraftProfileTexture modifyArg_loadSkin(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) { - return FakeSkinManager.getModelCache(profileTexture, location); - } - // 18w43b ~ 19w37a @Group( name = "modifyArgs_loadSkin", @@ -250,8 +225,8 @@ private void inject_getInsecureSkin(GameProfile profile, CallbackInfoReturnable< remap = false ) ) - private Object redirect_getOrLoad(LoadingCache loadingCache, Object cacheKey) throws Exception { - return FakeSkinManager.loadCache(loadingCache, cacheKey); + private Object redirect_getOrLoad(LoadingCache loadingCache, Object cacheKey, GameProfile profile) throws Exception { + return FakeSkinManager.loadCache(loadingCache, cacheKey, profile); } } } diff --git a/Fabric/src/main/resources/mixins.customskinloader.json b/Fabric/src/main/resources/mixins.customskinloader.json index 319aa0cf..ddd1c158 100644 --- a/Fabric/src/main/resources/mixins.customskinloader.json +++ b/Fabric/src/main/resources/mixins.customskinloader.json @@ -11,6 +11,7 @@ "MixinMinecraft", "MixinRenderPlayer", "MixinSkinManager$1", + "MixinSkinManager$CacheKey", "MixinSkinManager$TextureCache", "MixinSkinManager$V1", "MixinSkinManager$V2", diff --git a/Forge/Active/Forge.tsrg b/Forge/Active/Forge.tsrg index 0c67a859..07a77e44 100644 --- a/Forge/Active/Forge.tsrg +++ b/Forge/Active/Forge.tsrg @@ -7,6 +7,9 @@ customskinloader/fake/itf/IFakeIResourceManager customskinloader/fake/itf/IFakeI getResource (Lnet/minecraft/util/ResourceLocation;)Ljava/util/Optional; m_213713_ customskinloader/fake/itf/IFakeMinecraft customskinloader/fake/itf/IFakeMinecraft func_195551_G ()Lnet/minecraft/resources/IResourceManager; m_91098_ +customskinloader/fake/itf/IFakeSkinManagerCacheKey customskinloader/fake/itf/IFakeSkinManagerCacheKey + profile ()Lcom/mojang/authlib/GameProfile; f_290972_ + packedTextures ()Lcom/mojang/authlib/properties/Property; f_303729_ net/minecraft/client/Minecraft net/minecraft/client/Minecraft gameDir f_91069_ getCurrentServerData ()Lnet/minecraft/client/multiplayer/ServerData; m_91089_ @@ -51,7 +54,6 @@ net/minecraft/client/resources/SkinManager net/minecraft/client/resources/SkinMa loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;)Lnet/minecraft/util/ResourceLocation; m_118825_ net/minecraft/client/resources/SkinManager$1 net/minecraft/client/resources/SkinManager$1 net/minecraft/client/resources/SkinManager$CacheKey net/minecraft/client/resources/SkinManager$CacheKey - profile ()Lcom/mojang/authlib/GameProfile; f_290972_ net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/client/resources/SkinManager$SkinTextureCallback skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V m_118856_ net/minecraft/client/resources/SkinManager$TextureCache net/minecraft/client/resources/SkinManager$TextureCache diff --git a/Forge/Active/build.properties b/Forge/Active/build.properties index 83865134..68ff65f6 100644 --- a/Forge/Active/build.properties +++ b/Forge/Active/build.properties @@ -1,5 +1,5 @@ minecraft_version=1.17.1 -minecraft_full_versions=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 +minecraft_full_versions=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 java_full_versions=16,17,18,19,20,21 #forge gradle needs forge version forge_mc_version=1.12.2 diff --git a/Forge/Active/src/main/resources/transformers.js b/Forge/Active/src/main/resources/transformers.js index 2664f6e1..5ee5e40c 100644 --- a/Forge/Active/src/main/resources/transformers.js +++ b/Forge/Active/src/main/resources/transformers.js @@ -3,7 +3,6 @@ var Handle = getJavaType('org.objectweb.asm.Handle'); var Opcodes = getJavaType('org.objectweb.asm.Opcodes'); var Type = getJavaType('org.objectweb.asm.Type'); var FieldInsnNode = getJavaType('org.objectweb.asm.tree.FieldInsnNode'); -var FieldNode = getJavaType('org.objectweb.asm.tree.FieldNode'); var InsnNode = getJavaType('org.objectweb.asm.tree.InsnNode'); var IntInsnNode = getJavaType('org.objectweb.asm.tree.IntInsnNode'); var InvokeDynamicInsnNode = getJavaType('org.objectweb.asm.tree.InvokeDynamicInsnNode'); @@ -57,17 +56,6 @@ function initializeCoreMod() { } else if (checkName(mn.name, "m_118828_") && mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;)Lnet/minecraft/resources/ResourceLocation;")) { // 1.20.1- for (var iterator = mn.instructions.iterator(); iterator.hasNext();) { var node = iterator.next(); - if ((node.getOpcode() === Opcodes.INVOKESPECIAL && node.owner.equals("net/minecraft/resources/ResourceLocation") && checkName(node.name, "") && node.desc.equals("(Ljava/lang/String;)V")) // 1.19- - || (node.getOpcode() === Opcodes.INVOKESTATIC && node.owner.equals("net/minecraft/client/resources/SkinManager") && checkName(node.name, "m_242632_") && node.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;"))) { // 1.19.1+ - mn.instructions.insert(node, node = new VarInsnNode(Opcodes.ALOAD, 1)); - mn.instructions.insert(node, node = new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "setResourceLocation", "(Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Lnet/minecraft/resources/ResourceLocation;", false)); - } - - if (node.getOpcode() === Opcodes.INVOKEINTERFACE && node.owner.equals("net/minecraft/client/resources/SkinManager$SkinTextureCallback") && checkName(node.name, "onSkinTextureAvailable") && node.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V")) { - mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 5)); - mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "getModelCache", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lnet/minecraft/resources/ResourceLocation;)Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;", false)); - } - if (node.getOpcode() === Opcodes.INVOKESPECIAL && (node.owner.equals("net/minecraft/client/renderer/texture/HttpTexture") && checkName(node.name, "") && node.desc.equals("(Ljava/io/File;Ljava/lang/String;Lnet/minecraft/resources/ResourceLocation;ZLjava/lang/Runnable;)V"))) { var s = "("; var args = Type.getType(node.desc).getArgumentTypes(); @@ -138,7 +126,8 @@ function initializeCoreMod() { for (var iterator = mn.instructions.iterator(); iterator.hasNext();) { var node = iterator.next(); if (node.getOpcode() === Opcodes.INVOKEINTERFACE && node.owner.equals("com/google/common/cache/LoadingCache") && checkName(node.name, "getUnchecked") && node.desc.equals("(Ljava/lang/Object;)Ljava/lang/Object;")) { - mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadCache", "(Lcom/google/common/cache/LoadingCache;Ljava/lang/Object;)Ljava/lang/Object;", false)); + mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 1)); + mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadCache", "(Lcom/google/common/cache/LoadingCache;Ljava/lang/Object;Lcom/mojang/authlib/GameProfile;)Ljava/lang/Object;", false)); } } } @@ -164,8 +153,7 @@ function initializeCoreMod() { } mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/google/common/collect/ImmutableList", "of", s + ")Lcom/google/common/collect/ImmutableList;", false)); mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 1)); - mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/client/resources/SkinManager$CacheKey", mapName("f_290972_"), "()Lcom/mojang/authlib/GameProfile;", false)); - mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Lcom/google/common/collect/ImmutableList;Lcom/mojang/authlib/GameProfile;)[Ljava/lang/Object;", false)); + mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Lcom/google/common/collect/ImmutableList;Ljava/lang/Object;)[Ljava/lang/Object;", false)); for (var i = 0; i < args.length; i++) { mn.instructions.insertBefore(node, new InsnNode(Opcodes.DUP)); mn.instructions.insertBefore(node, new IntInsnNode(Opcodes.BIPUSH, i)); @@ -176,18 +164,36 @@ function initializeCoreMod() { mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP)); } } - } else if (checkName(mn.name, "m_293645_") && mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/client/resources/SkinManager$TextureInfo;")) { + } else if (checkName(mn.name, "m_293645_") && mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/client/resources/SkinManager$TextureInfo;")) { // 1.20.2 for (var iterator = mn.instructions.iterator(); iterator.hasNext();) { var node = iterator.next(); if (node.getOpcode() === Opcodes.INVOKEINTERFACE && node.owner.equals("com/mojang/authlib/minecraft/MinecraftSessionService") && checkName(node.name, "getTextures") && node.desc.equals("(Lcom/mojang/authlib/GameProfile;Z)Ljava/util/Map;")) { mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadSkinFromCache", "(Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/GameProfile;Z)Ljava/util/Map;", false)); } } + } else if (checkName(mn.name, "m_304063_") && mn.desc.equals("(Lnet/minecraft/client/resources/SkinManager$CacheKey;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)Lcom/mojang/authlib/minecraft/MinecraftProfileTextures;")) { // 1.20.3+ + for (var iterator = mn.instructions.iterator(); iterator.hasNext();) { + var node = iterator.next(); + if (node.getOpcode() === Opcodes.INVOKEINTERFACE && node.owner.equals("com/mojang/authlib/minecraft/MinecraftSessionService") && checkName(node.name, "unpackTextures") && node.desc.equals("(Lcom/mojang/authlib/properties/Property;)Lcom/mojang/authlib/minecraft/MinecraftProfileTextures;")) { + mn.instructions.insert(node, new TypeInsnNode(Opcodes.CHECKCAST, "com/mojang/authlib/minecraft/MinecraftProfileTextures")); + mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadSkinFromCache", "(Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/properties/Property;)Ljava/lang/Object;", false)); + } + } } }); return cn; } }, + 'SkinManager$CacheKeyTransformer': { // 1.20.2+ + 'target': { + 'type': 'CLASS', + 'name': 'net/minecraft/client/resources/SkinManager$CacheKey' + }, + 'transformer': function (cn) { + cn.interfaces.add("customskinloader/fake/itf/IFakeSkinManagerCacheKey"); + return cn; + } + }, 'IResourceTransformer': { 'target': { 'type': 'CLASS', @@ -252,10 +258,7 @@ function initializeCoreMod() { 'transformer': function (mn) { for (var iterator = mn.instructions.iterator(); iterator.hasNext();) { var node = iterator.next(); - if (node.getOpcode() === Opcodes.INVOKEVIRTUAL && node.owner.equals("net/minecraft/client/resources/SkinManager$TextureCache") && checkName(node.name, "m_293729_") && node.desc.equals("(Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;")) { - mn.instructions.insert(node, node = new VarInsnNode(Opcodes.ALOAD, 1)); - mn.instructions.insert(node, node = new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "setResourceLocation", "(Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Lnet/minecraft/resources/ResourceLocation;", false)); - } else if (node.getOpcode() === Opcodes.INVOKESPECIAL && (node.owner.equals("net/minecraft/client/renderer/texture/HttpTexture") && checkName(node.name, "") && node.desc.equals("(Ljava/io/File;Ljava/lang/String;Lnet/minecraft/resources/ResourceLocation;ZLjava/lang/Runnable;)V"))) { + if (node.getOpcode() === Opcodes.INVOKESPECIAL && (node.owner.equals("net/minecraft/client/renderer/texture/HttpTexture") && checkName(node.name, "") && node.desc.equals("(Ljava/io/File;Ljava/lang/String;Lnet/minecraft/resources/ResourceLocation;ZLjava/lang/Runnable;)V"))) { var s = "("; var args = Type.getType(node.desc).getArgumentTypes(); for (var i = 0; i < args.length; i++) { diff --git a/Forge/Legacy/src/main/java/customskinloader/forge/ForgeMod.java b/Forge/Legacy/src/main/java/customskinloader/forge/ForgeMod.java index 31fad8e4..68bbc5f9 100644 --- a/Forge/Legacy/src/main/java/customskinloader/forge/ForgeMod.java +++ b/Forge/Legacy/src/main/java/customskinloader/forge/ForgeMod.java @@ -1,11 +1,8 @@ package customskinloader.forge; -import customskinloader.CustomSkinLoader; -import net.minecraft.launchwrapper.Launch; import net.minecraftforge.fml.ExtensionPoint; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; import org.apache.commons.lang3.tuple.Pair; /** @@ -18,8 +15,7 @@ version = "@MOD_FULL_VERSION@", clientSideOnly = true, acceptedMinecraftVersions = "[1.8,1.13)", - acceptableRemoteVersions = "*", - certificateFingerprint = "52885f395e68f42e9b3b629ba56ecf606f7d4269" + acceptableRemoteVersions = "*" )//1.13- public class ForgeMod { public ForgeMod() { @@ -30,24 +26,6 @@ public ForgeMod() { } } - @Mod.EventHandler - public void fingerprintError(FMLFingerprintViolationEvent event) { - if ((boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment") || event.isDirectory()) return;//Development Environment - - CustomSkinLoader.logger.warning("!!!Fingerprint ERROR!!!"); - CustomSkinLoader.logger.warning("Failed to check fingerprint in file '" + event.getSource().getAbsolutePath() + "'."); - CustomSkinLoader.logger.warning("Excepted Fingerprint: " + event.getExpectedFingerprint()); - if (event.getFingerprints().isEmpty()) { - CustomSkinLoader.logger.warning("No Fingerprint Founded."); - } else { - CustomSkinLoader.logger.warning("Founded Fingerprint: "); - for (String s : event.getFingerprints()) - CustomSkinLoader.logger.warning(s); - } - - throw new RuntimeException("Fingerprint ERROR, please **DO NOT MODIFY** any mod."); - } - // Make sure the mod being absent on the other network side does not cause the client to display the server as incompatible after forge-1.13.2-25.0.107. private void setExtensionPoint() { ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> "customskinloader", (remote, isServer) -> isServer)); diff --git a/Forge/Legacy/src/main/java/customskinloader/forge/loader/LaunchWrapper.java b/Forge/Legacy/src/main/java/customskinloader/forge/loader/LaunchWrapper.java index 39c4187b..994d9854 100644 --- a/Forge/Legacy/src/main/java/customskinloader/forge/loader/LaunchWrapper.java +++ b/Forge/Legacy/src/main/java/customskinloader/forge/loader/LaunchWrapper.java @@ -19,7 +19,6 @@ public class LaunchWrapper implements IClassTransformer { private static final TransformerManager.IClassTransformer[] CLASS_TRANSFORMERS = { new FakeInterfacesTransformer.MinecraftTransformer(), new FakeInterfacesTransformer.IImageBufferTransformer(), - new FakeInterfacesTransformer.ThreadDownloadImageDataTransformer(), new FakeInterfacesTransformer.ClientIResourceTransformer(), new FakeInterfacesTransformer.ClientIResourceManagerTransformer(), new FakeInterfacesTransformer.IResourceTransformer(), diff --git a/Forge/Legacy/src/main/java/customskinloader/forge/transformer/FakeInterfacesTransformer.java b/Forge/Legacy/src/main/java/customskinloader/forge/transformer/FakeInterfacesTransformer.java index 801a03cd..092bf8ba 100644 --- a/Forge/Legacy/src/main/java/customskinloader/forge/transformer/FakeInterfacesTransformer.java +++ b/Forge/Legacy/src/main/java/customskinloader/forge/transformer/FakeInterfacesTransformer.java @@ -41,28 +41,6 @@ public ClassNode transform(ClassNode cn) { } } - @TransformerManager.TransformTarget( - className = "net.minecraft.client.renderer.ThreadDownloadImageData" - ) - public static class ThreadDownloadImageDataTransformer implements TransformerManager.IClassTransformer { - @Override - public ClassNode transform(ClassNode cn) { - cn.interfaces.add("customskinloader/fake/itf/IFakeThreadDownloadImageData"); - - MethodNode mn = new MethodNode(Opcodes.ACC_PUBLIC, "resetNewBufferedImage", "(Ljava/awt/image/BufferedImage;)V", null, null); - mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); - mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, cn.name, TransformerManager.mapFieldName(cn.name, "field_110559_g", "Z"), "Z")); - mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); - mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, cn.name, TransformerManager.mapFieldName(cn.name, "field_110560_d", "Ljava/awt/image/BufferedImage;"), "Ljava/awt/image/BufferedImage;")); - mn.instructions.add(new InsnNode(Opcodes.RETURN)); - cn.methods.add(mn); - - return cn; - } - } - @TransformerManager.TransformTarget( className = "net.minecraft.client.resources.IResource" ) diff --git a/Forge/Legacy/src/main/java/customskinloader/forge/transformer/SkinManagerTransformer.java b/Forge/Legacy/src/main/java/customskinloader/forge/transformer/SkinManagerTransformer.java index 1138e1f1..19e4a58f 100644 --- a/Forge/Legacy/src/main/java/customskinloader/forge/transformer/SkinManagerTransformer.java +++ b/Forge/Legacy/src/main/java/customskinloader/forge/transformer/SkinManagerTransformer.java @@ -47,26 +47,6 @@ public static class LoadSkinTransformer implements TransformerManager.IMethodTra @Override public MethodNode transform(ClassNode cn, MethodNode mn) { for (AbstractInsnNode ain : mn.instructions.toArray()) { - if (ain.getOpcode() == Opcodes.INVOKESPECIAL) { - MethodInsnNode min = (MethodInsnNode) ain; - if (TransformerManager.checkClassName(min.owner, "net/minecraft/util/ResourceLocation") && TransformerManager.checkMethodName(min.owner, min.name, min.desc, "") && TransformerManager.checkMethodDesc(min.desc, "(Ljava/lang/String;)V")) { - InsnList il = new InsnList(); - il.add(new VarInsnNode(Opcodes.ALOAD, 1)); - il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "setResourceLocation", "(Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Lnet/minecraft/util/ResourceLocation;", false)); - mn.instructions.insert(min, il); - } - } - - if (ain.getOpcode() == Opcodes.INVOKEINTERFACE) { - MethodInsnNode min = (MethodInsnNode) ain; - if (TransformerManager.checkClassName(min.owner, "net/minecraft/client/resources/SkinManager$SkinAvailableCallback") && TransformerManager.checkMethodName(min.owner, min.name, min.desc, "func_180521_a") && TransformerManager.checkMethodDesc(min.desc, "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V")) { - InsnList il = new InsnList(); - il.add(new VarInsnNode(Opcodes.ALOAD, 4)); - il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "getModelCache", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lnet/minecraft/util/ResourceLocation;)Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;", false)); - mn.instructions.insertBefore(min, il); - } - } - if (ain.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode min = (MethodInsnNode) ain; if (TransformerManager.checkClassName(min.owner, "net/minecraft/client/renderer/ThreadDownloadImageData") && TransformerManager.checkMethodName(min.owner, min.name, min.desc, "") && TransformerManager.checkMethodDesc(min.desc, "(Ljava/io/File;Ljava/lang/String;Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/IImageBuffer;)V")) { diff --git a/Forge/Legacy/src/main/resources/transformers.js b/Forge/Legacy/src/main/resources/transformers.js index ef8cbc4e..a2c1edce 100644 --- a/Forge/Legacy/src/main/resources/transformers.js +++ b/Forge/Legacy/src/main/resources/transformers.js @@ -57,19 +57,6 @@ function initializeCoreMod() { || mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$ISkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;"))) { // 1.14.2+ for (var iterator = mn.instructions.iterator(); iterator.hasNext();) { var node = iterator.next(); - if (node.getOpcode() === Opcodes.INVOKESPECIAL && node.owner.equals("net/minecraft/util/ResourceLocation") && checkName(node.name, "") && node.desc.equals("(Ljava/lang/String;)V")) { - mn.instructions.insert(node, node = new VarInsnNode(Opcodes.ALOAD, 1)); - mn.instructions.insert(node, node = new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "setResourceLocation", "(Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Lnet/minecraft/util/ResourceLocation;", false)); - } - - if (node.getOpcode() === Opcodes.INVOKEINTERFACE - && (node.owner.equals("net/minecraft/client/resources/SkinManager$SkinAvailableCallback") // 1.13.2- - || node.owner.equals("net/minecraft/client/resources/SkinManager$ISkinAvailableCallback")) // 1.14.2+ - && checkName(node.name, "onSkinTextureAvailable") && node.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V")) { - mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 5)); - mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "getModelCache", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lnet/minecraft/util/ResourceLocation;)Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;", false)); - } - if (node.getOpcode() === Opcodes.INVOKESPECIAL && (node.owner.equals("net/minecraft/client/renderer/texture/ThreadDownloadImageData") // 1.13.2- || node.owner.equals("net/minecraft/client/renderer/texture/DownloadingTexture")) // 1.14.2+ diff --git a/build.gradle b/build.gradle index 5c82ff2f..9c957040 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,7 @@ subprojects { ]) } + exclude "com/**" exclude "net/minecraft/client/renderer/RenderType.class" exclude "net/minecraft/client/renderer/texture/**" exclude "net/minecraft/resources/**"