diff --git a/build.gradle b/build.gradle index f80401d..881ea1d 100644 --- a/build.gradle +++ b/build.gradle @@ -122,6 +122,7 @@ subprojects { } configurations { + lwjglAgent lwjglAgent.extendsFrom runtimeOnly // see pb-api build.gradle, these need to be on the classpath when building our JavaDoc @@ -433,7 +434,7 @@ afterEvaluate { ? '' : System.getenv('GITHUB_RUN_NUMBER') != null && System.getenv('GITHUB_SHA') != null ? "-${System.getenv('GITHUB_RUN_NUMBER')}-${System.getenv('GITHUB_SHA').substring(0, 7)}" - : '-local' + : '' publishing { publications { "$project.name"(MavenPublication) { diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/event/render/ParticleEvent.java b/pb-api/src/main/java/me/earth/pingbypass/api/event/render/ParticleEvent.java deleted file mode 100644 index 8e9f4e3..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/event/render/ParticleEvent.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.earth.pingbypass.api.event.render; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import me.earth.pingbypass.api.event.event.CancellableEvent; -import net.minecraft.core.particles.ParticleType; - -@Getter -@RequiredArgsConstructor -public class ParticleEvent extends CancellableEvent { - private final ParticleType type; - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/launch/SideLaunchingPlugin.java b/pb-api/src/main/java/me/earth/pingbypass/api/launch/SideLaunchingPlugin.java index a33fdd8..ef98083 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/launch/SideLaunchingPlugin.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/launch/SideLaunchingPlugin.java @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Launches {@link Side#SERVER} and/or {@link Side#CLIENT} if their jar is in the "pingbypass/plugins" folder. + * Launches {@link Side#SERVER} and/or {@link Side#CLIENT}, or any other Side, if their jar is in the "pingbypass/plugins" folder. */ @Slf4j public class SideLaunchingPlugin implements SimpleMixinConfigPlugin { diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/MixinMinecraft.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/MixinMinecraft.java index 1524b14..b3e6afa 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/MixinMinecraft.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/MixinMinecraft.java @@ -8,7 +8,8 @@ import me.earth.pingbypass.api.event.loop.GameloopEvent; import me.earth.pingbypass.api.event.loop.TickEvent; import me.earth.pingbypass.api.mixins.resource.IPackRepository; -import me.earth.pingbypass.api.module.misc.AutoRespawn; +import me.earth.pingbypass.api.platform.Platform; +import me.earth.pingbypass.api.platform.PlatformProvider; import me.earth.pingbypass.api.resource.PackRepositoryHelper; import me.earth.pingbypass.api.util.mixin.MixinHelper; import net.minecraft.CrashReport; @@ -61,7 +62,9 @@ private int runTickHook(int i) { target = "Lnet/minecraft/client/Minecraft;resourcePackRepository:Lnet/minecraft/server/packs/repository/PackRepository;" /* shift = At.Shift.AFTER is done by the Injection point, because shifting would wrap it */)) private void resourcePackRepositoryHook(GameConfig config, CallbackInfo ci) { - PackRepositoryHelper.addPingBypassRepositorySource(((IPackRepository) resourcePackRepository)); + if (PlatformProvider.getInstance().getCurrent().equals(Platform.FABRIC)) { + PackRepositoryHelper.addPingBypassRepositorySource(((IPackRepository) resourcePackRepository)); + } } @Inject(method = "tick", at = @At("HEAD")) @@ -85,11 +88,6 @@ private void setScreenHook(Screen screen, CallbackInfo ci) { MixinHelper.hook(new GuiScreenEvent<>(screen), screen == null ? null : screen.getClass(), ci); } - @Inject(method = "setScreen", at = @At(value = "NEW", target = "(Lnet/minecraft/network/chat/Component;Z)Lnet/minecraft/client/gui/screens/DeathScreen;"), cancellable = true) - private void deathScreenHook(Screen screen, CallbackInfo ci) { - MixinHelper.hook(new AutoRespawn.DeathScreenEvent(), ci); - } - @Inject(method = "setScreen", at = @At("RETURN")) private void setScreenHookReturn(Screen screen, CallbackInfo ci) { PingBypassApi.getEventBus().post(new GuiScreenEvent.Post<>(screen), screen == null ? null : screen.getClass()); diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/IAbstractClientPlayer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/IAbstractClientPlayer.java new file mode 100644 index 0000000..7affc46 --- /dev/null +++ b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/IAbstractClientPlayer.java @@ -0,0 +1,13 @@ +package me.earth.pingbypass.api.mixins.entity; + +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.client.player.AbstractClientPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(AbstractClientPlayer.class) +public interface IAbstractClientPlayer { + @Invoker("getPlayerInfo") + PlayerInfo invokeGetPlayerInfo(); + +} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/IPlayer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/IPlayer.java deleted file mode 100644 index c7a4a6d..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/IPlayer.java +++ /dev/null @@ -1,15 +0,0 @@ -package me.earth.pingbypass.api.mixins.entity; - -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.world.entity.player.Player; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(Player.class) -public interface IPlayer { - @Accessor("DATA_PLAYER_ABSORPTION_ID") - static EntityDataAccessor getDataPlayerAbsorptionId() { - throw new IllegalStateException("DATA_PLAYER_ABSORPTION_ID accessor has not been mixed in!"); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinAbstractClientPlayer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinAbstractClientPlayer.java deleted file mode 100644 index 6fc7a98..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinAbstractClientPlayer.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.earth.pingbypass.api.mixins.entity; - -import me.earth.pingbypass.PingBypassApi; -import me.earth.pingbypass.api.module.render.NoRender; -import net.minecraft.client.player.AbstractClientPlayer; -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; - -@Mixin(AbstractClientPlayer.class) -public abstract class MixinAbstractClientPlayer { - @Inject(method = "getFieldOfViewModifier", at = @At("HEAD"), cancellable = true) - private void getFieldOfViewModifierHook(CallbackInfoReturnable cir) { - NoRender.Fov event = new NoRender.Fov(); - PingBypassApi.getEventBus().post(event); - if (event.isCancelled()) { - cir.setReturnValue(1.0f); - } - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinEntity.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinEntity.java deleted file mode 100644 index dc83136..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.earth.pingbypass.api.mixins.entity; - -import me.earth.pingbypass.api.module.movement.Velocity; -import me.earth.pingbypass.api.util.mixin.MixinHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.Entity; -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.util.Objects; - -@Mixin(Entity.class) -public abstract class MixinEntity { - // not great since it prevents us from pushing entities in SinglePlayer, but at least no @Redirect - @Inject( - method = "push(Lnet/minecraft/world/entity/Entity;)V", - at = @At(value = "INVOKE", target = "Ljava/lang/Math;sqrt(D)D", shift = At.Shift.BEFORE), - cancellable = true) - private void entityPushHook(Entity entity, CallbackInfo ci) { - //noinspection EqualsBetweenInconvertibleTypes - if (Objects.equals(this, Minecraft.getInstance().player) || Objects.equals(entity, Minecraft.getInstance().player)) { - MixinHelper.hook(new Velocity.EntityPush(), ci); - } - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinLocalPlayer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinLocalPlayer.java index 53b8c81..d6241ff 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinLocalPlayer.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/entity/MixinLocalPlayer.java @@ -2,8 +2,6 @@ import me.earth.pingbypass.PingBypassApi; import me.earth.pingbypass.api.event.loop.LocalPlayerUpdateEvent; -import me.earth.pingbypass.api.module.movement.Velocity; -import me.earth.pingbypass.api.util.mixin.MixinHelper; import net.minecraft.client.player.LocalPlayer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -22,9 +20,4 @@ private void tickHook(CallbackInfo ci) { PingBypassApi.getEventBus().post(new LocalPlayerUpdateEvent(LocalPlayer.class.cast(this))); } - @Inject(method = "moveTowardsClosestSpace", at = @At("HEAD"), cancellable = true) - private void moveTowardsClosestSpaceHook(double d, double e, CallbackInfo ci) { - MixinHelper.hook(new Velocity.PushOutOfBlocks(), ci); - } - } diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinCamera.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinCamera.java deleted file mode 100644 index 4d56ade..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinCamera.java +++ /dev/null @@ -1,24 +0,0 @@ -package me.earth.pingbypass.api.mixins.render; - -import me.earth.pingbypass.PingBypassApi; -import me.earth.pingbypass.api.event.event.CancellableEvent; -import me.earth.pingbypass.api.module.render.NoRender; -import net.minecraft.client.Camera; -import net.minecraft.world.level.material.FogType; -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; - -@Mixin(Camera.class) -public abstract class MixinCamera { - @Inject(method = "getFluidInCamera", at = @At("HEAD"), cancellable = true) - private void getFluidInCameraHook(CallbackInfoReturnable cir) { - CancellableEvent event = new NoRender.Liquids(); - PingBypassApi.getEventBus().post(event); - if (event.isCancelled()) { - cir.setReturnValue(FogType.NONE); - } - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinGameRenderer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinGameRenderer.java deleted file mode 100644 index 6779833..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinGameRenderer.java +++ /dev/null @@ -1,33 +0,0 @@ -package me.earth.pingbypass.api.mixins.render; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.earth.pingbypass.api.module.render.NoRender; -import me.earth.pingbypass.api.util.mixin.MixinHelper; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -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; - -@Mixin(GameRenderer.class) -public abstract class MixinGameRenderer { - @Inject(method = "displayItemActivation", at = @At("HEAD"), cancellable = true) - private void displayItemActivationHook(ItemStack arg, CallbackInfo ci) { - if (arg != null && arg.getItem() == Items.TOTEM_OF_UNDYING) { - MixinHelper.hook(new NoRender.Totems(), ci); - } - } - - @Inject(method = "bobHurt", at = @At("HEAD"), cancellable = true) - private void bobHurtHook(PoseStack arg, float f, CallbackInfo ci) { - MixinHelper.hook(new NoRender.Hurt(), ci); - } - - @Inject(method = "bobView", at = @At("HEAD"), cancellable = true) - private void bobViewHook(PoseStack arg, float f, CallbackInfo ci) { - MixinHelper.hook(new NoRender.Bob(), ci); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinLevelRenderer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinLevelRenderer.java deleted file mode 100644 index c33c971..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinLevelRenderer.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.earth.pingbypass.api.mixins.render; - -import me.earth.pingbypass.api.event.render.ParticleEvent; -import me.earth.pingbypass.api.util.mixin.MixinHelper; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.core.particles.ParticleOptions; -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; - -@Mixin(LevelRenderer.class) -public abstract class MixinLevelRenderer { - @Inject( - method = "addParticleInternal(Lnet/minecraft/core/particles/ParticleOptions;ZZDDDDDD)Lnet/minecraft/client/particle/Particle;", - at = @At("HEAD"), - cancellable = true) - private void addParticleInternalHook(ParticleOptions options, boolean force, boolean decreased, double x, double y, - double z, double xSpeed, double ySpeed, double zSpeed, - CallbackInfoReturnable cir) { - MixinHelper.hook(new ParticleEvent(options.getType()), cir); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinLightTexture.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinLightTexture.java deleted file mode 100644 index 5af8d1f..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinLightTexture.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.earth.pingbypass.api.mixins.render; - -import me.earth.pingbypass.PingBypassApi; -import me.earth.pingbypass.api.module.render.Fullbright; -import net.minecraft.client.renderer.LightTexture; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -@Mixin(LightTexture.class) -public abstract class MixinLightTexture { - // TODO: @ModifyArgs crashes runClientForge - @ModifyArg( - method = "updateLightTexture", - at = @At( - value = "INVOKE", - target = "Lcom/mojang/blaze3d/platform/NativeImage;setPixelRGBA(III)V"), - index = 2) - private int colorHook(int color) { - Fullbright.LightTextureEvent event = new Fullbright.LightTextureEvent(color); - PingBypassApi.getEventBus().post(event); - return event.getColor(); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinScreenEffectRenderer.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinScreenEffectRenderer.java deleted file mode 100644 index cf38161..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinScreenEffectRenderer.java +++ /dev/null @@ -1,31 +0,0 @@ -package me.earth.pingbypass.api.mixins.render; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.earth.pingbypass.api.module.render.NoRender; -import me.earth.pingbypass.api.util.mixin.MixinHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ScreenEffectRenderer; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -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; - -@Mixin(ScreenEffectRenderer.class) -public abstract class MixinScreenEffectRenderer { - @Inject(method = "renderFire", at = @At("HEAD"), cancellable = true) - private static void renderFireHook(Minecraft arg, PoseStack arg2, CallbackInfo ci) { - MixinHelper.hook(new NoRender.Fire(), ci); - } - - @Inject(method = "renderWater", at = @At("HEAD"), cancellable = true) - private static void renderTexHook(Minecraft arg, PoseStack arg2, CallbackInfo ci) { - MixinHelper.hook(new NoRender.Liquids(), ci); - } - - @Inject(method = "renderTex", at = @At("HEAD"), cancellable = true) - private static void renderTexHook(TextureAtlasSprite arg, PoseStack arg2, CallbackInfo ci) { - MixinHelper.hook(new NoRender.Blocks(), ci); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinSkylightEngine.java b/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinSkylightEngine.java deleted file mode 100644 index ba021b3..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/mixins/render/MixinSkylightEngine.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.earth.pingbypass.api.mixins.render; - -import me.earth.pingbypass.api.module.render.NoRender; -import me.earth.pingbypass.api.util.mixin.MixinHelper; -import net.minecraft.world.level.lighting.SkyLightEngine; -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; - -@Mixin(SkyLightEngine.class) -public abstract class MixinSkylightEngine { - @Inject(method = "propagateIncrease", at = @At("HEAD"), cancellable = true) - private void checkNeighborsAfterUpdateHook(long l, long m, int i, CallbackInfo ci) { - MixinHelper.hook(new NoRender.Skylight(), ci); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/module/CommonModuleInitializer.java b/pb-api/src/main/java/me/earth/pingbypass/api/module/CommonModuleInitializer.java index 1369b26..07d398c 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/module/CommonModuleInitializer.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/module/CommonModuleInitializer.java @@ -1,27 +1,12 @@ package me.earth.pingbypass.api.module; import me.earth.pingbypass.PingBypass; -import me.earth.pingbypass.api.module.ModuleManager; import me.earth.pingbypass.api.module.client.Notifications; -import me.earth.pingbypass.api.module.misc.AutoRespawn; -import me.earth.pingbypass.api.module.misc.Potions; -import me.earth.pingbypass.api.module.movement.Velocity; -import me.earth.pingbypass.api.module.render.Fullbright; -import me.earth.pingbypass.api.module.render.NoRender; public interface CommonModuleInitializer { default void registerCommonModules(PingBypass pb) { ModuleManager modules = pb.getModuleManager(); - modules.register(new Notifications(pb)); - - modules.register(new AutoRespawn(pb)); - modules.register(new Potions(pb)); - - modules.register(new Velocity(pb)); - - modules.register(new Fullbright(pb)); - modules.register(new NoRender(pb)); } } diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/module/misc/AutoRespawn.java b/pb-api/src/main/java/me/earth/pingbypass/api/module/misc/AutoRespawn.java deleted file mode 100644 index dcf722d..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/module/misc/AutoRespawn.java +++ /dev/null @@ -1,39 +0,0 @@ -package me.earth.pingbypass.api.module.misc; - -import me.earth.pingbypass.PingBypass; -import me.earth.pingbypass.api.event.event.CancellableEvent; -import me.earth.pingbypass.api.event.listeners.generic.Listener; -import me.earth.pingbypass.api.module.impl.Categories; -import me.earth.pingbypass.api.module.impl.ModuleImpl; -import me.earth.pingbypass.api.event.gui.GuiScreenEvent; -import net.minecraft.client.gui.screens.DeathScreen; - -public class AutoRespawn extends ModuleImpl { - public AutoRespawn(PingBypass pingBypass) { - super(pingBypass, "AutoRespawn", Categories.MISC, "Automatically respawns you when you die."); - listen(new Listener>() { - @Override - public void onEvent(GuiScreenEvent event) { - respawn(event); - } - }); - - listen(new Listener() { - @Override - public void onEvent(DeathScreenEvent event) { - respawn(event); - } - }); - } - - private void respawn(CancellableEvent event) { - if (mc.player != null) { - mc.player.respawn(); - } - - event.setCancelled(true); - } - - public static final class DeathScreenEvent extends CancellableEvent { } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/module/misc/Potions.java b/pb-api/src/main/java/me/earth/pingbypass/api/module/misc/Potions.java deleted file mode 100644 index 3b99dbf..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/module/misc/Potions.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.earth.pingbypass.api.module.misc; - -import me.earth.pingbypass.PingBypass; -import me.earth.pingbypass.api.module.impl.Categories; -import me.earth.pingbypass.api.module.impl.ModuleImpl; -import me.earth.pingbypass.api.setting.Setting; -import me.earth.pingbypass.api.event.network.PacketEvent; -import me.earth.pingbypass.api.event.network.PostListener; -import me.earth.pingbypass.api.event.network.ReceiveListener; -import me.earth.pingbypass.api.mixins.entity.IPlayer; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.EntityEvent; -import net.minecraft.world.entity.player.Player; - -public class Potions extends ModuleImpl { - private final Setting goldenApples = bool("GoldenApples", true, "More accurate damage calculations by tracking golden apples eaten by players."); - - public Potions(PingBypass pingBypass) { - super(pingBypass, "Potions", Categories.MISC, "Tweaks for potions and their effects."); - // see 3arthh4ck managers.minecraft.combat.PotionService, allows us to make better Damage calculations - listen(new PostListener.Safe.Direct(mc) { - @Override - public void onSafePacket(ClientboundEntityEventPacket packet, LocalPlayer localPlayer, ClientLevel level, MultiPlayerGameMode gameMode) { - if (goldenApples.getValue() && packet.getEventId() == EntityEvent.TALISMAN_ACTIVATE && packet.getEntity(level) instanceof Player player && player != localPlayer) { - player.getActiveEffectsMap().clear(); - player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 900, 1)); - player.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 100, 1)); - } - } - }); - - listen(new ReceiveListener.Scheduled.Safe(mc) { - @Override - public void onSafeEvent(PacketEvent.Receive event, LocalPlayer localPlayer, ClientLevel level, MultiPlayerGameMode gameMode) { - if (goldenApples.getValue() && level.getEntity(event.getPacket().id()) instanceof Player player && player != localPlayer) { - for (SynchedEntityData.DataValue value : event.getPacket().packedItems()) { - if (value.id() == IPlayer.getDataPlayerAbsorptionId().getId() && value.value() instanceof Float absorptionAmount) { - float previousAbsorptionAmount = player.getAbsorptionAmount(); - if (absorptionAmount == 4.0f && previousAbsorptionAmount < absorptionAmount) { // normal Golden Apple - player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 100, 1)); - player.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 0)); - } else if (absorptionAmount == 16.0f) { // Enchanted Golden Apple - player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 400, 1)); - player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 6000, 0)); - player.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 3)); - } // sadly no way to detect normal apple on top of enchanted one I think - } - } - } - } - }); - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/module/movement/Velocity.java b/pb-api/src/main/java/me/earth/pingbypass/api/module/movement/Velocity.java deleted file mode 100644 index 142a12d..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/module/movement/Velocity.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.earth.pingbypass.api.module.movement; - -import me.earth.pingbypass.PingBypass; -import me.earth.pingbypass.api.event.event.CancellableEvent; -import me.earth.pingbypass.api.event.listeners.generic.Listener; -import me.earth.pingbypass.api.module.impl.Categories; -import me.earth.pingbypass.api.module.impl.ModuleImpl; -import me.earth.pingbypass.api.event.CancellingListener; -import me.earth.pingbypass.api.event.network.AsyncReceiveListener; -import me.earth.pingbypass.api.event.network.PacketEvent; -import me.earth.pingbypass.api.mixins.network.s2c.IClientBoundExplodePacket; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.network.protocol.game.ClientboundExplodePacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; - -public class Velocity extends ModuleImpl { - public Velocity(PingBypass pingBypass) { - super(pingBypass, "Velocity", Categories.MOVEMENT, "Prevents knockback."); - listen(new AsyncReceiveListener(mc) { - @Override - public void onEvent(PacketEvent.Receive e, LocalPlayer p, ClientLevel ignore, MultiPlayerGameMode ignored) { - if (e.getPacket().getId() == p.getId()) { - e.setCancelled(true); - } - } - }); - - listen(new Listener>() { - @Override - public void onEvent(PacketEvent.Receive event) { - IClientBoundExplodePacket explodePacket = ((IClientBoundExplodePacket) event.getPacket()); - explodePacket.setKnockbackX(0.0f); - explodePacket.setKnockbackY(0.0f); - explodePacket.setKnockbackZ(0.0f); - } - }); - - listen(new CancellingListener.WithSetting<>(PushOutOfBlocks.class, bool("Blocks", true, "Prevents you from getting pushed out of blocks."))); - listen(new CancellingListener.WithSetting<>(EntityPush.class, bool("Entities", true, "Prevents you from getting pushed by entities."))); - } - - public static final class PushOutOfBlocks extends CancellableEvent {} - public static final class EntityPush extends CancellableEvent {} - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/module/render/Fullbright.java b/pb-api/src/main/java/me/earth/pingbypass/api/module/render/Fullbright.java deleted file mode 100644 index d0808a7..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/module/render/Fullbright.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.earth.pingbypass.api.module.render; - -import lombok.AllArgsConstructor; -import lombok.Data; -import me.earth.pingbypass.PingBypass; -import me.earth.pingbypass.api.event.listeners.generic.Listener; -import me.earth.pingbypass.api.module.impl.Categories; -import me.earth.pingbypass.api.module.impl.ModuleImpl; - -public class Fullbright extends ModuleImpl { - public Fullbright(PingBypass pingBypass) { - super(pingBypass, "Fullbright", Categories.RENDER, "Makes the game as bright as possible"); - listen(new Listener() { - @Override - public void onEvent(LightTextureEvent event) { - event.setColor(0xFFFFFFFF); - } - }); - } - - @Data - @AllArgsConstructor - public static class LightTextureEvent { - private int color; - } - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/module/render/NoRender.java b/pb-api/src/main/java/me/earth/pingbypass/api/module/render/NoRender.java deleted file mode 100644 index aab9f65..0000000 --- a/pb-api/src/main/java/me/earth/pingbypass/api/module/render/NoRender.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.earth.pingbypass.api.module.render; - -import me.earth.pingbypass.PingBypass; -import me.earth.pingbypass.api.event.event.CancellableEvent; -import me.earth.pingbypass.api.event.listeners.generic.Listener; -import me.earth.pingbypass.api.module.impl.Categories; -import me.earth.pingbypass.api.module.impl.ModuleImpl; -import me.earth.pingbypass.api.setting.Setting; -import me.earth.pingbypass.api.event.CancellingListener; -import me.earth.pingbypass.api.event.render.ParticleEvent; -import net.minecraft.core.particles.ParticleTypes; - -public class NoRender extends ModuleImpl { - public NoRender(PingBypass pingBypass) { - super(pingBypass, "NoRender", Categories.RENDER, "Disables certain animations."); - register("Fire", "Prevents fire from rendering.", Fire.class); - register("Totems", "Stops the totem animation.", Totems.class); - register("Blocks", "Prevents the block overlay from rendering.", Blocks.class); - register("Skylight", "Prevents Skylight updates.", Skylight.class); - register("Liquids", "Prevents the liquid overlay from rendering.", Liquids.class); - register("Hurtcam", "Stops your screen from shaking when you are hurt.", Hurt.class); - register("Bob", "Stops your screen from bobbing when you move.", Bob.class); - register("Fov", "Stops all effects changing your FOV.", Fov.class); - Setting explosions = bool("Explosions", true, "Removes explosion particles."); - Setting particles = bool("Particles", false, "Removes all particles."); - listen(new Listener() { - @Override - public void onEvent(ParticleEvent event) { - if (particles.getValue() || explosions.getValue() && (event.getType().equals(ParticleTypes.EXPLOSION) || event.getType().equals(ParticleTypes.EXPLOSION_EMITTER))) { - event.setCancelled(true); - } - } - }); - } - - private void register(String name, String description, Class eventType) { - Setting setting = bool(name, true, description); - listen(new CancellingListener.WithSetting<>(eventType, setting)); - } - - public static final class Fire extends CancellableEvent {} - public static final class Totems extends CancellableEvent {} - public static final class Skylight extends CancellableEvent {} - public static final class Blocks extends CancellableEvent {} - public static final class Liquids extends CancellableEvent {} - public static final class Hurt extends CancellableEvent {} - public static final class Bob extends CancellableEvent {} - public static final class Fov extends CancellableEvent {} - -} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/Handler.java b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolHandler.java similarity index 95% rename from pb-api/src/main/java/me/earth/pingbypass/api/protocol/Handler.java rename to pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolHandler.java index afa00da..3c628c5 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/Handler.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolHandler.java @@ -8,7 +8,7 @@ import net.minecraft.network.Connection; import net.minecraft.network.protocol.Packet; -public interface Handler> { +public interface ProtocolHandler> { default void handle(T packet, PingBypass pingBypass, Connection connection) { NullabilityUtil.safe(pingBypass.getMinecraft(), ((player, level, gameMode) -> handle(packet, pingBypass, connection, player, level, gameMode))); } diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolManager.java b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolManager.java index e4e85bd..b7f719a 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolManager.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/ProtocolManager.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import me.earth.pingbypass.PingBypass; +import me.earth.pingbypass.api.Constants; import me.earth.pingbypass.api.event.SubscriberImpl; import net.minecraft.network.Connection; import net.minecraft.network.FriendlyByteBuf; @@ -14,7 +15,7 @@ @RequiredArgsConstructor public class ProtocolManager extends SubscriberImpl { - public static final DiscardedPayload PAYLOAD = new DiscardedPayload(new ResourceLocation("pingbypass", "processed")); + public static final DiscardedPayload PAYLOAD = new DiscardedPayload(new ResourceLocation(Constants.NAME_LOW, "processed")); private final Map> factories = new ConcurrentHashMap<>(); private final PingBypass pingBypass; @@ -24,8 +25,8 @@ public void register(ResourceLocation location, FriendlyByt } @SuppressWarnings("unchecked") - public void register(ResourceLocation location, FriendlyByteBuf.Reader factory, @Nullable Handler handler) { - factories.put(location, new PacketHandler<>((FriendlyByteBuf.Reader) factory, (Handler) handler)); + public void register(ResourceLocation location, FriendlyByteBuf.Reader factory, @Nullable ProtocolHandler handler) { + factories.put(location, new PacketHandler<>((FriendlyByteBuf.Reader) factory, (ProtocolHandler) handler)); } public @Nullable PBPacket handle(ResourceLocation location, FriendlyByteBuf buf) { @@ -48,11 +49,11 @@ public boolean handle(Connection connection, T packet) { return false; } - private record PacketHandler(FriendlyByteBuf.Reader factory, @Nullable Handler handler) { + private record PacketHandler(FriendlyByteBuf.Reader factory, @Nullable ProtocolHandler handler) { public void handle(T packet, PingBypass pingBypass, Connection connection) { if (handler != null) { handler.handle(packet, pingBypass, connection); - } else if (packet instanceof Handler.SelfHandling selfHandling) { + } else if (packet instanceof ProtocolHandler.SelfHandling selfHandling) { selfHandling.handle(pingBypass, connection); } } diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/c2s/C2SNoMovementUpdate.java b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/c2s/C2SNoMovementUpdate.java index b17ffcf..a876321 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/c2s/C2SNoMovementUpdate.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/c2s/C2SNoMovementUpdate.java @@ -1,14 +1,15 @@ package me.earth.pingbypass.api.protocol.c2s; +import me.earth.pingbypass.api.Constants; import me.earth.pingbypass.api.protocol.C2SPacket; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; /** - * Send when instead of a {@link net.minecraft.network.protocol.game.ServerboundMovePlayerPacket}, if the client does not want to. + * Send instead of a {@link net.minecraft.network.protocol.game.ServerboundMovePlayerPacket}, if the client has ran a tick but not changed its position. */ public class C2SNoMovementUpdate implements C2SPacket { - public static final ResourceLocation ID = new ResourceLocation("pingbypass", "no-movement-update"); + public static final ResourceLocation ID = new ResourceLocation(Constants.NAME_LOW, "no-movement-update"); @Override public ResourceLocation getId() { diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/protocol/s2c/S2CGameProfilePacket.java b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/s2c/S2CGameProfilePacket.java new file mode 100644 index 0000000..731b86f --- /dev/null +++ b/pb-api/src/main/java/me/earth/pingbypass/api/protocol/s2c/S2CGameProfilePacket.java @@ -0,0 +1,4 @@ +package me.earth.pingbypass.api.protocol.s2c; + +public class S2CGameProfilePacket { +} diff --git a/pb-api/src/main/java/me/earth/pingbypass/api/util/PingUtil.java b/pb-api/src/main/java/me/earth/pingbypass/api/util/PingUtil.java index 1b4358f..d9f89fc 100644 --- a/pb-api/src/main/java/me/earth/pingbypass/api/util/PingUtil.java +++ b/pb-api/src/main/java/me/earth/pingbypass/api/util/PingUtil.java @@ -1,10 +1,25 @@ package me.earth.pingbypass.api.util; import lombok.experimental.UtilityClass; +import me.earth.pingbypass.api.mixins.entity.IAbstractClientPlayer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.world.entity.player.Player; @UtilityClass public class PingUtil { - public int getPing() { + public int getPing(Minecraft mc) { + return getPing(mc.player); + } + + public int getPing(Player player) { + if (player instanceof IAbstractClientPlayer iAbstractClientPlayer) { + PlayerInfo playerInfo = iAbstractClientPlayer.invokeGetPlayerInfo(); + if (playerInfo != null) { + return playerInfo.getLatency(); + } + } + return 0; } diff --git a/pb-api/src/main/resources/mixins.pingbypass.json b/pb-api/src/main/resources/mixins.pingbypass.json index d0f25b8..1bc93bb 100644 --- a/pb-api/src/main/resources/mixins.pingbypass.json +++ b/pb-api/src/main/resources/mixins.pingbypass.json @@ -8,8 +8,6 @@ "maxShiftBy": 10 }, "mixins": [ - "entity.IPlayer", - "entity.MixinEntity", "network.IPacketSet", "network.MixinConnection", "network.MixinConnectionProtocol", @@ -17,23 +15,17 @@ "network.c2s.MixinServerboundCustomPayloadPacket", "network.s2c.IClientBoundExplodePacket", "network.s2c.MixinClientboundCustomPayloadPacket", - "render.MixinSkylightEngine", "resource.IPackRepository" ], "client": [ "MixinMinecraft", - "entity.MixinAbstractClientPlayer", + "entity.IAbstractClientPlayer", "entity.MixinLocalPlayer", "gui.IScreen", "gui.MixinChatComponent", "gui.MixinCommandSuggestions", "gui.MixinTitleScreen", "network.MixinClientPacketListener", - "network.MixinPacketEncoder", - "render.MixinCamera", - "render.MixinGameRenderer", - "render.MixinLevelRenderer", - "render.MixinLightTexture", - "render.MixinScreenEffectRenderer" + "network.MixinPacketEncoder" ] } diff --git a/pb-api/src/neoforge/resources/META-INF/mods.toml b/pb-api/src/neoforge/resources/META-INF/mods.toml index b82270f..9d4f841 100644 --- a/pb-api/src/neoforge/resources/META-INF/mods.toml +++ b/pb-api/src/neoforge/resources/META-INF/mods.toml @@ -1,6 +1,6 @@ -modLoader="javafml" -loaderVersion="[48,)" -issueTrackerURL="https://github.com/3arthqu4ke/pingbypass" +modLoader = "javafml" +loaderVersion = "[1,)" +issueTrackerURL = "https://github.com/3arthqu4ke/pingbypass" license = "MIT" [[mods]] @@ -11,8 +11,8 @@ authors = "3arthqu4ke" description = "The PingBypass API" [[dependencies.pingbypass]] - modId="minecraft" - mandatory=true - versionRange="[1.20.4]" - ordering="NONE" - side="CLIENT" \ No newline at end of file +modId = "minecraft" +mandatory = true +versionRange = "[1.20.4]" +ordering = "NONE" +side = "CLIENT" \ No newline at end of file diff --git a/pb-api/src/test/java/me/earth/pingbypass/api/protocol/ProtocolManagerTest.java b/pb-api/src/test/java/me/earth/pingbypass/api/protocol/ProtocolManagerTest.java index 2bc3bc5..063cc8f 100644 --- a/pb-api/src/test/java/me/earth/pingbypass/api/protocol/ProtocolManagerTest.java +++ b/pb-api/src/test/java/me/earth/pingbypass/api/protocol/ProtocolManagerTest.java @@ -47,7 +47,7 @@ public void testProtocolManager() { } @RequiredArgsConstructor - private static final class TestPacket implements C2SPacket, Handler.SelfHandling { + private static final class TestPacket implements C2SPacket, ProtocolHandler.SelfHandling { private final int id; public TestPacket(FriendlyByteBuf buf) { diff --git a/pb-client/src/neoforge/resources/META-INF/mods.toml b/pb-client/src/neoforge/resources/META-INF/mods.toml index f958e5a..0e2cd0d 100644 --- a/pb-client/src/neoforge/resources/META-INF/mods.toml +++ b/pb-client/src/neoforge/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[48,)" +loaderVersion = "[1,)" issueTrackerURL = "https://github.com/3arthqu4ke/pingbypass" license = "MIT" diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/commands/ConnectCommand.java b/pb-server/src/main/java/me/earth/pingbypass/server/commands/ConnectCommand.java index 313b1e2..3d9691f 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/commands/ConnectCommand.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/commands/ConnectCommand.java @@ -3,19 +3,23 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import lombok.extern.slf4j.Slf4j; import me.earth.pingbypass.server.PingBypassServer; import me.earth.pingbypass.server.commands.api.AbstractServerCommand; import me.earth.pingbypass.server.commands.api.ServerCommandSource; +import me.earth.pingbypass.server.handlers.play.GameProfileTranslation; import me.earth.pingbypass.server.handlers.play.JoinWorldService; import me.earth.pingbypass.server.handlers.play.PlayPacketHandler; import me.earth.pingbypass.server.session.Session; import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.MultiPlayerGameMode; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; +@Slf4j public class ConnectCommand extends AbstractServerCommand { public ConnectCommand(PingBypassServer server) { super(server, "connect", "Connects PingBypass to a server"); @@ -32,8 +36,9 @@ public void build(LiteralArgumentBuilder builder) { if (player != null && level != null && gameMode != null) { session.getPipeline().lock(); // TODO: when is the best time to allow proxying packets from client to server? - session.setListener(new PlayPacketHandler(server, session, session.getCookie())); + session.addSubscriber(new GameProfileTranslation(session)); session.subscribe(); + session.setListener(new PlayPacketHandler(server, session, session.getCookie())); new JoinWorldService().join(session, player, gameMode, level); session.getPipeline().unlockAndFlush(); } else { diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/ConfigurationPacketListener.java b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/ConfigurationPacketListener.java index 8c2baee..a9d9cd7 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/ConfigurationPacketListener.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/ConfigurationPacketListener.java @@ -125,8 +125,8 @@ public void handleConfigurationFinished(ServerboundFinishConfigurationPacket pac lv.placeNewPlayer(session, lv3, this.createCookie(this.clientInformation)); session.resumeInboundAfterProtocolChange();*/ CommonListenerCookie cookie = this.createCookie(Objects.requireNonNull(this.clientInformation)); - session.setListener(new ConfigWorldPacketHandler(server, session, cookie)); session.setCookie(cookie); + session.setListener(new ConfigWorldPacketHandler(server, session, cookie)); new ConfigWorld(server, session).placeNewPlayer(cookie); session.resumeInboundAfterProtocolChange(); } catch (Exception e) { diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/GameProfileTranslation.java b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/GameProfileTranslation.java new file mode 100644 index 0000000..b833b11 --- /dev/null +++ b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/GameProfileTranslation.java @@ -0,0 +1,80 @@ +package me.earth.pingbypass.server.handlers.play; + +import lombok.extern.slf4j.Slf4j; +import me.earth.pingbypass.api.event.SubscriberImpl; +import me.earth.pingbypass.api.event.listeners.generic.Listener; +import me.earth.pingbypass.api.mixins.entity.IAbstractClientPlayer; +import me.earth.pingbypass.api.protocol.s2c.S2CGameProfilePacket; +import me.earth.pingbypass.server.mixins.network.IClientboundPlayerInfoUpdatePacket; +import me.earth.pingbypass.server.session.Session; +import net.minecraft.client.multiplayer.CommonListenerCookie; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * After the login process the GameProfile sent by the server will have been set immutably on the client, + * e.g. in a {@link CommonListenerCookie}. + * So we could land in a situation where we are playing with a different GameProfile on the PingBypassServer than on the Client. + * This is problematic because some stuff, like {@link AbstractClientPlayer#isSpectator()} depends on it. + * We can send a {@link S2CGameProfilePacket} to the client, or translate all packets containing our GameProfile to contain the client GameProfile instead. + */ +@Slf4j +public class GameProfileTranslation extends SubscriberImpl { + public GameProfileTranslation(Session session) { + listen(new Listener>() { + @Override + public void onEvent(PipelineEvent event) { + if (event.getSession() != session) { + return; + } + + event.setPacket(translate(session, event.getOriginal())); + } + }); + } + + public ClientboundPlayerInfoUpdatePacket translate(Session session, ClientboundPlayerInfoUpdatePacket packet) { + LocalPlayer player; + PlayerInfo playerInfo; + if ((player = session.getServer().getMinecraft().player) == null || (playerInfo = ((IAbstractClientPlayer) player).invokeGetPlayerInfo()) == null) { + return packet; + } + + for (ClientboundPlayerInfoUpdatePacket.Entry entry : packet.entries()) { + if (playerInfo.getProfile().getId().equals(entry.profileId())) { + return replace(session, packet, playerInfo); + } + } + + return packet; + } + + private ClientboundPlayerInfoUpdatePacket replace(Session session, ClientboundPlayerInfoUpdatePacket original, PlayerInfo playerInfo) { + var list = new ArrayList<>(original.entries()); + for (ClientboundPlayerInfoUpdatePacket.Entry entry : original.entries()) { + if (playerInfo.getProfile().getId().equals(entry.profileId())) { + list.add(new ClientboundPlayerInfoUpdatePacket.Entry( + session.getCookie().gameProfile().getId(), + entry.profile() == null ? null : session.getCookie().gameProfile(), + entry.listed(), + entry.latency(), + entry.gameMode(), + entry.displayName(), + entry.chatSession()) + ); + } else { + list.add(entry); + } + } + + var packet = new ClientboundPlayerInfoUpdatePacket(original.actions(), Collections.emptyList()); + ((IClientboundPlayerInfoUpdatePacket) packet).setEntries(list); + return packet; + } + +} diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/JoinWorldService.java b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/JoinWorldService.java index 30b4cfd..afb0570 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/JoinWorldService.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/JoinWorldService.java @@ -108,7 +108,7 @@ public void join(Session session, LocalPlayer player, MultiPlayerGameMode gameMo ); } - playerInfoUpdatePacketSender.send(session, player.connection, level); + playerInfoUpdatePacketSender.send(session, new GameProfileTranslation(session), player.connection, player, gameMode, level); this.sendLevelInfo(session, level); diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/PipelineEvent.java b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/PipelineEvent.java new file mode 100644 index 0000000..c189bb2 --- /dev/null +++ b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/PipelineEvent.java @@ -0,0 +1,23 @@ +package me.earth.pingbypass.server.handlers.play; + +import lombok.Getter; +import lombok.Setter; +import me.earth.pingbypass.server.session.Session; +import net.minecraft.network.protocol.Packet; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Getter +@Setter +public class PipelineEvent

> { + private final Session session; + private final P original; + private @Nullable Packet packet; + + public PipelineEvent(Session session, @NotNull P packet) { + this.session = session; + this.original = packet; + this.packet = packet; + } + +} diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/S2PB2CPipeline.java b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/S2PB2CPipeline.java index f77de05..a44660b 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/S2PB2CPipeline.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/S2PB2CPipeline.java @@ -37,7 +37,7 @@ public void onEvent(PacketEvent.Receive event) { if (locked.get()) { packets.add(event.getPacket()); } else { - session.send(event.getPacket()); + send(session, event.getPacket()); } } } @@ -55,13 +55,22 @@ public void lock() { @Synchronized("locked") public void unlockAndFlush() { for (Packet packet : packets) { - session.send(packet); + send(session, packet); } packets.clear(); locked.set(false); } + private

> void send(Session session, P packet) { + PipelineEvent

event = new PipelineEvent<>(session, packet); + session.getServer().getEventBus().post(event, packet.getClass()); + Packet packetToSend = event.getPacket(); + if (event.getPacket() != null) { + session.send(packetToSend); + } + } + private void doNotProxy(Class> type) { listen(new AbstractEventListener.Unsafe>(PacketEvent.Receive.class, type) { @Override diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/world/PlayerInfoUpdatePacketSender.java b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/world/PlayerInfoUpdatePacketSender.java index 4f8ea18..ded663b 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/world/PlayerInfoUpdatePacketSender.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/handlers/play/world/PlayerInfoUpdatePacketSender.java @@ -1,8 +1,12 @@ package me.earth.pingbypass.server.handlers.play.world; +import lombok.extern.slf4j.Slf4j; +import me.earth.pingbypass.api.util.PingUtil; +import me.earth.pingbypass.server.handlers.play.GameProfileTranslation; import me.earth.pingbypass.server.mixins.network.IClientboundPlayerInfoUpdatePacket; import me.earth.pingbypass.server.session.Session; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.RemotePlayer; @@ -15,13 +19,16 @@ import java.util.Collections; import java.util.List; +@Slf4j public class PlayerInfoUpdatePacketSender { - public void send(Session session, ClientPacketListener connection, Level level) { + public void send(Session session, GameProfileTranslation translation, ClientPacketListener connection, LocalPlayer localPlayer, MultiPlayerGameMode gameMode, Level level) { + boolean sentToLocalPlayer = false; var packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(Collections.emptyList()); List list = new ArrayList<>(level.players().size()); for (Player player : level.players()) { + boolean isLocalPlayer = player instanceof LocalPlayer; // make sure we do not send FakePlayers - if (player instanceof RemotePlayer || player instanceof LocalPlayer) { + if (isLocalPlayer || player instanceof RemotePlayer) { PlayerInfo info = connection.getPlayerInfo(player.getUUID()); if (info != null) { boolean isListed = connection.getListedOnlinePlayers().contains(info); @@ -37,12 +44,31 @@ public void send(Session session, ClientPacketListener connection, Level level) chatSession == null ? null : chatSession.asData() ) ); + + if (isLocalPlayer) { + sentToLocalPlayer = true; + } } } } + if (!sentToLocalPlayer) { + PlayerInfo playerInfo = localPlayer.connection.getPlayerInfo(localPlayer.getUUID()); + list.add( + new ClientboundPlayerInfoUpdatePacket.Entry( + playerInfo == null ? localPlayer.getUUID() : playerInfo.getProfile().getId(), + playerInfo == null ? localPlayer.getGameProfile() : playerInfo.getProfile(), + playerInfo != null && localPlayer.connection.getListedOnlinePlayers().contains(playerInfo), + PingUtil.getPing(session.getServer().getMinecraft()), + playerInfo == null ? gameMode.getPlayerMode() : playerInfo.getGameMode(), + playerInfo == null ? null : playerInfo.getTabListDisplayName(), + null + ) + ); + } + ((IClientboundPlayerInfoUpdatePacket) packet).setEntries(list); - session.send(packet); + session.send(translation.translate(session, packet)); } } diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/service/ServerStatusService.java b/pb-server/src/main/java/me/earth/pingbypass/server/service/ServerStatusService.java index d4f8a9b..53caaaa 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/service/ServerStatusService.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/service/ServerStatusService.java @@ -68,7 +68,7 @@ public Component getMotd() { .withStyle(ChatFormatting.RED); } - int ping = PingUtil.getPing(); + int ping = PingUtil.getPing(mc); int pos = queueService.getPosition(); if (queueService.isOn2b2t() && pos != -1) { return literal("2b2t.org") diff --git a/pb-server/src/main/java/me/earth/pingbypass/server/session/Session.java b/pb-server/src/main/java/me/earth/pingbypass/server/session/Session.java index b48c12b..36c79ed 100644 --- a/pb-server/src/main/java/me/earth/pingbypass/server/session/Session.java +++ b/pb-server/src/main/java/me/earth/pingbypass/server/session/Session.java @@ -79,15 +79,17 @@ public PacketEvent getReceiveEvent(Packet packet) { @Synchronized("subscribers") public void subscribe() { - for (Subscriber subscriber : subscribers) { - if (!server.getEventBus().isSubscribed(subscriber)) { - server.getEventBus().subscribe(subscriber); + if (isConnected()) { + for (Subscriber subscriber : subscribers) { + if (!server.getEventBus().isSubscribed(subscriber)) { + server.getEventBus().subscribe(subscriber); + } } } } @Synchronized("subscribers") - private void addSubscriber(Subscriber subscriber) { + public void addSubscriber(Subscriber subscriber) { this.subscribers.add(subscriber); } diff --git a/pb-server/src/neoforge/resources/META-INF/mods.toml b/pb-server/src/neoforge/resources/META-INF/mods.toml index 1b11e19..bc4f56d 100644 --- a/pb-server/src/neoforge/resources/META-INF/mods.toml +++ b/pb-server/src/neoforge/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[48,)" +loaderVersion = "[1,)" issueTrackerURL = "https://github.com/3arthqu4ke/pingbypass" license = "MIT"