Harmony AccessTools help

Started by thamuzz, July 25, 2022, 09:31:43 AM

Previous topic - Next topic

thamuzz

I'm trying to access a method in a protected class:
public static void GenerateShip(EnemyShipDef shipDef, Map map, TradeShip tradeShip, Faction fac, Lord lord, out Building core, bool clearArea = false, bool wreckEverything = false)

The trouble spot is with the pass by reference on out Building core.  When I try to call:
Traverse.Create(shipCombatManagerType).Method("GenerateShip").Value(...)
I get an error saying that it can't call a method that doesn't exist.  When I try to call

Building core = null;
ref Building coreRef = ref core;
Traverse.Create(shipCombatManagerType).Method("GenerateShip",
                    DefDatabase<EnemyShipDef>.AllDefs.Where(def=>def.spaceSite).RandomElement(),
                    map,
                    null,
                    Faction.OfAncients,
                    null,
                    coreRef,
                    true,
                    true).GetValue();

I don't get any errors but core doesn't get set.  I've tried several other permutations, and I can't quite figure it out.