Skip to content

Commit adaa387

Browse files
Sakura-TASakura-TA
andauthored
fix multithread race condition about pathfinder (#846)
* fix multithread race condition about pathfinder * remove un-necessary call to map.pathFinder.ForceCompleteScheduledJobs() * remove unnecessary comment * remove method IsForbiddenByFaction and drop more situation to original method --------- Co-authored-by: Sakura-TA <Sakura_TA@163.com>
1 parent 9355ff5 commit adaa387

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Source/Client/Comp/Map/MultiplayerMapComp.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public CustomFactionMapData GetCurrentCustomFactionData()
143143
return customFactionData[Faction.OfPlayer.loadID];
144144
}
145145

146+
public CustomFactionMapData GetCustomFactionData(Faction faction)
147+
{
148+
return customFactionData[faction.loadID];
149+
}
150+
146151
public void Notify_ThingDespawned(Thing t)
147152
{
148153
foreach (var data in customFactionData.Values)

Source/Client/Factions/Forbiddables.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@ namespace Multiplayer.Client
77
{
88
// todo handle conversion to singleplayer and PostSplitOff
99

10+
[HarmonyPatch(typeof(ForbidUtility), nameof(ForbidUtility.IsForbidden),
11+
typeof(Thing), typeof(Faction))]
12+
static class IsForbiddenPatch
13+
{
14+
static bool Prefix(Thing t, Faction faction, ref bool __result)
15+
{
16+
if (Multiplayer.Client == null || faction == null || !faction.IsPlayer) return true; // singleplayer: run vanilla
17+
18+
ThingWithComps thingWithComps = t as ThingWithComps;
19+
if (thingWithComps == null)
20+
{
21+
__result = false;
22+
return false;
23+
}
24+
CompForbiddable compForbiddable = thingWithComps.compForbiddable;
25+
26+
if(compForbiddable == null) {
27+
__result = false;
28+
return false;
29+
}
30+
31+
if(!t.Spawned)
32+
{
33+
__result = false;
34+
return false;
35+
}
36+
37+
__result = !t.Map.MpComp().GetCustomFactionData(faction).unforbidden.Contains(t); // use faction-specific data directly
38+
return false; // skip vanilla
39+
}
40+
41+
}
42+
1043
[HarmonyPatch(typeof(CompForbiddable), nameof(CompForbiddable.Forbidden), MethodType.Getter)]
1144
static class GetForbidPatch
1245
{

0 commit comments

Comments
 (0)