From b57bd533f48e3cbe3087fbf00dd5345725cf9757 Mon Sep 17 00:00:00 2001 From: LlamaLad7 Date: Tue, 21 May 2024 22:51:14 +0100 Subject: [PATCH] Change: Add stack checking to old `Target#findInitNodeFor` overload and un-deprecate it. The only reason MixinExtras uses this method is to match Redirect's behaviour, so I would like it to be kept in line with that. Additionally, there is nothing wrong with not checking the desc as long as you've definitely found the right `NEW` insn, which the injection point handles itself. --- .../asm/mixin/injection/struct/Target.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java index 9e2203c77..f4d47a167 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java @@ -638,22 +638,19 @@ public Iterator iterator() { * * @param newNode NEW insn * @return INVOKESPECIAL opcode of ctor, or null if not found - * - * @deprecated Use {@link #findInitNodeFor(TypeInsnNode, String)} instead: - * this method only matches the first matching <init> - * after the specified NEW, it also does not filter based on - * the descriptor passed into BeforeNew. */ - @Deprecated public MethodInsnNode findInitNodeFor(TypeInsnNode newNode) { int start = this.indexOf(newNode); + int depth = 0; for (Iterator iter = this.insns.iterator(start); iter.hasNext();) { AbstractInsnNode insn = iter.next(); if (insn instanceof MethodInsnNode && insn.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode methodNode = (MethodInsnNode)insn; - if (Constants.CTOR.equals(methodNode.name) && methodNode.owner.equals(newNode.desc)) { + if (Constants.CTOR.equals(methodNode.name) && --depth == 0 && methodNode.owner.equals(newNode.desc)) { return methodNode; } + } else if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW) { + depth++; } } return null;