public static bool PreCallAll()
        {
            Log.Message("Static constructors? Oh, sit down, vanilla, I'll do it myself. Starting now, at " + DateTime.Now.ToLongTimeString(), true);
            _toRun = GenTypes.AllTypesWithAttribute <StaticConstructorOnStartup>().ToList();

            BetterLoadingMain.LoadingScreen.StartCoroutine(StaticConstructAll());

            Log.Message("[BetterLoading] Overriding LongEventHandler's toExecuteWhenFinished", true);

            var result = LongEventHandlerMirror.ToExecuteWhenFinished;

            Log.Message($"[BetterLoading]    Got list of pending actions: {result}. Removing up to and including the static constructor call...", true);

            var staticCallIdx = result.FindIndex(i => i.Method.DeclaringType?.Name == "PlayDataLoader" && i.Method.Name.Contains("m__2"));

            Log.Message($"[BetterLoading]        (Which is at index {staticCallIdx} of {result.Count})", true);

            result = result.Skip(staticCallIdx + 1).Take(int.MaxValue).ToList(); //Remove the static constructor call

            _queue = result;

            Log.Message($"[BetterLoading]     Updating field in LEH to a new list of size {result.Count}...", true);
            LongEventHandlerMirror.ToExecuteWhenFinished = new List <Action>();

            LongEventHandler.QueueLongEvent(WaitForStaticCtors, null, true, null);

            return(false);
        }
示例#2
0
 public static void Prefix()
 {
     Log.Message("Loading Screen Manager :: Call Static CCtors :: Start");
     Manager.currentStage = LoadingStage.FinishUp;
     Manager.numStaticConstructorsToCall =
         GenTypes.AllTypesWithAttribute <StaticConstructorOnStartup>().Count();
 }
示例#3
0
        public override bool Prepare(Node node)
        {
            if (!base.Prepare(node))
            {
                return(false);
            }
            var DebugLevel   = node.DebugLevel;
            var DebugMessage = node.DebugMessage;
            var targets      = Targets(node.inputPorts);

            FieldToStat        = new Dictionary <FieldInfo, StatDef>();
            StatDefOfFieldInfo = new List <FieldInfo>();
            foreach (Type type in GenTypes.AllTypesWithAttribute <DefOf>())
            {
                foreach (FieldInfo field in type.GetFields().Where(t => t.FieldType == typeof(StatDef)))
                {
                    if (targets.GetData <StatDef>().FirstOrFallback(t => field.Name.Equals(t.defName)) is StatDef stat)
                    {
                        StatDefOfFieldInfo.Add(field);
                        FieldToStat.Add(field, stat);
                    }
                }
            }
            if (DebugLevel > 1)
            {
                DebugMessage.AppendLine($"Initialize stage: From [{defName}]: StatSearch method:\nFieldToStat:");
                FieldToStat.Do(t => DebugMessage.AppendLine($"{t.Key} : {t.Value} [{t.Key.DeclaringType}]"));
            }
            return(true);
        }
示例#4
0
        public static void FindSettingsDependentFields()
        {
#if DEBUG
            Log.Message("Finding settings dependant fields");
#endif
            var traverses = new List <Traverse>();

            var markedTypes = GenTypes.AllTypesWithAttribute <NVHasSettingsDependentFieldAttribute>();

            foreach (var type in markedTypes)
            {
                var fields = AccessTools.GetDeclaredFields(type)
                             .FindAll(fi => fi.HasAttribute <NVSettingsDependentFieldAttribute>());

#if DEBUG
                Log.Message($"Type: {type}");
#endif
                foreach (var info in fields)
                {
                    var traverse = new Traverse(type);
                    traverse = traverse.Field(info.Name);


#if DEBUG
                    Log.Message($"Field: {info.Name}");
#endif

                    traverses.Add(traverse);
                }
            }


            SettingsDependentFieldTraverses = traverses;
        }
 public override void Initialize(bool fromSave = false)
 {
     if (!replaceStatField.EnumerableNullOrEmpty())
     {
         return;
     }
     if (!replaceStat.EnumerableNullOrEmpty())
     {
         List <StatDef> statOut = replaceStat.Values.ToList();
         statOut.RemoveDuplicates();
         replaceStatField = replaceStat.Keys.ToDictionary(t => t, t => null as FieldInfo);
         foreach (Type type in GenTypes.AllTypesWithAttribute <DefOf>())
         {
             foreach (FieldInfo field in type.GetFields().Where(t => t.FieldType == typeof(StatDef)))
             {
                 if (statOut.FirstOrFallback(t => field.Name.Equals(t.defName)) is StatDef stat && !replaceStatField.ContainsKey(stat))
                 {
                     foreach (KeyValuePair <StatDef, StatDef> pair in replaceStat.Where(t => t.Value == stat))
                     {
                         replaceStatField[pair.Key] = field;
                     }
                 }
             }
         }
         return;
     }
     Log.Error($"[[LC]AutoPatcher]: TempError 451356");
 }
 public static void RebindAllDefOfs(bool earlyTryMode)
 {
     DefOfHelper.earlyTry = earlyTryMode;
     foreach (Type item in GenTypes.AllTypesWithAttribute <DefOf>())
     {
         DefOfHelper.BindDefsFor(item);
     }
 }
示例#7
0
        static public bool Prefix()
        {
            DeepProfilerStart.mute = true;

            IEnumerable <Type> enumerable = GenTypes.AllTypesWithAttribute <StaticConstructorOnStartup>();

            foreach (Type type in enumerable)
            {
                ModInfo info = StartupImpact.modlist.Get(ModConstructor.FindMod(type.Assembly));
                if (info != null)
                {
                    info.Start("constructor");
                }

                try
                {
                    RuntimeHelpers.RunClassConstructor(type.TypeHandle);
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[] { "Error in static constructor of ", type, ": ", ex }));
                }

                if (info != null)
                {
                    info.Stop("constructor");
                }
            }
            StaticConstructorOnStartupUtility.coreStaticAssetsLoaded = true;

            if (!StartupImpact.loadingTimeMeasured)
            {
                StartupImpact.loadingTimeMeasured = true;
                StartupImpact.loadingProfiler.Stop("loading");
                StartupImpact.loadingTime = StartupImpact.loadingProfiler.total;
            }

            int spentResolving;

            if (StartupImpact.baseGameProfiler.metrics.TryGetValue("Resolve references.", out spentResolving))
            {
                spentResolving -= ResolveReferences.totalResolving;
                if (spentResolving < 0)
                {
                    spentResolving = 0;
                }
                StartupImpact.baseGameProfiler.metrics["Resolve references."] = spentResolving;
            }

            return(false);
        }
示例#8
0
 public static void RebindAllDefOfs(bool earlyTryMode)
 {
     earlyTry   = earlyTryMode;
     bindingNow = true;
     try
     {
         foreach (Type item in GenTypes.AllTypesWithAttribute <DefOf>())
         {
             BindDefsFor(item);
         }
     }
     finally
     {
         bindingNow = false;
     }
 }
示例#9
0
 public static void RebindAllDefOfs(bool earlyTryMode)
 {
     DefOfHelper.earlyTry   = earlyTryMode;
     DefOfHelper.bindingNow = true;
     try
     {
         foreach (Type current in GenTypes.AllTypesWithAttribute <DefOf>())
         {
             DefOfHelper.BindDefsFor(current);
         }
     }
     finally
     {
         DefOfHelper.bindingNow = false;
     }
 }
示例#10
0
        static bool Prefix()
        {
            foreach (Type type in GenTypes.AllTypesWithAttribute <StaticConstructorOnStartup>())
            {
                DeepProfiler.Start($"Static ctor: {type.FullName}");

                try
                {
                    RuntimeHelpers.RunClassConstructor(type.TypeHandle);
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat("Error in static constructor of ", type, ": ", ex));
                }
                finally
                {
                    DeepProfiler.End();
                }
            }

            StaticConstructorOnStartupUtility.coreStaticAssetsLoaded = true;

            return(false);
        }
示例#11
0
        public void Initialize()
        {
            List <Type> StatDefOfTypes = GenTypes.AllTypesWithAttribute <DefOf>().
                                         Where(t => t.GetFields().FirstOrDefault(tt => tt.FieldType == typeof(StatDef)) != null).ToList();
            StringBuilder BaseMessage = new StringBuilder("[SurivalTools.AutoPatcher] : ");

            // Initialize oldStat FieldInfo
            if (oldStatType is null)
            {
                List <Type> foundTypes = StatDefOfTypes.Where(t => AccessTools.Field(t, oldStat.defName) != null).ToList();
                if (foundTypes.Count == 0)
                {
                    Log.Error(BaseMessage.ToString() + $"Did not find StatDefOf: [{oldStat}] : Please include it somewhere.");
                }
                else if (foundTypes.Count > 1)
                {
                    // This has no effect, I just want to prefer vanilla
                    if (foundTypes.Contains(typeof(StatDefOf)))
                    {
                        oldStatType = typeof(StatDefOf);
                    }
                    else if (foundTypes.Contains(typeof(ST_StatDefOf)))
                    {
                        oldStatType = typeof(ST_StatDefOf);
                    }
                    else
                    {
                        oldStatType = foundTypes[0];
                    }
                }
                else
                {
                    oldStatType = foundTypes[0];
                }
            }
            oldStatFieldInfo = AccessTools.Field(oldStatType, oldStat.defName);
            // Initialize newStat FieldInfo
            if (newStatType is null && newStat != null)
            {
                List <Type> foundTypes = StatDefOfTypes.Where(t => AccessTools.Field(t, newStat.defName) != null).ToList();
                if (foundTypes.Count == 0)
                {
                    Log.Error(BaseMessage.ToString() + $"Did not find StatDefOf: [{newStat}] : Please include it somewhere.");
                }
                else if (foundTypes.Count > 1)
                {
                    if (foundTypes.Contains(typeof(StatDefOf)))
                    {
                        newStatType = typeof(StatDefOf);
                    }
                    else if (foundTypes.Contains(typeof(ST_StatDefOf)))
                    {
                        newStatType = typeof(ST_StatDefOf);
                    }
                    else
                    {
                        newStatType = foundTypes[0];
                    }
                }
                else
                {
                    newStatType = foundTypes[0];
                }
            }
            if (newStat != null)
            {
                newStatFieldInfo = AccessTools.Field(newStatType, newStat.defName);
            }
            // Find StatReplacer.Initialize()
            if (StatReplacer != null)
            {
                StatReplacer_Initialize       = AccessTools.Method(StatReplacer, "Initialize");
                StatReplacer_CodeInstructions = AccessTools.Property(StatReplacer, "CodeInstructions");
            }
        }