diff --git a/src/main/java/com/github/manolo8/darkbot/Bot.java b/src/main/java/com/github/manolo8/darkbot/Bot.java index b8d822b62..c61d0ab54 100644 --- a/src/main/java/com/github/manolo8/darkbot/Bot.java +++ b/src/main/java/com/github/manolo8/darkbot/Bot.java @@ -55,7 +55,11 @@ public static void main(String[] args) throws IOException { UIManager.put("Table.cellFocusColor", new Color(0, 0, 0, 160)); // set icon here to use it in login popup, java check popup etc. - Popups.setDefaultIcon(MainGui.ICON); + try { + Popups.setDefaultIcon(MainGui.ICON); + } catch (Exception e) { + e.printStackTrace(); + } // Not recommended to keep for production //FlatInspector.install("ctrl shift alt X"); diff --git a/src/main/java/com/github/manolo8/darkbot/config/Config.java b/src/main/java/com/github/manolo8/darkbot/config/Config.java index 2aa8bf603..667c07356 100644 --- a/src/main/java/com/github/manolo8/darkbot/config/Config.java +++ b/src/main/java/com/github/manolo8/darkbot/config/Config.java @@ -294,6 +294,7 @@ public static class Performance { public @Option @Visibility(Level.INTERMEDIATE) Other OTHER = new Other(); public static class Other { + public @Option boolean SHOW_INSTRUCTIONS = true; public @Option boolean DISABLE_MASTER_PASSWORD = false; public @Option boolean ALWAYS_SHOW_CAPTCHA = false; public @Option @Number(min = 10, max = 300) int ZONE_RESOLUTION = 30; diff --git a/src/main/java/com/github/manolo8/darkbot/core/entities/Box.java b/src/main/java/com/github/manolo8/darkbot/core/entities/Box.java index 2448f9707..7188a8c15 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/entities/Box.java +++ b/src/main/java/com/github/manolo8/darkbot/core/entities/Box.java @@ -3,7 +3,9 @@ import com.github.manolo8.darkbot.config.BoxInfo; import com.github.manolo8.darkbot.config.ConfigEntity; import com.github.manolo8.darkbot.core.api.Capability; +import com.github.manolo8.darkbot.core.manager.HeroManager; import com.github.manolo8.darkbot.utils.Offsets; +import eu.darkbot.api.game.other.Location; import eu.darkbot.util.Timer; import org.jetbrains.annotations.Nullable; @@ -26,6 +28,10 @@ public class Box extends Entity implements eu.darkbot.api.game.entities.Box { public BoxInfo boxInfo; + private Box(int id) { + super(id); + } + public Box(int id, long address) { super(id); this.update(address); @@ -135,4 +141,61 @@ public Beacon(int id, long address) { super(id, address); } } + + public static class FakeBox extends Box implements eu.darkbot.api.game.entities.FakeEntity.FakeBox { + private static int CURR_ID = Integer.MIN_VALUE; + private Timer timeout; + private long removeDistance; + private boolean isRemoveWhenAttemptSelect; + + public FakeBox(String boxName, Location loc, long removeDistance, long keepAlive, boolean isRemoveWhenAttemptSelect) { + super(CURR_ID++); + super.locationInfo.updatePosition(loc.x(), loc.y()); + super.main = HeroManager.instance.main; + super.type = boxName; + super.boxInfo = ConfigEntity.INSTANCE.getOrCreateBoxInfo(type); + super.removed = false; + setRemoveDistance(removeDistance); + setTimeout(keepAlive); + setRemoveWhenAttemptSelect(isRemoveWhenAttemptSelect); + } + + public void setTimeout(long keepAlive) { + if (keepAlive != -1) { + timeout = Timer.get(keepAlive); + timeout.activate(); + } + else timeout = null; + } + + public void setRemoveDistance(long removeDistance) { + this.removeDistance = removeDistance; + } + + public void setRemoveWhenAttemptSelect(boolean removeWhenAttemptSelect) { + isRemoveWhenAttemptSelect = removeWhenAttemptSelect; + } + + public String getHash() { + return type + locationInfo.getCurrent(); + } + + public boolean tryCollect() { + return trySelect(false); + } + + public boolean isInvalid(long mapAddress) { + if (timeout != null && timeout.isInactive()) return false; + return HeroManager.instance.distanceTo(this) < removeDistance; + } + + public boolean trySelect(boolean tryAttack) { + if (isRemoveWhenAttemptSelect) removed(); + return false; + } + + public void update() {} + + public void update(long address) {} + } } diff --git a/src/main/java/com/github/manolo8/darkbot/core/entities/Mine.java b/src/main/java/com/github/manolo8/darkbot/core/entities/Mine.java index dbc82cce6..965a9cb40 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/entities/Mine.java +++ b/src/main/java/com/github/manolo8/darkbot/core/entities/Mine.java @@ -1,8 +1,11 @@ package com.github.manolo8.darkbot.core.entities; import com.github.manolo8.darkbot.core.itf.Obstacle; +import com.github.manolo8.darkbot.core.manager.HeroManager; import com.github.manolo8.darkbot.core.utils.pathfinder.AreaImpl; import com.github.manolo8.darkbot.core.utils.pathfinder.CircleImpl; +import eu.darkbot.api.game.other.Location; +import eu.darkbot.util.Timer; import static com.github.manolo8.darkbot.Main.API; @@ -14,6 +17,10 @@ public class Mine extends Entity implements Obstacle, eu.darkbot.api.game.entiti private final CircleImpl area = new CircleImpl(0, 0, 200); + private Mine(int id) { + super(id); + } + public Mine(int id, long address) { super(id); this.update(address); @@ -58,4 +65,42 @@ public String toString() { public int getTypeId() { return typeId; } + + public static class FakeMine extends Mine implements eu.darkbot.api.game.entities.FakeEntity.FakeMine { + private static int CURR_ID = Integer.MIN_VALUE; + private Timer timeout; + private long removeDistance; + + public FakeMine(int typeId, Location loc, long removeDistance, long keepAlive) { + super(CURR_ID++); + super.locationInfo.updatePosition(loc.x(), loc.y()); + super.main = HeroManager.instance.main; + super.typeId = typeId; + super.area.set(locationInfo.now, typeId == FROZEN_LAB_MINE ? 500 : 200); + super.removed = false; + setTimeout(keepAlive); + setRemoveDistance(removeDistance); + } + + public void setTimeout(long keepAlive) { + if (keepAlive != -1) { + timeout = Timer.get(keepAlive); + timeout.activate(); + } + else timeout = null; + } + + public void setRemoveDistance(long removeDistance) { + this.removeDistance = removeDistance; + } + + public boolean isInvalid(long mapAddress) { + if (timeout != null && timeout.isInactive()) return true; + return removeDistance == -1 || HeroManager.instance.distanceTo(this) < removeDistance; + } + + public void update() {} + + public void update(long address) {} + } } diff --git a/src/main/java/com/github/manolo8/darkbot/core/entities/Npc.java b/src/main/java/com/github/manolo8/darkbot/core/entities/Npc.java index 39e6b9370..7ae9de642 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/entities/Npc.java +++ b/src/main/java/com/github/manolo8/darkbot/core/entities/Npc.java @@ -3,6 +3,10 @@ import com.github.manolo8.darkbot.config.ConfigEntity; import com.github.manolo8.darkbot.config.NpcInfo; import com.github.manolo8.darkbot.core.manager.EffectManager; +import com.github.manolo8.darkbot.core.manager.HeroManager; +import eu.darkbot.api.game.entities.FakeEntity; +import eu.darkbot.api.game.other.Location; +import eu.darkbot.util.Timer; import java.util.Objects; @@ -53,4 +57,59 @@ public eu.darkbot.api.config.types.NpcInfo getInfo() { public int getShipId() { return getNpcId(); } + + public static class FakeNpc extends Npc implements FakeEntity.FakeShip { + private static int CURR_ID = Integer.MIN_VALUE; + private Timer timeout; + private long removeDistance; + private boolean isRemoveWhenAttemptSelect; + + public FakeNpc(String npcName, Location loc, long removeDistance, long keepAlive, boolean isRemoveWhenAttemptSelect) { + super(CURR_ID++); + this.npcInfo = ConfigEntity.INSTANCE.getOrCreateNpcInfo(npcName); + setLocation(loc); + setRemoveDistance(removeDistance); + setTimeout(keepAlive); + setRemoveWhenAttemptSelect(isRemoveWhenAttemptSelect); + } + + @Override + public void setRemoveWhenAttemptSelect(boolean removeWhenAttemptSelect) { + isRemoveWhenAttemptSelect = removeWhenAttemptSelect; + } + + @Override + public void setLocation(Location loc) { + locationInfo.updatePosition(loc.x(), loc.y()); + } + + @Override + public void setTimeout(long keepAlive) { + if (keepAlive != -1) { + timeout = Timer.get(keepAlive); + timeout.activate(); + } + else timeout = null; + } + + @Override + public void setRemoveDistance(long distance) { + removeDistance = distance; + } + + + public boolean trySelect(boolean tryAttack) { + if (isRemoveWhenAttemptSelect) removed(); + return false; + } + + public boolean isInvalid(long mapAddress) { + if (timeout != null && timeout.isInactive()) return false; + return HeroManager.instance.distanceTo(this) < removeDistance; + } + + public void update() {} + + public void update(long address) {} + } } diff --git a/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java b/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java index e74e4b9f1..27195435b 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java +++ b/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java @@ -141,6 +141,7 @@ public GuiManager(Main main, PluginAPI pluginAPI, RepairManager repairManager) { this.assembly = register("assembly"); register("ggBuilder", GateSpinnerGui.class); + register("refinement_count"); this.commandCenter = register("command_center"); diff --git a/src/main/java/com/github/manolo8/darkbot/core/utils/EntityList.java b/src/main/java/com/github/manolo8/darkbot/core/utils/EntityList.java index 101963825..b045a58c4 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/utils/EntityList.java +++ b/src/main/java/com/github/manolo8/darkbot/core/utils/EntityList.java @@ -23,6 +23,7 @@ import com.github.manolo8.darkbot.core.objects.swf.ObjArray; import com.github.manolo8.darkbot.core.utils.factory.EntityFactory; import com.github.manolo8.darkbot.core.utils.factory.EntityRegistry; +import eu.darkbot.api.game.entities.FakeEntity; import eu.darkbot.api.game.entities.Mist; import eu.darkbot.api.game.entities.Station; import eu.darkbot.api.managers.EntitiesAPI; @@ -128,6 +129,24 @@ private void onEntityCreate(Entity entity) { this.eventBroker.sendEvent(new EntityCreateEvent(entity)); } + public FakeEntity.FakeMine createFakeMine(int typeId, eu.darkbot.api.game.other.Location loc, long removeDistance, long keepAlive) { + return register(new Mine.FakeMine(typeId, loc, removeDistance, keepAlive), mines); + } + + public FakeEntity.FakeBox createFakeBox(String boxName, eu.darkbot.api.game.other.Location loc, long removeDistance, long keepAlive, boolean removeIfAttemptSelect) { + return register(new Box.FakeBox(boxName, loc, removeDistance, keepAlive, removeIfAttemptSelect), boxes); + } + + public FakeEntity.FakeShip createFakeNpc(String npcName, eu.darkbot.api.game.other.Location loc, long removeDistance, long keepAlive, boolean removeIfAttemptSelect) { + return register(new Npc.FakeNpc(npcName, loc, removeDistance, keepAlive, removeIfAttemptSelect), npcs); + } + + private T register(T entity, Collection collection) { + collection.add(entity); + onEntityCreate(entity); + return entity; + } + @SuppressWarnings("unchecked") private List register(EntityFactory... types) { List list = new ArrayList<>(); diff --git a/src/main/java/com/github/manolo8/darkbot/extensions/features/decorators/InstructionProviderDecorator.java b/src/main/java/com/github/manolo8/darkbot/extensions/features/decorators/InstructionProviderDecorator.java index d9649b932..c97d948e5 100644 --- a/src/main/java/com/github/manolo8/darkbot/extensions/features/decorators/InstructionProviderDecorator.java +++ b/src/main/java/com/github/manolo8/darkbot/extensions/features/decorators/InstructionProviderDecorator.java @@ -1,5 +1,6 @@ package com.github.manolo8.darkbot.extensions.features.decorators; +import com.github.manolo8.darkbot.config.ConfigEntity; import com.github.manolo8.darkbot.extensions.features.FeatureDefinition; import com.github.manolo8.darkbot.gui.utils.Popups; import com.github.manolo8.darkbot.utils.I18n; @@ -13,7 +14,10 @@ public class InstructionProviderDecorator extends FeatureDecorator fd, InstructionProvider obj) { - if (obj instanceof Module && !(obj instanceof TemporalModule)) showInstructions(obj, fd.getName()); + if (obj instanceof Module + && !(obj instanceof TemporalModule) + && ConfigEntity.INSTANCE.getConfig().BOT_SETTINGS.OTHER.SHOW_INSTRUCTIONS + ) showInstructions(obj, fd.getName()); } @Override diff --git a/src/main/java/com/github/manolo8/darkbot/extensions/plugins/PluginClassLoader.java b/src/main/java/com/github/manolo8/darkbot/extensions/plugins/PluginClassLoader.java index a0b4dcb05..bbe2ef352 100644 --- a/src/main/java/com/github/manolo8/darkbot/extensions/plugins/PluginClassLoader.java +++ b/src/main/java/com/github/manolo8/darkbot/extensions/plugins/PluginClassLoader.java @@ -36,6 +36,13 @@ private static Predicate toMatcher(String pattern) { super(urls); } + @SuppressWarnings("unused") + public Class defineClass(String name, byte[] bytes) throws ClassNotFoundException { + if (PROTECTED.stream().anyMatch(p -> p.test(name))) + throw new ClassNotFoundException(name + " is a protected class"); + return super.defineClass(name, bytes, 0 ,bytes.length); + } + @Override public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { if (PROTECTED.stream().anyMatch(p -> p.test(name))) diff --git a/src/main/resources/lang/strings_en.properties b/src/main/resources/lang/strings_en.properties index a32011db6..55c59d9a9 100644 --- a/src/main/resources/lang/strings_en.properties +++ b/src/main/resources/lang/strings_en.properties @@ -317,6 +317,10 @@ config.bot_settings.other.zone_resolution.desc=Amount of map subdivisions when s config.bot_settings.other.min_tick=Minimum tick time config.bot_settings.other.dev_stuff=Developer stuff shown config.bot_settings.other.dev_stuff.desc=Enabling this WILL make your bot use more cpu. +config.bot_settings.other.show_instructions=Show instructions +config.bot_settings.other.show_instructions.desc=Enabling showing instructions for modules after loading it +config.bot_settings.other.cross_app_events_router_address=Cross-application router +config.bot_settings.other.cross_app_events_router_address.desc=Address of router for cross-application communication (empty - disabled) # Misc misc.editor.checkbox_list.selected={0} selected