fix: Fixes PlayerVendor customizations not working due to constructor issues (#1451)
This commit is contained in:
parent
8389bfacfe
commit
23c729f31b
3 changed files with 25 additions and 12 deletions
|
|
@ -26,6 +26,13 @@ public static class ActivatorExtensions
|
|||
Type[] args = null
|
||||
) => type.GetConstructor(predicate, args, out _);
|
||||
|
||||
public static ConstructorInfo GetConstructor(
|
||||
this Type type,
|
||||
out int paramCount,
|
||||
Predicate<ConstructorInfo> predicate = null,
|
||||
Type[] args = null
|
||||
) => type.GetConstructor(predicate, args, out paramCount);
|
||||
|
||||
public static ConstructorInfo GetConstructor(
|
||||
this Type type,
|
||||
Predicate<ConstructorInfo> predicate,
|
||||
|
|
|
|||
|
|
@ -106,11 +106,10 @@ namespace Server.Commands
|
|||
pack = from.Backpack;
|
||||
}
|
||||
|
||||
var c = copy.GetType().GetConstructor();
|
||||
var c = copy.GetType().GetConstructor(out var paramCount);
|
||||
if (c != null)
|
||||
{
|
||||
var paramList = c.GetParameters();
|
||||
var args = paramList.Length == 0 ? null : new object[paramList.Length];
|
||||
var args = paramCount == 0 ? null : new object[paramCount];
|
||||
if (args != null)
|
||||
{
|
||||
Array.Fill(args, Type.Missing);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Server.HuePickers;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Network;
|
||||
using Server.Utilities;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
|
|
@ -751,6 +753,9 @@ namespace Server.Gumps
|
|||
|
||||
private class CustomItem
|
||||
{
|
||||
private ConstructorInfo _ctor;
|
||||
private object[] _params;
|
||||
|
||||
public CustomItem(int itemID, int loc, bool longText = false) : this(null, itemID, loc, 0, longText)
|
||||
{
|
||||
}
|
||||
|
|
@ -785,22 +790,24 @@ namespace Server.Gumps
|
|||
return null;
|
||||
}
|
||||
|
||||
Item i = null;
|
||||
if (_ctor == null)
|
||||
{
|
||||
_ctor = Type.GetConstructor(out var paramCount);
|
||||
_params = paramCount == 0 ? null : new object[paramCount];
|
||||
if (_params != null)
|
||||
{
|
||||
Array.Fill(_params, Type.Missing);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var ctor = Type.GetConstructor(Array.Empty<Type>());
|
||||
if (ctor != null)
|
||||
{
|
||||
i = ctor.Invoke(null) as Item;
|
||||
}
|
||||
return _ctor?.Invoke(_params) as Item;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
return null;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue