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

The following examples show how to use javassist.expr.FieldAccess#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: 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 2
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, FieldAccess fieldAccess)
        throws CannotCompileException, NotFoundException {
    if (!fieldAccess.isStatic()
            && fieldAccess.getClassName().equals(getSourceDeclaringClassName())) {

        Logger.warning(getCategoryName() + " reset parent for class " + inputClassName
                + " adapt super field access" +
                " at " + inputClassName + ".java" + ":" + fieldAccess.getLineNumber());

        String fieldName = fieldAccess.getFieldName();
        if (fieldAccess.isReader()) {
            fieldAccess.replace("$_=super." + fieldName + ";");
        } else if (fieldAccess.isWriter()) {
            fieldAccess.replace("super." + fieldName + "=$1;");
        }
        return true;
    }
    return false;
}
 
Example 3
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 4
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 5
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 6
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 7
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 8
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 9
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 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 {
            // 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 11
Source File: NeowEventPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
    return new ExprEditor() {
        public void edit(FieldAccess methodCall) throws CannotCompileException {
            if (methodCall.getClassName().equals(NeowEvent.class.getName()) && methodCall.getFieldName().equals("waitingToSave")) {
                methodCall.replace(String.format(
                        "{ %1$s.doAtStartOfAct(); $_ = $proceed($$); }",
                        AtStartOfActRelicSubscriber.class.getName()));
            }
        }
    };
}
 
Example 12
Source File: AbstractMonsterEscapeLeftPatch.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(Settings.class.getName()) && f.getFieldName().equals("scale")) {
                f.replace(String.format("{" +
                        "$_ = $proceed() * (%1$s.isLeftOfPlayer(this) ? -1.0F : 1.0F);" +
                        "}",
                        AbstractMonsterEscapeLeftPatch.class.getName()));
            }
        }
    };
}
 
Example 13
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 14
Source File: TrueDamagePatch.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 fa) throws CannotCompileException {
            // suppress the initial Intangible effect on info.output
            if (fa.getClassName().equals(DamageInfo.class.getName()) &&
                fa.getFieldName().equals("output") &&
                fa.isWriter())
            {
                fa.replace(String.format("{ if (!%1$s.isTrueDamage($0)) { $_ = $proceed($$); } }", TrueDamagePatchName));
            }
        }

        @Override
        public void edit(MethodCall mc) throws CannotCompileException {
            String cls = mc.getClassName();
            String method = mc.getMethodName();

            // clamp the onAttackToChangeDamage, onAttackedToChangeDamage, and onAttacked calls
            if ((cls.equals(AbstractPower.class.getName()) || cls.equals(AbstractRelic.class.getName())) &&
                (method.equals("onAttackToChangeDamage") || method.equals("onAttackedToChangeDamage") || method.equals("onAttacked")))
            {
                mc.replace(String.format("{ $_ = %1$s.updateDamage($1, $2, $proceed($$)); }", TrueDamagePatchName));
                return;
            }
        }
    };
}
 
Example 15
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 16
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 17
Source File: SourceTargetTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
protected String replaceInstrument(
        FieldAccess fieldAccess,
        String statement)
        throws CannotCompileException {
    String replacement = getReplaceStatement(fieldAccess, statement);
    try {
        String s = replacement.replaceAll("\n", "");
        fieldAccess.replace(s);
    } catch (CannotCompileException e) {
        Logger.error("Replace field access instrument error with statement: "
                + statement + "\n", e);
        throw e;
    }
    return replacement;
}
 
Example 18
Source File: CardBannerImageRarityPatch.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
@Override
public void edit(FieldAccess fieldAccess) throws CannotCompileException {
    if (fieldAccess.getClassName().equals(AbstractCard.class.getName()) && fieldAccess.getFieldName().equals("rarity")) {
        fieldAccess.replace(String.format("{ $_ = %1$s.getBannerRarity($0); }", CardBannerImageRarityPatch.class.getName()));
    }
}