Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.guedez.wurm.client;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.Field;
- import java.lang.reflect.InvocationHandler;
- import java.lang.reflect.Method;
- import java.nio.ByteBuffer;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.gotti.wurmunlimited.modloader.ReflectionUtil;
- import org.gotti.wurmunlimited.modloader.classhooks.HookException;
- import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
- import org.gotti.wurmunlimited.modloader.classhooks.InvocationHandlerFactory;
- import org.gotti.wurmunlimited.modloader.interfaces.Configurable;
- import org.gotti.wurmunlimited.modloader.interfaces.Initable;
- import org.gotti.wurmunlimited.modloader.interfaces.PreInitable;
- import org.gotti.wurmunlimited.modloader.interfaces.WurmClientMod;
- import org.lwjgl.input.Keyboard;
- import com.wurmonline.client.WurmClientBase;
- import com.wurmonline.client.comm.ServerConnectionListenerClass;
- import com.wurmonline.client.comm.SimpleServerConnectionClass;
- import com.wurmonline.client.console.KeyBinding;
- import com.wurmonline.client.console.WurmConsole;
- import com.wurmonline.client.game.PlayerObj;
- import com.wurmonline.client.game.World;
- import com.wurmonline.client.renderer.cell.CaveCell;
- import com.wurmonline.client.renderer.cell.Cell;
- import com.wurmonline.client.renderer.cell.CellRenderable;
- import com.wurmonline.client.renderer.cell.CellRenderer;
- import com.wurmonline.client.renderer.cell.CreatureCellRenderable;
- import com.wurmonline.client.renderer.cell.MobileModelRenderable;
- import com.wurmonline.client.renderer.cell.SurfaceCell;
- import com.wurmonline.client.renderer.gui.BmlWindowComponent;
- import com.wurmonline.client.renderer.gui.BmlWindowListener;
- import com.wurmonline.client.renderer.gui.HeadsUpDisplay;
- import com.wurmonline.client.renderer.gui.WurmComponent;
- import com.wurmonline.client.renderer.structures.StructureData;
- import com.wurmonline.client.startup.splash.StartupRenderer;
- import br.com.guedez.wurm.client.actionmod.ActionMod;
- import br.com.guedez.wurm.client.actionmod.Reflect;
- import br.com.guedez.wurm.client.automove.AutoMover;
- import br.com.guedez.wurm.client.autosort.AutoSortMod;
- import br.com.guedez.wurm.client.autosort.FilterItem;
- import br.com.guedez.wurm.client.autostop.IFCondition;
- import br.com.guedez.wurm.client.autostop.IfParser;
- import br.com.guedez.wurm.client.interfaces.GuedezWurmMod;
- import br.com.guedez.wurm.client.livemap.LiveHudMapMod;
- import javassist.CannotCompileException;
- import javassist.ClassPool;
- import javassist.CtClass;
- import javassist.CtPrimitiveType;
- import javassist.NotFoundException;
- import javassist.bytecode.Descriptor;
- public class GuedezMods implements WurmClientMod, Configurable, Initable, PreInitable {
- public class PlayerContainer {
- private PlayerObj player;
- private SimpleServerConnectionClass serverConnection;
- private ServerConnectionListenerClass listener;
- public PlayerContainer(PlayerObj player, SimpleServerConnectionClass serverConnection, ServerConnectionListenerClass listener) {
- this.player = player;
- this.serverConnection = serverConnection;
- this.listener = listener;
- }
- }
- public static AutoMover autoMover;
- public static AutoSortMod autoSort;
- public static ActionMod actionMod;
- public static LiveHudMapMod liveMapMod;
- private HashMap<String, Long> timedCommandMap = new HashMap<>();
- public static StructureData foundStructure;
- public static CellRenderable foundMount;
- public static CellRenderable foundPile;
- private HashMap<String, PlayerContainer> loggedMap = new HashMap<>();
- private static final Logger logger = Logger.getLogger("GuedezMods");
- private LinkedList<GuedezWurmMod> mods = new LinkedList<>();
- public static HeadsUpDisplay hud;
- public static WurmConsole console;
- public static World world;
- private static int last_xw;
- private static int last_yw;
- public static boolean lock_hoverw;
- private static int last_xu;
- private static int last_yu;
- public static boolean lock_hoveru;
- public static boolean autoSelectAll = false;
- public static float staminaPercent;
- private boolean toggle_draw_cart;
- private static int currentCommand = 0;
- private static ArrayList<String> commands = new ArrayList<>();
- private static boolean listening;
- private static ArrayList<String> filter = new ArrayList<>();
- private static String stack = "";
- private static int totalFiltered;
- private long commandRunnerInterval;
- private long autoClickingInterval;
- private long lastCommandRunnerTick;
- private long lastAutoClickingTick;
- private Field actionString;
- public boolean autoFeeder = false;
- public long autoFeederCooldown;
- public int autoFeederItemSlot;
- public boolean eatOrdrink;
- public LinkedList<IFCondition> _if = new LinkedList<>();
- public void commandRunner() {
- if (commands.size() > 0 && commandRunnerInterval > 10) {
- long currentTimeMillis = System.currentTimeMillis();
- if (commandRunnerInterval + lastCommandRunnerTick > currentTimeMillis) {
- return;
- }
- if (currentCommand >= commands.size()) {
- currentCommand = 0;
- return;
- }
- try {
- if (isBusy()) {
- return;
- }
- if (world.getPlayer().getStamina() < br.com.guedez.wurm.client.GuedezMods.staminaPercent) {
- return;
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- String input = commands.get(currentCommand++);
- // timedCommandMap
- if (input.startsWith("every")) {
- String[] parts = input.split("\\|", 2);
- if (timedCommandMap.containsKey(parts[1])) {
- if (timedCommandMap.get(parts[1]) + (Long.parseLong(parts[0].substring(5).trim()) * 1000) > currentTimeMillis) {
- return;
- } else {
- timedCommandMap.put(parts[1], currentTimeMillis);
- input = parts[1];
- }
- } else {
- timedCommandMap.put(parts[1], currentTimeMillis);
- input = parts[1];
- }
- }
- if (input.equalsIgnoreCase("wait_stamina")) {
- if (world.getPlayer().getStamina() < 0.99) {
- currentCommand--;
- }
- } else if (input.equalsIgnoreCase("wait_actions")) {
- if (isBusy()) {
- currentCommand--;
- }
- } else {
- console.handleInput(input, false);
- }
- currentCommand %= commands.size();
- lastCommandRunnerTick = currentTimeMillis;
- }
- }
- public void stopAt(WurmConsole console) {
- if (_if.size() > 0) {
- LinkedList<IFCondition> toRemove = new LinkedList<>();
- for (IFCondition __if : _if) {
- if (__if.test()) {
- toRemove.add(__if);
- handleInput(console, __if.after, false);
- }
- }
- _if.removeAll(toRemove);
- }
- }
- public void autoClicker() {
- if (autoClickingInterval + lastAutoClickingTick > System.currentTimeMillis()) {
- return;
- }
- try {
- if (isBusy()) {
- return;
- }
- if (world.getPlayer().getStamina() < br.com.guedez.wurm.client.GuedezMods.staminaPercent) {
- return;
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- if (autoClickingInterval != 0) {
- hud.mousePressed(last_xu, last_yu, 0, 1);
- hud.mouseReleased(last_xu, last_yu, 0);
- hud.consoleOutput("Clicked at " + last_xu + ", " + last_yu);
- lastAutoClickingTick = System.currentTimeMillis();
- }
- }
- private boolean isBusy() {
- try {
- if (actionString == null) {
- actionString = hud.getClass().getDeclaredField("actionString");
- actionString.setAccessible(true);
- }
- return actionString.get(hud) != null && !actionString.get(hud).toString().contains("placing");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- private Field TBF;
- private Method GIIS;
- private HashMap<Long, String> renamedCellRenderable = new HashMap<Long, String>();
- public static void logException(String msg, Throwable e) {
- if (logger != null)
- logger.log(Level.SEVERE, msg, e);
- }
- @SuppressWarnings("unchecked")
- public boolean handleInput(WurmConsole wcons, final String input, final boolean silent) {
- for (GuedezWurmMod mod : mods) {
- if (mod.handleInput(wcons, input, silent)) {
- return true;
- }
- }
- final String[] data = input.split("\\s+");
- final String cmd = data[0].toLowerCase();
- if (IfParser.parse(wcons, input, this)) {
- return true;
- }
- if (cmd.toLowerCase().equals("wait")) {
- return true;
- }
- if (cmd.toLowerCase().equals("list_bindings")) {
- Map<Integer, KeyBinding> bind;
- hud.consoleOutput("Outputing binds");
- try {
- if (bindings == null) {
- try {
- bindings = WurmConsole.class.getDeclaredField("keyBinds");
- bindings.setAccessible(true);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- bind = (Map<Integer, KeyBinding>) bindings.get(wcons);
- for (Entry<Integer, KeyBinding> se : bind.entrySet()) {
- hud.consoleOutput(se.getKey() + " -> " + se.getValue());
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- if (cmd.toLowerCase().equals("list_every")) {
- hud.consoleOutput("Outputing every");
- try {
- for (Entry<String, Long> se : timedCommandMap.entrySet()) {
- hud.consoleOutput(se.getKey() + " -> " + se.getValue());
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- if (cmd.toLowerCase().equals("toggle_draw_cart")) {
- toggle_draw_cart = !toggle_draw_cart;
- System.out.println("toggle_draw_cart is: " + toggle_draw_cart);
- return true;
- }
- if (cmd.toLowerCase().equals("toggle_log_sort")) {
- FilterItem.logSort = !FilterItem.logSort;
- System.out.println("FilterItem.logSort is: " + FilterItem.logSort);
- return true;
- }
- if (cmd.toLowerCase().equals("list_queued_actions")) {
- Map<Integer, KeyBinding> bind;
- hud.consoleOutput("Listing queued actions");
- try {
- if (bindings == null) {
- try {
- bindings = WurmConsole.class.getDeclaredField("keyBinds");
- bindings.setAccessible(true);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- bind = (Map<Integer, KeyBinding>) bindings.get(wcons);
- for (Entry<Integer, KeyBinding> se : bind.entrySet()) {
- hud.consoleOutput(se.getKey() + " -> " + se.getValue());
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- if (cmd.toLowerCase().equals("simulate_key")) {
- if (data.length == 2) {
- String letter = Character.toString(data[1].charAt(0)).toUpperCase();
- String code = "KEY_" + letter;
- Field f;
- try {
- f = Keyboard.class.getField(code);
- int keyEvent = f.getInt(null);
- KeyBinding currentBinding = wcons.getCurrentBinding(keyEvent);
- hud.consoleOutput(keyEvent + "was simulated whose action is: " + (currentBinding != null ? currentBinding.getAction() : "null"));
- wcons.toggleKey(keyEvent, true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return true;
- }
- if (cmd.toLowerCase().equals("load_script")) {
- System.out.println("Reading script file: " + data[1]);
- try (BufferedReader br = new BufferedReader(new FileReader(new File(data[1])))) {
- String line;
- while ((line = br.readLine()) != null) {
- if (line.startsWith("//")) {
- continue;
- }
- handleInput(wcons, line, false);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("Script loaded successfully");
- return true;
- }
- if (cmd.toLowerCase().equals("toggle_auto_feeder")) {
- autoFeeder = !autoFeeder;
- autoFeeder = GuedezMods.readBoolean(autoFeeder, data);
- hud.consoleOutput("Auto Feeding is " + (autoFeeder ? "On" : "Off"));
- return true;
- }
- if (cmd.toLowerCase().equals("toggle_lock_hover_world")) {
- lock_hoverw = !lock_hoverw;
- lock_hoverw = GuedezMods.readBoolean(lock_hoverw, data);
- hud.consoleOutput("World hover is " + (lock_hoverw ? "locked at " + last_xw + ", " + last_yw : "unlocked"));
- return true;
- }
- if (cmd.toLowerCase().equals("toggle_lock_hover_ui")) {
- lock_hoveru = !lock_hoveru;
- lock_hoveru = GuedezMods.readBoolean(lock_hoveru, data);
- hud.consoleOutput("UI hover is " + (lock_hoveru ? "locked at " + last_xu + ", " + last_yu : "unlocked"));
- return true;
- }
- if (cmd.toLowerCase().equals("toggle_auto_select_all")) {
- autoSelectAll = !autoSelectAll;
- autoSelectAll = GuedezMods.readBoolean(autoSelectAll, data);
- hud.consoleOutput((autoSelectAll ? "A" : "not a") + "utomatically asnwering quantity questions with all");
- return true;
- }
- if (cmd.toLowerCase().equals("print_coords")) {
- hud.consoleOutput(world.getPlayer().getPos().getX() / 4f + ", " + (world.getPlayer().getPos().getY() / 4f) + " | " + String.format("Height: %.1f", world.getPlayer().getPos().getH() * 10f));
- return true;
- }
- if (cmd.toLowerCase().equals("protect_stamina")) {
- if (data.length == 2) {
- staminaPercent = Float.parseFloat(data[1]);
- if (staminaPercent > 1 || staminaPercent < 0) {
- hud.consoleOutput("must use a value from 0 to 1");
- staminaPercent = 1;
- } else {
- hud.consoleOutput("staminaPercent = " + staminaPercent);
- }
- return true;
- }
- hud.consoleOutput("Usage: protect_stamina {0 to 1 representing stamina total}");
- hud.consoleOutput("" + world.getPlayer().getStamina());
- return true;
- }
- if (cmd.toLowerCase().equals("queue")) {
- StringBuilder builder = new StringBuilder();
- for (String s : data) {
- builder.append(s + " ");
- }
- commands.add(builder.toString().substring(data[0].length()).trim());
- hud.consoleOutput(commands.size() + " total actions");
- return true;
- }
- if (cmd.toLowerCase().equals("clear")) {
- commands.clear();
- currentCommand = 0;
- hud.consoleOutput(commands.size() + " total actions");
- return true;
- }
- if (cmd.toLowerCase().equals("start")) {
- if (data.length == 2) {
- commandRunnerInterval = Integer.parseInt(data[1]);
- if (commandRunnerInterval <= 10) {
- hud.consoleOutput("Interval must be higher than 10");
- } else {
- hud.consoleOutput("Interval = " + commandRunnerInterval);
- }
- return true;
- }
- hud.consoleOutput("Usage: start {interval in miliseconds}");
- return true;
- }
- if (cmd.toLowerCase().equals("stop")) {
- commands.clear();
- currentCommand = 0;
- commandRunnerInterval = 0;
- return true;
- }
- if (cmd.toLowerCase().equals("autoclicker")) {
- if (data.length == 2) {
- autoClickingInterval = Integer.parseInt(data[1]);
- if (autoClickingInterval <= 10) {
- hud.consoleOutput("Interval must be higher than 10");
- } else {
- hud.consoleOutput("Interval = " + autoClickingInterval);
- }
- return true;
- }
- hud.consoleOutput("Usage: autoclicker {interval in miliseconds}");
- return true;
- }
- if (cmd.toLowerCase().equals("stopautoclicker")) {
- autoClickingInterval = 0;
- return true;
- }
- if (cmd.toLowerCase().equals("listen")) {
- listening = true;
- hud.consoleOutput("listening to trafic");
- return true;
- }
- if (cmd.toLowerCase().equals("stoplisten")) {
- listening = false;
- hud.consoleOutput("not listening to trafic");
- return true;
- }
- if (cmd.toLowerCase().equals("filter")) {
- if (data.length == 2) {
- filter.add(data[1]);
- return true;
- }
- hud.consoleOutput("filtering using: " + filter);
- return true;
- }
- if (cmd.toLowerCase().equals("filter_clear")) {
- filter.clear();
- hud.consoleOutput("filter cleared");
- return true;
- }
- if (cmd.toLowerCase().equals("log_fiter")) {
- hud.consoleOutput("filtered: " + totalFiltered);
- return true;
- }
- if (cmd.toLowerCase().equals("stack")) {
- if (data.length == 2) {
- stack = data[1];
- return true;
- }
- hud.consoleOutput("getting stacktrace for: " + filter);
- return true;
- }
- if (cmd.toLowerCase().equals("find_nearest_structure")) {
- float sqDistance = 10e14f;
- float px = world.getPlayer().getPos().getX();
- float py = world.getPlayer().getPos().getY();
- String term = input.split("\\s+", 2)[1];
- foundStructure = null;
- for (StructureData structure : listAllStaticStructures()) {
- String lowerName = getName(structure).toLowerCase();
- if (lowerName.contains(term.toLowerCase())) {
- if (lowerName.contains(term.toLowerCase())) {
- float sx = structure.getXPos();
- float sy = structure.getYPos();
- float sqDist = (px - sx) * (px - sx) + (py - sy) * (py - sy);
- if (sqDist < sqDistance) {
- sqDistance = sqDist;
- foundStructure = structure;
- }
- }
- }
- }
- if (foundStructure != null) {
- System.out.println("Found Structure: " + foundStructure.getHoverName());
- }
- return true;
- }
- if (cmd.toLowerCase().equals("find_nearest_vehicle")) {
- float sqDistance = 10e14f;
- float px = world.getPlayer().getPos().getX();
- float py = world.getPlayer().getPos().getY();
- String term = input.split("\\s+", 2)[1];
- foundMount = null;
- for (CellRenderable structure : listAllMobileRenderables()) {
- String lowerName = getName(structure).toLowerCase();
- if (lowerName.contains(term.toLowerCase())) {
- float sx = structure.getXPos();
- float sy = structure.getYPos();
- float sqDist = (px - sx) * (px - sx) + (py - sy) * (py - sy);
- if (sqDist < sqDistance) {
- sqDistance = sqDist;
- foundMount = structure;
- }
- }
- }
- if (foundMount != null) {
- System.out.println("Found Structure: " + foundMount.getHoverName());
- }
- return true;
- }
- if (cmd.toLowerCase().equals("find_nearest_pile")) {
- float sqDistance = 10e14f;
- float px = world.getPlayer().getPos().getX() / 4;
- float py = world.getPlayer().getPos().getY() / 4;
- boolean cave = data.length > 1 ? data[1].equals("cave") : false;
- String term = input.split("\\s+", cave ? 3 : 2)[cave ? 2 : 1];
- foundPile = null;
- for (CellRenderable structure : listAllStaticRenderables(cave)) {
- String lowerName = getName(structure).toLowerCase();
- if (lowerName.contains(term.toLowerCase())) {
- float sx = structure.getVolume().getCenterX() / 4;
- float sy = structure.getVolume().getCenterY() / 4;
- float sqDist = (px - sx) * (px - sx) + (py - sy) * (py - sy);
- if (sqDist < sqDistance) {
- sqDistance = sqDist;
- foundPile = structure;
- }
- }
- }
- if (foundPile != null) {
- System.out.println("Found Structure: " + foundPile.getHoverName() + "at: " + foundPile.getVolume().getCenterX() / 4 + ", " + foundPile.getVolume().getCenterY() / 4);
- }
- return true;
- }
- if (cmd.toLowerCase().equals("clear_renames")) {
- renamedCellRenderable.clear();
- }
- if (cmd.toLowerCase().equals("rename")) {
- CellRenderable toRename = null;
- if (data[1].equals("foundPile")) {
- toRename = foundPile;
- } else if (data[1].equals("foundMount")) {
- toRename = foundMount;
- } else if (data[1].equals("foundStructure")) {
- toRename = foundStructure;
- }
- if (toRename != null) {
- renamedCellRenderable.put(toRename.getId(), data[2]);
- }
- }
- if (cmd.toLowerCase().equals("place_found_pile_at_player")) {
- float px = world.getPlayer().getPos().getX();
- float py = world.getPlayer().getPos().getY();
- float ph = world.getPlayer().getPos().getH();
- world.getServerConnection().sendPlaceItem(foundPile.getId(), px, py, ph, 0);
- }
- if (cmd.toLowerCase().equals("login")) {
- return login(data, false);
- }
- if (cmd.toLowerCase().equals("relog")) {
- return login(data, true);
- }
- if (cmd.toLowerCase().equals("swap")) {
- return swap(data);
- }
- return false;
- }
- private boolean swap(final String[] data) {
- try {
- PlayerContainer playerContainer = loggedMap.get(data[1].toLowerCase().trim());
- PlayerObj playerObj = playerContainer != null ? playerContainer.player : null;
- if (playerObj != null && world.getPlayer() != playerObj) {
- ReflectionUtil.setPrivateField(world, ReflectionUtil.getField(World.class, "player"), playerObj);
- ReflectionUtil.setPrivateField(world.getClient(), ReflectionUtil.getField(WurmClientBase.class, "serverConnection"), playerContainer.serverConnection);
- ReflectionUtil.setPrivateField(world.getClient(), ReflectionUtil.getField(WurmClientBase.class, "connectionListener"), playerContainer.listener);
- System.out.println(playerContainer.serverConnection.isLoggedIn());
- System.out.println("swapped to: " + data[1]);
- } else if (playerObj == null) {
- for (Entry<String, PlayerContainer> e : loggedMap.entrySet()) {
- System.out.println(e.getKey() + "->" + e.getValue().player);
- }
- return login(data, false);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- private boolean login(final String[] data, boolean relog) {
- try {
- PlayerContainer playerContainer = loggedMap.get(data[1].toLowerCase().trim());
- PlayerObj playerObj = playerContainer != null ? playerContainer.player : null;
- if (playerObj != null || getPlayerName(world.getPlayer()).equalsIgnoreCase(data[1])) {
- System.out.println("player already connected");
- return true;
- }
- WurmClientBase client = world.getClient();
- if (!loggedMap.containsKey(getPlayerName(world.getPlayer()).toLowerCase().trim())) {
- System.out.println("playername:" + getPlayerName(world.getPlayer()).toLowerCase().trim());
- loggedMap.put(getPlayerName(world.getPlayer()).toLowerCase().trim(), new PlayerContainer(world.getPlayer(), world.getServerConnection(), client.getConnectionListener()));
- }
- //////
- Constructor<PlayerObj> constructor = PlayerObj.class.getDeclaredConstructor(World.class);
- constructor.setAccessible(true);
- PlayerObj newInstance = constructor.newInstance(world);
- ReflectionUtil.setPrivateField(world, ReflectionUtil.getField(World.class, "player"), newInstance);
- //////
- System.out.println("begin login");
- ServerConnectionListenerClass serverConnectionListenerClass = new ServerConnectionListenerClass(client, this.world);
- System.out.println("new ServerConnectionListenerClass");
- ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "connectionListener"), serverConnectionListenerClass);
- System.out.println("connectionListener");
- SimpleServerConnectionClass simpleServerConnectionClass = new SimpleServerConnectionClass(serverConnectionListenerClass);
- System.out.println("new SimpleServerConnectionClass");
- ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "uname"), data[1].trim());
- loggedMap.put(getPlayerName(world.getPlayer()).toLowerCase().trim(), new PlayerContainer(newInstance, world.getServerConnection(), client.getConnectionListener()));
- simpleServerConnectionClass.setLoginInfo(//
- data[1], //
- ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(WurmClientBase.class, "passwrd")), //
- ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(WurmClientBase.class, "serverpasswrd")), //
- ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(WurmClientBase.class, "isExtraTileData")));
- System.out.println("setLoginInfo");
- ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "serverConnection"), simpleServerConnectionClass);
- System.out.println("serverConnection");
- ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "startupRenderer"), new StartupRenderer(0, 0));
- System.out.println("new StartupRenderer(0, 0)");
- ReflectionUtil.callPrivateMethod(client, ReflectionUtil.getMethod(WurmClientBase.class, "performConnection"));
- System.out.println("performConnection");
- return true;
- // NEEDS TO SET NEW WORLD VARIABLE
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- private String getPlayerName(PlayerObj obj) {
- return obj.getPlayerName();
- }
- private String getName(CellRenderable structure) {
- String newName = null;
- if ((newName = renamedCellRenderable.get(structure.getId())) != null) {
- return newName;
- }
- return structure.getHoverName();
- }
- public static int updateXW(int x) {
- if (lock_hoverw) {
- x = last_xw;
- } else {
- last_xw = x;
- }
- return x;
- }
- public static int updateYW(int y) {
- if (lock_hoverw) {
- y = last_yw;
- } else {
- last_yw = y;
- }
- return y;
- }
- public static int updateXU(int x) {
- if (lock_hoveru) {
- x = last_xu;
- } else {
- last_xu = x;
- }
- return x;
- }
- public static int updateYU(int y) {
- if (lock_hoveru) {
- y = last_yu;
- } else {
- last_yu = y;
- }
- return y;
- }
- public static void listen(int num, ByteBuffer bb) {
- int pos = bb.position();
- String tolog = "" + bb.get();
- bb.position(pos);
- if (listening) {
- if (!filter.contains(tolog)) {
- hud.consoleOutput(tolog);
- } else {
- totalFiltered++;
- }
- if (tolog.matches(stack)) {
- StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (int i = 0; i < stackTrace.length; i++) {
- hud.consoleOutput(stackTrace[i].toString());
- }
- }
- }
- }
- private static Field bindings;
- @Override
- public void init() {
- try {
- initToggleDrawCart();
- initConsole();
- initProtectStamina();
- initLockHover();
- initConnection();
- initAutos();
- initToolOverride();
- initLoginAndSwapHooks();
- worldHandle();
- for (GuedezWurmMod mod : mods) {
- mod.init();
- }
- } catch (Throwable e) {
- logException("Error loading mod", e);
- logger.log(Level.INFO, e.toString());
- logger.log(Level.INFO, e.getMessage());
- logger.log(Level.INFO, e.getStackTrace()[0].toString());
- logger.log(Level.INFO, e.getStackTrace()[1].toString());
- logger.log(Level.INFO, "Endofstack");
- }
- }
- @Override
- public void configure(Properties properties) {
- mods.add(autoMover = new AutoMover());
- mods.add(autoSort = new AutoSortMod());
- mods.add(actionMod = new ActionMod());
- mods.add(liveMapMod = new LiveHudMapMod());
- for (GuedezWurmMod mod : mods) {
- mod.configure(properties);
- }
- }
- private void worldHandle() {
- HookManager.getInstance().registerHook("com.wurmonline.client.renderer.gui.HeadsUpDisplay", "init", "(II)V", () -> (proxy, method, args) -> {
- method.invoke(proxy, args);
- hud = (HeadsUpDisplay) proxy;
- console = ReflectionUtil.getPrivateField(hud, ReflectionUtil.getField(hud.getClass(), "console"));
- world = ReflectionUtil.getPrivateField(hud, ReflectionUtil.getField(hud.getClass(), "world"));
- liveMapMod.initLiveMap((HeadsUpDisplay) proxy);
- Reflect.setup();
- logger.log(Level.INFO, "hud");
- return null;
- });
- CtClass[] paramTypes;
- try {
- paramTypes = new CtClass[] { //
- ClassPool.getDefault().getCtClass(WurmComponent.class.getName())// final WurmComponent comp
- };
- HookManager.getInstance().registerHook("com.wurmonline.client.renderer.gui.HeadsUpDisplay", "addDynamicComponent", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), () -> (proxy, method, args) -> {
- method.invoke(proxy, args);
- WurmComponent comp = (WurmComponent) args[0];
- if (comp instanceof BmlWindowComponent && autoSelectAll) {
- process((BmlWindowComponent) comp);
- }
- return null;
- });
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- private static Field ownerF;
- public static void process(BmlWindowComponent window) {
- try {
- if (ownerF == null) {
- ownerF = BmlWindowComponent.class.getDeclaredField("owner");
- ownerF.setAccessible(true);
- }
- BmlWindowListener owner = (BmlWindowListener) ownerF.get(window);
- owner.submit(window, "submit");
- System.out.println("submit");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void initConnection() {
- try {
- CtClass[] paramTypes = new CtClass[] { CtPrimitiveType.intType, ClassPool.getDefault().getCtClass(ByteBuffer.class.getName()) };
- HookManager.getInstance().registerHook("com.wurmonline.client.comm.SimpleServerConnectionClass", "reallyHandle", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- listen((int) args[0], (ByteBuffer) args[1]);
- return method.invoke(object, args);
- }
- };
- }
- });
- } catch (Exception e) {
- throw new HookException(e);
- }
- logger.log(Level.INFO, "initConnection()");
- }
- private void initLockHover() throws CannotCompileException, NotFoundException {
- ////////////////////////////////////
- String pickLock = "if (($1 = br.com.guedez.wurm.client.GuedezMods.updateXW($1)) + ($2 = br.com.guedez.wurm.client.GuedezMods.updateYW($2)) == 0);";
- ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.WorldRender")//
- .getMethod("pick", //
- Descriptor.ofMethod(//
- CtPrimitiveType.voidType, //
- new CtClass[] { CtClass.intType, CtClass.intType, CtClass.intType, CtClass.intType }))
- .insertBefore(pickLock);
- ////////////////////////////////////
- pickLock = "if (($1 = br.com.guedez.wurm.client.GuedezMods.updateXU($1)) + ($2 = br.com.guedez.wurm.client.GuedezMods.updateYU($2)) == 0);";
- ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.gui.HeadsUpDisplay")//
- .getMethod("getCommandTargetsFrom", //
- Descriptor.ofMethod(//
- ClassPool.getDefault().getCtClass(long[].class.getName()), //
- new CtClass[] { CtClass.intType, CtClass.intType }))
- .insertBefore(pickLock);
- ////////////////////////////////////
- pickLock = "if (($1 = br.com.guedez.wurm.client.GuedezMods.updateXU($1)) + ($2 = br.com.guedez.wurm.client.GuedezMods.updateYU($2)) == 0);";
- ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.gui.HeadsUpDisplay")//
- .getMethod("mouseMoved", //
- Descriptor.ofMethod(//
- CtClass.voidType, //
- new CtClass[] { CtClass.intType, CtClass.intType }))
- .insertBefore(pickLock);
- ////////////////////////////////////
- ClassPool.getDefault().getCtClass("com.wurmonline.client.WurmEventHandler")//
- .getMethod("isMouseUnavailable", Descriptor.ofMethod(CtPrimitiveType.booleanType, new CtClass[] {}))//
- .insertBefore("if (br.com.guedez.wurm.client.GuedezMods.lock_hoverw || br.com.guedez.wurm.client.GuedezMods.lock_hoveru) return false;");//
- ////////////////////////////////////
- logger.log(Level.INFO, "initLockHover()");
- }
- private void initToggleDrawCart() {
- try {
- CtClass queue = ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.backend.Queue");
- HookManager.getInstance().registerHook("com.wurmonline.client.renderer.cell.MobileModelRenderable", "render", Descriptor.ofMethod(//
- CtClass.voidType, //
- new CtClass[] { queue }), //
- new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- if (!shouldDraw(object)) {
- return null;
- }
- return method.invoke(object, args);
- }
- };
- }
- });
- HookManager.getInstance().registerHook("com.wurmonline.client.renderer.cell.MobileModelRenderable", "pick", Descriptor.ofMethod(//
- CtClass.voidType, //
- new CtClass[] { queue, CtClass.booleanType }), //
- new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- if (!shouldDraw(object)) {
- return null;
- }
- return method.invoke(object, args);
- }
- };
- }
- });
- logger.log(Level.INFO, "initToggleDrawCart()");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private boolean shouldDraw(Object object) {
- if (toggle_draw_cart && object != world.getPlayer().getPlayerBody()) {
- if (object instanceof CellRenderable) {
- if (world.getPlayer().getCarrierCreature() != null) {
- if (world.getPlayer().getCarrierCreature().getId() == ((CellRenderable) object).getId()) {
- return false;
- }
- if (object instanceof MobileModelRenderable) {
- CreatureCellRenderable carrierCreature = ((MobileModelRenderable) object).getCarrierCreature();
- if (carrierCreature != null && carrierCreature.getId() == world.getPlayer().getCarrierCreature().getId()) {
- return false;
- }
- }
- }
- }
- }
- return true;
- }
- private void initProtectStamina() throws CannotCompileException, NotFoundException {
- ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.gui.HeadsUpDisplay").//
- getMethod("sendAction", //
- Descriptor.ofMethod(//
- CtClass.voidType, //
- new CtClass[] { //
- ClassPool.getDefault().getCtClass("com.wurmonline.shared.constants.PlayerAction"), //
- ClassPool.getDefault().getCtClass(long[].class.getName())//
- })).//
- insertBefore("if(!action.isInstant() && world.getPlayer().getStamina() < br.com.guedez.wurm.client.GuedezMods.staminaPercent) return;");
- logger.log(Level.INFO, "initProtectStamina()");
- }
- private void initToolOverride() throws CannotCompileException, NotFoundException {
- HookManager.getInstance().registerHook("com.wurmonline.client.renderer.gui.HeadsUpDisplay", "getSourceItemId", Descriptor.ofMethod(//
- CtClass.longType, //
- new CtClass[] {}), new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- if (ActionMod.with != -1) {
- return ActionMod.with;
- }
- return method.invoke(object, args);
- }
- };
- }
- });
- }
- private void initAutos() throws CannotCompileException, NotFoundException {
- CtClass[] paramTypes = {};
- HookManager.getInstance().registerHook("com.wurmonline.client.WurmClientBase", "tickFrame", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- // handleInput((WurmConsole) object, (String) args[0], (boolean) args[1])
- stopAt(console);
- if (autoMover.autoWalkTo()) {
- autoClicker();
- commandRunner();
- }
- return method.invoke(object, args);
- }
- };
- }
- });
- logger.log(Level.INFO, "initAutos()");
- }
- private void initLoginAndSwapHooks() {
- CtClass[] paramTypes = {};
- HookManager.getInstance().registerHook("com.wurmonline.client.game.World", "tick", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- method.invoke(object, args);
- for (Entry<String, PlayerContainer> pl : loggedMap.entrySet()) {
- if (world.getPlayer() != pl.getValue().player) {
- pl.getValue().player.gametick();
- }
- }
- return null;
- }
- };
- }
- });
- logger.log(Level.INFO, "initLoginAndSwapHooks()");
- // world.public void tick()
- }
- // final String input, final boolean silent
- private void initConsole() throws CannotCompileException, NotFoundException {
- try {
- CtClass[] paramTypes = { ClassPool.getDefault().getCtClass("java.lang.String"), CtPrimitiveType.booleanType };
- HookManager.getInstance().registerHook("com.wurmonline.client.console.WurmConsole", "handleInput2", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
- @Override
- public InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- @Override
- public Object invoke(Object object, Method method, Object[] args) throws Throwable {
- if (handleInput((WurmConsole) object, (String) args[0], (boolean) args[1])) {
- return null;
- }
- return method.invoke(object, args);
- }
- };
- }
- });
- } catch (Exception e) {
- throw new HookException(e);
- }
- logger.log(Level.INFO, "initConsole()");
- }
- @Override
- public void preInit() {
- }
- private static Field surfaceSorted;
- private static Field caveSorted;
- private static Field staticStructures;// buildings List<StructureData>
- private static Field staticRenderables;// ground items List<CellRenderable>
- private static Field mobileRenderables;// horses and shit List<CellRenderable>
- public static List<StructureData> listAllStaticStructures() {
- SurfaceCell[] cells = null;
- try {
- if (surfaceSorted == null) {
- surfaceSorted = ReflectionUtil.getField(CellRenderer.class, "surfaceSorted");
- surfaceSorted.setAccessible(true);
- }
- if (staticStructures == null) {
- staticStructures = Cell.class.getDeclaredField("staticStructures");
- staticStructures.setAccessible(true);
- }
- cells = ReflectionUtil.getPrivateField(world.getCellRenderer(), surfaceSorted);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (cells != null) {
- List<StructureData> rends = new LinkedList<>();
- for (SurfaceCell c : cells) {
- try {
- rends.addAll((Collection<? extends StructureData>) staticStructures.get(c));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return rends;
- }
- return new LinkedList<>();
- }
- public static List<CellRenderable> listAllStaticRenderables(boolean cave) {
- SurfaceCell[] cells = null;
- CaveCell[] ccells = null;
- try {
- if (surfaceSorted == null) {
- surfaceSorted = ReflectionUtil.getField(CellRenderer.class, "surfaceSorted");
- surfaceSorted.setAccessible(true);
- }
- if (caveSorted == null) {
- caveSorted = ReflectionUtil.getField(CellRenderer.class, "caveSorted");
- caveSorted.setAccessible(true);
- }
- if (staticRenderables == null) {
- staticRenderables = Cell.class.getDeclaredField("staticRenderables");
- staticRenderables.setAccessible(true);
- }
- cells = ReflectionUtil.getPrivateField(world.getCellRenderer(), surfaceSorted);
- ccells = ReflectionUtil.getPrivateField(world.getCellRenderer(), caveSorted);
- } catch (Exception e) {
- e.printStackTrace();
- }
- List<CellRenderable> rends = new LinkedList<>();
- if (cells != null && !cave) {
- for (SurfaceCell c : cells) {
- try {
- rends.addAll((Collection<? extends CellRenderable>) staticRenderables.get(c));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- if (ccells != null && cave) {
- for (CaveCell c : ccells) {
- try {
- rends.addAll((Collection<? extends CellRenderable>) staticRenderables.get(c));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- return rends;
- }
- public static List<CellRenderable> listAllMobileRenderables() {
- SurfaceCell[] cells = null;
- try {
- if (surfaceSorted == null) {
- surfaceSorted = ReflectionUtil.getField(CellRenderer.class, "surfaceSorted");
- surfaceSorted.setAccessible(true);
- }
- if (mobileRenderables == null) {
- mobileRenderables = Cell.class.getDeclaredField("mobileRenderables");
- mobileRenderables.setAccessible(true);
- }
- cells = ReflectionUtil.getPrivateField(world.getCellRenderer(), surfaceSorted);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (cells != null) {
- List<CellRenderable> rends = new LinkedList<>();
- for (SurfaceCell c : cells) {
- try {
- rends.addAll((Collection<? extends CellRenderable>) mobileRenderables.get(c));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return rends;
- }
- return new LinkedList<>();
- }
- public static boolean readBoolean(final boolean original, final String[] data) {
- if (data.length == 1) {
- return original;
- }
- try {
- return Boolean.parseBoolean(data[1]);
- } catch (Exception e) {
- if (data[1].toLowerCase().equals("on")) {
- return true;
- } else if (data[1].toLowerCase().equals("off")) {
- return false;
- } else {
- e.printStackTrace();
- }
- }
- return original;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement