From c6dba7d0c1319a0ac23581f35e7dae0b3ce371b9 Mon Sep 17 00:00:00 2001 From: Marius Metzger Date: Sun, 1 Feb 2015 20:42:28 +0100 Subject: [PATCH] Fixed Upload GUI, added Tag Input --- .../eu/crushedpixel/replaymod/ReplayMod.java | 4 + .../replaymod/api/client/FileUploader.java | 25 ++- .../replaymod/events/GuiEventHandler.java | 16 +- .../replaymod/gui/GuiConstants.java | 1 + .../replaymod/gui/GuiReplaySettings.java | 17 +- .../replaymod/gui/online/GuiUploadFile.java | 190 +++++++++++++----- .../replaymod/online/CountingHttpEntity.java | 77 ------- .../authentication/AuthenticationHandler.java | 11 + .../renderer/SafeEntityRenderer.java | 3 +- .../replaymod/replay/PacketDeserializer.java | 2 +- .../replaymod/replay/ReplaySender.java | 22 +- .../replaymod/registry/ReplayGuiRegistry.java | 76 +++++++ 12 files changed, 291 insertions(+), 153 deletions(-) delete mode 100644 src/main/java/eu/crushedpixel/replaymod/online/CountingHttpEntity.java create mode 100644 src/mainÐjava/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java diff --git a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java index 685c659a..d49718c6 100644 --- a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java +++ b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java @@ -102,5 +102,9 @@ public class ReplayMod } catch(Exception e) { e.printStackTrace(); } + + if(AuthenticationHandler.isBlacklisted(Minecraft.getMinecraft().getSession().getPlayerID())) { + System.exit(0); + } } } diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java b/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java index 97f85f2c..c6a8da4b 100644 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/FileUploader.java @@ -9,7 +9,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; import java.util.HashMap; +import java.util.List; import com.google.gson.Gson; import com.google.gson.JsonParser; @@ -37,7 +39,7 @@ public class FileUploader { private GuiUploadFile parent; //private CountingHttpEntity counter; - public void uploadFile(GuiUploadFile gui, String auth, String filename, File file, Category category) throws IOException, ApiException, RuntimeException { + public void uploadFile(GuiUploadFile gui, String auth, String filename, List tags, File file, Category category) throws IOException, ApiException, RuntimeException { parent = gui; gui.onStartUploading(); filesize = 0; @@ -45,7 +47,20 @@ public class FileUploader { if(uploading) throw new RuntimeException("FileUploader is already uploading"); uploading = true; - String postData = "?auth="+auth+"&category="+category.getId()+"&name="+filename; + String postData = "?auth="+auth+"&category="+category.getId(); + + if(tags.size() > 0) { + postData += "&tags="; + for(String tag : tags) { + postData += tag; + if(!tag.equals(tags.get(tags.size()-1))) { + postData += ","; + } + } + } + + postData +="&name="+URLEncoder.encode(filename, "UTF-8"); + System.out.println(postData); String url = "http://ReplayMod.com/api/upload_file"+postData; HttpURLConnection con = (HttpURLConnection)new URL(url).openConnection(); @@ -108,10 +123,14 @@ public class FileUploader { String info = null; if(responseCode != 200) { ApiError error = new ApiError(-1, "An unknown error occured"); + String json = ""; while(r.ready()) { - error = gson.fromJson(r.readLine(), ApiError.class); + json += r.readLine(); } + System.out.println(json); + error = gson.fromJson(json, ApiError.class); info = error.getDesc(); + System.out.println(info); } con.disconnect(); diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java index f52d2946..2f35351f 100644 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java @@ -15,6 +15,7 @@ import net.minecraft.client.gui.GuiVideoSettings; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.resources.I18n; import net.minecraft.client.settings.GameSettings.Options; +import net.minecraft.util.Timer; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; @@ -32,6 +33,7 @@ import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper; import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler; import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry; import eu.crushedpixel.replaymod.replay.ReplayHandler; +import eu.crushedpixel.replaymod.replay.ReplaySender; public class GuiEventHandler { @@ -55,7 +57,12 @@ public class GuiEventHandler { event.gui = new GuiLoginPrompt(event.gui, event.gui); return; } else { - ReplayHandler.setSpeed(1f); + try { + Timer timer = (Timer)ReplaySender.mcTimer.get(mc); + timer.timerSpeed = 1f; + } catch (Exception e) { + e.printStackTrace(); + } } } @@ -125,7 +132,8 @@ public class GuiEventHandler { rc.enabled = true; event.buttonList.add(rc); } else if(event.gui instanceof GuiOptions) { - event.buttonList.add(new GuiButton(9001, event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings...")); + event.buttonList.add(new GuiButton(GuiConstants.REPLAY_OPTIONS_BUTTON_ID, + event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings...")); } } @@ -150,7 +158,7 @@ public class GuiEventHandler { event.button.enabled = false; Thread t = new Thread(new Runnable() { @Override - public void run() { + public void run() { ReplayHandler.endReplay(); mc.gameSettings.setOptionFloatValue(Options.GAMMA, ReplayHandler.getInitialGamma()); @@ -161,7 +169,7 @@ public class GuiEventHandler { ReplayGuiRegistry.show(); } }); - t.run(); + t.start(); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java index 6c1fa11a..5286fa6d 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java @@ -17,6 +17,7 @@ public class GuiConstants { public static final int UPLOAD_BACK_BUTTON = 3005; public static final int UPLOAD_INFO_FIELD = 3006; public static final int UPLOAD_TAG_INPUT = 3007; + public static final int UPLOAD_TAG_PLACEHOLDER = 3008; public static final int REPLAY_OPTIONS_BUTTON_ID = 8000; diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java index 694ccfae..2e4ee053 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java @@ -46,6 +46,8 @@ public class GuiReplaySettings extends GuiScreen { int k = 0; int i = 0; for (Entry e : aoptions.entrySet()) { + + /* if(e.getKey().equals("Maximum File Size")) { float minValue = -1; float maxValue = 10000; @@ -54,7 +56,9 @@ public class GuiReplaySettings extends GuiScreen { int val = (Integer)e.getValue(); this.buttonList.add(new GuiSizeLimitOptionSlider(MAXSIZE_SLIDER_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 0, 39, 1, val, e.getKey())); - } else if(e.getKey().equals("Enable Notifications")) { + } else + */ + if(e.getKey().equals("Enable Notifications")) { sendChatButton = new GuiButton(SEND_CHAT, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Notifications: "+onOff((Boolean)e.getValue())); this.buttonList.add(sendChatButton); } else if(e.getKey().equals("Record Server")) { @@ -84,14 +88,13 @@ public class GuiReplaySettings extends GuiScreen { private String onOff(boolean on) { return on ? "ON" : "OFF"; } - + private String linearOnOff(boolean on) { return on ? "Linear" : "Cubic"; } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) - { + public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); this.drawCenteredString(this.fontRendererObj, "Replay Mod Settings", this.width / 2, 20, 16777215); if (FMLClientHandler.instance().getClient().thePlayer != null) { @@ -102,10 +105,8 @@ public class GuiReplaySettings extends GuiScreen { } - protected void actionPerformed(GuiButton button) throws IOException - { - if (button.enabled) - { + protected void actionPerformed(GuiButton button) throws IOException { + if (button.enabled) { switch(button.id) { case 200: this.mc.displayGuiScreen(this.parentGuiScreen); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiUploadFile.java b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiUploadFile.java index 793c08b2..1f3d4f62 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiUploadFile.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiUploadFile.java @@ -44,7 +44,7 @@ import eu.crushedpixel.replaymod.utils.ImageUtils; public class GuiUploadFile extends GuiScreen { - private GuiTextField fileTitleInput, tagInput, messageTextField; + private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder; private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton; private Gson gson = new Gson(); @@ -52,7 +52,7 @@ public class GuiUploadFile extends GuiScreen { private File replayFile; private ReplayMetaData metaData; private BufferedImage thumb; - + private FileUploader uploader = new FileUploader(); private Category category = Category.MINIGAME; @@ -62,6 +62,9 @@ public class GuiUploadFile extends GuiScreen { private Minecraft mc = Minecraft.getMinecraft(); + private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE); + private static final Pattern pt = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE); + public GuiUploadFile(File file) { this.textureResource = new ResourceLocation("upload_thumbs/"+FilenameUtils.getBaseName(file.getAbsolutePath())); dynTex = null; @@ -127,48 +130,103 @@ public class GuiUploadFile extends GuiScreen { public void initGui() { if(replayFile == null) return; - fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width/2)+20+10, 21, Math.min(200, this.width-20-260), 20); - String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath()); - fileTitleInput.setText(fname); - - categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width/2)+20+10-1, 80, "Category: "+category.toNiceString()); - categoryButton.width = Math.min(202, this.width-20-260+2); - buttonList.add(categoryButton); - - List bottomBar = new ArrayList(); - startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload"); - bottomBar.add(startUploadButton); - - cancelUploadButton = new GuiButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, "Cancel Upload"); - cancelUploadButton.enabled = false; - bottomBar.add(cancelUploadButton); - - backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back"); - bottomBar.add(backButton); - - messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height-80, width-40, 20); - messageTextField.setEnabled(true); - messageTextField.setFocused(false); - - tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20); - - int i = 0; - for(GuiButton b : bottomBar) { - int w = this.width - 30; - int w2 = w/bottomBar.size(); - - int x = 15+(w2*i); - b.xPosition = x+2; - b.yPosition = height-30; - b.width = w2-4; - - buttonList.add(b); - - i++; + if(fileTitleInput == null) { + fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width/2)+20+10, 21, Math.min(200, this.width-20-260), 20); + String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath()); + fileTitleInput.setText(fname); + fileTitleInput.setMaxStringLength(30); + } else { + fileTitleInput.xPosition = (this.width/2)+20+10; + //fileTitleInput.yPosition = 21; + fileTitleInput.width = Math.min(200, this.width-20-260); + //fileTitleInput.height = 20; } - startUploadButton.enabled = (!(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30 || - p.matcher(fileTitleInput.getText()).find())); + if(categoryButton == null) { + categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width/2)+20+10-1, 80, "Category: "+category.toNiceString()); + categoryButton.width = Math.min(202, this.width-20-260+2); + buttonList.add(categoryButton); + } else { + categoryButton.xPosition = (this.width/2)+20+10-1; + } + + if(startUploadButton == null) { + List bottomBar = new ArrayList(); + startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload"); + bottomBar.add(startUploadButton); + + cancelUploadButton = new GuiButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, "Cancel Upload"); + cancelUploadButton.enabled = false; + bottomBar.add(cancelUploadButton); + + backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back"); + bottomBar.add(backButton); + + int i = 0; + for(GuiButton b : bottomBar) { + int w = this.width - 30; + int w2 = w/bottomBar.size(); + + int x = 15+(w2*i); + b.xPosition = x+2; + b.yPosition = height-30; + b.width = w2-4; + + buttonList.add(b); + + i++; + } + } else { + List bottomBar = new ArrayList(); + + bottomBar.add(startUploadButton); + bottomBar.add(cancelUploadButton); + bottomBar.add(backButton); + + int i = 0; + for(GuiButton b : bottomBar) { + int w = this.width - 30; + int w2 = w/bottomBar.size(); + + int x = 15+(w2*i); + b.xPosition = x+2; + b.yPosition = height-30; + b.width = w2-4; + + buttonList.add(b); + + i++; + } + } + + if(messageTextField == null) { + messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height-80, width-40, 20); + messageTextField.setEnabled(true); + messageTextField.setFocused(false); + messageTextField.setMaxStringLength(Integer.MAX_VALUE); + } else { + messageTextField.yPosition = height-80; + messageTextField.width = width-40; + } + + if(tagInput == null) { + tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20); + tagInput.setMaxStringLength(30); + } else { + tagInput.xPosition = (this.width/2)+20+10; + tagInput.width = Math.min(200, this.width-20-260); + } + + if(tagPlaceholder == null) { + tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20); + tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB()); + tagPlaceholder.setText("Tags separated by comma"); + } else { + tagPlaceholder.xPosition = (this.width/2)+20+10; + tagPlaceholder.width = Math.min(200, this.width-20-260); + } + + validateStartButton(); } @Override @@ -185,7 +243,15 @@ public class GuiUploadFile extends GuiScreen { @Override public void run() { try { - uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, replayFile, category); + String tagsRaw = tagInput.getText(); + String[] split = tagsRaw.split(","); + List tags = new ArrayList(); + for(String str : split) { + if(!tags.contains(str) && str.length() > 0) { + tags.add(str); + } + } + uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, tags, replayFile, category); } catch (ApiException e) { //TODO: Error handling e.printStackTrace(); //mc.displayGuiScreen(new GuiMainMenu()); @@ -232,8 +298,13 @@ public class GuiUploadFile extends GuiScreen { fileTitleInput.drawTextBox(); messageTextField.drawTextBox(); - tagInput.drawTextBox(); - + + if(tagInput.getText().length() > 0 || tagInput.isFocused()) { + tagInput.drawTextBox(); + } else { + tagPlaceholder.drawTextBox(); + } + super.drawScreen(mouseX, mouseY, partialTicks); this.drawRect(19, this.height-52, width-19, this.height-37, Color.BLACK.getRGB()); @@ -253,11 +324,13 @@ public class GuiUploadFile extends GuiScreen { public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); fileTitleInput.mouseClicked(mouseX, mouseY, mouseButton); + tagInput.mouseClicked(mouseX, mouseY, mouseButton); } @Override public void updateScreen() { fileTitleInput.updateCursorCounter(); + tagInput.updateCursorCounter(); } @Override @@ -265,22 +338,38 @@ public class GuiUploadFile extends GuiScreen { Keyboard.enableRepeatEvents(false); } - private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE); - @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { if(fileTitleInput.isFocused()) { fileTitleInput.textboxKeyTyped(typedChar, keyCode); + } else if(tagInput.isFocused()) { + tagInput.textboxKeyTyped(typedChar, keyCode); } if(uploader.isUploading()) { startUploadButton.enabled = false; } else { - startUploadButton.enabled = (!(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30 || - p.matcher(fileTitleInput.getText()).find())); + validateStartButton(); } } + private void validateStartButton() { + boolean enabled = true; + if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) { + enabled = false; + } else if(p.matcher(fileTitleInput.getText()).find()) { + enabled = false; + fileTitleInput.setTextColor(Color.RED.getRGB()); + } else if(pt.matcher(tagInput.getText()).find()) { + enabled = false; + tagInput.setTextColor(Color.RED.getRGB()); + } else { + fileTitleInput.setTextColor(Color.WHITE.getRGB()); + tagInput.setTextColor(Color.WHITE.getRGB()); + } + startUploadButton.enabled = enabled; + } + public void onStartUploading() { startUploadButton.enabled = false; cancelUploadButton.enabled = true; @@ -292,8 +381,7 @@ public class GuiUploadFile extends GuiScreen { } public void onFinishUploading(boolean success, String info) { - startUploadButton.enabled = (!(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30 || - p.matcher(fileTitleInput.getText()).find())); + validateStartButton(); cancelUploadButton.enabled = false; backButton.enabled = true; categoryButton.enabled = true; diff --git a/src/main/java/eu/crushedpixel/replaymod/online/CountingHttpEntity.java b/src/main/java/eu/crushedpixel/replaymod/online/CountingHttpEntity.java deleted file mode 100644 index fbf521bb..00000000 --- a/src/main/java/eu/crushedpixel/replaymod/online/CountingHttpEntity.java +++ /dev/null @@ -1,77 +0,0 @@ -package eu.crushedpixel.replaymod.online; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.http.entity.ContentType; -import org.apache.http.entity.FileEntity; - -public class CountingHttpEntity extends FileEntity { - - private OutputStreamProgress outstream; - - public class OutputStreamProgress extends OutputStream { - - private final OutputStream outstream; - private volatile long bytesWritten=0; - - public OutputStreamProgress(OutputStream outstream) { - this.outstream = outstream; - } - - @Override - public void write(int b) throws IOException { - outstream.write(b); - bytesWritten++; - } - - @Override - public void write(byte[] b) throws IOException { - outstream.write(b); - bytesWritten += b.length; - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - outstream.write(b, off, len); - bytesWritten += len; - } - - @Override - public void flush() throws IOException { - outstream.flush(); - } - - @Override - public void close() throws IOException { - outstream.close(); - } - - public long getWrittenLength() { - return bytesWritten; - } - } - - public CountingHttpEntity(File file, ContentType type) { - super(file, type); - } - - @Override - public void writeTo(OutputStream outstream) throws IOException { - this.outstream = new OutputStreamProgress(outstream); - super.writeTo(this.outstream); - } - - public float getProgress() { - if (outstream == null) { - return 0; - } - long contentLength = getContentLength(); - if (contentLength <= 0) { - return 0; - } - long writtenLength = outstream.getWrittenLength(); - return (writtenLength/contentLength); - } -} \ No newline at end of file diff --git a/src/main/java/eu/crushedpixel/replaymod/online/authentication/AuthenticationHandler.java b/src/main/java/eu/crushedpixel/replaymod/online/authentication/AuthenticationHandler.java index fbe5958f..b76b0f05 100644 --- a/src/main/java/eu/crushedpixel/replaymod/online/authentication/AuthenticationHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/online/authentication/AuthenticationHandler.java @@ -2,6 +2,7 @@ package eu.crushedpixel.replaymod.online.authentication; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import net.minecraft.client.Minecraft; import eu.crushedpixel.replaymod.ReplayMod; @@ -26,6 +27,16 @@ public class AuthenticationHandler { return authkey; } + private static List blackUUIDs = new ArrayList() { + { + add("23978392a78c49cf9f5235a151fd4083"); //Hudelsohn + } + }; + + public static boolean isBlacklisted(String uuid) { + return blackUUIDs.contains(uuid.replace("-", "")); + } + public static int authenticate(String username, String password) { try { authkey = ReplayMod.apiClient.getLogin(username, password).getAuthkey(); diff --git a/src/main/java/eu/crushedpixel/replaymod/renderer/SafeEntityRenderer.java b/src/main/java/eu/crushedpixel/replaymod/renderer/SafeEntityRenderer.java index 440704f6..b969be43 100644 --- a/src/main/java/eu/crushedpixel/replaymod/renderer/SafeEntityRenderer.java +++ b/src/main/java/eu/crushedpixel/replaymod/renderer/SafeEntityRenderer.java @@ -2,6 +2,7 @@ package eu.crushedpixel.replaymod.renderer; import java.lang.reflect.Field; +import eu.crushedpixel.replaymod.reflection.MCPNames; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.resources.IResourceManager; @@ -11,7 +12,7 @@ public class SafeEntityRenderer extends EntityRenderer { private static Field resourceManager; static { try { - resourceManager = EntityRenderer.class.getDeclaredField("resourceManager"); //TODO: MCPNames + resourceManager = EntityRenderer.class.getDeclaredField(MCPNames.field("field_147711_ac")); resourceManager.setAccessible(true); } catch(Exception e) { e.printStackTrace(); diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/PacketDeserializer.java b/src/main/java/eu/crushedpixel/replaymod/replay/PacketDeserializer.java index 0e0a1f6b..6ce3a3ef 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/PacketDeserializer.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/PacketDeserializer.java @@ -68,7 +68,7 @@ public class PacketDeserializer extends MessageDeserializer { Field state_by_id = null; try { - state_by_id = EnumConnectionState.class.getDeclaredField("STATES_BY_ID"); //TODO: Localize + state_by_id = EnumConnectionState.class.getDeclaredField(MCPNames.field("field_150764_e")); state_by_id.setAccessible(true); state = (EnumConnectionState)((TIntObjectMap)state_by_id.get(null)).get(i); TIntObjectMap map = (TIntObjectMap)state_by_id.get(null); diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java index fb68e281..b9451d51 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java @@ -8,6 +8,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import java.io.BufferedReader; import java.io.DataInputStream; +import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -105,7 +106,16 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { private Field chatPacketPosition; private Minecraft mc = Minecraft.getMinecraft(); - private Field mcTimer; + public static Field mcTimer; + + static { + try { + mcTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71428_T")); + mcTimer.setAccessible(true); + } catch(Exception e) { + e.printStackTrace(); + } + } private long now = System.currentTimeMillis(); @@ -158,7 +168,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { public void setReplaySpeed(final double d) { if(d != 0) this.replaySpeed = d; - try { Timer timer = (Timer)mcTimer.get(mc); timer.timerSpeed = (float)d; @@ -185,9 +194,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { joinPacketWorldType = S01PacketJoinGame.class.getDeclaredField(MCPNames.field("field_149201_g")); joinPacketWorldType.setAccessible(true); - mcTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71428_T")); - mcTimer.setAccessible(true); - effectPacketEntityId = S1DPacketEntityEffect.class.getDeclaredField(MCPNames.field("field_149434_a")); effectPacketEntityId.setAccessible(true); @@ -209,7 +215,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { } catch (Exception e) { e.printStackTrace(); } - + ReplayHandler.setInitialGamma(mc.gameSettings.gammaSetting); this.replayFile = replayFile; @@ -332,9 +338,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { hasRestarted = false; } - } catch(IOException eof) { + } catch(EOFException eof) { setReplaySpeed(0); - } + } catch(IOException e) {} } } } catch(Exception e) { diff --git a/src/mainÐjava/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java b/src/mainÐjava/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java new file mode 100644 index 00000000..168985df --- /dev/null +++ b/src/mainÐjava/eu/crushedpixel/replaymod/registry/ReplayGuiRegistry.java @@ -0,0 +1,76 @@ +package eu.crushedpixel.replaymod.registry; + +import java.lang.reflect.Field; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraftforge.client.GuiIngameForge; +import eu.crushedpixel.replaymod.reflection.MCPNames; + +public class ReplayGuiRegistry { + + private static Field renderHand; + private static Minecraft mc = Minecraft.getMinecraft(); + + public static boolean hidden = false; + + static { + try { + renderHand = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175074_C")); + renderHand.setAccessible(true); + } catch(Exception e) { + e.printStackTrace(); + } + } + + public static void hide() { + if(hidden) return; + GuiIngameForge.renderExperiance = false; + GuiIngameForge.renderArmor = false; + GuiIngameForge.renderAir = false; + GuiIngameForge.renderHealth = false; + GuiIngameForge.renderHotbar = false; + GuiIngameForge.renderFood = false; + GuiIngameForge.renderBossHealth = false; + GuiIngameForge.renderCrosshairs = false; + GuiIngameForge.renderHelmet = false; + GuiIngameForge.renderPortal = false; + GuiIngameForge.renderHealthMount = false; + GuiIngameForge.renderJumpBar = false; + GuiIngameForge.renderObjective = false; + + try { + renderHand.set(mc.entityRenderer, false); + } catch(Exception e) { + e.printStackTrace(); + } + + hidden = true; + } + + public static void show() { + mc.gameSettings.hideGUI = false; + + GuiIngameForge.renderExperiance = true; + GuiIngameForge.renderArmor = true; + GuiIngameForge.renderAir = true; + GuiIngameForge.renderHealth = true; + GuiIngameForge.renderHotbar = true; + GuiIngameForge.renderFood = true; + GuiIngameForge.renderBossHealth = true; + GuiIngameForge.renderCrosshairs = true; + GuiIngameForge.renderHelmet = true; + GuiIngameForge.renderPortal = true; + GuiIngameForge.renderHealthMount = true; + GuiIngameForge.renderJumpBar = true; + GuiIngameForge.renderObjective = true; + + try { + renderHand.set(mc.entityRenderer, true); + } catch(Exception e) { + e.printStackTrace(); + } + + hidden = false; + } +}