Skip to content

Instantly share code, notes, and snippets.

@jarhill0
Created November 24, 2017 05:30
Show Gist options
  • Save jarhill0/405aa966402aeb474d221d938d0dce27 to your computer and use it in GitHub Desktop.
Save jarhill0/405aa966402aeb474d221d938d0dce27 to your computer and use it in GitHub Desktop.
Cheat for the Telegram game Lumberjack. You'll have to adapt the pixel coordinates if you want it to work.
import java.awt.*;
import java.awt.event.InputEvent;
public class Cheater {
private static final int SKY_MIN_BLUE = 250;
private static final int default_x1 = 790;
private static final int default_x2 = 950;
private static final int default_y = 292;
Robot robot;
private int x1;
private int x2;
private int y;
private boolean nextPressIsLeft = true;
private Cheater(int x1, int x2, int y) {
try {
robot = new Robot();
} catch (AWTException e) {
System.out.println("Couldn't initialize robot.");
return;
}
this.x1 = x1;
this.x2 = x2;
this.y = y;
}
private Cheater() {
this(default_x1, default_x2, default_y);
}
private void run() {
robot.mouseMove(x1, y);
robot.mousePress(InputEvent.getMaskForButton(1));
mySleep(50);
robot.mouseRelease(InputEvent.getMaskForButton(1));
while (true) {
step();
}
}
private void step() {
boolean temp = nextPressIsLeft;
nextPressIsLeft = isBranchOnLeft();
chop(temp);
}
private void chop(boolean isLeft) {
int keycode = isLeft ? 39 : 37;
robot.keyPress(keycode);
mySleep(7);
robot.keyRelease(keycode);
mySleep(7);
robot.keyPress(keycode);
mySleep(7);
robot.keyRelease(keycode);
mySleep(70);
}
private boolean isBranchOnLeft() {
while (true) {
Color leftColor = robot.getPixelColor(x1, y);
Color rightColor = robot.getPixelColor(x2, y);
int leftBlue = leftColor.getBlue();
int rightBlue = rightColor.getBlue();
if (leftBlue < SKY_MIN_BLUE || rightBlue < SKY_MIN_BLUE) {
return leftBlue < SKY_MIN_BLUE;
}
}
}
private void mySleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
}
}
public static void main(String[] args) {
Cheater m = new Cheater();
m.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment