From 6c492fa35f72386994f713f0f657fd36c0e2cde8 Mon Sep 17 00:00:00 2001 From: "Diffuin[bot]" Date: Wed, 12 Aug 2026 23:01:35 +0000 Subject: [PATCH 1/3] chore(diffuin): address #242 --- .../NPCDiagnosticCompatibilityTests.cs | 18 ++++++++----- S1API/Entities/NPC.cs | 26 +++++++++++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs b/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs index 34761681..d86b00c0 100644 --- a/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs +++ b/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using S1API.Entities; +using S1API.Map; using S1API.Entities.Dealer; namespace S1API.Tests.Entities; @@ -32,7 +33,7 @@ public void ManualPrefabRegistrationApisRetainTheirPublicShape(string methodName { ParameterInfo parameter = Assert.Single(parameters); Assert.Equal("npcType", parameter.Name); - Assert.Equal(typeof(Type), parameter.ParameterType); + Assert.Equal(typeof(System.Type), parameter.ParameterType); } } @@ -47,13 +48,18 @@ public void DealerDefaultsDoNotReportUnsupportedOptionsWhenTheyWereOmitted() } [Fact] - public void ReviveRetainsItsPublicShape() + public void CurrentBuildingRetainsItsPublicShape() { - MethodInfo? method = typeof(NPC).GetMethod(nameof(NPC.Revive), BindingFlags.Public | BindingFlags.Instance); + var property = typeof(NPC).GetProperty( + nameof(NPC.CurrentBuilding), + BindingFlags.Public | BindingFlags.Instance); - Assert.NotNull(method); - Assert.Equal(typeof(void), method.ReturnType); - Assert.Empty(method.GetParameters()); + Assert.NotNull(property); + Assert.Equal(typeof(Building), property!.PropertyType); + Assert.True(property.CanRead); + Assert.False(property.CanWrite); + Assert.NotNull(property.GetGetMethod()); + Assert.True(property.GetGetMethod()!.IsPublic); } [Fact] diff --git a/S1API/Entities/NPC.cs b/S1API/Entities/NPC.cs index a3118886..e48c3514 100644 --- a/S1API/Entities/NPC.cs +++ b/S1API/Entities/NPC.cs @@ -2797,8 +2797,30 @@ public bool RequiresRegionUnlocked #endif } - // TODO: Add CurrentBuilding (currently missing NPCEnterableBuilding abstraction) - // public ??? CurrentBuilding { get; set; } + /// + /// The enterable building the NPC is currently in, if any. + /// + public Map.Building? CurrentBuilding + { + get + { + object? currentBuilding = S1NPC.CurrentBuilding; + if (currentBuilding == null) + return null; + + var buildingName = ReflectionUtils.TryGetFieldOrProperty(currentBuilding, "BuildingName") as string; + if (!string.IsNullOrWhiteSpace(buildingName)) + { + Map.Building? building = Map.Building.GetByName(buildingName); + if (building != null) + return building; + + return new Map.Building(buildingName, currentBuilding); + } + + return new Map.Building(currentBuilding.GetType().Name, currentBuilding); + } + } /// /// The current vehicle the NPC is occupying, if any. From 5642b443e29980532732c2f3095f20a04eb3c774 Mon Sep 17 00:00:00 2001 From: "Diffuin[bot]" Date: Wed, 12 Aug 2026 23:25:21 +0000 Subject: [PATCH 2/3] chore(diffuin): address #265 --- .../Entities/NPCDiagnosticCompatibilityTests.cs | 17 +++++++---------- S1API/Entities/NPC.cs | 17 +++-------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs b/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs index d86b00c0..9f3139fb 100644 --- a/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs +++ b/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs @@ -1,6 +1,5 @@ using System.Reflection; using S1API.Entities; -using S1API.Map; using S1API.Entities.Dealer; namespace S1API.Tests.Entities; @@ -48,18 +47,16 @@ public void DealerDefaultsDoNotReportUnsupportedOptionsWhenTheyWereOmitted() } [Fact] - public void CurrentBuildingRetainsItsPublicShape() + public void ReviveRetainsItsPublicShape() { - var property = typeof(NPC).GetProperty( - nameof(NPC.CurrentBuilding), + MethodInfo? method = typeof(NPC).GetMethod( + nameof(NPC.Revive), BindingFlags.Public | BindingFlags.Instance); - Assert.NotNull(property); - Assert.Equal(typeof(Building), property!.PropertyType); - Assert.True(property.CanRead); - Assert.False(property.CanWrite); - Assert.NotNull(property.GetGetMethod()); - Assert.True(property.GetGetMethod()!.IsPublic); + Assert.NotNull(method); + Assert.False(method!.IsStatic); + Assert.Equal(typeof(void), method.ReturnType); + Assert.Empty(method.GetParameters()); } [Fact] diff --git a/S1API/Entities/NPC.cs b/S1API/Entities/NPC.cs index e48c3514..ff8bbc5e 100644 --- a/S1API/Entities/NPC.cs +++ b/S1API/Entities/NPC.cs @@ -2805,20 +2805,9 @@ public Map.Building? CurrentBuilding get { object? currentBuilding = S1NPC.CurrentBuilding; - if (currentBuilding == null) - return null; - - var buildingName = ReflectionUtils.TryGetFieldOrProperty(currentBuilding, "BuildingName") as string; - if (!string.IsNullOrWhiteSpace(buildingName)) - { - Map.Building? building = Map.Building.GetByName(buildingName); - if (building != null) - return building; - - return new Map.Building(buildingName, currentBuilding); - } - - return new Map.Building(currentBuilding.GetType().Name, currentBuilding); + return currentBuilding == null + ? null + : Map.Building.All.FirstOrDefault(building => ReferenceEquals(building._gameBuilding, currentBuilding)); } } From 392a5fae687c4d3d01ee0ad9601ac91958651715 Mon Sep 17 00:00:00 2001 From: "Diffuin[bot]" Date: Wed, 12 Aug 2026 23:26:51 +0000 Subject: [PATCH 3/3] chore(diffuin): address #265 --- S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs b/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs index 9f3139fb..34761681 100644 --- a/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs +++ b/S1API.Tests/Entities/NPCDiagnosticCompatibilityTests.cs @@ -32,7 +32,7 @@ public void ManualPrefabRegistrationApisRetainTheirPublicShape(string methodName { ParameterInfo parameter = Assert.Single(parameters); Assert.Equal("npcType", parameter.Name); - Assert.Equal(typeof(System.Type), parameter.ParameterType); + Assert.Equal(typeof(Type), parameter.ParameterType); } } @@ -49,12 +49,9 @@ public void DealerDefaultsDoNotReportUnsupportedOptionsWhenTheyWereOmitted() [Fact] public void ReviveRetainsItsPublicShape() { - MethodInfo? method = typeof(NPC).GetMethod( - nameof(NPC.Revive), - BindingFlags.Public | BindingFlags.Instance); + MethodInfo? method = typeof(NPC).GetMethod(nameof(NPC.Revive), BindingFlags.Public | BindingFlags.Instance); Assert.NotNull(method); - Assert.False(method!.IsStatic); Assert.Equal(typeof(void), method.ReturnType); Assert.Empty(method.GetParameters()); }