Skip to content

Commit

Permalink
Fix window icon display
Browse files Browse the repository at this point in the history
  • Loading branch information
TangyKiwi committed Feb 29, 2024
1 parent c8f0a10 commit 2a3e5ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
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;
import com.tangykiwi.kiwiclient.modules.other.NoIP;
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;
import org.spongepowered.asm.mixin.injection.Redirect;
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;

Expand Down Expand Up @@ -99,4 +113,41 @@ public void shutdown(CallbackInfo info) {
ConfigManager.saveModules("default");
ConfigManager.saveClickGui("default");
}

@Redirect(method = "<init>", 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<InputStream> imgList = List.of(img16x16, img32x32);
List<ByteBuffer> 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) {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 2a3e5ec

Please sign in to comment.