Skip to content

Commit df2616c

Browse files
committed
1.3: singleplayer hacks
disabled by default
1 parent e1f7bcc commit df2616c

File tree

9 files changed

+373
-19
lines changed

9 files changed

+373
-19
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Download latest version from releases and launch it.
1717

1818
Select version you want to wrap and click 'Install'
1919

20+
**SINGLEPLAYER HACKS**
21+
22+
- Teleport hack (useful for checking farlands!)
23+
24+
Works all the way from 0.27 to Release 1.0, havent tested other versions but propably it works too.
25+
26+
You need to add -Dretrowrapper.hack=true to Java arguments in your launcher.
27+
2028
**HOW TO USE (manual)**
2129

2230
Download retrowrapper-1.2.jar from releases.

src/com/zero/retrowrapper/emulator/EmulatorConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package com.zero.retrowrapper.emulator;
22

3+
import java.applet.Applet;
4+
import java.lang.reflect.Field;
35
import java.util.Random;
46

57
public class EmulatorConfig
68
{
79
private static EmulatorConfig instance;
810

11+
public Field minecraftField;
12+
public Applet applet;
13+
914
private int port;
15+
16+
public String mobClass;
1017

1118
public EmulatorConfig()
1219
{
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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>&nbsp&nbsp&nbsp;x: null<br>&nbsp&nbsp&nbsp;y: null<br>&nbsp&nbsp&nbsp;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+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package com.zero.retrowrapper.hack;
2+
3+
import java.lang.reflect.Field;
4+
import java.lang.reflect.Modifier;
5+
6+
public class RetroPlayer
7+
{
8+
public Field x, y, z, x2, y2, z2;
9+
public double ax, ay, az;
10+
public Object aabb;
11+
public Class<?> entityClass;
12+
public Object playerObj;
13+
14+
public HackThread thread;
15+
public Field playerField;
16+
public Object minecraft;
17+
private boolean modeFloat;
18+
19+
public RetroPlayer(HackThread thread)
20+
{
21+
this.thread = thread;
22+
}
23+
24+
public void tick() throws IllegalArgumentException, IllegalAccessException, InterruptedException
25+
{
26+
try
27+
{
28+
playerObj = playerField.get(minecraft);
29+
if(playerObj != null)
30+
{
31+
setAABB();
32+
ax = getVariable(x2, aabb) - getX();
33+
ay = getVariable(y2, aabb) - getY();
34+
az = getVariable(z2, aabb) - getZ();
35+
thread.label.setText("<html>Position:<br>&nbsp&nbsp&nbsp;x: "+Math.floor(getX()*10)/10+"<br>&nbsp&nbsp&nbsp;y: "+Math.floor(getY()*10)/10+"<br>&nbsp&nbsp&nbsp;z: "+Math.floor(getZ()*10)/10+"</html>");
36+
}
37+
}catch(Exception e)
38+
{
39+
e.printStackTrace();
40+
Thread.sleep(1000);
41+
}
42+
}
43+
44+
public void setAABB() throws IllegalArgumentException, IllegalAccessException
45+
{
46+
boolean flag2 = false;
47+
48+
for(Field f : entityClass.getDeclaredFields())
49+
{
50+
if(!flag2)
51+
{
52+
if(f.getType().getName().equals("float"))
53+
{
54+
flag2 = true;
55+
}
56+
}else
57+
{
58+
if(!f.getType().isPrimitive())
59+
{
60+
aabb = f.get(playerObj);
61+
break;
62+
}
63+
}
64+
}
65+
66+
if(aabb != null)
67+
{
68+
int doubleCount = 0;
69+
70+
label:
71+
for(Field f : aabb.getClass().getDeclaredFields())
72+
{
73+
if(Modifier.isPublic(f.getModifiers()) && (f.getType().getName().equals("double") || f.getType().getName().equals("float")))
74+
{
75+
if(f.getType().getName().equals("float"))
76+
{
77+
modeFloat = true;
78+
}
79+
switch(doubleCount)
80+
{
81+
case 0:
82+
x = f;
83+
break;
84+
case 1:
85+
y = f;
86+
break;
87+
case 2:
88+
z = f;
89+
break;
90+
case 3:
91+
x2 = f;
92+
break;
93+
case 4:
94+
y2 = f;
95+
break;
96+
case 5:
97+
z2 = f;
98+
break;
99+
default:
100+
break label;
101+
}
102+
doubleCount++;
103+
}
104+
}
105+
}
106+
}
107+
108+
private double getX() throws IllegalArgumentException, IllegalAccessException
109+
{
110+
return getVariable(x, aabb);
111+
}
112+
113+
private double getY() throws IllegalArgumentException, IllegalAccessException
114+
{
115+
return getVariable(y, aabb);
116+
}
117+
118+
private double getZ() throws IllegalArgumentException, IllegalAccessException
119+
{
120+
return getVariable(z, aabb);
121+
}
122+
123+
private double getVariable(Field f, Object o) throws IllegalArgumentException, IllegalAccessException
124+
{
125+
if(modeFloat)
126+
{
127+
return ((Float)f.getFloat(o)).doubleValue();
128+
}else
129+
{
130+
return f.getDouble(o);
131+
}
132+
}
133+
134+
public void teleport(double dx, double dy, double dz) throws IllegalArgumentException, IllegalAccessException
135+
{
136+
if(modeFloat)
137+
{
138+
x.set(aabb, (float)dx);
139+
y.set(aabb, (float)dy);
140+
z.set(aabb, (float)dz);
141+
x2.set(aabb, (float)(dx+ax));
142+
y2.set(aabb, (float)(dy+ay));
143+
z2.set(aabb, (float)(dz+az));
144+
}else
145+
{
146+
x.set(aabb, dx);
147+
y.set(aabb, dy);
148+
z.set(aabb, dz);
149+
x2.set(aabb, dx+ax);
150+
y2.set(aabb, dy+ay);
151+
z2.set(aabb, dz+az);
152+
}
153+
}
154+
}

src/com/zero/retrowrapper/injector/LauncherFake.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public LauncherFake(Map<String, String> params, Applet applet)
1919
{
2020
this.params = params;
2121
}
22-
22+
2323
@Override
2424
public void appletResize(int width, int height) {}
2525

0 commit comments

Comments
 (0)