Skip to content
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 build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.chromascape"
version = "0.4.0"
version = "0.5.0"

java {
toolchain {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/chromascape/base/BaseScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class BaseScript {
private static final Logger logger = LogManager.getLogger(BaseScript.class);
private volatile boolean running = true;
private Thread scriptThread;
private boolean initialised = false;

/** Constructs a BaseScript. */
public BaseScript() {
Expand Down Expand Up @@ -51,6 +52,10 @@ public final void run() {
break;
}
try {
if (!initialised) {
onFirstCycle();
initialised = true;
}
cycle();
} catch (ScriptStoppedException e) {
logger.error("Cycle interrupted: {}", e.getMessage());
Expand All @@ -68,6 +73,14 @@ public final void run() {
logger.info("Finished running script.");
}

/**
* Will run operations on the first cycle and then never again. Useful for initialising data such
* as custom zones, or for setup actions.
*/
protected void onFirstCycle() {
// override this
}

/**
* Stops the script execution by interrupting the script thread.
*
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/chromascape/scripts/DemoMiningScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.chromascape.utils.actions.Idler;
import com.chromascape.utils.actions.ItemDropper;
import com.chromascape.utils.actions.PointSelector;
import com.chromascape.utils.core.screen.topology.MatchResult;
import com.chromascape.utils.core.screen.topology.TemplateMatching;
import com.chromascape.utils.core.screen.window.ScreenManager;
import java.awt.Point;
Expand Down Expand Up @@ -71,9 +72,13 @@ private void clickOre() {
* @return {@code true} if the inventory is full, otherwise {@code false}
*/
private boolean isInventoryFull() {
// Get the zone
Rectangle invSlot = controller().zones().getInventorySlots().get(27);
// Create a snapshot of the zone
BufferedImage invSlotImg = ScreenManager.captureZone(invSlot);
Rectangle match = TemplateMatching.match(ironOre, invSlotImg, 0.05).bounds();
return match != null;
// Run template matching
MatchResult match = TemplateMatching.match(ironOre, invSlotImg, 0.05);
// Return the result
return match.success();
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/chromascape/scripts/Screenshotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public class Screenshotter extends BaseScript {

public static final String ORIGINAL_IMAGE_PATH = "output/original.png";

/** Same constructor as super (BaseScript). */
public Screenshotter() {
super();
}

/**
* Takes a screenshot and saves it in the "/output" directory on the same level as /src. Although
* in the BaseScript - this function is repeated until the specified time duration is met - Here,
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/chromascape/utils/actions/PointSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* <ul>
* <li>Finds a random point within the bounding box of a detected image template.
* <li>Finds a random point inside the contour of the first detected object of a specified colour.
* <li>Supports both <b>heuristic-based</b> distributions (dynamic sizing) and <b>explicit
* tightness</b> control.
* <li>Contains overloads for a tightness parameter for the user to choose how closely towards the
* center the clicks should bias.
* </ul>
*
* <p>These utilities are commonly reused across scripts. The class does not perform any input
Expand All @@ -39,7 +39,7 @@
* // Default heuristic distribution
* Point imgPoint = PointSelector.getRandomPointInImage(templatePath, gameView, 0.15);
* // Custom tightness (maybe clicking a ground item)
* Point colorPoint = PointSelector.getRandomPointInColour(gameView, "Purple", 5, 15.0);
* Point colorPoint = PointSelector.getRandomPointInColour(gameView, "Purple", 0.05, 15.0);
* </pre>
*
* <p>All methods are static and thread-safe.
Expand All @@ -58,7 +58,7 @@ public class PointSelector {
*
* @param templatePath the BufferedImage template to locate within the larger image
* @param image the larger image to search inside (e.g. game view)
* @param threshold the match confidence threshold (0.0 to 1.0) required to consider a detection
* @param threshold the match confidence threshold (0.01 to 0.15) required to consider a detection
* valid
* @return a valid {@link Point} within the detected region, or {@code null} if no match is found
*/
Expand All @@ -78,7 +78,7 @@ public static Point getRandomPointInImage(
*
* @param templatePath the BufferedImage template to search for within the larger image view
* @param image the larger image to search inside (e.g. game view)
* @param threshold the match confidence threshold (0.0 to 1.0) required to consider a detection
* @param threshold the match confidence threshold (0.01 to 0.15) required to consider a detection
* valid
* @param tightness the distribution divisor. Higher values (e.g., 15.0) result in a tighter
* cluster around the center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ private Path resolveProfileDir() {
String home = System.getProperty("user.home");
String os = System.getProperty("os.name").toLowerCase();

Path windowsPath = Path.of(home, ".runelite/profiles2");
if (os.contains("win")) {
return Path.of(home, "AppData", "Local", "RuneLite", "profiles2");
return windowsPath;
}

if (os.contains("linux")) {
Expand All @@ -85,8 +86,8 @@ private Path resolveProfileDir() {
return Path.of(home, "Library/Application Support/RuneLite/profiles2");
}

// Fallback (Linux standard or unknown OS)
return Path.of(home, ".runelite/profiles2");
// Fallback
return windowsPath;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Manages the detection and mapping of key UI zones within the RuneLite client window, including
Expand Down Expand Up @@ -56,8 +54,6 @@ public class ZoneManager {
"/images/ui/minimap_fixed.png"
};

private static final Logger logger = LogManager.getLogger(ZoneManager.class.getName());

/** Constructs a new ZoneManager configured for either fixed or resizable mode. */
public ZoneManager() {
this.isFixed = checkIfFixed();
Expand All @@ -70,7 +66,6 @@ public ZoneManager() {
* <p>Any exceptions during mapping are caught and logged to standard error.
*/
public void mapper() {
// Cache the bounds first
chatBounds = locateUiElement(zoneTemplates[2]);
ctrlPanelBounds = locateUiElement(zoneTemplates[1]);

Expand All @@ -80,14 +75,15 @@ public void mapper() {

mouseOver = new Rectangle(0, 0, 407, 26);

Rectangle windowBounds = ScreenManager.getWindowBounds();
gridInfo = SubZoneMapper.mapGridInfo(new Rectangle(5, windowBounds.height - 226, 129, 56));

if (isFixed) {
minimapBounds = locateUiElement(zoneTemplates[3]);
minimap = SubZoneMapper.mapFixedMinimap(minimapBounds);
gridInfo = SubZoneMapper.mapGridInfo(new Rectangle(9, 24, 129, 56));
} else {
minimapBounds = locateUiElement(zoneTemplates[0]);
minimap = SubZoneMapper.mapMinimap(minimapBounds);
gridInfo = SubZoneMapper.mapGridInfo(new Rectangle(5, 20, 129, 56));
}
}

Expand Down
Loading
Loading