Commit d3ec7c4945e5c6644d2f927cab83a992646f813d
1 parent
2fbe188c
updating MCPBot Mappings, additional javadoc, minor refactoring of JSON transformer defs
Showing
9 changed files
with
328 additions
and
76 deletions
debug/obfuscation.properties
| 1 | field_71424_I=mcProfiler | 1 | field_71424_I=mcProfiler |
| 2 | field_78729_o=entityRenderMap field_110546_b=reloadListeners | 2 | field_78729_o=entityRenderMap field_110546_b=reloadListeners |
| 3 | field_147393_d=networkManager | 3 | field_147393_d=networkManager |
| 4 | -field_82596_a=registryObjects field_148759_a=underlyingIntegerMap #field_148749_a= | ||
| 5 | -#field_148748_b= field_147559_m=mapSpecialRenderers | 4 | +field_82596_a=registryObjects field_148759_a=underlyingIntegerMap field_148749_a=identityMap |
| 5 | +field_148748_b=objectList field_147559_m=mapSpecialRenderers | ||
| 6 | field_145855_i=nameToClassMap | 6 | field_145855_i=nameToClassMap |
| 7 | field_145853_j=classToNameMap func_148833_a=processPacket func_71411_J=runGameLoop func_71407_l=runTick func_78480_b=updateCameraAndRender | 7 | field_145853_j=classToNameMap func_148833_a=processPacket func_71411_J=runGameLoop func_71407_l=runTick func_78480_b=updateCameraAndRender |
| 8 | func_78471_a=renderWorld func_175180_a=renderGameOverlay func_76320_a=startSection | 8 | func_78471_a=renderWorld func_175180_a=renderGameOverlay func_76320_a=startSection |
java/client/com/mumfrey/liteloader/gl/GL.java
| @@ -1156,7 +1156,7 @@ public class GL | @@ -1156,7 +1156,7 @@ public class GL | ||
| 1156 | 1156 | ||
| 1157 | public static void glResetColor() | 1157 | public static void glResetColor() |
| 1158 | { | 1158 | { |
| 1159 | - GlStateManager.func_179117_G(); | 1159 | + GlStateManager.resetColor(); |
| 1160 | } | 1160 | } |
| 1161 | 1161 | ||
| 1162 | public static void glCallList(int list) | 1162 | public static void glCallList(int list) |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonDescriptor.java
| @@ -7,25 +7,48 @@ import com.google.gson.annotations.SerializedName; | @@ -7,25 +7,48 @@ import com.google.gson.annotations.SerializedName; | ||
| 7 | import com.mumfrey.liteloader.core.runtime.Obf; | 7 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; | 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
| 9 | 9 | ||
| 10 | +/** | ||
| 11 | + * A JSON method descriptor, | ||
| 12 | + * | ||
| 13 | + * @author Adam Mummery-Smith | ||
| 14 | + */ | ||
| 10 | public class JsonDescriptor implements Serializable | 15 | public class JsonDescriptor implements Serializable |
| 11 | { | 16 | { |
| 12 | private static final long serialVersionUID = 1L; | 17 | private static final long serialVersionUID = 1L; |
| 13 | 18 | ||
| 19 | + /** | ||
| 20 | + * Key used to refer to this method descriptor elsewhere | ||
| 21 | + */ | ||
| 14 | @SerializedName("key") | 22 | @SerializedName("key") |
| 15 | private String key; | 23 | private String key; |
| 16 | 24 | ||
| 25 | + /** | ||
| 26 | + * Name of the class which owns this method | ||
| 27 | + */ | ||
| 17 | @SerializedName("owner") | 28 | @SerializedName("owner") |
| 18 | private String owner; | 29 | private String owner; |
| 19 | 30 | ||
| 31 | + /** | ||
| 32 | + * Method name | ||
| 33 | + */ | ||
| 20 | @SerializedName("name") | 34 | @SerializedName("name") |
| 21 | private String name; | 35 | private String name; |
| 22 | 36 | ||
| 37 | + /** | ||
| 38 | + * Method return type, assumes VOID if none specified | ||
| 39 | + */ | ||
| 23 | @SerializedName("return") | 40 | @SerializedName("return") |
| 24 | private String returnType; | 41 | private String returnType; |
| 25 | 42 | ||
| 43 | + /** | ||
| 44 | + * Argument types for the method | ||
| 45 | + */ | ||
| 26 | @SerializedName("args") | 46 | @SerializedName("args") |
| 27 | private String[] argumentTypes; | 47 | private String[] argumentTypes; |
| 28 | 48 | ||
| 49 | + /** | ||
| 50 | + * Get the key used to refer to this method descriptor | ||
| 51 | + */ | ||
| 29 | public String getKey() | 52 | public String getKey() |
| 30 | { | 53 | { |
| 31 | if (this.key == null) | 54 | if (this.key == null) |
| @@ -36,6 +59,10 @@ public class JsonDescriptor implements Serializable | @@ -36,6 +59,10 @@ public class JsonDescriptor implements Serializable | ||
| 36 | return this.key; | 59 | return this.key; |
| 37 | } | 60 | } |
| 38 | 61 | ||
| 62 | + /** | ||
| 63 | + * @param obfTable | ||
| 64 | + * @return | ||
| 65 | + */ | ||
| 39 | public MethodInfo parse(JsonObfuscationTable obfTable) | 66 | public MethodInfo parse(JsonObfuscationTable obfTable) |
| 40 | { | 67 | { |
| 41 | if (this.owner == null || this.name == null) | 68 | if (this.owner == null || this.name == null) |
| @@ -46,21 +73,19 @@ public class JsonDescriptor implements Serializable | @@ -46,21 +73,19 @@ public class JsonDescriptor implements Serializable | ||
| 46 | Obf owner = obfTable.parseClass(this.owner); | 73 | Obf owner = obfTable.parseClass(this.owner); |
| 47 | Obf name = obfTable.parseMethod(this.name); | 74 | Obf name = obfTable.parseMethod(this.name); |
| 48 | 75 | ||
| 49 | - if (this.returnType == null) | 76 | + if (this.argumentTypes == null && this.returnType == null) |
| 50 | { | 77 | { |
| 51 | - if (this.argumentTypes != null) | ||
| 52 | - { | ||
| 53 | - throw new InvalidEventJsonException("Method descriptor was invalid, args specified with no return type!"); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | return new MethodInfo(owner, name); | 78 | return new MethodInfo(owner, name); |
| 57 | } | 79 | } |
| 58 | 80 | ||
| 59 | - Object returnType = obfTable.parseType(this.returnType); | 81 | + Object returnType = obfTable.parseType(this.returnType == null ? "VOID" : this.returnType); |
| 60 | Object[] args = (this.argumentTypes != null ? new Object[this.argumentTypes.length] : new Object[0]); | 82 | Object[] args = (this.argumentTypes != null ? new Object[this.argumentTypes.length] : new Object[0]); |
| 61 | - for (int arg = 0; arg < this.argumentTypes.length; arg++) | 83 | + if (this.argumentTypes != null) |
| 62 | { | 84 | { |
| 63 | - args[arg] = obfTable.parseType(this.argumentTypes[arg]); | 85 | + for (int arg = 0; arg < this.argumentTypes.length; arg++) |
| 86 | + { | ||
| 87 | + args[arg] = obfTable.parseType(this.argumentTypes[arg]); | ||
| 88 | + } | ||
| 64 | } | 89 | } |
| 65 | 90 | ||
| 66 | return new MethodInfo(owner, name, returnType, args); | 91 | return new MethodInfo(owner, name, returnType, args); |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonEvent.java
| @@ -9,29 +9,55 @@ import com.mumfrey.liteloader.transformers.event.Event; | @@ -9,29 +9,55 @@ import com.mumfrey.liteloader.transformers.event.Event; | ||
| 9 | import com.mumfrey.liteloader.transformers.event.InjectionPoint; | 9 | import com.mumfrey.liteloader.transformers.event.InjectionPoint; |
| 10 | import com.mumfrey.liteloader.transformers.event.MethodInfo; | 10 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
| 11 | 11 | ||
| 12 | +/** | ||
| 13 | + * An event definition in JSON, serialisable class read by Gson | ||
| 14 | + * | ||
| 15 | + * @author Adam Mummery-Smith | ||
| 16 | + */ | ||
| 12 | public class JsonEvent implements Serializable | 17 | public class JsonEvent implements Serializable |
| 13 | { | 18 | { |
| 14 | private static final long serialVersionUID = 1L; | 19 | private static final long serialVersionUID = 1L; |
| 15 | 20 | ||
| 16 | private static int nextEventID = 0; | 21 | private static int nextEventID = 0; |
| 17 | 22 | ||
| 23 | + /** | ||
| 24 | + * Event name | ||
| 25 | + */ | ||
| 18 | @SerializedName("name") | 26 | @SerializedName("name") |
| 19 | private String name; | 27 | private String name; |
| 20 | 28 | ||
| 29 | + /** | ||
| 30 | + * Whether the event is cancellable | ||
| 31 | + */ | ||
| 21 | @SerializedName("cancellable") | 32 | @SerializedName("cancellable") |
| 22 | private boolean cancellable; | 33 | private boolean cancellable; |
| 23 | 34 | ||
| 35 | + /** | ||
| 36 | + * Event priority (relative to other events at the same injection point) | ||
| 37 | + */ | ||
| 24 | @SerializedName("priority") | 38 | @SerializedName("priority") |
| 25 | private int priority = 1000; | 39 | private int priority = 1000; |
| 26 | 40 | ||
| 41 | + /** | ||
| 42 | + * Injection points specified in the JSON file | ||
| 43 | + */ | ||
| 27 | @SerializedName("injections") | 44 | @SerializedName("injections") |
| 28 | private List<JsonInjection> jsonInjections; | 45 | private List<JsonInjection> jsonInjections; |
| 29 | 46 | ||
| 47 | + /** | ||
| 48 | + * Listeners defined in the JSON file | ||
| 49 | + */ | ||
| 30 | @SerializedName("listeners") | 50 | @SerializedName("listeners") |
| 31 | private List<String> jsonListeners; | 51 | private List<String> jsonListeners; |
| 32 | 52 | ||
| 53 | + /** | ||
| 54 | + * Listener methods parsed from the JSON | ||
| 55 | + */ | ||
| 33 | private transient List<MethodInfo> listeners = new ArrayList<MethodInfo>(); | 56 | private transient List<MethodInfo> listeners = new ArrayList<MethodInfo>(); |
| 34 | 57 | ||
| 58 | + /** | ||
| 59 | + * Get the name of this event | ||
| 60 | + */ | ||
| 35 | public String getName() | 61 | public String getName() |
| 36 | { | 62 | { |
| 37 | if (this.name == null) | 63 | if (this.name == null) |
| @@ -42,52 +68,75 @@ public class JsonEvent implements Serializable | @@ -42,52 +68,75 @@ public class JsonEvent implements Serializable | ||
| 42 | return this.name; | 68 | return this.name; |
| 43 | } | 69 | } |
| 44 | 70 | ||
| 71 | + /** | ||
| 72 | + * Get whether this event is cancellable or not | ||
| 73 | + */ | ||
| 45 | public boolean isCancellable() | 74 | public boolean isCancellable() |
| 46 | { | 75 | { |
| 47 | return this.cancellable; | 76 | return this.cancellable; |
| 48 | } | 77 | } |
| 49 | 78 | ||
| 79 | + /** | ||
| 80 | + * Get the event priority | ||
| 81 | + */ | ||
| 50 | public int getPriority() | 82 | public int getPriority() |
| 51 | { | 83 | { |
| 52 | return this.priority; | 84 | return this.priority; |
| 53 | } | 85 | } |
| 54 | 86 | ||
| 87 | + /** | ||
| 88 | + * Get the list of listeners parsed from the JSON | ||
| 89 | + */ | ||
| 55 | public List<MethodInfo> getListeners() | 90 | public List<MethodInfo> getListeners() |
| 56 | { | 91 | { |
| 57 | return this.listeners; | 92 | return this.listeners; |
| 58 | } | 93 | } |
| 59 | 94 | ||
| 60 | - public void parse(JsonEvents json) | 95 | + /** |
| 96 | + * Parse the JSON to initialise this object | ||
| 97 | + */ | ||
| 98 | + public void parse(JsonMethods methods) | ||
| 61 | { | 99 | { |
| 62 | - this.parseInjectionPoints(json); | ||
| 63 | - this.parseListeners(json); | 100 | + this.parseInjectionPoints(methods); |
| 101 | + this.parseListeners(methods); | ||
| 64 | } | 102 | } |
| 65 | 103 | ||
| 66 | - private void parseInjectionPoints(JsonEvents json) | 104 | + /** |
| 105 | + * @param methods | ||
| 106 | + */ | ||
| 107 | + private void parseInjectionPoints(JsonMethods methods) | ||
| 67 | { | 108 | { |
| 68 | - if (this.jsonInjections == null || this.jsonInjections.size() == 0) | 109 | + if (this.jsonInjections == null || this.jsonInjections.isEmpty()) |
| 69 | { | 110 | { |
| 70 | throw new InvalidEventJsonException("Event " + this.getName() + " does not have any defined injections"); | 111 | throw new InvalidEventJsonException("Event " + this.getName() + " does not have any defined injections"); |
| 71 | } | 112 | } |
| 72 | 113 | ||
| 73 | for (JsonInjection injection : this.jsonInjections) | 114 | for (JsonInjection injection : this.jsonInjections) |
| 74 | { | 115 | { |
| 75 | - injection.parse(json); | 116 | + injection.parse(methods); |
| 76 | } | 117 | } |
| 77 | } | 118 | } |
| 78 | 119 | ||
| 79 | - private void parseListeners(JsonEvents json) | 120 | + /** |
| 121 | + * @param methods | ||
| 122 | + */ | ||
| 123 | + private void parseListeners(JsonMethods methods) | ||
| 80 | { | 124 | { |
| 81 | - if (this.jsonListeners == null || this.jsonListeners.size() == 0) | 125 | + if (this.jsonListeners == null || this.jsonListeners.isEmpty()) |
| 82 | { | 126 | { |
| 83 | throw new InvalidEventJsonException("Event " + this.getName() + " does not have any defined listeners"); | 127 | throw new InvalidEventJsonException("Event " + this.getName() + " does not have any defined listeners"); |
| 84 | } | 128 | } |
| 85 | 129 | ||
| 86 | for (String listener : this.jsonListeners) | 130 | for (String listener : this.jsonListeners) |
| 87 | { | 131 | { |
| 88 | - this.listeners.add(json.getMethod(listener)); | 132 | + this.listeners.add(methods.get(listener)); |
| 89 | } | 133 | } |
| 90 | } | 134 | } |
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * @param transformer | ||
| 138 | + * @return | ||
| 139 | + */ | ||
| 91 | public Event register(ModEventInjectionTransformer transformer) | 140 | public Event register(ModEventInjectionTransformer transformer) |
| 92 | { | 141 | { |
| 93 | Event event = Event.getOrCreate(this.getName(), this.isCancellable(), this.getPriority()); | 142 | Event event = Event.getOrCreate(this.getName(), this.isCancellable(), this.getPriority()); |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonEvents.java
| 1 | package com.mumfrey.liteloader.transformers.event.json; | 1 | package com.mumfrey.liteloader.transformers.event.json; |
| 2 | 2 | ||
| 3 | import java.io.Serializable; | 3 | import java.io.Serializable; |
| 4 | -import java.util.HashMap; | ||
| 5 | import java.util.List; | 4 | import java.util.List; |
| 6 | -import java.util.Map; | ||
| 7 | import java.util.regex.Matcher; | 5 | import java.util.regex.Matcher; |
| 8 | import java.util.regex.Pattern; | 6 | import java.util.regex.Pattern; |
| 9 | 7 | ||
| 10 | import com.google.gson.Gson; | 8 | import com.google.gson.Gson; |
| 11 | import com.google.gson.GsonBuilder; | 9 | import com.google.gson.GsonBuilder; |
| 12 | import com.google.gson.annotations.SerializedName; | 10 | import com.google.gson.annotations.SerializedName; |
| 13 | -import com.mumfrey.liteloader.transformers.event.MethodInfo; | ||
| 14 | 11 | ||
| 15 | /** | 12 | /** |
| 16 | - * Serialisable class which represents a set of event injection definitions | 13 | + * Serialisable class which represents a set of event injection definitions. Instances of this class are |
| 14 | + * created by deserialising with JSON. The JSON string should be passed to the static {@link #parse} method | ||
| 15 | + * which returns an instance of the class. | ||
| 16 | + * | ||
| 17 | + * After parsing, the events defined here can be injected into an event transformer instance by calling the | ||
| 18 | + * {@link #register} method | ||
| 17 | * | 19 | * |
| 18 | * @author Adam Mummery-Smith | 20 | * @author Adam Mummery-Smith |
| 19 | */ | 21 | */ |
| @@ -23,36 +25,56 @@ public class JsonEvents implements Serializable | @@ -23,36 +25,56 @@ public class JsonEvents implements Serializable | ||
| 23 | 25 | ||
| 24 | private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); | 26 | private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
| 25 | 27 | ||
| 28 | + /** | ||
| 29 | + * Tokens are an instruction to the parser to look up a value rather than using a literal | ||
| 30 | + */ | ||
| 26 | private static final Pattern tokenPattern = Pattern.compile("^\\$\\{([a-zA-Z0-9_\\-\\.\\$]+)\\}$"); | 31 | private static final Pattern tokenPattern = Pattern.compile("^\\$\\{([a-zA-Z0-9_\\-\\.\\$]+)\\}$"); |
| 27 | 32 | ||
| 33 | + /** | ||
| 34 | + * Serialised obfusctation entries | ||
| 35 | + */ | ||
| 28 | @SerializedName("obfuscation") | 36 | @SerializedName("obfuscation") |
| 29 | private JsonObfuscationTable obfuscation; | 37 | private JsonObfuscationTable obfuscation; |
| 30 | 38 | ||
| 39 | + /** | ||
| 40 | + * Serialised method descriptors | ||
| 41 | + */ | ||
| 31 | @SerializedName("descriptors") | 42 | @SerializedName("descriptors") |
| 32 | private List<JsonDescriptor> descriptors; | 43 | private List<JsonDescriptor> descriptors; |
| 33 | 44 | ||
| 45 | + /** | ||
| 46 | + * Serialised events | ||
| 47 | + */ | ||
| 34 | @SerializedName("events") | 48 | @SerializedName("events") |
| 35 | private List<JsonEvent> events; | 49 | private List<JsonEvent> events; |
| 36 | 50 | ||
| 37 | - private transient Map<String, MethodInfo> methods = new HashMap<String, MethodInfo>(); | 51 | + /** |
| 52 | + * Parsed method descriptors | ||
| 53 | + */ | ||
| 54 | + private transient JsonMethods methods; | ||
| 38 | 55 | ||
| 39 | - public void parse() | 56 | + /** |
| 57 | + * Attempts to parse the information in this object | ||
| 58 | + */ | ||
| 59 | + private void parse() | ||
| 40 | { | 60 | { |
| 61 | + if (this.events == null || this.events.isEmpty()) | ||
| 62 | + { | ||
| 63 | + throw new InvalidEventJsonException("No events were defined in the supplied JSON"); | ||
| 64 | + } | ||
| 65 | + | ||
| 41 | try | 66 | try |
| 42 | { | 67 | { |
| 68 | + // Parse the obfuscation table | ||
| 43 | this.obfuscation.parse(); | 69 | this.obfuscation.parse(); |
| 44 | 70 | ||
| 45 | - if (this.descriptors != null) | ||
| 46 | - { | ||
| 47 | - for (JsonDescriptor descriptor : this.descriptors) | ||
| 48 | - { | ||
| 49 | - this.methods.put(descriptor.getKey(), descriptor.parse(this.obfuscation)); | ||
| 50 | - } | ||
| 51 | - } | 71 | + // Parse the descriptor list |
| 72 | + this.methods = new JsonMethods(this.obfuscation, this.descriptors); | ||
| 52 | 73 | ||
| 74 | + // Parse the events | ||
| 53 | for (JsonEvent event : this.events) | 75 | for (JsonEvent event : this.events) |
| 54 | { | 76 | { |
| 55 | - event.parse(this); | 77 | + event.parse(this.methods); |
| 56 | } | 78 | } |
| 57 | } | 79 | } |
| 58 | catch (InvalidEventJsonException ex) | 80 | catch (InvalidEventJsonException ex) |
| @@ -65,6 +87,30 @@ public class JsonEvents implements Serializable | @@ -65,6 +87,30 @@ public class JsonEvents implements Serializable | ||
| 65 | } | 87 | } |
| 66 | } | 88 | } |
| 67 | 89 | ||
| 90 | + /** | ||
| 91 | + * Parse a token name, returns the token name as a string if the token is valid, or null if the token is not valid | ||
| 92 | + * | ||
| 93 | + * @param token | ||
| 94 | + * @return | ||
| 95 | + */ | ||
| 96 | + static String parseToken(String token) | ||
| 97 | + { | ||
| 98 | + token = token.replace(" ", "").trim(); | ||
| 99 | + | ||
| 100 | + Matcher tokenPatternMatcher = JsonEvents.tokenPattern.matcher(token); | ||
| 101 | + if (tokenPatternMatcher.matches()) | ||
| 102 | + { | ||
| 103 | + return tokenPatternMatcher.group(1); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + return null; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Called to register all events defined in this object into the specified transformer | ||
| 111 | + * | ||
| 112 | + * @param transformer | ||
| 113 | + */ | ||
| 68 | public void register(ModEventInjectionTransformer transformer) | 114 | public void register(ModEventInjectionTransformer transformer) |
| 69 | { | 115 | { |
| 70 | for (JsonEvent event : this.events) | 116 | for (JsonEvent event : this.events) |
| @@ -73,44 +119,33 @@ public class JsonEvents implements Serializable | @@ -73,44 +119,33 @@ public class JsonEvents implements Serializable | ||
| 73 | } | 119 | } |
| 74 | } | 120 | } |
| 75 | 121 | ||
| 76 | - public MethodInfo getMethod(String token) | 122 | +// public String toJson() |
| 123 | +// { | ||
| 124 | +// return JsonEvents.gson.toJson(this); | ||
| 125 | +// } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Parse a new JsonEvents object from the supplied JSON string | ||
| 129 | + * | ||
| 130 | + * @param json | ||
| 131 | + * @return | ||
| 132 | + * @throws InvalidEventJsonException if the JSON ins invalid | ||
| 133 | + */ | ||
| 134 | + public static JsonEvents parse(String json) throws InvalidEventJsonException | ||
| 77 | { | 135 | { |
| 78 | - String key = JsonEvents.parseToken(token); | ||
| 79 | - if (key == null) | 136 | + try |
| 80 | { | 137 | { |
| 81 | - throw new InvalidEventJsonException("\"" + token + "\" is not a valid token"); | 138 | + JsonEvents newJsonEvents = JsonEvents.gson.fromJson(json, JsonEvents.class); |
| 139 | + newJsonEvents.parse(); | ||
| 140 | + return newJsonEvents; | ||
| 82 | } | 141 | } |
| 83 | - | ||
| 84 | - MethodInfo method = this.methods.get(key); | ||
| 85 | - if (method == null) | 142 | + catch (InvalidEventJsonException ex) |
| 86 | { | 143 | { |
| 87 | - throw new InvalidEventJsonException("Could not locate method with token " + token); | 144 | + throw ex; |
| 88 | } | 145 | } |
| 89 | - return method; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - public String toJson() | ||
| 93 | - { | ||
| 94 | - return JsonEvents.gson.toJson(this); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - public static JsonEvents parse(String json) | ||
| 98 | - { | ||
| 99 | - JsonEvents newJsonEvents = JsonEvents.gson.fromJson(json, JsonEvents.class); | ||
| 100 | - newJsonEvents.parse(); | ||
| 101 | - return newJsonEvents; | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - protected static String parseToken(String token) | ||
| 105 | - { | ||
| 106 | - token = token.replace(" ", "").trim(); | ||
| 107 | - | ||
| 108 | - Matcher tokenPatternMatcher = JsonEvents.tokenPattern.matcher(token); | ||
| 109 | - if (tokenPatternMatcher.matches()) | 146 | + catch (Throwable th) |
| 110 | { | 147 | { |
| 111 | - return tokenPatternMatcher.group(1); | 148 | + throw new InvalidEventJsonException("An error occurred whilst parsing the event definition: " + th.getClass().getSimpleName() + ": " + th.getMessage(), th); |
| 112 | } | 149 | } |
| 113 | - | ||
| 114 | - return null; | ||
| 115 | } | 150 | } |
| 116 | } | 151 | } |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonInjection.java
| @@ -8,30 +8,57 @@ import com.mumfrey.liteloader.transformers.event.InjectionPoint; | @@ -8,30 +8,57 @@ import com.mumfrey.liteloader.transformers.event.InjectionPoint; | ||
| 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; | 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
| 9 | import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke; | 9 | import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke; |
| 10 | import com.mumfrey.liteloader.transformers.event.inject.BeforeReturn; | 10 | import com.mumfrey.liteloader.transformers.event.inject.BeforeReturn; |
| 11 | +import com.mumfrey.liteloader.transformers.event.inject.BeforeStringInvoke; | ||
| 11 | import com.mumfrey.liteloader.transformers.event.inject.MethodHead; | 12 | import com.mumfrey.liteloader.transformers.event.inject.MethodHead; |
| 12 | 13 | ||
| 14 | +/** | ||
| 15 | + * A JSON injection point definition | ||
| 16 | + * | ||
| 17 | + * @author Adam Mummery-Smith | ||
| 18 | + */ | ||
| 13 | public class JsonInjection implements Serializable | 19 | public class JsonInjection implements Serializable |
| 14 | { | 20 | { |
| 15 | private static final long serialVersionUID = 1L; | 21 | private static final long serialVersionUID = 1L; |
| 16 | 22 | ||
| 23 | + /** | ||
| 24 | + * Method to inject into | ||
| 25 | + */ | ||
| 17 | @SerializedName("method") | 26 | @SerializedName("method") |
| 18 | private String methodName; | 27 | private String methodName; |
| 19 | 28 | ||
| 29 | + /** | ||
| 30 | + * Type of injection point | ||
| 31 | + */ | ||
| 20 | @SerializedName("type") | 32 | @SerializedName("type") |
| 21 | private JsonInjectionType type; | 33 | private JsonInjectionType type; |
| 22 | 34 | ||
| 35 | + /** | ||
| 36 | + * Shift type (optional) | ||
| 37 | + */ | ||
| 23 | @SerializedName("shift") | 38 | @SerializedName("shift") |
| 24 | private JsonInjectionShiftType shift; | 39 | private JsonInjectionShiftType shift; |
| 25 | 40 | ||
| 41 | + /** | ||
| 42 | + * Target method to search for when using INVOKE and INVOKESTRING | ||
| 43 | + */ | ||
| 26 | @SerializedName("target") | 44 | @SerializedName("target") |
| 27 | private String target; | 45 | private String target; |
| 28 | 46 | ||
| 47 | + /** | ||
| 48 | + * Ordinal to use when using INVOKE and INVOKESTRING | ||
| 49 | + */ | ||
| 29 | @SerializedName("ordinal") | 50 | @SerializedName("ordinal") |
| 30 | private int ordinal = -1; | 51 | private int ordinal = -1; |
| 31 | 52 | ||
| 53 | + /** | ||
| 54 | + * InjectionPoint class to use for CUSTOM | ||
| 55 | + */ | ||
| 32 | @SerializedName("class") | 56 | @SerializedName("class") |
| 33 | private String className; | 57 | private String className; |
| 34 | 58 | ||
| 59 | + /** | ||
| 60 | + * Constructor arguments to pass wehn using CUSTOM | ||
| 61 | + */ | ||
| 35 | @SerializedName("args") | 62 | @SerializedName("args") |
| 36 | private Object[] args; | 63 | private Object[] args; |
| 37 | 64 | ||
| @@ -49,24 +76,26 @@ public class JsonInjection implements Serializable | @@ -49,24 +76,26 @@ public class JsonInjection implements Serializable | ||
| 49 | return this.injectionPoint; | 76 | return this.injectionPoint; |
| 50 | } | 77 | } |
| 51 | 78 | ||
| 52 | - public void parse(JsonEvents json) | 79 | + public void parse(JsonMethods methods) |
| 53 | { | 80 | { |
| 54 | - this.method = this.parseMethod(json); | ||
| 55 | - this.injectionPoint = this.parseInjectionPoint(json); | 81 | + this.method = this.parseMethod(methods); |
| 82 | + this.injectionPoint = this.parseInjectionPoint(methods); | ||
| 56 | } | 83 | } |
| 57 | 84 | ||
| 58 | - private MethodInfo parseMethod(JsonEvents json) | 85 | + private MethodInfo parseMethod(JsonMethods methods) |
| 59 | { | 86 | { |
| 60 | - return json.getMethod(this.methodName); | 87 | + return methods.get(this.methodName); |
| 61 | } | 88 | } |
| 62 | 89 | ||
| 63 | - public InjectionPoint parseInjectionPoint(JsonEvents json) | 90 | + public InjectionPoint parseInjectionPoint(JsonMethods methods) |
| 64 | { | 91 | { |
| 65 | switch (this.type) | 92 | switch (this.type) |
| 66 | { | 93 | { |
| 67 | case INVOKE: | 94 | case INVOKE: |
| 68 | - MethodInfo method = json.getMethod(this.getTarget()); | ||
| 69 | - return this.applyShift(new BeforeInvoke(method, this.ordinal)); | 95 | + return this.applyShift(new BeforeInvoke(methods.get(this.getTarget()), this.ordinal)); |
| 96 | + | ||
| 97 | + case INVOKESTRING: | ||
| 98 | + return this.applyShift(new BeforeStringInvoke(this.getArg(0).toString(), methods.get(this.getTarget()), this.ordinal)); | ||
| 70 | 99 | ||
| 71 | case RETURN: | 100 | case RETURN: |
| 72 | return this.applyShift(new BeforeReturn(this.ordinal)); | 101 | return this.applyShift(new BeforeReturn(this.ordinal)); |
| @@ -95,6 +124,14 @@ public class JsonInjection implements Serializable | @@ -95,6 +124,14 @@ public class JsonInjection implements Serializable | ||
| 95 | throw new InvalidEventJsonException("Could not parse injection type"); | 124 | throw new InvalidEventJsonException("Could not parse injection type"); |
| 96 | } | 125 | } |
| 97 | 126 | ||
| 127 | + private Object getArg(int arg) | ||
| 128 | + { | ||
| 129 | + if (this.args == null || this.args.length >= this.args.length || arg < 0) | ||
| 130 | + return ""; | ||
| 131 | + | ||
| 132 | + return this.args[arg]; | ||
| 133 | + } | ||
| 134 | + | ||
| 98 | private String getTarget() | 135 | private String getTarget() |
| 99 | { | 136 | { |
| 100 | if (this.target != null && this.shift == null) | 137 | if (this.target != null && this.shift == null) |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonInjectionType.java
| @@ -3,6 +3,8 @@ package com.mumfrey.liteloader.transformers.event.json; | @@ -3,6 +3,8 @@ package com.mumfrey.liteloader.transformers.event.json; | ||
| 3 | public enum JsonInjectionType | 3 | public enum JsonInjectionType |
| 4 | { | 4 | { |
| 5 | INVOKE, | 5 | INVOKE, |
| 6 | + INVOKESTRING, | ||
| 7 | + FIELD, | ||
| 6 | RETURN, | 8 | RETURN, |
| 7 | HEAD, | 9 | HEAD, |
| 8 | CUSTOM; | 10 | CUSTOM; |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonMethods.java
0 โ 100644
| 1 | +package com.mumfrey.liteloader.transformers.event.json; | ||
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.List; | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 7 | +import com.mumfrey.liteloader.transformers.event.MethodInfo; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * A simple registry of MethodInfo objects parsed from the JSON, objects which consume the specified | ||
| 11 | + * MethodInfo objects will be passed an instance of this object at parse time. | ||
| 12 | + * | ||
| 13 | + * @author Adam Mummery-Smith | ||
| 14 | + */ | ||
| 15 | +public class JsonMethods | ||
| 16 | +{ | ||
| 17 | + /** | ||
| 18 | + * Serialised obfusctation entries | ||
| 19 | + */ | ||
| 20 | + private final JsonObfuscationTable obfuscation; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * Method descriptors | ||
| 24 | + */ | ||
| 25 | + private final List<JsonDescriptor> descriptors; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * Method descriptors which have been parsed from the descriptors collection | ||
| 29 | + */ | ||
| 30 | + private Map<String, MethodInfo> methods = new HashMap<String, MethodInfo>(); | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * @param obfuscation | ||
| 34 | + * @param descriptors | ||
| 35 | + */ | ||
| 36 | + public JsonMethods(JsonObfuscationTable obfuscation, List<JsonDescriptor> descriptors) | ||
| 37 | + { | ||
| 38 | + this.obfuscation = obfuscation; | ||
| 39 | + this.descriptors = descriptors; | ||
| 40 | + | ||
| 41 | + this.parse(); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * | ||
| 46 | + */ | ||
| 47 | + private void parse() | ||
| 48 | + { | ||
| 49 | + if (this.descriptors != null) | ||
| 50 | + { | ||
| 51 | + for (JsonDescriptor descriptor : this.descriptors) | ||
| 52 | + { | ||
| 53 | + this.methods.put(descriptor.getKey(), descriptor.parse(this.obfuscation)); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Fetches a method descriptor by token | ||
| 60 | + * | ||
| 61 | + * @param token | ||
| 62 | + * @return | ||
| 63 | + */ | ||
| 64 | + public MethodInfo get(String token) | ||
| 65 | + { | ||
| 66 | + String key = JsonEvents.parseToken(token); | ||
| 67 | + if (key == null) | ||
| 68 | + { | ||
| 69 | + throw new InvalidEventJsonException("\"" + token + "\" is not a valid token"); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + MethodInfo method = this.methods.get(key); | ||
| 73 | + if (method == null) | ||
| 74 | + { | ||
| 75 | + throw new InvalidEventJsonException("Could not locate method with token " + token); | ||
| 76 | + } | ||
| 77 | + return method; | ||
| 78 | + } | ||
| 79 | +} | ||
| 0 | \ No newline at end of file | 80 | \ No newline at end of file |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonObfuscationTable.java
| @@ -9,6 +9,12 @@ import com.google.gson.annotations.SerializedName; | @@ -9,6 +9,12 @@ import com.google.gson.annotations.SerializedName; | ||
| 9 | import com.mumfrey.liteloader.core.runtime.Obf; | 9 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 10 | import com.mumfrey.liteloader.core.runtime.Packets; | 10 | import com.mumfrey.liteloader.core.runtime.Packets; |
| 11 | 11 | ||
| 12 | +/** | ||
| 13 | + * JSON-defined obfuscation table entries used like a registry by the other JSON components to look up obfuscation mappings | ||
| 14 | + * for methods and fields. | ||
| 15 | + * | ||
| 16 | + * @author Adam Mummery-Smith | ||
| 17 | + */ | ||
| 12 | public class JsonObfuscationTable implements Serializable | 18 | public class JsonObfuscationTable implements Serializable |
| 13 | { | 19 | { |
| 14 | private static final long serialVersionUID = 1L; | 20 | private static final long serialVersionUID = 1L; |
| @@ -22,10 +28,14 @@ public class JsonObfuscationTable implements Serializable | @@ -22,10 +28,14 @@ public class JsonObfuscationTable implements Serializable | ||
| 22 | @SerializedName("fields") | 28 | @SerializedName("fields") |
| 23 | private List<JsonObf> jsonFields; | 29 | private List<JsonObf> jsonFields; |
| 24 | 30 | ||
| 31 | + // Parsed values | ||
| 25 | private transient Map<String, Obf> classObfs = new HashMap<String, Obf>(); | 32 | private transient Map<String, Obf> classObfs = new HashMap<String, Obf>(); |
| 26 | private transient Map<String, Obf> methodObfs = new HashMap<String, Obf>(); | 33 | private transient Map<String, Obf> methodObfs = new HashMap<String, Obf>(); |
| 27 | private transient Map<String, Obf> fieldObfs = new HashMap<String, Obf>(); | 34 | private transient Map<String, Obf> fieldObfs = new HashMap<String, Obf>(); |
| 28 | 35 | ||
| 36 | + /** | ||
| 37 | + * Parse the entries in each collection to actual Obf objects | ||
| 38 | + */ | ||
| 29 | public void parse() | 39 | public void parse() |
| 30 | { | 40 | { |
| 31 | if (this.jsonClasses != null) | 41 | if (this.jsonClasses != null) |
| @@ -53,6 +63,9 @@ public class JsonObfuscationTable implements Serializable | @@ -53,6 +63,9 @@ public class JsonObfuscationTable implements Serializable | ||
| 53 | } | 63 | } |
| 54 | } | 64 | } |
| 55 | 65 | ||
| 66 | + /** | ||
| 67 | + * Look up a type (a class or primitive type) by token | ||
| 68 | + */ | ||
| 56 | public Object parseType(String token) | 69 | public Object parseType(String token) |
| 57 | { | 70 | { |
| 58 | token = token.replace(" ", "").trim(); | 71 | token = token.replace(" ", "").trim(); |
| @@ -76,16 +89,28 @@ public class JsonObfuscationTable implements Serializable | @@ -76,16 +89,28 @@ public class JsonObfuscationTable implements Serializable | ||
| 76 | return this.parseClass(token); | 89 | return this.parseClass(token); |
| 77 | } | 90 | } |
| 78 | 91 | ||
| 92 | + /** | ||
| 93 | + * @param token | ||
| 94 | + * @return | ||
| 95 | + */ | ||
| 79 | public Obf parseClass(String token) | 96 | public Obf parseClass(String token) |
| 80 | { | 97 | { |
| 81 | return this.parseObf(token, this.classObfs); | 98 | return this.parseObf(token, this.classObfs); |
| 82 | } | 99 | } |
| 83 | 100 | ||
| 101 | + /** | ||
| 102 | + * @param token | ||
| 103 | + * @return | ||
| 104 | + */ | ||
| 84 | public Obf parseMethod(String token) | 105 | public Obf parseMethod(String token) |
| 85 | { | 106 | { |
| 86 | return this.parseObf(token, this.methodObfs); | 107 | return this.parseObf(token, this.methodObfs); |
| 87 | } | 108 | } |
| 88 | 109 | ||
| 110 | + /** | ||
| 111 | + * @param token | ||
| 112 | + * @return | ||
| 113 | + */ | ||
| 89 | public Obf parseField(String token) | 114 | public Obf parseField(String token) |
| 90 | { | 115 | { |
| 91 | return this.parseObf(token, this.fieldObfs); | 116 | return this.parseObf(token, this.fieldObfs); |
| @@ -119,7 +144,7 @@ public class JsonObfuscationTable implements Serializable | @@ -119,7 +144,7 @@ public class JsonObfuscationTable implements Serializable | ||
| 119 | return packet; | 144 | return packet; |
| 120 | } | 145 | } |
| 121 | 146 | ||
| 122 | - throw new InvalidEventJsonException("The token " + token + " could not be resolved"); | 147 | + throw new InvalidEventJsonException("The token " + token + " could not be resolved to a type"); |
| 123 | } | 148 | } |
| 124 | 149 | ||
| 125 | return new JsonObf.Mapping(token, token, token); | 150 | return new JsonObf.Mapping(token, token, token); |