Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions S1API.Tests/Entities/NPCPanicApiCompatibilityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#if IL2CPPMELON
using NativeNpc = Il2CppScheduleOne.NPCs.NPC;
#elif MONOMELON
using NativeNpc = ScheduleOne.NPCs.NPC;
#endif

using System.Reflection;
using S1API.Entities;

namespace S1API.Tests.Entities;

public sealed class NPCPanicApiCompatibilityTests
{
[Fact]
public void PanicRetainsItsParameterlessManagedSurface()
{
MethodInfo? method = typeof(NPC).GetMethod(
nameof(NPC.Panic),
BindingFlags.Public | BindingFlags.Instance,
binder: null,
types: Type.EmptyTypes,
modifiers: null);

Assert.NotNull(method);
Assert.Equal(typeof(void), method!.ReturnType);
Assert.Empty(method.GetParameters());
}

[Fact]
public void NativePanicRpcRemainsParameterless()
{
MethodInfo? method = typeof(NativeNpc).GetMethod(
"SetPanicked_Server",
BindingFlags.Public | BindingFlags.Instance,
binder: null,
types: Type.EmptyTypes,
modifiers: null);

Assert.NotNull(method);
Assert.Equal(typeof(void), method!.ReturnType);
Assert.Empty(method.GetParameters());
}
}
26 changes: 2 additions & 24 deletions S1API/Entities/NPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2624,19 +2624,6 @@ private void EnsureMessageConversationInstance(ConversationCategoryList categori
}
}

private static bool SafeIsServer()
{
try
{
var nm = InstanceFinder.NetworkManager;
return nm != null && nm.IsServer;
}
catch
{
return false;
}
}

private static object? GetGameMember(object? target, string memberName)
{
return target == null
Expand Down Expand Up @@ -2907,19 +2894,10 @@ public void LerpScale(float scale, float lerpTime) =>
S1NPC.SetScale(scale, lerpTime);

/// <summary>
/// Causes the NPC to become panicked.
/// Currently host/server-only: non-host clients hit the SafeIsServer guard below and this becomes a silent no-op,
/// which is inconsistent with other server-RPC-style wrappers in the API and with the runtime docs.
/// Requests that the NPC become panicked.
/// </summary>
public void Panic()
{
// TODO: Revisit this guard. Unlike wrappers such as Cartel.SetStatus and CombatBehaviour.SetAndAttackTarget,
// Panic() can no longer be invoked meaningfully from multiplayer clients because non-host callers return here.
if (!SafeIsServer())
return;

public void Panic() =>
S1NPC.SetPanicked_Server();
}

/// <summary>
/// Causes the NPC to stop panicking, if they are currently.
Expand Down
Loading