ModernUO/Projects/Server/Items
Kamron Batman 312e3873f1
fix(core): Fixes encoded int. Adds dirty checking opt-out (#619)
### Additions
- Automatically opts-out `Item/Mobile/Guild/Accounts` from dirty checking with a new property `UseDirtyChecking`
- Codegen now enables `UseDirtyChecking` via getter. This requires that the property is `virtual` for derived types.

### Fixes
- Fixes `EncodedInt` being broken
- Fixes issues with new custom serializable types that are not derived from Item/Mobile/etc.
- Removes double dirty checking.

### Example of a brand new serializable type that isn't an Item/Mobile/etc.
User created code:
```cs
using System;

namespace Server.Items
{
    [Serializable(0)]
    public partial class NewTestEntityObject : ISerializable
    {
        [EncodedInt]
        [SerializableField(0)]
        private int _someProperty;

        public NewTestEntityObject()
        {
            SetTypeRef(GetType());
            // Add to serial tracking like World.Item
            /*
            Serial = World.NewEntity;
            World.AddEntity(this);
            */
        }

        [AfterDeserialization]
        private void AfterDeserialization()
        {
            Console.WriteLine("This ran!");
        }

        public int TypeRef { get; }
        public Serial Serial { get; }
        public void Delete()
        {
        }

        public bool Deleted { get; set; }
        public void SetTypeRef(Type type)
        {
            // Type tracking for persistence goes here
            /*
            TypeRef = World.NewEntityTypes.IndexOf(type);
            if (TypeRef == -1)
            {
                World.NewEntityTypes.Add(type);
                TypeRef = World.NewEntityTypes.Count - 1;
            }
            */
        }
    }
}
```

Generated code:
```cs
namespace Server.Items
{
    public partial class NewTestEntityObject
    {
#pragma warning disable 0414
        private const int _version = 0;
#pragma warning restore 0414

        public int SomeProperty
        {
            get => _someProperty;
            set
            {
                if (value != _someProperty)
                {
                    _someProperty = value;
                    ((ISerializable)this).MarkDirty();
                }
            }
        }

        long ISerializable.SavePosition { get; set; } = -1;
        BufferWriter ISerializable.SaveBuffer { get; set; }
        bool ISerializable.UseDirtyChecking => true;

        public NewTestEntityObject(Serial serial)
        {
            Serial = serial;
            SetTypeRef(typeof(NewTestEntityObject));
        }

        public void Serialize(IGenericWriter writer)
        {

            writer.WriteEncodedInt(_version);

            writer.WriteEncodedInt(SomeProperty);
        }

        public void Deserialize(IGenericReader reader)
        {
            var version = reader.ReadEncodedInt();

            SomeProperty = reader.ReadEncodedInt();

            Timer.DelayCall(AfterDeserialization);
        }
    }
}
```
2021-05-26 19:25:05 -07:00
..
BaseMulti.cs fix(core): Converts to ref struct enumerators (#426) 2021-01-22 19:41:44 -08:00
Container.cs chore(logging): Logging cleanup (#580) 2021-04-23 18:57:42 -07:00
Containers.cs fix(core): Fixes several serialization issues (#355) 2020-12-23 07:11:41 -08:00
Item.cs fix(core): Fixes encoded int. Adds dirty checking opt-out (#619) 2021-05-26 19:25:05 -07:00
ItemBounds.cs Cleanup/Housekeeping (#242) 2020-09-12 15:31:21 -07:00
Layer.cs Cleanup/Housekeeping (#242) 2020-09-12 15:31:21 -07:00
LightType.cs Cleanup/Housekeeping (#242) 2020-09-12 15:31:21 -07:00
SecureTradeContainer.cs fix(core): Converts some packets & misc fixes/cleanup (#414) 2021-01-16 21:01:54 -08:00
VirtualCheck.cs fix(currency): Changes virtual checks setting (#598) 2021-05-12 10:52:34 -07:00
VirtualHair.cs fix(party): Converts party packets (#401) 2021-01-10 14:23:10 -08:00