mirror of
https://github.com/2006-Scape/Parabot-317-API-Minified.git
synced 2026-07-03 00:38:00 +00:00
Finished base for randoms
This commit is contained in:
@@ -5,6 +5,8 @@ import org.parabot.core.Directories;
|
|||||||
import org.parabot.core.asm.ASMClassLoader;
|
import org.parabot.core.asm.ASMClassLoader;
|
||||||
import org.parabot.core.asm.adapters.AddInterfaceAdapter;
|
import org.parabot.core.asm.adapters.AddInterfaceAdapter;
|
||||||
import org.parabot.core.asm.hooks.HookFile;
|
import org.parabot.core.asm.hooks.HookFile;
|
||||||
|
import org.parabot.core.desc.ServerProviderInfo;
|
||||||
|
import org.parabot.core.ui.components.VerboseLoader;
|
||||||
import org.parabot.environment.api.utils.WebUtil;
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
import org.parabot.environment.scripts.Script;
|
import org.parabot.environment.scripts.Script;
|
||||||
import org.parabot.environment.servers.ServerManifest;
|
import org.parabot.environment.servers.ServerManifest;
|
||||||
@@ -18,16 +20,15 @@ import org.rev317.min.ui.BotMenu;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.applet.Applet;
|
import java.applet.Applet;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Everel
|
* @author Everel, Paradox
|
||||||
*/
|
*/
|
||||||
@ServerManifest(author = "Everel & Paradox", name = "Server name here", type = Type.INJECTION, version = 2.1)
|
@ServerManifest(author = "Everel & Paradox", name = "Server name here", type = Type.INJECTION, version = 2.1)
|
||||||
public class Loader extends ServerProvider {
|
public class Loader extends ServerProvider {
|
||||||
private Applet applet;
|
private Applet applet;
|
||||||
private HookFile hookFile; //= new HookFile(new File(Directories.getCachePath() + "/ikov-hooks.xml"), HookFile.TYPE_XML);
|
private HookFile hookFile = new HookFile(Context.getInstance().getServerProviderInfo().getExtendedHookFile(), HookFile.TYPE_XML);
|
||||||
|
|
||||||
public static Client getClient() {
|
public static Client getClient() {
|
||||||
return (Client) Context.getInstance().getClient();
|
return (Client) Context.getInstance().getClient();
|
||||||
@@ -38,10 +39,10 @@ public class Loader extends ServerProvider {
|
|||||||
try {
|
try {
|
||||||
final Context context = Context.getInstance();
|
final Context context = Context.getInstance();
|
||||||
final ASMClassLoader classLoader = context.getASMClassLoader();
|
final ASMClassLoader classLoader = context.getASMClassLoader();
|
||||||
final Class<?> clientClass = classLoader.loadClass("b");
|
final Class<?> clientClass = classLoader.loadClass(Context.getInstance().getServerProviderInfo().getClientClass());
|
||||||
Object instance = clientClass.newInstance();
|
Object instance = clientClass.newInstance();
|
||||||
applet = (Applet) instance;
|
this.applet = (Applet) instance;
|
||||||
return applet;
|
return this.applet;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@@ -50,11 +51,11 @@ public class Loader extends ServerProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getJar() {
|
public URL getJar() {
|
||||||
//ServerProviderInfo serverProvider = Context.getInstance().getServerProviderInfo();
|
ServerProviderInfo serverProvider = Context.getInstance().getServerProviderInfo();
|
||||||
|
|
||||||
File target = new File(Directories.getCachePath(), "3672181877.jar");
|
File target = new File(Directories.getCachePath(), serverProvider.getClientCRC32() + ".jar");
|
||||||
if (!target.exists()) {
|
if (!target.exists()) {
|
||||||
//WebUtil.downloadFile(serverProvider.getClient(), target, VerboseLoader.get());
|
WebUtil.downloadFile(serverProvider.getClient(), target, VerboseLoader.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return WebUtil.toURL(target);
|
return WebUtil.toURL(target);
|
||||||
@@ -72,11 +73,7 @@ public class Loader extends ServerProvider {
|
|||||||
super.injectHooks();
|
super.injectHooks();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
try {
|
this.hookFile = new HookFile(Context.getInstance().getServerProviderInfo().getHookFile(), HookFile.TYPE_XML);
|
||||||
this.hookFile = new HookFile(new File(Directories.getCachePath() + "/ikov-hooks.xml"), HookFile.TYPE_XML);
|
|
||||||
} catch (MalformedURLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
super.injectHooks();
|
super.injectHooks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.rev317.min.randoms;
|
package org.rev317.min.randoms;
|
||||||
|
|
||||||
import org.parabot.core.Context;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.Directories;
|
import org.parabot.core.Directories;
|
||||||
import org.parabot.core.io.ProgressListener;
|
import org.parabot.core.io.ProgressListener;
|
||||||
import org.parabot.environment.api.utils.WebUtil;
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
@@ -18,28 +18,43 @@ import java.net.URLClassLoader;
|
|||||||
public class Downloader {
|
public class Downloader {
|
||||||
|
|
||||||
public Downloader(){
|
public Downloader(){
|
||||||
downloadRandoms();
|
if (downloadRandoms()) {
|
||||||
|
Core.verbose("Parsing random(s)...");
|
||||||
parseRandoms();
|
parseRandoms();
|
||||||
|
}else{
|
||||||
|
Core.verbose("There do not seem to be any randoms for this server...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseRandoms(){
|
private void parseRandoms(){
|
||||||
File myJar = new File(Directories.getCachePath() + "/" + /* Context.getInstance().getServerProviderInfo().getCRC32() + "-randoms.jar"*/ "randoms.jar");
|
File myJar = new File(Directories.getCachePath() + "/randoms.jar");
|
||||||
|
if (!myJar.exists() || !myJar.canRead()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
URL url = myJar.toURI().toURL();
|
URL url = myJar.toURI().toURL();
|
||||||
URL[] urls = new URL[]{url};
|
URL[] urls = new URL[]{url};
|
||||||
|
String server = "ikov";
|
||||||
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
|
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
|
||||||
Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child);
|
Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child);
|
||||||
Method method = classToLoad.getDeclaredMethod("init");
|
Method method = classToLoad.getDeclaredMethod("init", String.class);
|
||||||
Object instance = classToLoad.newInstance();
|
Object instance = classToLoad.newInstance();
|
||||||
Object result = method.invoke(instance);
|
Object result = method.invoke(instance, server);
|
||||||
|
Core.verbose("Parsed random(s)!");
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadRandoms(){
|
private boolean downloadRandoms(){
|
||||||
try {
|
try {
|
||||||
WebUtil.downloadFile(new URL("http://sdn.parabot.org/providers/getRandom.php?id=" + Context.getInstance().getServerProviderInfo().getCRC32()), new File(Directories.getCachePath() + "/" + Context.getInstance().getServerProviderInfo().getCRC32() + "-randoms.jar"), new ProgressListener() {
|
File random = new File(Directories.getCachePath() + "/randoms.jar");
|
||||||
|
if (random.exists()){
|
||||||
|
Core.verbose("Random already exists, no need to download it.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String downloadLink = "http://sdn.parabot.org/randoms.php";
|
||||||
|
WebUtil.downloadFile(new URL(downloadLink), random, new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(double v) {
|
public void onProgressUpdate(double v) {
|
||||||
|
|
||||||
@@ -50,8 +65,9 @@ public class Downloader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (MalformedURLException e) {
|
return random.exists();
|
||||||
e.printStackTrace();
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author JKetelaar, Everel
|
||||||
|
*/
|
||||||
public class BotMenu implements ActionListener {
|
public class BotMenu implements ActionListener {
|
||||||
|
|
||||||
private RandomUI randomUI;
|
private RandomUI randomUI;
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author JKetelaar
|
||||||
|
*/
|
||||||
public class RandomUI implements ActionListener {
|
public class RandomUI implements ActionListener {
|
||||||
|
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
@@ -16,50 +18,54 @@ public class RandomUI implements ActionListener {
|
|||||||
|
|
||||||
public void openFrame(ArrayList<String> randoms) {
|
public void openFrame(ArrayList<String> randoms) {
|
||||||
frame = new JFrame();
|
frame = new JFrame();
|
||||||
frame.setBounds(100, 100, 351, 150);
|
frame.setBounds(100, 100, 351, 100 + (randoms.size() * 35));
|
||||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
frame.getContentPane().setLayout(null);
|
frame.getContentPane().setLayout(null);
|
||||||
|
|
||||||
JButton btnSubmit = new JButton("Submit");
|
JButton btnSubmit = new JButton("Submit");
|
||||||
btnSubmit.setBounds(228, 93, 117, 29);
|
btnSubmit.setBounds(228, 35 + (randoms.size() * 35), 117, 29);
|
||||||
frame.getContentPane().add(btnSubmit);
|
frame.getContentPane().add(btnSubmit);
|
||||||
|
|
||||||
JLabel lblRandoms = new JLabel("Randoms");
|
JLabel lblRandoms = new JLabel("Randoms:");
|
||||||
lblRandoms.setBounds(6, 6, 61, 16);
|
lblRandoms.setBounds(6, 6, 250, 16);
|
||||||
frame.getContentPane().add(lblRandoms);
|
frame.getContentPane().add(lblRandoms);
|
||||||
|
|
||||||
|
if (randoms.size() > 0) {
|
||||||
checkBoxes = new ArrayList<>();
|
checkBoxes = new ArrayList<>();
|
||||||
for (int i = 0; i < randoms.size(); i++){
|
for (int i = 0; i < randoms.size(); i++) {
|
||||||
JCheckBox checkBox = new JCheckBox(randoms.get(i));
|
JCheckBox checkBox = new JCheckBox(randoms.get(i));
|
||||||
checkBox.setBounds(6, 34 + (i * 35), 128, 23);
|
checkBox.setBounds(6, 35 + (i * 35), 250, 23);
|
||||||
frame.getContentPane().add(checkBox);
|
frame.getContentPane().add(checkBox);
|
||||||
if (isActive(randoms.get(i))){
|
if (isActive(randoms.get(i))) {
|
||||||
checkBox.setSelected(true);
|
checkBox.setSelected(true);
|
||||||
}
|
}
|
||||||
checkBoxes.add(checkBox);
|
checkBoxes.add(checkBox);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
JLabel lblNone = new JLabel("None (yet).");
|
||||||
|
lblNone.setBounds(6, 35, 120, 16);
|
||||||
|
frame.getContentPane().add(lblNone);
|
||||||
|
}
|
||||||
|
|
||||||
btnSubmit.addActionListener(this);
|
btnSubmit.addActionListener(this);
|
||||||
this.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
this.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
this.frame.setVisible(true);
|
this.frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JFrame getFrame() {
|
|
||||||
return frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Context.getInstance().getRandomHandler().clearActiveRandoms();
|
Context.getInstance().getRandomHandler().clearActiveRandoms();
|
||||||
for (JCheckBox checkBox : this.checkBoxes){
|
if (checkBoxes != null && checkBoxes.size() > 0) {
|
||||||
|
for (JCheckBox checkBox : this.checkBoxes) {
|
||||||
if (checkBox.isSelected()) {
|
if (checkBox.isSelected()) {
|
||||||
for (Random r : Context.getInstance().getRandomHandler().getRandoms()){
|
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
||||||
if (r.getName().equalsIgnoreCase(checkBox.getText().toLowerCase())){
|
if (r.getName().equalsIgnoreCase(checkBox.getText().toLowerCase())) {
|
||||||
Context.getInstance().getRandomHandler().setActive(r.getName());
|
Context.getInstance().getRandomHandler().setActive(r.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.frame.dispose();
|
this.frame.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user