2020-09-02 12:30:25 +08:00
|
|
|
package customskinloader.fabric;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
2020-09-20 21:12:14 +08:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.URL;
|
2023-01-26 18:51:20 +08:00
|
|
|
import java.nio.file.Paths;
|
2020-09-02 12:30:25 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
2020-11-05 21:54:43 +08:00
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
import com.google.gson.JsonParser;
|
2023-01-26 18:51:20 +08:00
|
|
|
import customskinloader.log.LogManager;
|
|
|
|
|
import customskinloader.log.Logger;
|
2020-09-02 12:30:25 +08:00
|
|
|
import org.objectweb.asm.tree.ClassNode;
|
|
|
|
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
|
|
|
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
|
|
|
|
|
|
|
|
|
public class MixinConfigPlugin implements IMixinConfigPlugin {
|
2023-01-26 18:51:20 +08:00
|
|
|
public static Logger logger = LogManager.getLogger("Fabric");
|
2020-11-05 21:54:43 +08:00
|
|
|
private long world_version;
|
|
|
|
|
private long protocol_version;
|
2020-09-20 21:12:14 +08:00
|
|
|
|
2020-09-02 12:30:25 +08:00
|
|
|
@Override
|
|
|
|
|
public void onLoad(String mixinPackage) {
|
2023-01-26 18:51:20 +08:00
|
|
|
LogManager.setLogFile(Paths.get("./CustomSkinLoader/CustomSkinLoader.log"));
|
2020-09-20 21:12:14 +08:00
|
|
|
URL versionJson = this.getClass().getResource("/version.json");
|
|
|
|
|
if (versionJson != null) {
|
|
|
|
|
logger.info("\"version.json\": " + versionJson.toString());
|
|
|
|
|
try (
|
|
|
|
|
InputStream is = versionJson.openStream();
|
|
|
|
|
InputStreamReader isr = new InputStreamReader(is)
|
|
|
|
|
) {
|
2020-11-05 21:54:43 +08:00
|
|
|
JsonObject object = new JsonParser().parse(isr).getAsJsonObject();
|
|
|
|
|
String name = object.get("name").getAsString();
|
|
|
|
|
this.world_version = object.get("world_version").getAsLong();
|
|
|
|
|
this.protocol_version = object.get("protocol_version").getAsLong();
|
|
|
|
|
logger.info("MinecraftVersion: {name='" + name + "', world_version='" + this.world_version + "', protocol_version='" + this.protocol_version + "'}");
|
2020-09-20 21:12:14 +08:00
|
|
|
} catch (Throwable t) {
|
|
|
|
|
logger.warning("An exception occurred when reading \"version.json\"!");
|
|
|
|
|
logger.warning(t);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
logger.warning("Can't read \"version.json\"! Ignore this message if the version you start is earlier than 18w47b.");
|
|
|
|
|
}
|
2021-01-03 02:53:57 +08:00
|
|
|
|
|
|
|
|
// This mod will remap extra classes when in the development environment.
|
|
|
|
|
DevEnvRemapper.initRemapper();
|
2020-09-02 12:30:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRefMapperConfig() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
2020-09-20 21:12:14 +08:00
|
|
|
boolean result = true;
|
2021-05-07 17:15:45 +08:00
|
|
|
if (mixinClassName.endsWith(".MixinThreadDownloadImageDataV2")) {
|
2021-06-09 14:55:20 +08:00
|
|
|
result = (this.world_version >= 2205 && this.world_version <= 2722) && ((this.protocol_version >= 554 && this.protocol_version <= 754) || (this.protocol_version >= 801 && this.protocol_version <= 803) || (this.protocol_version >= 0x40000001 && this.protocol_version <= 0x40000022)); // 19w38a ~ 1.17-rc1
|
2022-12-07 19:38:24 +08:00
|
|
|
} else if (mixinClassName.endsWith(".MixinSkinManager$V2")) {
|
|
|
|
|
result = this.world_version >= 2205 && this.protocol_version >= 554; // 19w38a+
|
2020-09-20 21:12:14 +08:00
|
|
|
} else if (mixinClassName.endsWith(".MixinLayerCape") || mixinClassName.endsWith(".MixinRenderPlayer")) {
|
2020-11-05 21:54:43 +08:00
|
|
|
result = this.world_version >= 2210 && this.protocol_version >= 558; // 19w41a+
|
2021-06-09 14:55:20 +08:00
|
|
|
} else if (mixinClassName.endsWith(".MixinThreadDownloadImageDataV3")) {
|
|
|
|
|
result = this.world_version >= 2723 && ((this.protocol_version >= 755 && this.protocol_version < 801) || (this.protocol_version > 803 && this.protocol_version < 0x40000001) || this.protocol_version >= 0x40000023); // 1.17-rc2+
|
2020-09-02 12:30:25 +08:00
|
|
|
}
|
2020-09-20 21:12:14 +08:00
|
|
|
logger.info("target: " + targetClassName + ", mixin: " + mixinClassName + ", result: " + result);
|
|
|
|
|
return result;
|
2020-09-02 12:30:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getMixins() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To be compatible with 0.7.11
|
|
|
|
|
public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To be compatible with 0.7.11
|
|
|
|
|
public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|