From b6ab9dddc7e293e99688492e55c19a6d417dbe88 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:05:04 -0400 Subject: [PATCH] Fix xenoarch exceptions + misc. cleanup (#38742) --- .../Artifact/XAT/XATMagnetSystem.cs | 2 +- .../Components/XenoArtifactNodeComponent.cs | 2 +- .../SharedXenoArtifactSystem.Graph.cs | 24 +++++++++---------- .../Artifact/SharedXenoArtifactSystem.Node.cs | 16 +++++-------- .../SharedXenoArtifactSystem.Unlock.cs | 2 +- .../Artifact/XAT/BaseQueryUpdateXATSystem.cs | 2 +- .../Artifact/XAT/XATDeathSystem.cs | 2 +- 7 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Content.Server/Xenoarchaeology/Artifact/XAT/XATMagnetSystem.cs b/Content.Server/Xenoarchaeology/Artifact/XAT/XATMagnetSystem.cs index d045682d55..5656182a9e 100644 --- a/Content.Server/Xenoarchaeology/Artifact/XAT/XATMagnetSystem.cs +++ b/Content.Server/Xenoarchaeology/Artifact/XAT/XATMagnetSystem.cs @@ -54,7 +54,7 @@ public sealed class XATMagnetSystem : BaseQueryUpdateXATSystem [DataField, AutoNetworkedField] - public NetEntity? Attached; + public EntityUid? Attached; #region Durability /// diff --git a/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Graph.cs b/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Graph.cs index fca5baf10f..24ff50b5ed 100644 --- a/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Graph.cs +++ b/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Graph.cs @@ -53,8 +53,8 @@ public abstract partial class SharedXenoArtifactSystem /// Throws if requested index doesn't exist on artifact. public Entity GetNode(Entity ent, int index) { - if (ent.Comp.NodeVertices[index] is { } netUid && GetEntity(netUid) is var uid) - return (uid, XenoArtifactNode(uid)); + if (ent.Comp.NodeVertices[index] is { } netUid && GetEntity(netUid) is var uid && _nodeQuery.TryComp(uid, out var comp)) + return (uid, comp); throw new ArgumentException($"index {index} does not correspond to an existing node in {ToPrettyString(ent)}"); } @@ -71,8 +71,8 @@ public abstract partial class SharedXenoArtifactSystem if (index < 0 || index >= ent.Comp.NodeVertices.Length) return false; - if (ent.Comp.NodeVertices[index] is { } netUid && GetEntity(netUid) is var uid) - node = (uid, XenoArtifactNode(uid)); + if (ent.Comp.NodeVertices[index] is { } netUid && GetEntity(netUid) is var uid && _nodeQuery.TryComp(uid, out var comp)) + node = (uid, comp); return node != null; } @@ -102,8 +102,8 @@ public abstract partial class SharedXenoArtifactSystem { foreach (var netNode in ent.Comp.NodeVertices) { - if (TryGetEntity(netNode, out var node)) - yield return (node.Value, XenoArtifactNode(node.Value)); + if (TryGetEntity(netNode, out var node) && _nodeQuery.TryComp(node, out var comp)) + yield return (node.Value, comp); } } @@ -253,7 +253,8 @@ public abstract partial class SharedXenoArtifactSystem return false; var uid = Spawn(entProtoId); - node = (uid, XenoArtifactNode(uid)); + var comp = EnsureComp(uid); + node = (uid, comp); return AddNode(ent, (node.Value, node.Value.Comp), dirty: dirty); } @@ -269,11 +270,10 @@ public abstract partial class SharedXenoArtifactSystem /// True if node adding was successful, false otherwise. public bool AddNode(Entity ent, Entity node, bool dirty = true) { - if (!Resolve(ent, ref ent.Comp)) + if (!Resolve(ent, ref ent.Comp) || !Resolve(node, ref node.Comp, false)) return false; - node.Comp ??= XenoArtifactNode(node); - node.Comp.Attached = GetNetEntity(ent); + node.Comp.Attached = ent.Owner; var nodeIdx = GetFreeNodeIndex((ent, ent.Comp)); _container.Insert(node.Owner, ent.Comp.NodeContainer); @@ -300,11 +300,9 @@ public abstract partial class SharedXenoArtifactSystem /// True if node was removed successfully, false otherwise. public bool RemoveNode(Entity ent, Entity node, bool dirty = true) { - if (!Resolve(ent, ref ent.Comp)) + if (!Resolve(ent, ref ent.Comp) || !Resolve(node, ref node.Comp, false)) return false; - node.Comp ??= XenoArtifactNode(node); - if (!TryGetIndex(ent, node, out var idx)) return false; // node isn't attached to this entity. diff --git a/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Node.cs b/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Node.cs index 899e578bcf..09a1e0bfea 100644 --- a/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Node.cs +++ b/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Node.cs @@ -33,21 +33,14 @@ public abstract partial class SharedXenoArtifactSystem SetNodeDurability((ent, ent), nodeComponent.MaxDurability); } - /// Gets node component by node entity uid. - public XenoArtifactNodeComponent XenoArtifactNode(EntityUid uid) - { - return _nodeQuery.Get(uid); - } - public void SetNodeUnlocked(Entity ent) { if (!Resolve(ent, ref ent.Comp)) return; - if (ent.Comp.Attached is not { } netArtifact) + if (ent.Comp.Attached is not { } artifact) return; - var artifact = GetEntity(netArtifact); if (!TryComp(artifact, out var artifactComponent)) return; @@ -197,7 +190,10 @@ public abstract partial class SharedXenoArtifactSystem foreach (var netNode in segment) { var node = GetEntity(netNode); - outSegment.Add((node, XenoArtifactNode(node))); + if (!_nodeQuery.TryComp(node, out var comp)) + continue; + + outSegment.Add((node, comp)); } output.Add(outSegment); @@ -385,7 +381,7 @@ public abstract partial class SharedXenoArtifactSystem return; } - var artifact = _xenoArtifactQuery.Get(GetEntity(nodeComponent.Attached.Value)); + var artifact = _xenoArtifactQuery.Get(nodeComponent.Attached.Value); var nonactiveNodes = GetActiveNodes(artifact); var durabilityEffect = MathF.Pow((float)nodeComponent.Durability / nodeComponent.MaxDurability, 2); diff --git a/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Unlock.cs b/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Unlock.cs index 57d6502bfb..fedb7f1f60 100644 --- a/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Unlock.cs +++ b/Content.Shared/Xenoarchaeology/Artifact/SharedXenoArtifactSystem.Unlock.cs @@ -45,7 +45,7 @@ public abstract partial class SharedXenoArtifactSystem if (!Resolve(ent, ref ent.Comp)) return false; - var artifact = GetEntity(ent.Comp.Attached); + var artifact = ent.Comp.Attached; if (!TryComp(artifact, out var artiComp)) return false; diff --git a/Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs b/Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs index 5a7fc53e9e..0abad7bdd5 100644 --- a/Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs +++ b/Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs @@ -31,7 +31,7 @@ public abstract class BaseQueryUpdateXATSystem : BaseXATSystem where T : C if (node.Attached == null) continue; - var artifact = _xenoArtifactQuery.Get(GetEntity(node.Attached.Value)); + var artifact = _xenoArtifactQuery.Get(node.Attached.Value); if (!CanTrigger(artifact, (uid, node))) continue; diff --git a/Content.Shared/Xenoarchaeology/Artifact/XAT/XATDeathSystem.cs b/Content.Shared/Xenoarchaeology/Artifact/XAT/XATDeathSystem.cs index 747bd82feb..50a7b0200e 100644 --- a/Content.Shared/Xenoarchaeology/Artifact/XAT/XATDeathSystem.cs +++ b/Content.Shared/Xenoarchaeology/Artifact/XAT/XATDeathSystem.cs @@ -36,7 +36,7 @@ public sealed class XATDeathSystem : BaseXATSystem if (node.Attached == null) continue; - var artifact = _xenoArtifactQuery.Get(GetEntity(node.Attached.Value)); + var artifact = _xenoArtifactQuery.Get(node.Attached.Value); if (!CanTrigger(artifact, (uid, node))) continue; -- 2.51.2