mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Add API calls for setting varcs, varbits, etc.
Add API support for arbitrary data storage Add RememberMyLogin plugin
This commit is contained in:
parent
7613080b2e
commit
b073365cd4
5 changed files with 106 additions and 1 deletions
|
|
@ -85,6 +85,11 @@ public abstract class Plugin {
|
||||||
*/
|
*/
|
||||||
public void OnVarpUpdate(int id, int value) {}
|
public void OnVarpUpdate(int id, int value) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OnLogin is called when the client processes a login.
|
||||||
|
*/
|
||||||
|
public void OnLogin() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OnLogout is called when the client logs out. This should be used to clear player-relevant plugin state.
|
* OnLogout is called when the client logs out. This should be used to clear player-relevant plugin state.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import plugin.api.MiniMenuEntry;
|
||||||
import plugin.api.MiniMenuType;
|
import plugin.api.MiniMenuType;
|
||||||
import rt4.*;
|
import rt4.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -20,6 +20,7 @@ import java.util.stream.Collectors;
|
||||||
*/
|
*/
|
||||||
public class PluginRepository {
|
public class PluginRepository {
|
||||||
static HashMap<PluginInfo, Plugin> loadedPlugins = new HashMap<>();
|
static HashMap<PluginInfo, Plugin> loadedPlugins = new HashMap<>();
|
||||||
|
public static HashMap<String, Object> pluginStorage = new HashMap<>();
|
||||||
|
|
||||||
public static void registerPlugin(PluginInfo info, Plugin plugin) {
|
public static void registerPlugin(PluginInfo info, Plugin plugin) {
|
||||||
loadedPlugins.put(info, plugin);
|
loadedPlugins.put(info, plugin);
|
||||||
|
|
@ -40,6 +41,23 @@ public class PluginRepository {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File pluginStorage = new File(GlobalJsonConfig.instance.pluginsFolder + File.separator + "plsto");
|
||||||
|
if (pluginStorage.exists()) {
|
||||||
|
try (FileInputStream fis = new FileInputStream(pluginStorage)) {
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
|
PluginRepository.pluginStorage = (HashMap<String, Object>) ois.readObject();
|
||||||
|
ois.close();
|
||||||
|
} catch (Exception e) {e.printStackTrace();}
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
try(FileOutputStream fos = new FileOutputStream(GlobalJsonConfig.instance.pluginsFolder + File.separator + "plsto")) {
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(PluginRepository.pluginStorage);
|
||||||
|
oos.close();
|
||||||
|
} catch (Exception e) {e.printStackTrace();}
|
||||||
|
}));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL[] classPath = {pluginsDirectory.toURI().toURL()};
|
URL[] classPath = {pluginsDirectory.toURI().toURL()};
|
||||||
URLClassLoader loader = new URLClassLoader(classPath);
|
URLClassLoader loader = new URLClassLoader(classPath);
|
||||||
|
|
@ -142,4 +160,8 @@ public class PluginRepository {
|
||||||
API.customMiniMenuIndex = 0;
|
API.customMiniMenuIndex = 0;
|
||||||
loadedPlugins.values().forEach((plugin) -> plugin.OnMiniMenuCreate(API.GetMiniMenuEntries()));
|
loadedPlugins.values().forEach((plugin) -> plugin.OnMiniMenuCreate(API.GetMiniMenuEntries()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void OnLogin() {
|
||||||
|
loadedPlugins.values().forEach((plugin) -> plugin.OnLogin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package plugin.api;
|
package plugin.api;
|
||||||
|
|
||||||
|
import plugin.PluginRepository;
|
||||||
import rt4.*;
|
import rt4.*;
|
||||||
import rt4.DisplayMode;
|
import rt4.DisplayMode;
|
||||||
import rt4.Font;
|
import rt4.Font;
|
||||||
|
|
@ -222,4 +223,34 @@ public class API {
|
||||||
MiniMenu.size++;
|
MiniMenu.size++;
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean IsLoggedIn() {
|
||||||
|
return client.gameState == 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StoreData(String key, Object value) {
|
||||||
|
PluginRepository.pluginStorage.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object GetData(String key) {
|
||||||
|
return PluginRepository.pluginStorage.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetVarcStr(int varcId, String str) {
|
||||||
|
VarcDomain.varcstrs[varcId] = JagString.of(str);
|
||||||
|
VarcDomain.updatedVarcstrs[VarcDomain.updatedVarcstrsWriterIndex++] = varcId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetVarc(int varcId, int value) {
|
||||||
|
VarcDomain.varcs[varcId] = value;
|
||||||
|
VarcDomain.updatedVarcs[VarcDomain.updatedVarcsWriterIndex++] = varcId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetVarp(int varpId, int value) {
|
||||||
|
VarpDomain.setVarbit(varpId, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetVarbit(int varbitId, int value) {
|
||||||
|
VarpDomain.setVarbitClient(varbitId, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -322,6 +322,9 @@ public final class client extends GameShell {
|
||||||
if (gameState == 0) {
|
if (gameState == 0) {
|
||||||
LoadingBarAwt.clear();
|
LoadingBarAwt.clear();
|
||||||
}
|
}
|
||||||
|
if (gameState == 30) {
|
||||||
|
PluginRepository.OnLogin();
|
||||||
|
}
|
||||||
if (arg0 == 40) {
|
if (arg0 == 40) {
|
||||||
LoginManager.clear();
|
LoginManager.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
44
plugin-playground/src/main/kotlin/RememberMyLogin/plugin.kt
Normal file
44
plugin-playground/src/main/kotlin/RememberMyLogin/plugin.kt
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
package RememberMyLogin
|
||||||
|
|
||||||
|
import plugin.Plugin
|
||||||
|
import plugin.annotations.PluginMeta
|
||||||
|
import plugin.api.API
|
||||||
|
import rt4.Component
|
||||||
|
import rt4.JagString
|
||||||
|
import rt4.Player
|
||||||
|
|
||||||
|
@PluginMeta (
|
||||||
|
author = "Ceikry",
|
||||||
|
description = "Stores your last used login for automatic reuse",
|
||||||
|
version = 1.0
|
||||||
|
)
|
||||||
|
class plugin : Plugin() {
|
||||||
|
var hasRan = false
|
||||||
|
var username = ""
|
||||||
|
var password = ""
|
||||||
|
|
||||||
|
override fun Init() {
|
||||||
|
username = API.GetData("login-user") as? String ?: ""
|
||||||
|
password = API.GetData("login-pass") as? String ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun ComponentDraw(componentIndex: Int, component: Component?, screenX: Int, screenY: Int) {
|
||||||
|
if (hasRan || API.IsLoggedIn()) return
|
||||||
|
if (component!!.text == JagString.of("Please Log In")) {
|
||||||
|
API.SetVarcStr(32, username)
|
||||||
|
API.SetVarcStr(33, password)
|
||||||
|
hasRan = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun OnLogin() {
|
||||||
|
username = String(Player.usernameInput.chars)
|
||||||
|
password = String(Player.password.chars)
|
||||||
|
API.StoreData("login-user", username)
|
||||||
|
API.StoreData("login-pass", password)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun OnLogout() {
|
||||||
|
hasRan = false
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue