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:
Kamron Batman 2026-09-06 09:43:44 -07:00 • committed by GitHub
parent a2c232f4a8
commit 84153fba58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 223 additions and 214 deletions

View file

@ -195,6 +195,7 @@ namespace Server.Items
{
UnscaleDurability();
_quality = value;
this.MarkDirty();
ScaleDurability();
}
}
@ -213,6 +214,7 @@ namespace Server.Items
{
UnscaleDurability();
_durability = value;
this.MarkDirty();
ScaleDurability();
}
}
@ -246,6 +248,7 @@ namespace Server.Items
UnscaleDurability();
_resource = value;
this.MarkDirty();
if (CraftItem.RetainsColor(GetType()))
{

View file

@ -53,6 +53,7 @@ public abstract partial class FillableContainer : LockableContainer
ClearContents();
_contentType = value;
this.MarkDirty();
Respawn();
}
}

View file

@ -350,6 +350,7 @@ public abstract partial class BaseBeverage : Item, IHasQuantity
set
{
_quantity = Math.Clamp(value, 0, MaxQuantity);
this.MarkDirty();
InvalidateProperties();

View file

@ -13,7 +13,7 @@ public partial class BloodwoodSpirit : BaseTalisman
Removal = TalismanRemoval.Damage;
Blessed = GetRandomBlessed();
Protection = GetRandomProtection(false);
Protection = GetRandomProtection(this, false);
SkillBonuses.SetValues(0, SkillName.SpiritSpeak, 10.0);
SkillBonuses.SetValues(1, SkillName.Necromancy, 5.0);

View file

@ -14,7 +14,7 @@ public partial class TotemOfVoid : BaseTalisman
MaxChargeTime = 1800;
Blessed = GetRandomBlessed();
Protection = GetRandomProtection(false);
Protection = GetRandomProtection(this, false);
Attributes.RegenHits = 2;
Attributes.LowerManaCost = 10;

View file

@ -74,13 +74,13 @@ public abstract partial class BasePlayerBB : Item, ISecurable
if (_greeting != null)
{
board.Greeting = new PlayerBBMessage(_greeting.Time, _greeting.Poster, _greeting.Message);
board.Greeting = new PlayerBBMessage(board, _greeting.Time, _greeting.Poster, _greeting.Message);
}
for (var i = 0; i < _messages.Count; i++)
{
var message = _messages[i];
board.AddToMessages(new PlayerBBMessage(message.Time, message.Poster, message.Message));
board.AddToMessages(new PlayerBBMessage(board, message.Time, message.Poster, message.Message));
}
}
@ -176,7 +176,7 @@ public abstract partial class BasePlayerBB : Item, ISecurable
if (text.Length > 0)
{
var message = new PlayerBBMessage(Core.Now, from, text);
var message = new PlayerBBMessage(board, Core.Now, from, text);
if (_greeting)
{
@ -265,6 +265,9 @@ public abstract partial class BasePlayerBB : Item, ISecurable
[SerializationGenerator(0)]
public partial class PlayerBBMessage
{
[DirtyTrackingEntity]
private BasePlayerBB _board;
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private DateTime _time;
@ -277,12 +280,11 @@ public partial class PlayerBBMessage
[SerializedCommandProperty(AccessLevel.GameMaster)]
private string _message;
public PlayerBBMessage()
{
}
public PlayerBBMessage(BasePlayerBB board) => _board = board;
public PlayerBBMessage(DateTime time, Mobile poster, string message)
public PlayerBBMessage(BasePlayerBB board, DateTime time, Mobile poster, string message)
{
_board = board;
_time = time;
_poster = poster;
_message = message;

View file

@ -42,6 +42,7 @@ public partial class RecallRune : Item
set
{
_house = value;
this.MarkDirty();
CalculateHue();
InvalidateProperties();
}

View file

@ -92,6 +92,7 @@ public abstract partial class BaseInstrument : Item, ICraftable, ISlayer
{
UnscaleUses();
_quality = value;
this.MarkDirty();
InvalidateProperties();
ScaleUses();
}
@ -109,6 +110,7 @@ public abstract partial class BaseInstrument : Item, ICraftable, ISlayer
set
{
_usesRemaining = value;
this.MarkDirty();
InvalidateProperties();
}
}

View file

@ -16,6 +16,9 @@ namespace Server.Items;
[SerializationGenerator(0)]
public partial class RaffleEntry
{
[DirtyTrackingEntity]
private HouseRaffleStone _stone;
[SerializableField(0, setter: "private")]
private Mobile _from;
@ -25,15 +28,17 @@ public partial class RaffleEntry
[SerializableField(2, setter: "private")]
private DateTime _date;
public RaffleEntry(Mobile from)
public RaffleEntry(HouseRaffleStone stone, Mobile from)
{
_stone = stone;
_from = from;
_address = from?.NetState?.Address ?? IPAddress.None;
_date = Core.Now;
}
public RaffleEntry()
public RaffleEntry(HouseRaffleStone stone)
{
_stone = stone;
_from = null;
_address = null;
_date = Core.Now;
@ -454,7 +459,7 @@ public partial class HouseRaffleStone : Item
if (_ticketPrice == 0 || from.Backpack?.ConsumeTotal(typeof(Gold), _ticketPrice) == true ||
Banker.Withdraw(from, _ticketPrice))
{
AddToEntries(new RaffleEntry(from));
AddToEntries(new RaffleEntry(this, from));
from.SendMessage(MessageHue, "You have successfully entered the plot's raffle.");
}
@ -539,7 +544,7 @@ public partial class HouseRaffleStone : Item
for (var i = 0; i < entryCount; i++)
{
var entry = new RaffleEntry();
var entry = new RaffleEntry(this);
entry.Deserialize(reader);
if (entry.From == null)

View file

@ -26,19 +26,19 @@ public partial class BaseTalisman
BlessedFor = reader.ReadEntity<Mobile>();
}
_protection = new TalismanAttribute();
_protection = new TalismanAttribute(this);
if (GetOldSaveFlag(flags, OldSaveFlag.Protection))
{
_protection.Deserialize(reader);
}
_killer = new TalismanAttribute();
_killer = new TalismanAttribute(this);
if (GetOldSaveFlag(flags, OldSaveFlag.Killer))
{
_killer.Deserialize(reader);
}
_summoner = new TalismanAttribute();
_summoner = new TalismanAttribute(this);
if (GetOldSaveFlag(flags, OldSaveFlag.Summoner))
{
_summoner.Deserialize(reader);

View file

@ -155,7 +155,7 @@ public partial class BaseTalisman : Item, IAosItem
public bool ShouldSerializeProtection() => !_protection.IsEmpty;
private TalismanAttribute ProtectionDefaultValue() => new();
private TalismanAttribute ProtectionDefaultValue() => new(this);
[SerializedIgnoreDupe]
[InvalidateProperties]
@ -166,7 +166,7 @@ public partial class BaseTalisman : Item, IAosItem
public bool ShouldSerializeKiller() => !_killer.IsEmpty;
private TalismanAttribute KillerDefaultValue() => new();
private TalismanAttribute KillerDefaultValue() => new(this);
[SerializedIgnoreDupe]
[InvalidateProperties]
@ -177,7 +177,7 @@ public partial class BaseTalisman : Item, IAosItem
public bool ShouldSerializeSummoner() => !_summoner.IsEmpty;
private TalismanAttribute SummonerDefaultValue() => new();
private TalismanAttribute SummonerDefaultValue() => new(this);
[InvalidateProperties]
[SerializableField(5)]
@ -267,9 +267,9 @@ public partial class BaseTalisman : Item, IAosItem
{
Layer = Layer.Talisman;
_protection = new TalismanAttribute();
_killer = new TalismanAttribute();
_summoner = new TalismanAttribute();
_protection = new TalismanAttribute(this);
_killer = new TalismanAttribute(this);
_summoner = new TalismanAttribute(this);
Attributes = new AosAttributes(this);
SkillBonuses = new AosSkillBonuses(this);
}
@ -319,9 +319,9 @@ public partial class BaseTalisman : Item, IAosItem
return;
}
talisman._summoner = new TalismanAttribute(_summoner);
talisman._protection = new TalismanAttribute(_protection);
talisman._killer = new TalismanAttribute(_killer);
talisman._summoner = new TalismanAttribute(talisman, _summoner);
talisman._protection = new TalismanAttribute(talisman, _protection);
talisman._killer = new TalismanAttribute(talisman, _killer);
talisman.Attributes = new AosAttributes(newItem, Attributes);
talisman.SkillBonuses = new AosSkillBonuses(newItem, SkillBonuses);
}
@ -660,17 +660,17 @@ public partial class BaseTalisman : Item, IAosItem
public virtual void SetSummoner(Type type, TextDefinition name)
{
_summoner = new TalismanAttribute(type, name);
_summoner = new TalismanAttribute(this, type, name);
}
public virtual void SetProtection(Type type, TextDefinition name, int amount)
{
_protection = new TalismanAttribute(type, name, amount);
_protection = new TalismanAttribute(this, type, name, amount);
}
public virtual void SetKiller(Type type, TextDefinition name, int amount)
{
_killer = new TalismanAttribute(type, name, amount);
_killer = new TalismanAttribute(this, type, name, amount);
}
public virtual void StartTimer()
@ -712,18 +712,18 @@ public partial class BaseTalisman : Item, IAosItem
public static Type GetRandomSummonType() => _summons.RandomElement();
public static TalismanAttribute GetRandomSummoner()
public static TalismanAttribute GetRandomSummoner(BaseTalisman owner)
{
if (Utility.RandomDouble() < 0.975)
{
return new TalismanAttribute();
return new TalismanAttribute(owner);
}
var num = Utility.Random(_summons.Length);
return num > 14
? new TalismanAttribute(_summons[num], _summonLabels[num], 10)
: new TalismanAttribute(_summons[num], _summonLabels[num]);
? new TalismanAttribute(owner, _summons[num], _summonLabels[num], 10)
: new TalismanAttribute(owner, _summons[num], _summonLabels[num]);
}
public static TalismanRemoval GetRandomRemoval()
@ -736,32 +736,32 @@ public partial class BaseTalisman : Item, IAosItem
return TalismanRemoval.None;
}
public static TalismanAttribute GetRandomKiller() => GetRandomKiller(true);
public static TalismanAttribute GetRandomKiller(BaseTalisman owner) => GetRandomKiller(owner, true);
public static TalismanAttribute GetRandomKiller(bool includingNone)
public static TalismanAttribute GetRandomKiller(BaseTalisman owner, bool includingNone)
{
if (includingNone && Utility.RandomBool())
{
return new TalismanAttribute();
return new TalismanAttribute(owner);
}
var num = Utility.Random(_killers.Length);
return new TalismanAttribute(_killers[num], _killerLabels[num], Utility.RandomMinMax(10, 100));
return new TalismanAttribute(owner, _killers[num], _killerLabels[num], Utility.RandomMinMax(10, 100));
}
public static TalismanAttribute GetRandomProtection() => GetRandomProtection(true);
public static TalismanAttribute GetRandomProtection(BaseTalisman owner) => GetRandomProtection(owner, true);
public static TalismanAttribute GetRandomProtection(bool includingNone)
public static TalismanAttribute GetRandomProtection(BaseTalisman owner, bool includingNone)
{
if (includingNone && Utility.RandomBool())
{
return new TalismanAttribute();
return new TalismanAttribute(owner);
}
var num = Utility.Random(_killers.Length);
return new TalismanAttribute(_killers[num], _killerLabels[num], Utility.RandomMinMax(5, 60));
return new TalismanAttribute(owner, _killers[num], _killerLabels[num], Utility.RandomMinMax(5, 60));
}
public static SkillName GetRandomSkill() => _skills.RandomElement();

View file

@ -8,7 +8,7 @@ public partial class RandomTalisman : BaseTalisman
[Constructible]
public RandomTalisman() : base(GetRandomItemID())
{
Summoner = GetRandomSummoner();
Summoner = GetRandomSummoner(this);
if (Summoner.IsEmpty)
{
@ -36,8 +36,8 @@ public partial class RandomTalisman : BaseTalisman
Blessed = GetRandomBlessed();
Slayer = GetRandomSlayer();
Protection = GetRandomProtection();
Killer = GetRandomKiller();
Protection = GetRandomProtection(this);
Killer = GetRandomKiller(this);
Skill = GetRandomSkill();
ExceptionalBonus = GetRandomExceptional();
SuccessBonus = GetRandomSuccessful();

View file

@ -7,6 +7,9 @@ namespace Server.Items;
[SerializationGenerator(1, false)]
public partial class TalismanAttribute
{
[DirtyTrackingEntity]
private BaseTalisman _owner;
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private Type _type;
@ -19,12 +22,12 @@ public partial class TalismanAttribute
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _amount;
public TalismanAttribute() : this(null, null)
{
}
public TalismanAttribute(BaseTalisman owner) => _owner = owner;
public TalismanAttribute(TalismanAttribute copy)
public TalismanAttribute(BaseTalisman owner, TalismanAttribute copy)
{
_owner = owner;
if (copy != null)
{
_type = copy.Type;
@ -33,8 +36,9 @@ public partial class TalismanAttribute
}
}
public TalismanAttribute(Type type, TextDefinition name, int amount = 0)
public TalismanAttribute(BaseTalisman owner, Type type, TextDefinition name, int amount = 0)
{
_owner = owner;
_type = type;
_name = name;
_amount = amount;