|
| 1 | +package com.zero.retrowrapper.hack; |
| 2 | + |
| 3 | +import java.awt.Dimension; |
| 4 | +import java.awt.event.ActionEvent; |
| 5 | +import java.awt.event.ActionListener; |
| 6 | +import java.lang.reflect.Field; |
| 7 | + |
| 8 | +import javax.swing.JButton; |
| 9 | +import javax.swing.JFrame; |
| 10 | +import javax.swing.JLabel; |
| 11 | +import javax.swing.JOptionPane; |
| 12 | +import javax.swing.JTextField; |
| 13 | +import javax.swing.UIManager; |
| 14 | +import javax.swing.WindowConstants; |
| 15 | + |
| 16 | +import com.zero.retrowrapper.emulator.EmulatorConfig; |
| 17 | +import com.zero.retrowrapper.injector.RetroTweakInjectorTarget; |
| 18 | + |
| 19 | +public class HackThread extends Thread implements Runnable |
| 20 | +{ |
| 21 | + public JFrame frame; |
| 22 | + public JLabel label; |
| 23 | + |
| 24 | + @Override |
| 25 | + public void run() |
| 26 | + { |
| 27 | + final RetroPlayer player = new RetroPlayer(this); |
| 28 | + |
| 29 | + try |
| 30 | + { |
| 31 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 32 | + }catch (Exception e) |
| 33 | + { |
| 34 | + e.printStackTrace(); |
| 35 | + } |
| 36 | + |
| 37 | + frame = new JFrame("Retrowrapper"); |
| 38 | + Dimension dim = new Dimension(654, 310); |
| 39 | + frame.setPreferredSize(dim); |
| 40 | + frame.setMinimumSize(dim); |
| 41 | + frame.setLayout(null); |
| 42 | + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
| 43 | + frame.setResizable(false); |
| 44 | + frame.setLocationRelativeTo(null); |
| 45 | + |
| 46 | + label = new JLabel("<html>Position:<br>   x: null<br>   y: null<br>   z: null</html>"); |
| 47 | + label.setBounds(30, 10, 500, 80); |
| 48 | + frame.add(label); |
| 49 | + |
| 50 | + JLabel xl = new JLabel("x:"); |
| 51 | + xl.setBounds(30, 103, 50, 20); |
| 52 | + frame.add(xl); |
| 53 | + |
| 54 | + JLabel yl = new JLabel("y:"); |
| 55 | + yl.setBounds(30, 135, 50, 20); |
| 56 | + frame.add(yl); |
| 57 | + |
| 58 | + JLabel zl = new JLabel("z:"); |
| 59 | + zl.setBounds(30, 167, 50, 20); |
| 60 | + frame.add(zl); |
| 61 | + |
| 62 | + final JTextField x = new JTextField(); |
| 63 | + x.setBounds(50, 100, 200, 30); |
| 64 | + frame.add(x); |
| 65 | + |
| 66 | + final JTextField y = new JTextField(); |
| 67 | + y.setBounds(50, 132, 200, 30); |
| 68 | + frame.add(y); |
| 69 | + |
| 70 | + final JTextField z = new JTextField(); |
| 71 | + z.setBounds(50, 164, 200, 30); |
| 72 | + frame.add(z); |
| 73 | + |
| 74 | + JButton b = new JButton("Teleport"); |
| 75 | + b.setBounds(50, 202, 200, 40); |
| 76 | + b.addActionListener(new ActionListener() |
| 77 | + { |
| 78 | + @Override |
| 79 | + public void actionPerformed(ActionEvent e) |
| 80 | + { |
| 81 | + try |
| 82 | + { |
| 83 | + float dx = Float.valueOf(x.getText().replaceAll(",", "").replaceAll(" ", "")); |
| 84 | + float dy = Float.valueOf(y.getText().replaceAll(",", "").replaceAll(" ", "")); |
| 85 | + float dz = Float.valueOf(z.getText().replaceAll(",", "").replaceAll(" ", "")); |
| 86 | + |
| 87 | + player.teleport(dx, dy, dz); |
| 88 | + }catch(Exception ee) |
| 89 | + { |
| 90 | + JOptionPane.showMessageDialog(null, "Exception occured!\n"+ee.getClass().getName()+"\n"+ee.getMessage()); |
| 91 | + } |
| 92 | + } |
| 93 | + }); |
| 94 | + frame.add(b); |
| 95 | + |
| 96 | + frame.setVisible(true); |
| 97 | + |
| 98 | + try |
| 99 | + { |
| 100 | + EmulatorConfig config = EmulatorConfig.getInstance(); |
| 101 | + |
| 102 | + config.minecraftField.setAccessible(true); |
| 103 | + player.minecraft = config.minecraftField.get(config.applet); |
| 104 | + |
| 105 | + Class<?> mcClass = getMostSuper(player.minecraft.getClass()); |
| 106 | + |
| 107 | + System.out.println("Minecraft class: "+mcClass.getName()); |
| 108 | + System.out.println("Mob class: "+config.mobClass); |
| 109 | + player.playerObj = null; |
| 110 | + Class<?> mobClass = RetroTweakInjectorTarget.getaClass(config.mobClass); |
| 111 | + |
| 112 | + while(player.playerObj == null) |
| 113 | + { |
| 114 | + for(Field f : mcClass.getDeclaredFields()) |
| 115 | + { |
| 116 | + if(mobClass.isAssignableFrom(f.getType()) || f.getType().equals(mobClass)) |
| 117 | + { |
| 118 | + player.playerField = f; |
| 119 | + player.playerObj = f.get(player.minecraft); |
| 120 | + break; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + Thread.sleep(1000); |
| 125 | + } |
| 126 | + |
| 127 | + System.out.println("Player class: "+player.playerObj.getClass().getName()); |
| 128 | + |
| 129 | + player.entityClass = getMostSuper(mobClass); |
| 130 | + |
| 131 | + System.out.println("Entity class: "+player.entityClass.getName()); |
| 132 | + |
| 133 | + player.setAABB(); |
| 134 | + |
| 135 | + if(player.aabb != null) |
| 136 | + { |
| 137 | + while(true) |
| 138 | + { |
| 139 | + player.tick(); |
| 140 | + Thread.sleep(100); |
| 141 | + } |
| 142 | + } |
| 143 | + }catch(Exception e) |
| 144 | + { |
| 145 | + e.printStackTrace(); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + private Class<?> getMostSuper(Class<?> mobClass) |
| 150 | + { |
| 151 | + while(true) |
| 152 | + { |
| 153 | + if(!mobClass.getSuperclass().equals(Object.class)) |
| 154 | + { |
| 155 | + mobClass = mobClass.getSuperclass(); |
| 156 | + }else |
| 157 | + { |
| 158 | + break; |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + return mobClass; |
| 163 | + } |
| 164 | +} |
0 commit comments