diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index 2f31ebc..b545280 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -8,7 +8,9 @@ import rt4.Font; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import static rt4.MathUtils.clamp; import static rt4.Player.plane; @@ -270,6 +272,13 @@ public class API { public static void DispatchCommand(String command) { Cheat.sendCheatPacket(JagString.of(command)); } + + public static void Screenshot(String... subfolders) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss"); + String dateTime = dateFormat.format(new Date()); + String username = PlayerList.self != null && PlayerList.self.username != null && !PlayerList.self.username.toString().isEmpty() ? PlayerList.self.username.toString() : "2009Scape"; + client.instance.saveScreenshot( username + "_" + dateTime + ".png", subfolders); + } public static void PlaySound(int volume, int trackId, int delay) { SoundPlayer.play(volume, trackId, delay); diff --git a/client/src/main/java/rt4/client.java b/client/src/main/java/rt4/client.java index fc98275..5ddd87e 100644 --- a/client/src/main/java/rt4/client.java +++ b/client/src/main/java/rt4/client.java @@ -1,14 +1,21 @@ package rt4; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.util.GLReadBufferUtil; import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalClass; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; import plugin.PluginRepository; +import javax.imageio.ImageIO; import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; import java.io.IOException; import java.net.Socket; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Calendar; import java.util.GregorianCalendar; @@ -483,6 +490,71 @@ public final class client extends GameShell { } arg0.pdata(local15, 24); } + + public void saveScreenshot(String filename, String... subfolders) { + String homeDirOverride = System.getProperty("clientHomeOverride"); + String homeDir = null; + String osNameRaw = ""; + String osName = ""; + try { + osNameRaw = System.getProperty("os.name"); + } catch (Exception local48) { + osNameRaw = "Unknown"; + } + osName = osNameRaw.toLowerCase(); + if (homeDirOverride != null) { + homeDir = homeDirOverride; + } else { + try { + if (homeDir == null) + homeDir = System.getProperty("user.home") + File.separatorChar; + + if (osName.startsWith("linux")) { + String xdgHome = System.getenv("XDG_DATA_HOME"); + + if (xdgHome != null) { + homeDir = xdgHome + "/2009scape/"; + } else { + homeDir += ".local/share/2009scape/"; + } + } else if (osName.startsWith("mac")) { + homeDir += "Library/Application Support/2009scape/"; + } else if (osName.startsWith("windows")) { + homeDir += "2009scape\\"; + } + } catch (Exception ex) { + } + } + + String subfolderPath = String.join(File.separator, subfolders); + if (!subfolderPath.isEmpty()) { + subfolderPath += File.separator; + } + + File outputFolder = new File(homeDir + File.separatorChar + "screenshots" + File.separatorChar + subfolderPath); + if (!outputFolder.exists()){ + outputFolder.mkdirs(); + } + + try { + Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); + if (window == null) { + return; + } + Point point = window.getLocationOnScreen(); + int x = (int) point.getX(); + int y = (int) point.getY(); + int w = window.getWidth(); + int h = window.getHeight(); + Robot robot = new Robot(window.getGraphicsConfiguration().getDevice()); + Rectangle captureSize = new Rectangle(x, y, w, h); + BufferedImage image = robot.createScreenCapture(captureSize); + File outputFile = new File(outputFolder, filename); + ImageIO.write(image, "png", outputFile); + } catch (Exception e) { + e.printStackTrace(); + } + } @OriginalMember(owner = "client!lb", name = "a", descriptor = "(Z)V") public static void method2721() { diff --git a/plugin-playground/src/main/kotlin/TakeScreenshot/plugin.kt b/plugin-playground/src/main/kotlin/TakeScreenshot/plugin.kt new file mode 100644 index 0000000..174200a --- /dev/null +++ b/plugin-playground/src/main/kotlin/TakeScreenshot/plugin.kt @@ -0,0 +1,24 @@ +package TakeScreenshot + +import plugin.Plugin +import plugin.annotations.PluginMeta +import plugin.api.API +import java.awt.event.KeyAdapter +import java.awt.event.KeyEvent + +@PluginMeta ( + author = "ipkpjersi", + description = "Allows you to use CRTL + PRINTSCREEN to take a screenshot.", + version = 1.0 +) +class plugin : Plugin() { + override fun Init() { + API.AddKeyboardListener(object : KeyAdapter() { + override fun keyPressed(e: KeyEvent) { + if (e.keyCode == KeyEvent.VK_PRINTSCREEN && e.isControlDown) { + API.Screenshot() + } + } + }) + } +} \ No newline at end of file