Skip to content

Commit

Permalink
Fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
SFort committed Dec 10, 2023
1 parent 07fcb31 commit e7465fe
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ org.gradle.jvmargs=-Xmx1G
sfini_version=1

# Mod Properties
mod_version = 1.3.4
mod_version = 1.3.5
maven_group = tf.ssf.sfort
archives_base_name = OCAIP
18 changes: 14 additions & 4 deletions src/main/java/sf/ssf/sfort/ocaip/Wire.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package sf.ssf.sfort.ocaip;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.i2p.crypto.eddsa.EdDSAPublicKey;
import tf.ssf.sfort.ini.SFIni;

Expand All @@ -18,7 +16,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Environment(EnvType.SERVER)

public class Wire {
public static final File conf = new File(Reel.dir+"/server_keys.sf.ini");

Expand All @@ -27,6 +25,7 @@ public class Wire {

public static POW pow = null;
public static boolean requireOCAIP = false;
public static boolean disableFAPIjank = true;

public static void addAndWrite(String name, PublicKey key) throws IOException {
if (!keys.containsKey(name)) {
Expand Down Expand Up @@ -105,7 +104,11 @@ public static void loadConf() {
"; Registration sha1pow zero count (complexity, higher value is more time)",
"sha1pow.zero=",
"; Registration sha1pow count",
"sha1pow.count="
"sha1pow.count=",
"; FabricAPI has some really janky injections, this will remove them",
"; when true other mods logins that depend on fapi might break might not",
"; when false if fapi is installed players with a vanilla game won't be able to connect",
"disableFAPIlogin=true",
}));
loadLegacyConf(defIni);

Expand Down Expand Up @@ -172,6 +175,13 @@ public static void loadConf(SFIni ini) {
if (d != null) d.val = "false";
Reel.log.error("OCAIP failed to read requireOCAIP, reset to default", e);
}
try {
disableFAPIjank = ini.getBoolean("disableFAPIlogin");
} catch (IllegalArgumentException e) {
SFIni.Data d = ini.getLastData("disableFAPIlogin");
if (d != null) d.val = "true";
Reel.log.error("OCAIP failed to read disableFAPIlogin, reset to default", e);
}
}
public static void loadLegacyConf(SFIni ini) {
File legacyConfFile = new File(Reel.dir + "/password");
Expand Down
130 changes: 130 additions & 0 deletions src/main/java/sf/ssf/sfort/ocaip/mixin/MixinConfigPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package sf.ssf.sfort.ocaip.mixin;

import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.transformer.Config;
import sf.ssf.sfort.ocaip.Reel;
import sf.ssf.sfort.ocaip.Wire;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

//From the bottom of my heart the fabricAPI dev that made these bits if you're reading this never code again, thanks.
public class MixinConfigPlugin implements IMixinConfigPlugin {

public static Function<Object, List<IMixinConfig>> getMixinInfoFromClassInfo = i -> Collections.emptyList();
static {
try {
Class<?> transClass = Class.forName("org.spongepowered.asm.mixin.transformer.MixinTransformer");
Class<?> procClass = Class.forName("org.spongepowered.asm.mixin.transformer.MixinProcessor");
Field processorField = transClass.getDeclaredField("processor");
Field pendingField = procClass.getDeclaredField("pendingConfigs");
processorField.setAccessible(true);
pendingField.setAccessible(true);
getMixinInfoFromClassInfo = tr -> {
try {
if (transClass.isInstance(tr)) {
Object proc = processorField.get(tr);
if (procClass.isInstance(proc)) {
Object pend = pendingField.get(proc);
if (pend instanceof List) {
List<?> list = (List<?>) pend;
List<IMixinConfig> ret = new ArrayList<>(list.size());
for (Object o : list) {
if (o instanceof IMixinConfig) {
ret.add((IMixinConfig) o);
}
}
return ret;
}
}
}
} catch (Exception e) {
Reel.log.error("Failed to reflect fabric-networking, vanilla auth likely broken: ", e);
}
return Collections.emptyList();
};
} catch (Throwable e) {
Reel.log.error("Failed to reflect fabric-networking, vanilla auth likely broken: ", e);
}
}

@Override
public void onLoad(String mixinPackage) {
if (!Wire.disableFAPIjank) return;
for (Config config : Mixins.getConfigs()) {
processIMC(config.getConfig());
}
for (IMixinConfig imc : getMixinInfoFromClassInfo.apply(MixinEnvironment.getCurrentEnvironment().getActiveTransformer())) {
processIMC(imc);
}

}
public static void processIMC(IMixinConfig imc) {
if (imc == null) return;
if (imc.getMixinPackage().startsWith("net.fabricmc.fabric.mixin.networking")) {
List<String> mixinClassesClient = pluck(imc.getClass(), imc, "mixinClasses");
if (mixinClassesClient == null) return;
if (mixinClassesClient.remove("ServerLoginNetworkHandlerMixin")) {
Reel.log.warn("REMOVING FAPIs ServerLoginNetworkHandlerMixin as it is soo poorly made it shouldn't exist, this may break some login networking, feel free to discuss this at https://github.com/FabricMC/fabric ");
}
}
}

@SuppressWarnings("unchecked")
private static <T> T pluck(Class<?> clazz, Object inst, String field) {
Field f = null;
Class<?> cursor = clazz;
while (f == null && cursor != null) {
try {
f = cursor.getDeclaredField(field);
} catch (NoSuchFieldException ignore) {}
cursor = cursor.getSuperclass();
}
if (f == null) throw new NoSuchFieldError(field);
f.setAccessible(true);
try {
return (T)f.get(inst);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}

@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) {
}

}

1 change: 1 addition & 0 deletions src/main/resources/ocaip.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"minVersion": "0.8",
"package": "sf.ssf.sfort.ocaip.mixin",
"compatibilityLevel": "JAVA_11",
"plugin": "sf.ssf.sfort.ocaip.mixin.MixinConfigPlugin",
"server": [
"NetServerLogin",
"NetServerSync"
Expand Down

0 comments on commit e7465fe

Please sign in to comment.