Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 40.49 KB | None | 0 0
  1. package br.com.guedez.wurm.client;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.lang.reflect.Constructor;
  7. import java.lang.reflect.Field;
  8. import java.lang.reflect.InvocationHandler;
  9. import java.lang.reflect.Method;
  10. import java.nio.ByteBuffer;
  11. import java.util.ArrayList;
  12. import java.util.Collection;
  13. import java.util.HashMap;
  14. import java.util.LinkedList;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Map.Entry;
  18. import java.util.Properties;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21.  
  22. import org.gotti.wurmunlimited.modloader.ReflectionUtil;
  23. import org.gotti.wurmunlimited.modloader.classhooks.HookException;
  24. import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
  25. import org.gotti.wurmunlimited.modloader.classhooks.InvocationHandlerFactory;
  26. import org.gotti.wurmunlimited.modloader.interfaces.Configurable;
  27. import org.gotti.wurmunlimited.modloader.interfaces.Initable;
  28. import org.gotti.wurmunlimited.modloader.interfaces.PreInitable;
  29. import org.gotti.wurmunlimited.modloader.interfaces.WurmClientMod;
  30. import org.lwjgl.input.Keyboard;
  31.  
  32. import com.wurmonline.client.WurmClientBase;
  33. import com.wurmonline.client.comm.ServerConnectionListenerClass;
  34. import com.wurmonline.client.comm.SimpleServerConnectionClass;
  35. import com.wurmonline.client.console.KeyBinding;
  36. import com.wurmonline.client.console.WurmConsole;
  37. import com.wurmonline.client.game.PlayerObj;
  38. import com.wurmonline.client.game.World;
  39. import com.wurmonline.client.renderer.cell.CaveCell;
  40. import com.wurmonline.client.renderer.cell.Cell;
  41. import com.wurmonline.client.renderer.cell.CellRenderable;
  42. import com.wurmonline.client.renderer.cell.CellRenderer;
  43. import com.wurmonline.client.renderer.cell.CreatureCellRenderable;
  44. import com.wurmonline.client.renderer.cell.MobileModelRenderable;
  45. import com.wurmonline.client.renderer.cell.SurfaceCell;
  46. import com.wurmonline.client.renderer.gui.BmlWindowComponent;
  47. import com.wurmonline.client.renderer.gui.BmlWindowListener;
  48. import com.wurmonline.client.renderer.gui.HeadsUpDisplay;
  49. import com.wurmonline.client.renderer.gui.WurmComponent;
  50. import com.wurmonline.client.renderer.structures.StructureData;
  51. import com.wurmonline.client.startup.splash.StartupRenderer;
  52.  
  53. import br.com.guedez.wurm.client.actionmod.ActionMod;
  54. import br.com.guedez.wurm.client.actionmod.Reflect;
  55. import br.com.guedez.wurm.client.automove.AutoMover;
  56. import br.com.guedez.wurm.client.autosort.AutoSortMod;
  57. import br.com.guedez.wurm.client.autosort.FilterItem;
  58. import br.com.guedez.wurm.client.autostop.IFCondition;
  59. import br.com.guedez.wurm.client.autostop.IfParser;
  60. import br.com.guedez.wurm.client.interfaces.GuedezWurmMod;
  61. import br.com.guedez.wurm.client.livemap.LiveHudMapMod;
  62. import javassist.CannotCompileException;
  63. import javassist.ClassPool;
  64. import javassist.CtClass;
  65. import javassist.CtPrimitiveType;
  66. import javassist.NotFoundException;
  67. import javassist.bytecode.Descriptor;
  68.  
  69. public class GuedezMods implements WurmClientMod, Configurable, Initable, PreInitable {
  70.  
  71.     public class PlayerContainer {
  72.         private PlayerObj player;
  73.         private SimpleServerConnectionClass serverConnection;
  74.         private ServerConnectionListenerClass listener;
  75.  
  76.         public PlayerContainer(PlayerObj player, SimpleServerConnectionClass serverConnection, ServerConnectionListenerClass listener) {
  77.             this.player = player;
  78.             this.serverConnection = serverConnection;
  79.             this.listener = listener;
  80.         }
  81.     }
  82.  
  83.     public static AutoMover autoMover;
  84.     public static AutoSortMod autoSort;
  85.     public static ActionMod actionMod;
  86.     public static LiveHudMapMod liveMapMod;
  87.     private HashMap<String, Long> timedCommandMap = new HashMap<>();
  88.  
  89.     public static StructureData foundStructure;
  90.     public static CellRenderable foundMount;
  91.     public static CellRenderable foundPile;
  92.  
  93.     private HashMap<String, PlayerContainer> loggedMap = new HashMap<>();
  94.  
  95.     private static final Logger logger = Logger.getLogger("GuedezMods");
  96.     private LinkedList<GuedezWurmMod> mods = new LinkedList<>();
  97.     public static HeadsUpDisplay hud;
  98.     public static WurmConsole console;
  99.     public static World world;
  100.     private static int last_xw;
  101.     private static int last_yw;
  102.     public static boolean lock_hoverw;
  103.     private static int last_xu;
  104.     private static int last_yu;
  105.     public static boolean lock_hoveru;
  106.     public static boolean autoSelectAll = false;
  107.     public static float staminaPercent;
  108.     private boolean toggle_draw_cart;
  109.  
  110.     private static int currentCommand = 0;
  111.     private static ArrayList<String> commands = new ArrayList<>();
  112.     private static boolean listening;
  113.     private static ArrayList<String> filter = new ArrayList<>();
  114.     private static String stack = "";
  115.     private static int totalFiltered;
  116.  
  117.     private long commandRunnerInterval;
  118.     private long autoClickingInterval;
  119.     private long lastCommandRunnerTick;
  120.     private long lastAutoClickingTick;
  121.     private Field actionString;
  122.  
  123.     public boolean autoFeeder = false;
  124.     public long autoFeederCooldown;
  125.     public int autoFeederItemSlot;
  126.     public boolean eatOrdrink;
  127.     public LinkedList<IFCondition> _if = new LinkedList<>();
  128.  
  129.     public void commandRunner() {
  130.         if (commands.size() > 0 && commandRunnerInterval > 10) {
  131.             long currentTimeMillis = System.currentTimeMillis();
  132.             if (commandRunnerInterval + lastCommandRunnerTick > currentTimeMillis) {
  133.                 return;
  134.             }
  135.             if (currentCommand >= commands.size()) {
  136.                 currentCommand = 0;
  137.                 return;
  138.             }
  139.             try {
  140.                 if (isBusy()) {
  141.                     return;
  142.                 }
  143.                 if (world.getPlayer().getStamina() < br.com.guedez.wurm.client.GuedezMods.staminaPercent) {
  144.                     return;
  145.                 }
  146.             } catch (Exception e1) {
  147.                 e1.printStackTrace();
  148.             }
  149.             String input = commands.get(currentCommand++);
  150.             // timedCommandMap
  151.             if (input.startsWith("every")) {
  152.                 String[] parts = input.split("\\|", 2);
  153.                 if (timedCommandMap.containsKey(parts[1])) {
  154.                     if (timedCommandMap.get(parts[1]) + (Long.parseLong(parts[0].substring(5).trim()) * 1000) > currentTimeMillis) {
  155.                         return;
  156.                     } else {
  157.                         timedCommandMap.put(parts[1], currentTimeMillis);
  158.                         input = parts[1];
  159.                     }
  160.                 } else {
  161.                     timedCommandMap.put(parts[1], currentTimeMillis);
  162.                     input = parts[1];
  163.                 }
  164.             }
  165.             if (input.equalsIgnoreCase("wait_stamina")) {
  166.                 if (world.getPlayer().getStamina() < 0.99) {
  167.                     currentCommand--;
  168.                 }
  169.             } else if (input.equalsIgnoreCase("wait_actions")) {
  170.                 if (isBusy()) {
  171.                     currentCommand--;
  172.                 }
  173.             } else {
  174.                 console.handleInput(input, false);
  175.             }
  176.             currentCommand %= commands.size();
  177.  
  178.             lastCommandRunnerTick = currentTimeMillis;
  179.         }
  180.     }
  181.  
  182.     public void stopAt(WurmConsole console) {
  183.         if (_if.size() > 0) {
  184.             LinkedList<IFCondition> toRemove = new LinkedList<>();
  185.             for (IFCondition __if : _if) {
  186.                 if (__if.test()) {
  187.                     toRemove.add(__if);
  188.                     handleInput(console, __if.after, false);
  189.                 }
  190.             }
  191.             _if.removeAll(toRemove);
  192.         }
  193.     }
  194.  
  195.     public void autoClicker() {
  196.         if (autoClickingInterval + lastAutoClickingTick > System.currentTimeMillis()) {
  197.             return;
  198.         }
  199.         try {
  200.             if (isBusy()) {
  201.                 return;
  202.             }
  203.             if (world.getPlayer().getStamina() < br.com.guedez.wurm.client.GuedezMods.staminaPercent) {
  204.                 return;
  205.             }
  206.         } catch (Exception e1) {
  207.             e1.printStackTrace();
  208.         }
  209.         if (autoClickingInterval != 0) {
  210.             hud.mousePressed(last_xu, last_yu, 0, 1);
  211.             hud.mouseReleased(last_xu, last_yu, 0);
  212.             hud.consoleOutput("Clicked at " + last_xu + ", " + last_yu);
  213.             lastAutoClickingTick = System.currentTimeMillis();
  214.         }
  215.     }
  216.  
  217.     private boolean isBusy() {
  218.         try {
  219.             if (actionString == null) {
  220.                 actionString = hud.getClass().getDeclaredField("actionString");
  221.                 actionString.setAccessible(true);
  222.             }
  223.             return actionString.get(hud) != null && !actionString.get(hud).toString().contains("placing");
  224.         } catch (Exception e) {
  225.             e.printStackTrace();
  226.         }
  227.         return false;
  228.     }
  229.  
  230.     private Field TBF;
  231.     private Method GIIS;
  232.     private HashMap<Long, String> renamedCellRenderable = new HashMap<Long, String>();
  233.  
  234.     public static void logException(String msg, Throwable e) {
  235.         if (logger != null)
  236.             logger.log(Level.SEVERE, msg, e);
  237.     }
  238.  
  239.     @SuppressWarnings("unchecked")
  240.     public boolean handleInput(WurmConsole wcons, final String input, final boolean silent) {
  241.         for (GuedezWurmMod mod : mods) {
  242.             if (mod.handleInput(wcons, input, silent)) {
  243.                 return true;
  244.             }
  245.         }
  246.         final String[] data = input.split("\\s+");
  247.         final String cmd = data[0].toLowerCase();
  248.         if (IfParser.parse(wcons, input, this)) {
  249.             return true;
  250.         }
  251.         if (cmd.toLowerCase().equals("wait")) {
  252.             return true;
  253.         }
  254.         if (cmd.toLowerCase().equals("list_bindings")) {
  255.             Map<Integer, KeyBinding> bind;
  256.             hud.consoleOutput("Outputing binds");
  257.             try {
  258.                 if (bindings == null) {
  259.                     try {
  260.                         bindings = WurmConsole.class.getDeclaredField("keyBinds");
  261.                         bindings.setAccessible(true);
  262.                     } catch (Exception e1) {
  263.                         e1.printStackTrace();
  264.                     }
  265.                 }
  266.                 bind = (Map<Integer, KeyBinding>) bindings.get(wcons);
  267.                 for (Entry<Integer, KeyBinding> se : bind.entrySet()) {
  268.                     hud.consoleOutput(se.getKey() + " -> " + se.getValue());
  269.                 }
  270.             } catch (Exception e) {
  271.                 e.printStackTrace();
  272.             }
  273.             return true;
  274.         }
  275.         if (cmd.toLowerCase().equals("list_every")) {
  276.             hud.consoleOutput("Outputing every");
  277.             try {
  278.                 for (Entry<String, Long> se : timedCommandMap.entrySet()) {
  279.                     hud.consoleOutput(se.getKey() + " -> " + se.getValue());
  280.                 }
  281.             } catch (Exception e) {
  282.                 e.printStackTrace();
  283.             }
  284.             return true;
  285.         }
  286.         if (cmd.toLowerCase().equals("toggle_draw_cart")) {
  287.             toggle_draw_cart = !toggle_draw_cart;
  288.             System.out.println("toggle_draw_cart is: " + toggle_draw_cart);
  289.             return true;
  290.         }
  291.         if (cmd.toLowerCase().equals("toggle_log_sort")) {
  292.             FilterItem.logSort = !FilterItem.logSort;
  293.             System.out.println("FilterItem.logSort is: " + FilterItem.logSort);
  294.             return true;
  295.         }
  296.         if (cmd.toLowerCase().equals("list_queued_actions")) {
  297.             Map<Integer, KeyBinding> bind;
  298.             hud.consoleOutput("Listing queued actions");
  299.             try {
  300.                 if (bindings == null) {
  301.                     try {
  302.                         bindings = WurmConsole.class.getDeclaredField("keyBinds");
  303.                         bindings.setAccessible(true);
  304.                     } catch (Exception e1) {
  305.                         e1.printStackTrace();
  306.                     }
  307.                 }
  308.                 bind = (Map<Integer, KeyBinding>) bindings.get(wcons);
  309.                 for (Entry<Integer, KeyBinding> se : bind.entrySet()) {
  310.                     hud.consoleOutput(se.getKey() + " -> " + se.getValue());
  311.                 }
  312.             } catch (Exception e) {
  313.                 e.printStackTrace();
  314.             }
  315.             return true;
  316.         }
  317.         if (cmd.toLowerCase().equals("simulate_key")) {
  318.             if (data.length == 2) {
  319.                 String letter = Character.toString(data[1].charAt(0)).toUpperCase();
  320.                 String code = "KEY_" + letter;
  321.                 Field f;
  322.                 try {
  323.                     f = Keyboard.class.getField(code);
  324.                     int keyEvent = f.getInt(null);
  325.                     KeyBinding currentBinding = wcons.getCurrentBinding(keyEvent);
  326.                     hud.consoleOutput(keyEvent + "was simulated whose action is: " + (currentBinding != null ? currentBinding.getAction() : "null"));
  327.                     wcons.toggleKey(keyEvent, true);
  328.                 } catch (Exception e) {
  329.                     e.printStackTrace();
  330.                 }
  331.             }
  332.             return true;
  333.         }
  334.         if (cmd.toLowerCase().equals("load_script")) {
  335.             System.out.println("Reading script file: " + data[1]);
  336.             try (BufferedReader br = new BufferedReader(new FileReader(new File(data[1])))) {
  337.                 String line;
  338.                 while ((line = br.readLine()) != null) {
  339.                     if (line.startsWith("//")) {
  340.                         continue;
  341.                     }
  342.                     handleInput(wcons, line, false);
  343.                 }
  344.             } catch (Exception e) {
  345.                 e.printStackTrace();
  346.             }
  347.             System.out.println("Script loaded successfully");
  348.             return true;
  349.         }
  350.         if (cmd.toLowerCase().equals("toggle_auto_feeder")) {
  351.             autoFeeder = !autoFeeder;
  352.             autoFeeder = GuedezMods.readBoolean(autoFeeder, data);
  353.             hud.consoleOutput("Auto Feeding is " + (autoFeeder ? "On" : "Off"));
  354.             return true;
  355.         }
  356.         if (cmd.toLowerCase().equals("toggle_lock_hover_world")) {
  357.             lock_hoverw = !lock_hoverw;
  358.             lock_hoverw = GuedezMods.readBoolean(lock_hoverw, data);
  359.             hud.consoleOutput("World hover is " + (lock_hoverw ? "locked at " + last_xw + ", " + last_yw : "unlocked"));
  360.             return true;
  361.         }
  362.         if (cmd.toLowerCase().equals("toggle_lock_hover_ui")) {
  363.             lock_hoveru = !lock_hoveru;
  364.             lock_hoveru = GuedezMods.readBoolean(lock_hoveru, data);
  365.             hud.consoleOutput("UI hover is " + (lock_hoveru ? "locked at " + last_xu + ", " + last_yu : "unlocked"));
  366.             return true;
  367.         }
  368.         if (cmd.toLowerCase().equals("toggle_auto_select_all")) {
  369.             autoSelectAll = !autoSelectAll;
  370.             autoSelectAll = GuedezMods.readBoolean(autoSelectAll, data);
  371.             hud.consoleOutput((autoSelectAll ? "A" : "not a") + "utomatically asnwering quantity questions with all");
  372.             return true;
  373.         }
  374.         if (cmd.toLowerCase().equals("print_coords")) {
  375.             hud.consoleOutput(world.getPlayer().getPos().getX() / 4f + ", " + (world.getPlayer().getPos().getY() / 4f) + " | " + String.format("Height: %.1f", world.getPlayer().getPos().getH() * 10f));
  376.             return true;
  377.         }
  378.         if (cmd.toLowerCase().equals("protect_stamina")) {
  379.             if (data.length == 2) {
  380.                 staminaPercent = Float.parseFloat(data[1]);
  381.                 if (staminaPercent > 1 || staminaPercent < 0) {
  382.                     hud.consoleOutput("must use a value from 0 to 1");
  383.                     staminaPercent = 1;
  384.                 } else {
  385.                     hud.consoleOutput("staminaPercent = " + staminaPercent);
  386.                 }
  387.                 return true;
  388.             }
  389.             hud.consoleOutput("Usage: protect_stamina {0 to 1 representing stamina total}");
  390.             hud.consoleOutput("" + world.getPlayer().getStamina());
  391.             return true;
  392.         }
  393.         if (cmd.toLowerCase().equals("queue")) {
  394.             StringBuilder builder = new StringBuilder();
  395.             for (String s : data) {
  396.                 builder.append(s + " ");
  397.             }
  398.             commands.add(builder.toString().substring(data[0].length()).trim());
  399.             hud.consoleOutput(commands.size() + " total actions");
  400.             return true;
  401.         }
  402.         if (cmd.toLowerCase().equals("clear")) {
  403.             commands.clear();
  404.             currentCommand = 0;
  405.             hud.consoleOutput(commands.size() + " total actions");
  406.             return true;
  407.         }
  408.         if (cmd.toLowerCase().equals("start")) {
  409.             if (data.length == 2) {
  410.                 commandRunnerInterval = Integer.parseInt(data[1]);
  411.                 if (commandRunnerInterval <= 10) {
  412.                     hud.consoleOutput("Interval must be higher than 10");
  413.                 } else {
  414.                     hud.consoleOutput("Interval = " + commandRunnerInterval);
  415.                 }
  416.                 return true;
  417.             }
  418.             hud.consoleOutput("Usage: start {interval in miliseconds}");
  419.             return true;
  420.         }
  421.         if (cmd.toLowerCase().equals("stop")) {
  422.             commands.clear();
  423.             currentCommand = 0;
  424.             commandRunnerInterval = 0;
  425.             return true;
  426.         }
  427.  
  428.         if (cmd.toLowerCase().equals("autoclicker")) {
  429.             if (data.length == 2) {
  430.                 autoClickingInterval = Integer.parseInt(data[1]);
  431.                 if (autoClickingInterval <= 10) {
  432.                     hud.consoleOutput("Interval must be higher than 10");
  433.                 } else {
  434.                     hud.consoleOutput("Interval = " + autoClickingInterval);
  435.                 }
  436.                 return true;
  437.             }
  438.             hud.consoleOutput("Usage: autoclicker {interval in miliseconds}");
  439.             return true;
  440.         }
  441.         if (cmd.toLowerCase().equals("stopautoclicker")) {
  442.             autoClickingInterval = 0;
  443.             return true;
  444.         }
  445.  
  446.         if (cmd.toLowerCase().equals("listen")) {
  447.             listening = true;
  448.             hud.consoleOutput("listening to trafic");
  449.             return true;
  450.         }
  451.         if (cmd.toLowerCase().equals("stoplisten")) {
  452.             listening = false;
  453.             hud.consoleOutput("not listening to trafic");
  454.             return true;
  455.         }
  456.         if (cmd.toLowerCase().equals("filter")) {
  457.             if (data.length == 2) {
  458.                 filter.add(data[1]);
  459.                 return true;
  460.             }
  461.             hud.consoleOutput("filtering using: " + filter);
  462.             return true;
  463.         }
  464.         if (cmd.toLowerCase().equals("filter_clear")) {
  465.             filter.clear();
  466.             hud.consoleOutput("filter cleared");
  467.             return true;
  468.         }
  469.         if (cmd.toLowerCase().equals("log_fiter")) {
  470.             hud.consoleOutput("filtered: " + totalFiltered);
  471.             return true;
  472.         }
  473.         if (cmd.toLowerCase().equals("stack")) {
  474.             if (data.length == 2) {
  475.                 stack = data[1];
  476.                 return true;
  477.             }
  478.             hud.consoleOutput("getting stacktrace for: " + filter);
  479.             return true;
  480.         }
  481.         if (cmd.toLowerCase().equals("find_nearest_structure")) {
  482.             float sqDistance = 10e14f;
  483.             float px = world.getPlayer().getPos().getX();
  484.             float py = world.getPlayer().getPos().getY();
  485.             String term = input.split("\\s+", 2)[1];
  486.             foundStructure = null;
  487.             for (StructureData structure : listAllStaticStructures()) {
  488.                 String lowerName = getName(structure).toLowerCase();
  489.                 if (lowerName.contains(term.toLowerCase())) {
  490.                     if (lowerName.contains(term.toLowerCase())) {
  491.                         float sx = structure.getXPos();
  492.                         float sy = structure.getYPos();
  493.                         float sqDist = (px - sx) * (px - sx) + (py - sy) * (py - sy);
  494.                         if (sqDist < sqDistance) {
  495.                             sqDistance = sqDist;
  496.                             foundStructure = structure;
  497.                         }
  498.                     }
  499.                 }
  500.             }
  501.             if (foundStructure != null) {
  502.                 System.out.println("Found Structure: " + foundStructure.getHoverName());
  503.             }
  504.             return true;
  505.         }
  506.         if (cmd.toLowerCase().equals("find_nearest_vehicle")) {
  507.             float sqDistance = 10e14f;
  508.             float px = world.getPlayer().getPos().getX();
  509.             float py = world.getPlayer().getPos().getY();
  510.             String term = input.split("\\s+", 2)[1];
  511.             foundMount = null;
  512.             for (CellRenderable structure : listAllMobileRenderables()) {
  513.                 String lowerName = getName(structure).toLowerCase();
  514.                 if (lowerName.contains(term.toLowerCase())) {
  515.                     float sx = structure.getXPos();
  516.                     float sy = structure.getYPos();
  517.                     float sqDist = (px - sx) * (px - sx) + (py - sy) * (py - sy);
  518.                     if (sqDist < sqDistance) {
  519.                         sqDistance = sqDist;
  520.                         foundMount = structure;
  521.                     }
  522.                 }
  523.             }
  524.             if (foundMount != null) {
  525.                 System.out.println("Found Structure: " + foundMount.getHoverName());
  526.             }
  527.             return true;
  528.         }
  529.         if (cmd.toLowerCase().equals("find_nearest_pile")) {
  530.             float sqDistance = 10e14f;
  531.             float px = world.getPlayer().getPos().getX() / 4;
  532.             float py = world.getPlayer().getPos().getY() / 4;
  533.             boolean cave = data.length > 1 ? data[1].equals("cave") : false;
  534.             String term = input.split("\\s+", cave ? 3 : 2)[cave ? 2 : 1];
  535.             foundPile = null;
  536.             for (CellRenderable structure : listAllStaticRenderables(cave)) {
  537.                 String lowerName = getName(structure).toLowerCase();
  538.                 if (lowerName.contains(term.toLowerCase())) {
  539.                     float sx = structure.getVolume().getCenterX() / 4;
  540.                     float sy = structure.getVolume().getCenterY() / 4;
  541.                     float sqDist = (px - sx) * (px - sx) + (py - sy) * (py - sy);
  542.                     if (sqDist < sqDistance) {
  543.                         sqDistance = sqDist;
  544.                         foundPile = structure;
  545.                     }
  546.                 }
  547.             }
  548.             if (foundPile != null) {
  549.                 System.out.println("Found Structure: " + foundPile.getHoverName() + "at: " + foundPile.getVolume().getCenterX() / 4 + ", " + foundPile.getVolume().getCenterY() / 4);
  550.             }
  551.             return true;
  552.         }
  553.         if (cmd.toLowerCase().equals("clear_renames")) {
  554.             renamedCellRenderable.clear();
  555.         }
  556.         if (cmd.toLowerCase().equals("rename")) {
  557.             CellRenderable toRename = null;
  558.             if (data[1].equals("foundPile")) {
  559.                 toRename = foundPile;
  560.             } else if (data[1].equals("foundMount")) {
  561.                 toRename = foundMount;
  562.             } else if (data[1].equals("foundStructure")) {
  563.                 toRename = foundStructure;
  564.             }
  565.             if (toRename != null) {
  566.                 renamedCellRenderable.put(toRename.getId(), data[2]);
  567.             }
  568.         }
  569.         if (cmd.toLowerCase().equals("place_found_pile_at_player")) {
  570.             float px = world.getPlayer().getPos().getX();
  571.             float py = world.getPlayer().getPos().getY();
  572.             float ph = world.getPlayer().getPos().getH();
  573.             world.getServerConnection().sendPlaceItem(foundPile.getId(), px, py, ph, 0);
  574.         }
  575.         if (cmd.toLowerCase().equals("login")) {
  576.             return login(data, false);
  577.         }
  578.         if (cmd.toLowerCase().equals("relog")) {
  579.             return login(data, true);
  580.         }
  581.         if (cmd.toLowerCase().equals("swap")) {
  582.             return swap(data);
  583.         }
  584.         return false;
  585.     }
  586.  
  587.     private boolean swap(final String[] data) {
  588.         try {
  589.             PlayerContainer playerContainer = loggedMap.get(data[1].toLowerCase().trim());
  590.             PlayerObj playerObj = playerContainer != null ? playerContainer.player : null;
  591.             if (playerObj != null && world.getPlayer() != playerObj) {
  592.                 ReflectionUtil.setPrivateField(world, ReflectionUtil.getField(World.class, "player"), playerObj);
  593.                 ReflectionUtil.setPrivateField(world.getClient(), ReflectionUtil.getField(WurmClientBase.class, "serverConnection"), playerContainer.serverConnection);
  594.                 ReflectionUtil.setPrivateField(world.getClient(), ReflectionUtil.getField(WurmClientBase.class, "connectionListener"), playerContainer.listener);
  595.                 System.out.println(playerContainer.serverConnection.isLoggedIn());
  596.                 System.out.println("swapped to: " + data[1]);
  597.             } else if (playerObj == null) {
  598.                 for (Entry<String, PlayerContainer> e : loggedMap.entrySet()) {
  599.                     System.out.println(e.getKey() + "->" + e.getValue().player);
  600.                 }
  601.                 return login(data, false);
  602.             }
  603.         } catch (Exception e) {
  604.             e.printStackTrace();
  605.         }
  606.         return true;
  607.     }
  608.  
  609.     private boolean login(final String[] data, boolean relog) {
  610.         try {
  611.             PlayerContainer playerContainer = loggedMap.get(data[1].toLowerCase().trim());
  612.             PlayerObj playerObj = playerContainer != null ? playerContainer.player : null;
  613.             if (playerObj != null || getPlayerName(world.getPlayer()).equalsIgnoreCase(data[1])) {
  614.                 System.out.println("player already connected");
  615.                 return true;
  616.             }
  617.             WurmClientBase client = world.getClient();
  618.             if (!loggedMap.containsKey(getPlayerName(world.getPlayer()).toLowerCase().trim())) {
  619.                 System.out.println("playername:" + getPlayerName(world.getPlayer()).toLowerCase().trim());
  620.                 loggedMap.put(getPlayerName(world.getPlayer()).toLowerCase().trim(), new PlayerContainer(world.getPlayer(), world.getServerConnection(), client.getConnectionListener()));
  621.             }
  622.             //////
  623.             Constructor<PlayerObj> constructor = PlayerObj.class.getDeclaredConstructor(World.class);
  624.             constructor.setAccessible(true);
  625.             PlayerObj newInstance = constructor.newInstance(world);
  626.             ReflectionUtil.setPrivateField(world, ReflectionUtil.getField(World.class, "player"), newInstance);
  627.             //////
  628.  
  629.             System.out.println("begin login");
  630.             ServerConnectionListenerClass serverConnectionListenerClass = new ServerConnectionListenerClass(client, this.world);
  631.             System.out.println("new ServerConnectionListenerClass");
  632.             ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "connectionListener"), serverConnectionListenerClass);
  633.             System.out.println("connectionListener");
  634.             SimpleServerConnectionClass simpleServerConnectionClass = new SimpleServerConnectionClass(serverConnectionListenerClass);
  635.             System.out.println("new SimpleServerConnectionClass");
  636.             ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "uname"), data[1].trim());
  637.             loggedMap.put(getPlayerName(world.getPlayer()).toLowerCase().trim(), new PlayerContainer(newInstance, world.getServerConnection(), client.getConnectionListener()));
  638.             simpleServerConnectionClass.setLoginInfo(//
  639.                     data[1], //
  640.                     ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(WurmClientBase.class, "passwrd")), //
  641.                     ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(WurmClientBase.class, "serverpasswrd")), //
  642.                     ReflectionUtil.getPrivateField(null, ReflectionUtil.getField(WurmClientBase.class, "isExtraTileData")));
  643.             System.out.println("setLoginInfo");
  644.             ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "serverConnection"), simpleServerConnectionClass);
  645.             System.out.println("serverConnection");
  646.             ReflectionUtil.setPrivateField(client, ReflectionUtil.getField(WurmClientBase.class, "startupRenderer"), new StartupRenderer(0, 0));
  647.             System.out.println("new StartupRenderer(0, 0)");
  648.             ReflectionUtil.callPrivateMethod(client, ReflectionUtil.getMethod(WurmClientBase.class, "performConnection"));
  649.             System.out.println("performConnection");
  650.             return true;
  651.             // NEEDS TO SET NEW WORLD VARIABLE
  652.         } catch (Exception e) {
  653.             e.printStackTrace();
  654.         }
  655.         return false;
  656.     }
  657.  
  658.     private String getPlayerName(PlayerObj obj) {
  659.         return obj.getPlayerName();
  660.     }
  661.  
  662.     private String getName(CellRenderable structure) {
  663.         String newName = null;
  664.         if ((newName = renamedCellRenderable.get(structure.getId())) != null) {
  665.             return newName;
  666.         }
  667.         return structure.getHoverName();
  668.     }
  669.  
  670.     public static int updateXW(int x) {
  671.         if (lock_hoverw) {
  672.             x = last_xw;
  673.         } else {
  674.             last_xw = x;
  675.         }
  676.         return x;
  677.     }
  678.  
  679.     public static int updateYW(int y) {
  680.         if (lock_hoverw) {
  681.             y = last_yw;
  682.         } else {
  683.             last_yw = y;
  684.         }
  685.         return y;
  686.     }
  687.  
  688.     public static int updateXU(int x) {
  689.         if (lock_hoveru) {
  690.             x = last_xu;
  691.         } else {
  692.             last_xu = x;
  693.         }
  694.         return x;
  695.     }
  696.  
  697.     public static int updateYU(int y) {
  698.         if (lock_hoveru) {
  699.             y = last_yu;
  700.         } else {
  701.             last_yu = y;
  702.         }
  703.         return y;
  704.     }
  705.  
  706.     public static void listen(int num, ByteBuffer bb) {
  707.         int pos = bb.position();
  708.         String tolog = "" + bb.get();
  709.         bb.position(pos);
  710.         if (listening) {
  711.             if (!filter.contains(tolog)) {
  712.                 hud.consoleOutput(tolog);
  713.             } else {
  714.                 totalFiltered++;
  715.             }
  716.             if (tolog.matches(stack)) {
  717.                 StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
  718.                 for (int i = 0; i < stackTrace.length; i++) {
  719.                     hud.consoleOutput(stackTrace[i].toString());
  720.                 }
  721.             }
  722.         }
  723.     }
  724.  
  725.     private static Field bindings;
  726.  
  727.     @Override
  728.     public void init() {
  729.         try {
  730.             initToggleDrawCart();
  731.  
  732.             initConsole();
  733.  
  734.             initProtectStamina();
  735.  
  736.             initLockHover();
  737.  
  738.             initConnection();
  739.  
  740.             initAutos();
  741.  
  742.             initToolOverride();
  743.  
  744.             initLoginAndSwapHooks();
  745.  
  746.             worldHandle();
  747.             for (GuedezWurmMod mod : mods) {
  748.                 mod.init();
  749.             }
  750.         } catch (Throwable e) {
  751.             logException("Error loading mod", e);
  752.             logger.log(Level.INFO, e.toString());
  753.             logger.log(Level.INFO, e.getMessage());
  754.             logger.log(Level.INFO, e.getStackTrace()[0].toString());
  755.             logger.log(Level.INFO, e.getStackTrace()[1].toString());
  756.             logger.log(Level.INFO, "Endofstack");
  757.         }
  758.     }
  759.  
  760.     @Override
  761.     public void configure(Properties properties) {
  762.         mods.add(autoMover = new AutoMover());
  763.         mods.add(autoSort = new AutoSortMod());
  764.         mods.add(actionMod = new ActionMod());
  765.         mods.add(liveMapMod = new LiveHudMapMod());
  766.         for (GuedezWurmMod mod : mods) {
  767.             mod.configure(properties);
  768.         }
  769.     }
  770.  
  771.     private void worldHandle() {
  772.         HookManager.getInstance().registerHook("com.wurmonline.client.renderer.gui.HeadsUpDisplay", "init", "(II)V", () -> (proxy, method, args) -> {
  773.             method.invoke(proxy, args);
  774.             hud = (HeadsUpDisplay) proxy;
  775.             console = ReflectionUtil.getPrivateField(hud, ReflectionUtil.getField(hud.getClass(), "console"));
  776.             world = ReflectionUtil.getPrivateField(hud, ReflectionUtil.getField(hud.getClass(), "world"));
  777.             liveMapMod.initLiveMap((HeadsUpDisplay) proxy);
  778.             Reflect.setup();
  779.             logger.log(Level.INFO, "hud");
  780.             return null;
  781.         });
  782.         CtClass[] paramTypes;
  783.         try {
  784.             paramTypes = new CtClass[] { //
  785.                     ClassPool.getDefault().getCtClass(WurmComponent.class.getName())// final WurmComponent comp
  786.             };
  787.             HookManager.getInstance().registerHook("com.wurmonline.client.renderer.gui.HeadsUpDisplay", "addDynamicComponent", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), () -> (proxy, method, args) -> {
  788.                 method.invoke(proxy, args);
  789.                 WurmComponent comp = (WurmComponent) args[0];
  790.                 if (comp instanceof BmlWindowComponent && autoSelectAll) {
  791.                     process((BmlWindowComponent) comp);
  792.                 }
  793.                 return null;
  794.             });
  795.         } catch (Exception e1) {
  796.             e1.printStackTrace();
  797.         }
  798.     }
  799.  
  800.     private static Field ownerF;
  801.  
  802.     public static void process(BmlWindowComponent window) {
  803.         try {
  804.             if (ownerF == null) {
  805.                 ownerF = BmlWindowComponent.class.getDeclaredField("owner");
  806.                 ownerF.setAccessible(true);
  807.             }
  808.             BmlWindowListener owner = (BmlWindowListener) ownerF.get(window);
  809.             owner.submit(window, "submit");
  810.             System.out.println("submit");
  811.         } catch (Exception e) {
  812.             e.printStackTrace();
  813.         }
  814.     }
  815.  
  816.     private void initConnection() {
  817.         try {
  818.             CtClass[] paramTypes = new CtClass[] { CtPrimitiveType.intType, ClassPool.getDefault().getCtClass(ByteBuffer.class.getName()) };
  819.             HookManager.getInstance().registerHook("com.wurmonline.client.comm.SimpleServerConnectionClass", "reallyHandle", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
  820.  
  821.                 @Override
  822.                 public InvocationHandler createInvocationHandler() {
  823.                     return new InvocationHandler() {
  824.                         @Override
  825.                         public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  826.                             listen((int) args[0], (ByteBuffer) args[1]);
  827.                             return method.invoke(object, args);
  828.                         }
  829.  
  830.                     };
  831.                 }
  832.             });
  833.         } catch (Exception e) {
  834.             throw new HookException(e);
  835.         }
  836.         logger.log(Level.INFO, "initConnection()");
  837.     }
  838.  
  839.     private void initLockHover() throws CannotCompileException, NotFoundException {
  840.         ////////////////////////////////////
  841.         String pickLock = "if (($1 = br.com.guedez.wurm.client.GuedezMods.updateXW($1)) + ($2 = br.com.guedez.wurm.client.GuedezMods.updateYW($2)) == 0);";
  842.         ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.WorldRender")//
  843.                 .getMethod("pick", //
  844.                         Descriptor.ofMethod(//
  845.                                 CtPrimitiveType.voidType, //
  846.                                 new CtClass[] { CtClass.intType, CtClass.intType, CtClass.intType, CtClass.intType }))
  847.                 .insertBefore(pickLock);
  848.         ////////////////////////////////////
  849.         pickLock = "if (($1 = br.com.guedez.wurm.client.GuedezMods.updateXU($1)) + ($2 = br.com.guedez.wurm.client.GuedezMods.updateYU($2)) == 0);";
  850.         ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.gui.HeadsUpDisplay")//
  851.                 .getMethod("getCommandTargetsFrom", //
  852.                         Descriptor.ofMethod(//
  853.                                 ClassPool.getDefault().getCtClass(long[].class.getName()), //
  854.                                 new CtClass[] { CtClass.intType, CtClass.intType }))
  855.                 .insertBefore(pickLock);
  856.         ////////////////////////////////////
  857.         pickLock = "if (($1 = br.com.guedez.wurm.client.GuedezMods.updateXU($1)) + ($2 = br.com.guedez.wurm.client.GuedezMods.updateYU($2)) == 0);";
  858.         ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.gui.HeadsUpDisplay")//
  859.                 .getMethod("mouseMoved", //
  860.                         Descriptor.ofMethod(//
  861.                                 CtClass.voidType, //
  862.                                 new CtClass[] { CtClass.intType, CtClass.intType }))
  863.                 .insertBefore(pickLock);
  864.         ////////////////////////////////////
  865.         ClassPool.getDefault().getCtClass("com.wurmonline.client.WurmEventHandler")//
  866.                 .getMethod("isMouseUnavailable", Descriptor.ofMethod(CtPrimitiveType.booleanType, new CtClass[] {}))//
  867.                 .insertBefore("if (br.com.guedez.wurm.client.GuedezMods.lock_hoverw || br.com.guedez.wurm.client.GuedezMods.lock_hoveru) return false;");//
  868.         ////////////////////////////////////
  869.         logger.log(Level.INFO, "initLockHover()");
  870.     }
  871.  
  872.     private void initToggleDrawCart() {
  873.         try {
  874.             CtClass queue = ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.backend.Queue");
  875.             HookManager.getInstance().registerHook("com.wurmonline.client.renderer.cell.MobileModelRenderable", "render", Descriptor.ofMethod(//
  876.                     CtClass.voidType, //
  877.                     new CtClass[] { queue }), //
  878.                     new InvocationHandlerFactory() {
  879.                         @Override
  880.                         public InvocationHandler createInvocationHandler() {
  881.                             return new InvocationHandler() {
  882.                                 @Override
  883.                                 public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  884.                                     if (!shouldDraw(object)) {
  885.                                         return null;
  886.                                     }
  887.                                     return method.invoke(object, args);
  888.                                 }
  889.  
  890.                             };
  891.                         }
  892.                     });
  893.             HookManager.getInstance().registerHook("com.wurmonline.client.renderer.cell.MobileModelRenderable", "pick", Descriptor.ofMethod(//
  894.                     CtClass.voidType, //
  895.                     new CtClass[] { queue, CtClass.booleanType }), //
  896.                     new InvocationHandlerFactory() {
  897.                         @Override
  898.                         public InvocationHandler createInvocationHandler() {
  899.                             return new InvocationHandler() {
  900.                                 @Override
  901.                                 public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  902.                                     if (!shouldDraw(object)) {
  903.                                         return null;
  904.                                     }
  905.                                     return method.invoke(object, args);
  906.                                 }
  907.  
  908.                             };
  909.                         }
  910.                     });
  911.             logger.log(Level.INFO, "initToggleDrawCart()");
  912.         } catch (Exception e) {
  913.             e.printStackTrace();
  914.         }
  915.  
  916.     }
  917.  
  918.     private boolean shouldDraw(Object object) {
  919.         if (toggle_draw_cart && object != world.getPlayer().getPlayerBody()) {
  920.             if (object instanceof CellRenderable) {
  921.                 if (world.getPlayer().getCarrierCreature() != null) {
  922.                     if (world.getPlayer().getCarrierCreature().getId() == ((CellRenderable) object).getId()) {
  923.                         return false;
  924.                     }
  925.                     if (object instanceof MobileModelRenderable) {
  926.                         CreatureCellRenderable carrierCreature = ((MobileModelRenderable) object).getCarrierCreature();
  927.                         if (carrierCreature != null && carrierCreature.getId() == world.getPlayer().getCarrierCreature().getId()) {
  928.                             return false;
  929.                         }
  930.                     }
  931.                 }
  932.             }
  933.         }
  934.         return true;
  935.     }
  936.  
  937.     private void initProtectStamina() throws CannotCompileException, NotFoundException {
  938.         ClassPool.getDefault().getCtClass("com.wurmonline.client.renderer.gui.HeadsUpDisplay").//
  939.                 getMethod("sendAction", //
  940.                         Descriptor.ofMethod(//
  941.                                 CtClass.voidType, //
  942.                                 new CtClass[] { //
  943.                                         ClassPool.getDefault().getCtClass("com.wurmonline.shared.constants.PlayerAction"), //
  944.                                         ClassPool.getDefault().getCtClass(long[].class.getName())//
  945.                                 })).//
  946.                 insertBefore("if(!action.isInstant() && world.getPlayer().getStamina() < br.com.guedez.wurm.client.GuedezMods.staminaPercent) return;");
  947.         logger.log(Level.INFO, "initProtectStamina()");
  948.     }
  949.  
  950.     private void initToolOverride() throws CannotCompileException, NotFoundException {
  951.  
  952.         HookManager.getInstance().registerHook("com.wurmonline.client.renderer.gui.HeadsUpDisplay", "getSourceItemId", Descriptor.ofMethod(//
  953.                 CtClass.longType, //
  954.                 new CtClass[] {}), new InvocationHandlerFactory() {
  955.  
  956.                     @Override
  957.                     public InvocationHandler createInvocationHandler() {
  958.                         return new InvocationHandler() {
  959.                             @Override
  960.                             public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  961.                                 if (ActionMod.with != -1) {
  962.                                     return ActionMod.with;
  963.                                 }
  964.                                 return method.invoke(object, args);
  965.                             }
  966.  
  967.                         };
  968.                     }
  969.                 });
  970.     }
  971.  
  972.     private void initAutos() throws CannotCompileException, NotFoundException {
  973.         CtClass[] paramTypes = {};
  974.         HookManager.getInstance().registerHook("com.wurmonline.client.WurmClientBase", "tickFrame", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
  975.  
  976.             @Override
  977.             public InvocationHandler createInvocationHandler() {
  978.                 return new InvocationHandler() {
  979.                     @Override
  980.                     public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  981.                         // handleInput((WurmConsole) object, (String) args[0], (boolean) args[1])
  982.                         stopAt(console);
  983.                         if (autoMover.autoWalkTo()) {
  984.                             autoClicker();
  985.                             commandRunner();
  986.                         }
  987.                         return method.invoke(object, args);
  988.                     }
  989.  
  990.                 };
  991.             }
  992.         });
  993.         logger.log(Level.INFO, "initAutos()");
  994.     }
  995.  
  996.     private void initLoginAndSwapHooks() {
  997.         CtClass[] paramTypes = {};
  998.         HookManager.getInstance().registerHook("com.wurmonline.client.game.World", "tick", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
  999.  
  1000.             @Override
  1001.             public InvocationHandler createInvocationHandler() {
  1002.                 return new InvocationHandler() {
  1003.                     @Override
  1004.                     public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  1005.                         method.invoke(object, args);
  1006.                         for (Entry<String, PlayerContainer> pl : loggedMap.entrySet()) {
  1007.                             if (world.getPlayer() != pl.getValue().player) {
  1008.                                 pl.getValue().player.gametick();
  1009.                             }
  1010.                         }
  1011.                         return null;
  1012.                     }
  1013.  
  1014.                 };
  1015.             }
  1016.         });
  1017.         logger.log(Level.INFO, "initLoginAndSwapHooks()");
  1018.         // world.public void tick()
  1019.     }
  1020.  
  1021.     // final String input, final boolean silent
  1022.     private void initConsole() throws CannotCompileException, NotFoundException {
  1023.         try {
  1024.             CtClass[] paramTypes = { ClassPool.getDefault().getCtClass("java.lang.String"), CtPrimitiveType.booleanType };
  1025.             HookManager.getInstance().registerHook("com.wurmonline.client.console.WurmConsole", "handleInput2", Descriptor.ofMethod(CtPrimitiveType.voidType, paramTypes), new InvocationHandlerFactory() {
  1026.  
  1027.                 @Override
  1028.                 public InvocationHandler createInvocationHandler() {
  1029.                     return new InvocationHandler() {
  1030.                         @Override
  1031.                         public Object invoke(Object object, Method method, Object[] args) throws Throwable {
  1032.                             if (handleInput((WurmConsole) object, (String) args[0], (boolean) args[1])) {
  1033.                                 return null;
  1034.                             }
  1035.                             return method.invoke(object, args);
  1036.                         }
  1037.  
  1038.                     };
  1039.                 }
  1040.             });
  1041.         } catch (Exception e) {
  1042.             throw new HookException(e);
  1043.         }
  1044.         logger.log(Level.INFO, "initConsole()");
  1045.     }
  1046.  
  1047.     @Override
  1048.     public void preInit() {
  1049.  
  1050.     }
  1051.  
  1052.     private static Field surfaceSorted;
  1053.     private static Field caveSorted;
  1054.     private static Field staticStructures;// buildings List<StructureData>
  1055.     private static Field staticRenderables;// ground items List<CellRenderable>
  1056.     private static Field mobileRenderables;// horses and shit List<CellRenderable>
  1057.  
  1058.     public static List<StructureData> listAllStaticStructures() {
  1059.         SurfaceCell[] cells = null;
  1060.         try {
  1061.             if (surfaceSorted == null) {
  1062.                 surfaceSorted = ReflectionUtil.getField(CellRenderer.class, "surfaceSorted");
  1063.                 surfaceSorted.setAccessible(true);
  1064.             }
  1065.             if (staticStructures == null) {
  1066.                 staticStructures = Cell.class.getDeclaredField("staticStructures");
  1067.                 staticStructures.setAccessible(true);
  1068.             }
  1069.             cells = ReflectionUtil.getPrivateField(world.getCellRenderer(), surfaceSorted);
  1070.         } catch (Exception e) {
  1071.             e.printStackTrace();
  1072.         }
  1073.         if (cells != null) {
  1074.             List<StructureData> rends = new LinkedList<>();
  1075.             for (SurfaceCell c : cells) {
  1076.                 try {
  1077.                     rends.addAll((Collection<? extends StructureData>) staticStructures.get(c));
  1078.                 } catch (Exception e) {
  1079.                     e.printStackTrace();
  1080.                 }
  1081.             }
  1082.             return rends;
  1083.         }
  1084.         return new LinkedList<>();
  1085.     }
  1086.  
  1087.     public static List<CellRenderable> listAllStaticRenderables(boolean cave) {
  1088.         SurfaceCell[] cells = null;
  1089.         CaveCell[] ccells = null;
  1090.         try {
  1091.             if (surfaceSorted == null) {
  1092.                 surfaceSorted = ReflectionUtil.getField(CellRenderer.class, "surfaceSorted");
  1093.                 surfaceSorted.setAccessible(true);
  1094.             }
  1095.             if (caveSorted == null) {
  1096.                 caveSorted = ReflectionUtil.getField(CellRenderer.class, "caveSorted");
  1097.                 caveSorted.setAccessible(true);
  1098.             }
  1099.             if (staticRenderables == null) {
  1100.                 staticRenderables = Cell.class.getDeclaredField("staticRenderables");
  1101.                 staticRenderables.setAccessible(true);
  1102.             }
  1103.             cells = ReflectionUtil.getPrivateField(world.getCellRenderer(), surfaceSorted);
  1104.             ccells = ReflectionUtil.getPrivateField(world.getCellRenderer(), caveSorted);
  1105.         } catch (Exception e) {
  1106.             e.printStackTrace();
  1107.         }
  1108.         List<CellRenderable> rends = new LinkedList<>();
  1109.  
  1110.         if (cells != null && !cave) {
  1111.             for (SurfaceCell c : cells) {
  1112.                 try {
  1113.                     rends.addAll((Collection<? extends CellRenderable>) staticRenderables.get(c));
  1114.                 } catch (Exception e) {
  1115.                     e.printStackTrace();
  1116.                 }
  1117.             }
  1118.         }
  1119.         if (ccells != null && cave) {
  1120.             for (CaveCell c : ccells) {
  1121.                 try {
  1122.                     rends.addAll((Collection<? extends CellRenderable>) staticRenderables.get(c));
  1123.                 } catch (Exception e) {
  1124.                     e.printStackTrace();
  1125.                 }
  1126.             }
  1127.         }
  1128.         return rends;
  1129.     }
  1130.  
  1131.     public static List<CellRenderable> listAllMobileRenderables() {
  1132.         SurfaceCell[] cells = null;
  1133.         try {
  1134.             if (surfaceSorted == null) {
  1135.                 surfaceSorted = ReflectionUtil.getField(CellRenderer.class, "surfaceSorted");
  1136.                 surfaceSorted.setAccessible(true);
  1137.             }
  1138.             if (mobileRenderables == null) {
  1139.                 mobileRenderables = Cell.class.getDeclaredField("mobileRenderables");
  1140.                 mobileRenderables.setAccessible(true);
  1141.             }
  1142.             cells = ReflectionUtil.getPrivateField(world.getCellRenderer(), surfaceSorted);
  1143.         } catch (Exception e) {
  1144.             e.printStackTrace();
  1145.         }
  1146.         if (cells != null) {
  1147.             List<CellRenderable> rends = new LinkedList<>();
  1148.             for (SurfaceCell c : cells) {
  1149.                 try {
  1150.                     rends.addAll((Collection<? extends CellRenderable>) mobileRenderables.get(c));
  1151.                 } catch (Exception e) {
  1152.                     e.printStackTrace();
  1153.                 }
  1154.             }
  1155.             return rends;
  1156.         }
  1157.         return new LinkedList<>();
  1158.     }
  1159.  
  1160.     public static boolean readBoolean(final boolean original, final String[] data) {
  1161.         if (data.length == 1) {
  1162.             return original;
  1163.         }
  1164.         try {
  1165.             return Boolean.parseBoolean(data[1]);
  1166.         } catch (Exception e) {
  1167.             if (data[1].toLowerCase().equals("on")) {
  1168.                 return true;
  1169.             } else if (data[1].toLowerCase().equals("off")) {
  1170.                 return false;
  1171.             } else {
  1172.                 e.printStackTrace();
  1173.             }
  1174.         }
  1175.         return original;
  1176.     }
  1177.  
  1178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement