Disabled Head rotation while saving replay video

Made video rendering possible while Minecraft is in background
This commit is contained in:
Marius Metzger
2015-03-08 22:51:50 +01:00
parent 5ce12162ce
commit b4ce266375
14 changed files with 122 additions and 143 deletions

View File

@@ -1,5 +1,7 @@
package eu.crushedpixel.replaymod; package eu.crushedpixel.replaymod;
import java.io.File;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
@@ -12,11 +14,11 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import eu.crushedpixel.replaymod.api.client.ApiClient; import eu.crushedpixel.replaymod.api.client.ApiClient;
import eu.crushedpixel.replaymod.editor.ReplayTrimmer;
import eu.crushedpixel.replaymod.events.GuiEventHandler; import eu.crushedpixel.replaymod.events.GuiEventHandler;
import eu.crushedpixel.replaymod.events.GuiReplayOverlay; import eu.crushedpixel.replaymod.events.GuiReplayOverlay;
import eu.crushedpixel.replaymod.events.KeyInputHandler; import eu.crushedpixel.replaymod.events.KeyInputHandler;
import eu.crushedpixel.replaymod.events.RecordingHandler; import eu.crushedpixel.replaymod.events.RecordingHandler;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler; import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.registry.KeybindRegistry; import eu.crushedpixel.replaymod.registry.KeybindRegistry;
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer; import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
@@ -106,6 +108,7 @@ public class ReplayMod
e.printStackTrace(); e.printStackTrace();
} }
//ReplayTrimmer.trim(new File("/Users/mariusmetzger/toTrim.mcpr"), new File("/Users/mariusmetzger/trimmed.mcpr"), 1000*60, 2000*60);
//if(AuthenticationHandler.isBlacklisted(Minecraft.getMinecraft().getSession().getPlayerID())) { //if(AuthenticationHandler.isBlacklisted(Minecraft.getMinecraft().getSession().getPlayerID())) {
//System.exit(0); //System.exit(0);
//} //}

View File

@@ -109,14 +109,14 @@ public class CameraEntity extends EntityPlayer {
} }
public void moveAbsolute(double x, double y, double z) { public void moveAbsolute(double x, double y, double z) {
if(ReplayHandler.isReplaying()) return; if(ReplayHandler.isInPath()) return;
this.lastTickPosX = this.prevPosX = this.posX = x; this.lastTickPosX = this.prevPosX = this.posX = x;
this.lastTickPosY = this.prevPosY = this.posY = y; this.lastTickPosY = this.prevPosY = this.posY = y;
this.lastTickPosZ = this.prevPosZ = this.posZ = z; this.lastTickPosZ = this.prevPosZ = this.posZ = z;
} }
public void moveRelative(double x, double y, double z) { public void moveRelative(double x, double y, double z) {
if(ReplayHandler.isReplaying()) return; if(ReplayHandler.isInPath()) return;
this.lastTickPosX = this.prevPosX = this.posX = this.posX+x; this.lastTickPosX = this.prevPosX = this.posX = this.posX+x;
this.lastTickPosY = this.prevPosY = this.posY = this.posY+y; this.lastTickPosY = this.prevPosY = this.posY = this.posY+y;
this.lastTickPosZ = this.prevPosZ = this.posZ = this.posZ+z; this.lastTickPosZ = this.prevPosZ = this.posZ = this.posZ+z;

View File

@@ -82,13 +82,13 @@ public class GuiEventHandler {
return; return;
} }
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) { if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
if(ReplayHandler.replayActive()) { if(ReplayHandler.isInReplay()) {
event.setCanceled(true); event.setCanceled(true);
} }
} }
else if(event.gui instanceof GuiDisconnected) { else if(event.gui instanceof GuiDisconnected) {
if(!ReplayHandler.replayActive() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) { if(!ReplayHandler.isInReplay() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
event.setCanceled(true); event.setCanceled(true);
} }
} }
@@ -111,7 +111,7 @@ public class GuiEventHandler {
@SubscribeEvent @SubscribeEvent
public void onInit(InitGuiEvent event) { public void onInit(InitGuiEvent event) {
if(event.gui instanceof GuiIngameMenu && ReplayHandler.replayActive()) { if(event.gui instanceof GuiIngameMenu && ReplayHandler.isInReplay()) {
for(GuiButton b : new ArrayList<GuiButton>(event.buttonList)) { for(GuiButton b : new ArrayList<GuiButton>(event.buttonList)) {
if(b.id == 1) { if(b.id == 1) {
b.displayString = "Exit Replay"; b.displayString = "Exit Replay";
@@ -164,7 +164,7 @@ public class GuiEventHandler {
mc.displayGuiScreen(new GuiReplaySettings(event.gui)); mc.displayGuiScreen(new GuiReplaySettings(event.gui));
} }
if(ReplayHandler.replayActive() && event.gui instanceof GuiIngameMenu && event.button.id == GuiConstants.EXIT_REPLAY_BUTTON) { if(ReplayHandler.isInReplay() && event.gui instanceof GuiIngameMenu && event.button.id == GuiConstants.EXIT_REPLAY_BUTTON) {
ReplayHandler.endReplay(); ReplayHandler.endReplay();
event.button.enabled = false; event.button.enabled = false;

View File

@@ -24,6 +24,7 @@ import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent; import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.gameevent.InputEvent;
@@ -89,6 +90,17 @@ public class GuiReplayOverlay extends Gui {
private boolean mouseDown = false; private boolean mouseDown = false;
private static boolean requestScreenshot = false; private static boolean requestScreenshot = false;
private static Field isGamePaused;
static {
try {
isGamePaused = Minecraft.class.getDeclaredField(MCPNames.field("field_71445_n"));
isGamePaused.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
//private Field drawBlockOutline; //private Field drawBlockOutline;
@@ -106,32 +118,41 @@ public class GuiReplayOverlay extends Gui {
//@SubscribeEvent TODO //@SubscribeEvent TODO
public void renderHand(RenderHandEvent event) { public void renderHand(RenderHandEvent event) {
if(ReplayHandler.replayActive()) { if(ReplayHandler.isInReplay()) {
event.setCanceled(true); event.setCanceled(true);
} }
} }
@SubscribeEvent @SubscribeEvent
public void tick(TickEvent event) { public void tick(TickEvent event) {
if(!ReplayHandler.replayActive()) return; if(!ReplayHandler.isInReplay()) return;
if(ReplayHandler.isReplaying() && !ReplayProcess.isVideoRecording()) ReplayProcess.tickReplay(); if(ReplayHandler.isInPath() && !ReplayProcess.isVideoRecording()) ReplayProcess.tickReplay();
ReplayProcess.unblock(); ReplayProcess.unblock();
if(ReplayHandler.getCameraEntity() != null) if(ReplayHandler.getCameraEntity() != null)
ReplayHandler.getCameraEntity().updateMovement(); ReplayHandler.getCameraEntity().updateMovement();
if(!ReplayHandler.isReplaying()) onMouseMove(new MouseEvent()); if(!ReplayHandler.isInPath()) onMouseMove(new MouseEvent());
FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent()); FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent());
} }
private double lastX, lastY, lastZ; private double lastX, lastY, lastZ;
private float lastPitch, lastYaw; private float lastPitch, lastYaw;
@SubscribeEvent
public void onChangeView(MouseEvent event) {
if(ReplayHandler.isInPath()) {
event.setCanceled(true);
}
}
@SubscribeEvent @SubscribeEvent
public void onRenderWorld(RenderWorldLastEvent event) public void onRenderWorld(RenderWorldLastEvent event)
throws IllegalAccessException, IllegalArgumentException, throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, IOException { InvocationTargetException, IOException {
if(!ReplayHandler.replayActive()) return; if(!ReplayHandler.isInReplay()) return;
if(ReplayHandler.isCamera()) ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity()); if(ReplayHandler.isCamera()) ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity());
if(ReplayHandler.replayActive() && ReplayHandler.isPaused()) { if(ReplayHandler.isInReplay() && ReplayHandler.isPaused()) {
if(mc != null && mc.thePlayer != null) if(mc != null && mc.thePlayer != null)
MinecraftTicker.runMouseKeyboardTick(mc); MinecraftTicker.runMouseKeyboardTick(mc);
} }
@@ -150,6 +171,9 @@ public class GuiReplayOverlay extends Gui {
requestScreenshot = false; requestScreenshot = false;
ReplayScreenshot.saveScreenshot(mc.getFramebuffer()); ReplayScreenshot.saveScreenshot(mc.getFramebuffer());
} }
if(mc.isGamePaused() && ReplayHandler.isInPath()) {
isGamePaused.set(mc, false);
}
} }
public void resetUI() throws Exception { public void resetUI() throws Exception {
@@ -171,7 +195,7 @@ public class GuiReplayOverlay extends Gui {
@SubscribeEvent @SubscribeEvent
public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException { public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException {
if(!ReplayHandler.replayActive() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) { if(!ReplayHandler.isInReplay() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) {
return; return;
} }
@@ -189,7 +213,7 @@ public class GuiReplayOverlay extends Gui {
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
// drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false);
if(!ReplayHandler.replayActive()) { if(!ReplayHandler.isInReplay()) {
return; return;
} }
@@ -718,7 +742,7 @@ public class GuiReplayOverlay extends Gui {
int dx = 0; int dx = 0;
int dy = 0; int dy = 0;
boolean play = ReplayHandler.isReplaying(); boolean play = ReplayHandler.isInPath();
hover = false; hover = false;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
@@ -742,7 +766,7 @@ public class GuiReplayOverlay extends Gui {
//Handling the click on the Replay starter //Handling the click on the Replay starter
if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(ReplayHandler.isReplaying()) { if(ReplayHandler.isInPath()) {
ReplayHandler.interruptReplay(); ReplayHandler.interruptReplay();
} else { } else {
ReplayHandler.startPath(false); ReplayHandler.startPath(false);
@@ -827,7 +851,7 @@ public class GuiReplayOverlay extends Gui {
@SubscribeEvent @SubscribeEvent
public void onMouseMove(MouseEvent event) { public void onMouseMove(MouseEvent event) {
if(!ReplayHandler.replayActive()) return; if(!ReplayHandler.isInReplay()) return;
boolean flag = Display.isActive(); boolean flag = Display.isActive();
flag = true; flag = true;

View File

@@ -21,7 +21,7 @@ public class KeyInputHandler {
@SubscribeEvent @SubscribeEvent
public void onKeyInput(KeyInputEvent event) { public void onKeyInput(KeyInputEvent event) {
if(!ReplayHandler.replayActive()) return; if(!ReplayHandler.isInReplay()) return;
if(mc.currentScreen != null) { if(mc.currentScreen != null) {
return; return;
} }

View File

@@ -24,6 +24,7 @@ import net.minecraft.client.renderer.ActiveRenderInfo;
import com.google.gson.Gson; import com.google.gson.Gson;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.gui.GuiReplaySaving; import eu.crushedpixel.replaymod.gui.GuiReplaySaving;
import eu.crushedpixel.replaymod.holders.PacketData; import eu.crushedpixel.replaymod.holders.PacketData;
@@ -33,17 +34,17 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
protected Long startTime = null; protected Long startTime = null;
protected String name; protected String name;
protected String worldName; protected String worldName;
private boolean singleplayer; private boolean singleplayer;
protected long lastSentPacket = 0; protected long lastSentPacket = 0;
protected boolean alive = true; protected boolean alive = true;
protected DataWriter dataWriter; protected DataWriter dataWriter;
private Gson gson = new Gson(); private Gson gson = new Gson();
protected Set<String> players = new HashSet<String>(); protected Set<String> players = new HashSet<String>();
public void setWorldName(String worldName) { public void setWorldName(String worldName) {
@@ -65,12 +66,12 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
DataOutputStream out = new DataOutputStream(bos); DataOutputStream out = new DataOutputStream(bos);
dataWriter = new DataWriter(out); dataWriter = new DataWriter(out);
} }
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
dataWriter.requestFinish(players); dataWriter.requestFinish(players);
} }
public class DataWriter { public class DataWriter {
private boolean active = true; private boolean active = true;
@@ -80,27 +81,24 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
public void writeData(PacketData data) { public void writeData(PacketData data) {
queue.add(data); queue.add(data);
} }
Thread outputThread = new Thread(new Runnable() { Thread outputThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
HashMap<Class, Integer> counts = new HashMap<Class, Integer>(); HashMap<Class, Integer> counts = new HashMap<Class, Integer>();
while(active) { while(active) {
PacketData dataReciever = queue.poll(); PacketData dataReciever = queue.poll();
if(dataReciever != null) { if(dataReciever != null) {
//write the ByteBuf to the given OutputStream //write the ByteBuf to the given OutputStream
byte[] array = dataReciever.getByteArray(); byte[] array = dataReciever.getByteArray();
if(array != null) { if(array != null) {
try { try {
stream.writeInt(dataReciever.getTimestamp()); //Timestamp ReplayFileIO.writePacket(dataReciever, stream);
stream.writeInt(array.length); //Lenght
stream.write(array); //Content
stream.flush(); stream.flush();
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -127,7 +125,7 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
for(Entry<Class, Integer> entries : counts.entrySet()) { for(Entry<Class, Integer> entries : counts.entrySet()) {
System.out.println(entries.getKey()+ "| "+entries.getValue()); System.out.println(entries.getKey()+ "| "+entries.getValue());
} }
} }
}); });
@@ -140,7 +138,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
public void requestFinish(Set<String> players) { public void requestFinish(Set<String> players) {
active = false; active = false;
byte[] buffer = new byte[1024];
try { try {
GuiReplaySaving.replaySaving = true; GuiReplaySaving.replaySaving = true;
@@ -150,9 +147,9 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
if(split.length > 0) { if(split.length > 0) {
mcversion = split[0]; mcversion = split[0];
} }
String[] pl = players.toArray(new String[players.size()]); String[] pl = players.toArray(new String[players.size()]);
ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime, pl, mcversion); ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime, pl, mcversion);
String json = gson.toJson(metaData); String json = gson.toJson(metaData);
@@ -162,29 +159,10 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
File archive = new File(folder, name+ConnectionEventHandler.ZIP_FILE_EXTENSION); File archive = new File(folder, name+ConnectionEventHandler.ZIP_FILE_EXTENSION);
archive.createNewFile(); archive.createNewFile();
FileOutputStream fos = new FileOutputStream(archive); ReplayFileIO.writeReplayFile(archive, file, metaData);
ZipOutputStream zos = new ZipOutputStream(fos);
zos.putNextEntry(new ZipEntry("metaData.json"));
PrintWriter pw = new PrintWriter(zos);
pw.write(json);
pw.flush();
zos.closeEntry();
zos.putNextEntry(new ZipEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION));
FileInputStream fis = new FileInputStream(file);
int len;
while((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
fis.close();
zos.closeEntry();
zos.close();
file.delete();
file.delete();
GuiReplaySaving.replaySaving = false; GuiReplaySaving.replaySaving = false;
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -19,6 +19,7 @@ import net.minecraft.network.play.server.S0DPacketCollectItem;
import net.minecraft.network.play.server.S0FPacketSpawnMob; import net.minecraft.network.play.server.S0FPacketSpawnMob;
import eu.crushedpixel.replaymod.chat.ChatMessageRequests; import eu.crushedpixel.replaymod.chat.ChatMessageRequests;
import eu.crushedpixel.replaymod.chat.ChatMessageRequests.ChatMessageType; import eu.crushedpixel.replaymod.chat.ChatMessageRequests.ChatMessageType;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.holders.PacketData; import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.reflection.MCPNames; import eu.crushedpixel.replaymod.reflection.MCPNames;
@@ -32,8 +33,6 @@ public class PacketListener extends DataListener {
private ChannelHandlerContext context = null; private ChannelHandlerContext context = null;
private static final PacketSerializer packetSerializer = new PacketSerializer(EnumPacketDirection.CLIENTBOUND);
public void saveOnly(Packet packet) { public void saveOnly(Packet packet) {
try { try {
if(packet instanceof S0CPacketSpawnPlayer) { if(packet instanceof S0CPacketSpawnPlayer) {
@@ -69,7 +68,7 @@ public class PacketListener extends DataListener {
if(packet instanceof S0DPacketCollectItem) { if(packet instanceof S0DPacketCollectItem) {
if(mc.thePlayer != null || if(mc.thePlayer != null ||
((S0DPacketCollectItem) packet).func_149353_d() == mc.thePlayer.getEntityId()) { ((S0DPacketCollectItem)packet).func_149353_d() == mc.thePlayer.getEntityId()) {
super.channelRead(ctx, msg); super.channelRead(ctx, msg);
return; return;
} }
@@ -115,10 +114,6 @@ public class PacketListener extends DataListener {
if(startTime == null) startTime = System.currentTimeMillis(); if(startTime == null) startTime = System.currentTimeMillis();
int timestamp = (int)(System.currentTimeMillis() - startTime); int timestamp = (int)(System.currentTimeMillis() - startTime);
//Converts the packet back to a ByteBuffer for correct saving
ByteBuf bb = Unpooled.buffer();
if(packet instanceof S0FPacketSpawnMob) { if(packet instanceof S0FPacketSpawnMob) {
DataWatcher l = (DataWatcher)spawnMobDataWatcher.get(packet); DataWatcher l = (DataWatcher)spawnMobDataWatcher.get(packet);
@@ -135,14 +130,8 @@ public class PacketListener extends DataListener {
spawnPlayerDataWatcher.set(packet, dw); spawnPlayerDataWatcher.set(packet, dw);
} }
} }
packetSerializer.encode(ctx, packet, bb);
bb.readerIndex(0); byte[] array = ReplayFileIO.serializePacket(packet);
byte[] array = new byte[bb.readableBytes()];
bb.readBytes(array);
bb.readerIndex(0);
return new PacketData(array, timestamp); return new PacketData(array, timestamp);
} }

View File

@@ -24,31 +24,24 @@ public class PacketSerializer extends MessageSerializer {
} }
@Override @Override
public void encode(ChannelHandlerContext p_encode_1_, Packet p_encode_2_, ByteBuf p_encode_3_) throws IOException { public void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf byteBuf) throws IOException {
//super.encode(p_encode_1_, p_encode_2_, p_encode_3_); EnumConnectionState state = ((EnumConnectionState)ctx.channel().attr(NetworkManager.attrKeyConnectionState).get());
encode(state, packet, byteBuf);
Integer integer = ((EnumConnectionState)p_encode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()).getPacketId(EnumPacketDirection.CLIENTBOUND, p_encode_2_); }
public void encode(EnumConnectionState state, Packet packet, ByteBuf byteBuf) {
Integer integer = state.getPacketId(EnumPacketDirection.CLIENTBOUND, packet);
if (integer == null) if (integer == null) {
{
return; return;
} } else {
else PacketBuffer packetbuffer = new PacketBuffer(byteBuf);
{
PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_);
packetbuffer.writeVarIntToBuffer(integer.intValue()); packetbuffer.writeVarIntToBuffer(integer.intValue());
try try {
{ packet.writePacketData(packetbuffer);
if (p_encode_2_ instanceof S0CPacketSpawnPlayer)
{
//p_encode_2_ = p_encode_2_; FML: Kill warning
}
p_encode_2_.writePacketData(packetbuffer);
} }
catch (Throwable throwable) catch (Throwable throwable) {
{
throwable.printStackTrace(); throwable.printStackTrace();
} }
} }

View File

@@ -30,6 +30,9 @@ public class ReplayMetaData {
public int getDuration() { public int getDuration() {
return duration; return duration;
} }
public void setDuration(int duration) {
this.duration = duration;
}
public long getDate() { public long getDate() {
return date; return date;
} }

View File

@@ -8,8 +8,6 @@ public class PacketInfo {
private EnumConnectionState connectionState; private EnumConnectionState connectionState;
private int packetID; private int packetID;
public PacketInfo(byte[] bytes, EnumConnectionState connectionState, public PacketInfo(byte[] bytes, EnumConnectionState connectionState,
int packetID) { int packetID) {
super(); super();

View File

@@ -40,13 +40,13 @@ public class ReplayHandler {
private static Keyframe selectedKeyframe; private static Keyframe selectedKeyframe;
private static boolean isReplaying = false; private static boolean inPath = false;
private static CameraEntity cameraEntity; private static CameraEntity cameraEntity;
private static List<Keyframe> keyframes = new ArrayList<Keyframe>(); private static List<Keyframe> keyframes = new ArrayList<Keyframe>();
private static boolean replayActive = false; private static boolean inReplay = false;
public static long lastExit = 0; public static long lastExit = 0;
@@ -93,20 +93,20 @@ public class ReplayHandler {
return gamma; return gamma;
} }
public static void setReplaying(boolean replaying) { public static void setInPath(boolean replaying) {
isReplaying = replaying; inPath = replaying;
} }
public static void startPath(boolean save) { public static void startPath(boolean save) {
if(!ReplayHandler.isReplaying()) ReplayProcess.startReplayProcess(save); if(!ReplayHandler.isInPath()) ReplayProcess.startReplayProcess(save);
} }
public static void interruptReplay() { public static void interruptReplay() {
ReplayProcess.stopReplayProcess(false); ReplayProcess.stopReplayProcess(false);
} }
public static boolean isReplaying() { public static boolean isInPath() {
return isReplaying; return inPath;
} }
public static void setCameraEntity(CameraEntity entity) { public static void setCameraEntity(CameraEntity entity) {
@@ -309,8 +309,8 @@ public class ReplayHandler {
sortKeyframes(); sortKeyframes();
} }
public static boolean replayActive() { public static boolean isInReplay() {
return replayActive; return inReplay;
} }
public static boolean isPaused() { public static boolean isPaused() {
@@ -364,7 +364,7 @@ public class ReplayHandler {
//Load lighting and trigger update //Load lighting and trigger update
ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled()); ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled());
replayActive = true; inReplay = true;
} }
public static void restartReplay() { public static void restartReplay() {
@@ -390,7 +390,7 @@ public class ReplayHandler {
ReplayMod.overlay.resetUI(); ReplayMod.overlay.resetUI();
} catch(Exception e) {} } catch(Exception e) {}
replayActive = true; inReplay = true;
} }
public static void endReplay() { public static void endReplay() {
@@ -406,7 +406,7 @@ public class ReplayHandler {
} }
*/ */
replayActive = false; inReplay = false;
} }
public static Keyframe getSelected() { public static Keyframe getSelected() {

View File

@@ -63,7 +63,7 @@ public class ReplayProcess {
lastTimestamp = -1; lastTimestamp = -1;
linear = ReplayMod.replaySettings.isLinearMovement(); linear = ReplayMod.replaySettings.isLinearMovement();
ReplayHandler.sortKeyframes(); ReplayHandler.sortKeyframes();
ReplayHandler.setReplaying(true); ReplayHandler.setInPath(true);
previousReplaySpeed = ReplayHandler.getSpeed(); previousReplaySpeed = ReplayHandler.getSpeed();
TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1); TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1);
@@ -85,7 +85,7 @@ public class ReplayProcess {
@Override @Override
public void run() { public void run() {
while(ReplayHandler.isReplaying()) { while(ReplayHandler.isInPath()) {
if(!blocked) { if(!blocked) {
mc.addScheduledTask(new Runnable() { mc.addScheduledTask(new Runnable() {
@Override @Override
@@ -109,10 +109,10 @@ public class ReplayProcess {
} }
public static void stopReplayProcess(boolean finished) { public static void stopReplayProcess(boolean finished) {
if(!ReplayHandler.isReplaying()) return; if(!ReplayHandler.isInPath()) return;
if(finished) ChatMessageRequests.addChatMessage("Replay finished!", ChatMessageType.INFORMATION); if(finished) ChatMessageRequests.addChatMessage("Replay finished!", ChatMessageType.INFORMATION);
else ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION); else ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION);
ReplayHandler.setReplaying(false); ReplayHandler.setInPath(false);
MCTimerHandler.setActiveTimer(); MCTimerHandler.setActiveTimer();
ReplayHandler.setSpeed(previousReplaySpeed); ReplayHandler.setSpeed(previousReplaySpeed);
ReplayHandler.setSpeed(0); ReplayHandler.setSpeed(0);
@@ -434,7 +434,7 @@ public class ReplayProcess {
//Video capturing, for testing purposes //Video capturing, for testing purposes
if(isVideoRecording()) { if(isVideoRecording()) {
try { try {
if(!VideoWriter.isRecording() && ReplayHandler.isReplaying()) { if(!VideoWriter.isRecording() && ReplayHandler.isInPath()) {
VideoWriter.startRecording(mc.displayWidth, mc.displayHeight); VideoWriter.startRecording(mc.displayWidth, mc.displayHeight);
} else { } else {
VideoWriter.writeImage(ScreenCapture.captureScreen()); VideoWriter.writeImage(ScreenCapture.captureScreen());

View File

@@ -15,7 +15,6 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiDownloadTerrain; import net.minecraft.client.gui.GuiDownloadTerrain;
@@ -48,7 +47,6 @@ import net.minecraft.network.play.server.S30PacketWindowItems;
import net.minecraft.network.play.server.S36PacketSignEditorOpen; import net.minecraft.network.play.server.S36PacketSignEditorOpen;
import net.minecraft.network.play.server.S37PacketStatistics; import net.minecraft.network.play.server.S37PacketStatistics;
import net.minecraft.network.play.server.S38PacketPlayerListItem; import net.minecraft.network.play.server.S38PacketPlayerListItem;
import net.minecraft.network.play.server.S38PacketPlayerListItem.AddPlayerData;
import net.minecraft.network.play.server.S39PacketPlayerAbilities; import net.minecraft.network.play.server.S39PacketPlayerAbilities;
import net.minecraft.network.play.server.S43PacketCamera; import net.minecraft.network.play.server.S43PacketCamera;
import net.minecraft.network.play.server.S45PacketTitle; import net.minecraft.network.play.server.S45PacketTitle;
@@ -63,11 +61,12 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.entities.CameraEntity; import eu.crushedpixel.replaymod.entities.CameraEntity;
import eu.crushedpixel.replaymod.events.RecordingHandler; import eu.crushedpixel.replaymod.events.RecordingHandler;
import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.holders.Position; import eu.crushedpixel.replaymod.holders.Position;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler; import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.recording.ReplayMetaData; import eu.crushedpixel.replaymod.recording.ReplayMetaData;
@@ -86,7 +85,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
private long toleratedTimeStamp = Long.MAX_VALUE; private long toleratedTimeStamp = Long.MAX_VALUE;
private File replayFile; private File replayFile;
private PacketDeserializer ds = new PacketDeserializer(EnumPacketDirection.SERVERBOUND);
private boolean active = true; private boolean active = true;
private ZipFile archive; private ZipFile archive;
private DataInputStream dis; private DataInputStream dis;
@@ -148,7 +146,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
setReplaySpeed(replaySpeed); setReplaySpeed(replaySpeed);
if((millis < currentTimeStamp && !isHurrying())) { if((millis < currentTimeStamp && !isHurrying())) {
if(ReplayHandler.isReplaying()) { if(ReplayHandler.isInPath()) {
if(millis < toleratedTimeStamp) { if(millis < toleratedTimeStamp) {
return; return;
} }
@@ -255,9 +253,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
lastPacketSent = System.currentTimeMillis(); lastPacketSent = System.currentTimeMillis();
ReplayHandler.restartReplay(); ReplayHandler.restartReplay();
} }
while(!terminate && !startFromBeginning && (!paused() || FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class))) { while(!terminate && !startFromBeginning && (!paused() || FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class))) {
try { try {
/* /*
* LOGIC: * LOGIC:
* While behind desired timestamp, only send packets * While behind desired timestamp, only send packets
@@ -270,15 +268,16 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
*/ */
if(!hurryToTimestamp && ReplayHandler.isReplaying()) { if(!hurryToTimestamp && ReplayHandler.isInPath()) {
continue; continue;
} }
int timestamp = dis.readInt(); PacketData pd = ReplayFileIO.readPacketData(dis);
currentTimeStamp = timestamp; currentTimeStamp = pd.getTimestamp();
//System.out.println(currentTimeStamp);
if(!ReplayHandler.isReplaying() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) { if(!ReplayHandler.isInPath() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) {
//if(!hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) { //if(!hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) {
int timeWait = (int)Math.round((currentTimeStamp - lastTimeStamp)/replaySpeed); int timeWait = (int)Math.round((currentTimeStamp - lastTimeStamp)/replaySpeed);
long timeDiff = System.currentTimeMillis() - lastPacketSent; long timeDiff = System.currentTimeMillis() - lastPacketSent;
@@ -287,15 +286,11 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
Thread.sleep(timeToSleep); Thread.sleep(timeToSleep);
} }
int bytes = dis.readInt(); ReplaySender.this.channelRead(ctx, pd.getByteArray());
byte[] bb = new byte[bytes];
dis.readFully(bb);
ReplaySender.this.channelRead(ctx, bb);
lastTimeStamp = currentTimeStamp; lastTimeStamp = currentTimeStamp;
if(ReplayHandler.isReplaying()) { if(ReplayHandler.isInPath()) {
toleratedTimeStamp = lastTimeStamp; toleratedTimeStamp = lastTimeStamp;
} else { } else {
toleratedTimeStamp = -1; toleratedTimeStamp = -1;
@@ -303,12 +298,12 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) { if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) {
hurryToTimestamp = false; hurryToTimestamp = false;
if(!ReplayHandler.isReplaying() || hasRestarted) { if(!ReplayHandler.isInPath() || hasRestarted) {
MCTimerHandler.advanceRenderPartialTicks(5); MCTimerHandler.advanceRenderPartialTicks(5);
MCTimerHandler.advancePartialTicks(5); MCTimerHandler.advancePartialTicks(5);
MCTimerHandler.advanceTicks(5); MCTimerHandler.advanceTicks(5);
} }
if(!ReplayHandler.isReplaying()) { if(!ReplayHandler.isInPath()) {
Position pos = ReplayHandler.getLastPosition(); Position pos = ReplayHandler.getLastPosition();
CameraEntity cam = ReplayHandler.getCameraEntity(); CameraEntity cam = ReplayHandler.getCameraEntity();
if(cam != null) { if(cam != null) {
@@ -320,17 +315,18 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
} }
} }
} }
if(!ReplayHandler.isReplaying()) { if(!ReplayHandler.isInPath()) {
setReplaySpeed(0); setReplaySpeed(0);
} }
hasRestarted = false; hasRestarted = false;
} }
} catch(EOFException eof) { } catch(EOFException eof) {
System.out.println("End of File encountered!");
dis = new DataInputStream(archive.getInputStream(replayEntry)); dis = new DataInputStream(archive.getInputStream(replayEntry));
setReplaySpeed(0); setReplaySpeed(0);
} catch(IOException e) { } catch(IOException e) {
//e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@@ -398,12 +394,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
byte[] ba = (byte[])msg; byte[] ba = (byte[])msg;
try { try {
ByteBuf bb = Unpooled.wrappedBuffer(ba); Packet p = ReplayFileIO.deserializePacket(ba);
PacketBuffer pb = new PacketBuffer(bb);
int i = pb.readVarIntFromBuffer();
Packet p = EnumConnectionState.PLAY.getPacket(EnumPacketDirection.CLIENTBOUND, i);
if(hurryToTimestamp) { //If hurrying, ignore some packets if(hurryToTimestamp) { //If hurrying, ignore some packets
if(p instanceof S45PacketTitle || if(p instanceof S45PacketTitle ||
@@ -425,8 +416,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(badPackets.contains(p.getClass())) return; if(badPackets.contains(p.getClass())) return;
try { try {
p.readPacketData(pb);
if(p instanceof S1CPacketEntityMetadata) { if(p instanceof S1CPacketEntityMetadata) {
if((Integer)metadataPacketEntityId.get(p) == actualID) { if((Integer)metadataPacketEntityId.get(p) == actualID) {
metadataPacketEntityId.set(p, RecordingHandler.entityID); metadataPacketEntityId.set(p, RecordingHandler.entityID);
@@ -434,6 +423,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
} }
if(p instanceof S01PacketJoinGame) { if(p instanceof S01PacketJoinGame) {
//System.out.println("FOUND JOIN PACKET");
allowMovement = true; allowMovement = true;
int entId = (Integer)joinPacketEntityId.get(p); int entId = (Integer)joinPacketEntityId.get(p);
actualID = entId; actualID = entId;
@@ -493,7 +483,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(p instanceof S08PacketPlayerPosLook) { if(p instanceof S08PacketPlayerPosLook) {
final S08PacketPlayerPosLook ppl = (S08PacketPlayerPosLook)p; final S08PacketPlayerPosLook ppl = (S08PacketPlayerPosLook)p;
if(ReplayHandler.isReplaying() && !hurryToTimestamp) return; if(ReplayHandler.isInPath() && !hurryToTimestamp) return;
CameraEntity cent = ReplayHandler.getCameraEntity(); CameraEntity cent = ReplayHandler.getCameraEntity();
@@ -531,6 +521,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(p instanceof S43PacketCamera) { if(p instanceof S43PacketCamera) {
return; return;
} }
super.channelRead(ctx, p); super.channelRead(ctx, p);
} catch(Exception e) { } catch(Exception e) {
System.out.println(p.getClass()); System.out.println(p.getClass());
@@ -538,7 +529,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
} }
} catch(Exception e) { } catch(Exception e) {
//e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@@ -24,7 +24,7 @@ public class SpectateHandler {
}; };
public static void openSpectateSelection() { public static void openSpectateSelection() {
if(!ReplayHandler.replayActive()) { if(!ReplayHandler.isInReplay()) {
return; return;
} }