Commit 7299229f5debdced46fe260a21315eb7190e9061

Authored by Mumfrey
1 parent 617b2c8f

minor fixes for BeforeInvoke when initialised using a MethodInfo

java/common/com/mumfrey/liteloader/transformers/event/inject/BeforeInvoke.java
... ... @@ -175,6 +175,16 @@ public class BeforeInvoke extends InjectionPoint
175 175 this.methodOwners = method.getOwners();
176 176 this.methodSignatures = method.getDescriptors();
177 177 this.ordinal = ordinal;
  178 +
  179 + for (int i = 0; i < this.methodOwners.length; i++)
  180 + {
  181 + if (this.methodOwners[i] != null) this.methodOwners[i] = this.methodOwners[i].replace('.', '/');
  182 + }
  183 +
  184 + for (int i = 0; i < this.methodSignatures.length; i++)
  185 + {
  186 + if (this.methodSignatures[i] != null) this.methodSignatures[i] = this.methodSignatures[i].replace('.', '/');
  187 + }
178 188 }
179 189  
180 190 public void setLogging(boolean logging)
... ... @@ -200,23 +210,25 @@ public class BeforeInvoke extends InjectionPoint
200 210 {
201 211 MethodInsnNode node = (MethodInsnNode)insn;
202 212  
203   - if (this.logging) LiteLoaderLogger.info("BeforeInvokeStrategy is considering invokation NAME=" + node.name + " DESC=" + node.desc + " OWNER=" + node.owner);
  213 + if (this.logging) LiteLoaderLogger.info("BeforeInvoke is considering invokation NAME=" + node.name + " DESC=" + node.desc + " OWNER=" + node.owner);
204 214  
205 215 int index = BeforeInvoke.arrayIndexOf(this.methodNames, node.name, -1);
206   - if (index > -1 && this.logging) LiteLoaderLogger.info("BeforeInvokeStrategy found a matching invoke, checking owner/signature...");
  216 + if (index > -1 && this.logging) LiteLoaderLogger.info("BeforeInvoke found a matching invoke, checking owner/signature...");
207 217  
208   - if (index > -1 && BeforeInvoke.arrayIndexOf(this.methodOwners, node.owner, index) == index && BeforeInvoke.arrayIndexOf(this.methodSignatures, node.desc, index) == index)
  218 + int ownerIndex = BeforeInvoke.arrayIndexOf(this.methodOwners, node.owner, index);
  219 + int descIndex = BeforeInvoke.arrayIndexOf(this.methodSignatures, node.desc, index);
  220 + if (index > -1 && ownerIndex == index && descIndex == index)
209 221 {
210   - if (this.logging) LiteLoaderLogger.info("BeforeInvokeStrategy found a matching invoke, checking ordinal...");
  222 + if (this.logging) LiteLoaderLogger.info("BeforeInvoke found a matching invoke, checking ordinal...");
211 223 if (this.ordinal == -1)
212 224 {
213   - if (this.logging) LiteLoaderLogger.info("BeforeInvokeStrategy found a matching invoke at ordinal %d", ordinal);
  225 + if (this.logging) LiteLoaderLogger.info("BeforeInvoke found a matching invoke at ordinal %d", ordinal);
214 226 nodes.add(node);
215 227 found = true;
216 228 }
217 229 else if (this.ordinal == ordinal)
218 230 {
219   - if (this.logging) LiteLoaderLogger.info("BeforeInvokeStrategy found a matching invoke at ordinal %d", ordinal);
  231 + if (this.logging) LiteLoaderLogger.info("BeforeInvoke found a matching invoke at ordinal %d", ordinal);
220 232 nodes.add(node);
221 233 return true;
222 234 }
... ... @@ -240,10 +252,11 @@ public class BeforeInvoke extends InjectionPoint
240 252 private static int arrayIndexOf(String[] haystack, String needle, int pos)
241 253 {
242 254 if (haystack == null) return pos;
  255 + if (pos > -1 && pos < haystack.length && needle.equals(haystack[pos])) return pos;
  256 +
243 257 for (int index = 0; index < haystack.length; index++)
244   - {
245 258 if (needle.equals(haystack[index])) return index;
246   - }
247   - return pos;
  259 +
  260 + return -1;
248 261 }
249 262 }
... ...