Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.evacipated.cardcrawl.modthespire;

import com.evacipated.cardcrawl.modthespire.classfilters.CardFilter;
import com.evacipated.cardcrawl.modthespire.classfilters.RelicFilter;
import org.clapper.util.classutil.*;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class CustomContent
{
public static List<String> find(ClassFilter typeFilter, URL[] urls) throws URISyntaxException
{
ClassFinder finder = new ClassFinder();
File[] files = new File[urls.length];
for (int i=0; i<urls.length; ++i) {
files[i] = new File(urls[i].toURI());
}
finder.add(files);

ClassFilter filter =
new AndClassFilter(
new NotClassFilter(new InterfaceOnlyClassFilter()),
new NotClassFilter(new AbstractClassFilter()),
typeFilter
);
Collection<ClassInfo> foundClasses = new ArrayList<>();
finder.findClasses(foundClasses, filter);

List<String> ret = new ArrayList<>();
for (ClassInfo classInfo : foundClasses) {
ret.add(classInfo.getClassName());
}
return ret;
}

public static List<String> findCards(URL[] urls) throws URISyntaxException
{
return find(new CardFilter(), urls);
}

public static List<String> findRelics(URL[] urls) throws URISyntaxException
{
return find(new RelicFilter(), urls);
}
}
10 changes: 9 additions & 1 deletion src/main/java/com/evacipated/cardcrawl/modthespire/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class Loader {
public static ModInfo[] MODINFOS;
public static URL[] MODONLYURLS;

public static List<String> MODCARDS;
public static List<String> MODRELICS;

private static Object ARGS;

public static void main(String[] args) {
Expand Down Expand Up @@ -90,12 +93,17 @@ public static void runMods(File[] modJars) {
Patcher.finalizePatches(loader);
Patcher.compilePatches(loader, ctClasses);

System.out.println("Finding cards...");
MODCARDS = CustomContent.findCards(modOnlyUrls);
System.out.println("Finding relics...");
MODRELICS = CustomContent.findRelics(modOnlyUrls);

System.out.printf("Patching enums...");
Patcher.patchEnums(loader, Loader.class.getResource(Loader.COREPATCHES_JAR));
// Patch SpireEnums from mods
Patcher.patchEnums(loader, Loader.MODONLYURLS);
System.out.println("Done.");

// Set Settings.isModded = true
System.out.printf("Setting isModded = true...");
System.out.flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.evacipated.cardcrawl.modthespire.classfilters;


public class CardFilter extends SuperClassNameFilter
{
public CardFilter()
{
super("com.megacrit.cardcrawl.cards.AbstractCard");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.evacipated.cardcrawl.modthespire.classfilters;

public class RelicFilter extends SuperClassNameFilter
{
public RelicFilter()
{
super("com.megacrit.cardcrawl.relics.AbstractRelic");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.evacipated.cardcrawl.modthespire.classfilters;

import org.clapper.util.classutil.ClassFilter;
import org.clapper.util.classutil.ClassFinder;
import org.clapper.util.classutil.ClassInfo;

public class SuperClassNameFilter implements ClassFilter
{
private final String baseClassName;

public SuperClassNameFilter(Class baseClass)
{
this(baseClass.getName());
}

public SuperClassNameFilter(String baseClassName)
{
this.baseClassName = baseClassName;
}

@Override
public boolean accept(ClassInfo classInfo, ClassFinder classFinder)
{
return baseClassName != null && baseClassName.equals(classInfo.getSuperClassName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.evacipated.cardcrawl.modthespire.patches.cards.AbstractCard;

import com.badlogic.gdx.graphics.Color;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.helpers.CardHelper;
import javassist.CannotCompileException;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;

import java.lang.reflect.Field;

@SpirePatch(
cls="com.megacrit.cardcrawl.cards.AbstractCard",
method="createCardImage"
)
public class CreateCardImage
{
public static void Prefix(Object __obj_instance)
{
AbstractCard card = (AbstractCard)__obj_instance;
switch (card.color) {
case RED:
case GREEN:
case BLUE:
case COLORLESS:
case CURSE:
return;
}

try {
// TODO: What is even the point of any of these fields?
// As far as I can tell, they are never used
Field bgColor = AbstractCard.class.getDeclaredField("bgColor");
bgColor.setAccessible(true);
bgColor.set(card, CardHelper.getColor(19.0F, 45.0F, 40.0F));

Field backColor = AbstractCard.class.getDeclaredField("backColor");
backColor.setAccessible(true);
backColor.set(card, CardHelper.getColor(32.0F, 91.0F, 43.0F));

Field frameColor = AbstractCard.class.getDeclaredField("frameColor");
frameColor.setAccessible(true);
frameColor.set(card, CardHelper.getColor(52.0F, 123.0F, 8.0F));

Field frameOutlineColor = AbstractCard.class.getDeclaredField("frameOutlineColor");
frameOutlineColor.setAccessible(true);
frameOutlineColor.set(card, new Color(1.0F, 0.75F, 0.43F, 1.0F));

Field descBoxColor = AbstractCard.class.getDeclaredField("descBoxColor");
descBoxColor.setAccessible(true);
descBoxColor.set(card, CardHelper.getColor(53.0F, 58.0F, 64.0F));
} catch (Exception e) {
e.printStackTrace();
}
}

// Stop needless logger errors
public static ExprEditor Instrument()
{
return new ExprEditor() {
@Override
public void edit(MethodCall m) throws CannotCompileException
{
if (m.getMethodName().equals("info")) {
m.replace("");
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.evacipated.cardcrawl.modthespire.patches.cards.AbstractCard;

import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import javassist.CannotCompileException;
import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess;
import javassist.expr.MethodCall;

@SpirePatch(
cls="com.megacrit.cardcrawl.cards.AbstractCard",
method="renderAttackBg"
)
public class RenderAttackBg
{
public static ExprEditor Instrument()
{
return new ExprEditor() {
@Override
public void edit(FieldAccess f) throws CannotCompileException
{
if (f.getClassName().equals("com.megacrit.cardcrawl.helpers.ImageMaster") && f.getFieldName().equals("CARD_SKILL_BG_BLACK")) {
f.replace("if (color != com.megacrit.cardcrawl.cards.AbstractCard.CardColor.CURSE) {" +
"$_ = com.megacrit.cardcrawl.helpers.ImageMaster.CARD_ATTACK_BG_BLUE;" +
"} else {" +
"$_ = $proceed();" +
"}");
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.evacipated.cardcrawl.modthespire.patches.cards.AbstractCard;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.helpers.ImageMaster;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@SpirePatch(
cls="com.megacrit.cardcrawl.cards.AbstractCard",
method="renderEnergy"
)
public class RenderEnergy
{
@SpireInsertPatch(
rloc=25,
localvars={"drawX", "drawY"}
)
public static void Insert(Object __obj_instance, Object sb, float drawX, float drawY)
{
AbstractCard card = (AbstractCard)__obj_instance;
switch (card.color) {
case RED:
case GREEN:
case BLUE:
case COLORLESS:
case CURSE:
return;
}

try {
Field renderColor = AbstractCard.class.getDeclaredField("renderColor");
renderColor.setAccessible(true);

Method renderHelper = AbstractCard.class.getDeclaredMethod("renderHelper", SpriteBatch.class, Color.class, Texture.class, float.class, float.class);
renderHelper.setAccessible(true);
renderHelper.invoke(card, sb, renderColor.get(card), ImageMaster.CARD_COLORLESS_ORB, drawX, drawY);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.evacipated.cardcrawl.modthespire.patches.cards.AbstractCard;

import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import javassist.CannotCompileException;
import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess;

@SpirePatch(
cls="com.megacrit.cardcrawl.cards.AbstractCard",
method="renderPowerBg"
)
public class RenderPowerBg
{
public static ExprEditor Instrument()
{
return new ExprEditor() {
@Override
public void edit(FieldAccess f) throws CannotCompileException
{
if (f.getClassName().equals("com.megacrit.cardcrawl.helpers.ImageMaster") && f.getFieldName().equals("CARD_SKILL_BG_BLACK")) {
f.replace("if (color != com.megacrit.cardcrawl.cards.AbstractCard.CardColor.CURSE) {" +
"$_ = com.megacrit.cardcrawl.helpers.ImageMaster.CARD_ATTACK_BG_BLUE;" +
"} else {" +
"$_ = $proceed();" +
"}");
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.evacipated.cardcrawl.modthespire.patches.cards.AbstractCard;

import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import javassist.CannotCompileException;
import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess;

@SpirePatch(
cls="com.megacrit.cardcrawl.cards.AbstractCard",
method="renderSkillBg"
)
public class RenderSkillBg
{
public static ExprEditor Instrument()
{
return new ExprEditor() {
@Override
public void edit(FieldAccess f) throws CannotCompileException
{
if (f.getClassName().equals("com.megacrit.cardcrawl.helpers.ImageMaster") && f.getFieldName().equals("CARD_SKILL_BG_BLACK")) {
f.replace("if (color != com.megacrit.cardcrawl.cards.AbstractCard.CardColor.CURSE) {" +
"$_ = com.megacrit.cardcrawl.helpers.ImageMaster.CARD_ATTACK_BG_BLUE;" +
"} else {" +
"$_ = $proceed();" +
"}");
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.evacipated.cardcrawl.modthespire.patches.helpers.CardLibrary;

import com.evacipated.cardcrawl.modthespire.Loader;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.helpers.CardLibrary;

@SpirePatch(
cls="com.megacrit.cardcrawl.helpers.CardLibrary",
method="initialize"
)
public class AddCustomCards
{
@SpireInsertPatch(
rloc=9
)
public static void Insert()
{
ClassLoader loader = CardLibrary.class.getClassLoader();

for (String cardClassName : Loader.MODCARDS) {
try {
AbstractCard card = (AbstractCard) loader.loadClass(cardClassName).newInstance();
CardLibrary.add(card);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}
Loading