This commit is contained in:
ThatGamerBlue
2021-02-04 06:13:57 +00:00
parent e2787027bd
commit df909d2a73
127 changed files with 649 additions and 2409 deletions

View File

@@ -1,27 +1,33 @@
package com.openosrs.client;
import com.openosrs.client.game.NPCStats;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.UUID;
public class OpenOSRS
{
public static final File OPENOSRS_DIR = new File(System.getProperty("user.home"), ".openosrs");
public static final File EXTERNALPLUGIN_DIR = new File(OPENOSRS_DIR, "plugins");
public static final String SYSTEM_VERSION = "0.0.1";
public static final String SYSTEM_VERSION;
public static String uuid = UUID.randomUUID().toString();
public static void init()
static
{
Properties properties = new Properties();
try
{
NPCStats.loadStats();
properties.load(OpenOSRS.class.getResourceAsStream("/openosrs.properties"));
}
catch (Exception e)
catch (IOException e)
{
e.printStackTrace();
}
SYSTEM_VERSION = properties.getProperty("oprs.version", "0.0.0");
}
public static void preload()
{
}
}

View File

@@ -35,7 +35,7 @@ import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
import net.runelite.client.config.Range;
import net.runelite.client.config.Units;
import com.openosrs.client.plugins.ExternalPluginManager;
import net.runelite.client.plugins.OPRSExternalPluginManager;
@ConfigGroup("openosrs")
public interface OpenOSRSConfig extends Config
@@ -136,7 +136,7 @@ public interface OpenOSRSConfig extends Config
)
default String getExternalRepositories()
{
return ExternalPluginManager.DEFAULT_PLUGIN_REPOS;
return OPRSExternalPluginManager.DEFAULT_PLUGIN_REPOS;
}
@ConfigItem(

View File

@@ -25,11 +25,10 @@
package com.openosrs.client.events;
import lombok.Data;
import net.runelite.api.events.Event;
import net.runelite.client.plugins.Plugin;
@Data
public class ExternalPluginChanged implements Event
public class ExternalPluginChanged
{
private final String pluginId;
private final Plugin plugin;

View File

@@ -25,8 +25,7 @@
package com.openosrs.client.events;
import lombok.Data;
import net.runelite.api.events.Event;
@Data
public class ExternalPluginsLoaded implements Event
public class ExternalPluginsLoaded
{}

View File

@@ -25,10 +25,9 @@
package com.openosrs.client.events;
import lombok.Data;
import net.runelite.api.events.Event;
@Data
public class ExternalRepositoryChanged implements Event
public class ExternalRepositoryChanged
{
private final String owner;
private final boolean added;

View File

@@ -1,229 +0,0 @@
/*
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
* 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 com.openosrs.client.game;
import com.google.common.collect.ImmutableMap;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import lombok.Builder;
import lombok.Value;
@Value
@Builder(builderClassName = "Builder")
public class NPCStats
{
public static ImmutableMap<Integer, NPCStats> statsMap;
String name;
int hitpoints;
int combatLevel;
int slayerLevel;
int attackSpeed;
int attackLevel;
int strengthLevel;
int defenceLevel;
int rangeLevel;
int magicLevel;
int stab;
int slash;
int crush;
int range;
int magic;
int stabDef;
int slashDef;
int crushDef;
int rangeDef;
int magicDef;
int bonusAttack;
int bonusStrength;
int bonusRangeStrength;
int bonusMagicDamage;
boolean poisonImmune;
boolean venomImmune;
boolean dragon;
boolean demon;
boolean undead;
/**
* Based off the formula found here: http://services.runescape.com/m=forum/c=PLuJ4cy6gtA/forums.ws?317,318,712,65587452,209,337584542#209
*
* @return bonus XP modifier
*/
public double calculateXpModifier()
{
final double averageLevel = Math.floor((attackLevel + strengthLevel + defenceLevel + hitpoints) / 4);
final double averageDefBonus = Math.floor((stabDef + slashDef + crushDef) / 3);
return (1 + Math.floor(averageLevel * (averageDefBonus + bonusStrength + bonusAttack) / 5120) / 40);
}
// Because this class is here we can't add the TypeAdapter to gson (easily)
// doesn't mean we can't use one to do it a bit quicker
public static final TypeAdapter<NPCStats> NPC_STATS_TYPE_ADAPTER = new TypeAdapter<NPCStats>()
{
@Override
public void write(JsonWriter out, NPCStats value)
{
throw new UnsupportedOperationException("Not supported");
}
@Override
public NPCStats read(JsonReader in) throws IOException
{
in.beginObject();
NPCStats.Builder builder = NPCStats.builder();
// Name is the only one that's guaranteed
in.skipValue();
builder.name(in.nextString());
while (in.hasNext())
{
switch (in.nextName())
{
case "hitpoints":
builder.hitpoints(in.nextInt());
break;
case "combatLevel":
builder.combatLevel(in.nextInt());
break;
case "slayerLevel":
builder.slayerLevel(in.nextInt());
break;
case "attackSpeed":
builder.attackSpeed(in.nextInt());
break;
case "attackLevel":
builder.attackLevel(in.nextInt());
break;
case "strengthLevel":
builder.strengthLevel(in.nextInt());
break;
case "defenceLevel":
builder.defenceLevel(in.nextInt());
break;
case "rangeLevel":
builder.rangeLevel(in.nextInt());
break;
case "magicLevel":
builder.magicLevel(in.nextInt());
break;
case "stab":
builder.stab(in.nextInt());
break;
case "slash":
builder.slash(in.nextInt());
break;
case "crush":
builder.crush(in.nextInt());
break;
case "range":
builder.range(in.nextInt());
break;
case "magic":
builder.magic(in.nextInt());
break;
case "stabDef":
builder.stabDef(in.nextInt());
break;
case "slashDef":
builder.slashDef(in.nextInt());
break;
case "crushDef":
builder.crushDef(in.nextInt());
break;
case "rangeDef":
builder.rangeDef(in.nextInt());
break;
case "magicDef":
builder.magicDef(in.nextInt());
break;
case "bonusAttack":
builder.bonusAttack(in.nextInt());
break;
case "bonusStrength":
builder.bonusStrength(in.nextInt());
break;
case "bonusRangeStrength":
builder.bonusRangeStrength(in.nextInt());
break;
case "bonusMagicDamage":
builder.bonusMagicDamage(in.nextInt());
break;
case "poisonImmune":
builder.poisonImmune(in.nextBoolean());
break;
case "venomImmune":
builder.venomImmune(in.nextBoolean());
break;
case "dragon":
builder.dragon(in.nextBoolean());
break;
case "demon":
builder.demon(in.nextBoolean());
break;
case "undead":
builder.undead(in.nextBoolean());
break;
}
}
in.endObject();
return builder.build();
}
};
public static void loadStats() throws IOException
{
try (JsonReader reader = new JsonReader(new InputStreamReader(NPCStats.class.getResourceAsStream("npc_stats.json"), StandardCharsets.UTF_8)))
{
ImmutableMap.Builder<Integer, NPCStats> builder = ImmutableMap.builderWithExpectedSize(2821);
reader.beginObject();
while (reader.hasNext())
{
builder.put(
Integer.parseInt(reader.nextName()),
NPCStats.NPC_STATS_TYPE_ADAPTER.read(reader)
);
}
reader.endObject();
statsMap = builder.build();
}
}
}

View File

@@ -1,13 +0,0 @@
package com.openosrs.client.plugins;
import org.pf4j.DevelopmentPluginClasspath;
class ExternalPluginClasspath extends DevelopmentPluginClasspath
{
static final String GRADLE_DEPS_PATH = "build/deps";
ExternalPluginClasspath()
{
addJarsDirectories(GRADLE_DEPS_PATH);
}
}

View File

@@ -1,61 +0,0 @@
package com.openosrs.client.plugins;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.List;
/**
* Determines whether a {@link File} is an external plugin folder. To be considered a plugin a folder must:
* <p>
* * Must not be a blacklisted name
* * Have a {@code .gradle.kts} file in the root named after the folder
* * Have a {@code MANIFEST.MF} located at {@code build/tmp/jar/MANIFEST.MF}
*/
public class ExternalPluginFileFilter implements FileFilter
{
private static final List<String> blacklist = Arrays.asList(
".git",
"build",
"target",
"release"
);
private static final List<String> buildFiles = Arrays.asList(
"%s.gradle.kts",
"%s.gradle"
);
@Override
public boolean accept(File pathName)
{
// Check if this path looks like a plugin development directory
if (!pathName.isDirectory())
{
return false;
}
String dirName = pathName.getName();
if (blacklist.contains(dirName))
{
return false;
}
// Check if the plugin directory has a MANIFEST.MF which si required for loading
if (!new File(pathName, ExternalPluginManager.DEVELOPMENT_MANIFEST_PATH).exists())
{
return false;
}
// By convention plugins their directory is $name and they have a $name.gradle.kts or $name.gradle file in their root
for (String buildFile : buildFiles)
{
if (new File(pathName, String.format(buildFile, dirName)).exists())
{
return true;
}
}
return false;
}
}

View File

@@ -1,9 +0,0 @@
package com.openosrs.client.plugins;
import com.google.inject.Injector;
import org.pf4j.ExtensionPoint;
public class Plugin extends net.runelite.client.plugins.Plugin implements ExtensionPoint
{
public Injector injector;
}

View File

@@ -27,8 +27,8 @@
package com.openosrs.client.plugins.openosrs;
import ch.qos.logback.classic.Logger;
import com.openosrs.client.plugins.openosrs.externals.ExternalPluginManagerPanel;
import com.openosrs.client.config.OpenOSRSConfig;
import com.openosrs.client.plugins.openosrs.externals.ExternalPluginManagerPanel;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -78,6 +78,10 @@ public class OpenOSRSPlugin extends Plugin
@Override
public void hotkeyPressed()
{
if (client == null)
{
return;
}
detach = !detach;
client.setOculusOrbState(detach ? 1 : 0);
client.setOculusOrbNormalSpeed(detach ? 36 : 12);

View File

@@ -1,6 +1,6 @@
package com.openosrs.client.plugins.openosrs.externals;
import com.openosrs.client.plugins.ExternalPluginManager;
import net.runelite.client.plugins.OPRSExternalPluginManager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
@@ -46,12 +46,12 @@ public class ExternalPluginManagerPanel extends PluginPanel
ADD_HOVER_ICON_GH = new ImageIcon(ImageUtil.alphaOffset(addIconGh, 0.53f));
}
private final ExternalPluginManager externalPluginManager;
private final OPRSExternalPluginManager externalPluginManager;
private final ScheduledExecutorService executor;
private final EventBus eventBus;
@Inject
private ExternalPluginManagerPanel(ExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
private ExternalPluginManagerPanel(OPRSExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
{
super(false);
@@ -134,7 +134,7 @@ public class ExternalPluginManagerPanel extends PluginPanel
return;
}
if (ExternalPluginManager.testGHRepository(owner.getText(), name.getText()))
if (OPRSExternalPluginManager.testGHRepository(owner.getText(), name.getText()))
{
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
JOptionPane.ERROR_MESSAGE);
@@ -222,7 +222,7 @@ public class ExternalPluginManagerPanel extends PluginPanel
return;
}
if (ExternalPluginManager.testRepository(urlActual))
if (OPRSExternalPluginManager.testRepository(urlActual))
{
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
JOptionPane.ERROR_MESSAGE);

View File

@@ -1,11 +1,10 @@
package com.openosrs.client.plugins.openosrs.externals;
import com.openosrs.client.plugins.ExternalPluginManager;
import net.runelite.client.plugins.OPRSExternalPluginManager;
import com.google.gson.JsonSyntaxException;
import com.openosrs.client.events.ExternalPluginChanged;
import com.openosrs.client.events.ExternalRepositoryChanged;
import com.openosrs.client.util.DeferredDocumentChangedListener;
import com.openosrs.client.util.ImageUtil;
import net.runelite.client.util.DeferredDocumentChangedListener;
import com.openosrs.client.util.SwingUtil;
import java.awt.BorderLayout;
import java.awt.Color;
@@ -45,6 +44,7 @@ import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
import net.runelite.client.util.ImageUtil;
import org.pf4j.update.PluginInfo;
import org.pf4j.update.UpdateManager;
import org.pf4j.update.UpdateRepository;
@@ -82,7 +82,7 @@ public class PluginsPanel extends JPanel
DELETE_HOVER_ICON_GRAY = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.grayscaleImage(deleteImg), 0.53f));
}
private final ExternalPluginManager externalPluginManager;
private final OPRSExternalPluginManager externalPluginManager;
private final UpdateManager updateManager;
private final ScheduledExecutorService executor;
private final EventBus eventBus;
@@ -97,7 +97,7 @@ public class PluginsPanel extends JPanel
private JComboBox<String> filterComboBox;
private Set<String> deps;
PluginsPanel(ExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
PluginsPanel(OPRSExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
{
this.externalPluginManager = externalPluginManager;
this.updateManager = externalPluginManager.getUpdateManager();

View File

@@ -1,8 +1,7 @@
package com.openosrs.client.plugins.openosrs.externals;
import com.openosrs.client.plugins.ExternalPluginManager;
import net.runelite.client.plugins.OPRSExternalPluginManager;
import com.openosrs.client.ui.JMultilineLabel;
import com.openosrs.client.util.ImageUtil;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
@@ -19,6 +18,7 @@ import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.LinkBrowser;
import org.pf4j.update.PluginInfo;
import org.pf4j.update.UpdateRepository;
@@ -53,7 +53,7 @@ public class RepositoryBox extends JPanel
DISCORD_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(discordImg, 0.53f));
}
RepositoryBox(ExternalPluginManager externalPluginManager, UpdateRepository updateRepository)
RepositoryBox(OPRSExternalPluginManager externalPluginManager, UpdateRepository updateRepository)
{
setLayout(new BorderLayout());
setBackground(ColorScheme.DARKER_GRAY_COLOR);

View File

@@ -1,6 +1,6 @@
package com.openosrs.client.plugins.openosrs.externals;
import com.openosrs.client.plugins.ExternalPluginManager;
import net.runelite.client.plugins.OPRSExternalPluginManager;
import com.openosrs.client.events.ExternalRepositoryChanged;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@@ -18,11 +18,11 @@ public class RepositoryPanel extends JPanel
@Inject
public EventBus eventBus;
private final ExternalPluginManager externalPluginManager;
private final OPRSExternalPluginManager externalPluginManager;
private final GridBagConstraints c = new GridBagConstraints();
RepositoryPanel(ExternalPluginManager externalPluginManager, EventBus eventBus)
RepositoryPanel(OPRSExternalPluginManager externalPluginManager, EventBus eventBus)
{
this.externalPluginManager = externalPluginManager;

View File

@@ -24,6 +24,7 @@
*/
package com.openosrs.client.ui.components;
import com.openosrs.client.OpenOSRS;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
@@ -88,7 +89,7 @@ public class InfoPanel extends JPanel
c.weighty = 0;
// OpenOSRS version
this.add(createPanelTextButton("OpenOSRS Version: " + RuneLiteProperties.getLauncherVersion()), c);
this.add(createPanelTextButton("OpenOSRS Version: " + OpenOSRS.SYSTEM_VERSION), c);
c.gridy++;
final JLabel logsFolder = createPanelButton("Open logs folder", null, () -> LinkBrowser.openLocalFile(LOGS_DIR));

View File

@@ -1,34 +0,0 @@
package com.openosrs.client.util;
import java.awt.Color;
public class ColorUtil extends net.runelite.client.util.ColorUtil
{
/**
* Modifies the alpha component on a Color
*
* @param color The color to set the alpha value on
* @param alpha The alpha value to set on the color
* @return color
*/
public static int setAlphaComponent(Color color, int alpha)
{
return setAlphaComponent(color.getRGB(), alpha);
}
/**
* Modifies the alpha component on a Color
*
* @param color The color to set the alpha value on
* @param alpha The alpha value to set on the color
* @return color
*/
public static int setAlphaComponent(int color, int alpha)
{
if (alpha < 0 || alpha > 255)
{
throw new IllegalArgumentException("alpha must be between 0 and 255.");
}
return (color & 0x00ffffff) | (alpha << 24);
}
}

View File

@@ -1,58 +0,0 @@
package com.openosrs.client.util;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class DeferredDocumentChangedListener implements DocumentListener
{
private final Timer timer;
private final List<ChangeListener> listeners;
public DeferredDocumentChangedListener()
{
listeners = new ArrayList<>(25);
timer = new Timer(200, e -> fireStateChanged());
timer.setRepeats(false);
}
public void addChangeListener(ChangeListener listener)
{
listeners.add(listener);
}
private void fireStateChanged()
{
if (!listeners.isEmpty())
{
ChangeEvent evt = new ChangeEvent(this);
for (ChangeListener listener : listeners)
{
listener.stateChanged(evt);
}
}
}
@Override
public void insertUpdate(DocumentEvent e)
{
timer.restart();
}
@Override
public void removeUpdate(DocumentEvent e)
{
timer.restart();
}
@Override
public void changedUpdate(DocumentEvent e)
{
timer.restart();
}
}

View File

@@ -1,59 +0,0 @@
package com.openosrs.client.util;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.util.function.Predicate;
public class ImageUtil extends net.runelite.client.util.ImageUtil
{
/**
* Recolors pixels of the given image with the given color based on a given recolor condition
* predicate.
*
* @param image The image which should have its non-transparent pixels recolored.
* @param color The color with which to recolor pixels.
* @param recolorCondition The condition on which to recolor pixels with the given color.
* @return The given image with all pixels fulfilling the recolor condition predicate
* set to the given color.
*/
public static BufferedImage recolorImage(final BufferedImage image, final Color color, final Predicate<Color> recolorCondition)
{
final BufferedImage recoloredImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < recoloredImage.getWidth(); x++)
{
for (int y = 0; y < recoloredImage.getHeight(); y++)
{
final Color pixelColor = new Color(image.getRGB(x, y), true);
if (!recolorCondition.test(pixelColor))
{
recoloredImage.setRGB(x, y, image.getRGB(x, y));
continue;
}
recoloredImage.setRGB(x, y, color.getRGB());
}
}
return recoloredImage;
}
public static BufferedImage recolorImage(BufferedImage image, final Color color)
{
int width = image.getWidth();
int height = image.getHeight();
WritableRaster raster = image.getRaster();
for (int xx = 0; xx < width; xx++)
{
for (int yy = 0; yy < height; yy++)
{
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
pixels[0] = color.getRed();
pixels[1] = color.getGreen();
pixels[2] = color.getBlue();
raster.setPixel(xx, yy, pixels);
}
}
return image;
}
}

View File

@@ -70,6 +70,7 @@ import net.runelite.client.game.ItemManager;
import net.runelite.client.game.LootManager;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.OPRSExternalPluginManager;
import net.runelite.client.rs.ClientLoader;
import net.runelite.client.rs.ClientUpdateCheckMode;
import net.runelite.client.ui.ClientUI;
@@ -114,7 +115,7 @@ public class RuneLite
private ExternalPluginManager externalPluginManager;
@Inject
private com.openosrs.client.plugins.ExternalPluginManager oprsExternalPluginManager;
private OPRSExternalPluginManager oprsExternalPluginManager;
@Inject
private EventBus eventBus;
@@ -241,6 +242,8 @@ public class RuneLite
}
});
OpenOSRS.preload();
OkHttpClient.Builder okHttpClientBuilder = RuneLiteAPI.CLIENT.newBuilder()
.cache(new Cache(new File(CACHE_DIR, "okhttp"), MAX_OKHTTP_CACHE_SIZE));
@@ -286,8 +289,6 @@ public class RuneLite
injector.getInstance(RuneLite.class).start();
OpenOSRS.init();
final long end = System.currentTimeMillis();
final RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
final long uptime = rb.getUptime();

View File

@@ -1,4 +1,29 @@
package com.openosrs.client.plugins;
/*
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
* 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;
import com.openosrs.client.OpenOSRS;
import java.io.Closeable;
@@ -33,11 +58,11 @@ import org.pf4j.PluginWrapper;
import org.pf4j.RuntimeMode;
@Slf4j
class ExternalPf4jPluginManager extends DefaultPluginManager
class OPRSExternalPf4jPluginManager extends DefaultPluginManager
{
private final ExternalPluginManager externalPluginManager;
private final OPRSExternalPluginManager externalPluginManager;
public ExternalPf4jPluginManager(ExternalPluginManager externalPluginManager)
public OPRSExternalPf4jPluginManager(OPRSExternalPluginManager externalPluginManager)
{
super(OpenOSRS.EXTERNALPLUGIN_DIR.toPath());
this.externalPluginManager = externalPluginManager;
@@ -55,7 +80,7 @@ class ExternalPf4jPluginManager extends DefaultPluginManager
// The superclass performs a find, which is slow in development mode since we're pointing
// at a sources directory, which can have a lot of files. The external plugin template
// will always output the manifest at the following location, so we can hardcode this path.
return pluginPath.resolve(ExternalPluginManager.DEVELOPMENT_MANIFEST_PATH);
return pluginPath.resolve(OPRSExternalPluginManager.DEVELOPMENT_MANIFEST_PATH);
}
return super.getManifestPath(pluginPath);
@@ -78,7 +103,7 @@ class ExternalPf4jPluginManager extends DefaultPluginManager
protected PluginLoader createPluginLoader()
{
return new CompoundPluginLoader()
.add(new BasePluginLoader(this, new ExternalPluginClasspath()), this::isDevelopment)
.add(new BasePluginLoader(this, new OPRSExternalPluginClasspath()), this::isDevelopment)
.add(new JarPluginLoader(this), this::isNotDevelopment);
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
* 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;
import org.pf4j.DevelopmentPluginClasspath;
class OPRSExternalPluginClasspath extends DevelopmentPluginClasspath
{
static final String GRADLE_DEPS_PATH = "build/deps";
OPRSExternalPluginClasspath()
{
addJarsDirectories(GRADLE_DEPS_PATH);
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
* 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;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.List;
/**
* Determines whether a {@link File} is an external plugin folder. To be considered a plugin a folder must:
* <p>
* * Must not be a blacklisted name
* * Have a {@code .gradle.kts} file in the root named after the folder
* * Have a {@code MANIFEST.MF} located at {@code build/tmp/jar/MANIFEST.MF}
*/
public class OPRSExternalPluginFileFilter implements FileFilter
{
private static final List<String> blacklist = Arrays.asList(
".git",
"build",
"target",
"release"
);
private static final List<String> buildFiles = Arrays.asList(
"%s.gradle.kts",
"%s.gradle"
);
@Override
public boolean accept(File pathName)
{
// Check if this path looks like a plugin development directory
if (!pathName.isDirectory())
{
return false;
}
String dirName = pathName.getName();
if (blacklist.contains(dirName))
{
return false;
}
// Check if the plugin directory has a MANIFEST.MF which si required for loading
if (!new File(pathName, OPRSExternalPluginManager.DEVELOPMENT_MANIFEST_PATH).exists())
{
return false;
}
// By convention plugins their directory is $name and they have a $name.gradle.kts or $name.gradle file in their root
for (String buildFile : buildFiles)
{
if (new File(pathName, String.format(buildFile, dirName)).exists())
{
return true;
}
}
return false;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Owain van Brakel <https://github.com/Owain94>
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -22,7 +22,7 @@
* (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 com.openosrs.client.plugins;
package net.runelite.client.plugins;
import com.google.common.collect.Lists;
import com.google.common.graph.GraphBuilder;
@@ -75,9 +75,6 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginInstantiationException;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.ui.ClientUI;
import org.jgroups.Message;
import org.pf4j.DefaultPluginManager;
@@ -92,9 +89,9 @@ import org.pf4j.update.UpdateRepository;
@Slf4j
@Singleton
public class ExternalPluginManager
public class OPRSExternalPluginManager
{
public static final String DEFAULT_PLUGIN_REPOS = "OpenOSRS:https://raw.githubusercontent.com/zeruth/runelite-plugins-release/master/";
public static final String DEFAULT_PLUGIN_REPOS = "OpenOSRS:https://raw.githubusercontent.com/open-osrs/plugins-v2/master/";
static final String DEVELOPMENT_MANIFEST_PATH = "build/tmp/jar/MANIFEST.MF";
public static ArrayList<ClassLoader> pluginClassLoaders = new ArrayList<>();
@@ -115,7 +112,7 @@ public class ExternalPluginManager
private final boolean safeMode;
@Inject
public ExternalPluginManager(
public OPRSExternalPluginManager(
@Named("safeMode") final boolean safeMode,
PluginManager pluginManager,
OpenOSRSConfig openOSRSConfig,
@@ -143,7 +140,7 @@ public class ExternalPluginManager
private void initPluginManager()
{
externalPluginManager = new ExternalPf4jPluginManager(this);
externalPluginManager = new OPRSExternalPf4jPluginManager(this);
externalPluginManager.setSystemVersion(SYSTEM_VERSION);
}

View File

@@ -27,8 +27,9 @@ package net.runelite.client.plugins;
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Module;
import org.pf4j.ExtensionPoint;
public abstract class Plugin implements Module
public abstract class Plugin implements Module, ExtensionPoint
{
protected Injector injector;

View File

@@ -29,8 +29,8 @@ import java.awt.Dimension;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JToggleButton;
import com.openosrs.client.util.ImageUtil;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.SwingUtil;
class PluginToggleButton extends JToggleButton

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.info;
import com.google.common.base.MoreObjects;
import com.google.inject.Inject;
import com.openosrs.client.OpenOSRS;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
@@ -135,8 +136,11 @@ public class InfoPanel extends PluginPanel
final Font smallFont = FontManager.getRunescapeSmallFont();
JLabel version = new JLabel(htmlLabel("RuneLite version: ", runeliteVersion));
version.setFont(smallFont);
JLabel rlVersion = new JLabel(htmlLabel("RuneLite version: ", runeliteVersion));
rlVersion.setFont(smallFont);
JLabel oprsVersion = new JLabel(htmlLabel("OpenOSRS version: ", OpenOSRS.SYSTEM_VERSION));
oprsVersion.setFont(smallFont);
JLabel revision = new JLabel();
revision.setFont(smallFont);
@@ -147,7 +151,7 @@ public class InfoPanel extends PluginPanel
engineVer = String.format("Rev %d", client.getRevision());
}
revision.setText(htmlLabel("Oldschool revision: ", engineVer));
revision.setText(htmlLabel("OldSchool revision: ", engineVer));
JLabel launcher = new JLabel(htmlLabel("Launcher version: ", MoreObjects
.firstNonNull(RuneLiteProperties.getLauncherVersion(), "Unknown")));
@@ -170,7 +174,8 @@ public class InfoPanel extends PluginPanel
}
});
versionPanel.add(version);
versionPanel.add(rlVersion);
versionPanel.add(oprsVersion);
versionPanel.add(revision);
versionPanel.add(launcher);
versionPanel.add(Box.createGlue());

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
* 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.util;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class DeferredDocumentChangedListener implements DocumentListener
{
private final Timer timer;
private final List<ChangeListener> listeners;
public DeferredDocumentChangedListener()
{
listeners = new ArrayList<>(25);
timer = new Timer(200, e -> fireStateChanged());
timer.setRepeats(false);
}
public void addChangeListener(ChangeListener listener)
{
listeners.add(listener);
}
private void fireStateChanged()
{
if (!listeners.isEmpty())
{
ChangeEvent evt = new ChangeEvent(this);
for (ChangeListener listener : listeners)
{
listener.stateChanged(evt);
}
}
}
@Override
public void insertUpdate(DocumentEvent e)
{
timer.restart();
}
@Override
public void removeUpdate(DocumentEvent e)
{
timer.restart();
}
@Override
public void changedUpdate(DocumentEvent e)
{
timer.restart();
}
}

View File

@@ -34,10 +34,12 @@ import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.PixelGrabber;
import java.awt.image.RescaleOp;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import javax.imageio.ImageIO;
import javax.swing.GrayFilter;
import lombok.extern.slf4j.Slf4j;
@@ -524,4 +526,54 @@ public class ImageUtil
return sprite;
}
/**
* Recolors pixels of the given image with the given color based on a given recolor condition
* predicate.
*
* @param image The image which should have its non-transparent pixels recolored.
* @param color The color with which to recolor pixels.
* @param recolorCondition The condition on which to recolor pixels with the given color.
* @return The given image with all pixels fulfilling the recolor condition predicate
* set to the given color.
*/
public static BufferedImage recolorImage(final BufferedImage image, final Color color, final Predicate<Color> recolorCondition)
{
final BufferedImage recoloredImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < recoloredImage.getWidth(); x++)
{
for (int y = 0; y < recoloredImage.getHeight(); y++)
{
final Color pixelColor = new Color(image.getRGB(x, y), true);
if (!recolorCondition.test(pixelColor))
{
recoloredImage.setRGB(x, y, image.getRGB(x, y));
continue;
}
recoloredImage.setRGB(x, y, color.getRGB());
}
}
return recoloredImage;
}
public static BufferedImage recolorImage(BufferedImage image, final Color color)
{
int width = image.getWidth();
int height = image.getHeight();
WritableRaster raster = image.getRaster();
for (int xx = 0; xx < width; xx++)
{
for (int yy = 0; yy < height; yy++)
{
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
pixels[0] = color.getRed();
pixels[1] = color.getGreen();
pixels[2] = color.getBlue();
raster.setPixel(xx, yy, pixels);
}
}
return image;
}
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
* 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.util;
import java.awt.Polygon;
import net.runelite.api.Client;
import net.runelite.api.Player;
import net.runelite.api.Varbits;
import net.runelite.api.WorldType;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.geometry.Cuboid;
public class PvPUtil
{
private static final Polygon NOT_WILDERNESS_BLACK_KNIGHTS = new Polygon( // this is black knights castle
new int[]{2994, 2995, 2996, 2996, 2994, 2994, 2997, 2998, 2998, 2999, 3000, 3001, 3002, 3003, 3004, 3005, 3005,
3005, 3019, 3020, 3022, 3023, 3024, 3025, 3026, 3026, 3027, 3027, 3028, 3028, 3029, 3029, 3030, 3030, 3031,
3031, 3032, 3033, 3034, 3035, 3036, 3037, 3037},
new int[]{3525, 3526, 3527, 3529, 3529, 3534, 3534, 3535, 3536, 3537, 3538, 3539, 3540, 3541, 3542, 3543, 3544,
3545, 3545, 3546, 3546, 3545, 3544, 3543, 3543, 3542, 3541, 3540, 3539, 3537, 3536, 3535, 3534, 3533, 3532,
3531, 3530, 3529, 3528, 3527, 3526, 3526, 3525},
43
);
private static final Cuboid MAIN_WILDERNESS_CUBOID = new Cuboid(2944, 3525, 0, 3391, 4351, 3);
private static final Cuboid GOD_WARS_WILDERNESS_CUBOID = new Cuboid(3008, 10112, 0, 3071, 10175, 3);
private static final Cuboid WILDERNESS_UNDERGROUND_CUBOID = new Cuboid(2944, 9920, 0, 3391, 10879, 3);
/**
* Gets the wilderness level based on a world point
* Java reimplementation of clientscript 384 [proc,wilderness_level]
*
* @param point the point in the world to get the wilderness level for
* @return the int representing the wilderness level
*/
public static int getWildernessLevelFrom(WorldPoint point)
{
if (MAIN_WILDERNESS_CUBOID.contains(point))
{
if (NOT_WILDERNESS_BLACK_KNIGHTS.contains(point.getX(), point.getY()))
{
return 0;
}
return ((point.getY() - 3520) / 8) + 1; // calc(((coordz(coord) - (55 * 64)) / 8) + 1)
}
else if (GOD_WARS_WILDERNESS_CUBOID.contains(point))
{
return ((point.getY() - 9920) / 8) - 1; // calc(((coordz(coord) - (155 * 64)) / 8) - 1)
}
else if (WILDERNESS_UNDERGROUND_CUBOID.contains(point))
{
return ((point.getY() - 9920) / 8) + 1; // calc(((coordz(coord) - (155 * 64)) / 8) + 1)
}
return 0;
}
/**
* Determines if another player is attackable based off of wilderness level and combat levels
*
* @param client The client of the local player
* @param player the player to determine attackability
* @return returns true if the player is attackable, false otherwise
*/
public static boolean isAttackable(Client client, Player player)
{
int wildernessLevel = 0;
if (WorldType.isDeadmanWorld(client.getWorldType()))
{
return true;
}
if (WorldType.isPvpWorld(client.getWorldType()))
{
wildernessLevel += 15;
}
if (client.getVar(Varbits.IN_WILDERNESS) == 1)
{
wildernessLevel += getWildernessLevelFrom(client.getLocalPlayer().getWorldLocation());
}
return wildernessLevel != 0 && Math.abs(client.getLocalPlayer().getCombatLevel() - player.getCombatLevel()) <= wildernessLevel;
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
oprs.version=@open.osrs.version@