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
22 changes: 21 additions & 1 deletion Source/Client/Syncing/Game/SyncDelegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using HarmonyLib;
using Multiplayer.API;
using Multiplayer.Client.Patches;
using Multiplayer.Common;
using MultiplayerLoader;
using RimWorld;
using RimWorld.Planet;
Expand Down Expand Up @@ -351,7 +352,8 @@ private static void InitChoiceLetters()

// Growth moment for a child
CloseDialogsForExpiredLetters.RegisterDefaultLetterChoice(AccessTools.Method(typeof(SyncDelegates), nameof(PickRandomTraitAndPassions)), typeof(ChoiceLetter_GrowthMoment));
SyncMethod.Register(typeof(ChoiceLetter_GrowthMoment), nameof(ChoiceLetter_GrowthMoment.MakeChoices)).ExposeParameter(1);
SyncMethod.Register(typeof(ChoiceLetter_GrowthMoment), nameof(ChoiceLetter_GrowthMoment.MakeChoices))
.TransformArgument(1, TraitSerializer);

// Creep joiner
SyncMethod.LambdaInGetter(typeof(ChoiceLetter_AcceptCreepJoiner), nameof(ChoiceLetter_AcceptCreepJoiner.Choices), 0); // Accept joiner
Expand All @@ -361,6 +363,24 @@ private static void InitChoiceLetters()
.method); // Reject joiner
}

private static readonly SyncType TraitType = new(typeof(Trait)) { expose = true };
private static readonly Serializer<Trait, byte[]> TraitSerializer = Serializer.New<Trait, byte[]>(trait =>
{
if (trait == ChoiceLetter_GrowthMoment.NoTrait) return [0];

var writer = new ByteWriter();
writer.WriteByte(1);
SyncSerialization.WriteSyncObject(writer, trait, TraitType);
return writer.ToArray();
}, bytes =>
{
var reader = new ByteReader(bytes);
var tag = reader.ReadByte();
if (tag == 0) return ChoiceLetter_GrowthMoment.NoTrait;

return (Trait)SyncSerialization.ReadSyncObject(reader, TraitType);
});

static void SyncBabyToChildLetter(ChoiceLetter_BabyToChild letter)
{
if (letter.bornSlave)
Expand Down
Loading