ModernUO/Projects/Server/Serialization
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
..
AdhocPersistence.cs fix(core): Updates to serialization (#590) 2021-05-09 00:10:39 -07:00
AfterDeserialization.cs feat(codegen): Adds AfterDeserialization support (#615) 2021-05-24 22:30:13 -07:00
BinaryFileReader.cs fix(core): Cleans up serialization (#606) 2021-05-16 13:45:32 -07:00
BinaryFileWriter.cs fix(core): Updates to serialization (#590) 2021-05-09 00:10:39 -07:00
BufferReader.cs fix(core): Cleans up serialization (#606) 2021-05-16 13:45:32 -07:00
BufferWriter.cs feat: Source generated Serialization/Deserialization (#550) 2021-05-23 21:06:23 -07:00
DeltaDateTimeAttribute.cs feat: Source generated Serialization/Deserialization (#550) 2021-05-23 21:06:23 -07:00
EncodedIntAttribute.cs fix(codegen): Adds string intern, encoded int, enum and legacy version support (#613) 2021-05-24 01:01:56 -07:00
GenericPersistence.cs feat: Source generated Serialization/Deserialization (#550) 2021-05-23 21:06:23 -07:00
IGenericReader.cs fix(core): Removes byte indicator for Enum (#614) 2021-05-24 01:14:10 -07:00
IGenericWriter.cs fix(core): Removes byte indicator for Enum (#614) 2021-05-24 01:14:10 -07:00
InternStringAttribute.cs fix(codegen): Adds string intern, encoded int, enum and legacy version support (#613) 2021-05-24 01:01:56 -07:00
InvalidatePropertiesAttribute.cs feat(codegen): Adds InvalidateProperties (#616) 2021-05-24 22:49:00 -07:00
ISerializable.cs fix(core): Fixes encoded int. Adds dirty checking opt-out (#619) 2021-05-26 19:25:05 -07:00
Persistence.cs feat(logging): Adds support for Serilog (#573) 2021-04-19 23:43:54 -07:00
SerializableAttribute.cs fix(codegen): Adds string intern, encoded int, enum and legacy version support (#613) 2021-05-24 01:01:56 -07:00
SerializableFieldAttribute.cs feat(codegen): Adds support for partial opt-in with already existing properties (#617) 2021-05-26 13:20:52 -07:00
SerializableFieldAttributeAttribute.cs feat(codegen): Adds support for partial opt-in with already existing properties (#617) 2021-05-26 13:20:52 -07:00