Added ability to disable Meteor's API

This commit is contained in:
Cloudburst
2021-07-23 13:52:31 +02:00
parent a1d8e3d567
commit de891d6c6d
5 changed files with 100 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
package cloudburst.rejects.mixin.meteor;
import cloudburst.rejects.utils.RejectsConfig;
import meteordevelopment.meteorclient.gui.tabs.builtin.ConfigTab;
import meteordevelopment.meteorclient.settings.*;
import org.spongepowered.asm.mixin.*;
@Mixin(ConfigTab.class)
public class ConfigTabMixin {
@Shadow
@Final
private static Settings settings;
private static final SettingGroup sgRejects = settings.createGroup("Rejects");
private static final Setting<RejectsConfig.HttpAllowed> httpAllowed = sgRejects.add(new EnumSetting.Builder<RejectsConfig.HttpAllowed>()
.name("http-allowed")
.description("Changes what api endpoints can be reached.")
.defaultValue(RejectsConfig.get().httpAllowed)
.onChanged(v -> RejectsConfig.get().httpAllowed = v)
.build()
);
}

View File

@@ -0,0 +1,27 @@
package cloudburst.rejects.mixin.meteor;
import cloudburst.rejects.utils.RejectsConfig;
import meteordevelopment.meteorclient.utils.network.Http;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
@Mixin(Http.class)
public class HttpMixin {
@ModifyArg(method="get", at= @At(value = "INVOKE", target = "Lmeteordevelopment/meteorclient/utils/network/Http$Request;<init>(Lmeteordevelopment/meteorclient/utils/network/Http$Method;Ljava/lang/String;)V"), remap = false)
private static String onGet(String url) {
if (RejectsConfig.get().httpAllowed == RejectsConfig.HttpAllowed.Nothing) return "http://0.0.0.0";
else if (RejectsConfig.get().httpAllowed == RejectsConfig.HttpAllowed.NotMeteorApi && url.startsWith("https://meteorclient.com/api")) return "http://0.0.0.0";
else if (RejectsConfig.get().httpAllowed == RejectsConfig.HttpAllowed.NotMeteorPing && url.startsWith("https://meteorclient.com/api/online")) return "http://0.0.0.0";
return url;
}
@ModifyArg(method="post", at= @At(value = "INVOKE", target = "Lmeteordevelopment/meteorclient/utils/network/Http$Request;<init>(Lmeteordevelopment/meteorclient/utils/network/Http$Method;Ljava/lang/String;)V"), remap = false)
private static String onPost(String url) {
if (RejectsConfig.get().httpAllowed == RejectsConfig.HttpAllowed.Nothing) return "http://0.0.0.0";
else if (RejectsConfig.get().httpAllowed == RejectsConfig.HttpAllowed.NotMeteorApi && url.startsWith("https://meteorclient.com/api")) return "http://0.0.0.0";
else if (RejectsConfig.get().httpAllowed == RejectsConfig.HttpAllowed.NotMeteorPing && url.startsWith("https://meteorclient.com/api/online")) return "http://0.0.0.0";
return url;
}
}

View File

@@ -0,0 +1,41 @@
package cloudburst.rejects.utils;
import meteordevelopment.meteorclient.systems.System;
import meteordevelopment.meteorclient.MeteorClient;
import net.minecraft.nbt.NbtCompound;
public class RejectsConfig extends System<RejectsConfig> {
private static final RejectsConfig rejectsConfig = new RejectsConfig();
public enum HttpAllowed {
Everything,
NotMeteorApi,
NotMeteorPing,
Nothing
}
public HttpAllowed httpAllowed = HttpAllowed.Everything;
public RejectsConfig() {
super("rejects-config");
init();
load(MeteorClient.FOLDER);
}
public static RejectsConfig get() {
return rejectsConfig;
}
@Override
public NbtCompound toTag() {
NbtCompound tag = new NbtCompound();
tag.putString("httpAllowed", httpAllowed.toString());
return tag;
}
@Override
public RejectsConfig fromTag(NbtCompound tag) {
httpAllowed = HttpAllowed.valueOf(tag.getString("httpAllowed"));
return this;
}
}

View File

@@ -1,5 +1,7 @@
package cloudburst.rejects.utils; package cloudburst.rejects.utils;
import meteordevelopment.meteorclient.MeteorClient;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@@ -7,6 +9,10 @@ public class RejectsUtils {
public static int CPS = 0; public static int CPS = 0;
public static void init() { public static void init() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
RejectsConfig.get().save(MeteorClient.FOLDER);
}));
new Timer().scheduleAtFixedRate(newTimerTaskFromLambda(() -> CPS = 0), 0, 1000); new Timer().scheduleAtFixedRate(newTimerTaskFromLambda(() -> CPS = 0), 0, 1000);
} }

View File

@@ -4,6 +4,8 @@
"compatibilityLevel": "JAVA_16", "compatibilityLevel": "JAVA_16",
"mixins": [ ], "mixins": [ ],
"client": [ "client": [
"GuiRendererAccessor" "ConfigTabMixin",
"GuiRendererAccessor",
"HttpMixin"
] ]
} }