|
You will need the following dependencies:
Maven:
ORCode:<dependency> <groupId>com.github.MinnDevelopment</groupId> <artifactId>java-discord-rpc</artifactId> <version>v1.3.1</version> </dependency> <dependency> <groupId>com.github.MinnDevelopment</groupId> <artifactId>discord-rpc-release</artifactId> <version>v3.3.0</version> </dependency>
Gradle:
ORCode:repositories { jcenter() maven { url 'https://jitpack.io/' } } dependencies { compile 'com.github.MinnDevelopment:java-discord-rpc:v1.3.1' compile 'com.github.MinnDevelopment:discord-rpc-release:v3.3.0' }
Download link:
Sucky library, I know.
DISCORD-SIDED:
Go to:
https://discordapp.com/developers/applications/
Create an application. Name it your server's name and set the pictures as you feel. Look up a video for more info. Keep in mind the client ID is here.
CLIENT-SIDED:
Make a new file called RichPresence.java and put this in it:
Put your client ID in:Code:import club.minnced.discord.rpc.DiscordEventHandlers; import club.minnced.discord.rpc.DiscordRPC; import club.minnced.discord.rpc.DiscordRichPresence; /** * @author Arham 4 */ public class RichPresence { private final String CLIENT_ID = "YOUR_CLIENT_ID"; private DiscordRPC lib; private DiscordRichPresence presence; public void initiate() { lib = DiscordRPC.INSTANCE; DiscordEventHandlers handlers = new DiscordEventHandlers(); lib.Discord_Initialize(CLIENT_ID, handlers, true, ""); presence = new DiscordRichPresence(); presence.startTimestamp = System.currentTimeMillis() / 1000; presence.largeImageKey = "YOUR_LARGE_IMAGE_KEY"; presence.smallImageKey = "YOUR_SMALL_IMAGE_KEY"; updatePresence(); new Thread(() -> { while (!Thread.currentThread().isInterrupted()) { lib.Discord_RunCallbacks(); try { Thread.sleep(2000); } catch (InterruptedException ignored) {} } }, "RPC-Callback-Handler").start(); } public boolean presenceIsNull() { return presence == null; } public void updateDetails(String details) { presence.details = details; updatePresence(); } public void updateState(String state) { presence.state = state; updatePresence(); } public void updateSmallImageKey(String key) { presence.smallImageKey = key; updatePresence(); } private void updatePresence() { lib.Discord_UpdatePresence(presence); } }
In Client.java:Code:private final String CLIENT_ID = "YOUR_CLIENT_ID";
Find:Code:public static final RichPresence RICH_PRESENCE = new RichPresence();
Add:Code:public static void main(String[] args) {
Find:Code:RICH_PRESENCE.initiate();
If there is too many results, make sure you are in the following method:Code:case 81:
Find something along the lines of this in that method:Code:boolean parsePacket() {
Add the following:Code:switch (pktType) {
Now, I'm not sure where your size constants are. Basically, this is an array that has the packet sizes for all your packets. In the client that comes with Ruse, these are in the SizeConstants.java file and the array is called PACKET_SIZES. It'll appear something along the lines of this:Code:case 131: String details = getInputBuffer().getString(); RICH_PRESENCE.updateDetails(details); pktType = -1; return true; case 132: String state = getInputBuffer().getString(); RICH_PRESENCE.updateState(state); pktType = -1; return true; case 133: String key = getInputBuffer().getString(); RICH_PRESENCE.updateSmallImageKey(key); pktType = -1; return true;
You need to modify packets 131, 132, and 133 to be -1 packet size. So, find the following (atleast, for me):Code:public static final int[] PACKET_SIZES = { 0, 0, 0, 1, 6, 0, 0, 0, 4, 0, //0 0, 2, -1, 1, 1, -1, 1, 0, 0, 0, // 10 0, 0, 0, 0, 1, 0, 0, -1, 1, 1, //20 0, 0, 0, 0, -2, 4, 3, 0, 2, 0, //30 0, 0, 0, 0, 11, 8, 0, 6, 0, 0, //40 9, 0, 0, -2, 0, 0, 0, 0, 0, 0, //50 -2, 1, 0, 0, 2, -2, 0, 0, 0, 0, //60 6, 3, 2, 4, 2, 4, 0, 0, 0, 4, //70 0, -2, 0, 0, 7, 2, 1, 6, 6, 0, //80 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, //90 2, 2, 0, 1, -1, 4, 1, 0, 1, 0, //100 1, 1, 1, 1, 2, 1, 0, 15, 0, 0, //110 0, 4, 4, -1, 9, -1, -2, 1, 0, 0, //120 // 9 -1, 0, 0, 0, 9, 0, 0, 0, 0, 0, // 130 3, 10, 2, 0, 0, 0, 0, 14, 0, 0, //140 0, 4, 3, 3, 0, 0, 3, 0, 0, 0, //150 4, 5, 0, 0, 2, 0, 6, 0, 0, 0, //160 //0, 3, /*0*/ -1, 0, 5, 7, 10, 6, 5, 1, //170 0, 3, -2, -2, 5, 5, 10, 6, 5, -2, // 170 0, 0, 0, 0, 0, 2, 0, -1, 0, 0, //180 0, 0, 0, 0, 0, 2, -1, 0, -1, 0, //190 4, 0, 0, 0, 0, 0, 3, 0, 2, 0, //200 0, 0, 0, 0, -2, 7, 0, -2, 2, 0, //210 4, 1, 0, 4, 0, 0, 0, 0, 0, 0, // 220 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,//230 2, -2, 0, 0, -1, 0, 6, 0, 4, 3,//240 -1, 0, 0, -1, 6, 0, 0//250 };
This has the sizes for packets 130, 131, 132, 133, 134, 135, 136, 137, 138, and 139, in that order. Thus, change the 2nd, 3rd, and 4th numbers to -1, as such:Code:-1, 0, 0, 0, 9, 0, 0, 0, 0, 0, // 130
SERVER-SIDED:Code:-1, -1, -1, -1, 9, 0, 0, 0, 0, 0, // 130
Now, let's make packets server-sided to send custom info to our Discord rich presence. The following is for Ruse, you will need to modify it for your own needs. Add the following to PacketSender:
Example:Code:public PacketSender sendRichPressenceDetails(String details) { PacketBuilder out = new PacketBuilder(131, PacketType.BYTE); out.putString(details); player.getSession().queueMessage(out); return this; } public PacketSender sendRichPressenceState(String state) { PacketBuilder out = new PacketBuilder(132, PacketType.BYTE); out.putString(state); player.getSession().queueMessage(out); return this; } public PacketSender sendSmallImageKey(String key) { PacketBuilder out = new PacketBuilder(133, PacketType.BYTE); out.putString(key); player.getSession().queueMessage(out); return this; }
Code:player.getPacketSender().sendSmallImageKey("fabulous"); // 'fabulous' is the name of the gnome child image. player.getPacketSender().sendRichPresenceDetails("haha this works"); player.getPacketSender().sendRichPresenceState("interesting, this too"); // the RuneRoyale logo is showing because it was set in the RichPresence class in the client at: // presence.largeImageKey = "YOUR_LARGE_IMAGE_KEY"; // you may also have a default small image key in that class too: // presence.smallImageKey = "YOUR_SMALL_IMAGE_KEY";
Thanks for the contribution. I'm sure many people will put this to use.
This looks awesome, thanks for the snippet!
Nice work mate.
Nice
Why three packets for what could be one?
Gist here.Code:class DiscordRichPresenceUpdate(private val details: String?, private val state: String?, private val key: String?) { fun encode(): PacketBuilder { val buffer = PacketBuilder(PACKET_ID, PacketType.BYTE) val builder = PacketBuilder() var mask: Byte = 0 if (details != null) { mask = mask xor DETAILS_MASK builder.putString(details) } if (state != null) { mask = mask xor STATE_MASK builder.putString(state) } if (key != null) { mask = mask xor KEY_MASK builder.putString(key) } buffer.putByte(mask) builder.writeTo(buffer) return buffer } companion object { const val PACKET_ID = 131 const val DETAILS_MASK: Byte = 0x1 const val STATE_MASK: Byte = 0x2 const val KEY_MASK: Byte = 0x4 //leaves 5 bits reserved for later usage } }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |