javassist.expr.MethodCall Java Examples
The following examples show how to use
javassist.expr.MethodCall.
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 |
@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: TrueDamagePatch.java From jorbs-spire-mod with MIT License | 6 votes |
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 #3
Source File: InvisiblePowerPatch.java From StSLib with MIT License | 6 votes |
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 #4
Source File: BranchingUpgradesPatch.java From StSLib with MIT License | 6 votes |
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 #5
Source File: SneckoPatch.java From StSLib with MIT License | 6 votes |
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 #6
Source File: MainMenuModList.java From ModTheSpire with MIT License | 6 votes |
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: ReparentClassTransformer.java From DroidAssist with Apache License 2.0 | 6 votes |
@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 #8
Source File: SaveBaseModBadges.java From ModTheSpire with MIT License | 5 votes |
public static ExprEditor Instrument() { return new ExprEditor() { @Override public void edit(MethodCall m) throws CannotCompileException { if (m.getMethodName().equals("add")) { m.replace("$_ = true;"); } } }; }
Example #9
Source File: TopPanelModList.java From ModTheSpire with MIT License | 5 votes |
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 #10
Source File: UseDazed.java From FruityMod-StS with MIT License | 5 votes |
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 #11
Source File: BetterOnLoseHpPatch.java From StSLib with MIT License | 5 votes |
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 #12
Source File: BranchingUpgradesPatch.java From StSLib with MIT License | 5 votes |
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 #13
Source File: SoulboundPatch.java From StSLib with MIT License | 5 votes |
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 #14
Source File: InvisiblePowerPatch.java From StSLib with MIT License | 5 votes |
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 #15
Source File: CanUseDazed.java From FruityMod-StS with MIT License | 5 votes |
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 #16
Source File: StunMonsterPatch.java From StSLib with MIT License | 5 votes |
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 #17
Source File: EntombedPatch.java From jorbs-spire-mod with MIT License | 5 votes |
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: MagicMirrorPatch.java From jorbs-spire-mod with MIT License | 5 votes |
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 #19
Source File: CutsceneMultiScreenPatch.java From jorbs-spire-mod with MIT License | 5 votes |
public static ExprEditor Instrument() { return new ExprEditor() { @Override public void edit(MethodCall methodCall) throws CannotCompileException { if (methodCall.getClassName().equals(CutscenePanel.class.getName()) && methodCall.getMethodName().equals("activate")) { methodCall.replace(String.format( "{ %1$s.fadePanelsOnPreviousScreen(this.panels, $0); $_ = $proceed($$); }", CutsceneFadeOlderPanelsOnNewScreen.class.getName())); } } }; }
Example #20
Source File: MethodCallTimingTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
@Override protected boolean execute( CtClass inputClass, String inputClassName, MethodCall methodCall) throws CannotCompileException, NotFoundException { if (methodCall.isSuper()) { return false; } String insnClassName = methodCall.getClassName(); String insnName = methodCall.getMethodName(); String insnSignature = methodCall.getSignature(); CtClass insnClass = tryGetClass(insnClassName, inputClassName); if (insnClass == null) { return false; } if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) { return false; } String target = getTarget(); String statement = getDefaultTimingStatement(isVoidSourceReturnType(), target); String replacement = replaceInstrument(methodCall, statement); Logger.warning(getPrettyName() + " by: " + replacement + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber()); return true; }
Example #21
Source File: CustomPotionDrinkPatch.java From jorbs-spire-mod with MIT License | 5 votes |
public static ExprEditor Instrument() { return new ExprEditor() { @Override public void edit(MethodCall methodCall) throws CannotCompileException { if (methodCall.getClassName().equals(SoundMaster.class.getName()) && methodCall.getMethodName().equals("play")) { methodCall.replace(String.format( "{ $_ = $proceed(%1$s.updateWithCustomHoverSound($1, p)); }", CustomPotionDrinkPatch.class.getName())); } } }; }
Example #22
Source File: CustomPotionDrinkPatch.java From jorbs-spire-mod with MIT License | 5 votes |
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 #23
Source File: AgentTransformer.java From ns4_gear_watchdog with Apache License 2.0 | 5 votes |
private void insertMethod(CtMethod method) throws NotFoundException, CannotCompileException { //situation 1:添加监控时间 method.instrument(new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { m.replace("{ long stime = System.currentTimeMillis(); $_ = $proceed($$);System.out.println(\"" + m.getClassName() + "." + m.getMethodName() + " cost:\" + (System.currentTimeMillis() - stime) + \" ms\");}"); } }); //situation 2:在方法体前后语句 //method.insertBefore("System.out.println(\"enter method\");"); //method.insertAfter("System.out.println(\"leave method\");"); }
Example #24
Source File: MethodCallTryCatchTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
@Override protected boolean execute( CtClass inputClass, String inputClassName, MethodCall methodCall) throws CannotCompileException, NotFoundException { if (methodCall.isSuper()) { return false; } String insnClassName = methodCall.getClassName(); String insnName = methodCall.getMethodName(); String insnSignature = methodCall.getSignature(); CtClass insnClass = tryGetClass(insnClassName, inputClassName); if (insnClass == null) { return false; } if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) { return false; } String target = getTarget(); String proceed = isVoidSourceReturnType() ? "$proceed($$);" : "$_ =$proceed($$);"; String statement = "try{" + proceed + "} catch (" + getException() + " e) {" + target.replace("$e", "e") + "}"; String replacement = replaceInstrument(methodCall, statement); Logger.warning(getPrettyName() + " by: " + replacement + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber()); return true; }
Example #25
Source File: SourceTargetTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
protected String getReplaceStatement(MethodCall methodCall, String statement) { int line = methodCall.getLineNumber(); String name = methodCall.getMethodName(); String className = methodCall.getClassName(); String fileName = methodCall.getFileName(); return getReplaceStatement(statement, line, name, className, fileName); }
Example #26
Source File: SourceTargetTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
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 #27
Source File: MethodCallReplaceTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
@Override protected boolean execute( CtClass inputClass, String inputClassName, MethodCall methodCall) throws CannotCompileException, NotFoundException { if (methodCall.isSuper()) { return false; } String insnClassName = methodCall.getClassName(); String insnName = methodCall.getMethodName(); String insnSignature = methodCall.getSignature(); CtClass insnClass = tryGetClass(insnClassName, inputClassName); if (insnClass == null) { return false; } if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) { return false; } String target = getTarget(); String replacement = replaceInstrument(methodCall, target); Logger.warning(getPrettyName() + " by: " + replacement + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber()); return true; }
Example #28
Source File: ExprExecTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
protected boolean execute( CtClass inputClass, String inputClassName, MethodCall methodCall) throws CannotCompileException, NotFoundException { return false; }
Example #29
Source File: MethodCallAroundTransformer.java From DroidAssist with Apache License 2.0 | 5 votes |
@Override protected boolean execute( CtClass inputClass, String inputClassName, MethodCall methodCall) throws CannotCompileException, NotFoundException { if (methodCall.isSuper()) { return false; } String insnClassName = methodCall.getClassName(); String insnName = methodCall.getMethodName(); String insnSignature = methodCall.getSignature(); CtClass insnClass = tryGetClass(insnClassName, inputClassName); if (insnClass == null) { return false; } if (!isMatchSourceMethod(insnClass, insnName, insnSignature)) { return false; } String before = getTargetBefore(); String after = getTargetAfter(); Logger.warning(getPrettyName() + " by: " + before + " $proceed($$) " + after + " at " + inputClassName + ".java" + ":" + methodCall.getLineNumber()); String proceed = isVoidSourceReturnType() ? "$proceed($$);" : "$_ =$proceed($$);"; String statement = "{" + before + proceed + after + "}"; replaceInstrument(methodCall, statement); return true; }
Example #30
Source File: EphemeralPatch.java From jorbs-spire-mod with MIT License | 5 votes |
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())); } } }; }