Skip to content

Commit

Permalink
Monkey-patching EntityManager.Dirty() function to avoid fatal crashes…
Browse files Browse the repository at this point in the history
… in production server

Imagine having an unhandled assertion in production build? Cool? Nope.
  • Loading branch information
k3yw committed Dec 29, 2023
1 parent f3644c0 commit af0b8c5
Showing 1 changed file with 78 additions and 44 deletions.
122 changes: 78 additions & 44 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,44 +360,63 @@ public void Dirty(IComponent component, MetaDataComponent? meta = null)
/// <inheritdoc />
public virtual void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
{
DebugTools.Assert(component.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {component.GetType()}");

if (component.LifeStage >= ComponentLifeStage.Removing || !component.NetSyncEnabled)
return;
//DebugTools.Assert(component.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"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)
{
}

}

/// <inheritdoc />
public virtual void Dirty<T>(Entity<T> ent, MetaDataComponent? meta = null) where T : IComponent
{
DebugTools.Assert(ent.Comp.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"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<NetworkedComponentAttribute>(),
// $"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)
{
}

}

/// <inheritdoc />
public virtual void Dirty<T1, T2>(Entity<T1, T2> ent, MetaDataComponent? meta = null)
where T1 : IComponent
where T2 : IComponent
{
DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}");
DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}");
//DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}");
//DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"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)
{
}

}

/// <inheritdoc />
Expand All @@ -406,19 +425,26 @@ public virtual void Dirty<T1, T2, T3>(Entity<T1, T2, T3> ent, MetaDataComponent?
where T2 : IComponent
where T3 : IComponent
{
DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}");
DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}");
DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}");
//DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}");
//DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}");
//DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"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)
{
}

}

/// <inheritdoc />
Expand All @@ -428,22 +454,30 @@ public virtual void Dirty<T1, T2, T3, T4>(Entity<T1, T2, T3, T4> ent, MetaDataCo
where T3 : IComponent
where T4 : IComponent
{
DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}");
DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}");
DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}");
DebugTools.Assert(ent.Comp4.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
$"Attempted to dirty a non-networked component: {ent.Comp4.GetType()}");
//DebugTools.Assert(ent.Comp1.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"Attempted to dirty a non-networked component: {ent.Comp1.GetType()}");
//DebugTools.Assert(ent.Comp2.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"Attempted to dirty a non-networked component: {ent.Comp2.GetType()}");
//DebugTools.Assert(ent.Comp3.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"Attempted to dirty a non-networked component: {ent.Comp3.GetType()}");
//DebugTools.Assert(ent.Comp4.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
// $"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)
{

}

}

/// <summary>
Expand Down

0 comments on commit af0b8c5

Please sign in to comment.