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

Optional update 2.9.1 #70

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>bh.bot</groupId>
<artifactId>99bot</artifactId>
<version>2.9.0</version>
<version>2.9.1</version>

<dependencies>
<dependency>
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/bh/bot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ private static String[] buildArgument(String[] args) {
FlagPlayOnWeb flagPlayOnWeb = new FlagPlayOnWeb();
boolean isWeb = lArgs.stream().anyMatch(x -> x.equalsIgnoreCase(flagPlayOnWeb.getCode()));
boolean isSteam = lArgs.stream().anyMatch(x -> x.equalsIgnoreCase(flagPlayOnSteam.getCode()));

if (isWeb || isSteam) {
// ignore
} else {

if (!isWeb && !isSteam) {
if (flagPlayOnSteam.isSupportedOnCurrentOsPlatform()) {
lArgs.add(readInput("Steam or Web?\n\t1. Steam\n\t2. Web", null, s -> {
try {
Expand Down Expand Up @@ -184,12 +182,15 @@ private static String[] buildArgument(String[] args) {
lArgs.add(newFlag);
}
} else {
Rad.exec(50, () -> {
info(Cu.i().cyan("You can save the command-line into script ").green(scriptFileName("<name>.c")).cyan(" and re-use later").reset());
});
Rad.exec(50, () -> info(Cu.i()
.cyan("You can save the command-line into script ")
.green(scriptFileName("<name>.c"))
.cyan(" and re-use later")
.reset()
));
}

return lArgs.stream().distinct().collect(Collectors.toList()).toArray(new String[0]);
return lArgs.stream().distinct().toArray(String[]::new);
}

private static void process(String[] args) throws Exception {
Expand Down Expand Up @@ -226,14 +227,14 @@ private static void process(String[] args) throws Exception {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));
currentVersion = model.getVersion();
} catch (Exception ignored) {
if (!(ignored instanceof FileNotFoundException))
dev(ignored);
} catch (Exception forDevPurposeOnly) {
if (!(forDevPurposeOnly instanceof FileNotFoundException))
dev(forDevPurposeOnly);

try (InputStream fCurVer = Configuration.class.getResourceAsStream("/current-version.txt")) {
currentVersion = readFromInputStream(fCurVer).trim();
} catch (Exception ignored2) {
dev(ignored2);
} catch (Exception forDevPurposeOnly2) {
dev(forDevPurposeOnly2);
}
}

Expand All @@ -242,8 +243,8 @@ private static void process(String[] args) throws Exception {
Rad.print(33, ColorizeUtil.formatAsk, "Hi, my name is %s v%s, have a nice day", botName, currentVersion);
SematicVersion appVersion = VersionUtil.setCurrentAppVersion(currentVersion);
VersionUtil.saveBotInfo(appVersion);
} catch (Exception ignored) {
dev(ignored);
} catch (Exception forDevPurposeOnly) {
dev(forDevPurposeOnly);
}
} else {
info(ColorizeUtil.formatAsk, "Hi, my name is %s, have a nice day", botName);
Expand Down Expand Up @@ -345,6 +346,7 @@ private static ParseArgumentsResult parseArguments(String[] args) throws Invalid
AppMeta anAppMeta = applicationClassFromAppCode.getAnnotation(AppMeta.class);

if (!anAppMeta.requireClientType()) {
//noinspection ConstantConditions
isSteam = false;
isWeb = true;
} else if (OS.isWin) {
Expand Down Expand Up @@ -417,6 +419,7 @@ public static <T> T readInput(String ask, String desc, Function<String, Tuple3<B
return readInput(ask, desc, null, transform, allowBlankAndIfBlankThenReturnNull);
}

@SuppressWarnings("unused")
public static boolean readYesNoInput(String ask, String desc) {
return readYesNoInput(ask, desc, false, false);
}
Expand Down
105 changes: 38 additions & 67 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package bh.bot.app;

import static bh.bot.Main.readInput;
import static bh.bot.common.Log.*;
import static bh.bot.common.utils.Extensions.scriptFileName;
import static bh.bot.common.utils.ImageUtil.freeMem;
import static bh.bot.common.utils.InteractionUtil.Keyboard.sendEscape;
import static bh.bot.common.utils.InteractionUtil.Keyboard.sendSpaceKey;
import static bh.bot.common.utils.InteractionUtil.Mouse.clickRadioButton;
import static bh.bot.common.utils.InteractionUtil.Mouse.hideCursor;
import static bh.bot.common.utils.InteractionUtil.Mouse.mouseClick;
import static bh.bot.common.utils.InteractionUtil.Mouse.mouseMoveAndClickAndHide;
import static bh.bot.common.utils.InteractionUtil.Mouse.moveCursor;
import static bh.bot.common.utils.InteractionUtil.Screen.captureElementInEstimatedArea;
import static bh.bot.common.utils.InteractionUtil.Screen.captureScreen;
import static bh.bot.common.utils.InteractionUtil.Screen.getPixelColor;
import static bh.bot.common.utils.ThreadUtil.sleep;
import bh.bot.Main;
import bh.bot.common.Configuration;
import bh.bot.common.Log;
import bh.bot.common.OS;
import bh.bot.common.Telegram;
import bh.bot.common.exceptions.InvalidDataException;
import bh.bot.common.exceptions.NotSupportedException;
import bh.bot.common.extensions.Rad;
import bh.bot.common.jna.*;
import bh.bot.common.types.*;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.annotations.RequireSingleInstance;
import bh.bot.common.types.flags.*;
import bh.bot.common.types.images.BwMatrixMeta;
import bh.bot.common.types.tuples.Tuple2;
import bh.bot.common.types.tuples.Tuple3;
import bh.bot.common.types.tuples.Tuple4;
import bh.bot.common.utils.*;
import bh.bot.common.utils.ColorizeUtil.Cu;
import bh.bot.common.utils.InteractionUtil.Keyboard;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinNT;
import org.fusesource.jansi.Ansi;

import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
Expand All @@ -35,53 +43,15 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import javax.imageio.ImageIO;

import bh.bot.common.Log;
import bh.bot.common.exceptions.InvalidFlagException;
import bh.bot.common.extensions.Rad;
import bh.bot.common.types.annotations.RequireSingleInstance;
import bh.bot.common.types.flags.*;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.platform.win32.WinDef.HWND;

import bh.bot.Main;
import bh.bot.common.Configuration;
import bh.bot.common.OS;
import bh.bot.common.Telegram;
import bh.bot.common.exceptions.InvalidDataException;
import bh.bot.common.exceptions.NotSupportedException;
import bh.bot.common.jna.AbstractLinuxJna;
import bh.bot.common.jna.IJna;
import bh.bot.common.jna.MiniClientLinuxJna;
import bh.bot.common.jna.MiniClientMacOsJna;
import bh.bot.common.jna.MiniClientWindowsJna;
import bh.bot.common.jna.SteamWindowsJna;
import bh.bot.common.types.Familiar;
import bh.bot.common.types.Offset;
import bh.bot.common.types.ParseArgumentsResult;
import bh.bot.common.types.ScreenResolutionProfile;
import bh.bot.common.types.UserConfig;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.images.BwMatrixMeta;
import bh.bot.common.types.tuples.Tuple2;
import bh.bot.common.types.tuples.Tuple3;
import bh.bot.common.types.tuples.Tuple4;
import bh.bot.common.utils.ColorizeUtil;
import bh.bot.common.utils.ColorizeUtil.Cu;
import bh.bot.common.utils.Extensions;
import bh.bot.common.utils.ImageUtil;
import bh.bot.common.utils.InteractionUtil;
import bh.bot.common.utils.InteractionUtil.Keyboard;
import bh.bot.common.utils.InteractionUtil.Screen.ScreenCapturedResult;
import bh.bot.common.utils.RandomUtil;
import bh.bot.common.utils.StringUtil;
import bh.bot.common.utils.TimeUtil;
import bh.bot.common.utils.ValidationUtil;
import bh.bot.common.utils.VersionUtil;
import com.sun.jna.platform.win32.WinNT;
import org.fusesource.jansi.Ansi;
import static bh.bot.Main.readInput;
import static bh.bot.common.Log.*;
import static bh.bot.common.utils.Extensions.scriptFileName;
import static bh.bot.common.utils.ImageUtil.freeMem;
import static bh.bot.common.utils.InteractionUtil.Keyboard.sendEscape;
import static bh.bot.common.utils.InteractionUtil.Keyboard.sendSpaceKey;
import static bh.bot.common.utils.InteractionUtil.Mouse.*;
import static bh.bot.common.utils.InteractionUtil.Screen.*;
import static bh.bot.common.utils.ThreadUtil.sleep;

public abstract class AbstractApplication {
protected ParseArgumentsResult argumentInfo;
Expand Down Expand Up @@ -734,6 +704,7 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
boolean showWarningWorldBossTeam = st.showWarningWorldBossTeam;

if (persuade) {
warn("Auto persuade had been turned on, that means in case of any persuade screen appears, bot will automatically persuade the monster with Gold. If you want to disable this feature, you can use '%s' flag", FlagDisablePersuade.FlagName);
if (Configuration.enableDevFeatures) {
final String fileBribeName = "bribe.txt";
File fBribe = new File(fileBribeName);
Expand Down Expand Up @@ -812,7 +783,7 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
}

private long addSec(int secs) {
return System.currentTimeMillis() + secs * 1_000;
return System.currentTimeMillis() + secs * 1_000L;
}

protected static class SmallTasks {
Expand Down Expand Up @@ -1123,7 +1094,7 @@ private void autoExit(AtomicBoolean masterSwitch) {
if (argumentInfo.exitAfterXSecs < 1)
return;

long applicationExpectedExitTime = applicationStartTime + argumentInfo.exitAfterXSecs * 1_000;
long applicationExpectedExitTime = applicationStartTime + argumentInfo.exitAfterXSecs * 1_000L;
long now = System.currentTimeMillis();
if (applicationExpectedExitTime <= now) {
masterSwitch.set(true);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/bh/bot/app/AfkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private void doLoop(//
if (first.isPresent()) {
naBtnFightPvp = first.get();
final NextAction tmp = naBtnFightPvp;
//noinspection ConstantConditions
if (naBtnFightPvp != null) {
pvpPia = pvpPia.stream().filter(x -> x != tmp).collect(Collectors.toList());
}
Expand Down Expand Up @@ -653,6 +654,7 @@ private static AfkBatch getEventListFromArg(String[] args) {
} else if (c == codeGauntlet) {
result.doGauntlet = true;
} else if (c == ',' || c == ';' || c == '+') {
//noinspection UnnecessaryContinue
continue;
} else {
throw new InvalidDataException("Unrecognized code value '%s'. Accepted values are combination of %s. For example combination '%s%s%s' stands for PVP + World Boss + Trials", c, shortDescArg, codePvp, codeWorldBoss1, codeTrials);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/bh/bot/app/FishingApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void internalRun(String[] args) {
warn("The FISHING label (white colored, center top of game window screen) must be clearly visible");
info("Exiting");
Main.exit(Main.EXIT_CODE_UNABLE_DETECTING_FISHING_ANCHOR);
return;
}

debug("labelFishingCord: %3d, %3d", labelFishingCord.x, labelFishingCord.y);
Expand Down Expand Up @@ -320,7 +321,7 @@ private boolean isContains(BufferedImage sc, BwMatrixMeta im) {
return isContains(sc, im, false);
}

private boolean isContains(BufferedImage sc, BwMatrixMeta im, boolean debug) {
private boolean isContains(BufferedImage sc, BwMatrixMeta im, @SuppressWarnings("SameParameterValue") boolean debug) {
if (im.throwIfNotAvailable())
return false;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/bh/bot/app/GenMiniClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ protected void internalRun(String[] args) {
// chromeArgs.add(String.format("\"--user-data-dir=%s\"", chromeUserDir.getAbsolutePath()));
chromeArgs.add("--window-size=805,545");
chromeArgs.add("--window-position=0,0");
chromeArgs.add(String.format("\"--app=file://%s\"", pathIndex.toAbsolutePath().toString()));
chromeArgs.add(String.format("\"--app=file://%s\"", pathIndex.toAbsolutePath()));
} else if (OS.isWin) {
app = String.format("\"%s\"", chromePathOnWindows);
chromeArgs.add(String.format("\"--user-data-dir=%s\"", chromeUserDir));
chromeArgs.add("--window-size=820,565");
chromeArgs.add("--window-position=0,0");
chromeArgs.add(String.format("\"--app=file://%s\"", pathIndex.toAbsolutePath().toString()));
chromeArgs.add(String.format("\"--app=file://%s\"", pathIndex.toAbsolutePath()));
} else {
app = "google-chrome";
chromeArgs.add(String.format("'--user-data-dir=%s'", chromeUserDir));
chromeArgs.add("--window-size=800,520");
chromeArgs.add("--window-position=0,0");
chromeArgs.add(String.format("'--app=file://%s'", pathIndex.toAbsolutePath().toString()));
chromeArgs.add(String.format("'--app=file://%s'", pathIndex.toAbsolutePath()));
}

StringBuilder sb = new StringBuilder();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/bh/bot/app/ReRunApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import bh.bot.Main;
import bh.bot.common.Configuration;
import bh.bot.common.Log;
import bh.bot.common.Telegram;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.annotations.RequireSingleInstance;
Expand Down
40 changes: 16 additions & 24 deletions src/main/java/bh/bot/common/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
package bh.bot.common;

import static bh.bot.common.Log.debug;
import static bh.bot.common.Log.err;
import static bh.bot.common.Log.info;
import static bh.bot.common.Log.warn;
import static bh.bot.common.utils.StringUtil.isBlank;
import static bh.bot.common.utils.StringUtil.isNotBlank;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Properties;
import java.util.stream.Collectors;

import bh.bot.Main;
import bh.bot.app.AbstractApplication;
import bh.bot.common.exceptions.InvalidDataException;
import bh.bot.common.exceptions.NotImplementedException;
import bh.bot.common.types.AtomicOffset;
import bh.bot.common.types.Offset;
import bh.bot.common.types.ParseArgumentsResult;
import bh.bot.common.types.ScreenResolutionProfile;
import bh.bot.common.types.UserConfig;
import bh.bot.common.types.*;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.flags.FlagAlterLoopInterval;
import bh.bot.common.types.flags.FlagProfileName;
Expand All @@ -36,6 +14,20 @@
import bh.bot.common.utils.TimeUtil;
import bh.bot.common.utils.ValidationUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Properties;
import java.util.stream.Collectors;

import static bh.bot.common.Log.*;
import static bh.bot.common.utils.StringUtil.isBlank;
import static bh.bot.common.utils.StringUtil.isNotBlank;

public class Configuration {
public static ScreenResolutionProfile screenResolutionProfile = null;
public static String profileName = null;
Expand Down Expand Up @@ -92,7 +84,7 @@ public static class Timeout {
public static final byte defaultLongTimeNoSeeInMinutes = 15;
}

private static Properties properties = new Properties();
private static final Properties properties = new Properties();

public static void loadSystemConfig(final ParseArgumentsResult parseArgumentsResult) throws IOException {
final ScreenResolutionProfile screenResolutionProfile = parseArgumentsResult.screenResolutionProfile;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bh/bot/common/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static void err(Object obj) {
}
if (obj == null)
return;
System.err.println(colorize(String.format("** ERR ** %s", obj.toString()), formatError));
System.err.println(colorize(String.format("** ERR ** %s", obj), formatError));
}

public static void err(String format, Object... objs) {
Expand All @@ -116,7 +116,7 @@ public static void err(String format, Object... objs) {
private static void println(Object obj) {
if (obj == null)
return;
System.out.println(obj.toString());
System.out.println(obj);
}

private static String colorize(String text, Function<Ansi, Ansi> formatter) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/bh/bot/common/jna/SteamWindowsJna.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Tuple4<Boolean, String, Rectangle, Offset> locateGameScreenOffset(HWND hw
);
showErrAskIfBhRunningOrReqAdm();
Main.exit(Main.EXIT_CODE_WINDOW_DETECTION_ISSUE);
return null;
}

if (rect.width <= 0 || rect.height <= 0)
Expand Down Expand Up @@ -106,6 +107,7 @@ public Tuple4<Boolean, String, Rectangle, Offset> locateGameScreenOffset(HWND hw
);
showErrAskIfBhRunningOrReqAdm();
Main.exit(Main.EXIT_CODE_WINDOW_DETECTION_ISSUE);
return null;
}

if (rect.width < ew || rect.height < eh) {
Expand Down
Loading