From 2cdedc4e5db57564d05c50230c52e8e887d2d8b5 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Sat, 4 Feb 2023 14:39:11 +0100 Subject: Restrict texture https upgrading to only minecraft.net (#578) --- .../notenoughupdates/hooks/ThreadDownloadImageHook.java | 17 ++++++++++++----- .../mixins/MixinThreadDownloadImageData.java | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java b/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java index 4fa57360..e84fce11 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Linnea Gräf + * Copyright (C) 2022-2023 Linnea Gräf * * This file is part of NotEnoughUpdates. * @@ -26,15 +26,22 @@ import javax.net.ssl.HttpsURLConnection; import java.net.HttpURLConnection; public class ThreadDownloadImageHook { + public static String hookThreadImageLink(String originalLink) { + if (!NotEnoughUpdates.INSTANCE.config.misc.fixSteveSkulls || originalLink == null || !originalLink.startsWith( + "http://textures.minecraft.net")) + return originalLink; + return originalLink.replace("http://", "https://"); + } + public static void hookThreadImageConnection(HttpURLConnection connection) { if ((connection instanceof HttpsURLConnection) && NotEnoughUpdates.INSTANCE.config.misc.fixSteveSkulls) { ApiUtil.patchHttpsRequest((HttpsURLConnection) connection); } } - public static String hookThreadImageLink(String originalLink) { - if (!NotEnoughUpdates.INSTANCE.config.misc.fixSteveSkulls || originalLink == null) - return originalLink; - return originalLink.replace("http://", "https://"); + public interface AccessorThreadDownloadImageData { + String getOriginalUrl(); + + String getPatchedUrl(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java index c6d25a9e..fd4ee495 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Linnea Gräf + * Copyright (C) 2022-2023 Linnea Gräf * * This file is part of NotEnoughUpdates. * @@ -30,12 +30,14 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ThreadDownloadImageData.class) -public class MixinThreadDownloadImageData { +public class MixinThreadDownloadImageData implements ThreadDownloadImageHook.AccessorThreadDownloadImageData{ @Mutable @Shadow @Final private String imageUrl; + private String originalUrl; + @Redirect( method = "", at = @At( @@ -44,5 +46,16 @@ public class MixinThreadDownloadImageData { opcode = Opcodes.PUTFIELD)) public void useHttpsDownloadLinks(ThreadDownloadImageData instance, String value) { this.imageUrl = ThreadDownloadImageHook.hookThreadImageLink(value); + this.originalUrl = value; + } + + @Override + public String getOriginalUrl() { + return originalUrl; + } + + @Override + public String getPatchedUrl() { + return imageUrl; } } -- cgit