Fixed "failed to write event" errors when a client or server tries to change an enum value of an item (e.g. the output type of an oscillator component)

This commit is contained in:
Joonas Rikkonen
2018-07-20 15:18:46 +03:00
parent a61ac1716d
commit 0abdcb969d
2 changed files with 23 additions and 0 deletions

View File

@@ -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;

View File

@@ -223,6 +223,7 @@ namespace Barotrauma
return false;
}
propertyInfo.SetValue(obj, enumVal);
return true;
}
else
{