Skip to content

Commit

Permalink
Add hacky mixin into ModInjector to ensure floodgate-fabric works wit…
Browse files Browse the repository at this point in the history
…h direct connections (#122)
  • Loading branch information
onebeastchris authored May 1, 2024
1 parent 3d35cdb commit bf91d26
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ dependencies {
include("org.geysermc.event", "events", "1.1-SNAPSHOT")
include("org.lanternpowered", "lmbda", "2.0.0") // used in events

// Geyser dependency for the fun injector mixin :)))
modImplementation("org.geysermc.geyser:fabric:2.2.3-SNAPSHOT")

// cloud
include("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
modImplementation("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
Expand Down Expand Up @@ -134,7 +137,7 @@ modrinth {
syncBodyFrom.set(rootProject.file("README.md").readText())

uploadFile.set(tasks.named("remapModrinthJar"))
gameVersions.addAll("1.20.5")
gameVersions.addAll("1.20.5", "1.20.6")

loaders.add("fabric")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package org.geysermc.floodgate.inject.fabric;

import com.google.inject.Inject;
import io.netty.channel.*;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.inject.CommonPlatformInjector;

@RequiredArgsConstructor
public final class FabricInjector extends CommonPlatformInjector {

@Setter @Getter
private static FabricInjector instance;

@Getter private final boolean injected = true;

@Inject private FloodgateLogger logger;

@Override
public void inject() throws Exception {
//no-op
}

public void injectClient(ChannelFuture future) {
if (future.channel().pipeline().names().contains("floodgate-init")) {
logger.debug("Tried to inject twice!");
return;
}

future.channel().pipeline().addFirst("floodgate-init", new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg) throws Exception {
Expand Down Expand Up @@ -47,11 +59,4 @@ public void removeInjection() throws Exception {
//no-op
}

public static FabricInjector getInstance() {
return instance;
}

public static void setInstance(FabricInjector injector) {
instance = injector;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.geysermc.floodgate.mixin;

import io.netty.channel.ChannelFuture;
import org.geysermc.floodgate.inject.fabric.FabricInjector;
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.platform.mod.GeyserModInjector;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(value = GeyserModInjector.class, remap = false)
public class GeyserModInjectorMixin {

@Shadow
private List<ChannelFuture> allServerChannels;

@Inject(method = "initializeLocalChannel0", at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"))
public void onChannelAdd(GeyserBootstrap bootstrap, CallbackInfo ci) {
FabricInjector.getInstance().injectClient(this.allServerChannels.get(this.allServerChannels.size() - 1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
//returns true if fabricproxy-lite is present, therefore loading the mixin. If not present, the mixin will not be loaded.
return FabricLoader.getInstance().isModLoaded("fabricproxy-lite");
}
if (mixinClassName.equals("org.geysermc.floodgate.mixin.GeyserModInjectorMixin")) {
return FabricLoader.getInstance().isModLoaded("geyser-fabric");
}
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/floodgate.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"compatibilityLevel": "JAVA_16",
"mixins": [
"ChunkMapMixin",
"ClientIntentionPacketMixinInterface",
"ClientIntentionPacketMixin",
"ClientIntentionPacketMixinInterface",
"ConnectionMixin",
"GeyserModInjectorMixin",
"ServerConnectionListenerMixin"
],
"plugin": "org.geysermc.floodgate.util.MixinConfigPlugin",
Expand Down

0 comments on commit bf91d26

Please sign in to comment.