Skip to content
Kiooeht edited this page Aug 28, 2021 · 2 revisions

SpireReturn is a way for patches to make the method they are patching return early.

This example, if patching RelicLibrary.getRelic, would make every relic be the Blue Candle by always returning the Blue Candle.

                        // v Should match the return type of the method being patched
public static SpireReturn<AbstractRelic> Prefix(String key)
{
    return SpireReturn.Return(new BlueCandle());
}

To return early in a method that returns void simply use SpireReturn<Void> and return without a parameter.

public static SpireReturn<Void> Insert()
{
    return SpireReturn.Return();
}

To continue the patched method normally, use SpireReturn.Continue().

public static SpireReturn<AbstractRelic> Prefix(String key)
{
    if (key.equals(BurningBlood.ID)) {
        return SpireReturn.Continue(); // Continue the original method as normal
    } else if (key.equals(BlueCandle.ID)) {
        return SpireReturn.Return(new Circlet()); // Immediately return a new Circlet object
    } else {
        return SpireReturn.Return(new BlueCandle()); // Immediately return a new BlueCandle object
    }
}

When the method being patched returns a primative type (int, boolean, etc.) use the wrapper classes as your return type.

// Original method returns boolean
public static SpireReturn<Boolean> Insert()
{
    return SpireReturn.Return(false);
}

// Original method returns int
public static SpireReturn<Integer> Insert()
{
    return SpireReturn.Return(9);
}