[C# Snippet] Change Research Progress

Started by jecrell, November 19, 2016, 04:37:36 AM

Previous topic - Next topic

jecrell

In-case anyone wanted to change ANY research project progress in the game (not just the current project selected), here's a quick bit of code I struggled over that you can use in your projects.


        public static void ChangeResearchProgress(ResearchProjectDef projectDef, float progressValue)
        {
            FieldInfo researchProgressInfo = typeof(ResearchManager).GetField("progress", BindingFlags.Instance | BindingFlags.NonPublic);
            var researchProgress = researchProgressInfo.GetValue(Find.ResearchManager);
            PropertyInfo itemPropertyInfo = researchProgress.GetType().GetProperty("Item");
            itemPropertyInfo.SetValue(researchProgress, progressValue, new[] { projectDef });
            Find.ResearchManager.ReapplyAllMods();
        }

...Psst. Still there? If you'd like to support
me and my works, do check out my Patreon.
Someday, I could work for RimWorld full time!

https://www.patreon.com/jecrell