/*
* Coded by: Morph3s
* Date: 3/12/2013
* Released on: ShellSec.org
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.util.Scanner;
import javax.swing.KeyStroke;
import com.tulskiy.keymaster.common.HotKey;
import com.tulskiy.keymaster.common.HotKeyListener;
import com.tulskiy.keymaster.common.Provider;
public class MainDasher {
public int x = 1920;
public int y = 1080;
public final int gamewidth = 400;
public final int gameheight = 350;
public final Color cornercolor = new Color(231,117,78);
//Diamonds
public final Color blueb = new Color(6,101,252);
public final Color redb = new Color(241,43,46);
public final Color greenb = new Color(64,193,30);
public final Color yellowb = new Color(235,178,0);
public final Color purpleb = new Color(185,59,255);
//Multidimensional array for mapping the entire game
public Diamond[][] diamondmap = new Diamond[10][9];
public BufferedImage gamescreenshot;
public Rectangle gameRect;
//Corner in game size
public int corneroner1x;
public int corneroner1y;
public int cornertwo2x;
public int cornertwo2y;
public int diamondsfound = 0;
Robot robo;
Scanner scn = new Scanner(System.in);
Boolean runBot = true;
Boolean foundcorner = false;
Boolean allowedToRun = false;
int match;
public static void main(String args[]){
System.out.println("Credits goes to Morph3s at ShellSec.org");
System.out.println("Press escape to stop it from running");
MainDasher md = new MainDasher();
md.start();
}
public void start(){
//Initializes global hotkey
initscreenres();
inithotkey();
try {
robo = new Robot();
Rectangle screenRect = new Rectangle(x, y);
BufferedImage screenshot = robo.createScreenCapture(screenRect);
//Find corner
for(int a=1; a<x; a++){
for(int b=1; b<y; b++){
int scrnRGB = screenshot.getRGB(a, b);
if(convertToRgb(scrnRGB).equals(cornercolor)){
System.out.println("Found corner at: x=" + a + " and y=" + b);
corneroner1x = a + 40;
corneroner1y = b + 40;
cornertwo2x = a+450-39;
cornertwo2y = b+400-39;
foundcorner=true;
break;
}
}
}
if(!foundcorner){
System.out.println("Could not find corner. Quitting.");
return;
}
System.out.println("The bot has started...");
while(runBot){
try {
Thread.sleep(40);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
allowedToRun = false;
gameRect = new Rectangle((corneroner1x+11), (corneroner1y+11), gamewidth, gameheight);
gamescreenshot = robo.createScreenCapture(gameRect);
int rowcount = 0;
int columncount = 0;
//Map every diamond
for(int a=1; a<gamewidth; a+=40){
for(int b=1; b<gameheight; b+=40){
int scrnRGB = gamescreenshot.getRGB(a, b);
Color diamondColor = convertToRgb(scrnRGB);
Diamond diamond = new Diamond((a+corneroner1x+11), (b+corneroner1y+11), diamondColor);
diamondmap[rowcount][columncount] = diamond;
columncount++;
if(columncount==9){
columncount=0;
}
}
rowcount++;
}
//Find match for every diamond
matchloop:
for (int row = 0; row < 10; row++) {
for (int col = 0; col < 9; col++) {
if(findMatch(row, col, "none") >= 2){
System.out.println("Three diamonds found");
System.out.println("At: " + row + " " + col);
robo.mouseMove(diamondmap[row][col].x, diamondmap[row][col].y);
robo.mousePress(InputEvent.BUTTON1_MASK);
robo.mouseRelease(InputEvent.BUTTON1_MASK);
match = 0;
break matchloop;
}
match = 0;
}
}
}
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Recursive function for finding matches.
public int findMatch(int rowcount, int columncount, String last){
if(match >= 2){
return match;
}
if(rowcount > 0 && diamondmap[rowcount-1][columncount].color.equals(diamondmap[rowcount][columncount].color) && last!="right"){
match++;
findMatch(rowcount-1, columncount, "left");
}
if(rowcount < 9 && diamondmap[rowcount+1][columncount].color.equals(diamondmap[rowcount][columncount].color) && last!="left"){
match++;
findMatch(rowcount+1, columncount, "right");
}
if(columncount > 0 && diamondmap[rowcount][columncount-1].color.equals(diamondmap[rowcount][columncount].color) && last!="down"){
match++;
findMatch(rowcount, columncount-1, "up");
}
if(columncount < 8 && diamondmap[rowcount][columncount+1].color.equals(diamondmap[rowcount][columncount].color) && last!="up"){
match++;
findMatch(rowcount, columncount+1, "down");
}
return match;
}
final HotKeyListener listener = new HotKeyListener() {
public void onHotKey(final HotKey hotKey) {
System.out.println("Stopping!");
runBot = false;
}
};
public void inithotkey(){
System.out.println("Initializing hotkey");
Provider provider = Provider.getCurrentProvider(false);
provider.register(KeyStroke.getKeyStroke("ESCAPE"), listener);
}
public void initscreenres(){
System.out.println("Please enter the screen resolution of your screen. If your resolution is 1920x1020 then x=1920 and y=1020");
System.out.print("x: ");
x = scn.nextInt();
System.out.print("y: ");
y = scn.nextInt();
System.out.println("Screen resolution set to: " + x + "x" + y + " if this is wrong then.... You're retarded.");
}
public Color convertToRgb(int rgb){
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
return new Color(red, green, blue);
}
}
class Diamond{
public int x;
public int y;
public Color color;
Diamond(int x, int y, Color color){
this.x = x;
this.y = y;
this.color = color;
}
}