Skip to content

Commit

Permalink
Merge pull request #521 from chsami/development
Browse files Browse the repository at this point in the history
1.6.2
  • Loading branch information
chsami authored Nov 25, 2024
2 parents 366b6f3 + 537b8b7 commit eb4155c
Show file tree
Hide file tree
Showing 67 changed files with 679 additions and 1,475 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "1.6.1.1"
automatic_release_tag: "1.6.2"
prerelease: false
title: "Release 1.6.1.1"
title: "Release 1.6.2"
files: |
/home/runner/work/Microbot/Microbot/runelite-client/target/microbot-*.jar
Expand Down
2 changes: 1 addition & 1 deletion runelite-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<git.commit.id.abbrev>nogit</git.commit.id.abbrev>
<git.dirty>false</git.dirty>
<shade.skip>false</shade.skip>
<microbot.version>1.6.1.1</microbot.version>
<microbot.version>1.6.2</microbot.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@
*/
package net.runelite.client;

import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ClientShutdown;
import net.runelite.client.plugins.microbot.MicrobotApi;
import net.runelite.client.util.RunnableExceptionLogger;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

@Singleton
@Slf4j
public class ClientSessionManager
Expand All @@ -52,15 +54,17 @@ public class ClientSessionManager

private UUID sessionId;
private UUID microbotSessionId;
private MicrobotApi microbotApi;

@Inject
ClientSessionManager(ScheduledExecutorService executorService,
@Nullable Client client,
SessionClient sessionClient)
SessionClient sessionClient, MicrobotApi microbotApi)
{
this.executorService = executorService;
this.client = client;
this.sessionClient = sessionClient;
this.microbotApi = microbotApi;
}

public void start()
Expand All @@ -70,7 +74,7 @@ public void start()
try
{
sessionId = sessionClient.open();
microbotSessionId = sessionClient.microbotOpen();
microbotSessionId = microbotApi.microbotOpen();
log.debug("Opened session {}", sessionId);
}
catch (IOException ex)
Expand Down Expand Up @@ -100,7 +104,8 @@ private void onClientShutdown(ClientShutdown e)
UUID localMicrobotUuid = microbotSessionId;
if (localMicrobotUuid != null)
{
sessionClient.microbotDelete(localMicrobotUuid);
microbotApi.sendScriptStatistics();
microbotApi.microbotDelete(localMicrobotUuid);
}
}
catch (IOException ex)
Expand Down Expand Up @@ -151,7 +156,7 @@ private void microbotPing()
try
{
if (microbotSessionId == null) {
microbotSessionId = sessionClient.microbotOpen();
microbotSessionId = microbotApi.microbotOpen();
return;
}
}
Expand All @@ -170,7 +175,7 @@ private void microbotPing()

try
{
sessionClient.microbotPing(microbotSessionId, loggedIn);
microbotApi.microbotPing(microbotSessionId, loggedIn);
}
catch (IOException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class RuneLiteProperties
private static final String API_BASE = "runelite.api.base";
private static final String RUNELITE_CONFIG = "runelite.config";
private static final String OSRS_TWITTER_LINK = "runelite.osrstwitter.link";
private static final String MICROBOT_VERSION = "microbot.version";


@Getter(AccessLevel.PACKAGE)
private static final Properties properties = new Properties();
Expand Down Expand Up @@ -140,4 +142,9 @@ public static String getOSRSTwitterLink()
{
return properties.getProperty(OSRS_TWITTER_LINK);
}
public static String getMicrobotVersion()
{
return properties.getProperty(MICROBOT_VERSION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,13 @@ class SessionClient {
private final HttpUrl sessionUrl;
private final Gson gson;

//TODO: put this in the runelite.properties
private final String microbotApiUrl = "https://microbot-api.azurewebsites.net/api";

@Inject
private SessionClient(OkHttpClient client, @Named("runelite.session") HttpUrl sessionUrl, Gson gson) {
this.client = client;
this.sessionUrl = sessionUrl;
this.gson = gson;
}

UUID microbotOpen() throws IOException {
try (Response response = client.newCall(new Request.Builder().url(microbotApiUrl + "/session").build()).execute()) {
ResponseBody body = response.body();

InputStream in = body.byteStream();
return gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), UUID.class);
} catch (JsonParseException | IllegalArgumentException ex) // UUID.fromString can throw IllegalArgumentException
{
throw new IOException(ex);
}
}

void microbotPing(UUID uuid, boolean loggedIn) throws IOException {
try (Response response = client.newCall(new Request.Builder().url(microbotApiUrl + "/session?sessionId=" + uuid.toString()
+ "&isLoggedIn=" + loggedIn
+ "&version=1.10.26" ).build()).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unsuccessful ping");
}
}
}

void microbotDelete(UUID uuid) throws IOException {
Request request = new Request.Builder()
.delete()
.url(microbotApiUrl + "/session?sessionId=" + uuid)
.build();

client.newCall(request).execute().close();
}

UUID open() throws IOException {
HttpUrl url = sessionUrl.newBuilder()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ public void setInjector(Injector injector)
{
this.injector = injector;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.common.reflect.ClassPath.ClassInfo;
import com.google.inject.Module;
import com.google.inject.*;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.RuneLite;
Expand Down Expand Up @@ -79,12 +80,12 @@ public class PluginManager

private final boolean developerMode;
private final boolean safeMode;
private final boolean disableWalkerUpdate;
private final EventBus eventBus;
private final Scheduler scheduler;
private final ConfigManager configManager;
private final Provider<GameEventManager> sceneTileManager;
private final List<Plugin> plugins = new CopyOnWriteArrayList<>();
@Getter
private final List<Plugin> activePlugins = new CopyOnWriteArrayList<>();

@Setter
Expand All @@ -107,7 +108,6 @@ public void addPlugin(Plugin plugin) {
{
this.developerMode = developerMode;
this.safeMode = safeMode;
this.disableWalkerUpdate = disableWalkerUpdate;
this.eventBus = eventBus;
this.scheduler = scheduler;
this.configManager = configManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@
import javax.inject.Inject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -146,28 +144,14 @@ public class Microbot {

public static int cantReachTargetRetries = 0;

@Getter
public static HashMap<String, Integer> scriptRuntimes = new HashMap<>();

public static boolean isDebug() {
return java.lang.management.ManagementFactory.getRuntimeMXBean().
getInputArguments().toString().contains("-agentlib:jdwp");
}

@Deprecated(since = "Use isMoving", forRemoval = true)
public static boolean isWalking() {
return Microbot.getClientThread().runOnClientThread(() -> Microbot.getClient().getLocalPlayer().getPoseAnimation()
!= Microbot.getClient().getLocalPlayer().getIdlePoseAnimation());
}

@Deprecated(since = "1.2.4 - use Rs2Player variant", forRemoval = true)
public static boolean isMoving() {
return Microbot.getClientThread().runOnClientThread(() -> Microbot.getClient().getLocalPlayer().getPoseAnimation()
!= Microbot.getClient().getLocalPlayer().getIdlePoseAnimation());
}

@Deprecated(since = "1.2.4 - use Rs2Player variant", forRemoval = true)
public static boolean isAnimating() {
return Microbot.getClientThread().runOnClientThread(() -> getClient().getLocalPlayer().getAnimation() != -1);
}

public static int getVarbitValue(int varbit) {
return getClientThread().runOnClientThread(() -> getClient().getVarbitValue(varbit));
}
Expand Down Expand Up @@ -209,11 +193,6 @@ public static boolean isHopping() {
return idx == GameState.HOPPING;
}

@Deprecated(since = "1.4.0 - use Rs2Player variant", forRemoval = true)
public static boolean hasLevel(int levelRequired, Skill skill) {
return Microbot.getClient().getRealSkillLevel(skill) >= levelRequired;
}

public static boolean hopToWorld(int worldNumber) {
if (!Microbot.isLoggedIn()) return false;
if (Microbot.isHopping()) return true;
Expand Down Expand Up @@ -349,12 +328,6 @@ public static void click(Rectangle rectangle) {
}
}

@Deprecated(since = "1.3.8 - use Mouse class", forRemoval = true)
private static void mouseEvent(int id, Point point) {
MouseEvent e = new MouseEvent(client.getCanvas(), id, System.currentTimeMillis(), 0, point.getX(), point.getY(), 1, false, 1);
client.getCanvas().dispatchEvent(e);
}

public static List<LootTrackerRecord> getAggregateLootRecords() {
return LootTrackerPlugin.panel.aggregateRecords;
}
Expand Down Expand Up @@ -448,5 +421,68 @@ public static Injector getInjector() {
}
return RuneLite.getInjector();
}

/**
* Retrieves a list of active plugins that are part of the "microbot" package, excluding specific plugins.
*
* This method filters the active plugins managed by the `pluginManager` to include only those whose
* package name contains "microbot" (case-insensitive). It further excludes certain plugins based on
* their class names, such as "QuestHelperPlugin", "MInventorySetupsPlugin", "MicrobotPlugin",
* "MicrobotConfigPlugin", "ShortestPathPlugin", "AntibanPlugin", and "ExamplePlugin".
*
* @return a list of active plugins belonging to the "microbot" package, excluding the specified plugins.
*/
public static List<Plugin> getActiveMicrobotPlugins() {
return pluginManager.getActivePlugins().stream()
.filter(x -> x.getClass().getPackage().getName().toLowerCase().contains("microbot"))
.filter(x -> !x.getClass().getSimpleName().equalsIgnoreCase("QuestHelperPlugin")
&& !x.getClass().getSimpleName().equalsIgnoreCase("MInventorySetupsPlugin")
&& !x.getClass().getSimpleName().equalsIgnoreCase("MicrobotPlugin")
&& !x.getClass().getSimpleName().equalsIgnoreCase("MicrobotConfigPlugin")
&& !x.getClass().getSimpleName().equalsIgnoreCase("ShortestPathPlugin")
&& !x.getClass().getSimpleName().equalsIgnoreCase("AntibanPlugin")
&& !x.getClass().getSimpleName().equalsIgnoreCase("ExamplePlugin"))
.collect(Collectors.toList());
}

/**
* Retrieves a list of active `Script` instances from the currently active microbot plugins.
*
* This method iterates through all active microbot plugins and inspects their fields using reflection
* to find fields of type `Script` or its subclasses. The identified `Script` fields are extracted
* and returned as a list.
*
* Key Details:
* - The method uses reflection to access the fields of each plugin class.
* - Only fields that are assignable to the `Script` type are included.
* - Private fields are made accessible via `field.setAccessible(true)` to retrieve their values.
* - Any exceptions encountered during field access (e.g., `IllegalAccessException`) are logged, and
* the corresponding field is skipped.
* - Null values resulting from inaccessible or uninitialized fields are filtered out.
*
* @return a list of active `Script` instances extracted from the microbot plugins.
*/
public static List<Script> getActiveScripts() {
return getActiveMicrobotPlugins().stream()
.flatMap(x -> {
// Get all fields of the class
Field[] fields = x.getClass().getDeclaredFields();

// Filter fields that are assignable to Script
return java.util.Arrays.stream(fields)
.filter(field -> Script.class.isAssignableFrom(field.getType()))
.map(field -> {
field.setAccessible(true); // Allow access to private fields
try {
return (Script) field.get(x); // Map the field to a Script instance
} catch (IllegalAccessException e) {
e.printStackTrace();
return null; // Handle exception if field cannot be accessed
}
});
})
.filter(Objects::nonNull) // Exclude nulls
.collect(Collectors.toList());
}
}

Loading

0 comments on commit eb4155c

Please sign in to comment.