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:
@@ -1430,6 +1430,10 @@ namespace Barotrauma
|
|||||||
msg.Write(((Rectangle)value).Width);
|
msg.Write(((Rectangle)value).Width);
|
||||||
msg.Write(((Rectangle)value).Height);
|
msg.Write(((Rectangle)value).Height);
|
||||||
}
|
}
|
||||||
|
else if (value is Enum)
|
||||||
|
{
|
||||||
|
msg.Write((int)value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException("Serializing item properties of the type \"" + value.GetType() + "\" not supported");
|
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()));
|
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
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -223,6 +223,7 @@ namespace Barotrauma
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
propertyInfo.SetValue(obj, enumVal);
|
propertyInfo.SetValue(obj, enumVal);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user