Skip to content

Commit ccb653a

Browse files
authored
fix(managed): Invalid ClassData creation on null returns from Core (#110)
2 parents 000ff96 + 4d20529 commit ccb653a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/managed/API/Scripting/Generic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static Player[] FindPlayersByTarget(string target, bool matchbots)
189189
Player? player = GetPlayer(i);
190190
if (player == null) continue;
191191

192-
if (player.IsFakeClient() && !matchbots) continue;
192+
if (!matchbots && player.IsFakeClient()) continue;
193193

194194
if(target == "@all")
195195
{
@@ -273,7 +273,7 @@ public static Player[] FindPlayersByTarget(string target, bool matchbots)
273273
}
274274
public static Player? GetPlayer(int playerid)
275275
{
276-
return Internal_API.Invoker.CallNative<Player?>("_G", "GetPlayer", Internal_API.CallKind.Function, playerid);
276+
return Internal_API.Invoker.CallNative<Player>("_G", "GetPlayer", Internal_API.CallKind.Function, playerid);
277277
}
278278
public static ulong GetTime()
279279
{

src/managed/Internal_API/CallContext.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,17 @@ internal unsafe object GetArgument(Type type, int index)
641641
{
642642
fixed (CallData* data = &m_cdata)
643643
{
644-
if (data->has_return == 0) return Activator.CreateInstance(type);
644+
if (data->has_return == 0)
645+
{
646+
if (type == typeof(ClassData) || typeof(ClassData).IsAssignableFrom(type))
647+
{
648+
return null;
649+
}
650+
else
651+
{
652+
return Activator.CreateInstance(type);
653+
}
654+
}
645655
byte* p = data->return_value;
646656
return ReadValue(ref type, ref p);
647657
}

0 commit comments

Comments
 (0)