Fix CreateServerEventString

Prevents AmbiguousMatchException
Reuses GetComponentString to get the component
Fixes wrong Invoke Parameters
This commit is contained in:
Roland Firmont
2022-03-21 15:32:35 +01:00
committed by GitHub
parent a3263ce3eb
commit 65dbc6fc00

View File

@@ -61,26 +61,26 @@ namespace Barotrauma
{
public object CreateServerEventString(string component)
{
Type type = Type.GetType("Barotrauma.Items.Components." + component);
var comp = GetComponentString(component);
if (type == null)
if (comp == null)
return null;
MethodInfo method = typeof(Item).GetMethod(nameof(Item.CreateServerEvent));
MethodInfo generic = method.MakeGenericMethod(type);
return generic.Invoke(this, null);
MethodInfo method = typeof(Item).GetMethod(nameof(Item.CreateServerEvent), new Type[]{ Type.MakeGenericMethodParameter(0) });
MethodInfo generic = method.MakeGenericMethod(comp.GetType());
return generic.Invoke(this, new object[]{ comp });
}
public object CreateServerEventString(string component, object[] extraData)
{
Type type = Type.GetType("Barotrauma.Items.Components." + component);
var comp = GetComponentString(component);
if (type == null)
if (comp == null)
return null;
MethodInfo method = typeof(Item).GetMethod(nameof(Item.CreateServerEvent));
MethodInfo generic = method.MakeGenericMethod(type);
return generic.Invoke(this, new object[]{ extraData });
MethodInfo method = typeof(Item).GetMethod(nameof(Item.CreateServerEvent), new Type[]{ Type.MakeGenericMethodParameter(0), typeof(object[]) });
MethodInfo generic = method.MakeGenericMethod(comp.GetType());
return generic.Invoke(this, new object[]{comp, extraData });
}
}
@@ -133,4 +133,4 @@ namespace Barotrauma.Items.Components
}
}
}