From 73c52b5cf05c101645f554188391b1caf3cd18d0 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Wed, 22 Aug 2018 17:28:06 +0200 Subject: [PATCH] Backport quick mode to 1.9.4+ and disable below --- .../java/com/replaymod/core/utils/Utils.java | 13 +++++++ .../replaymod/replay/FullReplaySender.java | 2 +- .../replaymod/replay/QuickReplaySender.java | 33 +++++++++++----- .../com/replaymod/replay/ReplayHandler.java | 38 +++++++++++++++++++ src/main/resources/assets/replaymod/lang | 2 +- 5 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/replaymod/core/utils/Utils.java b/src/main/java/com/replaymod/core/utils/Utils.java index d173d1c8..cef6e9a2 100644 --- a/src/main/java/com/replaymod/core/utils/Utils.java +++ b/src/main/java/com/replaymod/core/utils/Utils.java @@ -281,4 +281,17 @@ public class Utils { super.draw(renderer, size, renderInfo); } } + + public static void throwIfInstanceOf(Throwable t, Class cls) throws T { + if (cls.isInstance(t)) { + throw cls.cast(t); + } + } + public static void throwIfUnchecked(Throwable t) { + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } else if (t instanceof Error) { + throw (Error) t; + } + } } diff --git a/src/main/java/com/replaymod/replay/FullReplaySender.java b/src/main/java/com/replaymod/replay/FullReplaySender.java index c91316fc..ec0a3693 100755 --- a/src/main/java/com/replaymod/replay/FullReplaySender.java +++ b/src/main/java/com/replaymod/replay/FullReplaySender.java @@ -496,7 +496,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend //#if MC>=10809 //$$ String url = packet.getURL(); //#else - //$$ String url = packet.func_179783_a(); + //$$ String url = packet.func_179783_a(); //#endif //#endif if (url.startsWith("replay://")) { diff --git a/src/main/java/com/replaymod/replay/QuickReplaySender.java b/src/main/java/com/replaymod/replay/QuickReplaySender.java index 34acf4af..31b376cf 100644 --- a/src/main/java/com/replaymod/replay/QuickReplaySender.java +++ b/src/main/java/com/replaymod/replay/QuickReplaySender.java @@ -1,3 +1,4 @@ +//#if MC>=10904 package com.replaymod.replay; import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; @@ -32,14 +33,13 @@ import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.stream.StreamNetInput; import com.github.steveice10.packetlib.io.stream.StreamNetOutput; import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimaps; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; -import com.replaymod.core.utils.WrappedTimer; +import com.replaymod.core.utils.Utils; import com.replaymod.replaystudio.PacketData; import com.replaymod.replaystudio.io.ReplayInputStream; import com.replaymod.replaystudio.io.ReplayOutputStream; @@ -79,6 +79,10 @@ import java.util.TreeMap; import java.util.UUID; import java.util.function.Consumer; +//#if MC>=11200 +import com.replaymod.core.utils.WrappedTimer; +//#endif + import static com.replaymod.core.versions.MCVer.FML_BUS; import static com.replaymod.replay.ReplayModReplay.LOGGER; @@ -574,12 +578,17 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe byteBuf.skipBytes(8); // Skip packet length & timestamp - int packetId = packetBuf.readVarInt(); + int packetId = + //#if MC>=11102 + packetBuf.readVarInt(); + //#else + //$$ packetBuf.readVarIntFromBuffer(); + //#endif Packet mcPacket = EnumConnectionState.PLAY.getPacket(EnumPacketDirection.CLIENTBOUND, packetId); mcPacket.readPacketData(packetBuf); return mcPacket; } catch (Exception e) { - Throwables.throwIfUnchecked(e); + Utils.throwIfUnchecked(e); throw new RuntimeException(e); } finally { byteBuf.readerIndex(readerIndex); // Reset reader & writer index for next use @@ -594,13 +603,18 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe try { packetBuf.writeBytes(in.readBytes(in.readVarInt())); - int packetId = packetBuf.readVarInt(); + int packetId = + //#if MC>=11102 + packetBuf.readVarInt(); + //#else + //$$ packetBuf.readVarIntFromBuffer(); + //#endif Packet mcPacket = EnumConnectionState.PLAY.getPacket(EnumPacketDirection.CLIENTBOUND, packetId); mcPacket.readPacketData(packetBuf); return mcPacket; } catch (Exception e) { - Throwables.throwIfInstanceOf(e, IOException.class); - Throwables.throwIfUnchecked(e); + Utils.throwIfInstanceOf(e, IOException.class); + Utils.throwIfUnchecked(e); throw new RuntimeException(e); } finally { byteBuf.readerIndex(readerIndex); // Reset reader & writer index for next use @@ -640,8 +654,8 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe out.writeByte(byteBuf.readByte()); } } catch (Exception e) { - Throwables.throwIfInstanceOf(e, IOException.class); - Throwables.throwIfUnchecked(e); + Utils.throwIfInstanceOf(e, IOException.class); + Utils.throwIfUnchecked(e); throw new RuntimeException(e); } finally { byteBuf.readerIndex(readerIndex); // Reset reader & writer index for next use @@ -908,3 +922,4 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe } } } +//#endif diff --git a/src/main/java/com/replaymod/replay/ReplayHandler.java b/src/main/java/com/replaymod/replay/ReplayHandler.java index 81d70521..45007209 100755 --- a/src/main/java/com/replaymod/replay/ReplayHandler.java +++ b/src/main/java/com/replaymod/replay/ReplayHandler.java @@ -34,6 +34,12 @@ import org.lwjgl.opengl.Display; import java.io.IOException; import java.util.*; +//#if MC<10904 +//$$ import de.johni0702.minecraft.gui.element.GuiLabel; +//$$ import de.johni0702.minecraft.gui.popup.GuiInfoPopup; +//$$ import de.johni0702.minecraft.gui.utils.Colors; +//#endif + //#if MC>=10800 import com.mojang.authlib.GameProfile; import net.minecraft.client.network.NetHandlerPlayClient; @@ -78,8 +84,12 @@ public class ReplayHandler { * Decodes and sends packets into channel. */ private final FullReplaySender fullReplaySender; + //#if MC>=10904 private final QuickReplaySender quickReplaySender; private boolean quickMode = false; + //#else + //$$ private static final String QUICK_MODE_MIN_MC = "1.9.4"; + //#endif /** * Currently active replay restrictions. @@ -117,7 +127,9 @@ public class ReplayHandler { markers = new ArrayList<>(replayFile.getMarkers().or(Collections.emptySet())); fullReplaySender = new FullReplaySender(this, replayFile, false); + //#if MC>=10904 quickReplaySender = new QuickReplaySender(ReplayModReplay.instance, replayFile); + //#endif setup(); @@ -149,7 +161,9 @@ public class ReplayHandler { FML_BUS.post(new ReplayCloseEvent.Pre(this)); fullReplaySender.terminateReplay(); + //#if MC>=10904 quickReplaySender.unregister(); + //#endif replayFile.save(); replayFile.close(); @@ -214,6 +228,9 @@ public class ReplayHandler { //$$ channel.attr(NetworkDispatcher.FML_DISPATCHER).set(networkDispatcher); //$$ //$$ channel.pipeline().addFirst("ReplayModReplay_replaySender", fullReplaySender); + //#if MC>=10904 + //$$ channel.pipeline().addFirst("ReplayModReplay_quickReplaySender", quickReplaySender); + //#endif //$$ channel.pipeline().addAfter("ReplayModReplay_replaySender", "fml:packet_handler", networkDispatcher); //$$ channel.pipeline().fireChannelActive(); //#endif @@ -266,13 +283,18 @@ public class ReplayHandler { } public ReplaySender getReplaySender() { + //#if MC>=10904 return quickMode ? quickReplaySender : fullReplaySender; + //#else + //$$ return fullReplaySender; + //#endif } public GuiReplayOverlay getOverlay() { return overlay; } + //#if MC>=10904 public void ensureQuickModeInitialized(Runnable andThen) { ListenableFuture future = quickReplaySender.getInitializationPromise(); if (future == null) { @@ -346,6 +368,20 @@ public class ReplayHandler { public boolean isQuickMode() { return quickMode; } + //#else + //$$ public void ensureQuickModeInitialized(@SuppressWarnings("unused") Runnable andThen) { + //$$ GuiInfoPopup.open(overlay, + //$$ new GuiLabel().setI18nText("replaymod.gui.noquickmode", QUICK_MODE_MIN_MC).setColor(Colors.BLACK)); + //$$ } + //$$ + //$$ public void setQuickMode(@SuppressWarnings("unused") boolean quickMode) { + //$$ throw new UnsupportedOperationException("Quick Mode not supported on this version."); + //$$ } + //$$ + //$$ public boolean isQuickMode() { + //$$ return false; + //$$ } + //#endif public int getReplayDuration() { return replayDuration; @@ -460,10 +496,12 @@ public class ReplayHandler { } public void doJump(int targetTime, boolean retainCameraPosition) { + //#if MC>=10904 if (getReplaySender() == quickReplaySender) { quickReplaySender.sendPacketsTill(targetTime); return; } + //#endif FullReplaySender replaySender = fullReplaySender; if (replaySender.isHurrying()) { diff --git a/src/main/resources/assets/replaymod/lang b/src/main/resources/assets/replaymod/lang index 692a6765..16508289 160000 --- a/src/main/resources/assets/replaymod/lang +++ b/src/main/resources/assets/replaymod/lang @@ -1 +1 @@ -Subproject commit 692a6765560bd96f02c9364798395914470c2c9e +Subproject commit 165082892e4f323d0bc5ef6bc390325664372035