/// <summary> /// Determines if the client is logged out /// </summary> /// <returns>true if we are verifiably logged out</returns> public bool IsLoggedOut(bool readWindow = false) { if (readWindow && !ReadWindow()) { RunParams.LoggedIn = false; return(false); } Color color; Point loginOffset = LoginScreenOffset(); int height = Height; int top = loginOffset.Y; int centerX = Center.X + loginOffset.X; int checkRow = Math.Min(Math.Max(0, height - 1), loginOffset.Y + ScreenScraper.LOGIN_WINDOW_HEIGHT + 1); //1 pixel below where the bottom of the login window should be int xOffset = (ScreenScraper.LOGIN_WINDOW_WIDTH / 2) + 2; int blackPixels = 0; int totalPixels = 0; for (int x = centerX - xOffset; x < centerX + xOffset; x++) { //check bottom of login box color = Value[x, checkRow]; blackPixels += ImageProcessing.ColorsAreEqual(color, Color.Black) ? 1 : 0; totalPixels++; } for (int y = top; y < checkRow; y++) //check sides { //check left of login box color = Value[centerX - xOffset, y]; blackPixels += ImageProcessing.ColorsAreEqual(color, Color.Black) ? 1 : 0; totalPixels++; //check right of login box color = Value[centerX + xOffset, y]; blackPixels += ImageProcessing.ColorsAreEqual(color, Color.Black) ? 1 : 0; totalPixels++; } //assume we are logged out if a majority off the border pixels are perfectly black if ((blackPixels / ((double)totalPixels)) < 0.25) { return(false); } //Check for "Welcome to RuneScape" yellow text. We are probably logged out at this point. int topWelcome = top + 241; int bottomWelcome = topWelcome + 13; int leftWelcome = Center.X - 75; int rightWelcome = leftWelcome + 146; bool[,] welcomeText = ImageProcessing.ColorFilterPiece(Value, RGBHSBRangeFactory.Yellow(), leftWelcome, rightWelcome, topWelcome, bottomWelcome); double welcomeMatch = ImageProcessing.FractionalMatch(welcomeText); if (!Numerical.WithinRange(welcomeMatch, 0.23275, 0.01)) //ex 0.23275 { //Check for the "Enter your username/email & password." text. leftWelcome = Center.X - 140; rightWelcome = leftWelcome + 280; topWelcome = top + 206; bottomWelcome = topWelcome + 10; welcomeText = ImageProcessing.ColorFilterPiece(Value, RGBHSBRangeFactory.Yellow(), leftWelcome, rightWelcome, topWelcome, bottomWelcome); welcomeMatch = ImageProcessing.FractionalMatch(welcomeText); if (!Numerical.WithinRange(welcomeMatch, 0.25234, 0.01)) //ex. 0.2523 { return(false); //Could not find the welcome text or the enter text. } } RunParams.LoggedIn = false; return(true); }