diff --git a/src/main/java/com/tangykiwi/kiwiclient/mixin/MinecraftClientMixin.java b/src/main/java/com/tangykiwi/kiwiclient/mixin/MinecraftClientMixin.java index c97c7d0..67b0593 100644 --- a/src/main/java/com/tangykiwi/kiwiclient/mixin/MinecraftClientMixin.java +++ b/src/main/java/com/tangykiwi/kiwiclient/mixin/MinecraftClientMixin.java @@ -1,5 +1,6 @@ package com.tangykiwi.kiwiclient.mixin; +import com.mojang.blaze3d.systems.RenderSystem; import com.tangykiwi.kiwiclient.KiwiClient; import com.tangykiwi.kiwiclient.event.OpenScreenEvent; import com.tangykiwi.kiwiclient.event.TickEvent; @@ -7,14 +8,23 @@ import com.tangykiwi.kiwiclient.modules.render.ESP; import com.tangykiwi.kiwiclient.modules.render.Freecam; import com.tangykiwi.kiwiclient.util.ConfigManager; +import com.tangykiwi.kiwiclient.util.Utils; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.texture.NativeImage; +import net.minecraft.client.util.Icons; +import net.minecraft.client.util.MacWindowUtil; import net.minecraft.client.util.Window; import net.minecraft.entity.Entity; import net.minecraft.resource.InputSupplier; +import net.minecraft.resource.ResourcePack; +import org.lwjgl.glfw.GLFW; +import org.lwjgl.glfw.GLFWImage; +import org.lwjgl.system.MemoryStack; +import org.lwjgl.system.MemoryUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -22,8 +32,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.io.IOException; import java.io.InputStream; +import java.nio.ByteBuffer; import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; import static com.tangykiwi.kiwiclient.KiwiClient.discordRPC; @@ -99,4 +113,41 @@ public void shutdown(CallbackInfo info) { ConfigManager.saveModules("default"); ConfigManager.saveClickGui("default"); } + + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;setIcon(Lnet/minecraft/resource/ResourcePack;Lnet/minecraft/client/util/Icons;)V")) + private void onChangeIcon(Window instance, ResourcePack resourcePack, Icons icons) throws IOException { + RenderSystem.assertInInitPhase(); + + if (GLFW.glfwGetPlatform() == 393218) { + MacWindowUtil.setApplicationIconImage(icons.getMacIcon(resourcePack)); + return; + } + setWindowIcon(KiwiClient.class.getResourceAsStream("/assets/kiwiclient/icon64.png"), KiwiClient.class.getResourceAsStream("/assets/kiwiclient/icon128.png")); + } + + public void setWindowIcon(InputStream img16x16, InputStream img32x32) { + try (MemoryStack memorystack = MemoryStack.stackPush()) { + GLFWImage.Buffer buffer = GLFWImage.malloc(2, memorystack); + List imgList = List.of(img16x16, img32x32); + List buffers = new ArrayList<>(); + + for (int i = 0; i < imgList.size(); i++) { + NativeImage nativeImage = NativeImage.read(imgList.get(i)); + ByteBuffer bytebuffer = MemoryUtil.memAlloc(nativeImage.getWidth() * nativeImage.getHeight() * 4); + + bytebuffer.asIntBuffer().put(nativeImage.copyPixelsRgba()); + buffer.position(i); + buffer.width(nativeImage.getWidth()); + buffer.height(nativeImage.getHeight()); + buffer.pixels(bytebuffer); + + buffers.add(bytebuffer); + } + + GLFW.glfwSetWindowIcon(Utils.mc.getWindow().getHandle(), buffer); + buffers.forEach(MemoryUtil::memFree); + } catch (IOException ignored) { + } + } + } diff --git a/src/main/java/com/tangykiwi/kiwiclient/mixin/SplashOverlayMixin.java b/src/main/java/com/tangykiwi/kiwiclient/mixin/SplashOverlayMixin.java index 783e9d8..ddcd826 100644 --- a/src/main/java/com/tangykiwi/kiwiclient/mixin/SplashOverlayMixin.java +++ b/src/main/java/com/tangykiwi/kiwiclient/mixin/SplashOverlayMixin.java @@ -26,7 +26,6 @@ public class SplashOverlayMixin { @Inject(method = "init(Lnet/minecraft/client/MinecraftClient;)V", at = @At("TAIL"), cancellable=true) private static void init(MinecraftClient client, CallbackInfo ci) { -// Utils.mc.getWindow().setIcon(InputSupplier.create(Paths.get(new File(SplashOverlayMixin.class.getResource("/assets/kiwiclient/icon64.png").getFile()).getPath())), InputSupplier.create(Paths.get(new File(SplashOverlayMixin.class.getResource("/assets/kiwiclient/icon128.png").getFile()).getPath()))); if(KiwiClient.moduleManager.getModule(com.tangykiwi.kiwiclient.modules.other.LoadingScreen.class).isEnabled()) { client.getTextureManager().registerTexture(LOGO, new LoadingScreen(LOGO)); }