mes: Add right click 'Last-destination' option for Jewellery Boxes (#1737)

* api: menu event, prio runelite menuopcode, widget stuff, eventbus logging

add "Menu" event to keep everything in chronological order

add MenuOpcode.PRIO_RUNELITE which is sub 1000 so it doesn't get sorted

add Jewellery box widget info

add getOnOp

fix exception logging in eventbus

redisable gpu debug messages

* mes: add (right click only) last destination to jewellery boxes

* mes: use Object objects for eventbus instead of strings
This commit is contained in:
Lucwousin
2019-10-08 20:18:20 +02:00
committed by Ganom
parent eadc7bc1b6
commit 1a1684d1c3
19 changed files with 1682 additions and 775 deletions

View File

@@ -12,7 +12,6 @@ import java.util.Objects;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.Event;
import org.apache.commons.lang3.exception.ExceptionUtils;
@Slf4j
@Singleton
@@ -55,8 +54,7 @@ public class EventBus implements EventBusInterface
.cast(eventClass) // Cast it for easier usage
.subscribe(action, error ->
{
log.error("Error in eventbus: {}", error.getMessage());
log.error(ExceptionUtils.getStackTrace(error));
log.error("Error in eventbus", error);
});
getCompositeDisposable(lifecycle).add(disposable);

View File

@@ -291,11 +291,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
modelBufferSmall = new GpuIntBuffer();
modelBuffer = new GpuIntBuffer();
if (log.isDebugEnabled())
{
System.setProperty("jogl.debug", "true");
}
GLProfile.initSingleton();
GLProfile glProfile = GLProfile.get(GLProfile.GL4);

View File

@@ -2,7 +2,7 @@
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2019, alanbaumgartner <https://github.com/alanbaumgartner>
* Copyright (c) 2019, Kyle <https://github.com/kyleeld>
* Copyright (c) 2019, lucouswin <https://github.com/lucouswin>
* Copyright (c) 2019, Lucas <https://github.com/lucwousin>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1292,6 +1292,17 @@ public interface MenuEntrySwapperConfig extends Config
// Teleportation
//------------------------------------------------------------//
@ConfigItem(
keyName = "lastJewel",
name = "Last Destination for Jewellery Box",
description = "Adds a \"Last-destination\" menu option when Jewellery Boxes are right clicked",
section = "teleportationSection"
)
default boolean lastJewel()
{
return true;
}
@ConfigItem(
keyName = "swapFairyRing",
name = "Fairy Ring",
@@ -1913,4 +1924,23 @@ public interface MenuEntrySwapperConfig extends Config
{
return "cure other, energy transfer, heal other, vengeance other";
}
@ConfigItem(
keyName = "lastDes",
name = "",
description = "Last jewellery box destination (option)",
hidden = true
)
default String lastDes()
{
return "";
}
@ConfigItem(
keyName = "lastDes",
name = "",
description = "Last jewellery box destination (option)",
hidden = true
)
void lastDes(String des);
}

View File

@@ -3,7 +3,7 @@
* Copyright (c) 2018, Kamiel
* Copyright (c) 2019, alanbaumgartner <https://github.com/alanbaumgartner>
* Copyright (c) 2019, Kyle <https://github.com/kyleeld>
* Copyright (c) 2019, lucouswin <https://github.com/lucouswin>
* Copyright (c) 2019, Lucas <https://github.com/lucwousin>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -65,10 +65,16 @@ import net.runelite.api.events.ClientTick;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.Menu;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOpened;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.util.Text;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.Keybind;
@@ -102,6 +108,7 @@ import net.runelite.client.plugins.menuentryswapper.util.GamesNecklaceMode;
import net.runelite.client.plugins.menuentryswapper.util.GloryMode;
import net.runelite.client.plugins.menuentryswapper.util.HouseAdvertisementMode;
import net.runelite.client.plugins.menuentryswapper.util.HouseMode;
import net.runelite.client.plugins.menuentryswapper.util.JewelleryBoxDestination;
import net.runelite.client.plugins.menuentryswapper.util.MaxCapeMode;
import net.runelite.client.plugins.menuentryswapper.util.NecklaceOfPassageMode;
import net.runelite.client.plugins.menuentryswapper.util.ObeliskMode;
@@ -115,6 +122,7 @@ import net.runelite.client.plugins.pvptools.PvpToolsConfig;
import net.runelite.client.plugins.pvptools.PvpToolsPlugin;
import net.runelite.client.util.HotkeyListener;
import static net.runelite.client.util.MenuUtil.swap;
import org.apache.commons.lang3.ArrayUtils;
@PluginDescriptor(
name = "Menu Entry Swapper",
@@ -127,10 +135,14 @@ import static net.runelite.client.util.MenuUtil.swap;
@PluginDependency(PvpToolsPlugin.class)
public class MenuEntrySwapperPlugin extends Plugin
{
private static final String HOTKEY = "menuentryswapper hotkey";
private static final String CONTROL = "menuentryswapper control";
private static final String HOTKEY_CHECK = "menuentryswapper hotkey check";
private static final String CONTROL_CHECK = "menuentryswapper control check";
private static final Object HOTKEY = new Object();
private static final Object CONTROL = new Object();
private static final Object HOTKEY_CHECK = new Object();
private static final Object CONTROL_CHECK = new Object();
private static final Object JEWEL_CLICKED = new Object();
private static final Object JEWEL_TELE = new Object();
private static final Object JEWEL_WIDGET = new Object();
private static final int PURO_PURO_REGION_ID = 10307;
private static final Set<MenuOpcode> NPC_MENU_TYPES = ImmutableSet.of(
MenuOpcode.NPC_FIRST_OPTION, MenuOpcode.NPC_SECOND_OPTION, MenuOpcode.NPC_THIRD_OPTION,
@@ -286,6 +298,8 @@ public class MenuEntrySwapperPlugin extends Plugin
private boolean swapTravel;
private boolean swapWildernessLever;
private JewelleryBoxDestination lastDes;
@Provides
MenuEntrySwapperConfig provideConfig(ConfigManager configManager)
{
@@ -295,6 +309,8 @@ public class MenuEntrySwapperPlugin extends Plugin
@Override
public void startUp()
{
this.lastDes = JewelleryBoxDestination.withOption(config.lastDes());
migrateConfig();
updateConfig();
addSubscriptions();
@@ -346,6 +362,11 @@ public class MenuEntrySwapperPlugin extends Plugin
eventBus.subscribe(MenuOpened.class, this, this::onMenuOpened);
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded);
eventBus.subscribe(FocusChanged.class, this, this::onFocusChanged);
if (config.lastJewel())
{
eventBus.subscribe(MenuOptionClicked.class, JEWEL_CLICKED, this::onMenuOptionClicked);
}
}
private void onFocusChanged(FocusChanged event)
@@ -400,6 +421,16 @@ public class MenuEntrySwapperPlugin extends Plugin
case "removedObjects":
updateRemovedObjects();
return;
case "lastJewel":
if (config.lastJewel())
{
eventBus.subscribe(MenuOptionClicked.class, JEWEL_CLICKED, this::onMenuOptionClicked);
}
else
{
eventBus.unregister(JEWEL_CLICKED);
}
return;
}
if (event.getKey().startsWith("swapSell") || event.getKey().startsWith("swapBuy") ||
@@ -524,6 +555,21 @@ public class MenuEntrySwapperPlugin extends Plugin
}
}
if (config.lastJewel() && option.equals("teleport") && entry.getTarget().contains("Jewellery Box") && lastDes != null)
{
final MenuEntry lastDesEntry = new MenuEntry();
lastDesEntry.setOpcode(MenuOpcode.PRIO_RUNELITE.getId());
lastDesEntry.setOption(lastDes.getOption());
lastDesEntry.setTarget(entry.getTarget());
lastDesEntry.setIdentifier(entry.getIdentifier());
lastDesEntry.setParam0(entry.getParam0());
lastDesEntry.setParam1(entry.getParam1());
menu_entries.add(lastDesEntry);
}
menu_entries.add(entry);
}
@@ -676,6 +722,84 @@ public class MenuEntrySwapperPlugin extends Plugin
}
}
private void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getOpcode() == MenuOpcode.WIDGET_DEFAULT.getId() &&
WidgetInfo.TO_GROUP(event.getActionParam1()) == WidgetID.JEWELLERY_BOX_GROUP_ID)
{
if (event.getOption().equals(lastDes == null ? null : lastDes.getOption()))
{
return;
}
JewelleryBoxDestination newDest = JewelleryBoxDestination.withOption(event.getOption());
if (newDest == null)
{
return;
}
lastDes = newDest;
config.lastDes(lastDes.getOption());
}
else if (event.getOption().equals("Teleport") && event.getTarget().contains("Jewellery Box"))
{
eventBus.unregister("wait for widget");
}
else if (lastDes != null &&
event.getOpcode() == MenuOpcode.PRIO_RUNELITE.getId() &&
event.getOption().equals(lastDes.getOption()))
{
MenuEntry e = event.getMenuEntry();
e.setOption("Teleport");
e.setOpcode(MenuOpcode.GAME_OBJECT_FIRST_OPTION.getId());
eventBus.subscribe(ScriptCallbackEvent.class, JEWEL_WIDGET, this::onScriptCallback);
}
}
private void onScriptCallback(ScriptCallbackEvent event)
{
if (!event.getEventName().equals("jewelleryBoxDone"))
{
return;
}
eventBus.unregister(JEWEL_WIDGET);
// Use a event so we don't accidentally run another script before returning
// menu also is when jagex is probably expecting input like this so :)
eventBus.subscribe(Menu.class, JEWEL_TELE, this::teleportInputs);
}
private void teleportInputs(Menu menu)
{
final Widget parent = client.getWidget(lastDes.getParent());
if (parent == null)
{
return;
}
final Widget child = parent.getChild(lastDes.getChildIndex());
if (child == null)
{
return;
}
Object[] args = child.getOnOp();
if (args == null)
{
return;
}
// Replace opIndex with 1
args[ArrayUtils.indexOf(args, 0x80000004)] = 1;
client.runScript(args);
eventBus.unregister(JEWEL_TELE);
menu.dontRun();
}
private void loadCustomSwaps(String config, Map<AbstractComparableEntry, Integer> map)
{
final Map<AbstractComparableEntry, Integer> tmp = new HashMap<>();

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2019, Lucas <https://github.com/lucwousin>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.menuentryswapper.util;
import com.google.common.collect.ImmutableMap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.runelite.api.widgets.WidgetInfo;
@RequiredArgsConstructor
@Getter
public enum JewelleryBoxDestination
{
DUEL_ARENA("Duel Arena", WidgetInfo.JEWELLERY_BOX_DUEL_RING, 5),
CASTLE_WARS("Castle Wars", WidgetInfo.JEWELLERY_BOX_DUEL_RING, 6),
CLAN_WARS("Clan Wars", WidgetInfo.JEWELLERY_BOX_DUEL_RING, 7),
BURTHORPE("Burthorpe", WidgetInfo.JEWELLERY_BOX_GAME_NECK, 5),
BARB_OUTPOST("Barbarian Outpost", WidgetInfo.JEWELLERY_BOX_GAME_NECK, 6),
CORP("Corporeal Beast", WidgetInfo.JEWELLERY_BOX_GAME_NECK, 7),
TEARS_OF_GUTHIX("Tears of Guthix", WidgetInfo.JEWELLERY_BOX_GAME_NECK, 8),
WINTERTODT("Wintertodt Camp", WidgetInfo.JEWELLERY_BOX_GAME_NECK, 9),
WARRIOR_GUILD("Warriors' Guild", WidgetInfo.JEWELLERY_BOX_COMB_BRAC, 5),
CHAMPION_GUILD("Champions' Guild", WidgetInfo.JEWELLERY_BOX_COMB_BRAC, 6),
MONASTERY("Monastery", WidgetInfo.JEWELLERY_BOX_COMB_BRAC, 7),
RANGING_GUILD("Ranging Guild", WidgetInfo.JEWELLERY_BOX_COMB_BRAC, 8),
FISHING_GUILD("Fishing Guild", WidgetInfo.JEWELLERY_BOX_SKIL_NECK, 5),
MINING_GUILD("Mining Guild", WidgetInfo.JEWELLERY_BOX_SKIL_NECK, 6),
CRAFTING_GUILD("Crafting Guild", WidgetInfo.JEWELLERY_BOX_SKIL_NECK, 7),
COOKING_GUILD("Cooking Guild", WidgetInfo.JEWELLERY_BOX_SKIL_NECK, 8),
WOODCUTTING_GUILD("Woodcutting Guild", WidgetInfo.JEWELLERY_BOX_SKIL_NECK, 9),
FARMING_GUILD("Farming Guild", WidgetInfo.JEWELLERY_BOX_SKIL_NECK, 10),
MISCELLANIA("Miscellania", WidgetInfo.JEWELLERY_BOX_RING_OFGP, 5),
GRAND_EXCHANGE("Grand Exchange", WidgetInfo.JEWELLERY_BOX_RING_OFGP, 6),
FALADOR_PARK("Falador Park", WidgetInfo.JEWELLERY_BOX_RING_OFGP, 7),
DONDAKAN("Dondakan's Rock", WidgetInfo.JEWELLERY_BOX_RING_OFGP, 8),
EDGEVILLE("Edgeville", WidgetInfo.JEWELLERY_BOX_AMUL_GLOR, 5),
KARAMJA("Karamja", WidgetInfo.JEWELLERY_BOX_AMUL_GLOR, 6),
DRAYNOR("Draynor Village", WidgetInfo.JEWELLERY_BOX_AMUL_GLOR, 7),
AL_KHARID("Al Kharid", WidgetInfo.JEWELLERY_BOX_AMUL_GLOR, 8);
final String option;
final WidgetInfo parent;
final int childIndex;
private static final ImmutableMap<String, JewelleryBoxDestination> map;
static
{
final ImmutableMap.Builder<String, JewelleryBoxDestination> builder = ImmutableMap.builderWithExpectedSize(values().length);
for (JewelleryBoxDestination val : values())
{
builder.put(val.option, val);
}
map = builder.build();
}
public static JewelleryBoxDestination withOption(String option)
{
return map.get(option);
}
}