From af0b8c5841b785299e6cde906485f5efeb1f0762 Mon Sep 17 00:00:00 2001 From: k3ywarrior Date: Sat, 30 Dec 2023 06:08:55 +0700 Subject: [PATCH] Monkey-patching EntityManager.Dirty() function to avoid fatal crashes in production server Imagine having an unhandled assertion in production build? Cool? Nope. --- Robust.Shared/GameObjects/EntityManager.cs | 122 +++++++++++++-------- 1 file changed, 78 insertions(+), 44 deletions(-) diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 614e1c504b8..27034ddb582 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -360,27 +360,39 @@ public void Dirty(IComponent component, MetaDataComponent? meta = null) /// public virtual void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null) { - DebugTools.Assert(component.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {component.GetType()}"); - - if (component.LifeStage >= ComponentLifeStage.Removing || !component.NetSyncEnabled) - return; + //DebugTools.Assert(component.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {component.GetType()}"); + try + { + if (component.LifeStage >= ComponentLifeStage.Removing || !component.NetSyncEnabled) + return; - DirtyEntity(uid, meta); - component.LastModifiedTick = CurrentTick; + DirtyEntity(uid, meta); + component.LastModifiedTick = CurrentTick; + } + catch (Exception) + { + } + } /// public virtual void Dirty(Entity ent, MetaDataComponent? meta = null) where T : IComponent { - DebugTools.Assert(ent.Comp.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp.GetType()}"); - - if (ent.Comp.LifeStage >= ComponentLifeStage.Removing || !ent.Comp.NetSyncEnabled) - return; + //DebugTools.Assert(ent.Comp.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp.GetType()}"); + try + { + if (ent.Comp.LifeStage >= ComponentLifeStage.Removing || !ent.Comp.NetSyncEnabled) + return; - DirtyEntity(ent, meta); - ent.Comp.LastModifiedTick = CurrentTick; + DirtyEntity(ent, meta); + ent.Comp.LastModifiedTick = CurrentTick; + } + catch (Exception) + { + } + } /// @@ -388,16 +400,23 @@ public virtual void Dirty(Entity ent, MetaDataComponent? meta = where T1 : IComponent where T2 : IComponent { - DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}"); - DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}"); + //DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}"); + //DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}"); // We're not gonna bother checking ent.Comp.NetSyncEnabled // chances are at least one of these components didn't get net-sync disabled. - DirtyEntity(ent, meta); - ent.Comp1.LastModifiedTick = CurrentTick; - ent.Comp2.LastModifiedTick = CurrentTick; + try + { + DirtyEntity(ent, meta); + ent.Comp1.LastModifiedTick = CurrentTick; + ent.Comp2.LastModifiedTick = CurrentTick; + } + catch (Exception) + { + } + } /// @@ -406,19 +425,26 @@ public virtual void Dirty(Entity ent, MetaDataComponent? where T2 : IComponent where T3 : IComponent { - DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}"); - DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}"); - DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}"); + //DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}"); + //DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}"); + //DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}"); // We're not gonna bother checking ent.Comp.NetSyncEnabled // chances are at least one of these components didn't get net-sync disabled. - DirtyEntity(ent, meta); - ent.Comp1.LastModifiedTick = CurrentTick; - ent.Comp2.LastModifiedTick = CurrentTick; - ent.Comp3.LastModifiedTick = CurrentTick; + try + { + DirtyEntity(ent, meta); + ent.Comp1.LastModifiedTick = CurrentTick; + ent.Comp2.LastModifiedTick = CurrentTick; + ent.Comp3.LastModifiedTick = CurrentTick; + } + catch (Exception) + { + } + } /// @@ -428,22 +454,30 @@ public virtual void Dirty(Entity ent, MetaDataCo where T3 : IComponent where T4 : IComponent { - DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}"); - DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}"); - DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}"); - DebugTools.Assert(ent.Comp4.GetType().HasCustomAttribute(), - $"Attempted to dirty a non-networked component: {ent.Comp4.GetType()}"); + //DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}"); + //DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}"); + //DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}"); + //DebugTools.Assert(ent.Comp4.GetType().HasCustomAttribute(), + // $"Attempted to dirty a non-networked component: {ent.Comp4.GetType()}"); // We're not gonna bother checking ent.Comp.NetSyncEnabled // chances are at least one of these components didn't get net-sync disabled. - DirtyEntity(ent, meta); - ent.Comp1.LastModifiedTick = CurrentTick; - ent.Comp2.LastModifiedTick = CurrentTick; - ent.Comp3.LastModifiedTick = CurrentTick; - ent.Comp4.LastModifiedTick = CurrentTick; + try + { + DirtyEntity(ent, meta); + ent.Comp1.LastModifiedTick = CurrentTick; + ent.Comp2.LastModifiedTick = CurrentTick; + ent.Comp3.LastModifiedTick = CurrentTick; + ent.Comp4.LastModifiedTick = CurrentTick; + } + catch (Exception) + { + + } + } ///