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 | 1 | field_71424_I=mcProfiler |
| 2 | 2 | field_78729_o=entityRenderMap field_110546_b=reloadListeners |
| 3 | 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 | 6 | field_145855_i=nameToClassMap |
| 7 | 7 | field_145853_j=classToNameMap func_148833_a=processPacket func_71411_J=runGameLoop func_71407_l=runTick func_78480_b=updateCameraAndRender |
| 8 | 8 | func_78471_a=renderWorld func_175180_a=renderGameOverlay func_76320_a=startSection | ... | ... |
java/client/com/mumfrey/liteloader/gl/GL.java
java/common/com/mumfrey/liteloader/transformers/event/json/JsonDescriptor.java
| ... | ... | @@ -7,25 +7,48 @@ import com.google.gson.annotations.SerializedName; |
| 7 | 7 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 8 | 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
| 9 | 9 | |
| 10 | +/** | |
| 11 | + * A JSON method descriptor, | |
| 12 | + * | |
| 13 | + * @author Adam Mummery-Smith | |
| 14 | + */ | |
| 10 | 15 | public class JsonDescriptor implements Serializable |
| 11 | 16 | { |
| 12 | 17 | private static final long serialVersionUID = 1L; |
| 13 | 18 | |
| 19 | + /** | |
| 20 | + * Key used to refer to this method descriptor elsewhere | |
| 21 | + */ | |
| 14 | 22 | @SerializedName("key") |
| 15 | 23 | private String key; |
| 16 | 24 | |
| 25 | + /** | |
| 26 | + * Name of the class which owns this method | |
| 27 | + */ | |
| 17 | 28 | @SerializedName("owner") |
| 18 | 29 | private String owner; |
| 19 | 30 | |
| 31 | + /** | |
| 32 | + * Method name | |
| 33 | + */ | |
| 20 | 34 | @SerializedName("name") |
| 21 | 35 | private String name; |
| 22 | 36 | |
| 37 | + /** | |
| 38 | + * Method return type, assumes VOID if none specified | |
| 39 | + */ | |
| 23 | 40 | @SerializedName("return") |
| 24 | 41 | private String returnType; |
| 25 | 42 | |
| 43 | + /** | |
| 44 | + * Argument types for the method | |
| 45 | + */ | |
| 26 | 46 | @SerializedName("args") |
| 27 | 47 | private String[] argumentTypes; |
| 28 | 48 | |
| 49 | + /** | |
| 50 | + * Get the key used to refer to this method descriptor | |
| 51 | + */ | |
| 29 | 52 | public String getKey() |
| 30 | 53 | { |
| 31 | 54 | if (this.key == null) |
| ... | ... | @@ -36,6 +59,10 @@ public class JsonDescriptor implements Serializable |
| 36 | 59 | return this.key; |
| 37 | 60 | } |
| 38 | 61 | |
| 62 | + /** | |
| 63 | + * @param obfTable | |
| 64 | + * @return | |
| 65 | + */ | |
| 39 | 66 | public MethodInfo parse(JsonObfuscationTable obfTable) |
| 40 | 67 | { |
| 41 | 68 | if (this.owner == null || this.name == null) |
| ... | ... | @@ -46,21 +73,19 @@ public class JsonDescriptor implements Serializable |
| 46 | 73 | Obf owner = obfTable.parseClass(this.owner); |
| 47 | 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 | 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 | 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 | 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 | 9 | import com.mumfrey.liteloader.transformers.event.InjectionPoint; |
| 10 | 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 | 17 | public class JsonEvent implements Serializable |
| 13 | 18 | { |
| 14 | 19 | private static final long serialVersionUID = 1L; |
| 15 | 20 | |
| 16 | 21 | private static int nextEventID = 0; |
| 17 | 22 | |
| 23 | + /** | |
| 24 | + * Event name | |
| 25 | + */ | |
| 18 | 26 | @SerializedName("name") |
| 19 | 27 | private String name; |
| 20 | 28 | |
| 29 | + /** | |
| 30 | + * Whether the event is cancellable | |
| 31 | + */ | |
| 21 | 32 | @SerializedName("cancellable") |
| 22 | 33 | private boolean cancellable; |
| 23 | 34 | |
| 35 | + /** | |
| 36 | + * Event priority (relative to other events at the same injection point) | |
| 37 | + */ | |
| 24 | 38 | @SerializedName("priority") |
| 25 | 39 | private int priority = 1000; |
| 26 | 40 | |
| 41 | + /** | |
| 42 | + * Injection points specified in the JSON file | |
| 43 | + */ | |
| 27 | 44 | @SerializedName("injections") |
| 28 | 45 | private List<JsonInjection> jsonInjections; |
| 29 | 46 | |
| 47 | + /** | |
| 48 | + * Listeners defined in the JSON file | |
| 49 | + */ | |
| 30 | 50 | @SerializedName("listeners") |
| 31 | 51 | private List<String> jsonListeners; |
| 32 | 52 | |
| 53 | + /** | |
| 54 | + * Listener methods parsed from the JSON | |
| 55 | + */ | |
| 33 | 56 | private transient List<MethodInfo> listeners = new ArrayList<MethodInfo>(); |
| 34 | 57 | |
| 58 | + /** | |
| 59 | + * Get the name of this event | |
| 60 | + */ | |
| 35 | 61 | public String getName() |
| 36 | 62 | { |
| 37 | 63 | if (this.name == null) |
| ... | ... | @@ -42,52 +68,75 @@ public class JsonEvent implements Serializable |
| 42 | 68 | return this.name; |
| 43 | 69 | } |
| 44 | 70 | |
| 71 | + /** | |
| 72 | + * Get whether this event is cancellable or not | |
| 73 | + */ | |
| 45 | 74 | public boolean isCancellable() |
| 46 | 75 | { |
| 47 | 76 | return this.cancellable; |
| 48 | 77 | } |
| 49 | 78 | |
| 79 | + /** | |
| 80 | + * Get the event priority | |
| 81 | + */ | |
| 50 | 82 | public int getPriority() |
| 51 | 83 | { |
| 52 | 84 | return this.priority; |
| 53 | 85 | } |
| 54 | 86 | |
| 87 | + /** | |
| 88 | + * Get the list of listeners parsed from the JSON | |
| 89 | + */ | |
| 55 | 90 | public List<MethodInfo> getListeners() |
| 56 | 91 | { |
| 57 | 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 | 111 | throw new InvalidEventJsonException("Event " + this.getName() + " does not have any defined injections"); |
| 71 | 112 | } |
| 72 | 113 | |
| 73 | 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 | 127 | throw new InvalidEventJsonException("Event " + this.getName() + " does not have any defined listeners"); |
| 84 | 128 | } |
| 85 | 129 | |
| 86 | 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 | 140 | public Event register(ModEventInjectionTransformer transformer) |
| 92 | 141 | { |
| 93 | 142 | Event event = Event.getOrCreate(this.getName(), this.isCancellable(), this.getPriority()); | ... | ... |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonEvents.java
| 1 | 1 | package com.mumfrey.liteloader.transformers.event.json; |
| 2 | 2 | |
| 3 | 3 | import java.io.Serializable; |
| 4 | -import java.util.HashMap; | |
| 5 | 4 | import java.util.List; |
| 6 | -import java.util.Map; | |
| 7 | 5 | import java.util.regex.Matcher; |
| 8 | 6 | import java.util.regex.Pattern; |
| 9 | 7 | |
| 10 | 8 | import com.google.gson.Gson; |
| 11 | 9 | import com.google.gson.GsonBuilder; |
| 12 | 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 | 20 | * @author Adam Mummery-Smith |
| 19 | 21 | */ |
| ... | ... | @@ -23,36 +25,56 @@ public class JsonEvents implements Serializable |
| 23 | 25 | |
| 24 | 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 | 31 | private static final Pattern tokenPattern = Pattern.compile("^\\$\\{([a-zA-Z0-9_\\-\\.\\$]+)\\}$"); |
| 27 | 32 | |
| 33 | + /** | |
| 34 | + * Serialised obfusctation entries | |
| 35 | + */ | |
| 28 | 36 | @SerializedName("obfuscation") |
| 29 | 37 | private JsonObfuscationTable obfuscation; |
| 30 | 38 | |
| 39 | + /** | |
| 40 | + * Serialised method descriptors | |
| 41 | + */ | |
| 31 | 42 | @SerializedName("descriptors") |
| 32 | 43 | private List<JsonDescriptor> descriptors; |
| 33 | 44 | |
| 45 | + /** | |
| 46 | + * Serialised events | |
| 47 | + */ | |
| 34 | 48 | @SerializedName("events") |
| 35 | 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 | 66 | try |
| 42 | 67 | { |
| 68 | + // Parse the obfuscation table | |
| 43 | 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 | 75 | for (JsonEvent event : this.events) |
| 54 | 76 | { |
| 55 | - event.parse(this); | |
| 77 | + event.parse(this.methods); | |
| 56 | 78 | } |
| 57 | 79 | } |
| 58 | 80 | catch (InvalidEventJsonException ex) |
| ... | ... | @@ -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 | 114 | public void register(ModEventInjectionTransformer transformer) |
| 69 | 115 | { |
| 70 | 116 | for (JsonEvent event : this.events) |
| ... | ... | @@ -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 | 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
| 9 | 9 | import com.mumfrey.liteloader.transformers.event.inject.BeforeInvoke; |
| 10 | 10 | import com.mumfrey.liteloader.transformers.event.inject.BeforeReturn; |
| 11 | +import com.mumfrey.liteloader.transformers.event.inject.BeforeStringInvoke; | |
| 11 | 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 | 19 | public class JsonInjection implements Serializable |
| 14 | 20 | { |
| 15 | 21 | private static final long serialVersionUID = 1L; |
| 16 | 22 | |
| 23 | + /** | |
| 24 | + * Method to inject into | |
| 25 | + */ | |
| 17 | 26 | @SerializedName("method") |
| 18 | 27 | private String methodName; |
| 19 | 28 | |
| 29 | + /** | |
| 30 | + * Type of injection point | |
| 31 | + */ | |
| 20 | 32 | @SerializedName("type") |
| 21 | 33 | private JsonInjectionType type; |
| 22 | 34 | |
| 35 | + /** | |
| 36 | + * Shift type (optional) | |
| 37 | + */ | |
| 23 | 38 | @SerializedName("shift") |
| 24 | 39 | private JsonInjectionShiftType shift; |
| 25 | 40 | |
| 41 | + /** | |
| 42 | + * Target method to search for when using INVOKE and INVOKESTRING | |
| 43 | + */ | |
| 26 | 44 | @SerializedName("target") |
| 27 | 45 | private String target; |
| 28 | 46 | |
| 47 | + /** | |
| 48 | + * Ordinal to use when using INVOKE and INVOKESTRING | |
| 49 | + */ | |
| 29 | 50 | @SerializedName("ordinal") |
| 30 | 51 | private int ordinal = -1; |
| 31 | 52 | |
| 53 | + /** | |
| 54 | + * InjectionPoint class to use for CUSTOM | |
| 55 | + */ | |
| 32 | 56 | @SerializedName("class") |
| 33 | 57 | private String className; |
| 34 | 58 | |
| 59 | + /** | |
| 60 | + * Constructor arguments to pass wehn using CUSTOM | |
| 61 | + */ | |
| 35 | 62 | @SerializedName("args") |
| 36 | 63 | private Object[] args; |
| 37 | 64 | |
| ... | ... | @@ -49,24 +76,26 @@ public class JsonInjection implements Serializable |
| 49 | 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 | 92 | switch (this.type) |
| 66 | 93 | { |
| 67 | 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 | 100 | case RETURN: |
| 72 | 101 | return this.applyShift(new BeforeReturn(this.ordinal)); |
| ... | ... | @@ -95,6 +124,14 @@ public class JsonInjection implements Serializable |
| 95 | 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 | 135 | private String getTarget() |
| 99 | 136 | { |
| 100 | 137 | if (this.target != null && this.shift == null) | ... | ... |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonInjectionType.java
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 | 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 | 9 | import com.mumfrey.liteloader.core.runtime.Obf; |
| 10 | 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 | 18 | public class JsonObfuscationTable implements Serializable |
| 13 | 19 | { |
| 14 | 20 | private static final long serialVersionUID = 1L; |
| ... | ... | @@ -22,10 +28,14 @@ public class JsonObfuscationTable implements Serializable |
| 22 | 28 | @SerializedName("fields") |
| 23 | 29 | private List<JsonObf> jsonFields; |
| 24 | 30 | |
| 31 | + // Parsed values | |
| 25 | 32 | private transient Map<String, Obf> classObfs = new HashMap<String, Obf>(); |
| 26 | 33 | private transient Map<String, Obf> methodObfs = new HashMap<String, Obf>(); |
| 27 | 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 | 39 | public void parse() |
| 30 | 40 | { |
| 31 | 41 | if (this.jsonClasses != null) |
| ... | ... | @@ -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 | 69 | public Object parseType(String token) |
| 57 | 70 | { |
| 58 | 71 | token = token.replace(" ", "").trim(); |
| ... | ... | @@ -76,16 +89,28 @@ public class JsonObfuscationTable implements Serializable |
| 76 | 89 | return this.parseClass(token); |
| 77 | 90 | } |
| 78 | 91 | |
| 92 | + /** | |
| 93 | + * @param token | |
| 94 | + * @return | |
| 95 | + */ | |
| 79 | 96 | public Obf parseClass(String token) |
| 80 | 97 | { |
| 81 | 98 | return this.parseObf(token, this.classObfs); |
| 82 | 99 | } |
| 83 | 100 | |
| 101 | + /** | |
| 102 | + * @param token | |
| 103 | + * @return | |
| 104 | + */ | |
| 84 | 105 | public Obf parseMethod(String token) |
| 85 | 106 | { |
| 86 | 107 | return this.parseObf(token, this.methodObfs); |
| 87 | 108 | } |
| 88 | 109 | |
| 110 | + /** | |
| 111 | + * @param token | |
| 112 | + * @return | |
| 113 | + */ | |
| 89 | 114 | public Obf parseField(String token) |
| 90 | 115 | { |
| 91 | 116 | return this.parseObf(token, this.fieldObfs); |
| ... | ... | @@ -119,7 +144,7 @@ public class JsonObfuscationTable implements Serializable |
| 119 | 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 | 150 | return new JsonObf.Mapping(token, token, token); | ... | ... |