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

Battle.net Client beta breaks capability to launch alternate versions of games #37

Open
dafzor opened this issue Nov 2, 2019 · 6 comments

Comments

@dafzor
Copy link
Owner

dafzor commented Nov 2, 2019

The latest beta of the Battle.net client breaks both methods bnetlauncher was using to start blizzard games:

  • The --exec parameter no longer launches the game.
  • Pressing enter on Battle.net client no longer defaults to the play action.

Not being able to use Enter key breaks the launch of ptr and WoW Classic versions of the game.

@Nyi-code
Copy link

Nyi-code commented Apr 8, 2020

The --exec parameter no longer launches the game.
it does, as long as you already have battle.net.exe running...

@dafzor dafzor changed the title Battle.net Client 1.17 breaks bnetlauncher Battle.net Client 1.17 beta breaks bnetlauncher Sep 22, 2020
@dafzor
Copy link
Owner Author

dafzor commented Sep 22, 2020

Battle.net client 1.23 has had some usability fixes so some progress by blizzard is being made, however enter still does not default to launching the game.

Tested in 1.25.0.12296 beta

@dafzor dafzor changed the title Battle.net Client 1.17 beta breaks bnetlauncher Battle.net Client beta breaks capability to launch alternate versions of games Nov 28, 2020
@dafzor
Copy link
Owner Author

dafzor commented Mar 23, 2021

Update on the issue, beta is now released with enter key functionality still removed. So launching alternative versions of games is still broken.

A proof of concept been done on trying to find a button in a window and sending a mouse click event but it's not very elegant or robust.

That said I currently not inclined to invest the time into bnetlauncher to re-implement the feature.

@dafzor
Copy link
Owner Author

dafzor commented Apr 2, 2021

So had some time this long weekend and made an experimental fix for those brave enough to try it

@behzad62
Copy link

I would suggest looking for more than one pixel color match to make it more robust in the case there is a pixel with a same color somewhere else in the Battle.net client window.
The code below should be able to find the button location within the Bnet client in few milliseconds, given the bitmap of the client window.

unsafe Point? FindButtonLocation(Bitmap bitmap, Color btnColor)
            {
                int bytesPerPixel = 4;
                const int neededMatchPixelColors = 100;
                Size focusSize = new Size(10, 10);
                System.Drawing.Imaging.BitmapData mapSource = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
                int scanStride = bitmap.Width * bytesPerPixel;
                byte* scanFirstPixel = (byte*)mapSource.Scan0;
                Point? btnLocation = null;
                for(int y = bitmap.Height / 2; y < bitmap.Height; y++)
                {
                    byte* currentLine = scanFirstPixel + (y * scanStride);
                    for (int x = 0; x < scanStride / 3; x += bytesPerPixel)
                    {
                        var currentScreenPosition = new Point(x / bytesPerPixel, y);
                        byte A = currentLine[x + 3];
                        byte R = currentLine[x + 2];
                        byte G = currentLine[x + 1];
                        byte B = currentLine[x];
                        bool mainPixelFound = A == btnColor.A && R == btnColor.R && G == btnColor.G && B == btnColor.B;
                        if (!mainPixelFound)
                            continue;
                        int checkPixelsFound = 0;
                        bool allcheckPixelsFound = checkPixelsFound == neededMatchPixelColors;
                        if (!allcheckPixelsFound)
                        {
                            var mainPixelLocation = new Point(x / bytesPerPixel, y);//relative to the scan region
                            var focusRegion = GetScanRegionAroundMainPixel(mainPixelLocation, focusSize);//relative to the scan region
                            byte* focusFirstPixel = scanFirstPixel + (focusRegion.Y * scanStride) + focusRegion.X * bytesPerPixel;
                            int focusStride = focusRegion.Width * bytesPerPixel;
                            for (int j = 0; j < focusRegion.Height; j++)
                            {
                                byte* focustLine = focusFirstPixel + (j * scanStride);
                                for (int i = 0; i < focusStride; i += bytesPerPixel)
                                {
                                    A = focustLine[i + 3];
                                    R = focustLine[i + 2];
                                    G = focustLine[i + 1];
                                    B = focustLine[i];
                                    bool checkPixelFound = A == btnColor.A && R == btnColor.R && G == btnColor.G && B == btnColor.B;
                                    if (checkPixelFound)
                                    {
                                        checkPixelsFound++;
                                        allcheckPixelsFound = checkPixelsFound == neededMatchPixelColors;
                                    }
                                    if (allcheckPixelsFound)
                                    {
                                        bitmap.UnlockBits(mapSource);
                                        btnLocation = currentScreenPosition;
                                        return btnLocation;
                                    }
                                }
                            }
                        }
                    }
                }
                bitmap.UnlockBits(mapSource);
                return btnLocation;

                Rectangle GetScanRegionAroundMainPixel(Point currentLocation, Size focusScanSize)
                {
                    Point centerPoint = new Point(currentLocation.X - focusScanSize.Width / 2, currentLocation.Y - focusScanSize.Height / 2);//adjust point to be center of rectangle
                    return new Rectangle(centerPoint, focusScanSize);
                }
            }

@dafzor
Copy link
Owner Author

dafzor commented Oct 4, 2021

@SilverSaw has done some testing in #56 (comment) which shows the flaws of current implementation.

Issues to resolve

  • Unreliable method to obtain main game window
  • Single pixel match instead of "zone"

I'm opening the project to Pull request targeted at fixing this issue.

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

No branches or pull requests

3 participants