fix: Fixes dirty-tracking gaps in generated content: setters, sub-object owners, BaseVendor (#2609)
## Why Delta world saves re-serialize an entity only when it has been marked dirty. An audit of the generated classes found three ways serialized state changes without a mark; this PR closes the ones that do not need a new generator package. ## What - **Custom `[SerializableProperty]` setters mark dirty.** Twelve hand-written setters assigned their backing field without `this.MarkDirty()`. `PlagueBeastLord.OpenedBy` was an auto-property carrying the attribute with no backing field at all; it is now a generated field with the same name, order and command-property exposure. - **Generated sub-objects are linked to their owner.** Without a `[DirtyTrackingEntity]` member the generator emits setters that mark nothing. Eight entity-owned sub-objects now carry the link and receive the owner through the constructor the generator calls: `BOBFilter` (owner is `IEntity`: a `PlayerMobile` or a `BulkOrderBook`), `BOBLargeSubEntry`, `PuzzleChestSolution` and `PuzzleChestSolutionAndTime`, `TalismanAttribute` (the random factories now take the talisman), `VendorItem`, `PlayerBBMessage`, `RaffleEntry`, `ShardPollOption`. Migration schemas were regenerated with the pinned tool; the only change is the value rule argument becoming `DeserializationRequiresParent`. - **BaseVendor uses the generator; restock amounts are no longer persisted.** The only state it wrote was which buy entries had grown restock amounts, packed by index into the live `SBInfos` tables. Restock is transient now and rebuilds on load; version 1 records are read and discarded through the legacy path. Every vendor subclass now serializes through a generated chain. ## Generator 4.1.0 This PR adopts SerializationGenerator 4.1.0 (modernuo/SerializationGenerator#55): SG3019/SG3020 diagnostics, `[VolatileSerializedState]`, `StopXxx()` timer helpers, and owner-constructor preference for sub-objects (so dictionary values are constructed with their owner; the 4.0.0 relink fallback is gone). `PlayerVendor.v3.json` gains `DeserializationRequiresParent` for its `VendorItem` values so the migration content struct constructs them with their vendor. SG3019 is an error under `TreatWarningsAsErrors` and generator diagnostics ignore pragmas, so the five contexts that live in whole-file player-keyed persistences (`ChampionTitle`, `ChampionTitleContext`, `MurderContext`, `VirtueContext`, `JailRecord`) now carry a `[DirtyTrackingEntity]` link to their `PlayerMobile`, which is where they will live once those blobs move onto the player record. `JailSystem.EmptyRecord` keeps a null player (`[CanBeNull]`). `ChampionTitle` needs both a context and a player constructor because the generator resolves the rule against the containing type but emits the call with the parent field; a comment in the file records this. ## Wire format Unchanged. No version bumps except `BaseVendor` 1 to 2 (which now writes nothing of its own). Schema diffs are rule-argument only (`DeserializationRequiresParent`). ## Testing Server.Tests 848 passed, UOContent.Tests 759 passed.
This commit is contained in:
parent
a2c232f4a8
commit
84153fba58
49 changed files with 223 additions and 214 deletions
|
|
@ -5,6 +5,11 @@ namespace Server.Engines.BulkOrders;
|
|||
[SerializationGenerator(2)]
|
||||
public partial class BOBFilter
|
||||
{
|
||||
[DirtyTrackingEntity]
|
||||
private IEntity _owner;
|
||||
|
||||
public BOBFilter(IEntity owner) => _owner = owner;
|
||||
|
||||
[SerializableField(0)]
|
||||
[SaveFlag(nameof(ShouldSerializeType))]
|
||||
private int _type;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public partial class BOBLargeEntry : BaseBOBEntry
|
|||
|
||||
for (var i = 0; i < _entries.Length; ++i)
|
||||
{
|
||||
_entries[i] = new BOBLargeSubEntry(bod.Entries[i]);
|
||||
_entries[i] = new BOBLargeSubEntry(this, bod.Entries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ public partial class BOBLargeEntry : BaseBOBEntry
|
|||
|
||||
for (var i = 0; i < Entries.Length; ++i)
|
||||
{
|
||||
_entries[i] = new BOBLargeSubEntry();
|
||||
_entries[i] = new BOBLargeSubEntry(this);
|
||||
_entries[i].Deserialize(reader);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ namespace Server.Engines.BulkOrders;
|
|||
[SerializationGenerator(0)]
|
||||
public partial class BOBLargeSubEntry
|
||||
{
|
||||
[DirtyTrackingEntity]
|
||||
private BOBLargeEntry _parent;
|
||||
|
||||
[SerializableField(0, setter: "private")]
|
||||
private Type _itemType;
|
||||
|
||||
|
|
@ -21,12 +24,11 @@ public partial class BOBLargeSubEntry
|
|||
[SerializableField(3, setter: "private")]
|
||||
private int _graphic;
|
||||
|
||||
public BOBLargeSubEntry()
|
||||
{
|
||||
}
|
||||
public BOBLargeSubEntry(BOBLargeEntry parent) => _parent = parent;
|
||||
|
||||
public BOBLargeSubEntry(LargeBulkEntry lbe)
|
||||
public BOBLargeSubEntry(BOBLargeEntry parent, LargeBulkEntry lbe)
|
||||
{
|
||||
_parent = parent;
|
||||
_itemType = lbe.Details.Type;
|
||||
_amountCur = lbe.Amount;
|
||||
_number = lbe.Details.Number;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public partial class BulkOrderBook : Item, ISecurable
|
|||
LootType = LootType.Blessed;
|
||||
|
||||
_entries = [];
|
||||
_filter = new BOBFilter();
|
||||
_filter = new BOBFilter(this);
|
||||
|
||||
_level = SecureLevel.CoOwners;
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ public partial class BulkOrderBook : Item, ISecurable
|
|||
|
||||
_bookName = reader.ReadString();
|
||||
|
||||
_filter = new BOBFilter();
|
||||
_filter = new BOBFilter(this);
|
||||
_filter.Deserialize(reader);
|
||||
|
||||
var count = reader.ReadEncodedInt();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Engines.CannedEvil;
|
||||
|
||||
[SerializationGenerator(0)]
|
||||
public partial class ChampionTitle
|
||||
{
|
||||
[DirtyTrackingEntity]
|
||||
private PlayerMobile _player;
|
||||
|
||||
public ChampionTitle(ChampionTitleContext context) : this(context?.Player)
|
||||
{
|
||||
}
|
||||
|
||||
// The generator resolves the deserialization constructor against the owning type, but emits the
|
||||
// owner's own dirty-tracking reference (the player) at the call site, so both overloads exist.
|
||||
public ChampionTitle(PlayerMobile player) => _player = player;
|
||||
|
||||
[EncodedInt]
|
||||
[SerializableField(0)]
|
||||
private int _value;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public partial class ChampionTitleContext
|
|||
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
||||
private int _harrower;
|
||||
|
||||
[DirtyTrackingEntity]
|
||||
private PlayerMobile _player;
|
||||
|
||||
public PlayerMobile Player => _player;
|
||||
|
|
@ -45,7 +46,7 @@ public partial class ChampionTitleContext
|
|||
throw new NotImplementedException($"Cannot find ChampionSpawnType value {type}.");
|
||||
}
|
||||
|
||||
title = new ChampionTitle();
|
||||
title = new ChampionTitle(this);
|
||||
title.Deserialize(reader);
|
||||
}
|
||||
}
|
||||
|
|
@ -290,7 +291,7 @@ public partial class ChampionTitleContext
|
|||
return null;
|
||||
}
|
||||
|
||||
return title ??= new ChampionTitle();
|
||||
return title ??= new ChampionTitle(this);
|
||||
}
|
||||
|
||||
public void SetValue(ChampionSpawnType type, int value)
|
||||
|
|
@ -313,7 +314,7 @@ public partial class ChampionTitleContext
|
|||
}
|
||||
else
|
||||
{
|
||||
title = new ChampionTitle();
|
||||
title = new ChampionTitle(this);
|
||||
}
|
||||
|
||||
title.Value = value;
|
||||
|
|
|
|||
|
|
@ -23,11 +23,19 @@ namespace Server.Items
|
|||
[SerializationGenerator(1)]
|
||||
public partial class PuzzleChestSolution
|
||||
{
|
||||
[DirtyTrackingEntity]
|
||||
private PuzzleChest _chest;
|
||||
|
||||
[SerializableField(0)]
|
||||
private PuzzleChestCylinder[] _cylinders;
|
||||
|
||||
public const int Length = 5;
|
||||
|
||||
// Declared first: the generator picks the first matching constructor, and a deserialized
|
||||
// solution must know its chest to mark it dirty.
|
||||
public PuzzleChestSolution(PuzzleChest chest) : this() => _chest = chest;
|
||||
|
||||
// Transient solutions (player guesses being edited in a gump) have no owning chest.
|
||||
public PuzzleChestSolution() =>
|
||||
_cylinders = [RandomCylinder(), RandomCylinder(), RandomCylinder(), RandomCylinder(), RandomCylinder()];
|
||||
|
||||
|
|
@ -42,6 +50,9 @@ namespace Server.Items
|
|||
solution.Cylinders.AsSpan().CopyTo(Cylinders);
|
||||
}
|
||||
|
||||
protected PuzzleChestSolution(PuzzleChest chest, PuzzleChestSolution solution) : this(solution) =>
|
||||
_chest = chest;
|
||||
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
var length = reader.ReadEncodedInt();
|
||||
|
|
@ -174,10 +185,11 @@ namespace Server.Items
|
|||
[SerializableField(0)]
|
||||
private DateTime _when;
|
||||
|
||||
public PuzzleChestSolutionAndTime(DateTime when, PuzzleChestSolution solution) : base(solution) => _when = when;
|
||||
public PuzzleChestSolutionAndTime(PuzzleChest chest, DateTime when, PuzzleChestSolution solution)
|
||||
: base(chest, solution) => _when = when;
|
||||
|
||||
// For serialization
|
||||
public PuzzleChestSolutionAndTime()
|
||||
// The generator deserializes guesses through this constructor so each one knows its chest.
|
||||
public PuzzleChestSolutionAndTime(PuzzleChest chest) : base(chest)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -214,7 +226,7 @@ namespace Server.Items
|
|||
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
_solution = new PuzzleChestSolution();
|
||||
_solution = new PuzzleChestSolution(this);
|
||||
_solution.Deserialize(reader);
|
||||
|
||||
var length = reader.ReadEncodedInt();
|
||||
|
|
@ -238,7 +250,7 @@ namespace Server.Items
|
|||
for (var i = 0; i < guessCount; i++)
|
||||
{
|
||||
var m = reader.ReadEntity<Mobile>();
|
||||
(_guesses[m] = new PuzzleChestSolutionAndTime()).Deserialize(reader);
|
||||
(_guesses[m] = new PuzzleChestSolutionAndTime(this)).Deserialize(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -329,7 +341,7 @@ namespace Server.Items
|
|||
}
|
||||
else
|
||||
{
|
||||
(_guesses ??= []).Add(m, new PuzzleChestSolutionAndTime(Core.Now, solution));
|
||||
(_guesses ??= []).Add(m, new PuzzleChestSolutionAndTime(this, Core.Now, solution));
|
||||
StartCleanupTimer();
|
||||
|
||||
m.SendGump(new StatusGump(correctCylinders, correctColors));
|
||||
|
|
@ -525,7 +537,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Solution = new PuzzleChestSolution();
|
||||
Solution = new PuzzleChestSolution(this);
|
||||
}
|
||||
|
||||
private void StartCleanupTimer()
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ public partial class PlantItem : Item, ISecurable
|
|||
var ratio = PlantSystem != null ? (double)PlantSystem.Hits / PlantSystem.MaxHits : 1.0;
|
||||
|
||||
_plantStatus = value;
|
||||
this.MarkDirty();
|
||||
|
||||
if (_plantStatus >= PlantStatus.DecorativePlant)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ public partial class MurderContext
|
|||
_lastMurderTime = Core.Now;
|
||||
}
|
||||
|
||||
[DirtyTrackingEntity]
|
||||
public PlayerMobile _player;
|
||||
|
||||
public PlayerMobile Player => _player;
|
||||
|
|
|
|||
|
|
@ -308,6 +308,7 @@ public abstract partial class BaseSpawner : Item, ISpawner
|
|||
{
|
||||
_walkingRange = value;
|
||||
InvalidateProperties();
|
||||
this.MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,13 @@ namespace Server.Engines.Virtues;
|
|||
[SerializationGenerator(1)]
|
||||
public partial class VirtueContext
|
||||
{
|
||||
[DirtyTrackingEntity]
|
||||
private PlayerMobile _player;
|
||||
|
||||
public PlayerMobile Player => _player;
|
||||
|
||||
public VirtueContext(PlayerMobile player) => _player = player;
|
||||
|
||||
private void MigrateFrom(V0Content content)
|
||||
{
|
||||
// Save-flagged values arrive as nullables; unset flags fall back to the same
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class VirtueSystem : GenericPersistence
|
|||
for (var i = 0; i < contextCount; i++)
|
||||
{
|
||||
var player = reader.ReadEntity<PlayerMobile>();
|
||||
var virtues = new VirtueContext();
|
||||
var virtues = new VirtueContext(player);
|
||||
virtues.Deserialize(reader);
|
||||
|
||||
if (player != null && virtues.IsUsed())
|
||||
|
|
@ -122,7 +122,7 @@ public class VirtueSystem : GenericPersistence
|
|||
ref var context = ref CollectionsMarshal.GetValueRefOrAddDefault(_playerVirtues, from, out var exists);
|
||||
if (!exists)
|
||||
{
|
||||
context = new VirtueContext();
|
||||
context = new VirtueContext(from);
|
||||
}
|
||||
|
||||
return context;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue