Updated main loop to use a while loop instead, added full try{}catch()

block. Added proper threading on displays and force updating of fields.
secondmonitor
sigonasr2 4 years ago
parent 6eee74a868
commit f6c627f3c1
  1. BIN
      DivaBot/DivaBot.jar
  2. 8
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/capture.png
  4. BIN
      DivaBot/capture_2.png
  5. BIN
      DivaBot/capture_3.png
  6. BIN
      DivaBot/capture_4.png
  7. BIN
      DivaBot/capture_5.png
  8. 2
      DivaBot/config.txt
  9. 4
      DivaBot/src/sig/Calibrator.java
  10. 48
      DivaBot/src/sig/Display.java
  11. 10
      DivaBot/src/sig/DrawCanvas.java
  12. 583
      DivaBot/src/sig/MyRobot.java

Binary file not shown.

@ -1,4 +1,4 @@
768
504
1548
940
746
577
1527
1014

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

After

Width:  |  Height:  |  Size: 536 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

After

Width:  |  Height:  |  Size: 535 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 528 KiB

After

Width:  |  Height:  |  Size: 529 KiB

@ -1,4 +1,4 @@
DISPLAYDATA -16776961*-13369549*100*Gungsuh*600*90*300*Song Title (Japanese+Romanized)*176*136*~-16776961*-13369549*24*Gulim*400*40*300*Overall Rating|Song Title (Romanized)|FC Count*176*240*
DISPLAYDATA -16776961*-13369549*100*Gungsuh*600*90*5000*Song Title (Japanese+Romanized)*176*136*~-16776961*-13369549*24*Gulim*400*40*300*Overall Rating|Song Title (Romanized)|FC Count*176*240*~-16776961*-13369549*24*Gulim*400*40*300*Best Play*0*0*
LAST_HEIGHT 40
WIDTH 1127
HEIGHT 765

@ -63,6 +63,8 @@ public class Calibrator{
MyRobot.FRAME.setCursor(Cursor.getDefaultCursor());
Overlay.started=false;
MyRobot.FRAME.setAlwaysOnTop(false);
Overlay.OVERLAY.setVisible(true);
if (((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04||
((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))>=16/9f+0.04) {
int dialogResult = JOptionPane.showConfirmDialog (null, "Could not detect Megamix properly!\n\nYour calibration cut a bit "+((((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04)?"more":"less")+" than expected. Do you want to try selecting a more accurate region?","Warning",JOptionPane.YES_NO_OPTION);
@ -74,7 +76,7 @@ public class Calibrator{
return;
}
}
Overlay.OVERLAY.setVisible(true);
MyRobot.FRAME.setAlwaysOnTop(true);
// failed=CalibrationStage3(p);
// if (failed) {return;}

@ -20,6 +20,8 @@ public class Display {
int width=200;
int height=48;
int delay=10000;
long nextUpdateTime = System.currentTimeMillis();
boolean forceUpdate=false;
String[] labels;
String currentText;
int cycle=0;
@ -101,10 +103,17 @@ public class Display {
public void run() {
try {
while (!deleted) {
AdvanceCycle();
updateFont();
MyRobot.p.repaint();
Thread.sleep(delay);
if (System.currentTimeMillis()>nextUpdateTime) {
if (!forceUpdate) {
AdvanceCycle();
}
updateFont();
currentText=interpretLabel(labels[cycle]);
MyRobot.p.repaint();
nextUpdateTime=System.currentTimeMillis()+delay;
forceUpdate=false;
}
Thread.sleep(50);
}
} catch (InterruptedException e) {
e.printStackTrace();
@ -205,19 +214,40 @@ public class Display {
return (data.songname + " - " + ((data.romanizedname.length()>0)?(data.romanizedname.equalsIgnoreCase(data.englishname))?data.romanizedname:data.romanizedname+" ("+data.englishname+")":data.englishname)) + " by "+data.artist;
}
case "Play Count":{
return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
if (data.plays>0) {
return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
} else {
return "No Plays";
}
}
case "Pass/Play Count":{
return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
if (data.plays>0) {
return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
}
else {
return "No Plays";
}
}
case "Pass/Play Count (+%)":{
return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)";
if (data.plays>0) {
return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)";
} else {
return "No Plays";
}
}
case "FC Count":{
return data.fcCount +" FC"+(data.fcCount==1?"":"s");
if (data.plays>0) {
return data.fcCount +" FC"+(data.fcCount==1?"":"s");
} else {
return "No Plays";
}
}
case "FC Count (+%)":{
return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate";
if (data.plays>0) {
return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate";
} else {
return "No Plays";
}
}
default:{
return string;

@ -80,7 +80,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
boolean targetBuffer=false;
static Color background = new Color(170,170,170);
public static HashMap<String,String> configData = new HashMap<String,String>();
List<Display> displays = new ArrayList<Display>();
static List<Display> displays = new ArrayList<Display>();
public static Display selectedDisplay = null;
public static Display draggedDisplay = null;
DrawCanvas() throws FontFormatException, IOException {
@ -103,6 +103,13 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
t.start();
}
public static void refreshAllLabels() {
for (Display d : displays) {
d.forceUpdate=true;
d.nextUpdateTime=System.currentTimeMillis()-1;
}
}
public void pullData(final String songname,final String difficulty) {
this.songname=(songname.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(songname.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":songname);
this.difficulty=difficulty;
@ -162,6 +169,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
}
scrollX = 0;*/
MyRobot.p.repaint();
MyRobot.p.refreshAllLabels();
}
}
} catch (JSONException | IOException e) {

@ -162,7 +162,7 @@ public class MyRobot{
public static String USERNAME = "";
public static String AUTHTOKEN = "";
public static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
public static long lastmainlooptime = 0;
public static void main(String[] args) throws JSONException, IOException, FontFormatException {
@ -266,315 +266,322 @@ public class MyRobot{
}
void BotMain() {
lastmainlooptime=System.currentTimeMillis();
while (true) {
try {
RunMainLoop();
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void RunMainLoop() {
try {
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
p.lastRating = p.overallrating;
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
if (obj.has("rating")) {
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Timer t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
if (CALIBRATION_MODE) {
if (MyRobot.calibrating) {
MyRobot.calibrating=false;
Overlay.OVERLAY.setVisible(false);
Thread.sleep(1000);
Calibrator c = new Calibrator();
}
} else {
//ImageIO.write(MYROBOT.createScreenCapture(),"png",new File("testscreen.png"));
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
MyRobot.p.repaint();
}
GetCurrentSong();
GetCurrentDifficulty();
recordedResults=false;
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
MyRobot.p.repaint();
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
MyRobot.p.repaint();
}
if ((selectedSong!=null && difficulty!=null)) {
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(200);
MYROBOT.refreshScoreScreen();
ImageIO.write(MYROBOT.createScoreScreenCapture(),"png",new File("scoreimage.png"));
File tmp = new File("tmp");
if (tmp.exists()) {
FileUtils.deleteFile(tmp);
} else {
tmp.mkdir();
}
try {
Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
System.out.println(data);
//ImageIO.write(MYROBOT.,"png",new File("test.png"));
if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
System.out.println("Waiting for results to populate...");
} else
if ((data.combo!=lastcombo || data.fail!=lastfail || data.cool!=lastcool || lastfine!=data.fine || lastsafe!=data.safe || lastsad!=data.sad || lastworst!=data.worst)
&& data.score!=lastscore /*|| lastpercent!=percent*/){
//System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.cool+"/"+data.fine+"/"+data.safe+"/"+data.sad+"/"+data.worst+" "+data.percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.display());
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
recordedResults=true;
lastcool=data.cool;
lastfine=data.fine;
lastsafe=data.safe;
lastsad=data.sad;
lastworst=data.worst;
lastpercent=data.percent;
lastcombo=data.combo;
lastscore=data.score;
lastfail=data.fail;
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+""
+ "_"+data.combo+"_"+data.score+".png"));
results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.mod,data.combo,data.score,data.fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
} catch (IOException|NumberFormatException|IndexOutOfBoundsException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", USERNAME));
params.add(new BasicNameValuePair("authentication_token", AUTHTOKEN));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", r.mod));
params.add(new BasicNameValuePair("combo", Integer.toString(r.combo)));
params.add(new BasicNameValuePair("gameScore", Integer.toString(r.score)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/"+USERNAME+"/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
p.lastRating = p.overallrating;
if (obj2.has("score")) {
double newScore = obj2.getDouble("score");
if (newScore>p.lastScore) {
p.bestPlayTime=System.currentTimeMillis();
}
p.lastScore = newScore;
}
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
}
}
}
MYROBOT.refreshScreen();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
if (CALIBRATION_MODE) {
if (MyRobot.calibrating) {
MyRobot.calibrating=false;
Overlay.OVERLAY.setVisible(false);
Thread.sleep(1000);
Calibrator c = new Calibrator();
}
} else {
//ImageIO.write(MYROBOT.createScreenCapture(),"png",new File("testscreen.png"));
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
MyRobot.p.repaint();
}
GetCurrentSong();
GetCurrentDifficulty();
recordedResults=false;
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
MyRobot.p.refreshAllLabels();
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
MyRobot.p.repaint();
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
private boolean OnResultsScreen() throws IOException {
//r.x-418, r.y-204
/*ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));*/
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0));
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0));
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
//System.out.println(c1+"/"+c2+"/"+c3);
return c1.getRed()>=250 && c1.getGreen()>=250 && c1.getBlue()>=250 && c2.getRed()>=10 && c2.getRed()<=25 && c2.getGreen()>=200 && c2.getGreen()<=240 && c2.getBlue()>=180 && c2.getBlue()<=220 &&
c3.getRed()>=200 && c3.getRed()<=255 && c3.getGreen()>=200 && c3.getGreen()<=255 && c3.getBlue()>=140 && c3.getBlue()<=220;
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
MyRobot.p.repaint();
}
if ((selectedSong!=null && difficulty!=null)) {
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(200);
MYROBOT.refreshScoreScreen();
ImageIO.write(MYROBOT.createScoreScreenCapture(),"png",new File("scoreimage.png"));
File tmp = new File("tmp");
if (tmp.exists()) {
FileUtils.deleteFile(tmp);
} else {
tmp.mkdir();
}
private void GetCurrentDifficulty() {
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(320,274,10,10)).getRGB(0, 0));
//return c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
if (c.getRed()>100 && c.getRed()<200 && c.getBlue()>200 && c.getBlue()<255 && c.getGreen()<50) {
difficulty="EXEX";
} else
if (c.getRed()>150 && c.getRed()<255 && c.getBlue()<50 && c.getGreen()<50) {
difficulty="EX";
} else
if (c.getRed()>175 && c.getRed()<225 && c.getBlue()<50 && c.getGreen()<175 && c.getGreen()>135) {
difficulty="H";
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()<50 && c.getGreen()<255 && c.getGreen()>190) {
difficulty="N";
try {
Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
System.out.println(data);
//ImageIO.write(MYROBOT.,"png",new File("test.png"));
if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
System.out.println("Waiting for results to populate...");
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()>170 && c.getBlue()<230 && c.getGreen()<190 && c.getGreen()>150) {
difficulty="E";
if ((data.combo!=lastcombo || data.fail!=lastfail || data.cool!=lastcool || lastfine!=data.fine || lastsafe!=data.safe || lastsad!=data.sad || lastworst!=data.worst)
&& data.score!=lastscore /*|| lastpercent!=percent*/){
//System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.cool+"/"+data.fine+"/"+data.safe+"/"+data.sad+"/"+data.worst+" "+data.percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.display());
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
recordedResults=true;
lastcool=data.cool;
lastfine=data.fine;
lastsafe=data.safe;
lastsad=data.sad;
lastworst=data.worst;
lastpercent=data.percent;
lastcombo=data.combo;
lastscore=data.score;
lastfail=data.fail;
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+""
+ "_"+data.combo+"_"+data.score+".png"));
results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.mod,data.combo,data.score,data.fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
} catch (IOException|NumberFormatException|IndexOutOfBoundsException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
private void GetCurrentSong() throws IOException {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(812-10,380-10,WIDTH+20,HEIGHT+20)));
boolean found=false;
LOOP1:
for (int x=0;x<10;x++) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", USERNAME));
params.add(new BasicNameValuePair("authentication_token", AUTHTOKEN));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", r.mod));
params.add(new BasicNameValuePair("combo", Integer.toString(r.combo)));
params.add(new BasicNameValuePair("gameScore", Integer.toString(r.score)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
if (!found) {
LOOP2:
for (int x=0;x>-10;x--) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/"+USERNAME+"/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
p.lastRating = p.overallrating;
if (obj2.has("score")) {
double newScore = obj2.getDouble("score");
if (newScore>p.lastScore) {
p.bestPlayTime=System.currentTimeMillis();
}
p.lastScore = newScore;
}
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
}
}
}
MYROBOT.refreshScreen();
}
}catch(Exception e) {
e.printStackTrace();
}
}
private boolean OnResultsScreen() throws IOException {
//r.x-418, r.y-204
/*ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));*/
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0));
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0));
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
//System.out.println(c1+"/"+c2+"/"+c3);
return c1.getRed()>=250 && c1.getGreen()>=250 && c1.getBlue()>=250 && c2.getRed()>=10 && c2.getRed()<=25 && c2.getGreen()>=200 && c2.getGreen()<=240 && c2.getBlue()>=180 && c2.getBlue()<=220 &&
c3.getRed()>=200 && c3.getRed()<=255 && c3.getGreen()>=200 && c3.getGreen()<=255 && c3.getBlue()>=140 && c3.getBlue()<=220;
}
private void GetCurrentDifficulty() {
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(320,274,10,10)).getRGB(0, 0));
//return c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
if (c.getRed()>100 && c.getRed()<200 && c.getBlue()>200 && c.getBlue()<255 && c.getGreen()<50) {
difficulty="EXEX";
} else
if (c.getRed()>150 && c.getRed()<255 && c.getBlue()<50 && c.getGreen()<50) {
difficulty="EX";
} else
if (c.getRed()>175 && c.getRed()<225 && c.getBlue()<50 && c.getGreen()<175 && c.getGreen()>135) {
difficulty="H";
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()<50 && c.getGreen()<255 && c.getGreen()>190) {
difficulty="N";
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()>170 && c.getBlue()<230 && c.getGreen()<190 && c.getGreen()>150) {
difficulty="E";
}
}
private void GetCurrentSong() throws IOException {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(812-10,380-10,WIDTH+20,HEIGHT+20)));
boolean found=false;
LOOP1:
for (int x=0;x<10;x++) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
}
}
if (!found) {
LOOP2:
for (int x=0;x>-10;x--) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
},
0,
50);
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
}
}
}
void go() throws FontFormatException, IOException {

Loading…
Cancel
Save