Skip to content

Commit

Permalink
Convert CardCrawlGame patches to new patching system
Browse files Browse the repository at this point in the history
  • Loading branch information
daviscook477 committed Mar 31, 2018
1 parent 937f6d8 commit ca2e7de
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import java.util.ArrayList;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.evacipated.cardcrawl.modthespire.lib.ByRef;
import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="createCharacter")
public class CreateCharacterSwitch {
public static final Logger logger = LogManager.getLogger(BaseMod.class.getName());

@SpireInsertPatch(rloc=16, localvars={"p"})
@SpireInsertPatch(localvars={"p"})
public static void Insert(Object selectionObj, @ByRef(type="com.megacrit.cardcrawl.characters.AbstractPlayer") Object[] pObj) {
logger.info("hooking into character creation");

Expand All @@ -30,4 +37,10 @@ public static void Insert(Object selectionObj, @ByRef(type="com.megacrit.cardcra
}
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.FieldAccessMatcher(
"com.megacrit.cardcrawl.characters.AbstractPlayer", "masterDeck");

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="render")
public class PostRenderHook {
@SpireInsertPatch(rloc=97, localvars={"sb"})

@SpireInsertPatch(localvars={"sb"})
public static void Insert(Object __obj_instance, SpriteBatch sb) {
BaseMod.publishPostRender(sb);
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.MethodCallMatcher(
SpriteBatch.class.getName(), "end");

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

import java.util.ArrayList;

import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.helpers.InputHelper;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="update")
public class PostUpdateHook {
@SpireInsertPatch(rloc=164)

@SpireInsertPatch
public static void Insert(Object __obj_instance) {
BaseMod.publishPostUpdate();
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.MethodCallMatcher(InputHelper.class.getName(), "updateLast");

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;
import java.util.ArrayList;

import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.helpers.InputHelper;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="update")
public class PreUpdateHook {
@SpireInsertPatch(rloc=18)
@SpireInsertPatch
public static void Insert(Object __obj_instance) {
BaseMod.publishPreUpdate();
}

private static int[] offset(int[] originalArr, int offset) {
int[] resultArr = new int[originalArr.length];
for (int i = 0; i < originalArr.length; i++) {
resultArr[i] = originalArr[i] + offset;
}
return resultArr;
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.MethodCallMatcher(InputHelper.class.getName(), "updateFirst");

int[] beforeLines = LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);

// offset by 1 to be called **after** the found method call
return offset(beforeLines, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.helpers.DrawMaster;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

@SpirePatch(cls = "com.megacrit.cardcrawl.core.CardCrawlGame", method = "render")
public class RenderHook {
@SpireInsertPatch(rloc = 49, localvars = { "sb" })

@SpireInsertPatch(localvars = { "sb" })
public static void Insert(Object __obj_instance, SpriteBatch sb) {
BaseMod.publishRender(sb);
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.MethodCallMatcher(DrawMaster.class.getName(), "draw");

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;


import basemod.BaseMod;
import java.util.ArrayList;

import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.screens.DungeonTransitionScreen;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="update")
public class StartActHook {
@SpireInsertPatch(rloc=154)

@SpireInsertPatch
public static void Insert(Object __obj_instance) {
if (CardCrawlGame.dungeonTransitionScreen.levelName.equals("Exordium")) {
BaseMod.publishPreStartGame();
}

BaseMod.publishStartAct();
}

private static int[] offset(int[] originalArr, int offset) {
int[] resultArr = new int[originalArr.length];
for (int i = 0; i < originalArr.length; i++) {
resultArr[i] = originalArr[i] + offset;
}
return resultArr;
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.NewExprMatcher(DungeonTransitionScreen.class.getName());

int[] beforeLines = LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);

// offset by 1 to be called **after** the found method call
return offset(beforeLines, 1);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
package basemod.patches.com.megacrit.cardcrawl.core.CardCrawlGame;

import basemod.BaseMod;
import javassist.CannotCompileException;
import javassist.CtBehavior;

import java.util.ArrayList;

import com.evacipated.cardcrawl.modthespire.lib.LineFinder;
import com.evacipated.cardcrawl.modthespire.lib.Matcher;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.patcher.PatchingException;
import com.megacrit.cardcrawl.screens.DungeonTransitionScreen;

@SpirePatch(cls="com.megacrit.cardcrawl.core.CardCrawlGame", method="startNewGame")
public class StartGameHook {
@SpireInsertPatch(rloc=26)

@SpireInsertPatch
public static void Insert(Object __obj_instance) {
BaseMod.publishStartGame();
}

public static int[] Locator(CtBehavior ctMethodToPatch) throws CannotCompileException, PatchingException {
Matcher finalMatcher = new Matcher.NewExprMatcher(DungeonTransitionScreen.class.getName());

return LineFinder.findInOrder(ctMethodToPatch, new ArrayList<Matcher>(), finalMatcher);
}

}
10 changes: 5 additions & 5 deletions src/main/resources/ModTheSpire.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Base Mod
author=t-larson, test447, FlipskiZ, Haashi, Blank The Evil, kiooeht
description=Unofficial modding API for Slay the Spire
mts_version=2.3.0
sts_version=03-22-2018
name=Base Mod
author=t-larson, test447, FlipskiZ, Haashi, Blank The Evil, kiooeht
description=Unofficial modding API for Slay the Spire
mts_version=2.6.0
sts_version=03-29-2018
4 changes: 2 additions & 2 deletions src/main/resources/ModTheSpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"author_list": ["t-larson", "test447", "Haashi", "kiooeht", "Blank The Evil", "FlipskiZ"],
"description": "Unofficial modding API for Slay the Spire. Also a Dev Console.",
"version": "2.4.0",
"sts_version": "03-22-2018",
"mts_version": "2.3.0"
"sts_version": "03-29-2018",
"mts_version": "2.6.0"
}

0 comments on commit ca2e7de

Please sign in to comment.