make ping able to hold all packets
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m39s
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m39s
This commit is contained in:
parent
90f711b567
commit
9d948144b0
4 changed files with 94 additions and 15 deletions
|
@ -9,6 +9,7 @@ import de.com.baseband.client.feature.Feature;
|
||||||
import de.com.baseband.client.feature.Features;
|
import de.com.baseband.client.feature.Features;
|
||||||
import de.com.baseband.client.feature.modules.client.Client;
|
import de.com.baseband.client.feature.modules.client.Client;
|
||||||
import de.com.baseband.client.feature.modules.render.HUD;
|
import de.com.baseband.client.feature.modules.render.HUD;
|
||||||
|
import de.com.baseband.client.mixin.MixinProxy;
|
||||||
import de.com.baseband.client.registry.Configuration;
|
import de.com.baseband.client.registry.Configuration;
|
||||||
import de.com.baseband.client.registry.Updater;
|
import de.com.baseband.client.registry.Updater;
|
||||||
import de.com.baseband.client.util.interact.Chat;
|
import de.com.baseband.client.util.interact.Chat;
|
||||||
|
@ -57,6 +58,7 @@ public class BaseBand {
|
||||||
}
|
}
|
||||||
|
|
||||||
mc = Minecraft.getMinecraft();
|
mc = Minecraft.getMinecraft();
|
||||||
|
MixinProxy.minecraft = mc;
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(STATIC_EVENT_HANDLER);
|
MinecraftForge.EVENT_BUS.register(STATIC_EVENT_HANDLER);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.com.baseband.client.feature.modules.ingame;
|
package de.com.baseband.client.feature.modules.ingame;
|
||||||
|
|
||||||
|
import de.com.baseband.client.BaseBand;
|
||||||
import de.com.baseband.client.event.events.PacketEvent;
|
import de.com.baseband.client.event.events.PacketEvent;
|
||||||
import de.com.baseband.client.feature.Feature;
|
import de.com.baseband.client.feature.Feature;
|
||||||
import de.com.baseband.client.feature.category.Ingame;
|
import de.com.baseband.client.feature.category.Ingame;
|
||||||
|
@ -7,19 +8,33 @@ import de.com.baseband.client.registry.annotation.Config;
|
||||||
import de.com.baseband.client.registry.annotation.Description;
|
import de.com.baseband.client.registry.annotation.Description;
|
||||||
import de.com.baseband.client.registry.annotation.Range;
|
import de.com.baseband.client.registry.annotation.Range;
|
||||||
import net.minecraft.network.play.client.CPacketKeepAlive;
|
import net.minecraft.network.play.client.CPacketKeepAlive;
|
||||||
|
import net.minecraft.network.play.server.SPacketKeepAlive;
|
||||||
|
import net.minecraft.network.Packet;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
@Ingame
|
@Ingame
|
||||||
public class Ping extends Feature {
|
public class Ping extends Feature {
|
||||||
|
|
||||||
PacketHolder holder = null;
|
Queue<PacketHolder> holderSend = new LinkedList<>();
|
||||||
|
Queue<PacketHolder> holderRecv = new LinkedList<>();
|
||||||
|
|
||||||
long totalRecieved = 0;
|
long totalRecieved = 0;
|
||||||
|
long totalSent = 0;
|
||||||
|
|
||||||
@Config("Seconds")
|
@Config("Hold all packets")
|
||||||
@Description("How many seconds to add to your ping.\n" +
|
@Description("Hold all packets, not just ping.\nEnable this to increase your §lreal ping§r.")
|
||||||
|
public boolean holdAll = false;
|
||||||
|
|
||||||
|
@Config("Milliseconds")
|
||||||
|
@Description("How many milliseconds to add to your ping.\n" +
|
||||||
"§lWarning§r: You might get timed out on high settings (Time-out happens at 15 seconds including real ping).")
|
"§lWarning§r: You might get timed out on high settings (Time-out happens at 15 seconds including real ping).")
|
||||||
@Range("0..14")
|
@Range("0..14000")
|
||||||
public int seconds;
|
public int milliseconds;
|
||||||
|
|
||||||
|
Packet<?> allowRecv = null;
|
||||||
|
Packet<?> allowSend = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -28,40 +43,92 @@ public class Ping extends Feature {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEveryTick() {
|
public void onEveryTick() {
|
||||||
meta = seconds + "s: " + totalRecieved + (holder == null ? "" : "§cH§7");
|
meta = milliseconds + "ms: " +
|
||||||
|
(holderSend.isEmpty() ? "-" : "§c" + holderSend.size()) + "↑§f/" +
|
||||||
|
(holderRecv.isEmpty() ? "-" : "§c" + holderRecv.size()) + "↓§7";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
if (mc.player != null && holder != null && holder.passed()) {
|
if(notIngame())
|
||||||
mc.player.connection.sendPacket(holder.packet);
|
return;
|
||||||
holder = null;
|
while (true) {
|
||||||
|
PacketHolder holder = this.holderSend.peek();
|
||||||
|
if(holder == null || !holder.passed())
|
||||||
|
break;
|
||||||
|
this.holderSend.remove();
|
||||||
|
allowSend = holder.packet;
|
||||||
|
mc.player.connection.sendPacket(allowSend);
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
PacketHolder holder = this.holderRecv.peek();
|
||||||
|
if(holder == null || !holder.passed())
|
||||||
|
break;
|
||||||
|
this.holderRecv.remove();
|
||||||
|
allowRecv = holder.packet;
|
||||||
|
try {
|
||||||
|
mc.player.connection.getNetworkManager().channelRead(null, allowRecv);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BaseBand.notifyAll("!! BaseBand encountered a BUG. Please report as soon as possible and include the game log.");
|
||||||
|
new RuntimeException("[BaseBand BUG] Cannot emulate packet read", e).printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
totalRecieved = 0;
|
totalRecieved = 0;
|
||||||
|
totalSent = 0;
|
||||||
|
if(notIngame()) {
|
||||||
|
holderSend.clear();
|
||||||
|
holderRecv.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while(!holderSend.isEmpty()) {
|
||||||
|
allowSend = holderSend.remove().packet;
|
||||||
|
mc.player.connection.sendPacket(allowSend);
|
||||||
|
}
|
||||||
|
while(!holderRecv.isEmpty()) {
|
||||||
|
allowRecv = holderRecv.remove().packet;
|
||||||
|
try {
|
||||||
|
mc.player.connection.getNetworkManager().channelRead(null, allowRecv);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BaseBand.notifyAll("!! BaseBand encountered a BUG. Please report as soon as possible and include the game log.");
|
||||||
|
new RuntimeException("[BaseBand BUG] Cannot emulate packet read", e).printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPacket(PacketEvent.Send e) {
|
public void onPacket(PacketEvent.Send e) {
|
||||||
if (e.getPacket() instanceof CPacketKeepAlive && holder == null) {
|
if(allowSend == e.getPacket())
|
||||||
|
return;
|
||||||
|
if (e.getPacket() instanceof CPacketKeepAlive || holdAll) {
|
||||||
|
totalSent++;
|
||||||
|
holderSend.add(new PacketHolder(e.getPacket(), System.currentTimeMillis()));
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPacket(PacketEvent.Receive e) {
|
||||||
|
if(allowRecv == e.getPacket())
|
||||||
|
return;
|
||||||
|
if (e.getPacket() instanceof SPacketKeepAlive || holdAll) {
|
||||||
totalRecieved++;
|
totalRecieved++;
|
||||||
holder = new PacketHolder((CPacketKeepAlive) e.getPacket(), System.currentTimeMillis());
|
holderRecv.add(new PacketHolder(e.getPacket(), System.currentTimeMillis()));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PacketHolder {
|
public class PacketHolder {
|
||||||
long time;
|
long time;
|
||||||
CPacketKeepAlive packet;
|
Packet<?> packet;
|
||||||
|
|
||||||
public PacketHolder(CPacketKeepAlive packet, long time) {
|
public PacketHolder(Packet<?> packet, long time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.packet = packet;
|
this.packet = packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean passed() {
|
public boolean passed() {
|
||||||
return (System.currentTimeMillis() - time) >= (seconds * 1000L);
|
return (System.currentTimeMillis() - time) >= (milliseconds / 2L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import de.com.baseband.client.util.adapt.FieldFinder;
|
||||||
import de.com.baseband.client.util.net.ScreenshotHelper;
|
import de.com.baseband.client.util.net.ScreenshotHelper;
|
||||||
import de.com.baseband.prod.LoadHandler;
|
import de.com.baseband.prod.LoadHandler;
|
||||||
import de.tudbut.tools.Tools;
|
import de.tudbut.tools.Tools;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.ChatLine;
|
import net.minecraft.client.gui.ChatLine;
|
||||||
import net.minecraft.client.gui.Gui;
|
import net.minecraft.client.gui.Gui;
|
||||||
import net.minecraft.client.multiplayer.WorldClient;
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
@ -43,6 +44,8 @@ public class MixinProxy {
|
||||||
@Unique
|
@Unique
|
||||||
public static final Field FIELD_PITCH = FieldFinder.findUnmarked(CPacketPlayer.class, float.class, 1);
|
public static final Field FIELD_PITCH = FieldFinder.findUnmarked(CPacketPlayer.class, float.class, 1);
|
||||||
|
|
||||||
|
public static Minecraft minecraft;
|
||||||
|
|
||||||
public static void saveScreenshot(int n, int n2, Framebuffer framebuffer) {
|
public static void saveScreenshot(int n, int n2, Framebuffer framebuffer) {
|
||||||
if(!Features.isFeatureEnabled(Client.class))
|
if(!Features.isFeatureEnabled(Client.class))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,21 +4,28 @@ import de.com.baseband.client.mixin.MixinProxy;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(NetworkManager.class)
|
@Mixin(NetworkManager.class)
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public class MixinNetworkManager {
|
public class MixinNetworkManager {
|
||||||
|
|
||||||
@Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
|
||||||
public void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet<?> p_channelRead0_2_, CallbackInfo ci) {
|
public void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet<?> p_channelRead0_2_, CallbackInfo ci) {
|
||||||
|
if(MixinProxy.minecraft.player != null && MixinProxy.minecraft.player.connection.getNetworkManager() != (Object) this)
|
||||||
|
return;
|
||||||
MixinProxy.onPacketReceive(p_channelRead0_2_, ci);
|
MixinProxy.onPacketReceive(p_channelRead0_2_, ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
|
||||||
public void channelRead0(Packet<?> packetIn, CallbackInfo ci) {
|
public void sendPacket(Packet<?> packetIn, CallbackInfo ci) {
|
||||||
|
if(MixinProxy.minecraft.player != null && MixinProxy.minecraft.player.connection.getNetworkManager() != (Object) this)
|
||||||
|
return;
|
||||||
MixinProxy.onPacketSend(packetIn, ci);
|
MixinProxy.onPacketSend(packetIn, ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue