Skip to content

Commit

Permalink
Add builtin plugin to handle additional pluginhubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnuh committed Oct 3, 2023
1 parent 7d5fe26 commit f0b4f37
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 43 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@ Random project I made to run my own custom or modified external plugins on the o

![example](https://im.arnah.ca/3cB8zf5ZaE.png)

If properly done, you should see "RuneLiteHijack Plugin Hub" in plugin configuration
If properly done, you should see "RuneLiteHijack Plugin Hub" or a "RuneLiteHijack" plugin in plugin configuration

![example](https://im.arnah.ca/Bn1tEIgJLC9rWGF.png)

# Adding additional Plugin Hubs

RuneLite Hijack comes with a builtin plugin that allows you to add additional plugin hubs. You can access this plugin like the similar "RuneLite" builtin
plugin.

![example](https://im.arnah.ca/c4orAVtodc7VkeE.png)

The default plugin hub is a GitHub repository viewable [here](https://github.com/Arnuh/RuneLiteHijack-PluginHub). You can use this as a template to create
your own plugin hub, while also using the provided plugin to customize additional plugin hubs by using a comma separated list.
your own plugin hub.

For GitHub repositories, you need to make sure the url is a "raw githubusercontent" link
like the following `https://raw.githubusercontent.com/Arnuh/RuneLiteHijack-PluginHub/master/`.

With the "Plugin Hubs" settings, you can add additional plugin hubs to the list by using a comma separated list of urls.

For GitHub repositories, you need to make sure the url is a "raw githubusercontent" link like `https://raw.githubusercontent.
com/Arnuh/RuneLiteHijack-PluginHub/master/`.
![Plugin Hub Example](https://im.arnah.ca/jHNzJb81jtxWDfP.png)

# Structure of Plugin Hubs

Expand Down
46 changes: 41 additions & 5 deletions src/main/java/ca/arnah/runelite/HijackedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import javax.inject.Inject;
import ca.arnah.runelite.plugin.ArnahPluginManager;
import ca.arnah.runelite.plugin.config.ArnahPluginListPanel;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.ui.SplashScreen;

/**
Expand All @@ -11,12 +15,24 @@
*/
public class HijackedClient{

private final ArnahPluginManager arnahPluginManager;

private final ArnahPluginListPanel pluginListPanel;
private final EventBus eventBus;
private final ConfigManager configManager;
private final RuneLiteHijackConfig runeLiteHijackConfig;

@Inject
private ArnahPluginManager arnahPluginManager;
@Inject
private ArnahPluginListPanel pluginListPanel;
public HijackedClient(ArnahPluginManager arnahPluginManager, ArnahPluginListPanel pluginListPanel, EventBus eventBus, ConfigManager configManager){
this.arnahPluginManager = arnahPluginManager;
this.pluginListPanel = pluginListPanel;
this.eventBus = eventBus;
this.configManager = configManager;
this.runeLiteHijackConfig = configManager.getConfig(RuneLiteHijackConfig.class);
}

public void start(){
eventBus.register(this);
System.out.println("Start");
new Thread(()->{
while(SplashScreen.isOpen()){
Expand All @@ -27,13 +43,33 @@ public void start(){
}
}
System.out.println("Splash Screen done");

try{
arnahPluginManager.loadExternalPlugins();
pluginListPanel.init();
startup();
arnahPluginManager.loadExternalPlugins();
}catch(Exception ex){
ex.printStackTrace();
}
}).start();
}

private void startup(){
pluginListPanel.addFakePlugin("RuneLiteHijack", "RuneLiteHijack settings", new String[]{"pluginhub"}, runeLiteHijackConfig, configManager.getConfigDescriptor(runeLiteHijackConfig));
refreshConfig(false);
}


@Subscribe
public void onConfigChanged(ConfigChanged e){
if(e.getGroup().equals(RuneLiteHijackConfig.GROUP_NAME)){
refreshConfig(true);
}
}

private void refreshConfig(boolean update){
System.setProperty(RuneLiteHijackProperties.PLUGINHUB_BASE, runeLiteHijackConfig.urls());
if(update){
arnahPluginManager.update();
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/ca/arnah/runelite/RuneLiteHijackConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ca.arnah.runelite;

import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;

@ConfigGroup(RuneLiteHijackConfig.GROUP_NAME)
public interface RuneLiteHijackConfig extends Config{

String GROUP_NAME = "runelitehijack";

@ConfigItem(keyName = "pluginhub", name = "Plugin Hubs", description = "List of plugin hubs separated by commas", position = 1)
default String urls(){
return RuneLiteHijackProperties.PLUGINHUB_BASE_URL;
}
}
4 changes: 2 additions & 2 deletions src/main/java/ca/arnah/runelite/RuneLiteHijackProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
**/
public class RuneLiteHijackProperties{

private static final String PLUGINHUB_BASE = "runelitehijack.pluginhub.url";
private static final String PLUGINHUB_BASE_URL = "https://raw.githubusercontent.com/Arnuh/RuneLiteHijack-PluginHub/master/";
public static final String PLUGINHUB_BASE = "runelitehijack.pluginhub.url";
public static final String PLUGINHUB_BASE_URL = "https://raw.githubusercontent.com/Arnuh/RuneLiteHijack-PluginHub/master/";

public static List<HttpUrl> getPluginHubBase(){
return Arrays.stream(getPluginHubs()).map(HttpUrl::parse).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import ca.arnah.runelite.plugin.ArnahPluginManager;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigDescriptor;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
Expand Down Expand Up @@ -76,38 +78,36 @@ public ArnahPluginListPanel(ConfigManager configManager, PluginManager pluginMan
}

public void init(){
pluginManager.getPlugins().stream()
.filter(ConfigPlugin.class::isInstance)
.findAny().ifPresent(plugin->{
try{
Field field = ConfigPlugin.class.getDeclaredField("pluginListPanelProvider");
field.setAccessible(true);
Provider<PluginPanel> pluginPanelProvider = (Provider<PluginPanel>) field.get(plugin);
pluginListPanel = (PluginPanel) (objPluginListPanel = pluginPanelProvider.get());
SwingUtilities.invokeLater(()->{
JPanel southPanel = new FixedWidthPanel();
southPanel.setLayout(new BorderLayout());
for(Component maybeAButton : pluginListPanel.getComponents()){
if(maybeAButton instanceof JButton){
JButton button = (JButton) maybeAButton;
if(button.getText() == null) continue;
if(!button.getText().equals("Plugin Hub")) continue;
pluginListPanel.remove(button);
southPanel.add(button, "North");
}
}
JButton externalPluginButton = new JButton("RuneLiteHijack Plugin Hub");
externalPluginButton.setBorder(new EmptyBorder(5, 5, 5, 5));
externalPluginButton.setLayout(new BorderLayout(0, PluginPanel.BORDER_OFFSET));
externalPluginButton.addActionListener(l->getMuxer().pushState(pluginHubPanelProvider.get()));
southPanel.add(externalPluginButton, "South");
pluginListPanel.add(southPanel, "South");
rebuildPluginList();
});
}catch(Exception ex){
log.error("Failed to initialize RuneLiteHijack Plugin Hub", ex);
}
});
pluginManager.getPlugins().stream().filter(ConfigPlugin.class::isInstance).findAny().ifPresent(plugin->{
try{
Field field = ConfigPlugin.class.getDeclaredField("pluginListPanelProvider");
field.setAccessible(true);
Provider<PluginPanel> pluginPanelProvider = (Provider<PluginPanel>) field.get(plugin);
pluginListPanel = (PluginPanel) (objPluginListPanel = pluginPanelProvider.get());
SwingUtilities.invokeLater(()->{
JPanel southPanel = new FixedWidthPanel();
southPanel.setLayout(new BorderLayout());
for(Component maybeAButton : pluginListPanel.getComponents()){
if(maybeAButton instanceof JButton){
JButton button = (JButton) maybeAButton;
if(button.getText() == null) continue;
if(!button.getText().equals("Plugin Hub")) continue;
pluginListPanel.remove(button);
southPanel.add(button, "North");
}
}
JButton externalPluginButton = new JButton("RuneLiteHijack Plugin Hub");
externalPluginButton.setBorder(new EmptyBorder(5, 5, 5, 5));
externalPluginButton.setLayout(new BorderLayout(0, PluginPanel.BORDER_OFFSET));
externalPluginButton.addActionListener(l->getMuxer().pushState(pluginHubPanelProvider.get()));
southPanel.add(externalPluginButton, "South");
pluginListPanel.add(southPanel, "South");
rebuildPluginList();
});
}catch(Exception ex){
log.error("Failed to initialize RuneLiteHijack Plugin Hub", ex);
}
});
}

public MultiplexingPluginPanel getMuxer(){
Expand Down Expand Up @@ -135,6 +135,22 @@ void rebuildPluginList(){
refresh();
}

public void addFakePlugin(String name, String description, String[] tags, Config config, ConfigDescriptor configDescriptor){
try{
var method = objPluginListPanel.getClass().getDeclaredField("fakePlugins");
method.setAccessible(true);
List<Object> fakePlugins = (List<Object>) method.get(objPluginListPanel);

var clazz = Class.forName("net.runelite.client.plugins.config.PluginConfigurationDescriptor")
.getDeclaredConstructor(String.class, String.class, String[].class, Config.class, ConfigDescriptor.class);
clazz.setAccessible(true);
Object descriptor = clazz.newInstance(name, description, tags, config, configDescriptor);
fakePlugins.add(descriptor);
}catch(Exception ex){
ex.printStackTrace();
}
}

void refresh(){
// update enabled / disabled status of all items
/*pluginList.forEach(listItem ->
Expand Down

0 comments on commit f0b4f37

Please sign in to comment.