Skip to content

Commit

Permalink
Fix #284 (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZekerZhayard authored Dec 18, 2023
1 parent d277269 commit 7fd5ff8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Common/src/main/java/customskinloader/CustomSkinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public static Object loadProfileLazily(GameProfile gameProfile, Function<UserPro
// Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
if (username == null) {
logger.warning("Could not load profile: username is null.");
return function.apply(null);
return function.apply(new UserProfile());
}
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(null);
return function.apply(new UserProfile());
}
Object result = function.apply(loadProfile(gameProfile));
Thread.currentThread().setName(tempName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public static void setSkinCacheDir(Path skinCacheDirectory) {
return cacheLoader = loader;
}

/**
* Invoked from {@link SkinManager#getOrLoad(GameProfile)}
*/
public static Property createProperty(Property property) {
return property == null ? new Property(null, null) : new Property(TextureUtil.AuthlibField.PROPERTY_NAME.get(property), TextureUtil.AuthlibField.PROPERTY_VALUE.get(property), TextureUtil.AuthlibField.PROPERTY_SIGNATURE.get(property));
}

/**
* Invoked from {@link SkinManager#getOrLoad(GameProfile)}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
} 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$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+
result = this.world_version >= 3567 && ((this.protocol_version >= 764 && this.protocol_version < 801) || (this.protocol_version > 803 && this.protocol_version < 0x40000001) || this.protocol_version >= 0x40000090); // 23w31a+
} else if (mixinClassName.endsWith(".MixinSkinManager$V3")) {
result = this.world_version >= 3684 && ((this.protocol_version >= 765 && this.protocol_version < 801) || (this.protocol_version > 803 && this.protocol_version < 0x40000001) || this.protocol_version >= 0x4000009D); // 23w42a+
} 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
} else if (mixinClassName.endsWith(".MixinThreadDownloadImageData$V2")) {
Expand Down
16 changes: 16 additions & 0 deletions Fabric/src/main/java/customskinloader/mixin/MixinSkinManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.renderer.texture.TextureManager;
import net.minecraft.client.resources.SkinManager;
Expand Down Expand Up @@ -229,4 +230,19 @@ private Object redirect_getOrLoad(LoadingCache<?, ?> loadingCache, Object cacheK
return FakeSkinManager.loadCache(loadingCache, cacheKey, profile);
}
}

// 23w42a+
@Mixin(SkinManager.class)
public abstract static class V3 {
@ModifyArg(
method = "Lnet/minecraft/client/resources/SkinManager;getOrLoad(Lcom/mojang/authlib/GameProfile;)Ljava/util/concurrent/CompletableFuture;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/resources/SkinManager$CacheKey;<init>(Ljava/util/UUID;Lcom/mojang/authlib/properties/Property;)V"
)
)
private Property modifyArg_getOrLoad(Property property) {
return FakeSkinManager.createProperty(property);
}
}
}
1 change: 1 addition & 0 deletions Fabric/src/main/resources/mixins.customskinloader.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"MixinSkinManager$TextureCache",
"MixinSkinManager$V1",
"MixinSkinManager$V2",
"MixinSkinManager$V3",
"MixinThreadDownloadImageData$V1",
"MixinThreadDownloadImageData$V2"
],
Expand Down
4 changes: 3 additions & 1 deletion Forge/Active/src/main/resources/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ function initializeCoreMod() {
} else if (checkName(mn.name, "m_293351_") && mn.desc.equals("(Lcom/mojang/authlib/GameProfile;)Ljava/util/concurrent/CompletableFuture;")) { // 1.20.2+
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;")) {
if (node.getOpcode() === Opcodes.INVOKESPECIAL && node.owner.equals("net/minecraft/client/resources/SkinManager$CacheKey") && checkName(node.name, "<init>") && node.desc.equals("(Ljava/util/UUID;Lcom/mojang/authlib/properties/Property;)V")) {
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "createProperty", "(Lcom/mojang/authlib/properties/Property;)Lcom/mojang/authlib/properties/Property;", false))
} else 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.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));
}
Expand Down

0 comments on commit 7fd5ff8

Please sign in to comment.