mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-21 05:42:20 +00:00
23w42a (#281)
This commit is contained in:
1 parent
f4b5954dad
commit
0ffa9ef137
33 files changed
+283
-290
No files matched your search
@@ -0,0 +1,7 @@
|
||||
package com.mojang.authlib;
|
||||
|
||||
public enum SignatureState {
|
||||
UNSIGNED,
|
||||
INVALID,
|
||||
SIGNED
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -70,24 +70,24 @@ public class CustomSkinLoader {
|
||||
THREAD_POOL.execute(runnable);
|
||||
}
|
||||
|
||||
public static Object loadProfileLazily(GameProfile gameProfile, Function<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>, ?> function) {
|
||||
public static Object loadProfileLazily(GameProfile gameProfile, Function<UserProfile, ?> 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<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>, ?> func = profileCache.getLastLoader(credential);
|
||||
Function<UserProfile, ?> func = profileCache.getLastLoader(credential);
|
||||
if (func != null) {
|
||||
result = loadProfileLazily(gameProfile, func);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public class CustomSkinLoader {
|
||||
}
|
||||
|
||||
//For User Skin
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> 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 class CustomSkinLoader {
|
||||
profileCache.setLoading(credential, true);
|
||||
profile = loadProfile0(gameProfile, false);
|
||||
}
|
||||
return ModelManager0.fromUserProfile(profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
//Core
|
||||
|
||||
@@ -7,9 +7,7 @@ import java.util.function.BiPredicate;
|
||||
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 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
|
||||
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 class FakeCapeBuffer extends FakeSkinBuffer {
|
||||
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 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
|
||||
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) {
|
||||
|
||||
@@ -2,15 +2,16 @@ package customskinloader.fake;
|
||||
|
||||
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<String, String> MODEL_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private final HttpTextureUtil.HttpTextureInfo info;
|
||||
private final Map<String, String> metadata;
|
||||
private ResourceLocation resourceLocation;
|
||||
|
||||
public FakeMinecraftProfileTexture(String url, Map<String, String> metadata) {
|
||||
super(url, metadata);
|
||||
@@ -18,22 +19,27 @@ public class FakeMinecraftProfileTexture extends MinecraftProfileTexture {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,30 +4,30 @@ import java.awt.image.BufferedImage;
|
||||
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<ResourceLocation, MinecraftProfileTexture> MODEL_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Invoked from {@link SkinManager(net.minecraft.client.renderer.texture.TextureManager, File, MinecraftSessionService)}
|
||||
*/
|
||||
@@ -53,28 +53,8 @@ public class FakeSkinManager {
|
||||
/**
|
||||
* 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)}
|
||||
* <p>
|
||||
* {@code skinAvailableCallback.skinAvailable(textureType, resourcelocation, profileTexture);} -> {@code skinAvailableCallback.skinAvailable(textureType, resourcelocation, this.fakeManager.getModelCache(profileTexture, resourcelocation));}
|
||||
* <p>
|
||||
*/
|
||||
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 class FakeSkinManager {
|
||||
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 class FakeSkinManager {
|
||||
/**
|
||||
* 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 class FakeSkinManager {
|
||||
|
||||
/**
|
||||
* 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<Object> list, GameProfile profile) {
|
||||
public static Object[] loadProfileTextures(ImmutableList<Object> 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 class FakeSkinManager {
|
||||
/**
|
||||
* Invoked from {@link SkinManager#lambda$loadProfileTextures$1(GameProfile, boolean, SkinAvailableCallback)}
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getUserProfile(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) {
|
||||
// This is a hack.
|
||||
return (Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>) ((Optional) profile.getProperties().removeAll(KEY).stream().findFirst()).orElse(Maps.newHashMap());
|
||||
return ModelManager0.fromUserProfile(UserProfile.fromProperties(profile.getProperties().values()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,8 +136,12 @@ public class FakeSkinManager {
|
||||
profile.getProperties().put(SKULL_KEY, new Property(SKULL_KEY, "true"));
|
||||
}
|
||||
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> 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<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSkinFromCache(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) {
|
||||
@@ -176,8 +153,12 @@ public class FakeSkinManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> 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 @@ public class FakeSkinManager {
|
||||
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 class FakeSkinManager {
|
||||
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 class FakeSkinManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures) {
|
||||
return new MinecraftProfileTextures(textures.get(MinecraftProfileTexture.Type.SKIN), textures.get(MinecraftProfileTexture.Type.CAPE), textures.get(MinecraftProfileTexture.Type.ELYTRA), SignatureState.SIGNED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import java.io.IOException;
|
||||
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 class FakeInterfaceManager {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -109,6 +109,7 @@ 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<String, GameProfile> gameProfileCache = new ConcurrentHashMap<>();
|
||||
|
||||
public static GameProfile loadGameProfileCached(String apiRoot, String username) {
|
||||
@@ -118,14 +119,12 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
//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 class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
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 class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
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();
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LogManager {
|
||||
}
|
||||
//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();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DynamicSkullManager {
|
||||
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;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ProfileCache {
|
||||
|
||||
private Map<String, CachedProfile> cachedProfiles = new ConcurrentHashMap<>();
|
||||
private Map<String, UserProfile> localProfiles = new ConcurrentHashMap<>();
|
||||
private Map<String, Deque<Function<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>, ?>>> profileLoaders = new ConcurrentHashMap<>();
|
||||
private Map<String, Deque<Function<UserProfile, ?>>> profileLoaders = new ConcurrentHashMap<>();
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public ProfileCache(){
|
||||
@@ -52,8 +52,8 @@ public class ProfileCache {
|
||||
return localProfiles.get(username.toLowerCase());
|
||||
return loadLocalProfile(username);
|
||||
}
|
||||
public Function<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>, ?> getLastLoader(String username) {
|
||||
Deque<Function<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>, ?>> deque = this.profileLoaders.get(username);
|
||||
public Function<UserProfile, ?> getLastLoader(String username) {
|
||||
Deque<Function<UserProfile, ?>> deque = this.profileLoaders.get(username);
|
||||
if (deque != null) {
|
||||
return deque.pollLast();
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class ProfileCache {
|
||||
return;
|
||||
saveLocalProfile(username,profile);
|
||||
}
|
||||
public void putLoader(String username, Function<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>, ?> loader) {
|
||||
public void putLoader(String username, Function<UserProfile, ?> loader) {
|
||||
this.profileLoaders.putIfAbsent(username, new ConcurrentLinkedDeque<>());
|
||||
this.profileLoaders.get(username).offerLast(loader);
|
||||
}
|
||||
|
||||
@@ -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 class UserProfile {
|
||||
(StringUtils.isBlank(elytraUrl)?" ":" , ElytraUrl: "+elytraUrl)+
|
||||
(expiry==0?"":(" , Expiry: "+expiry))+")";
|
||||
}
|
||||
|
||||
public List<Property> 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<Property> 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.
|
||||
|
||||
@@ -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 class TextureUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private final static MethodHandles.Lookup IMPL_LOOKUP = ((Supplier<MethodHandles.Lookup>) () -> {
|
||||
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> T get(Object o) {
|
||||
public <R> R get(Object o) {
|
||||
try {
|
||||
return (T) this.field.get(o);
|
||||
return (R) this.getter.invokeWithArguments(o);
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(Object o, Object value) {
|
||||
try {
|
||||
this.setter.invokeWithArguments(o, value);
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user