mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
Merge branch 'capture-screenshots' into 'master'
Added ability to capture screenshots from within client See merge request 2009scape/rt4-client!16
This commit is contained in:
commit
7298df8792
3 changed files with 105 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
@ -271,6 +273,13 @@ public class API {
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -484,6 +491,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() {
|
||||
SceneGraph.clear();
|
||||
|
|
|
|||
24
plugin-playground/src/main/kotlin/TakeScreenshot/plugin.kt
Normal file
24
plugin-playground/src/main/kotlin/TakeScreenshot/plugin.kt
Normal file
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue