command line args

This commit is contained in:
Millz committed 2023-12-08 09:26:51 +00:00
1 parent 7f369e10d5
commit 74f657f644
8 files changed
+281 -66831

No files matched your search

+15
View File
@@ -62,3 +62,18 @@ font=Comic Neue
with "Comic Neue" replaced with the font you want to use. Unless you want to use Comic Neue.
RSC by default tries to use Helvetica/Arial, but can't if you don't have it installed.
Using command line arguments
------------------
Execute the bot passing in the arguments below. An account must already be setup and added to the bot
before using the auto launch --username: parameter.
```
--no-console Launches the bot without console
--username:username Default account name for launcher. Must already be added as account.
--height:558 Also: --h. Window height. Height and Width must both be set together.
--width:670 Also: --w. Window width. Height and Width must both be set together.
--x:200 X Location on screen. X and Y must both be set together.
--y:200 Y Location on screen. X and Y must both be set together.
```
+62 -66810
View File
File diff suppressed because it is too large. Load diff
BIN
View File
Binary file not shown.
@@ -5,8 +5,11 @@ import com.aposbot.gui.BotFrame;
import com.aposbot.gui.EntryFrame;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Properties;
/**
@@ -20,13 +23,59 @@ public final class BotLoader {
private String font;
private int defaultOCR;
private boolean showConsole = true;
private String cmdUsername = "";
private static int cmdWindowHeight = 0;
private static int cmdWindowWidth = 0;
private static int cmdLocationX = 0;
private static int cmdLocationY = 0;
public BotLoader(final String[] argv, final IClientInit clientInit) {
new EntryFrame(this, clientInit).setVisible(true);
System.out.println("------------------------------------------------");
System.out.println("Command-line args:");
System.out.println("--no-console Launches the bot without console");
System.out.println("--username:username Default account name for launcher. Must already be added as account.");
System.out.println("--height:558 Also: --h. Window height. Height and Width must both be set together.");
System.out.println("--width:670 Also: --w. Window width. Height and Width must both be set together.");
System.out.println("--x:200 X Location on screen. X and Y must both be set together.");
System.out.println("--y:200 Y Location on screen. X and Y must both be set together.");
System.out.println("------------------------------------------------");
if (argv.length == 0) {
System.out.println("To launch the bot without the built-in console, use at least one command-line argument.");
for (String s : argv) {
switch (s.toLowerCase().split(":")[0]) {
case "--no-console":
showConsole = false;
System.out.println("Disabling console.");
break;
case "--username":
cmdUsername = s.toLowerCase().split(":")[1];
System.out.println("Account: " + cmdUsername);
break;
case "--h":
case "--height":
cmdWindowHeight = Integer.parseInt(s.toLowerCase().split(":")[1]);
System.out.println("Height: " + cmdWindowHeight);
break;
case "--w":
case "--width":
cmdWindowWidth = Integer.parseInt(s.toLowerCase().split(":")[1]);
System.out.println("Width: " + cmdWindowWidth);
break;
case "--x":
cmdLocationX = Integer.parseInt(s.toLowerCase().split(":")[1]);
System.out.println("X: " + cmdLocationX);
break;
case "--y":
cmdLocationY = Integer.parseInt(s.toLowerCase().split(":")[1]);
System.out.println("Y: " + cmdLocationY);
break;
default:
System.out.println("Unknown command line arg: " + s);
break;
}
}
if (showConsole) {
final TextArea cTextArea = new TextArea(null, 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
BotFrame.setColours(cTextArea);
cTextArea.setEditable(false);
@@ -61,6 +110,38 @@ public final class BotLoader {
}
}
EntryFrame entryFrame = new EntryFrame(this, clientInit);
if (cmdUsername.isEmpty() || entryFrame.accountNames.length == 0) {
entryFrame.setVisible(true);
} else {
if (!cmdUsername.toLowerCase().equals(entryFrame.account.toLowerCase())) {
System.out.println("Auto load account isn't setup! You must add the account manually before setting up auto load account.");
System.exit(1);
}
ActionEvent triggerOk = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "OKButtonClicked");
for (ActionListener listener : entryFrame.okButton.getActionListeners()) {
listener.actionPerformed(triggerOk);
}
entryFrame.setVisible(false);
entryFrame.dispose();
}
}
public static Dimension getHeightWidth(){
if (cmdWindowHeight != 0 && cmdWindowWidth != 0)
return new Dimension(cmdWindowWidth, cmdWindowHeight);
return null;
}
public static Point getLocation(){
if (cmdLocationX != 0 && cmdLocationY != 0)
return new Point(cmdLocationX, cmdLocationY);
return null;
}
public static Properties getProperties() {
@@ -95,6 +176,7 @@ public final class BotLoader {
public String getFont() {
return font;
}
public String getCmdUsername() { return cmdUsername; }
public int getDefaultOCR() {
return defaultOCR;
@@ -1,5 +1,6 @@
package com.aposbot.gui;
import com.aposbot.BotLoader;
import com.aposbot._default.*;
import com.aposbot.applet.AVStub;
import com.aposbot.Constants;
@@ -271,16 +272,6 @@ public final class BotFrame extends Frame {
checkPanel.add(t3d);
checkPanel.add(i3d);
((Component) client)
.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent e) {
final int w = ((Component) client).getWidth();
final int h = ((Component) client).getHeight();
clientInit.getPaintListener().doResize(w, h);
}
});
add((Component) client, BorderLayout.CENTER);
add(sidePanel, BorderLayout.EAST);
@@ -296,12 +287,85 @@ public final class BotFrame extends Frame {
add(checkPanel, BorderLayout.SOUTH);
}
pack();
setMinimumSize(getSize());
if (BotLoader.getHeightWidth() == null) {
pack();
setMinimumSize(getSize());
}
client.init();
stub.setActive(true);
client.start();
addComponentListener(new ComponentAdapter() {
private boolean initialSizeSet = false;
@Override
public void componentResized(final ComponentEvent e) {
final int w = ((Component) client).getWidth();
final int h = ((Component) client).getHeight();
if (isVisible() && isDisplayable()) {
final Point location = getLocationOnScreen();
if (location != null) {
final int windowWidth = getWidth();
final int windowHeight = getHeight();
final int x = location.x;
final int y = location.y;
setTitle(String.format("APOS (%s) - Window [H: %s, W: %s], Location [X: %s, Y: %s]", account, windowHeight, windowWidth, x, y));
}
}
if (!initialSizeSet) {
System.out.println("Setting window bounds");
initialSizeSet = true;
pack();
setMinimumSize(getSize());
if (BotLoader.getHeightWidth() != null) {
System.out.println("Setting window dimensions");
setSize(BotLoader.getHeightWidth().width, BotLoader.getHeightWidth().height);
}
if (BotLoader.getLocation() != null) {
System.out.println("Setting location");
setBounds(BotLoader.getLocation().x, BotLoader.getLocation().y, getWidth(), getHeight());
}
}
}
@Override
public void componentMoved(final ComponentEvent e) {
if (isVisible() && ((Component) client).isDisplayable() && ((Applet) client).isVisible()) {
final Point location = ((Component) client).getLocationOnScreen();
if (location != null) {
final int windowWidth = getWidth();
final int windowHeight = getHeight();
final int x = location.x;
final int y = location.y;
setTitle(String.format("APOS (%s) - Window [H: %s, W: %s], Location [X: %s, Y: %s]", account, windowHeight, windowWidth, x, y));
}
}
}
});
((Component) client)
.addComponentListener(new ComponentAdapter() {
private boolean initialSizeSet = false;
@Override
public void componentResized(final ComponentEvent e) {
final int w = ((Component) client).getWidth();
final int h = ((Component) client).getHeight();
clientInit.getPaintListener().doResize(w, h);
}
});
}
private void quit() {
@@ -12,6 +12,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
/**
@@ -19,8 +20,10 @@ import java.util.Properties;
*/
public final class EntryFrame extends Frame {
private AuthFrame authFrame;
private String[] accountNames;
private String account;
public String[] accountNames;
public String account;
public Button okButton;
public EntryFrame(final BotLoader botLoader, final IClientInit clientInit) {
super("APOS");
@@ -37,12 +40,23 @@ public final class EntryFrame extends Frame {
final Choice accountChoice = new Choice();
accountChoice.setPreferredSize(new Dimension(150, 15));
for (final String accountName : accountNames) {
accountChoice.add(accountName);
if (Objects.equals(botLoader.getCmdUsername().toLowerCase(), accountName.toLowerCase())) {
account = accountName;
accountChoice.add(accountName);
}
}
if (accountNames.length > 0) {
for (final String accountName : accountNames) {
if (!Objects.equals(botLoader.getCmdUsername(), accountName))
accountChoice.add(accountName);
}
if ((account == null || account.isEmpty()) && accountNames.length > 0) {
account = accountNames[0];
}
accountChoice.addItemListener(event -> account = String.valueOf(event.getItem()));
accountPanel.add(accountChoice);
@@ -86,7 +100,7 @@ public final class EntryFrame extends Frame {
final Panel buttonPanel = new Panel();
final Button okButton = new Button("OK");
okButton = new Button("OK");
okButton.addActionListener(e -> {
if (authFrame != null) {
authFrame.dispose();
@@ -125,6 +139,9 @@ public final class EntryFrame extends Frame {
add(buttonPanel, BorderLayout.SOUTH);
pack();
}
private void loadAccounts() {
+20
View File
@@ -0,0 +1,20 @@
REM ------------------------------------------------
REM Command-line args:
REM --no-console Launches the bot without console
REM --username:username Default account name for launcher. Must already be added as account.
REM --height:558 Also: --h. Window height. Height and Width must both be set together.
REM --width:670 Also: --w. Window width. Height and Width must both be set together.
REM --x:200 X Location on screen. X and Y must both be set together.
REM --y:200 Y Location on screen. X and Y must both be set together.
REM ------------------------------------------------
@echo off
IF NOT EXIST bot.jar (
echo Missing bot.jar ...
echo.
call compile_all.cmd
)
start javaw -jar bot.jar --username:myuser
exit
+1 -1
View File
@@ -1,3 +1,3 @@
@echo off
run.cmd _
run.cmd --no-console