javassist.expr.ExprEditor Java Examples

The following examples show how to use javassist.expr.ExprEditor. 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: Dagger2Extension.java    From EasyMVP with Apache License 2.0 6 votes vote down vote up
private void replacePresenterWithPresenterProvider(CtClass membersInjectorClass,
                                                   final String presenterFieldName,
                                                   final String presenterProviderField)
        throws NotFoundException, CannotCompileException {
    CtMethod injectMembers = membersInjectorClass.getDeclaredMethod("injectMembers");
    final int[] injectedPresenterLineNumber = {-1};
    injectMembers.instrument(new ExprEditor() {
        @Override
        public void edit(FieldAccess f) throws CannotCompileException {
            if (f.isWriter() && f.getFieldName().equals(presenterFieldName)) {
                injectedPresenterLineNumber[0] = f.getLineNumber();
            }
        }
    });
    if (injectedPresenterLineNumber[0] != -1) {
        deleteLine(injectMembers, injectedPresenterLineNumber[0]);
        fillPresenterProviderInView(injectMembers, presenterProviderField, injectedPresenterLineNumber[0]);
        viewDelegateBinder.log("DaggerExtension",
                               "Remove presenter injection from " +
                                       membersInjectorClass.getSimpleName() +
                                       " and replace with our presenterProvider ");
        viewDelegateBinder.writeClass(membersInjectorClass);
    }
}
 
Example #2
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 #3
Source File: SneckoPatch.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.getClassName().equals("com.megacrit.cardcrawl.helpers.FontHelper") && m.getMethodName().equals("renderFont")) {
                m.replace("if (((Boolean) com.evacipated.cardcrawl.mod.stslib.fields.cards.AbstractCard.SneckoField.snecko.get(card)).booleanValue()) {" +
                        "$3 = \"?\";" +
                        "$4 = 674.0f * com.megacrit.cardcrawl.core.Settings.scale;" +
                        "}" +
                        "$_ = $proceed($$);");
            }
        }
    };
}
 
Example #4
Source File: ActionShouldPersistPostCombatPatch.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(Instanceof instanceOf) throws CannotCompileException {
            try {
                if (instanceOf.getType().getName().equals(HealAction.class.getName())) {
                    instanceOf.replace(String.format(
                            "{ $_ = (%1$s.shouldPersistPostCombat($1) || $proceed($$)); }",
                            ActionShouldPersistPostCombatPatch.class.getName()));
                }
            } catch (NotFoundException e) {
                throw new CannotCompileException(e);
            }
        }
    };
}
 
Example #5
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 #6
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 #7
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 #8
Source File: BottledMemoryPatch.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(FieldAccess fieldAccess) throws CannotCompileException {
            // Transforms `!inBottleTornado` into `!(inBottleTornado || inBottleMemory)`
            // Logically equivalent to `!inBottleTornado && !inBottleMemory`
            if (fieldAccess.getClassName().equals(AbstractCard.class.getName()) && fieldAccess.getFieldName().equals("inBottleTornado")) {
                fieldAccess.replace("{ $_ = ($proceed() || stsjorbsmod.patches.BottledMemoryPatch.isInBottleMemory(c)); }");
            }
        }
    };
}
 
Example #9
Source File: VoiceoverMasterPatch.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(FieldAccess fieldAccess) throws CannotCompileException {
            if (fieldAccess.getClassName().equals(Settings.class.getName()) && fieldAccess.getFieldName().equals("MASTER_VOLUME")) {
                fieldAccess.replace("{" +
                        "$_ = ($proceed() * " + VoiceoverMaster.class.getName() +".MASTER_DAMPENING_FACTOR);" +
                        "}");
            }
        }
    };
}
 
Example #10
Source File: BottledMemoryPatch.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(FieldAccess fieldAccess) throws CannotCompileException {
            // replacing the "((AbstractCard)AbstractDungeon.player.masterDeck.group.get(i)).inBottleFlame"
            // expression in the original if statement to add in an "|| card.hasTag(LEGENDARY)"
            if (fieldAccess.getClassName().equals(AbstractCard.class.getName()) && fieldAccess.getFieldName().equals("inBottleFlame")) {
                fieldAccess.replace("{ $_ = ($proceed() || stsjorbsmod.patches.BottledMemoryPatch.isInBottleMemory($0)); }");
            }
        }
    };
}
 
Example #11
Source File: BurningPatch.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(FieldAccess f) throws CannotCompileException {
            if (f.getClassName().contains(AbstractCreature.class.getName()) && f.getFieldName().equals("blockColor")) {
                f.replace(String.format("{ $_ = %1$s.renderBurningBlock(this, $proceed()); }",
                        BurningPatch.class.getName()));
            }
        }
    };
}
 
Example #12
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 #13
Source File: RetainHpPatch.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(FieldAccess fieldAccess) throws CannotCompileException {
            if (fieldAccess.getClassName().equals(AbstractMonster.class.getName()) && fieldAccess.getFieldName().equals("lastDamageTaken")) {
                fieldAccess.replace("{ damageAmount = " + RetainHpPatch.class.getName() + ".retainHP(this, info, damageAmount); $proceed($$); }");
            }
        }
    };
}
 
Example #14
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 #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: SoulboundPatch.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("java.util.ArrayList") && m.getMethodName().equals("add"))
                    || (m.getClassName().equals("com.megacrit.cardcrawl.cards.CardGroup") && m.getMethodName().equals("removeCard"))) {
                m.replace("if (com.evacipated.cardcrawl.mod.stslib.patches.SoulboundPatch.FountainOfCurseRemoval_buttonEffect.canRemove(i))" +
                        "{ $_ = $proceed($$); }");
            }
        }
    };
}
 
Example #17
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 #18
Source File: BranchingUpgradesPatch.java    From StSLib with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        private boolean accessedUpgradeHb = false;
        @Override
        public void edit(FieldAccess f) throws CannotCompileException
        {
            if (accessedUpgradeHb && f.getFieldName().equals("hovered")) {
                f.replace("$_ = $proceed($$) || ((" + Hitbox.class.getName() + ") " + BranchUpgradeButton.class.getName() + ".branchUpgradeHb.get(this)).hovered;");
                accessedUpgradeHb = false;
            } else if (f.getFieldName().equals("upgradeHb")) {
                accessedUpgradeHb = true;
            }
        }
    };
}
 
Example #19
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 #20
Source File: InstrumentPatchInfo.java    From ModTheSpire with MIT License 5 votes vote down vote up
@Override
public void doPatch() throws PatchingException
{
    try {
        ExprEditor exprEditor = (ExprEditor) method.invoke(null);
        ctMethodToPatch.instrument(exprEditor);
    } catch (IllegalAccessException | CannotCompileException | InvocationTargetException e) {
        throw new PatchingException(e);
    }
}
 
Example #21
Source File: TopPanelModList.java    From ModTheSpire 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.getMethodName().equals("renderFontRightTopAligned")) {
                ++count;
                if (count == 2) {
                    m.replace(
                        "{" +
                            String.format("$5 -= 24 * %s.scale;", Settings.class.getName()) +
                            "$_ = $proceed($$);" +
                            "}"
                    );
                }
            }
        }

        @Override
        public void edit(FieldAccess f) throws CannotCompileException
        {
            if (f.getFieldName().equals("VERSION_NUM")) {
                f.replace(String.format("$_ = %s.alterVersion2($proceed($$));", MainMenuModList.class.getName()));
            }
        }
    };
}
 
Example #22
Source File: AlwaysEnableCustomMode.java    From ModTheSpire with MIT License 5 votes vote down vote up
public static ExprEditor Instrument()
{
    return new ExprEditor() {
        @Override
        public void edit(FieldAccess f) throws CannotCompileException
        {
            if (f.getClassName().equals("com.megacrit.cardcrawl.screens.stats.CharStat")
                && f.getFieldName().equals("highestDaily")) {
                f.replace("$_ = 1;");
            }
        }
    };
}
 
Example #23
Source File: SaveBaseModBadges.java    From ModTheSpire 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("add")) {
                m.replace("$_ = true;");
            }
        }
    };
}
 
Example #24
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 #25
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 #26
Source File: TipHelperTouchScreenFix.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(FieldAccess f) throws CannotCompileException {
            if (f.getClassName().contains(AbstractPlayer.class.getName()) && f.getFieldName().equals("isHoveringDropZone")) {
                f.replace(String.format("{" +
                                "$_ = (%1$s.isInHoverTargetMode($0) && $proceed());" +
                                "}",
                        TipHelperTouchScreenFix.class.getName()));
            }
        }
    };
}
 
Example #27
Source File: EphemeralPatch.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(FieldAccess f) throws CannotCompileException {
            if (f.getClassName().contains(AbstractPlayer.class.getName()) && f.getFieldName().equals("discardPile")) {
                f.replace(String.format("{" +
                                "$_ = (%1$s.isEphemeral(this.card) ? $0.exhaustPile : $proceed());" +
                                "}",
                        EphemeralPatch.class.getName()));
            }
        }
    };
}
 
Example #28
Source File: EphemeralPatch.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 m) throws CannotCompileException {
            if (m.getClassName().contains(SoulGroup.class.getName()) && m.getMethodName().equals("discard")) {
                m.replace(String.format("{" +
                                "if (%1$s.isEphemeral(this.card)) { %1$s.exhaustVisual($1); }" +
                                "else { $_ = $proceed($$); }" +
                                "}",
                        EphemeralPatch.class.getName()));
            }
        }
    };
}
 
Example #29
Source File: AtStartOfTurnPreLoseBlockPatch.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(FieldAccess f) throws CannotCompileException {
            if (f.getClassName().contains(AbstractDungeon.class.getName()) && f.getFieldName().equals("topLevelEffects")) {
                f.replace(String.format("{ %1$s.applyStartOfTurnPreLoseBlockPowers(); $_ = $proceed(); }",
                        AtStartOfTurnPreLoseBlockPatch.class.getName()));
            }
        }
    };
}
 
Example #30
Source File: ExertedPatch.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.isExerted($1)) { $_ = $proceed($$); } }", ExertedPatch.class.getName()));
            }
        }
    };
}