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

Loads of API fixes and tweaks #36

Merged
merged 1 commit into from
Apr 1, 2020
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 rsb/event/impl/DrawInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onRepaint(final Graphics render) {

for (RSItem inventoryItem : inventoryItems) {
if (inventoryItem.getID() != -1) {
final Point location = inventoryItem.getComponent().getCenter();
final Point location = new Point (inventoryItem.getItem().getItemLocation().getX(), inventoryItem.getItem().getItemLocation().getY() + 20);
render.drawString("" + inventoryItem.getID(), location.x, location.y);
}
}
Expand Down
9 changes: 5 additions & 4 deletions rsb/event/impl/DrawItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public void onRepaint(final Graphics render) {
}
final FontMetrics metrics = render.getFontMetrics();
final RSTile location = player.getLocation();
final int locX = location.getWorldLocation().getX();
final int locY = location.getWorldLocation().getY();
final int locX = location.getTile(ctx).getWorldLocation().getX();//location.getWorldLocation().getX();
final int locY = location.getTile(ctx).getWorldLocation().getY();//location.getWorldLocation().getY();
final int locPlane = location.getTile(ctx).getPlane();
final int tHeight = metrics.getHeight();
for (int x = locX - 25; x < locX + 25; x++) {
for (int y = locY - 25; y < locY + 25; y++) {
final Point screen = ctx.calc.tileToScreen(new RSTile(x, y));
if (!ctx.calc.pointOnScreen(screen)) {
final Point screen = ctx.calc.tileToScreen(new RSTile(x, y, locPlane));
if (screen == null || !ctx.calc.pointOnScreen(screen)) {
continue;
}
final RSGroundItem[] items = ctx.groundItems.getAllAt(x, y);
Expand Down
5 changes: 3 additions & 2 deletions rsb/event/impl/DrawNPCs.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void onRepaint(final Graphics render) {

final FontMetrics metrics = render.getFontMetrics();
for (RSNPC npc : ctx.npcs.getAll()) {
final Point location = ctx.calc.tileToScreen(npc.getLocation(), npc.getHeight() / 2);
if (!ctx.calc.pointOnScreen(location)) {
final Point location = ctx.calc.tileToScreen(npc.getLocation(), ctx.client.getPlane());
//Point location = npc.getScreenLocation();
if (location == null || !ctx.calc.pointOnScreen(location)) {
continue;
}
render.setColor(Color.RED);
Expand Down
9 changes: 5 additions & 4 deletions rsb/event/impl/DrawObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public void onRepaint(final Graphics render) {
}
final FontMetrics metrics = render.getFontMetrics();
final RSTile location = player.getLocation();
final int locX = location.getWorldLocation().getX();
final int locY = location.getWorldLocation().getY();
final int locX = location.getTile(ctx).getWorldLocation().getX();//location.getWorldLocation().getX();
final int locY = location.getTile(ctx).getWorldLocation().getY();//location.getWorldLocation().getY();
final int locPlane = location.getTile(ctx).getPlane();
final int tHeight = metrics.getHeight();
for (int x = locX - 25; x < locX + 25; x++) {
for (int y = locY - 25; y < locY + 25; y++) {
RSTile tile = new RSTile(x, y, ctx.client.getPlane());
RSTile tile = new RSTile(x, y, locPlane);
final Point screen = ctx.calc.tileToScreen(tile);
if (!ctx.calc.pointOnScreen(screen)) {
if (screen == null || !ctx.calc.pointOnScreen(screen)) {
continue;
}
final RSObject[] objects = ctx.objects.getAllAt(tile);
Expand Down
4 changes: 2 additions & 2 deletions rsb/event/impl/DrawPlayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public void onRepaint(final Graphics render) {
continue;
}
final RSPlayer player = element;
final Point location = ctx.calc.tileToScreen(player.getLocation(), player.getHeight() / 2);
if (!ctx.calc.pointOnScreen(location)) {
final Point location = ctx.calc.tileToScreen(player.getLocation(), ctx.client.getPlane());
if (location == null || !ctx.calc.pointOnScreen(location)) {
continue;
}
render.setColor(Color.RED);
Expand Down
8 changes: 5 additions & 3 deletions rsb/event/impl/TFPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
import net.runelite.api.Client;
import net.runelite.client.rsb.botLauncher.RuneLite;
import net.runelite.client.rsb.event.listener.TextPaintListener;
import net.runelite.client.rsb.methods.MethodContext;
import net.runelite.client.rsb.util.StringUtil;

import java.awt.*;

public class TFPS implements TextPaintListener {

private int fps;
private MethodContext ctx;

public TFPS(RuneLite bot) {
fps = bot.getClient().getFPS();
this.ctx = bot.getMethodContext();
}

public int drawLine(final Graphics render, int idx) {
StringUtil.drawLine(render, idx++, String.format("%2d fps", fps));
StringUtil.drawLine(render, idx++, String.format("%2d fps", ctx.client.getFPS()));
return idx;
}
}
15 changes: 10 additions & 5 deletions rsb/event/impl/TPlayerPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.runelite.client.rsb.botLauncher.RuneLite;
import net.runelite.client.rsb.event.listener.TextPaintListener;
import net.runelite.client.rsb.methods.MethodContext;
import net.runelite.client.rsb.methods.Players;
import net.runelite.client.rsb.util.StringUtil;
import net.runelite.client.rsb.wrappers.RSTile;
Expand All @@ -10,16 +11,20 @@

public class TPlayerPosition implements TextPaintListener {

private final Players players;
private MethodContext ctx;

public TPlayerPosition(RuneLite bot) {
players = bot.getMethodContext().players;
ctx = bot.getMethodContext();
}

public int drawLine(final Graphics render, int idx) {
final RSTile position = players.getMyPlayer().getLocation();
StringUtil.drawLine(render, idx++, "Position: " + position);
return idx;
if (ctx.client.getLocalPlayer() != null) {
final RSTile position = ctx.players.getMyPlayer().getLocation();
StringUtil.drawLine(render, idx++, "Player " + position.getWorldLocation().toString());
StringUtil.drawLine(render, idx++, "Player " + position.getLocalLocation(ctx).toString());
return idx;
}
return idx+2;
}

}
9 changes: 8 additions & 1 deletion rsb/event/impl/TTab.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package net.runelite.client.rsb.event.impl;

import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import net.runelite.client.rsb.botLauncher.RuneLite;
import net.runelite.client.rsb.event.listener.TextPaintListener;
import net.runelite.client.rsb.methods.Game;
import net.runelite.client.rsb.util.StringUtil;

import java.awt.*;
import java.util.Arrays;
import java.util.stream.Collectors;

import static net.runelite.client.rsb.methods.Game.TABS;

public class TTab implements TextPaintListener {

Expand All @@ -18,7 +24,8 @@ public TTab(RuneLite bot) {
public int drawLine(final Graphics render, int idx) {
final int cTab = game.getCurrentTab();
StringUtil.drawLine(render, idx++,
"Current Tab: " + cTab + (cTab != -1 ? " (" + Game.TAB_NAMES[cTab] + ")" : ""));
//Ints.asList(Game.TABS).indexOf lets us actually find the object with the value of cTab rather than the obvious array out of bounds you'd normally get
"Current Tab: " + cTab + (cTab != -1 ? " (" + Game.TAB_NAMES[(Ints.asList(Game.TABS).indexOf(cTab))] + ")" : ""));
return idx;
}

Expand Down
15 changes: 11 additions & 4 deletions rsb/methods/Calculations.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ public int angleToTile(RSTile t) {
* <code>new Point(-1, -1)</code>.
*/
public Point tileToScreen(final RSTile tile, final double dX, final double dY, final int height) {
return groundToScreen((int) ((tile.getWorldLocation().getX() - methods.client.getBaseX() + dX) * 512),
(int) ((tile.getWorldLocation().getY() - methods.client.getBaseY() + dY) * 512), height);
return Perspective.localToCanvas(methods.client, LocalPoint.fromWorld(methods.client, tile.getWorldLocation()), height);
/*
return groundToScreen((int) ((tile.getWorldLocation().getX() - methods.client.getBaseX() + 0.5)),
(int) ((tile.getWorldLocation().getY() - methods.client.getBaseY() + 0.5)), height);

*/
}

/**
Expand Down Expand Up @@ -372,12 +376,15 @@ public Point worldToMinimap(double x, double y) {
* <code>new Point(-1, -1)</code>.
*/
public Point groundToScreen(final int x, final int y, final int height) {
return Perspective.localToCanvas(methods.client, x, y, height);
/*
if ((methods.client.getTileSettings() == null) || (methods.client.getTileHeights() == null) || (x < 512) ||
(y < 512) || (x > 52224) || (y > 52224)) {
(y < 512) || (x > 13056) || (y > 52224)) {
return new Point(-1, -1);
}
int z = tileHeight(x, y) + height;
return worldToScreen(x, y, z);
*/
}

/**
Expand Down Expand Up @@ -425,7 +432,7 @@ public int tileHeight(final int x, final int y) {
* <code>new Point(-1, -1)</code>.
*/
public Point worldToScreen(int x, int y, int z) {
return Perspective.localToCanvas(methods.client, x, y, z);
return Perspective.localToCanvas(methods.client, LocalPoint.fromWorld(methods.client, x, y), z);
}

// ---- Internal ----
Expand Down
97 changes: 43 additions & 54 deletions rsb/methods/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,39 @@ public enum ChatMode {
VIEW, ON, FRIENDS, OFF, HIDE, AUTOCHAT, STANDARD, CLEAR, SWITCH
}

public static final int TAB_ATTACK = WidgetInfo.FIXED_VIEWPORT_COMBAT_TAB.getChildId();
public static final int TAB_STATS = WidgetInfo.FIXED_VIEWPORT_STATS_TAB.getChildId();
public static final int TAB_QUESTS = WidgetInfo.FIXED_VIEWPORT_QUESTS_TAB.getChildId();
public static final int TAB_INVENTORY = WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB.getChildId();
public static final int TAB_EQUIPMENT = WidgetInfo.FIXED_VIEWPORT_EQUIPMENT_TAB.getChildId();
public static final int TAB_PRAYER = WidgetInfo.FIXED_VIEWPORT_PRAYER_TAB.getChildId();
public static final int TAB_MAGIC = WidgetInfo.FIXED_VIEWPORT_MAGIC_TAB.getChildId();
public static final int TAB_FRIENDS = WidgetInfo.FIXED_VIEWPORT_FRIENDS_TAB.getChildId();
public static final int TAB_CLAN_CHAT = WidgetInfo.FIXED_VIEWPORT_CLAN_CHAT_TAB.getChildId();
public static final int TAB_OPTIONS = WidgetInfo.FIXED_VIEWPORT_OPTIONS_TAB.getChildId();
public static final int TAB_MUSIC = WidgetInfo.FIXED_VIEWPORT_MUSIC_TAB.getChildId();
public static final int TAB_LOGOUT = WidgetInfo.FIXED_VIEWPORT_LOGOUT_TAB.getChildId();
public static int TAB_ATTACK;
public static int TAB_STATS;
public static int TAB_QUESTS;
public static int TAB_INVENTORY;
public static int TAB_EQUIPMENT;
public static int TAB_PRAYER;
public static int TAB_MAGIC;
public static int TAB_FRIENDS;
public static int TAB_CLAN_CHAT;
public static int TAB_OPTIONS;
public static int TAB_MUSIC;
public static int TAB_LOGOUT;

public static int[] TABS =
{
TAB_ATTACK = WidgetInfo.FIXED_VIEWPORT_COMBAT_TAB.getChildId(),
TAB_STATS = WidgetInfo.FIXED_VIEWPORT_STATS_TAB.getChildId(),
TAB_QUESTS = WidgetInfo.FIXED_VIEWPORT_QUESTS_TAB.getChildId(),
TAB_INVENTORY = WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB.getChildId(),
TAB_EQUIPMENT = WidgetInfo.FIXED_VIEWPORT_EQUIPMENT_TAB.getChildId(),
TAB_PRAYER = WidgetInfo.FIXED_VIEWPORT_PRAYER_TAB.getChildId(),
TAB_MAGIC = WidgetInfo.FIXED_VIEWPORT_MAGIC_TAB.getChildId(),
TAB_FRIENDS = WidgetInfo.FIXED_VIEWPORT_FRIENDS_TAB.getChildId(),
TAB_CLAN_CHAT = WidgetInfo.FIXED_VIEWPORT_CLAN_CHAT_TAB.getChildId(),
TAB_OPTIONS = WidgetInfo.FIXED_VIEWPORT_OPTIONS_TAB.getChildId(),
TAB_MUSIC = WidgetInfo.FIXED_VIEWPORT_MUSIC_TAB.getChildId(),
TAB_LOGOUT = WidgetInfo.FIXED_VIEWPORT_LOGOUT_TAB.getChildId()
};

public static final String[] TAB_NAMES = new String[]{"Combat Styles", "Stats", "Quest Journals", "Inventory",
"Worn Equipment", "Prayer List", "Magic Spellbook",
"Friends List", "Clan Chat", "Options",
"Music Player", "Exit"};

public static final int INDEX_LOGIN_SCREEN = 3;
public static final int INDEX_LOBBY_SCREEN = 7;
Expand Down Expand Up @@ -103,13 +124,6 @@ public enum ChatMode {
421};
public static final int[] INTERFACE_OPTIONS = new int[]{230, 228};

public static final String[] TAB_NAMES = new String[]{"Combat Styles",
"Task System", "Stats", "Quest Journals", "Inventory",
"Worn Equipment", "Prayer List", "Magic Spellbook", "",
"Friends List", "Friends Chat", "Clan Chat", "Options",
"Emotes",
"Music Player", "Notes", "Exit"};

Game(final MethodContext ctx) {
super(ctx);
}
Expand Down Expand Up @@ -258,42 +272,17 @@ public boolean mouseChatButton(int button, boolean left) {
* @return The currently open tab or the logout tab by default.
*/
public int getCurrentTab() {
/*We declare these here for convenience and grouping
Originally this used an invasive method into the RuneLite API, but upon removing this would've
Required far more effort to fix.*/
class Tabs {
public final int TAB_ATTACK = WidgetInfo.FIXED_VIEWPORT_COMBAT_TAB.getChildId();
public final int TAB_STATS = WidgetInfo.FIXED_VIEWPORT_STATS_TAB.getChildId();
public final int TAB_QUESTS = WidgetInfo.FIXED_VIEWPORT_QUESTS_TAB.getChildId();
public final int TAB_INVENTORY = WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB.getChildId();
public final int TAB_EQUIPMENT = WidgetInfo.FIXED_VIEWPORT_EQUIPMENT_TAB.getChildId();
public final int TAB_PRAYER = WidgetInfo.FIXED_VIEWPORT_PRAYER_TAB.getChildId();
public final int TAB_MAGIC = WidgetInfo.FIXED_VIEWPORT_MAGIC_TAB.getChildId();
public final int TAB_FRIENDS = WidgetInfo.FIXED_VIEWPORT_FRIENDS_TAB.getChildId();
public final int TAB_CLAN_CHAT = WidgetInfo.FIXED_VIEWPORT_CLAN_CHAT_TAB.getChildId();
public final int TAB_OPTIONS = WidgetInfo.FIXED_VIEWPORT_OPTIONS_TAB.getChildId();
public final int TAB_MUSIC = WidgetInfo.FIXED_VIEWPORT_MUSIC_TAB.getChildId();
public final int TAB_LOGOUT = WidgetInfo.FIXED_VIEWPORT_LOGOUT_TAB.getChildId();
}
Tabs tabs = new Tabs();
try {
for (Field i : tabs.getClass().getDeclaredFields()) {
int x = Integer.valueOf(i.get(tabs).toString());

net.runelite.api.widgets.Widget tab = methods.gui.getTab(x);
if (tab == null) {
continue;
}

if (tab.getSpriteId() != -1) {
return x;
}
for (int i : TABS) {
net.runelite.api.widgets.Widget tab = methods.gui.getTab(i);
if (tab == null) {
continue;
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return -1; // no selected ones. (never happens, always return
// TAB_LOGOUT)

if (tab.getSpriteId() != -1) {
return i;
}
}
return -1; // no selected ones. (never happens, always return TAB_LOGOUT
}

/**
Expand Down
7 changes: 5 additions & 2 deletions rsb/methods/GroundItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ public RSGroundItem[] getAllAt(int x, int y) {
int id = x | y << 14 | methods.client.getPlane() << 28;

RSTile tile = new RSTile(x, y, methods.client.getPlane());
List<TileItem> groundItems = tile.getTile(methods).getGroundItems();

for (TileItem item : tile.getTile(methods).getGroundItems()) {
list.add(new RSGroundItem(methods, tile, new RSItem(methods, item)));
if (groundItems != null && !groundItems.isEmpty()) {
for (TileItem item : groundItems) {
list.add(new RSGroundItem(methods, tile, new RSItem(methods, item)));
}
}

return list.toArray(new RSGroundItem[list.size()]);
Expand Down
5 changes: 3 additions & 2 deletions rsb/methods/NPCs.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public RSNPC[] getAll(final Filter<RSNPC> filter) {
NPC[] npcs = getNPCs();
Set<RSNPC> rsNPCs = new HashSet<RSNPC>();
for (NPC npc : npcs) {
if (filter.accept((RSNPC) npc)) {
rsNPCs.add((RSNPC) npc);
RSNPC rsnpc = new RSNPC(methods, npc);
if (filter.accept(rsnpc)) {
rsNPCs.add(rsnpc);
}
}
return rsNPCs.toArray(new RSNPC[rsNPCs.size()]);
Expand Down
2 changes: 1 addition & 1 deletion rsb/script/Random.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void stopScript(boolean logout) {

public final void run(Script ctx) {
script = ctx;
//name = getClass().getAnnotation(ScriptManifest.class).name();
name = getClass().getAnnotation(ScriptManifest.class).name();
ctx.ctx.runeLite.getEventManager().removeListener(ctx);
for (Script s : ctx.delegates) {
ctx.ctx.runeLite.getEventManager().removeListener(s);
Expand Down
3 changes: 2 additions & 1 deletion rsb/script/randoms/LoginBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import static java.lang.Thread.sleep;

/**
* @author Iscream, Aut0r, Doout, Pervy
* @author Gigiaj
*/
@ScriptManifest(authors = {"GigiaJ"}, name = "Login", version = 1.0)
@Slf4j
public class LoginBot extends Random {

Expand Down
8 changes: 7 additions & 1 deletion rsb/wrappers/RSTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class RSTile {

private int plane;

public RSTile(Tile tile) {
this.x = tile.getWorldLocation().getX();
this.y = tile.getWorldLocation().getY();
this.plane = tile.getWorldLocation().getPlane();
}

public RSTile(int x, int y, int plane) {
this.x = x;
this.y = y;
Expand Down Expand Up @@ -51,7 +57,7 @@ public Tile getTile(MethodContext ctx) {
WorldPoint worldPoint = new WorldPoint(x, y, plane);
if (worldPoint.isInScene(ctx.client)) {
LocalPoint localPoint = LocalPoint.fromWorld(ctx.client, worldPoint);
return ctx.client.getScene().getTiles()[worldPoint.getPlane()][localPoint.getX()][localPoint.getY()];
return ctx.client.getScene().getTiles()[worldPoint.getPlane()][localPoint.getSceneX()][localPoint.getSceneY()];
}
return null;
}
Expand Down