mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 06:51:32 +01:00
Screenshot Manager
This commit is contained in:
parent
b668956d89
commit
dcb8a74264
@ -0,0 +1,15 @@
|
||||
package net.silentclient.client.event.impl;
|
||||
|
||||
import net.silentclient.client.event.EventCancelable;
|
||||
|
||||
public class RunCommandEvent extends EventCancelable {
|
||||
private final String command;
|
||||
|
||||
public RunCommandEvent(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package net.silentclient.client.mixin.mixins;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.silentclient.client.event.impl.RunCommandEvent;
|
||||
import net.silentclient.client.utils.ResolutionHelper;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -30,4 +31,14 @@ public class GuiScreenMixin {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "handleComponentClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;sendChatMessage(Ljava/lang/String;Z)V"))
|
||||
public void event(GuiScreen instance, String msg, boolean addToChat) {
|
||||
RunCommandEvent event = new RunCommandEvent(msg);
|
||||
event.call();
|
||||
|
||||
if(!event.isCancelable()) {
|
||||
instance.sendChatMessage(msg, addToChat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import net.minecraft.client.shader.Framebuffer;
|
||||
import net.minecraft.client.stream.IStream;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.ScreenShotHelper;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.event.impl.*;
|
||||
import net.silentclient.client.gui.GuiNews;
|
||||
@ -36,6 +38,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MinecraftMixin {
|
||||
@Inject(method = "startGame", at = @At("HEAD"))
|
||||
@ -103,6 +107,10 @@ public abstract class MinecraftMixin {
|
||||
|
||||
@Shadow public EntityRenderer entityRenderer;
|
||||
|
||||
@Shadow @Final public File mcDataDir;
|
||||
|
||||
@Shadow private Framebuffer framebufferMc;
|
||||
|
||||
@Inject(method = "displayGuiScreen", at = @At("RETURN"), cancellable = true)
|
||||
public void displayGuiScreenInject(GuiScreen guiScreenIn, CallbackInfo ci) {
|
||||
if(Client.backgroundPanorama == null) {
|
||||
@ -247,4 +255,9 @@ public abstract class MinecraftMixin {
|
||||
return (char) (Keyboard.getEventCharacter() + 256);
|
||||
}
|
||||
//#endif
|
||||
|
||||
@Redirect(method = "dispatchKeypresses", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;printChatMessage(Lnet/minecraft/util/IChatComponent;)V", ordinal = 1))
|
||||
public void cancelChatMessage(GuiNewChat instance, IChatComponent chatComponent) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package net.silentclient.client.mixin.mixins;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.shader.Framebuffer;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.ScreenShotHelper;
|
||||
import net.silentclient.client.utils.AsyncScreenshots;
|
||||
import net.silentclient.client.utils.Multithreading;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
@Mixin(ScreenShotHelper.class)
|
||||
public class ScreenShotHelperMixin {
|
||||
@Shadow private static IntBuffer pixelBuffer;
|
||||
@Shadow private static int[] pixelValues;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@Inject(method = "saveScreenshot(Ljava/io/File;Ljava/lang/String;IILnet/minecraft/client/shader/Framebuffer;)Lnet/minecraft/util/IChatComponent;", at = @At("HEAD"), cancellable = true)
|
||||
private static void silent$screenshotManager(File gameDirectory, String screenshotName, int width, int height, Framebuffer buffer, CallbackInfoReturnable<IChatComponent> cir) {
|
||||
File screenshotDirectory = new File(Minecraft.getMinecraft().mcDataDir, "screenshots");
|
||||
if (!screenshotDirectory.exists()) {
|
||||
screenshotDirectory.mkdir();
|
||||
}
|
||||
if (OpenGlHelper.isFramebufferEnabled()) {
|
||||
width = buffer.framebufferTextureWidth;
|
||||
height = buffer.framebufferTextureHeight;
|
||||
}
|
||||
int scale = width * height;
|
||||
if (pixelBuffer == null || pixelBuffer.capacity() < scale) {
|
||||
pixelBuffer = BufferUtils.createIntBuffer(scale);
|
||||
pixelValues = new int[scale];
|
||||
}
|
||||
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
|
||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||
pixelBuffer.clear();
|
||||
if (OpenGlHelper.isFramebufferEnabled()) {
|
||||
GlStateManager.bindTexture(buffer.framebufferTexture);
|
||||
GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
|
||||
} else {
|
||||
GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixelBuffer);
|
||||
}
|
||||
pixelBuffer.get(pixelValues);
|
||||
Multithreading.runAsync(new AsyncScreenshots(width, height, pixelValues, screenshotDirectory));
|
||||
|
||||
cir.setReturnValue(null);
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import javax.imageio.ImageIO;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiNewChat;
|
||||
import net.minecraft.event.ClickEvent;
|
||||
import net.minecraft.event.HoverEvent;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
@ -82,22 +83,22 @@ public class AsyncScreenshots implements Runnable {
|
||||
IChatComponent chatComponent;
|
||||
chatComponent = new ChatComponentText("SC Sceenshot");
|
||||
|
||||
// final IChatComponent deleteComponent = new ChatComponentText(EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD +
|
||||
//"[DELETE]");
|
||||
// deleteComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_SCREEN_COMMAND, "/$delete"));
|
||||
//
|
||||
// final IChatComponent copyComponent = new ChatComponentText(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD +
|
||||
// "[COPY]");
|
||||
// copyComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_SCREEN_COMMAND, "/$copyss"));
|
||||
final IChatComponent deleteComponent = new ChatComponentText(EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD +
|
||||
"[DELETE]");
|
||||
deleteComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/$delete"));
|
||||
|
||||
final IChatComponent copyComponent = new ChatComponentText(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD +
|
||||
"[COPY]");
|
||||
copyComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/$copyss"));
|
||||
|
||||
final IChatComponent folderComponent = new ChatComponentText(EnumChatFormatting.BLUE.toString() + EnumChatFormatting.BOLD +
|
||||
"[OPEN]");
|
||||
folderComponent.getChatStyle()
|
||||
.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, screenshotDirectory.getCanonicalPath()));
|
||||
.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, screenshot.getCanonicalPath()));
|
||||
|
||||
chatComponent.appendText(" ").appendSibling(folderComponent);
|
||||
// chatComponent.appendText(" ").appendSibling(copyComponent);
|
||||
// chatComponent.appendText(" ").appendSibling(deleteComponent);
|
||||
chatComponent.appendText(" ").appendSibling(copyComponent);
|
||||
chatComponent.appendText(" ").appendSibling(deleteComponent);
|
||||
|
||||
final GuiNewChat chat = mc.ingameGUI.getChatGUI();
|
||||
chat.printChatMessage(chatComponent);
|
||||
@ -118,18 +119,6 @@ public class AsyncScreenshots implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// public static class UploadScreenshot extends Command {
|
||||
//
|
||||
// public UploadScreenshot() {
|
||||
// super("$upload", true, true);
|
||||
// }
|
||||
//
|
||||
// @DefaultHandler
|
||||
// public void handle() {
|
||||
// UploadScreenshotTask.INSTANCE.execute(screenshot);
|
||||
// }
|
||||
// }
|
||||
|
||||
static class ImageSelection implements Transferable {
|
||||
private final Image image;
|
||||
|
||||
|
@ -7,6 +7,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import net.silentclient.client.event.EventTarget;
|
||||
import net.silentclient.client.event.impl.RunCommandEvent;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -41,10 +43,10 @@ public class ScreenshotManager {
|
||||
public BufferedImage getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void command(String msg) {
|
||||
Client.logger.info(msg);
|
||||
switch(msg) {
|
||||
|
||||
@EventTarget()
|
||||
public void command(RunCommandEvent event) {
|
||||
switch(event.getCommand()) {
|
||||
case "/$openfolder":
|
||||
File file1 = new File(mc.mcDataDir, "screenshots");
|
||||
String s = file1.getAbsolutePath();
|
||||
@ -96,25 +98,28 @@ public class ScreenshotManager {
|
||||
Client.logger.info("Opening via system class!");
|
||||
Sys.openURL("file://" + s);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
case "/$delete":
|
||||
try {
|
||||
if (screenshot.exists() && screenshot.delete()) {
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + screenshot.getName() + " has been deleted."));
|
||||
NotificationUtils.showNotification("success", "Image has been deleted.");
|
||||
screenshot = null;
|
||||
} else {
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Couldn't find " + screenshot.getName()));
|
||||
NotificationUtils.showNotification("success", "Couldn't find image.");
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
case "/$copyss":
|
||||
try {
|
||||
copyScreenshot(true);
|
||||
} catch(Exception e) {
|
||||
|
||||
NotificationUtils.showNotification("success", e.getMessage());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -128,7 +133,7 @@ public class ScreenshotManager {
|
||||
Multithreading.runAsync(() -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null));
|
||||
|
||||
if (message) {
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Screenshot has been copied to your clipboard."));
|
||||
NotificationUtils.showNotification("success", "Image copied!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@
|
||||
"mixins.PacketThreadUtilMixin",
|
||||
"mixins.ServerAddressMixin",
|
||||
"mixins.ServerListMixin",
|
||||
"mixins.EntityPacketsMixin"
|
||||
"mixins.EntityPacketsMixin",
|
||||
"mixins.ScreenShotHelperMixin"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user