Thread: Discord Rich Presence - "Custom" Packets

Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1 Discord Rich Presence - "Custom" Packets 
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    You will need the following dependencies:

    Maven:
    Code:
            <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>
    OR

    Gradle:
    Code:
    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'
    }
    OR

    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:
    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);
        }
    }
    Put your client ID in:
    Code:
    private final String CLIENT_ID = "YOUR_CLIENT_ID";
    In Client.java:
    Code:
    public static final RichPresence RICH_PRESENCE = new RichPresence();
    Find:
    Code:
    public static void main(String[] args) {
    Add:
    Code:
    RICH_PRESENCE.initiate();
    Find:
    Code:
    case 81:
    If there is too many results, make sure you are in the following method:
    Code:
    boolean parsePacket() {
    Find something along the lines of this in that method:
    Code:
    switch (pktType) {
    Add the following:
    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;
    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:
    	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
    		};
    You need to modify packets 131, 132, and 133 to be -1 packet size. So, find the following (atleast, for me):
    Code:
    -1, 0, 0, 0, 9, 0, 0, 0, 0, 0, // 130
    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, -1, -1, -1, 9, 0, 0, 0, 0, 0, // 130
    SERVER-SIDED:

    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:
    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;
        }
    Example:
    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";
    Attached image
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     


  2. #2  
    Extreme Donator


    Join Date
    Jun 2018
    Posts
    58
    Thanks given
    100
    Thanks received
    44
    Rep Power
    1323
    Thanks for the contribution. I'm sure many people will put this to use.
    Reply With Quote  
     

  3. #3  
    Donator


    Join Date
    Sep 2016
    Posts
    131
    Thanks given
    115
    Thanks received
    52
    Rep Power
    77
    This looks awesome, thanks for the snippet!
    If a man does not have the sauce, then he is lost. But the same man can be lost in the sauce.
    Reply With Quote  
     

  4. #4  
    Extreme Donator

    Unzy's Avatar
    Join Date
    Feb 2017
    Posts
    1,086
    Thanks given
    0
    Thanks received
    2,881
    Rep Power
    5000
    Nice work mate.
    Attached image
    Reply With Quote  
     

  5. #5  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    The particular design practice used for running the thread could be improved. The concept is great, thanks for the share!
    Reply With Quote  
     

  6. #6  
    Discord Johnyblob22#7757


    Join Date
    Mar 2016
    Posts
    1,384
    Thanks given
    365
    Thanks received
    575
    Rep Power
    5000
    Nice
    Attached image
    Reply With Quote  
     

  7. #7  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    26
    Posts
    1,474
    Thanks given
    3,312
    Thanks received
    691
    Rep Power
    1098
    Why three packets for what could be one?

    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
    
    
    
    
        }
    
    
    
    
    }
    Gist here.
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Quote Originally Posted by hc747 View Post
    Why three packets for what could be one?

    Code:
    class DiscordRichPresenceUpdate(private val details: String?, private val state: String?, private val key: String?) {
    
    
        fun encode(): PacketBuilder {
            val buffer = PacketBuilder()
    
    
            val builder = PacketBuilder(PACKET_ID, PacketType.BYTE)
            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
    
    
        }
    
    
    }
    Gist here.

    Edit: I see the issue with the mask appearing before the opcode; however, you get the general idea.
    Though I'm not a fan of your approach, I do think this could all be one packet now that I think about it.
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  10. Thankful user:


  11. #9  
    Banned

    Join Date
    Jul 2018
    Posts
    121
    Thanks given
    82
    Thanks received
    55
    Rep Power
    0
    Quote Originally Posted by arham 4 View Post
    Though I'm not a fan of your approach, I do think this could all be one packet now that I think about it.

    What are the packets for like are they really needed could they be stored in the client?

    Edit: looked it over more i did not really had any need for the packets but nice work
    Reply With Quote  
     

  12. Thankful user:


  13. #10  
    Registered Member

    Join Date
    Dec 2009
    Posts
    774
    Thanks given
    367
    Thanks received
    455
    Rep Power
    927
    Quote Originally Posted by hc747 View Post
    Why three packets for what could be one?

    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
    
    
    
    
        }
    
    
    
    
    }
    Gist here.
    I wouldn't use the byte packet header here since you're using strings. Also, you can calculatie the size of the packet by using the length of the strings.
    link removed
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [614] Custom packets
    By ill pk ur as in forum Help
    Replies: 3
    Last Post: 04-05-2011, 11:56 PM
  2. Custom Packet Help
    By ToxicScreams in forum Help
    Replies: 0
    Last Post: 01-21-2010, 05:43 AM
  3. custom packets?
    By R0cky 0wnz in forum Help
    Replies: 26
    Last Post: 12-22-2009, 01:53 PM
  4. My Custom Packet
    By Coombser in forum Help
    Replies: 2
    Last Post: 11-28-2009, 02:57 AM
  5. Adding custom packets
    By Yarnova in forum Tutorials
    Replies: 11
    Last Post: 11-08-2009, 07:18 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •