Thread: Console

Results 1 to 2 of 2
  1. #1 Console 
    Extreme Donator
    Market Banned Market Banned


    Mark.'s Avatar
    Join Date
    Jul 2020
    Posts
    149
    Thanks given
    98
    Thanks received
    151
    Discord
    View profile
    Rep Power
    294
    Hey, guys so for my second post I thought ill release a snippet on some console upgrades I did this is what you're adding.



    Features:
    • Resizing
    • Command History
    • Copy and paste
    • Editing input using left and right arrow keys
    • Command System


    If you have any issues add me on discord or if you want to request a change just post blow


    Code:
    package com.runescape.draw.console;
    
    import com.runescape.Client;
    
    public interface Command {
    
        abstract void execute(Console console, String command, String[] parts);
    
        abstract boolean canUse(Client client);
    
    }
    Code:
    public class CommandManager {
    
        public static final Map<String, Command> commands = new HashMap<String, Command>();
        
        private static void put(Command command, String... keys) {
            for (String key : keys) {
                commands.put(key, command);
            }
        }
        
        public static void loadCommands() {
            commands.clear();
            
            /**
             * Players Command
             */
            put(new TestCommand(), "test");
    
        }
    
        static {
            loadCommands();
        }
    }
    Code:
    package com.runescape.draw.console;
    
    import com.runescape.Client;
    import com.runescape.draw.Rasterizer2D;
    
    import java.awt.*;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.awt.event.KeyEvent;
    import java.io.IOException;
    import java.util.ArrayList;
    import static com.runescape.Client.screenAreaHeight;
    import static com.runescape.Client.tick;
    
    public class Console {
    
    
        private final int inputLimit = 80; //Input limit for the command box
        private final int height = 140; //Default height of the client
        private int keyPosition = 0;  //Position of the char input
        private int historyPosition = -1;  //Position of the char input
        public boolean consoleOpen;  //If the console is open
        private String consoleInput = ""; //Console Input string
        private ArrayList<String> consoleInputs = new ArrayList<>();  //List of past inputs
        private ArrayList<String> consoleMessages = new ArrayList<>();  //List of messages in the console that was sent
        private final Client client; //Instance of the Client
        private final String startMessage = "This is the developer console. To close, press the ` key on your keyboard.";
        public boolean extendingConsole;
        public int extraConsoleY;
    
        /**
         * Initialize the console
         * @Param client Client class
         */
        public Console(Client client) {
            this.client = client;
            CommandManager.loadCommands();
            consoleMessages.add(startMessage);
        }
    
        /**
         *  Draws the console on screen
         */
        public void drawConsole() {
            if (consoleOpen) {
                Rasterizer2D.drawTransparentBox(0, 0, Client.frameWidth, height + extraConsoleY, 5320850, 200);
                Rasterizer2D.drawHorizontalLine(0, height - 15 + extraConsoleY, Client.frameWidth, 0x979797);
                Rasterizer2D.drawHorizontalLine(0, height + extraConsoleY, Client.frameWidth, 0x979797);
                client.newSmallFont.drawBasicString("> " + consoleInput, 10, height - 3 + extraConsoleY, 0xFFFFFF, 0);
    
                client.newSmallFont.drawBasicString(((tick % 40 < 20) ? "_" : ""), 10 + client.newSmallFont.getTextWidth("> " + consoleInput), height - 2 + extraConsoleY, 0xFFFFFF, 0);
    
    
                if(Client.instance.clickMode3 == 1 &&  Client.instance.clickInRegion(0,0,Client.frameWidth,height + extraConsoleY)) {
                    extendingConsole = true;
                }
    
    
                Rasterizer2D.setDrawingArea(height - 18 + extraConsoleY, 0, Client.frameWidth, 4);
                int yPos = height - 20;
                for (int index = consoleMessages.size() - 1; index >= 0; index--) {
                    client.newSmallFont.drawBasicString(consoleMessages.get(index), 10, yPos + extraConsoleY, 0xFFFFFF, 0);
                    yPos -= 13;
    
                }
                Rasterizer2D.defaultDrawingAreaSize();
            }
        }
    
    
        public void processExtend() {
    
            if (extendingConsole) {
                if(Client.frameMode == Client.ScreenMode.FIXED) {
                    if(Client.instance.mouseY <= screenAreaHeight - 150) {
                        extraConsoleY = Client.instance.mouseY;
                    }
                }
            }
    
        }
    
        /**
         *  Manages the inputs for this console
         */
        private void handleConsoleInput() {
            String input = consoleInput;
            if(!input.equals("")) {
                consoleInputs.add(input);
                consoleInput = "";
                String[] parts = input.split(" ");
                parts[0] = parts[0].toLowerCase();
    
                Command command = CommandManager.commands.get(parts[0]);
                if (command != null) {
                    if (command.canUse(client)) {
                        consoleMessages.add("> " + input);
                        command.execute(this, input, parts);
                    }
                } else {
                    sendMessage("This command does not exist.");
                }
            }
        }
    
        /**
         * Sends a command message to the user
         * @Param message Message sent to the console
         */
        public void sendMessage(String message) {
            consoleMessages.add(message);
        }
    
        /**
         * Manages the key inputs for this console
         * @Param keyEvent key event
         */
        public void parseKeyForConsole(KeyEvent keyEvent) {
            if(keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
                if(consoleInput.length() > 0 && keyPosition != 0) {
                    StringBuilder sb = new StringBuilder(consoleInput);
                    sb.deleteCharAt(keyPosition - 1);
                    consoleInput = sb.toString();
                    keyPosition--;
                }
            } else if(keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                handleConsoleInput();
                keyPosition = 0;
                historyPosition = 0;
            } else if(keyEvent.isControlDown() && keyEvent.getKeyCode() == KeyEvent.VK_V) {
                try {
                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                    Transferable contents = clipboard.getContents(null);
                    boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
                    if(hasTransferableText) {
                        System.out.println("Paste Text");
                        consoleInput += (String)contents.getTransferData(DataFlavor.stringFlavor);
                    }
                } catch (UnsupportedFlavorException | IOException e) {
                    e.printStackTrace();
                }
            } else if(keyEvent.getKeyCode() == KeyEvent.VK_LEFT) {
                    if(keyPosition != 0) {
                        keyPosition--;
                    }
            } else if(keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) {
                if(keyPosition != consoleInput.length()) {
                    keyPosition++;
                }
            } else if(keyEvent.getKeyCode() == KeyEvent.VK_UP) {
                if(consoleInputs != null) {
                    if(consoleInputs.size() != 0 &&  consoleInputs.size() > historyPosition) {
                        consoleInput = consoleInputs.get(historyPosition + 1);
                        historyPosition += 1;
                        keyPosition = consoleInputs.get(historyPosition + 1).length();
                    }
                }
            } else if(keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
                if(consoleInputs != null) {
                    if(consoleInputs.size() != 0 &&  consoleInputs.size() > historyPosition) {
                        consoleInput = consoleInputs.get(historyPosition - 1);
                        historyPosition -= 1;
                        keyPosition = consoleInputs.get(historyPosition - 1).length();
                    }
                }
            } else {
                if (keyEvent.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
                    if(consoleInput.length() <= inputLimit) {
                        StringBuilder sb = new StringBuilder(consoleInput);
                        sb.insert(keyPosition,keyEvent.getKeyChar());
                        keyPosition++;
                        consoleInput = sb.toString();
                    }
                }
            }
        }
    
    
    }
    Command Exmaple:

    Code:
    package com.runescape.draw.console.impl;
    
    import com.runescape.Client;
    import com.runescape.draw.console.Command;
    import com.runescape.draw.console.Console;
    
    public class TestCommand implements Command {
    
        @Override
        public void execute(Console console, String command, String[] parts) {
            console.sendMessage("hey i found you woop");
        }
    
        @Override
        public boolean canUse(Client client) {
            return true;
        }
    }
    Client.java


    Code:
    public Console console = new Console(this);
    next find processRightClick and under anInt1315 = 0;

    add

    Code:
     if(console.consoleOpen) {return;}
    now find if (atInventoryInterfaceType == 3) and add

    Code:
    console.processExtend();
    Finally find
    Code:
    draw3dScreen();
    under it add this

    Code:
    if(console.consoleOpen) {
                console.drawConsole();
            }

    GameApplet

    Find mouseReleased at the very bottom add

    Code:
    Client.instance.console.extendingConsole = false;
    Find keyPressed at the very top below where it gets the keycodes add

    keyPressed

    Code:
    if(keyevent.getKeyCode() == 192) {
                Client.instance.console.consoleOpen = ! Client.instance.console.consoleOpen;
                return;
            }
    
            if(Client.instance.console.consoleOpen) {
                Client.instance.console.parseKeyForConsole(keyevent);
                return;
            }
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Join Date
    Nov 2019
    Posts
    28
    Thanks given
    5
    Thanks received
    1
    Rep Power
    11
    Nice!
    Reply With Quote  
     


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. Runescape for all consoles ?
    By Makam in forum Voting
    Replies: 32
    Last Post: 03-20-2008, 12:06 AM
  2. looking for a console
    By Bowle in forum Tools
    Replies: 5
    Last Post: 02-03-2008, 09:05 AM
  3. Console Commands [OLD]
    By PeeHPee in forum Tutorials
    Replies: 4
    Last Post: 12-15-2007, 01:05 AM
  4. Timestamping your console
    By twostars in forum Tutorials
    Replies: 3
    Last Post: 11-13-2007, 02:42 PM
  5. Console Commands
    By ZeroFreeze in forum Tutorials
    Replies: 7
    Last Post: 04-30-2007, 12:53 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •