81 lines
2.6 KiB
Java
81 lines
2.6 KiB
Java
package io.gitlab.jfronny.yescheat;
|
|
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import org.objectweb.asm.tree.ClassNode;
|
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.Properties;
|
|
import java.util.Set;
|
|
|
|
public class YesCheatPlugin implements IMixinConfigPlugin {
|
|
private Properties config;
|
|
FabricLoader loader = FabricLoader.getInstance();
|
|
private final File path = loader.getConfigDir().resolve("yescheat.properties").toFile();
|
|
@Override
|
|
public void onLoad(String s) {
|
|
config = new Properties();
|
|
try (FileInputStream fs = new FileInputStream(path)) {
|
|
config.load(fs);
|
|
} catch (IOException e) {
|
|
System.err.println("[YesCheat] Could not read config, using defaults");
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void save() {
|
|
try (FileOutputStream fs = new FileOutputStream(path)) {
|
|
config.store(fs, "YesCheat config, you can toggle individual mixins here");
|
|
} catch (IOException e) {
|
|
System.err.println("[YesCheat] Could not save config, using defaults");
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getRefMapperConfig() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
|
String mixinPath = "io.gitlab.jfronny.yescheat.mixin";
|
|
if (!mixinClassName.startsWith(mixinPath)) {
|
|
System.err.println("[YesCheat] found foreign mixin " + mixinClassName + "for" + targetClassName + ", disabling");
|
|
return false;
|
|
}
|
|
String mixin = mixinClassName.substring(mixinPath.length() + 1, mixinClassName.length() - 5);
|
|
if (!config.containsKey(mixin)) {
|
|
System.err.println("[YesCheat] Could not load value for " + mixinClassName + ", using default");
|
|
config.put(mixin, true);
|
|
save();
|
|
}
|
|
return Boolean.parseBoolean((String) config.get(mixin));
|
|
}
|
|
|
|
@Override
|
|
public void acceptTargets(Set<String> set, Set<String> set1) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public List<String> getMixins() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void preApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void postApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
|
|
|
|
}
|
|
}
|