From 800b26bf18f1851bb057021cfe8c57afb0ee646c Mon Sep 17 00:00:00 2001 From: gnembon Date: Sun, 7 Jul 2019 18:52:56 -0300 Subject: [PATCH] portal suffocation and antiCheat disabled. --- src/main/java/carpet/CarpetServer.java | 9 +- .../mixins/Entity_portalSuffocationMixin.java | 51 +++++++++ .../carpet/mixins/IntegratedServerMixin.java | 8 +- .../mixins/MinecraftDedicatedServerMixin.java | 8 +- .../mixins/MinecraftServer_coreMixin.java | 29 ++--- .../PortalForcer_portalSuffocationMixin.java | 100 ++++++++++++++++++ .../mixins/ServerPlayNetworkHandlerMixin.java | 11 -- ...layNetworkHandler_antiCheatSpeedMixin.java | 52 +++++++++ .../java/carpet/settings/CarpetSettings.java | 14 +-- src/main/resources/carpet.mixins.json | 5 + 10 files changed, 239 insertions(+), 48 deletions(-) create mode 100644 src/main/java/carpet/mixins/Entity_portalSuffocationMixin.java create mode 100644 src/main/java/carpet/mixins/PortalForcer_portalSuffocationMixin.java create mode 100644 src/main/java/carpet/mixins/ServerPlayNetworkHandler_antiCheatSpeedMixin.java diff --git a/src/main/java/carpet/CarpetServer.java b/src/main/java/carpet/CarpetServer.java index 1443a87c..5c411f08 100644 --- a/src/main/java/carpet/CarpetServer.java +++ b/src/main/java/carpet/CarpetServer.java @@ -48,11 +48,6 @@ public class CarpetServer // static for now - easier to handle all around the co extensions.forEach(CarpetExtension::onGameStarted); } - public static void init(MinecraftServer server) //aka constructor of this static singleton class - { - // no sure we really need this here, needs testing and moving to onServerLoaded - //CarpetServer.minecraft_server = server; - } public static void onServerLoaded(MinecraftServer server) { CarpetServer.minecraft_server = server; @@ -70,8 +65,12 @@ public class CarpetServer // static for now - easier to handle all around the co TickSpeed.tick(server); HUDController.update_hud(server); scriptServer.events.tick(); + //in case something happens CarpetSettings.impendingFillSkipUpdates = false; + CarpetSettings.currentTelepotingEntityBox = null; + CarpetSettings.fixedPosition = null; + extensions.forEach(e -> e.onTick(server)); } diff --git a/src/main/java/carpet/mixins/Entity_portalSuffocationMixin.java b/src/main/java/carpet/mixins/Entity_portalSuffocationMixin.java new file mode 100644 index 00000000..d5de13d0 --- /dev/null +++ b/src/main/java/carpet/mixins/Entity_portalSuffocationMixin.java @@ -0,0 +1,51 @@ +package carpet.mixins; + +import carpet.settings.CarpetSettings; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.world.dimension.DimensionType; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Entity.class) +public abstract class Entity_portalSuffocationMixin +{ + @Shadow public abstract Box getBoundingBox(); + + @Inject(method = "changeDimension", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;getLastPortalDirection()Lnet/minecraft/util/math/Direction;" + )) + private void registerEntityDimensionChange(DimensionType dimensionType_1, CallbackInfoReturnable cir) + { + if (CarpetSettings.portalSuffocationFix) + { + CarpetSettings.currentTelepotingEntityBox = getBoundingBox(); + CarpetSettings.fixedPosition = null; + } + } + + @Redirect(method = "changeDimension", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;setPositionAndAngles(Lnet/minecraft/util/math/BlockPos;FF)V" + )) + private void alternativeSetPositionAndAngles(Entity entity, BlockPos blockPos_1, float float_1, float float_2) + { + if (CarpetSettings.portalSuffocationFix && CarpetSettings.fixedPosition != null) + entity.setPositionAndAngles(CarpetSettings.fixedPosition.x, CarpetSettings.fixedPosition.y, CarpetSettings.fixedPosition.z, float_1, float_2); + else + entity.setPositionAndAngles(blockPos_1, float_1, float_2); + } + + @Inject(method = "changeDimension", at = @At("RETURN")) + private void removeEntity(DimensionType dimensionType_1, CallbackInfoReturnable cir) + { + CarpetSettings.currentTelepotingEntityBox = null; + CarpetSettings.fixedPosition = null; + } +} diff --git a/src/main/java/carpet/mixins/IntegratedServerMixin.java b/src/main/java/carpet/mixins/IntegratedServerMixin.java index a5149af5..c81dbf84 100644 --- a/src/main/java/carpet/mixins/IntegratedServerMixin.java +++ b/src/main/java/carpet/mixins/IntegratedServerMixin.java @@ -1,17 +1,19 @@ package carpet.mixins; import carpet.CarpetServer; +import com.google.gson.JsonElement; import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.world.level.LevelGeneratorType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(IntegratedServer.class) public class IntegratedServerMixin { - @Inject(method = "setupServer", at = @At("TAIL")) - private void onSetupServerIntegrated(CallbackInfoReturnable cir) { + @Inject(method = "loadWorld", at = @At("HEAD")) + private void onSetupServerIntegrated(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) { CarpetServer.onServerLoaded((IntegratedServer) (Object) this); } } diff --git a/src/main/java/carpet/mixins/MinecraftDedicatedServerMixin.java b/src/main/java/carpet/mixins/MinecraftDedicatedServerMixin.java index c4842e13..a9cf010a 100644 --- a/src/main/java/carpet/mixins/MinecraftDedicatedServerMixin.java +++ b/src/main/java/carpet/mixins/MinecraftDedicatedServerMixin.java @@ -12,12 +12,14 @@ public class MinecraftDedicatedServerMixin { //to inject right before // this.tickWorlds(booleanSupplier_1); - @Inject(method = "setupServer", at = @At("TAIL")) + @Inject(method = "setupServer", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/dedicated/MinecraftDedicatedServer;loadWorld(Ljava/lang/String;Ljava/lang/String;JLnet/minecraft/world/level/LevelGeneratorType;Lcom/google/gson/JsonElement;)V", + shift = At.Shift.BEFORE + )) private void onSetupServer(CallbackInfoReturnable cir) { //CM start game hook CarpetServer.onGameStarted(); - //CM init - all stuff loaded from the server, just before worlds loading - CarpetServer.onServerLoaded((MinecraftDedicatedServer) (Object) this); } } diff --git a/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java b/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java index 11107bbf..4061db16 100644 --- a/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java +++ b/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java @@ -1,37 +1,19 @@ package carpet.mixins; import carpet.CarpetServer; -import com.mojang.authlib.GameProfileRepository; -import com.mojang.authlib.minecraft.MinecraftSessionService; -import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; -import com.mojang.datafixers.DataFixer; +import com.google.gson.JsonElement; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.WorldGenerationProgressListenerFactory; -import net.minecraft.server.command.CommandManager; -import net.minecraft.util.UserCache; +import net.minecraft.world.level.LevelGeneratorType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.io.File; -import java.net.Proxy; import java.util.function.BooleanSupplier; @Mixin(MinecraftServer.class) public abstract class MinecraftServer_coreMixin { - @Inject(method = "", at = @At(value = "RETURN")) - private void onMinecraftServerCTOR(File file_1, Proxy proxy_1, DataFixer dataFixer_1, - CommandManager serverCommandManager_1, YggdrasilAuthenticationService yggdrasilAuthenticationService_1, - MinecraftSessionService minecraftSessionService_1, GameProfileRepository gameProfileRepository_1, - UserCache userCache_1, WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory_1, - String string_1, CallbackInfo ci) - { - // Called during game start - CarpetServer.init((MinecraftServer) (Object) this); - } - //to inject right before // this.tickWorlds(booleanSupplier_1); @Inject( @@ -46,4 +28,11 @@ public abstract class MinecraftServer_coreMixin private void onTick(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { CarpetServer.tick((MinecraftServer) (Object) this); } + + // Dedicated server only + @Inject(method = "loadWorld", at = @At("HEAD")) + private void serverLoaded(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) + { + CarpetServer.onServerLoaded((MinecraftServer) (Object) this); + } } diff --git a/src/main/java/carpet/mixins/PortalForcer_portalSuffocationMixin.java b/src/main/java/carpet/mixins/PortalForcer_portalSuffocationMixin.java new file mode 100644 index 00000000..ea18d73a --- /dev/null +++ b/src/main/java/carpet/mixins/PortalForcer_portalSuffocationMixin.java @@ -0,0 +1,100 @@ +package carpet.mixins; + +import carpet.settings.CarpetSettings; +import net.minecraft.block.pattern.BlockPattern; +import net.minecraft.entity.Entity; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.PortalForcer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PortalForcer.class) +public class PortalForcer_portalSuffocationMixin +{ + @Inject(method = "usePortal", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;getLastPortalDirectionVector()Lnet/minecraft/util/math/Vec3d;" + )) + private void registerEntityDimensionChange(Entity entity_1, float float_1, CallbackInfoReturnable cir) + { + if (CarpetSettings.portalSuffocationFix) + { + CarpetSettings.currentTelepotingEntityBox = entity_1.getBoundingBox(); + CarpetSettings.fixedPosition = null; + } + } + + @Redirect(method = "usePortal", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;setPositionAndAngles(DDDFF)V" + )) + private void alternativeSetPositionAndAngles(Entity entity, double double_1, double double_2, double double_3, float float_1, float float_2) + { + if (CarpetSettings.portalSuffocationFix && CarpetSettings.fixedPosition != null) + entity.setPositionAndAngles(CarpetSettings.fixedPosition.x, CarpetSettings.fixedPosition.y, CarpetSettings.fixedPosition.z, float_1, float_2); + else + entity.setPositionAndAngles(double_1, double_2, double_3, float_1, float_2); + + } + + @Redirect(method = "usePortal", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;requestTeleport(DDDFF)V" + )) + private void alternativeSetPositionAndAngles(ServerPlayNetworkHandler serverPlayNetworkHandler, double double_1, double double_2, double double_3, float float_1, float float_2) + { + if (CarpetSettings.portalSuffocationFix && CarpetSettings.fixedPosition != null) + serverPlayNetworkHandler.requestTeleport(CarpetSettings.fixedPosition.x, CarpetSettings.fixedPosition.y, CarpetSettings.fixedPosition.z, float_1, float_2); + else + serverPlayNetworkHandler.requestTeleport(double_1, double_2, double_3, float_1, float_2); + + } + + @Inject(method = "usePortal", at = @At("RETURN")) + private void removeEntity(Entity entity_1, float float_1, CallbackInfoReturnable cir) + { + CarpetSettings.currentTelepotingEntityBox = null; + CarpetSettings.fixedPosition = null; + } + + + @Redirect(method = "getPortal",at = @At( + value = "INVOKE", + target = "Lnet/minecraft/block/pattern/BlockPattern$Result;method_18478(Lnet/minecraft/util/math/Direction;Lnet/minecraft/util/math/BlockPos;DLnet/minecraft/util/math/Vec3d;D)Lnet/minecraft/block/pattern/BlockPattern$TeleportTarget;" + )) + private BlockPattern.TeleportTarget newResult(BlockPattern.Result portal, Direction direction_1, BlockPos blockPos_1, double height_position_from_top, Vec3d vec3d_1, double width_position) + { + if (CarpetSettings.portalSuffocationFix && CarpetSettings.currentTelepotingEntityBox != null) + { + double entityWidth = CarpetSettings.currentTelepotingEntityBox.getXSize(); + double entityHeight = CarpetSettings.currentTelepotingEntityBox.getYSize(); + if (entityWidth >= portal.getWidth()) + { + width_position = 0.5; // will suffocate anyways, placing in the middle + } + else + { + width_position = MathHelper.clamp(width_position, entityWidth/(2*portal.getWidth()), 1.0-entityWidth/(2*portal.getWidth())); + } + if (entityHeight >= portal.getHeight()) + { + height_position_from_top = 1.0; + } + else + { + height_position_from_top = MathHelper.clamp(height_position_from_top, entityHeight/portal.getHeight(),1.0); + } + + } + BlockPattern.TeleportTarget target = portal.method_18478(direction_1, blockPos_1, height_position_from_top, vec3d_1, width_position); + CarpetSettings.fixedPosition = target.pos; + return target; + } +} diff --git a/src/main/java/carpet/mixins/ServerPlayNetworkHandlerMixin.java b/src/main/java/carpet/mixins/ServerPlayNetworkHandlerMixin.java index 779e7619..ea11e749 100644 --- a/src/main/java/carpet/mixins/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayNetworkHandlerMixin.java @@ -1,6 +1,5 @@ package carpet.mixins; -import carpet.settings.CarpetSettings; import carpet.helpers.TickSpeed; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; @@ -10,7 +9,6 @@ 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayNetworkHandler.class) @@ -43,13 +41,4 @@ public class ServerPlayNetworkHandlerMixin TickSpeed.reset_player_active_timeout(); } } - - @Redirect(method = "onPlayerMove", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/server/network/ServerPlayerEntity;isInTeleportationState()Z")) - private boolean relaxMoveRestrictions(ServerPlayerEntity serverPlayerEntity) - { - return serverPlayerEntity.isInTeleportationState() || CarpetSettings.antiCheatSpeed; - } - } diff --git a/src/main/java/carpet/mixins/ServerPlayNetworkHandler_antiCheatSpeedMixin.java b/src/main/java/carpet/mixins/ServerPlayNetworkHandler_antiCheatSpeedMixin.java new file mode 100644 index 00000000..ff4958dc --- /dev/null +++ b/src/main/java/carpet/mixins/ServerPlayNetworkHandler_antiCheatSpeedMixin.java @@ -0,0 +1,52 @@ +package carpet.mixins; + +import carpet.settings.CarpetSettings; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ServerPlayNetworkHandler.class) +public abstract class ServerPlayNetworkHandler_antiCheatSpeedMixin +{ + @Shadow private int floatingTicks; + + @Shadow private int vehicleFloatingTicks; + + @Shadow protected abstract boolean isServerOwner(); + + @Inject(method = "tick", at = @At("HEAD")) + private void restrictFloatingBits(CallbackInfo ci) + { + if (CarpetSettings.antiCheatDisabled) + { + if (floatingTicks > 70) floatingTicks--; + if (vehicleFloatingTicks > 70) vehicleFloatingTicks--; + } + + } + + @Redirect(method = "onVehicleMove", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;isServerOwner()Z" + )) + private boolean isServerTrusting(ServerPlayNetworkHandler serverPlayNetworkHandler) + { + return isServerOwner() || CarpetSettings.antiCheatDisabled; + } + + @Redirect(method = "onPlayerMove", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayerEntity;isInTeleportationState()Z")) + private boolean relaxMoveRestrictions(ServerPlayerEntity serverPlayerEntity) + { + return CarpetSettings.antiCheatDisabled || serverPlayerEntity.isInTeleportationState(); + } + + + +} diff --git a/src/main/java/carpet/settings/CarpetSettings.java b/src/main/java/carpet/settings/CarpetSettings.java index 4a14e5f0..5c38ea71 100644 --- a/src/main/java/carpet/settings/CarpetSettings.java +++ b/src/main/java/carpet/settings/CarpetSettings.java @@ -9,7 +9,9 @@ import net.minecraft.server.world.ChunkTicketType; import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Unit; +import net.minecraft.util.math.Box; import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.dimension.DimensionType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -28,12 +30,13 @@ public class CarpetSettings public static final Logger LOG = LogManager.getLogger(); public static boolean skipGenerationChecks = false; public static boolean impendingFillSkipUpdates = false; + public static Box currentTelepotingEntityBox = null; + public static Vec3d fixedPosition = null; @Rule( desc = "Nether portals correctly place entities going through", extra = "Entities shouldn't suffocate in obsidian", - category = BUGFIX, - validate = Validator.WIP.class + category = BUGFIX ) public static boolean portalSuffocationFix = false; @@ -109,11 +112,10 @@ public class CarpetSettings @Rule( desc = "Prevents players from rubberbanding when moving too fast", - extra = "Puts more trust in clients positioning", - category = {CREATIVE, SURVIVAL}, - validate = Validator.WIP.class + extra = {"... or being kicked out for 'flying'","Puts more trust in clients positioning"}, + category = {CREATIVE, SURVIVAL} ) - public static boolean antiCheatSpeed = false; + public static boolean antiCheatDisabled = false; @Rule(desc = "Pistons, droppers and dispensers react if block above them is powered", category = CREATIVE) public static boolean quasiConnectivity = true; diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index c9ab03c2..1d86b2fa 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -69,9 +69,14 @@ "ItemUsageContext_cactusMixin", "DispenserBehaviour_cactusMixin", + "ServerPlayNetworkHandler_antiCheatSpeedMixin", + "PortalForcer_portalCachingMixin", "PortalBlock_portalCachingMixin", + "Entity_portalSuffocationMixin", + "PortalForcer_portalSuffocationMixin", + "HopperBlockEntityMixin", "ContainerMixin", "ClientConnectionMixin",