devtools plugin: add commands to get and set varbits
This commit is contained in:
@@ -167,6 +167,12 @@ public interface Client extends GameEngine
|
|||||||
|
|
||||||
int getSetting(Varbits varbit);
|
int getSetting(Varbits varbit);
|
||||||
|
|
||||||
|
void setSetting(Varbits varbit, int value);
|
||||||
|
|
||||||
|
int getVarbitValue(int varbit);
|
||||||
|
|
||||||
|
void setVarbitValue(int varbit, int value);
|
||||||
|
|
||||||
HashTable getWidgetFlags();
|
HashTable getWidgetFlags();
|
||||||
|
|
||||||
HashTable getComponentTable();
|
HashTable getComponentTable();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.devtools;
|
package net.runelite.client.plugins.devtools;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
@@ -33,7 +34,10 @@ import java.util.Collection;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.ChatMessageType;
|
||||||
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.events.CommandExecuted;
|
import net.runelite.api.events.CommandExecuted;
|
||||||
|
import net.runelite.api.events.VarbitChanged;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
@@ -50,6 +54,9 @@ import net.runelite.client.ui.overlay.Overlay;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class DevToolsPlugin extends Plugin
|
public class DevToolsPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
@Inject
|
||||||
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PluginToolbar pluginToolbar;
|
private PluginToolbar pluginToolbar;
|
||||||
|
|
||||||
@@ -62,6 +69,9 @@ public class DevToolsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private BorderOverlay borderOverlay;
|
private BorderOverlay borderOverlay;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EventBus eventBus;
|
||||||
|
|
||||||
private boolean togglePlayers;
|
private boolean togglePlayers;
|
||||||
private boolean toggleNpcs;
|
private boolean toggleNpcs;
|
||||||
private boolean toggleGroundItems;
|
private boolean toggleGroundItems;
|
||||||
@@ -123,9 +133,28 @@ public class DevToolsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onCommand(CommandExecuted commandExecuted) {
|
public void onCommand(CommandExecuted commandExecuted)
|
||||||
if (commandExecuted.getCommand().equalsIgnoreCase("test")) {
|
{
|
||||||
log.debug("Test!");
|
String[] args = commandExecuted.getArguments();
|
||||||
|
|
||||||
|
switch (commandExecuted.getCommand())
|
||||||
|
{
|
||||||
|
case "getvar":
|
||||||
|
{
|
||||||
|
int varbit = Integer.parseInt(args[0]);
|
||||||
|
int value = client.getVarbitValue(varbit);
|
||||||
|
client.addChatMessage(ChatMessageType.SERVER, "", "Varbit " + varbit + ": " + value, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "setvar":
|
||||||
|
{
|
||||||
|
int varbit = Integer.parseInt(args[0]);
|
||||||
|
int value = Integer.parseInt(args[1]);
|
||||||
|
client.setVarbitValue(varbit, value);
|
||||||
|
client.addChatMessage(ChatMessageType.SERVER, "", "Set varbit " + varbit + " to " + value, null);
|
||||||
|
eventBus.post(new VarbitChanged()); // fake event
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,21 @@ public abstract class VarbitMixin implements RSClient
|
|||||||
public int getSetting(Varbits varbit)
|
public int getSetting(Varbits varbit)
|
||||||
{
|
{
|
||||||
int varbitId = varbit.getId();
|
int varbitId = varbit.getId();
|
||||||
|
return getVarbitValue(varbitId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void setSetting(Varbits varbit, int value)
|
||||||
|
{
|
||||||
|
int varbitId = varbit.getId();
|
||||||
|
setVarbitValue(varbitId, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public int getVarbitValue(int varbitId)
|
||||||
|
{
|
||||||
RSVarbit v = varbitCache.getIfPresent(varbitId);
|
RSVarbit v = varbitCache.getIfPresent(varbitId);
|
||||||
if (v == null)
|
if (v == null)
|
||||||
{
|
{
|
||||||
@@ -71,4 +86,24 @@ public abstract class VarbitMixin implements RSClient
|
|||||||
int mask = (1 << ((msb - lsb) + 1)) - 1;
|
int mask = (1 << ((msb - lsb) + 1)) - 1;
|
||||||
return (value >> lsb) & mask;
|
return (value >> lsb) & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void setVarbitValue(int varbitId, int value)
|
||||||
|
{
|
||||||
|
RSVarbit v = varbitCache.getIfPresent(varbitId);
|
||||||
|
if (v == null)
|
||||||
|
{
|
||||||
|
client.getVarbit(varbitId); // load varbit into cache
|
||||||
|
RSNodeCache varbits = client.getVarbitCache();
|
||||||
|
v = (RSVarbit) varbits.get(varbitId); // get from cache
|
||||||
|
varbitCache.put(varbitId, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] varps = getVarps();
|
||||||
|
int lsb = v.getLeastSignificantBit();
|
||||||
|
int msb = v.getMostSignificantBit();
|
||||||
|
int mask = (1 << ((msb - lsb) + 1)) - 1;
|
||||||
|
varps[v.getIndex()] = (varps[v.getIndex()] & ~(mask << lsb)) | ((value & mask) << lsb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user