Skip to content

Commit 6725c21

Browse files
Sakura-TASakura-TA
andauthored
Fix sending transporters from other player-faction's faction base to use correct faction (rwmt#850)
* assign pawn's faction to worldobject transporter instead of faction.OfPlayer * Remove unnecessary closing brace in SyncMethods.cs --------- Co-authored-by: Sakura-TA <Sakura_TA@163.com>
1 parent 1bfc18a commit 6725c21

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Source/Client/Syncing/Game/SyncMethods.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,39 @@ public static void TryDirtyCurrentPawnTable(object instance = null, object[] arg
869869
table.SetDirty();
870870
}
871871
}
872+
[HarmonyPatch(typeof(FlyShipLeaving), nameof(FlyShipLeaving.LeaveMap))]
873+
static class FlyShipLeaving_LeaveMap_Patch
874+
{
875+
//When launch transporter, should try to use pawn inside's faction instead of Faction.OfPlayer
876+
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
877+
{
878+
var ofPlayerGetter = AccessTools.PropertyGetter(typeof(Faction), nameof(Faction.OfPlayer));
879+
var replacement = AccessTools.Method(typeof(FlyShipLeaving_LeaveMap_Patch),
880+
nameof(GetFactionFromContents));
881+
882+
foreach (var ci in insts)
883+
{
884+
if (ci.Calls(ofPlayerGetter))
885+
{
886+
yield return new CodeInstruction(OpCodes.Ldarg_0);
887+
ci.opcode = OpCodes.Call;
888+
ci.operand = replacement;
889+
}
890+
yield return ci;
891+
}
892+
}
893+
894+
static Faction GetFactionFromContents(FlyShipLeaving flyShip)
895+
{
896+
foreach (Thing t in flyShip.Contents.innerContainer)
897+
{
898+
Pawn pawn = t as Pawn;
899+
if (pawn?.Faction != null && pawn.Faction.IsPlayer)
900+
return pawn.Faction;
901+
}
902+
return Faction.OfPlayer; // fallback
903+
}
904+
}
872905

873906
[HarmonyPatch(typeof(ITab_ContentsBooks), nameof(ITab_ContentsBooks.DoRow))]
874907
static class ITab_ContentsBooks_DoRow_Patch

0 commit comments

Comments
 (0)