Skip to content

Commit

Permalink
Add allowed skin domains in config
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Aug 18, 2022
1 parent 0feca3e commit 88d09c0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version=0.14.9
fabric_version=0.59.0+1.19.2
quilt_mappings=3
# Mod Properties
mod_version=2.0.0
mod_version=2.0.1
maven_group=org.samo_lego
archives_base_name=fabrictailor
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public void onInitializeClient() {

// Reset values
ClientLoginConnectionEvents.DISCONNECT.register((handler, server) -> {
System.out.println("Disconnected from server");
TAILORED_SERVER = false;
ALLOW_DEFAULT_SKIN = true;
forceOpen = false;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/samo_lego/fabrictailor/config/TailorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Set;

import static org.samo_lego.fabrictailor.FabricTailor.MOD_ID;
import static org.samo_lego.fabrictailor.FabricTailor.configFile;
Expand Down Expand Up @@ -52,6 +53,22 @@ public class TailorConfig implements IBrigadierConfigurator {
@SerializedName("custom_skin_server")
public String customSkinServer = "";

@SerializedName("allowed_texture_domains")
public Set<String> allowedTextureDomains = Set.of(
"minecraft.net",
"mojang.com",
"crafatar.com",
"imgur.com",
"githubusercontent.com",
"minecraftskins.com",
"mc-heads.net",
"ely.by",
"namemc.com",
"planetminecraft.com",
"googleusercontent.com",
"nocookie.net"
);

@Override
public void save() {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.samo_lego.fabrictailor.mixin.client;

import com.google.common.net.InternetDomainName;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.net.URI;

import static org.samo_lego.fabrictailor.FabricTailor.config;

@Mixin(value = YggdrasilMinecraftSessionService.class, remap = false)
public class MYggDrasilMinecraftSessionService_AllSkinsAcceptor {
Expand All @@ -16,9 +22,18 @@ private void ft_enableInsecureValue(Property property, CallbackInfoReturnable<St
cir.setReturnValue(property.getValue());
}

@Inject(method = "isAllowedTextureDomain", at = @At("TAIL"), cancellable = true)
private static void ft_allowAllTextureDomains(String url, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(true);
@Inject(method = "isAllowedTextureDomain", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private static void ft_allowAllTextureDomains(String url, CallbackInfoReturnable<Boolean> cir, URI uri, String domain) {
if (url.startsWith("file://")) {
cir.setReturnValue(true);
return;
}

String topDomain = InternetDomainName.from(domain)
.topDomainUnderRegistrySuffix()
.toString()
.toLowerCase();
cir.setReturnValue(config.allowedTextureDomains.contains(topDomain));
}

@ModifyVariable(method = "getTextures", at = @At("HEAD"), argsOnly = true)
Expand Down

0 comments on commit 88d09c0

Please sign in to comment.