Skip to content

Commit 94dd114

Browse files
Cherry-pick upstream PR rwmt#818: sync all gizmos
From rwmt#818 (commit 919f8cb): - Sync refuelable gizmo hotkey, trained animal attack gizmos - Sync outfit stand gizmos, archonexus/crate float menu options - Add sync worker delegates for ReadingOutcomeDoer, Tile, etc. - Split SyncGizmoSlider into SyncGizmoSliderChanges + SyncRefuelableChanges
1 parent 02130a3 commit 94dd114

File tree

8 files changed

+189
-26
lines changed

8 files changed

+189
-26
lines changed

Source/Client/Syncing/Dict/SyncDictDlc.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,29 @@ public static class SyncDictDlc
397397
return new PawnPsychicRitualRoleSelectionWidget(ritual, assignments.session.candidatePool, assignments);
398398
}
399399
},
400+
{
401+
(ByteWriter data, PsychicRitualToil toil) =>
402+
{
403+
data.WriteString(toil.uniqueId);
404+
},
405+
(ByteReader data) =>
406+
{
407+
var psychicRitualId = data.ReadString();
408+
409+
// Check all maps
410+
return Find.Maps.SelectMany(map => map.lordManager.lords)
411+
// Grab all lord toils
412+
.Select(lord => lord.CurLordToil)
413+
// Grab all psychic ritual toils
414+
.OfType<LordToil_PsychicRitual>()
415+
// Select all current psychic ritual toils
416+
.Select(lordToil => lordToil.RitualData?.CurPsychicRitualToil)
417+
// But only if not null, just as a precaution
418+
.AllNotNull()
419+
// Grab the first one with matching ID
420+
.FirstOrDefault(toil => toil.uniqueId == psychicRitualId);
421+
}, true // Implicit
422+
},
400423

401424
#endregion
402425
};

Source/Client/Syncing/Dict/SyncDictMisc.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ public static class SyncDictMisc
113113
return context;
114114
}
115115
},
116+
{
117+
(ByteWriter data, AcceptanceReport report) =>
118+
{
119+
data.WriteBool(report.acceptedInt);
120+
data.WriteString(report.reasonTextInt);
121+
},
122+
(ByteReader data) => new AcceptanceReport
123+
{
124+
acceptedInt = data.ReadBool(),
125+
reasonTextInt = data.ReadStringNullable()
126+
}
127+
},
116128
#endregion
117129

118130
#region Unity

Source/Client/Syncing/Dict/SyncDictRimWorld.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,24 @@ public static class SyncDictRimWorld
775775
return (parent.gun as ThingWithComps).TryGetComp<CompChangeableProjectile>();
776776
}
777777
},
778+
{
779+
(ByteWriter writer, ReadingOutcomeDoer doer) =>
780+
{
781+
WriteSync(writer, doer.Readable);
782+
writer.WriteInt32(doer.Readable.doers.IndexOf(doer));
783+
},
784+
(ByteReader reader) =>
785+
{
786+
var parent = ReadSync<CompReadable>(reader);
787+
var index = reader.ReadInt32();
788+
789+
// Make sure we have a valid doer
790+
if (parent == null || index < 0 || index >= parent.doers.Count)
791+
return null;
792+
793+
return parent.doers[index];
794+
}, true // implicit
795+
},
778796
#endregion
779797

780798
#region Things
@@ -1061,6 +1079,32 @@ public static class SyncDictRimWorld
10611079
return Find.WorldGrid.PlanetLayers[layerId];
10621080
}, true
10631081
},
1082+
{
1083+
(ByteWriter data, Tile tile) =>
1084+
{
1085+
var map = Find.Maps.Find(m => m.pocketTileInfo == tile);
1086+
1087+
// Handle pocket map
1088+
if (map != null)
1089+
{
1090+
data.WriteInt32(map.uniqueID);
1091+
}
1092+
// Handle normal tile
1093+
else
1094+
{
1095+
data.WriteInt32(-1);
1096+
WriteSync(data, tile.tile);
1097+
}
1098+
},
1099+
(ByteReader data) =>
1100+
{
1101+
var pocketMapId = data.ReadInt32();
1102+
1103+
if (pocketMapId >= 0)
1104+
return Find.Maps.Find(m => m.uniqueID == pocketMapId)?.pocketTileInfo;
1105+
return ReadSync<PlanetTile>(data).Tile;
1106+
}
1107+
},
10641108
#endregion
10651109

10661110
#region Game

Source/Client/Syncing/Game/SyncDelegates.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static void Init()
4343
SyncDelegate.Lambda(typeof(Building_PassengerShuttle), nameof(Building_PassengerShuttle.GetGizmos), 2); // Fill shuttle from cargo on map
4444
SyncMethod.Lambda(typeof(CompFlickable), nameof(CompFlickable.CompGetGizmosExtra), 1); // Toggle flick designation
4545
SyncMethod.Lambda(typeof(Pawn_PlayerSettings), nameof(Pawn_PlayerSettings.GetGizmos), 1); // Toggle release animals
46+
SyncMethod.Lambda(typeof(Pawn_PlayerSettings), nameof(Pawn_PlayerSettings.GetGizmos), 2); // Force animals to attack specific target
4647
SyncMethod.Lambda(typeof(Building_TurretGun), nameof(Building_TurretGun.GetGizmos), 2); // Toggle turret hold fire
4748
SyncMethod.Lambda(typeof(Building_Trap), nameof(Building_Trap.GetGizmos), 1); // Toggle trap auto-rearm
4849
SyncMethod.Lambda(typeof(Building_Door), nameof(Building_Door.GetGizmos), 1); // Toggle door hold open
@@ -97,7 +98,7 @@ public static void Init()
9798
SyncMethod.Lambda(typeof(CompTreeConnection), nameof(CompTreeConnection.CompGetGizmosExtra), 2).SetDebugOnly(); // Increase connection strength by 10%
9899
SyncMethod.Lambda(typeof(CompTreeConnection), nameof(CompTreeConnection.CompGetGizmosExtra), 3).SetDebugOnly(); // Decrease connection strength by 10%
99100

100-
SyncMethod.Lambda(typeof(CompNeuralSupercharger), nameof(CompNeuralSupercharger.CompGetGizmosExtra), 1); // Neural supercharger: allow temporary pawns to use
101+
SyncMethod.Lambda(typeof(CompNeuralSupercharger), nameof(CompNeuralSupercharger.CompGetGizmosExtra), 1); // Neural supercharger: allow temporary pawns (guests) to use
101102

102103
SyncMethod.Lambda(typeof(CompPilotConsole), nameof(CompPilotConsole.CompGetGizmosExtra), 1).SetDebugOnly(); // Dev launch instantly
103104
SyncMethod.Lambda(typeof(CompPilotConsole), nameof(CompPilotConsole.CompGetGizmosExtra), 2).SetDebugOnly(); // Dev reset cooldown
@@ -129,10 +130,10 @@ public static void Init()
129130
SyncDelegate.Lambda(typeof(Pawn_CarryTracker), nameof(Pawn_CarryTracker.GetGizmos), 1).SetDebugOnly(); // Trigger dissolution event (CompDissolution)
130131

131132
// CompSpawner
132-
SyncMethod.Lambda(typeof(CompSpawner), nameof(CompSpawner.CompGetGizmosExtra), 0).SetDebugOnly();
133-
SyncMethod.Lambda(typeof(CompSpawnerHives), nameof(CompSpawnerHives.CompGetGizmosExtra), 0).SetDebugOnly();
134-
SyncMethod.Lambda(typeof(CompSpawnerItems), nameof(CompSpawnerItems.CompGetGizmosExtra), 0).SetDebugOnly();
135-
SyncMethod.Lambda(typeof(CompSpawnerPawn), nameof(CompSpawnerPawn.CompGetGizmosExtra), 0).SetDebugOnly();
133+
SyncMethod.Lambda(typeof(CompSpawner), nameof(CompSpawner.CompGetGizmosExtra), 0).SetDebugOnly(); // Spawn thing
134+
SyncMethod.Lambda(typeof(CompSpawnerHives), nameof(CompSpawnerHives.CompGetGizmosExtra), 0).SetDebugOnly(); // Reproduce
135+
SyncMethod.Lambda(typeof(CompSpawnerItems), nameof(CompSpawnerItems.CompGetGizmosExtra), 0).SetDebugOnly(); // Spawn items
136+
SyncMethod.Lambda(typeof(CompSpawnerPawn), nameof(CompSpawnerPawn.CompGetGizmosExtra), 0).SetDebugOnly(); // Spawn pawn
136137

137138
SyncMethod.Lambda(typeof(CompSendSignalOnCountdown), nameof(CompSendSignalOnCountdown.CompGetGizmosExtra), 0).SetDebugOnly();
138139

@@ -242,6 +243,9 @@ public static void Init()
242243
SyncDelegate.Lambda(typeof(GeneResourceDrainUtility), nameof(GeneResourceDrainUtility.GetResourceDrainGizmos), 0).SetDebugOnly(); // -10% resource
243244
SyncDelegate.Lambda(typeof(GeneResourceDrainUtility), nameof(GeneResourceDrainUtility.GetResourceDrainGizmos), 1).SetDebugOnly(); // +10% resource
244245
SyncMethod.Register(typeof(CompBreakdownable), nameof(CompBreakdownable.Notify_Repaired)).SetDebugOnly(); // Dev repair breakdownable
246+
SyncDelegate.Lambda(typeof(CompCanBeDormant), nameof(CompCanBeDormant.CompGetGizmosExtra), 1).SetDebugOnly(); // Wake up after delay
247+
SyncDelegate.Lambda(typeof(Tile), nameof(Tile.GetGizmos), 0).SetDebugOnly(); // Generate settlement
248+
SyncDelegate.Lambda(typeof(Tile), nameof(Tile.GetGizmos), 4).SetDebugOnly(); // Generate map
245249

246250
// Hediffs
247251
SyncMethod.Register(typeof(Hediff_CubeInterest), nameof(Hediff_CubeInterest.StartWithdrawal)).SetDebugOnly();
@@ -272,6 +276,10 @@ public static void Init()
272276

273277
SyncDelegate.Lambda(typeof(CompNociosphere), nameof(CompNociosphere.TargetLocation), 1);
274278

279+
// Animal training tracker
280+
SyncDelegate.Lambda(typeof(Pawn_TrainingTracker), nameof(Pawn_TrainingTracker.GetGizmos), 0, fields: [SyncDelegate.DelegateThis, "master"]).SetContext(SyncContext.MapSelected).CancelIfNoSelectedMapObjects(); // Force attack target
281+
SyncDelegate.Lambda(typeof(Pawn_TrainingTracker), nameof(Pawn_TrainingTracker.GetGizmos), 3).SetContext(SyncContext.MapSelected).CancelIfNoSelectedMapObjects(); // Cancel attacking target
282+
275283
InitRituals();
276284
InitChoiceLetters();
277285
InitDevTools();

Source/Client/Syncing/Game/SyncFields.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ static void WatchAwaitingExecution(Pawn pawn)
610610
}
611611

612612
[MpPrefix(typeof(Gizmo_Slider), nameof(Gizmo_Slider.GizmoOnGUI))]
613-
static void SyncGizmoSlider(Gizmo_Slider __instance)
613+
static void SyncGizmoSliderChanges(Gizmo_Slider __instance)
614614
{
615615
if (__instance is GeneGizmo_Resource geneGizmo)
616616
{
@@ -628,12 +628,16 @@ static void SyncGizmoSlider(Gizmo_Slider __instance)
628628
SyncActivityCompTarget.Watch(comp);
629629
SyncActivityCompSuppression.Watch(comp);
630630
}
631-
else if (__instance is Gizmo_SetFuelLevel fuelGizmo)
632-
{
633-
var refuelable = fuelGizmo.refuelable;
634-
SyncCompRefuelableValue.Watch(refuelable);
635-
SyncCompRefuelableTargetFuelLevel.Watch(refuelable);
636-
}
631+
}
632+
633+
[MpPrefix(typeof(Gizmo_SetFuelLevel), nameof(Gizmo_SetFuelLevel.GizmoOnGUI))]
634+
static void SyncRefuelableChanges(Gizmo_SetFuelLevel __instance)
635+
{
636+
// Must be separate from SyncGizmoSliderChanges, as this type overrides the base
637+
// method and modifies the field in there (toggle the value using a hotkey).
638+
var refuelable = __instance.refuelable;
639+
SyncCompRefuelableValue.Watch(refuelable);
640+
SyncCompRefuelableTargetFuelLevel.Watch(refuelable);
637641
}
638642

639643
[MpPrefix(typeof(ITab_ContentsGenepackHolder), nameof(ITab_ContentsGenepackHolder.DoItemsLists))]

0 commit comments

Comments
 (0)