diff --git a/Ktisis/GlobalStateAttribute.cs b/Ktisis/GlobalStateAttribute.cs
index cc661a3a3..0e83b04db 100644
--- a/Ktisis/GlobalStateAttribute.cs
+++ b/Ktisis/GlobalStateAttribute.cs
@@ -5,5 +5,7 @@ namespace Ktisis {
* Indicates that this class has global state and may contain static methods annotated with and/or .
*/
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
- public class GlobalStateAttribute : Attribute {}
+ public class GlobalStateAttribute : Attribute {
+ public Type[] InitAfter { get; set; } = Array.Empty();
+ }
}
diff --git a/Ktisis/Ktisis.cs b/Ktisis/Ktisis.cs
index f90cedf7e..5a4ce02bd 100644
--- a/Ktisis/Ktisis.cs
+++ b/Ktisis/Ktisis.cs
@@ -17,6 +17,7 @@
using Ktisis.History;
using Ktisis.Events;
using Ktisis.Overlay;
+using System.Runtime.CompilerServices;
namespace Ktisis {
public sealed class Ktisis : IDalamudPlugin {
@@ -135,8 +136,15 @@ private static void GlobalInit() {
}
private static IEnumerable GetGlobalInitTypes() =>
- typeof(Ktisis).Assembly.GetTypes()
- .Where(x => x.CustomAttributes.Any(x => x.AttributeType == typeof(GlobalStateAttribute)));
+ typeof(Ktisis).Assembly.GetTypes().Select(type => (type, globalStateAttr: type.GetCustomAttribute()))
+ .Where(x => x.globalStateAttr != null)
+ .OrderBy(x => (x.type, initAfter: new HashSet(x.globalStateAttr!.InitAfter)), new DelegateComparer<(Type type, HashSet initAfter)>((a, b) => {
+ if(a.initAfter.Contains(b.type))
+ return 1;
+ if(b.initAfter.Contains(a.type))
+ return -1;
+ return 0;
+ })).Select(x => x.type);
private static void GlobalDispose() {
while (ToGloballyDispose.TryPop(out MethodInfo? toDispose)) {
@@ -144,4 +152,18 @@ private static void GlobalDispose() {
}
}
}
+
+ public struct DelegateComparer : IComparer {
+
+ public delegate int Comparer(T? x, T? y);
+
+ public Comparer comparer;
+
+ public DelegateComparer(Comparer comparer) {
+ this.comparer = comparer;
+ }
+
+ public int Compare(T? x, T? y) => this.comparer(x, y);
+ }
+
}