Java Code Examples for javassist.expr.MethodCall#replace()

The following examples show how to use javassist.expr.MethodCall#replace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AfterBurner.java    From afterburner with Apache License 2.0 6 votes vote down vote up
@Override
public void edit(MethodCall m) throws CannotCompileException {
    if (m.getMethodName().equals(insertionMethod)) {

        String origMethodCall = "$_ = $proceed($$);;\n";
        if (insertAfter) {
            origMethodCall = origMethodCall + bodyToInsert;
        } else {
            origMethodCall = bodyToInsert + origMethodCall;
        }

        log.info("Injected : " + origMethodCall);
        log.info("Class " + classToTransform.getName() + " has been enhanced.");
        m.replace(origMethodCall);
        isSuccessful = true;
    }
}
 
Example 2
Source File: InvisiblePowerPatch.java    From StSLib with MIT License 6 votes vote down vote up
public static ExprEditor Instrument()
{
    return new ExprEditor()
    {
        @Override
        public void edit(MethodCall m) throws CannotCompileException
        {
            if (m.getMethodName().equals("renderIcons") || m.getMethodName().equals("renderAmount")) {
                m.replace("if (p instanceof " + InvisiblePower.class.getName() + ") {" +
                        "offset -= POWER_ICON_PADDING_X;" +
                        "} else {" +
                        "$proceed($$);" +
                        "}");
            }
        }
    };
}
 
Example 3
Source File: BranchingUpgradesPatch.java    From StSLib with MIT License 6 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        private int count = 0;
        @Override
        public void edit(MethodCall m) throws CannotCompileException
        {
            if (m.getClassName().equals(SpriteBatch.class.getName()) && m.getMethodName().equals("draw")) {
                if (count != 0) {
                    m.replace("if (forUpgrade && hoveredCard instanceof " + BranchingUpgradesCard.class.getName() + ") {" +
                            "$10 = 45f;" +
                            "$3 += 64f * " + Settings.class.getName() + ".scale *" + count + ";" +
                            "$_ = $proceed($$);" +
                            "$10 = -45f;" +
                            "$3 -= 2 * 64f * " + Settings.class.getName() + ".scale *" + count + ";" +
                            "}" +
                            "$_ = $proceed($$);");
                }
                ++count;
            }
        }
    };
}
 
Example 4
Source File: TrueDamagePatch.java    From jorbs-spire-mod with MIT License 6 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall mc) throws CannotCompileException {
            String cls = mc.getClassName();
            String method = mc.getMethodName();

            // Clamp all the damage modifier hooks with first parameter of "float tmp"
            if ((
                    cls.equals(AbstractRelic.class.getName()) ||
                    cls.equals(AbstractPower.class.getName()) ||
                    cls.equals(AbstractStance.class.getName())
                ) && (
                    method.equals("atDamageModify") ||
                    method.equals("atDamageGive") ||
                    method.equals("atDamageReceive") ||
                    method.equals("atDamageFinalGive") ||
                    method.equals("atDamageFinalReceive")
            )) {
                mc.replace(String.format("{ $_ = %1$s.updateDamage(this, $1, $proceed($$)); }", TrueDamagePatchName));
            }
        }
    };
}
 
Example 5
Source File: ReparentClassTransformer.java    From DroidAssist with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean execute(CtClass inputClass, String inputClassName, MethodCall methodCall)
        throws CannotCompileException, NotFoundException {
    if (methodCall.isSuper()) {
        String signature = methodCall.getSignature();
        boolean voidType =
                Descriptor.getReturnType(signature, classPool) == CtClass.voidType;
        String methodName = methodCall.getMethodName();

        Logger.warning(getCategoryName() + " reset parent for class " + inputClassName
                + " adapt super method call" +
                " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber());

        methodCall.replace((!voidType ? "$_=" : "") + "super." + methodName + "($$);");
        return true;
    }
    return false;
}
 
Example 6
Source File: MainMenuModList.java    From ModTheSpire with MIT License 6 votes vote down vote up
public static ExprEditor Instrument()
{
    return new ExprEditor() {
        @Override
        public void edit(FieldAccess f) throws CannotCompileException
        {
            if (f.getFieldName().equals("VERSION_INFO")) {
                f.replace(String.format("$_ = %s.alterVersion($proceed($$));", MainMenuModList.class.getName()));
            }
        }

        @Override
        public void edit(MethodCall m) throws CannotCompileException
        {
            if (m.getMethodName().equals("renderSmartText")) {
                m.replace(
                    "{" +
                        String.format("$5 = %s.getSmartHeight($2, $3, $6, $7);", MainMenuModList.class.getName()) +
                        "$proceed($$);" +
                        "}"
                );
            }
        }
    };
}
 
Example 7
Source File: PlayableCursesPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        public void edit(MethodCall methodCall) throws CannotCompileException {
            if (methodCall.getClassName().equals(AbstractPlayer.class.getName()) &&
                    methodCall.getMethodName().equals("hasRelic")) {
                methodCall.replace(String.format(
                        "{ $_ = ($proceed($$) || (%1$s.isBlueCandle($1) && %1$s.hasCatharsisPower($0))); }",
                        PlayableCursesPatch.class.getName()));
            }
        }
    };
}
 
Example 8
Source File: CustomStackBehaviorPowerPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall methodCall) throws CannotCompileException {
        if (methodCall.getClassName().equals(AbstractPower.class.getName()) && methodCall.getMethodName().equals("stackPower")) {
            methodCall.replace("{ if (" + CustomStackBehaviorPowerPatch.class.getName() + ".patchedStackPower($0, this.powerToApply)) { $_ = $proceed($$); } }");
        }
        }
    };
}
 
Example 9
Source File: UseDazed.java    From FruityMod-StS with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        public void edit(MethodCall m) throws CannotCompileException {
            if (m.getMethodName().equals("addToTop")) {
                // pass the original argument (relicID) + this ($0 which is the AbstractCard)
                m.replace("{ fruitymod.SeekerMod.maybeUseDazed(this); }");
            }
        }
    };
}
 
Example 10
Source File: BetterOnLoseHpPatch.java    From StSLib with MIT License 5 votes vote down vote up
public static ExprEditor Instrument()
{
    return new ExprEditor() {
        @Override
        public void edit(MethodCall m) throws CannotCompileException
        {
            if (m.getClassName().equals(AbstractRelic.class.getName()) && m.getMethodName().equals("onLoseHp")) {
                m.replace("{" +
                        "damageAmount = " + BetterOnLoseHpPatch.class.getName() + ".Do(info, r, damageAmount);" +
                        "$proceed(damageAmount);" +
                        "}");
            }
        }
    };
}
 
Example 11
Source File: CardCrawlGamePatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        public void edit(MethodCall methodCall) throws CannotCompileException {
            if (methodCall.getClassName().equals(DungeonMapScreen.class.getName()) && methodCall.getMethodName().equals("open")) {
                methodCall.replace(String.format(
                        "{ %1$s.doAtStartOfAct(); $_ = $proceed($$); }",
                        AtStartOfActRelicSubscriber.class.getName()));
            }
        }
    };
}
 
Example 12
Source File: CustomPotionDrinkPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall methodCall) throws CannotCompileException {
            if (methodCall.getClassName().equals(AbstractPotion.class.getName()) && methodCall.getMethodName().equals("playPotionSound")) {
                methodCall.replace(String.format(
                        "{ if (! %1$s.playCustomPotionSound(potionToObtain)) { $proceed($$); } }",
                        CustomPotionDrinkPatch.class.getName()));
            }
        }
    };
}
 
Example 13
Source File: BranchingUpgradesPatch.java    From StSLib with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall m) throws CannotCompileException
        {
            if (m.getMethodName().equals("renderArrows")) {
                m.replace("$_ = $proceed($$);" +
                        "if (" + RenderBranchingUpgrade.class.getName() + ".Do(this, sb).isPresent()) {" +
                        "return;" +
                        "}");
            }
        }
    };
}
 
Example 14
Source File: CanUseDazed.java    From FruityMod-StS with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        public void edit(MethodCall m) throws CannotCompileException {
            if (m.getMethodName().equals("hasRelic")) {
                // pass the original argument (relicID) + this ($0 which is the AbstractCard)
                m.replace("{ $_ = fruitymod.SeekerMod.hasRelicCustom($1, this); }");
            }
        }
    };
}
 
Example 15
Source File: InvisiblePowerPatch.java    From StSLib with MIT License 5 votes vote down vote up
public static ExprEditor Instrument()
{
    return new ExprEditor()
    {
        private int count = 0;

        @Override
        public void edit(MethodCall m) throws CannotCompileException
        {
            if (m.getFileName().equals("AbstractMonster.java") || m.getFileName().equals("AbstractPlayer.java")) {
                if (m.getClassName().equals(ArrayList.class.getName()) && m.getMethodName().equals("add")) {
                    // Skip first instance of tips.add()
                    if (count > 0) {
                        m.replace("if (!(p instanceof " + InvisiblePower.class.getName() + ")) {" +
                                "$_ = $proceed($$);" +
                                "}");
                    }
                    ++count;
                }
            } else {
                if (m.getClassName().equals(ArrayList.class.getName()) && m.getMethodName().equals("add")) {
                    m.replace("if (!(p instanceof " + InvisiblePower.class.getName() + ")) {" +
                            "$_ = $proceed($$);" +
                            "}");
                }
            }
        }
    };
}
 
Example 16
Source File: MagicMirrorPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        public void edit(MethodCall m) throws CannotCompileException {
            if (m.getClassName().equals(AbstractMonster.class.getName()) && m.getMethodName().equals("takeTurn")) {
                m.replace(String.format("if (!%1$s.entangledAndAttacking($0)) {$_ = $proceed($$);}", MagicMirrorPatch.class.getName()));
            }
        }
    };
}
 
Example 17
Source File: EntombedPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall methodCall) throws CannotCompileException {
            if (methodCall.getClassName().equals(CardGroup.class.getName()) && methodCall.getMethodName().equals("addToTop")) {
                methodCall.replace(String.format("{ if (!%1$s.isEntombed($1)) { $_ = $proceed($$); } }", EntombedPatch.class.getName()));
            }
        }
    };
}
 
Example 18
Source File: StunMonsterPatch.java    From StSLib with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        @Override
        public void edit(MethodCall m) throws CannotCompileException {
            if (m.getClassName().equals("com.megacrit.cardcrawl.monsters.AbstractMonster")
                    && m.getMethodName().equals("takeTurn")) {
                m.replace("if (!m.hasPower(com.evacipated.cardcrawl.mod.stslib.powers.StunMonsterPower.POWER_ID)) {" +
                        "$_ = $proceed($$);" +
                        "}");
            }
        }
    };
}
 
Example 19
Source File: SourceTargetTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
protected String replaceInstrument(
        MethodCall methodCall,
        String statement)
        throws CannotCompileException {
    String replacement = getReplaceStatement(methodCall, statement);
    try {
        String s = replacement.replaceAll("\n", "");
        methodCall.replace(s);
    } catch (CannotCompileException e) {
        Logger.error("Replace method call instrument error with statement: "
                + statement + "\n", e);
        throw new DroidAssistBadStatementException(e);
    }
    return replacement;
}
 
Example 20
Source File: BottledRelic_onEquipPatch.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
@Override
public void edit(MethodCall methodCall) throws CannotCompileException {
    if (methodCall.getClassName().equals(CardGroup.class.getName()) && methodCall.getMethodName().equals("getPurgeableCards")) {
        methodCall.replace(String.format("{ $_ = %1$s.getCardsForBottling($proceed($$)); }", CardUtils.class.getName()));
    }
}