Skip to content

Commit

Permalink
1.21.4 (#321)
Browse files Browse the repository at this point in the history
* 1.21.4

* Disable making the source jar.
  • Loading branch information
ZekerZhayard authored Dec 23, 2024
1 parent a9b2484 commit 1cb4cf4
Show file tree
Hide file tree
Showing 93 changed files with 762 additions and 181 deletions.
5 changes: 5 additions & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This subproject is only to provide dependency for other subprojects.

dependencies {
implementation project(':Dummy')
}
12 changes: 8 additions & 4 deletions Common/src/main/java/customskinloader/fake/FakeCapeBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

import customskinloader.CustomSkinLoader;
import customskinloader.fake.itf.FakeInterfaceManager;
import customskinloader.fake.texture.FakeImage;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;

public class FakeCapeBuffer extends FakeSkinBuffer {
private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("minecraft", "textures/entity/elytra.png");
private static final ResourceLocation TEXTURE_ELYTRA_V1 = new ResourceLocation("minecraft", "textures/entity/elytra.png");
private static final ResourceLocation TEXTURE_ELYTRA_V2 = new ResourceLocation("minecraft", "textures/entity/equipment/wings/elytra.png");
private static int loadedGlobal = 0;
private static FakeImage elytraImage;

private static FakeImage loadElytra(FakeImage originalImage) {
loadedGlobal++;
try {
InputStream is = FakeInterfaceManager.IResource_getInputStream(FakeInterfaceManager.IResourceManager_getResource(FakeInterfaceManager.Minecraft_getResourceManager(Minecraft.getMinecraft()), TEXTURE_ELYTRA).get());
Object resourceManager = FakeInterfaceManager.Minecraft_getResourceManager(Minecraft.getMinecraft());
InputStream is = FakeInterfaceManager.IResource_getInputStream(FakeInterfaceManager.IResourceManager_getResource(resourceManager, TEXTURE_ELYTRA_V1)
.orElseGet(() -> FakeInterfaceManager.IResourceManager_getResource(resourceManager, TEXTURE_ELYTRA_V2).orElse(null)));
if (is != null) {
FakeImage image = originalImage.createImage(is);
if (image.getWidth() % 64 != 0 || image.getHeight() % 32 != 0) { // wtf?
Expand All @@ -28,7 +31,8 @@ private static FakeImage loadElytra(FakeImage originalImage) {
image = resetImageFormat(image, 22, 0, 46, 22);
return image;
}
} catch (IOException | NoSuchElementException ignored) {
} catch (IOException e) {
CustomSkinLoader.logger.warning(e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;

import customskinloader.CustomSkinLoader;
import customskinloader.utils.MinecraftUtil;
import net.minecraft.client.renderer.ThreadDownloadImageData;
Expand All @@ -16,15 +15,15 @@
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
import net.minecraft.client.resources.SkinManager$SkinAvailableCallback;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;

public class FakeClientPlayer {
/**
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager.SkinAvailableCallback)}
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager$SkinAvailableCallback)}
*/
public static ThreadDownloadImageData putCache(ThreadDownloadImageData threaddownloadimagedata, SkinManager.SkinAvailableCallback skinAvailableCallback, ResourceLocation resourcelocation) {
public static ThreadDownloadImageData putCache(ThreadDownloadImageData threaddownloadimagedata, SkinManager$SkinAvailableCallback skinAvailableCallback, ResourceLocation resourcelocation) {
if (skinAvailableCallback instanceof FakeClientPlayer.LegacyBuffer) {//Cache for client player
textureCache.put(resourcelocation, threaddownloadimagedata);
}
Expand Down Expand Up @@ -69,7 +68,7 @@ public static UUID getOfflineUUID(String username) {

public static Map<ResourceLocation, ITextureObject> textureCache = Maps.newHashMap();

public static class LegacyBuffer implements SkinAvailableCallback {
public static class LegacyBuffer implements SkinManager$SkinAvailableCallback {
ResourceLocation resourceLocationIn;
boolean loaded = false;

Expand Down
17 changes: 15 additions & 2 deletions Common/src/main/java/customskinloader/fake/FakeSkinBuffer.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
package customskinloader.fake;

import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.function.Function;
import java.util.function.Predicate;

import customskinloader.CustomSkinLoader;
import customskinloader.fake.texture.FakeBufferedImage;
import customskinloader.fake.texture.FakeImage;
import customskinloader.fake.texture.FakeNativeImage;
import customskinloader.fake.texture.FakeThreadDownloadImageData;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.resources.IResourceManager;

public class FakeSkinBuffer implements IImageBuffer {
private int ratio = 1;
FakeImage image = null;

//parseUserSkin for 1.15+
/**
* 19w38a ~ 24w45a
* Invoked from {@link ThreadDownloadImageData#loadTexture(InputStream)}
*
* 24w46a+
* Invoked from {@link FakeThreadDownloadImageData#loadContents(IResourceManager)}
*/
public static NativeImage processLegacySkin(NativeImage image, Runnable processTask, Function<NativeImage, NativeImage> processLegacySkin) {
if (processTask instanceof IImageBuffer) {
return ((IImageBuffer) processTask).func_195786_a(image);
} else if (processLegacySkin != null) {
return processLegacySkin.apply(image);
} else {
return image;
}
return processLegacySkin.apply(image);
}

//parseUserSkin for 1.13+
Expand Down
75 changes: 59 additions & 16 deletions Common/src/main/java/customskinloader/fake/FakeSkinManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.File;
import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;

import com.google.common.cache.CacheLoader;
Expand All @@ -17,6 +19,7 @@
import com.mojang.authlib.properties.Property;
import customskinloader.CustomSkinLoader;
import customskinloader.fake.itf.FakeInterfaceManager;
import customskinloader.fake.texture.FakeThreadDownloadImageData;
import customskinloader.loader.MojangAPILoader;
import customskinloader.profile.ModelManager0;
import customskinloader.profile.UserProfile;
Expand All @@ -25,65 +28,91 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.PlayerSkin$Model;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.client.resources.SkinManager$1;
import net.minecraft.client.resources.SkinManager$CacheKey;
import net.minecraft.client.resources.SkinManager$SkinAvailableCallback;
import net.minecraft.client.resources.SkinManager$TextureCache;

public class FakeSkinManager {
/**
* Invoked from {@link SkinManager(net.minecraft.client.renderer.texture.TextureManager, File, MinecraftSessionService)}
* 1.20.1-
* Invoked from {@link SkinManager(TextureManager , File, MinecraftSessionService)}
*/
public static void setSkinCacheDir(File skinCacheDirectory) {
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
}

/**
* Invoked from {@link SkinManager(net.minecraft.client.renderer.texture.TextureManager, Path, MinecraftSessionService, java.util.concurrent.Executor)}
* 23w31a+
* Invoked from {@link SkinManager(TextureManager, Path, MinecraftSessionService, Executor)}
*/
public static void setSkinCacheDir(Path skinCacheDirectory) {
HttpTextureUtil.defaultCacheDir = skinCacheDirectory.toFile();
}

private static CacheLoader<Object, ?> cacheLoader;
/**
* Invoked from {@link SkinManager(net.minecraft.client.renderer.texture.TextureManager, Path, MinecraftSessionService, java.util.concurrent.Executor)}
* 23w31a+
* Invoked from {@link SkinManager(TextureManager, Path, MinecraftSessionService, Executor)}
*/
public static CacheLoader<Object, ?> setCacheLoader(CacheLoader<Object, ?> loader) {
return cacheLoader = loader;
}

/**
* 23w42a+
* 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));
}

/**
* 23w31a+
* Invoked from {@link SkinManager#getOrLoad(GameProfile)}
*/
public static Object loadCache(LoadingCache<?, ?> loadingCache, Object cacheKey, GameProfile profile) throws Exception {
return cacheLoader.load(FakeCacheKey.wrapCacheKey(cacheKey, profile));
}

/**
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager.SkinAvailableCallback)}
* 1.20.1-
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager$SkinAvailableCallback)}
*
* 23w31a+
* Invoked from {@link SkinManager$TextureCache#registerTexture(MinecraftProfileTexture)}
*/
public static Object[] createThreadDownloadImageData(ImmutableList<Object> list, MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType) {
Object[] params = list.toArray();
if (profileTexture instanceof FakeMinecraftProfileTexture && params.length > 1) {
if (profileTexture instanceof FakeMinecraftProfileTexture) {
FakeMinecraftProfileTexture fakeProfileTexture = (FakeMinecraftProfileTexture) profileTexture;
params[0] = fakeProfileTexture.getCacheFile();
if (params[params.length - 2] instanceof Boolean) {
params[params.length - 2] = true;
File cacheFile = fakeProfileTexture.getCacheFile();
if (params.length == 4) {
if (params[3] instanceof Boolean) { // 24w46a+
FakeInterfaceManager.ResourceLocation_setTexture(params[0], FakeThreadDownloadImageData.createTexture(params[0], cacheFile.toPath(), params[2], false, new BaseBuffer(null, textureType, fakeProfileTexture)));
params[1] = cacheFile.toPath();
params[3] = false;
} else { // 19w37a-
params[0] = cacheFile;
params[3] = new BaseBuffer((Runnable) params[3], textureType, fakeProfileTexture);
}
} else if (params.length == 5) { // 19w38a ~ 24w45a
params[0] = cacheFile;
params[3] = true;
params[4] = new BaseBuffer((Runnable) params[4], textureType, fakeProfileTexture);
}
params[params.length - 1] = new BaseBuffer((Runnable) params[params.length - 1], textureType, fakeProfileTexture);
}
return params;
}


private final static String KEY = "CustomSkinLoaderInfo";
/**
* Invoked from {@link SkinManager#loadProfileTextures(GameProfile, SkinManager.SkinAvailableCallback, boolean)}
* 1.20.1-
* Invoked from {@link SkinManager#loadProfileTextures(GameProfile, SkinManager$SkinAvailableCallback, boolean)}
*/
public static void loadProfileTextures(Runnable runnable, GameProfile profile) {
CustomSkinLoader.loadProfileTextures(() -> CustomSkinLoader.loadProfileLazily(profile, p -> {
Expand All @@ -95,7 +124,7 @@ public static void loadProfileTextures(Runnable runnable, GameProfile profile) {

/**
* 23w31a+
* Invoked from net.minecraft.client.resources.SkinManager$1#load(net.minecraft.client.resources.SkinManager$CacheKey)
* Invoked from {@link SkinManager$1#load(SkinManager$CacheKey)}
*/
public static Object[] loadProfileTextures(ImmutableList<Object> list, Object cacheKey) {
Object[] params = list.toArray();
Expand All @@ -115,16 +144,18 @@ public static Object[] loadProfileTextures(ImmutableList<Object> list, Object ca
}

/**
* Invoked from {@link SkinManager#lambda$loadProfileTextures$1(GameProfile, boolean, SkinAvailableCallback)}
* 1.20.1-
* Invoked from {@link SkinManager#func_210275_a(GameProfile, boolean, SkinManager$SkinAvailableCallback)}
*/
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getUserProfile(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) {
return ModelManager0.fromUserProfile(UserProfile.fromProperties(profile.getProperties().values()));
}

/**
* Invoked from {@link SkinManager#lambda$null$0(Map, SkinAvailableCallback)}
* 1.20.1-
* Invoked from {@link SkinManager#func_210276_a(Map, SkinManager$SkinAvailableCallback)}
*/
public static void loadElytraTexture(SkinManager skinManager, Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map, SkinManager.SkinAvailableCallback skinAvailableCallback) {
public static void loadElytraTexture(SkinManager skinManager, Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map, SkinManager$SkinAvailableCallback skinAvailableCallback) {
for (int i = 2; i < MinecraftProfileTexture.Type.values().length; i++) {
MinecraftProfileTexture.Type type = MinecraftProfileTexture.Type.values()[i];
if (map.containsKey(type)) {
Expand All @@ -133,6 +164,18 @@ public static void loadElytraTexture(SkinManager skinManager, Map<MinecraftProfi
}
}

/**
* 24w46a+
* Invoked from {@link SkinManager#lambda$registerTextures$1(CompletableFuture, String, CompletableFuture, CompletableFuture, PlayerSkin$Model, MinecraftProfileTextures, Void)}
*/
public static PlayerSkin$Model loadSkinModel(PlayerSkin$Model model, MinecraftProfileTextures textures) {
MinecraftProfileTexture texture = textures.skin();
if (texture != null) {
model = PlayerSkin$Model.byName(texture.getMetadata("model"));
}
return model;
}

private final static String SKULL_KEY = "CSL$IsSkull";
/**
* 23w31a+
Expand All @@ -149,7 +192,7 @@ public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSki

/**
* 23w31a ~ 23w41a
* Invoked from net.minecraft.client.resources.SkinManager$1#lambda$load$0(GameProfile)
* Invoked from {@link SkinManager$1#lambda$load$0(MinecraftSessionService, GameProfile)}
*/
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSkinFromCache(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) {
if (profile.getProperties().containsKey(SKULL_KEY)) {
Expand All @@ -162,7 +205,7 @@ public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSki

/**
* 23w42a+
* Invoked from net.minecraft.client.resources.SkinManager$1#lambda$load$0(SkinManager.CacheKey, MinecraftSessionService)
* Invoked from {@link 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static InputStream IResource_getInputStream(Object resource) {
return ((IFakeIResource.V2) resource).open();
}

public static Optional<IResource> IResourceManager_getResource(Object resourceManager, ResourceLocation location) throws IOException {
public static Optional<IResource> IResourceManager_getResource(Object resourceManager, ResourceLocation location) {
return ((IFakeIResourceManager) resourceManager).getResource(location);
}

Expand All @@ -31,6 +31,14 @@ public static void NativeImage_setPixel(Object nativeImage, int x, int y, int co
((IFakeNativeImage) nativeImage).setPixel(x, y, color);
}

public static Object ResourceLocation_getTexture(Object location) {
return ((IFakeResourceLocation) location).customskinloader$getTexture();
}

public static void ResourceLocation_setTexture(Object location, Object texture) {
((IFakeResourceLocation) location).customskinloader$setTexture(texture);
}

public static GameProfile SkinManagerCacheKey_profile(Object skinManagerCacheKey) {
return ((IFakeSkinManagerCacheKey) skinManagerCacheKey).profile();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package customskinloader.fake.itf;

import java.io.IOException;
import java.util.Optional;

import net.minecraft.client.resources.IResourceManager;
Expand All @@ -9,12 +8,12 @@

public interface IFakeIResourceManager {
// 1.13.2 ~ 22w13a
default IResource func_199002_a(ResourceLocation location) throws IOException {
default IResource func_199002_a(ResourceLocation location) {
return (IResource) ((IResourceManager) this).getResource(location);
}

// 22w14a+
default Optional getResource(ResourceLocation location) throws IOException {
default Optional getResource(ResourceLocation location) {
return Optional.ofNullable(this.func_199002_a(location));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package customskinloader.fake.itf;

public interface IFakeResourceLocation {
Object customskinloader$getTexture();
void customskinloader$setTexture(Object texture);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.mojang.authlib.properties.Property;

public interface IFakeSkinManagerCacheKey {
default GameProfile profile() {
return null;
}

default GameProfile profile() { return null; }
Property packedTextures();
}
Loading

0 comments on commit 1cb4cf4

Please sign in to comment.