Skip to content

Commit

Permalink
Add online mode hack
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Jan 26, 2021
1 parent 530e2ce commit ce21876
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ This will have the better compatibility with other mods.
* Start server to generate config
* Setting velocity `player-info-forwarding-mode` to `modern` and `forwarding-secret`
* Setting `secret` in `config/Fabric-Lite.toml` match velocity config
* Set server to **offline mode**
48 changes: 43 additions & 5 deletions src/main/java/one/oktw/FabricProxyLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
import net.minecraft.text.LiteralText;
import one.oktw.mixin.ClientConnection_AddressAccessor;
import one.oktw.mixin.ServerLoginNetworkHandler_ProfileAccessor;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

public class FabricProxyLite implements DedicatedServerModInitializer {
import java.util.List;
import java.util.Set;

public class FabricProxyLite implements DedicatedServerModInitializer, IMixinConfigPlugin {
public static ModConfig config;

@Override
public void onInitializeServer() {
// Config
AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();

// Packet receiver
ServerLoginNetworking.registerGlobalReceiver(VelocityLib.PLAYER_INFO_CHANNEL, this::handleVelocityPacket);
ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> sender.sendPacket(VelocityLib.PLAYER_INFO_CHANNEL, PacketByteBufs.empty()));
Expand All @@ -44,4 +46,40 @@ private void handleVelocityPacket(MinecraftServer server, ServerLoginNetworkHand

((ServerLoginNetworkHandler_ProfileAccessor) handler).setProfile(VelocityLib.createProfile(buf));
}

// Only load hack mixin if enabled
@Override
public void onLoad(String mixinPackage) {
if (config == null) {
AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
}
}

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

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return config.getHackOnlineMode() && !config.getSecret().isEmpty();
}

@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) {
}
}
11 changes: 11 additions & 0 deletions src/main/java/one/oktw/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"})
@Config(name = "FabricProxy-Lite")
public class ModConfig implements ConfigData {
private boolean hackOnlineMode = true;

@Comment("Velocity proxy secret")
private String secret = "";

public boolean getHackOnlineMode() {
String env = System.getenv("FABRIC_PROXY_HACK_ONLINE_MODE");
if (env == null) {
return hackOnlineMode;
} else {
return Boolean.parseBoolean(env);
}
}

public String getSecret() {
String env = System.getenv("FABRIC_PROXY_SECRET");
if (env == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package one.oktw.mixin.hack;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ServerLoginNetworkHandler.class)
public class ServerLoginNetworkHandler_SkipKeyPacket {
@Redirect(method = "onHello", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;isOnlineMode()Z"))
private boolean skipKeyPacket(MinecraftServer minecraftServer) {
return false;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
]
},
"mixins": [
"core.mixins.json"
"core.mixins.json",
"hack.mixins.json"
],

"depends": {
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/hack.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"minVersion": "0.8",
"package": "one.oktw.mixin.hack",
"plugin": "one.oktw.FabricProxyLite",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ServerLoginNetworkHandler_SkipKeyPacket"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit ce21876

Please sign in to comment.