mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -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) {}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import plugin.api.MiniMenuEntry;
|
|||
import plugin.api.MiniMenuType;
|
||||
import rt4.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -20,6 +20,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class PluginRepository {
|
||||
static HashMap<PluginInfo, Plugin> loadedPlugins = new HashMap<>();
|
||||
public static HashMap<String, Object> pluginStorage = new HashMap<>();
|
||||
|
||||
public static void registerPlugin(PluginInfo info, Plugin plugin) {
|
||||
loadedPlugins.put(info, plugin);
|
||||
|
|
@ -40,6 +41,23 @@ public class PluginRepository {
|
|||
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 {
|
||||
URL[] classPath = {pluginsDirectory.toURI().toURL()};
|
||||
URLClassLoader loader = new URLClassLoader(classPath);
|
||||
|
|
@ -142,4 +160,8 @@ public class PluginRepository {
|
|||
API.customMiniMenuIndex = 0;
|
||||
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;
|
||||
|
||||
import plugin.PluginRepository;
|
||||
import rt4.*;
|
||||
import rt4.DisplayMode;
|
||||
import rt4.Font;
|
||||
|
|
@ -222,4 +223,34 @@ public class API {
|
|||
MiniMenu.size++;
|
||||
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) {
|
||||
LoadingBarAwt.clear();
|
||||
}
|
||||
if (gameState == 30) {
|
||||
PluginRepository.OnLogin();
|
||||
}
|
||||
if (arg0 == 40) {
|
||||
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