diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 5fe179479..4e3d6f8e4 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1430,6 +1430,10 @@ namespace Barotrauma msg.Write(((Rectangle)value).Width); msg.Write(((Rectangle)value).Height); } + else if (value is Enum) + { + msg.Write((int)value); + } else { throw new System.NotImplementedException("Serializing item properties of the type \"" + value.GetType() + "\" not supported"); @@ -1487,6 +1491,24 @@ namespace Barotrauma { property.TrySetValue(new Vector4(msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32())); } + else if (typeof(Enum).IsAssignableFrom(type)) + { + int intVal = msg.ReadInt32(); + try + { + property.TrySetValue(Enum.ToObject(type, intVal)); + } + catch (Exception e) + { +#if DEBUG + DebugConsole.ThrowError("Failed to convert the int value \"" + intVal + "\" to " + type, e); +#endif + GameAnalyticsManager.AddErrorEventOnce( + "Item.ReadPropertyChange:" + Name + ":" + type, + GameAnalyticsSDK.Net.EGAErrorSeverity.Warning, + "Failed to convert the int value \"" + intVal + "\" to " + type + " (item " + Name + ")"); + } + } else { return; diff --git a/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs b/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs index 6ab463699..7e1d34860 100644 --- a/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs +++ b/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs @@ -223,6 +223,7 @@ namespace Barotrauma return false; } propertyInfo.SetValue(obj, enumVal); + return true; } else {