using System; using System.Linq; using System.Linq.Expressions; using HarmonyLib; using Svelto.ECS; namespace TechbloxModdingAPI.Common.Utils { public static class EcsUtils { public static Type[] GetValidEntityComponents(Type entityDescriptorType) { // TODO: Cache var templateType = typeof(EntityDescriptorTemplate<>).MakeGenericType(entityDescriptorType); var templateDescriptor = AccessTools.Property(templateType, "descriptor"); var getDescriptorExpr = Expression.MakeMemberAccess(null, templateDescriptor ?? throw new InvalidOperationException()); var getTemplateDescriptorExpr = Expression.Lambda>(getDescriptorExpr); var getTemplateDescriptor = getTemplateDescriptorExpr.Compile(); var builders = getTemplateDescriptor().componentsToBuild; return builders.Select(builder => builder.GetEntityComponentType()).ToArray(); } } }