Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Source/Client/Syncing/Game/SyncMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,39 @@ public static void TryDirtyCurrentPawnTable(object instance = null, object[] arg
table.SetDirty();
}
}
[HarmonyPatch(typeof(FlyShipLeaving), nameof(FlyShipLeaving.LeaveMap))]
static class FlyShipLeaving_LeaveMap_Patch
{
//When launch transporter, should try to use pawn inside's faction instead of Faction.OfPlayer
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
{
var ofPlayerGetter = AccessTools.PropertyGetter(typeof(Faction), nameof(Faction.OfPlayer));
var replacement = AccessTools.Method(typeof(FlyShipLeaving_LeaveMap_Patch),
nameof(GetFactionFromContents));

foreach (var ci in insts)
{
if (ci.Calls(ofPlayerGetter))
{
yield return new CodeInstruction(OpCodes.Ldarg_0);
ci.opcode = OpCodes.Call;
ci.operand = replacement;
}
yield return ci;
}
}

static Faction GetFactionFromContents(FlyShipLeaving flyShip)
{
foreach (Thing t in flyShip.Contents.innerContainer)
{
Pawn pawn = t as Pawn;
if (pawn?.Faction != null && pawn.Faction.IsPlayer)
return pawn.Faction;
}
return Faction.OfPlayer; // fallback
}
}

[HarmonyPatch(typeof(ITab_ContentsBooks), nameof(ITab_ContentsBooks.DoRow))]
static class ITab_ContentsBooks_DoRow_Patch
Expand Down
Loading