mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Add hacky mixin into ModInjector to ensure floodgate-fabric works with direct connections (#122)
This commit is contained in:
@@ -49,6 +49,9 @@ dependencies {
|
|||||||
include("org.geysermc.event", "events", "1.1-SNAPSHOT")
|
include("org.geysermc.event", "events", "1.1-SNAPSHOT")
|
||||||
include("org.lanternpowered", "lmbda", "2.0.0") // used in events
|
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
|
// cloud
|
||||||
include("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
|
include("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
|
||||||
modImplementation("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
|
modImplementation("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
|
||||||
@@ -134,7 +137,7 @@ modrinth {
|
|||||||
syncBodyFrom.set(rootProject.file("README.md").readText())
|
syncBodyFrom.set(rootProject.file("README.md").readText())
|
||||||
|
|
||||||
uploadFile.set(tasks.named("remapModrinthJar"))
|
uploadFile.set(tasks.named("remapModrinthJar"))
|
||||||
gameVersions.addAll("1.20.5")
|
gameVersions.addAll("1.20.5", "1.20.6")
|
||||||
|
|
||||||
loaders.add("fabric")
|
loaders.add("fabric")
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
package org.geysermc.floodgate.inject.fabric;
|
package org.geysermc.floodgate.inject.fabric;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||||
import org.geysermc.floodgate.inject.CommonPlatformInjector;
|
import org.geysermc.floodgate.inject.CommonPlatformInjector;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public final class FabricInjector extends CommonPlatformInjector {
|
public final class FabricInjector extends CommonPlatformInjector {
|
||||||
|
|
||||||
|
@Setter @Getter
|
||||||
private static FabricInjector instance;
|
private static FabricInjector instance;
|
||||||
|
|
||||||
@Getter private final boolean injected = true;
|
@Getter private final boolean injected = true;
|
||||||
|
|
||||||
|
@Inject private FloodgateLogger logger;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inject() throws Exception {
|
public void inject() throws Exception {
|
||||||
//no-op
|
//no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectClient(ChannelFuture future) {
|
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() {
|
future.channel().pipeline().addFirst("floodgate-init", new ChannelInboundHandlerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg) throws Exception {
|
public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg) throws Exception {
|
||||||
@@ -47,11 +59,4 @@ public final class FabricInjector extends CommonPlatformInjector {
|
|||||||
//no-op
|
//no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FabricInjector getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setInstance(FabricInjector injector) {
|
|
||||||
instance = injector;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,9 @@ public class MixinConfigPlugin implements IMixinConfigPlugin {
|
|||||||
//returns true if fabricproxy-lite is present, therefore loading the mixin. If not present, the mixin will not be loaded.
|
//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");
|
return FabricLoader.getInstance().isModLoaded("fabricproxy-lite");
|
||||||
}
|
}
|
||||||
|
if (mixinClassName.equals("org.geysermc.floodgate.mixin.GeyserModInjectorMixin")) {
|
||||||
|
return FabricLoader.getInstance().isModLoaded("geyser-fabric");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
"compatibilityLevel": "JAVA_16",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"ChunkMapMixin",
|
"ChunkMapMixin",
|
||||||
"ClientIntentionPacketMixinInterface",
|
|
||||||
"ClientIntentionPacketMixin",
|
"ClientIntentionPacketMixin",
|
||||||
|
"ClientIntentionPacketMixinInterface",
|
||||||
"ConnectionMixin",
|
"ConnectionMixin",
|
||||||
|
"GeyserModInjectorMixin",
|
||||||
"ServerConnectionListenerMixin"
|
"ServerConnectionListenerMixin"
|
||||||
],
|
],
|
||||||
"plugin": "org.geysermc.floodgate.util.MixinConfigPlugin",
|
"plugin": "org.geysermc.floodgate.util.MixinConfigPlugin",
|
||||||
|
|||||||
Reference in New Issue
Block a user