, April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.engine.mapper;
21 |
22 | import com.nur1popcorn.irrlicht.engine.wrappers.Wrapper;
23 |
24 | import java.lang.annotation.ElementType;
25 | import java.lang.annotation.Retention;
26 | import java.lang.annotation.RetentionPolicy;
27 | import java.lang.annotation.Target;
28 |
29 | /**
30 | * The {@link DiscoveryMethod} is responsible for telling the {@link Mapper} how a class/method/field
31 | * is supposed to be discovered. It does this by attaching additional information and the kinds of methods
32 | * that are supposed to be used to discover it.
33 | *
34 | * @see Wrapper
35 | * @see Mapper
36 | * @see DiscoveryHandler
37 | * @see WrapperDelegationHandler
38 | * @see java.lang.reflect.Modifier
39 | *
40 | * @author nur1popcorn
41 | * @since 1.0.0-alpha
42 | */
43 | @Target({
44 | ElementType.TYPE,
45 | ElementType.METHOD
46 | })
47 | @Retention(RetentionPolicy.RUNTIME)
48 | public @interface DiscoveryMethod
49 | {
50 | /**
51 | * The methods which are supposed to be used to discover the obfuscated class/method/field.
52 | *
53 | * @see Mapper
54 | *
55 | * @return the different kind of flags used to discover the class/method/field.
56 | */
57 | public int checks() default Mapper.DEFAULT;
58 |
59 | /**
60 | * @see Mapper
61 | * @see java.lang.reflect.Modifier
62 | *
63 | * @return The kind of modifiers attached to the method/field
64 | */
65 | public int modifiers() default -1;
66 |
67 | /**
68 | * The class declaring the class by extending it or declaring it as a field.
69 | *
70 | *
71 | * if the class declaring specified is {@link Wrapper} it will be ignored
72 | * otherwise the interface specified should extend {@link Wrapper}
73 | *
74 | *
75 | * @see Mapper
76 | *
77 | * @return the class declaring the class this is attached to.
78 | */
79 | public Class extends Wrapper> declaring() default Wrapper.class;
80 |
81 | /**
82 | * A set of class/method specific string constants.
83 | * Example:
84 | * minecraft:container
85 | *
86 | * @return a set of for the class/method unique string constants.
87 | */
88 | public String[] constants() default { };
89 |
90 | /**
91 | * A set of method specific opcodes:
92 | * Example:
93 | *
94 | *
95 | * aload0
96 | * getfield bew s
97 | * dconst_0
98 | * aload0
99 | * getfield bew u
100 | * invokespecial cj ((DDD)V);
101 | * invokevirtual adm e((Lcj;)Z);
102 | * ifne L3
103 | *
104 | *
105 | * @return a set of for the method unique opcodes.
106 | */
107 | public int[] opcodes() default { };
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/gui/components/Button.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.gui.components;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Arrays;
24 | import java.util.List;
25 |
26 | /**
27 | * The {@link Button} is a clickable {@link Component}.
28 | *
29 | * @see LockableComponent
30 | * @see Focusable
31 | * @see Observable
32 | * @see Observer
33 | *
34 | * @author nur1popcorn
35 | * @since 1.0.0-alpha
36 | */
37 | public class Button extends LockableComponent implements Focusable
38 | {
39 | private List listeners = new ArrayList<>();
40 |
41 | private String text;
42 |
43 | public Button(String text, int width, int height, ButtonListener... listeners)
44 | {
45 | super(width, height);
46 | this.text = text;
47 | addListener(listeners);
48 | }
49 |
50 | public Button(String text, ButtonListener... listeners)
51 | {
52 | this(text, 35, 9, listeners);
53 | }
54 |
55 | public Button(ButtonListener... listeners)
56 | {
57 | this("", listeners);
58 | }
59 |
60 | /**
61 | * @return the {@link Button}'s text.
62 | */
63 | public String getText()
64 | {
65 | return text;
66 | }
67 |
68 | /**
69 | * Sets the {@link Button}'s text.
70 | *
71 | * @param text the {@link Button}'s text.
72 | */
73 | public void setText(String text)
74 | {
75 | this.text = text;
76 | }
77 |
78 | /**
79 | * Adds {@link ButtonListener} to the {@link Button}.
80 | *
81 | * @param listeners the {@link ButtonListener}s to be added to the {@link Button}.
82 | */
83 | public void addListener(ButtonListener... listeners)
84 | {
85 | this.listeners.addAll(Arrays.asList(listeners));
86 | }
87 |
88 | /**
89 | * Removes {@link ButtonListener}s from {@link Button}.
90 | *
91 | * @param listeners the {@link ButtonListener} to be removed from the {@link Button}.
92 | */
93 | public void removeListener(ButtonListener... listeners)
94 | {
95 | this.listeners.addAll(Arrays.asList(listeners));
96 | }
97 |
98 | /**
99 | * Removes all {@link ButtonListener}s from {@link Button}.
100 | */
101 | public void clear()
102 | {
103 | listeners.clear();
104 | }
105 |
106 | /**
107 | * Calls all {@link ButtonListener}.
108 | */
109 | public void click()
110 | {
111 | listeners.forEach(listener -> listener.call(this));
112 | }
113 |
114 | /**
115 | * Can be attached to {@link Button}s inorder to overhear the {@link Button}'s clicks.
116 | */
117 | public interface ButtonListener
118 | {
119 | /**
120 | * Called when the {@link Button} is clicked.
121 | */
122 | public void call(T button);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/engine/wrappers/client/Minecraft.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.engine.wrappers.client;
21 |
22 | import com.nur1popcorn.irrlicht.engine.mapper.DiscoveryMethod;
23 | import com.nur1popcorn.irrlicht.engine.mapper.Mapper;
24 | import com.nur1popcorn.irrlicht.engine.wrappers.Wrapper;
25 | import com.nur1popcorn.irrlicht.engine.wrappers.client.entity.PlayerSp;
26 | import com.nur1popcorn.irrlicht.engine.wrappers.client.gui.GuiIngame;
27 | import com.nur1popcorn.irrlicht.engine.wrappers.client.gui.GuiScreen;
28 | import com.nur1popcorn.irrlicht.engine.wrappers.client.minecraft.Timer;
29 | import com.nur1popcorn.irrlicht.engine.wrappers.client.renderer.EntityRenderer;
30 | import com.nur1popcorn.irrlicht.engine.wrappers.client.settings.GameSettings;
31 | import com.nur1popcorn.irrlicht.engine.wrappers.world.WorldClient;
32 |
33 | import java.lang.reflect.Modifier;
34 |
35 | /**
36 | * The {@link Minecraft} class is storing most of the useful variables it's the main
37 | * of the game.
38 | *
39 | * @see Wrapper
40 | * @see PlayerSp
41 | * @see Timer
42 | * @see GameSettings
43 | * @see GuiIngame
44 | * @see GuiScreen
45 | *
46 | * @author nur1popcorn
47 | * @since 1.0.0-alpha
48 | */
49 | @DiscoveryMethod(checks = Mapper.CUSTOM)
50 | public interface Minecraft extends Wrapper
51 | {
52 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
53 | public PlayerSp getPlayer();
54 |
55 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
56 | public Timer getTimer();
57 |
58 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
59 | public Timer setTimer(Timer timer);
60 |
61 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
62 | public GameSettings getGameSettings();
63 |
64 | @DiscoveryMethod(checks = Mapper.CUSTOM | Mapper.FIELD)
65 | public int getLeftClickDelay();
66 |
67 | @DiscoveryMethod(checks = Mapper.CUSTOM | Mapper.FIELD)
68 | public void setLeftClickDelay(int delay);
69 |
70 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
71 | public GuiIngame getIngameGui();
72 |
73 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
74 | public GuiScreen getGuiScreen();
75 |
76 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
77 | public WorldClient getWorld();
78 |
79 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.FIELD)
80 | public EntityRenderer getEntityRenderer();
81 |
82 | @DiscoveryMethod(modifiers = Modifier.PUBLIC | Modifier.STATIC)
83 | public Minecraft getMinecraft();
84 |
85 | public void displayGuiScreen(GuiScreen guiScreen);
86 |
87 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.STRING_CONST,
88 | constants = "Null returned as \'hitResult\', this shouldn't happen!")
89 | public void clickMouse();
90 |
91 | @DiscoveryMethod(checks = Mapper.DEFAULT | Mapper.STRING_CONST,
92 | constants = "Ticking screen")
93 | public void tick();
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/Agent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht;
21 |
22 | import com.nur1popcorn.irrlicht.engine.exceptions.MappingException;
23 | import com.nur1popcorn.irrlicht.engine.hooker.Hooker;
24 | import com.nur1popcorn.irrlicht.engine.mapper.Mapper;
25 | import com.nur1popcorn.irrlicht.engine.wrappers.Wrapper;
26 | import com.nur1popcorn.irrlicht.management.GameConfig;
27 | import com.nur1popcorn.irrlicht.utils.LoggerFactory;
28 |
29 | import java.lang.instrument.Instrumentation;
30 | import java.lang.reflect.Method;
31 | import java.util.Arrays;
32 | import java.util.HashMap;
33 | import java.util.Map;
34 | import java.util.logging.Level;
35 | import java.util.logging.Logger;
36 |
37 | /**
38 | * The {@link Agent} is the agent's entry point.
39 | *
40 | * @see Mapper
41 | * @see Hooker
42 | * @see Irrlicht
43 | *
44 | * @author nur1popcorn
45 | * @since 1.0.0-alpha
46 | */
47 | public class Agent
48 | {
49 | private static final Logger LOGGER = LoggerFactory.getLogger(Agent.class);
50 |
51 | public static void premain(String args, Instrumentation instrumentation)
52 | {
53 | agentmain(args, instrumentation);
54 | }
55 |
56 | public static void agentmain(String args, Instrumentation instrumentation)
57 | {
58 | final Map agentParameters = new HashMap<>();
59 | for(String s : args.split(","))
60 | {
61 | final String[] values = s.split("=");
62 | if(values.length >= 2)
63 | agentParameters.put(values[0], Arrays.copyOfRange(values, 1, values.length));
64 | }
65 |
66 | try
67 | {
68 | Irrlicht.bootstrap(
69 | new GameConfig(
70 | agentParameters.get("version")[0],
71 | agentParameters.get("gameDir")[0],
72 | agentParameters.get("assetsDir")[0],
73 | agentParameters.get("main")[0]
74 | )
75 | );
76 | Mapper.getInstance()
77 | .generate();
78 | Hooker.createHooker()
79 | .hook(instrumentation);
80 | }
81 | catch (MappingException e)
82 | {
83 | // TODO: Better error handling
84 | LOGGER.log(Level.SEVERE, "");
85 | for(Class extends Wrapper> wrapper : e.getWrappers())
86 | {
87 | LOGGER.log(Level.SEVERE, wrapper.toString());
88 | for(Method method : wrapper.getDeclaredMethods())
89 | if (Mapper.getInstance().getMappedMethod(method) == null)
90 | LOGGER.log(Level.SEVERE, method.toString());
91 | }
92 | LOGGER.log(Level.SEVERE, "", e);
93 | }
94 | catch (ClassNotFoundException e)
95 | {
96 | LOGGER.log(Level.SEVERE, "Got an exception.", e);
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/resources/launcher.css:
--------------------------------------------------------------------------------
1 | .window-border {
2 | -fx-background-color: #1b1b1b;
3 | }
4 |
5 | .window-border .label {
6 | -fx-font: 12px Helvetica;
7 | -fx-text-fill: #b4b4b4;
8 | }
9 |
10 | .window-border .button {
11 | -fx-background-color: #1b1b1b;
12 | -fx-border-color: #1b1b1b;
13 | }
14 |
15 | .root-element,
16 | .log-output {
17 | -fx-background-color: #202020;
18 | -fx-border-color: linear-gradient(transparent, #32739B);
19 | -fx-border-width: 1;
20 | }
21 |
22 | .log-output-container,
23 | log-output {
24 | -fx-border-color: linear-gradient(transparent, #32739B);
25 | -fx-border-width: 1;
26 | }
27 |
28 | .scroll-bar:horizontal .thumb {
29 | -fx-background-color: #101010,
30 | linear-gradient(to bottom, #404040, #323232),
31 | linear-gradient(to bottom, #404040, #323232);
32 | -fx-border-radius: 3 3 3 3;
33 | }
34 |
35 | .scroll-bar:vertical .thumb {
36 | -fx-background-color: #101010,
37 | linear-gradient(to right, #404040, #323232),
38 | linear-gradient(to right, #404040, #323232);
39 | -fx-border-radius: 3 3 3 3;
40 | }
41 |
42 | .scroll-bar,
43 | .track,
44 | .increment-button,
45 | .decrement-button,
46 | .corner {
47 | -fx-background-color: #202020;
48 | -fx-border-color: #202020;
49 | }
50 |
51 | .log-output .list-cell:odd {
52 | -fx-background-color: #1f1f1f;
53 | }
54 |
55 | .log-output .list-cell:even {
56 | -fx-background-color: #202020;
57 | }
58 |
59 | .log-output .list-cell:filled:hover {
60 | -fx-background-color: #252525;
61 | }
62 |
63 | .log-output .list-cell:info {
64 | -fx-text-fill: #b4b4b4;
65 | }
66 |
67 | .log-output .list-cell:warning {
68 | -fx-text-fill: yellow;
69 | }
70 |
71 | .log-output .list-cell:severe {
72 | -fx-text-fill: red;
73 | }
74 |
75 | .button,
76 | .toggle-button,
77 | .combo-box,
78 | .text-field {
79 | -fx-background-color: linear-gradient(#404040, #323232);
80 | -fx-border-color: #101010;
81 | -fx-border-radius: 3 3 3 3;
82 | -fx-text-fill: #dcdcdc;
83 | -fx-font-family: "Helvetica";
84 | }
85 |
86 | .button .text,
87 | .toggle-button .text,
88 | .combo-box .text,
89 | .label {
90 | -fx-effect: dropshadow(gaussian, #101010, 0, 0, 0, 1);
91 | -fx-text-fill: white;
92 | -fx-fill: white;
93 | }
94 |
95 | .button:hover,
96 | .toggle-button:hover {
97 | -fx-background-color: linear-gradient(#505050, #424242);
98 | }
99 |
100 | .button:pressed,
101 | .toggle-button:pressed {
102 | -fx-background-color: linear-gradient(#303030, #222222);
103 | }
104 |
105 | .toggle-button:selected {
106 | -fx-background-color: linear-gradient(#545454, #424242);
107 | }
108 |
109 | .combo-box .list-view {
110 | -fx-background-color: #222222;
111 | }
112 |
113 | .combo-box .list-view .list-cell {
114 | -fx-background-color: #323232;
115 | }
116 |
117 | .combo-box .list-view .list-cell:hover {
118 | -fx-background-color: #424242;
119 | }
120 |
121 | .performance-charts {
122 | -fx-background-color: #1d1d1d;
123 | }
124 |
125 | .chart-plot-background {
126 | -fx-background-color: #1b1b1b;
127 | }
128 |
129 | .chart-type-label {
130 | -fx-text-fill: #c9c9c9;
131 | }
132 |
133 | .chart-series-area-line {
134 | -fx-stroke: #6ed0e0;
135 | -fx-stroke-width: 2px;
136 | }
137 |
138 | .chart-series-area-fill {
139 | -fx-fill: linear-gradient(to top, #41493b88, #41493b49);
140 | }
141 |
142 | .axis {
143 | -fx-border-color: transparent;
144 | }
145 |
146 | .chart-vertical-grid-lines,
147 | .chart-horizontal-grid-lines,
148 | .chart-vertical-zero-line,
149 | .chart-horizontal-zero-line {
150 | -fx-stroke: transparent;
151 | }
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/engine/mapper/WrapperBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.engine.mapper;
21 |
22 | import com.nur1popcorn.irrlicht.engine.wrappers.Wrapper;
23 | import com.nur1popcorn.irrlicht.engine.wrappers.client.gui.GuiScreen;
24 | import com.nur1popcorn.irrlicht.utils.LoggerFactory;
25 | import javassist.util.proxy.MethodHandler;
26 | import javassist.util.proxy.ProxyFactory;
27 |
28 | import java.lang.reflect.InvocationTargetException;
29 | import java.lang.reflect.Method;
30 | import java.util.HashMap;
31 | import java.util.Map;
32 | import java.util.logging.Level;
33 | import java.util.logging.Logger;
34 |
35 | /**
36 | * The {@link WrapperBridge} is responsible for redirecting method calls to an obfuscated
37 | * class to the implementation of the {@link Wrapper} it's mapped to.
38 | *
39 | * @see ProxyFactory
40 | * @see Mapper
41 | * @see Wrapper
42 | *
43 | * @author nur1popcorn
44 | * @since 1.1.0-alpha
45 | */
46 | public abstract class WrapperBridge implements Wrapper
47 | {
48 | private Object handle;
49 | private final Class extends Wrapper> clazz;
50 |
51 | public WrapperBridge(Class extends Wrapper> clazz)
52 | {
53 | this.clazz = clazz;
54 | }
55 |
56 | @Override
57 | public final Object getHandle()
58 | {
59 | if(handle != null)
60 | return handle;
61 | final ProxyFactory proxyFactory = new ProxyFactory();
62 | final Mapper mapper = Mapper.getInstance();
63 | proxyFactory.setSuperclass(mapper.getMappedClass(clazz));
64 | try
65 | {
66 | return handle = proxyFactory.create(null, null, new MethodHandler() {
67 | final Map methodMap = new HashMap<>();
68 | {
69 | for(Method method : clazz.getDeclaredMethods())
70 | methodMap.put(mapper.getMappedMethod(method), method);
71 | }
72 |
73 | @Override
74 | public Object invoke(Object proxy, Method thisMethod, Method proceed, Object[] args) throws Throwable
75 | {
76 | final Method method = methodMap.get(thisMethod);
77 | if(method != null)
78 | {
79 | final Class types[] = method.getParameterTypes();
80 | final Object handledArgs[] = new Object[args.length];
81 | for(int i = 0; i < args.length; i++)
82 | handledArgs[i] = Wrapper.class.isAssignableFrom(types[i]) ?
83 | WrapperDelegationHandler.createWrapperProxy((Class extends Wrapper>)types[i], args[i]) :
84 | args[i];
85 | return method.invoke(this, handledArgs);
86 | }
87 | return null;
88 | }
89 | });
90 | }
91 | catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e)
92 | {
93 | e.printStackTrace();
94 | throw new RuntimeException("Failed to create WrapperBridge.");
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/modules/Module.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.modules;
21 |
22 | import com.nur1popcorn.irrlicht.engine.events.EventManager;
23 | import com.nur1popcorn.irrlicht.management.values.Value;
24 | import com.nur1popcorn.irrlicht.management.values.ValueTarget;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 | import java.util.stream.Stream;
29 |
30 | /**
31 | * The {@link Module} is a cheat that can be enabled.
32 | *
33 | * @see Category
34 | * @see Value
35 | * @see ValueTarget
36 | * @see EventManager
37 | *
38 | * @author nur1popcorn
39 | * @since 1.0.0-alpha
40 | */
41 | public abstract class Module
42 | {
43 | private final String name = getClass().getAnnotation(ModuleInfo.class).name();
44 | private final Category category = getClass().getAnnotation(ModuleInfo.class).category();
45 | private final List values = new ArrayList<>();
46 | private boolean toggled;
47 |
48 | /**
49 | * @see Value
50 | * @see ValueTarget
51 | *
52 | * Obtains all of the {@link Module}'s {@link Value}s if they have a
53 | * {@link ValueTarget} annotaion attached to them.
54 | */
55 | public final void init()
56 | {
57 | Stream.of(getClass().getDeclaredFields()).forEach(field -> {
58 | if(field.getAnnotationsByType(ValueTarget.class) != null &&
59 | Value.class.isAssignableFrom(field.getType()))
60 | try
61 | {
62 | field.setAccessible(true);
63 | values.add((Value) field.get(this));
64 | }
65 | catch (IllegalAccessException e)
66 | {
67 | e.printStackTrace();
68 | }
69 | });
70 | }
71 |
72 | /**
73 | * @see EventManager
74 | *
75 | * Called when the {@link Module} is toggled.
76 | */
77 | public void onEnable()
78 | {
79 | EventManager.register(this);
80 | }
81 |
82 | /**
83 | * @see EventManager
84 | *
85 | * Called when the {@link Module} is toggled off.
86 | */
87 | public void onDisable()
88 | {
89 | EventManager.unregister(this);
90 | }
91 |
92 | /**
93 | * Toggles the {@link Module} on or off.
94 | */
95 | public void toggle()
96 | {
97 | if(toggled = !toggled)
98 | onEnable();
99 | else
100 | onDisable();
101 | }
102 |
103 | /**
104 | * @return whether or not the {@link Module} is toggled.
105 | */
106 | public boolean isToggled()
107 | {
108 | return toggled;
109 | }
110 |
111 | /**
112 | * @return the {@link Module}'s name.
113 | */
114 | public String getName()
115 | {
116 | return name;
117 | }
118 |
119 | /**
120 | * @see Category
121 | *
122 | * @return the {@link Module}'s {@link Category}.
123 | */
124 | public Category getCategory()
125 | {
126 | return category;
127 | }
128 |
129 | /**
130 | * @see Value
131 | *
132 | * @return the {@link Module}'s settings.
133 | */
134 | public List getValues()
135 | {
136 | return values;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/gui/components/containers/Frame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.gui.components.containers;
21 |
22 | import com.nur1popcorn.irrlicht.gui.components.Component;
23 | import com.nur1popcorn.irrlicht.gui.components.Focusable;
24 | import com.nur1popcorn.irrlicht.gui.components.containers.Container;
25 |
26 | /**
27 | * The {@link Frame} is a movable {@link Container}.
28 | *
29 | * @see Container
30 | * @see Component
31 | * @see Focusable
32 | *
33 | * @author nur1popcorn
34 | * @since 1.0.0-alpha
35 | */
36 | public class Frame extends Container implements Focusable
37 | {
38 | private String title;
39 | private float dragX,
40 | dragY;
41 |
42 | private boolean draggable,
43 | dragging;
44 |
45 | public Frame(String title)
46 | {
47 | this.title = title;
48 | }
49 |
50 | public Frame(String title, int x, int y, int width, int height, Component... components)
51 | {
52 | super(components);
53 | this.title = title;
54 | prefX = x;
55 | prefY = y;
56 | prefWidth = width;
57 | prefHeight = height;
58 | }
59 | /**
60 | * Sets the {@link Frame}'s title.
61 | *
62 | * @param title the {@link Frame}'s title.
63 | */
64 | public void setTitle(String title)
65 | {
66 | this.title = title;
67 | }
68 |
69 | /**
70 | * @return the {@link Frame}'s title.
71 | */
72 | public String getTitle()
73 | {
74 | return title;
75 | }
76 |
77 | /**
78 | * Sets x offset for the {@link Frame} when being dragged.
79 | *
80 | * @param dragX the x offset for the {@link Frame} when being dragged.
81 | */
82 | public void setDragX(float dragX)
83 | {
84 | this.dragX = dragX;
85 | }
86 |
87 | /**
88 | * Sets y offset for {@link Frame} when being dragged.
89 | *
90 | * @param dragY the y offset for the {@link Frame} when being dragged.
91 | */
92 | public void setDragY(float dragY)
93 | {
94 | this.dragY = dragY;
95 | }
96 |
97 | /**
98 | * @return the x offset for the {@link Frame} when being dragged.
99 | */
100 | public float getDragX()
101 | {
102 | return dragX;
103 | }
104 |
105 | /**
106 | * @return the y offset for the {@link Frame} when being dragged.
107 | */
108 | public float getDragY()
109 | {
110 | return dragY;
111 | }
112 |
113 | /**
114 | * Sets whether or not the {@link Frame} is draggable.
115 | *
116 | * @param draggable whether or not the {@link Frame} is draggable.
117 | */
118 | public void setDraggable(boolean draggable)
119 | {
120 | this.draggable = draggable;
121 | }
122 |
123 | /**
124 | * @return whether or not the {@link Frame} is draggable.
125 | */
126 | public boolean isDraggable()
127 | {
128 | return draggable;
129 | }
130 |
131 | /**
132 | * Sets whether or not the {@link Frame} is currently being dragged.
133 | *
134 | * @param dragging whether or not the {@link Frame} is currently being dragged.
135 | */
136 | public void setDragging(boolean dragging)
137 | {
138 | this.dragging = dragging;
139 | }
140 |
141 | /**
142 | * @return whether or not the {@link Frame} is currently being dragged.
143 | */
144 | public boolean isDragging()
145 | {
146 | return dragging;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/gui/GuiScreenBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.gui;
21 |
22 | import com.nur1popcorn.irrlicht.Irrlicht;
23 | import com.nur1popcorn.irrlicht.engine.mapper.WrapperBridge;
24 | import com.nur1popcorn.irrlicht.engine.wrappers.client.Minecraft;
25 | import com.nur1popcorn.irrlicht.engine.wrappers.client.gui.GuiScreen;
26 | import org.lwjgl.input.Keyboard;
27 | import org.lwjgl.input.Mouse;
28 | import org.lwjgl.opengl.Display;
29 |
30 | /**
31 | * The {@link GuiScreenBridge} is a class used to emulate {@link GuiScreen}s.
32 | *
33 | * @see WrapperBridge
34 | * @see GuiScreen
35 | *
36 | * @author nur1popcorn
37 | * @since 1.1.0-alpha
38 | */
39 | public class GuiScreenBridge extends WrapperBridge implements GuiScreen
40 | {
41 | protected int width,
42 | height;
43 |
44 | public GuiScreenBridge()
45 | {
46 | super(GuiScreen.class);
47 | }
48 |
49 | @Override
50 | public final void handleInput()
51 | {
52 | if(Mouse.isCreated())
53 | while(Mouse.next())
54 | {
55 | final int x = Mouse.getEventX() * width / Display.getWidth(),
56 | y = height - Mouse.getEventY() * height / Display.getHeight() - 1,
57 | button = Mouse.getEventButton();
58 | if(Mouse.getEventButtonState())
59 | mouseClicked(x, y, button);
60 | else if(button != -1)
61 | mouseReleased(x, y, button);
62 | }
63 |
64 | if(Keyboard.isCreated())
65 | while(Keyboard.next())
66 | if(Keyboard.getEventKeyState())
67 | keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
68 | }
69 |
70 | /**
71 | * Called when any mouse button is clicked.
72 | *
73 | * @param mouseX the x position of the mouse.
74 | * @param mouseY the y position of the mouse.
75 | * @param mouseButton the mouse button clicked.
76 | *
77 | * @see GuiScreen
78 | */
79 | public void mouseClicked(int mouseX, int mouseY, int mouseButton)
80 | {}
81 |
82 | /**
83 | * Called when any mouse button is released.
84 | *
85 | * @param mouseX the x position of the mouse.
86 | * @param mouseY the y position of the mouse.
87 | * @param mouseButton the mouse button released.
88 | *
89 | * @see GuiScreen
90 | */
91 | public void mouseReleased(int mouseX, int mouseY, int mouseButton)
92 | {}
93 |
94 | /**
95 | * Called when any key is pressed.
96 | *
97 | * @param typedChar the character which was typed.
98 | * @param keyCode the keycode of the key which was pressed.
99 | *
100 | * @see GuiScreen
101 | */
102 | public void keyTyped(char typedChar, int keyCode)
103 | {
104 | if(keyCode == Keyboard.KEY_ESCAPE)
105 | Irrlicht.getMinecraft()
106 | .displayGuiScreen(null);
107 | }
108 |
109 | @Override
110 | public void initGui(Minecraft minecraft, int width, int height)
111 | {
112 | Keyboard.enableRepeatEvents(true);
113 | this.width = width;
114 | this.height = height;
115 | }
116 |
117 | @Override
118 | public void resize(Minecraft minecraft, int width, int height)
119 | {
120 | initGui(minecraft, width, height);
121 | }
122 |
123 | @Override
124 | public boolean shouldPauseGame()
125 | {
126 | return false;
127 | }
128 |
129 | @Override
130 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
131 | {}
132 |
133 | @Override
134 | public void onUpdate()
135 | {}
136 |
137 | @Override
138 | public void onClose()
139 | {}
140 | }
141 |
--------------------------------------------------------------------------------
/src/main/java/com/nur1popcorn/irrlicht/engine/mapper/WrapperDelegationHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Keanu Poeschko - All Rights Reserved
3 | * Unauthorized copying of this file is strictly prohibited
4 | *
5 | * Created by Keanu Poeschko , April 2017
6 | * This file is part of {Irrlicht}.
7 | *
8 | * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko}
9 | *
10 | * Permission to use, copy, modify, and distribute my software for
11 | * educational, and research purposes, without a signed licensing agreement
12 | * and for free, is hereby granted, provided that the above copyright notice
13 | * and this paragraph appear in all copies, modifications, and distributions.
14 | *
15 | *
16 | *
17 | *
18 | */
19 |
20 | package com.nur1popcorn.irrlicht.engine.mapper;
21 |
22 | import com.nur1popcorn.irrlicht.engine.wrappers.Wrapper;
23 |
24 | import java.lang.reflect.*;
25 | import java.util.stream.Stream;
26 |
27 | /**
28 | * The {@link WrapperDelegationHandler} is responsible for redirecting the {@link Wrapper}'s method
29 | * calls to the {@link Mapper}'s mapped methods.
30 | *
31 | * @see Mapper
32 | * @see Wrapper
33 | * @see Proxy
34 | * @see InvocationHandler
35 | *
36 | * @author nur1popcorn
37 | * @since 1.0.0-alpha
38 | */
39 | public class WrapperDelegationHandler implements InvocationHandler
40 | {
41 | private final Object handle;
42 |
43 | //prevent construction :/
44 | private WrapperDelegationHandler(Object handle)
45 | {
46 | this.handle = handle;
47 | }
48 |
49 | /**
50 | * Creates a new instance of a {@link Wrapper} using the handle provided.
51 | *
52 | * @param wrapper the {@link Wrapper} of which an instance is supposed to be created.
53 | * @param handle the to which the method calls etc. will be redirected.
54 | *
55 | * @return an instance of the {@link Wrapper}.
56 | */
57 | public static T createWrapperProxy(Class wrapper, Object handle)
58 | {
59 | return wrapper.cast(Proxy.newProxyInstance(WrapperDelegationHandler.class.getClassLoader(), new Class[] { wrapper }, new WrapperDelegationHandler(handle)));
60 | }
61 |
62 | @Override
63 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
64 | {
65 | if(Wrapper.class.getDeclaredMethods()[0].equals(method))
66 | return handle;
67 |
68 | final Mapper mapper = Mapper.getInstance();
69 | final Method obfMethod = mapper.getMappedMethod(method);
70 |
71 | final Object argsHandles[] = args != null ?
72 | Stream.of(args)
73 | .map(arg -> arg instanceof Wrapper ? ((Wrapper) arg).getHandle() : arg)
74 | .toArray() :
75 | null;
76 |
77 | if(obfMethod != null)
78 | {
79 | obfMethod.setAccessible(true);
80 | return convertToType(obfMethod.invoke(handle, argsHandles), method.getReturnType());
81 | }
82 |
83 | final Field field = mapper.getMappedField(method);
84 | if(field != null)
85 | {
86 | field.setAccessible(true);
87 | if(method.getReturnType() == void.class)
88 | {
89 | field.set(handle, argsHandles[0]);
90 | return null;
91 | }
92 | return convertToType(field.get(handle), method.getReturnType());
93 | }
94 |
95 | final Constructor constructor = mapper.getMappedConstructor(method);
96 | if(constructor != null)
97 | {
98 | constructor.setAccessible(true);
99 | return convertToType(constructor.newInstance(argsHandles), method.getReturnType());
100 | }
101 |
102 | return method.invoke(handle, args);
103 | }
104 |
105 | /**
106 | * A helper method for checking if the given object is a {@link Wrapper} and returning a
107 | * wrapped version of it if so.
108 | *
109 | * @param object the object supposed to be wrapped.
110 | * @param type the type the object is supposed to be converted to.
111 | *
112 | * @see #invoke(Object, Method, Object[])
113 | *
114 | * @return a wrapped version of the object provided.
115 | */
116 | private Object convertToType(Object object, Class type)
117 | {
118 | return Wrapper.class.isAssignableFrom(type) ?
119 | createWrapperProxy((Class extends Wrapper>)type, object) :
120 | object;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------