Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Love the project; having an issue with canvas logged in. #64

Closed
FindZach opened this issue Jun 26, 2020 · 4 comments
Closed

[BUG] Love the project; having an issue with canvas logged in. #64

FindZach opened this issue Jun 26, 2020 · 4 comments
Assignees
Labels
bug Denotes that this a bug

Comments

@FindZach
Copy link

FindZach commented Jun 26, 2020

https://i.gyazo.com/ee7aaf8ae1165ab21d51a49152b617e2.mp4

If I switch the script to the test script

https://i.gyazo.com/d92f15046cbea11fed113e1ab3dbe0be.mp4

It's something to do with the canvas class; if I find a fix I will post here

**Unofficial Fix - Works for me

Replace your BotHooks#draw method with mine**

@Override
public void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y) {
    try {


        //Preferably initialize the value of bot with the current bot on screen
       // IE Application.getBot or similar manner.



        if (graphics == null) {
            return;
        }
        // We only want do do this once because this would MASSIVELY affect performance.


        /*
        if (SUPERCLASS_MAP.get(SUPERCLASS_MAP.keySet().iterator().next()) == null) {

            for (Method method : this.getClass().getSuperclass().getDeclaredMethods()) {
                Iterator itr = SUPERCLASS_MAP.keySet().iterator();
                while (itr.hasNext()) {
                    String name = (String) itr.next();
                    if (method.getName().equals(name)) {
                        method.setAccessible(true);
                        SUPERCLASS_MAP.replace(name, null, method);
                    }
                }
            }
            for (Field field : this.getClass().getSuperclass().getDeclaredFields()) {
                Iterator itr = SUPERCLASS_MAP.keySet().iterator();
                while (itr.hasNext()) {
                    String name = (String) itr.next();
                    if (field.getName().equals(name)) {
                        field.setAccessible(true);
                        SUPERCLASS_MAP.replace(name, null, field);
                    }
                }
            }
        }*/

        //We then simply invoke the method as needed here. It should perform similar to how it does in RuneLite
        //final Graphics2D graphics2d = (Graphics2D) ((Method) SUPERCLASS_MAP.get(GETGRAPHICS)).invoke(this,
         //       mainBufferProvider);

        Image image = mainBufferProvider.getImage();
        // finalImage is backed by the client buffer which will change soon. make a copy
        // so that callbacks can safely use it later from threads.
        drawManager.processDrawComplete(() -> copy(image));

        final Graphics2D g2d = (Graphics2D) bot.getCanvas().getGraphics(bot, mainBufferProvider);

        // Draw the image onto the game canvas
        //graphics.drawImage(image, 0, 0, bot.getCanvas());

        g2d.drawImage(image, 0, 0, bot.getCanvas());


    } catch (Exception e) {
        e.printStackTrace();
        //log.warn("Bot hooks failed to paint properly");
    }
}
@FindZach FindZach added the bug Denotes that this a bug label Jun 26, 2020
@FindZach
Copy link
Author

FindZach commented Jun 26, 2020

Update the issue was coming from the

BotHooks#draw(MainBufferProvider, Graphics, x, y) method

Commented out the draw method inside of the method above

        // Draw the image onto the game canvas
        //graphics.drawImage(image, 0, 0, bot.getCanvas());

@FindZach
Copy link
Author

**Unofficial Fix - Works for me

Replace your BotHooks#draw method with mine**

    @Override
    public void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y) {
        try {


            //Preferably initialize the value of bot with the current bot on screen
           // IE Application.getBot or similar manner.



            if (graphics == null) {
                return;
            }
            // We only want do do this once because this would MASSIVELY affect performance.


            /*
            if (SUPERCLASS_MAP.get(SUPERCLASS_MAP.keySet().iterator().next()) == null) {

                for (Method method : this.getClass().getSuperclass().getDeclaredMethods()) {
                    Iterator itr = SUPERCLASS_MAP.keySet().iterator();
                    while (itr.hasNext()) {
                        String name = (String) itr.next();
                        if (method.getName().equals(name)) {
                            method.setAccessible(true);
                            SUPERCLASS_MAP.replace(name, null, method);
                        }
                    }
                }
                for (Field field : this.getClass().getSuperclass().getDeclaredFields()) {
                    Iterator itr = SUPERCLASS_MAP.keySet().iterator();
                    while (itr.hasNext()) {
                        String name = (String) itr.next();
                        if (field.getName().equals(name)) {
                            field.setAccessible(true);
                            SUPERCLASS_MAP.replace(name, null, field);
                        }
                    }
                }
            }*/

            //We then simply invoke the method as needed here. It should perform similar to how it does in RuneLite
            //final Graphics2D graphics2d = (Graphics2D) ((Method) SUPERCLASS_MAP.get(GETGRAPHICS)).invoke(this,
             //       mainBufferProvider);

            Image image = mainBufferProvider.getImage();
            // finalImage is backed by the client buffer which will change soon. make a copy
            // so that callbacks can safely use it later from threads.
            drawManager.processDrawComplete(() -> copy(image));

            final Graphics2D g2d = (Graphics2D) bot.getCanvas().getGraphics(bot, mainBufferProvider);

            // Draw the image onto the game canvas
            //graphics.drawImage(image, 0, 0, bot.getCanvas());

            g2d.drawImage(image, 0, 0, bot.getCanvas());


        } catch (Exception e) {
            e.printStackTrace();
            //log.warn("Bot hooks failed to paint properly");
        }
    }

@GigiaJ
Copy link
Collaborator

GigiaJ commented Jul 2, 2020

Looks good, I'll check in a bit to make sure it works properly. Basically what happens on
final Graphics2D g2d = (Graphics2D) bot.getCanvas().getGraphics(bot, mainBufferProvider);
is that it allows the bot canvas to be passed the MainBufferProvider for use in getBufferGraphics
It simply allows overlay from the bot to be painted onto the canvas and stores the buffer on the variable back. (Might be unnecessary, but a good bit of the code is just an inefficient port.)

Not sure what could've caused it to have any issues.

@GigiaJ
Copy link
Collaborator

GigiaJ commented Aug 19, 2020

Been a bit, but I just got around to checking after porting a completely different code base to use with this.

Seems your change causes the bot to fail to display at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Denotes that this a bug
Projects
None yet
Development

No branches or pull requests

2 participants