private static void Inject()
        {
            #region Automatic hookup

            // Loop through all detour attributes and try to hook them up
            foreach (var targetType in Assembly.GetTypes())
            {
                foreach (var bindingFlags in BindingFlagCombos)
                {
                    foreach (var targetMethod in targetType.GetMethods(bindingFlags))
                    {
                        foreach (DetourAttribute detour in targetMethod.GetCustomAttributes(typeof(DetourAttribute), true))
                        {
                            var flags        = detour.bindingFlags != default(BindingFlags) ? detour.bindingFlags : bindingFlags;
                            var sourceMethod = detour.source.GetMethod(targetMethod.Name, flags);
                            if (sourceMethod == null)
                            {
                                Log.Error(string.Format(AssemblyName + " Can't find source method {0} with bindingflags {1}", targetMethod.Name, flags));
                            }
                            if (!Detours.TryDetourFromTo(sourceMethod, targetMethod))
                            {
                                Log.Message(AssemblyName + " Failed to get injected properly.");
                            }
                        }
                    }
                }
            }

            #endregion

            Log.Message(AssemblyName + " injected.");
        }
Esempio n. 2
0
        static Bootstrap()
        {
            try
            {
                {
                    MethodInfo method1 = typeof(RimWorld.ThinkNode_ConditionalShouldFollowMaster).GetMethod("Satisfied", BindingFlags.Instance | BindingFlags.NonPublic);
                    MethodInfo method2 = typeof(ThinkNode_ConditionalShouldFollowMaster_Detour).GetMethod("Satisfied", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 1");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(RimWorld.ForbidUtility).GetMethod("CaresAboutForbidden", BindingFlags.Static | BindingFlags.NonPublic);
                    MethodInfo method2 = typeof(ForbidUtility_Detour).GetMethod("CaresAboutForbidden", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 1");
                        return;
                    }
                }
            }
            catch (Exception)
            {
                Log.Error("something is seriously wrong");
            }
        }
Esempio n. 3
0
        public override bool Inject()
        {
            #region Automatic hookup
            // Loop through all detour attributes and try to hook them up
            foreach (Type targetType in Assembly.GetTypes())
            {
                foreach (BindingFlags bindingFlags in bindingFlagCombos)
                {
                    foreach (MethodInfo targetMethod in targetType.GetMethods(bindingFlags))
                    {
                        foreach (DetourAttribute detour in targetMethod.GetCustomAttributes(typeof(DetourAttribute), true))
                        {
                            BindingFlags flags        = detour.bindingFlags != default(BindingFlags) ? detour.bindingFlags : bindingFlags;
                            MethodInfo   sourceMethod = detour.source.GetMethod(targetMethod.Name, flags);
                            if (sourceMethod == null)
                            {
                                Log.Error(string.Format("ColonistBarKF :: Detours :: Can't find source method '{0} with bindingflags {1}", targetMethod.Name, flags));
                                return(false);
                            }
                            if (!Detours.TryDetourFromTo(sourceMethod, targetMethod))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            #endregion

            return(true);
        }
Esempio n. 4
0
        public void Start()
        {
            Log.Message("Initiated Corruption Detours.");
            MethodInfo method3 = typeof(RimWorld.ThoughtHandler).GetMethod("CanGetThought", new Type[] { typeof(ThoughtDef) });
            MethodInfo method4 = typeof(Corruption.SituationalThoughtHandlerModded).GetMethod("CanGetThought", new Type[] { typeof(ThoughtDef) });

            try
            {
                if (method3 == null)
                {
                    Log.Message("No Ori");
                }
                if (method4 == null)
                {
                    Log.Message("No Src");
                }
                Detours.TryDetourFromTo(method3, method4);

                Log.Message("Corruption methods detoured!");
            }
            catch (Exception)
            {
                Log.Error("Could not detour thoughts");
                throw;
            }
        }
 public override bool Inject()
 {
     return(Detours.TryDetourFromTo(typeof(ThoughtUtility).GetMethod("GiveThoughtsForPawnDied", BindingFlags.Static | BindingFlags.Public), typeof(_ThoughtUtility).GetMethod("_GiveThoughtsForPawnDied", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(ThoughtUtility).GetMethod("GiveThoughtsForPawnExecuted", BindingFlags.Static | BindingFlags.Public), typeof(_ThoughtUtility).GetMethod("_GiveThoughtsForPawnExecuted", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(ThoughtUtility).GetMethod("GiveThoughtsForPawnOrganHarvested", BindingFlags.Static | BindingFlags.Public), typeof(_ThoughtUtility).GetMethod("_GiveThoughtsForPawnOrganHarvested", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Pawn_RelationsTracker).GetMethod("Notify_RescuedBy", BindingFlags.Instance | BindingFlags.Public), typeof(_Pawn_RelationsTracker).GetMethod("_Notify_RescuedBy", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Pawn_RelationsTracker).GetMethod("AttractionTo", BindingFlags.Instance | BindingFlags.Public), typeof(_Pawn_RelationsTracker).GetMethod("_AttractionTo", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Recipe_InstallArtificialBodyPart).GetMethod("ApplyOnPawn", BindingFlags.Instance | BindingFlags.Public), typeof(_Recipe_InstallArtificialBodyPart).GetMethod("_ApplyOnPawn", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Recipe_InstallNaturalBodyPart).GetMethod("ApplyOnPawn", BindingFlags.Instance | BindingFlags.Public), typeof(_Recipe_InstallNaturalBodyPart).GetMethod("_ApplyOnPawn", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Recipe_InstallImplant).GetMethod("ApplyOnPawn", BindingFlags.Instance | BindingFlags.Public), typeof(_Recipe_InstallImplant).GetMethod("_ApplyOnPawn", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Recipe_MedicalOperation).GetMethod("CheckSurgeryFail", BindingFlags.Instance | BindingFlags.NonPublic), typeof(_Recipe_MedicalOperation).GetMethod("_CheckSurgeryFail", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(TendUtility).GetMethod("DoTend", BindingFlags.Static | BindingFlags.Public), typeof(_TendUtility).GetMethod("_DoTend", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Tradeable_Pawn).GetMethod("ResolveTrade", BindingFlags.Instance | BindingFlags.Public), typeof(_Tradeable_Pawn).GetMethod("_ResolveTrade", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(Need_Rest).GetMethod("NeedInterval", BindingFlags.Instance | BindingFlags.Public), typeof(_Need_Rest).GetMethod("_NeedInterval", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(RecordsUtility).GetMethod("Notify_BillDone", BindingFlags.Static | BindingFlags.Public), typeof(_RecordsUtility).GetMethod("_Notify_BillDone", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(FoodUtility).GetMethod("ThoughtsFromIngesting", BindingFlags.Static | BindingFlags.Public), typeof(_FoodUtility).GetMethod("_ThoughtsFromIngesting", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(InteractionWorker_RomanceAttempt).GetMethod("SuccessChance", BindingFlags.Instance | BindingFlags.Public), typeof(_InteractionWorker_RomanceAttempt).GetMethod("_SuccessChance", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(InteractionWorker_RomanceAttempt).GetMethod("RandomSelectionWeight", BindingFlags.Instance | BindingFlags.Public), typeof(_InteractionWorker_RomanceAttempt).GetMethod("_RandomSelectionWeight", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(InteractionWorker_RomanceAttempt).GetMethod("Interacted", BindingFlags.Instance | BindingFlags.Public), typeof(_InteractionWorker_RomanceAttempt).GetMethod("_Interacted", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(InteractionWorker_RomanceAttempt).GetMethod("TryAddCheaterThought", BindingFlags.Instance | BindingFlags.NonPublic), typeof(_InteractionWorker_RomanceAttempt).GetMethod("_TryAddCheaterThought", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(InteractionWorker_Breakup).GetMethod("RandomSelectionWeight", BindingFlags.Instance | BindingFlags.Public), typeof(_InteractionWorker_Breakup).GetMethod("_RandomSelectionWeight", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(InteractionWorker_Breakup).GetMethod("Interacted", BindingFlags.Instance | BindingFlags.Public), typeof(_InteractionWorker_Breakup).GetMethod("_Interacted", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(ChildRelationUtility).GetMethod("ChanceOfBecomingChildOf", BindingFlags.Static | BindingFlags.Public), typeof(_ChildRelationUtility).GetMethod("_ChanceOfBecomingChildOf", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(LovePartnerRelationUtility).GetMethod("LovePartnerRelationGenerationChance", BindingFlags.Static | BindingFlags.Public), typeof(_LovePartnerRelationUtility).GetMethod("_LovePartnerRelationGenerationChance", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(PawnRelationWorker_Sibling).GetMethod("GenerateParent", BindingFlags.Static | BindingFlags.NonPublic), typeof(_PawnRelationWorker_Sibling).GetMethod("_GenerateParent", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(PawnObserver).GetMethod("ObserveSurroundingThings", BindingFlags.Instance | BindingFlags.NonPublic), typeof(_PawnObserver).GetMethod("_ObserveSurroundingThings", BindingFlags.Static | BindingFlags.NonPublic)) &&
            Detours.TryDetourFromTo(typeof(JobGiver_GetRest).GetMethod("GetPriority", BindingFlags.Instance | BindingFlags.Public), typeof(_JobGiver_GetRest).GetMethod("_GetPriority", BindingFlags.Static | BindingFlags.NonPublic)));
 }
Esempio n. 6
0
        static Bootstrap()
        {
            try
            {
                {
                    MethodInfo method1 = typeof(RimWorld.MedicalCareUtility).GetMethod("MedicalCareSetter", BindingFlags.Static | BindingFlags.Public);
                    MethodInfo method2 = typeof(MedicalCareUtility_Detour).GetMethod("MedicalCareSetter", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 1");
                        return;
                    }
                }

                {
                    ConstructorInfo method1 = typeof(RimWorld.Pawn_PlayerSettings).GetConstructor(new Type[] { typeof(Pawn) });
                    MethodInfo      method2 = typeof(Pawn_PlayerSettings_Detour).GetMethod("Pawn_PlayerSettings", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 2");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(RimWorld.Pawn_PlayerSettings).GetMethod("Notify_MadePrisoner", BindingFlags.Instance | BindingFlags.Public);
                    MethodInfo method2 = typeof(Pawn_PlayerSettings_Detour).GetMethod("Notify_MadePrisoner", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 3");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(RimWorld.Pawn_PlayerSettings).GetMethod("Notify_FactionChanged", BindingFlags.Instance | BindingFlags.Public);
                    MethodInfo method2 = typeof(Pawn_PlayerSettings_Detour).GetMethod("Notify_FactionChanged", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 4");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(Verse.Pawn).GetMethod("SetFaction", BindingFlags.Instance | BindingFlags.Public);
                    MethodInfo method2 = typeof(Pawn_Detour).GetMethod("SetFaction", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 5");
                        return;
                    }
                }
            }
            catch (Exception)
            {
                Log.Error("something is seriously wrong");
            }
        }
Esempio n. 7
0
        public override void Inject()
        {
            // detour apparel selection methods
            MethodInfo source = typeof(JobGiver_OptimizeApparel).GetMethod("ApparelScoreGain",
                                                                           BindingFlags.Static | BindingFlags.Public);
            MethodInfo destination = typeof(ApparelStatsHelper).GetMethod("ApparelScoreGain",
                                                                          BindingFlags.Static | BindingFlags.Public);

            Detours.TryDetourFromTo(source, destination);
        }
Esempio n. 8
0
        public override bool Inject()
        {
            MethodInfo method1 = typeof(Thing).GetMethod("SpawnSetup", BindingFlags.Instance | BindingFlags.Public);
            MethodInfo method2 = typeof(_Thing).GetMethod("_SpawnSetup", BindingFlags.Instance | BindingFlags.NonPublic);

            if (!Detours.TryDetourFromTo(method1, method2))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        public override bool Inject()
        {
            Type[] types = Injector_StorageSearch.Assembly.GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
                Type           type  = types[i];
                BindingFlags[] array = Injector_StorageSearch.bindingFlagCombos;
                for (int j = 0; j < array.Length; j++)
                {
                    BindingFlags bindingFlags = array[j];
                    MethodInfo[] methods      = type.GetMethods(bindingFlags);
                    for (int k = 0; k < methods.Length; k++)
                    {
                        MethodInfo methodInfo       = methods[k];
                        object[]   customAttributes = methodInfo.GetCustomAttributes(typeof(DetourAttribute), true);
                        for (int l = 0; l < customAttributes.Length; l++)
                        {
                            DetourAttribute detourAttribute = (DetourAttribute)customAttributes[l];
                            BindingFlags    bindingFlags2   = (detourAttribute.bindingFlags != BindingFlags.Default) ? detourAttribute.bindingFlags : bindingFlags;
                            MethodInfo      method          = detourAttribute.source.GetMethod(methodInfo.Name, bindingFlags2);
                            if (method == null)
                            {
                                Log.Error(string.Format("StorageSearch :: Detours :: Can't find source method '{0} with bindingflags {1}", methodInfo.Name, bindingFlags2));
                                return(false);
                            }
                            if (!Detours.TryDetourFromTo(method, methodInfo))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            MethodInfo arg_132_0 = typeof(StorageSettings).GetMethod("ExposeData", BindingFlags.Instance | BindingFlags.Public);
            MethodInfo method2   = typeof(StorageSettings_Enhanced).GetMethod("ExposeData", BindingFlags.Static | BindingFlags.Public);

            if (Detours.TryDetourFromTo(arg_132_0, method2))
            {
                MethodInfo arg_16A_0 = typeof(StoreUtility).GetMethod("NoStorageBlockersIn", BindingFlags.Static | BindingFlags.NonPublic);
                method2 = typeof(StoreUtility_Detour).GetMethod("NoStorageBlockersIn", BindingFlags.Static | BindingFlags.Public);
                if (Detours.TryDetourFromTo(arg_16A_0, method2))
                {
                    ITab_Storage_Detour.Init();
                    MethodInfo arg_1A7_0 = typeof(ITab_Storage).GetMethod("FillTab", BindingFlags.Instance | BindingFlags.NonPublic);
                    method2 = typeof(ITab_Storage_Detour).GetMethod("FillTab", BindingFlags.Static | BindingFlags.Public);
                    bool arg_1AF_0 = !Detours.TryDetourFromTo(arg_1A7_0, method2);
                }
            }
            Log.Message("Hardcore SK :: Storage search injected");
            return(true);
        }
Esempio n. 10
0
        public void Start()
        {
            Log.Message("Initiated FactionColors Detours.");
            MethodInfo method1a = typeof(Verse.PawnGraphicSet).GetMethod("ResolveApparelGraphics", BindingFlags.Instance | BindingFlags.Public);
            MethodInfo method1b = typeof(FactionColors.ApparelGraphicSet).GetMethod("ResolveApparelGraphicsOriginal", BindingFlags.Instance | BindingFlags.Public);

            MethodInfo method2a = typeof(Verse.PawnRenderer).GetMethod("DrawEquipmentAiming", BindingFlags.Instance | BindingFlags.Public);
            MethodInfo method2b = typeof(FactionColors.FactionItemRenderer).GetMethod("DrawEquipmentAimingModded", BindingFlags.Instance | BindingFlags.Public);

            MethodInfo method3a = typeof(RimWorld.FloatMenuMakerMap).GetMethod("AddHumanlikeOrders", BindingFlags.Static | BindingFlags.NonPublic);
            MethodInfo method3b = typeof(FactionColors.MenuMakerMapRestricted).GetMethod("AddHumanlikeOrders", BindingFlags.Static | BindingFlags.NonPublic);


            if (method1a == null)
            {
                Log.Message("No Method1A");
            }
            if (method1b == null)
            {
                Log.Message("No Method1B");
            }
            if (method2a == null)
            {
                Log.Message("No Method2A");
            }
            if (method2b == null)
            {
                Log.Message("No Method2b");
            }
            if (method3a == null)
            {
                Log.Message("No Method3A");
            }
            if (method3b == null)
            {
                Log.Message("No Method3B");
            }
            try
            {
                Detours.TryDetourFromTo(method1a, method1b);
                Detours.TryDetourFromTo(method2a, method2b);
                Detours.TryDetourFromTo(method3a, method3b);
                Log.Message("ResolveApparelGraphics method detoured!");
            }
            catch (Exception)
            {
                Log.Error("Could not detour Faction graphics");
                throw;
            }
        }
Esempio n. 11
0
 static Bootstrap()
 {
     {
         MethodInfo method1 = typeof(RimWorld.Building_Trap).GetMethod("PathFindCostFor", BindingFlags.Instance | BindingFlags.Public);
         MethodInfo method2 = typeof(Building_Trap_Detour).GetMethod("PathFindCostFor", BindingFlags.Static | BindingFlags.Public);
         if (!Detours.TryDetourFromTo(method1, method2))
         {
             Debug.LogError("EVERYTHING IS BROKEN");
             return;
         }
         else
         {
             Debug.LogError("We're all good!");
         }
     }
 }
Esempio n. 12
0
        public override bool Inject()
        {
            // Special detours
            #region Special detours
            // Change guest bed gizmos to default building gizmos
            if (!Detours.TryDetourFromTo(
                    typeof(Building_GuestBed).GetMethod("GetGizmos", BindingFlags.Instance | BindingFlags.Public),
                    typeof(Building).GetMethod("GetGizmos", BindingFlags.Instance | BindingFlags.Public)))
            {
                return(false);
            }
            #endregion

            #region Automatic hookup
            // Loop through all detour attributes and try to hook them up
            foreach (var targetType in Assembly.GetTypes())
            {
                foreach (var bindingFlags in bindingFlagCombos)
                {
                    foreach (var targetMethod in targetType.GetMethods(bindingFlags))
                    {
                        foreach (DetourAttribute detour in targetMethod.GetCustomAttributes(typeof(DetourAttribute), true))
                        {
                            var flags        = detour.bindingFlags != default(BindingFlags) ? detour.bindingFlags : bindingFlags;
                            var sourceMethod = detour.source.GetMethod(targetMethod.Name, flags);
                            if (sourceMethod == null)
                            {
                                Log.Error(string.Format("Hospitality :: Detours :: Can't find source method '{0} with bindingflags {1}", targetMethod.Name, flags));
                                return(false);
                            }
                            if (!Detours.TryDetourFromTo(sourceMethod, targetMethod))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            #endregion

            InjectTab(typeof(ITab_Pawn_Guest), def => def.race != null && def.race.Humanlike);

            InjectComp(typeof(CompProperties_Guest), def => def.race != null && def.race.Humanlike);

            return(true);
        }
Esempio n. 13
0
        public override bool Inject()
        {
            {
                MethodInfo method1 = typeof(RimWorld.BillUtility).GetMethod("MakeNewBill", BindingFlags.Static | BindingFlags.Public);
                MethodInfo method2 = typeof(BillUtility_Detour).GetMethod("MakeNewBill", BindingFlags.Static | BindingFlags.Public);
                if (!Detours.TryDetourFromTo(method1, method2))
                {
                    return(false);
                }
            }

            Type Verse_TexButton = Data.Assembly_CSharp.GetType("Verse.TexButton");

            ButtonPlus  = Verse_TexButton.GetField("Plus", BindingFlags.Static | BindingFlags.Public);
            ButtonMinus = Verse_TexButton.GetField("Minus", BindingFlags.Static | BindingFlags.Public);

            return(true);
        }
Esempio n. 14
0
 static Bootstrap()
 {
     try
     {
         MethodInfo method1 = typeof(Verse.PawnRenderer).GetMethod("RenderPawnInternal", BindingFlags.Instance | BindingFlags.NonPublic,
                                                                   null,
                                                                   new Type[] { typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(Rot4), typeof(Rot4), typeof(RotDrawMode), typeof(bool) },
                                                                   null);
         MethodInfo method2 = typeof(PawnRenderer_Detour).GetMethod("RenderPawnInternal", BindingFlags.Static | BindingFlags.Public);
         if (!Detours.TryDetourFromTo(method1, method2))
         {
             Log.Error("EVERYTHING IS BROKEN");
             return;
         }
     }
     catch (Exception)
     {
         Log.Error("something is seriously wrong");
     }
 }
Esempio n. 15
0
        public override bool Inject()
        {
            // Loop through all detour attributes and try to hook them up
            foreach (Type targetType in Assembly.GetTypes())
            {
                foreach (BindingFlags bindingFlags in bindingFlagCombos)
                {
                    foreach (MethodInfo targetMethod in targetType.GetMethods(bindingFlags))
                    {
                        foreach (DetourAttribute detour in targetMethod.GetCustomAttributes(
                                     typeof(DetourAttribute),
                                     true))
                        {
                            BindingFlags flags = detour.bindingFlags != default(BindingFlags)
                                                     ? detour.bindingFlags
                                                     : bindingFlags;
                            MethodInfo sourceMethod = detour.source.GetMethod(targetMethod.Name, flags);
                            if (sourceMethod == null)
                            {
                                Log.Error(
                                    string.Format(
                                        "Outfitter :: Detours :: Can't find source method '{0} with bindingflags {1}",
                                        targetMethod.Name,
                                        flags));
                                return(false);
                            }

                            if (!Detours.TryDetourFromTo(sourceMethod, targetMethod))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            /*
             * MethodInfo coreMethod = typeof(JobGiver_OptimizeApparel).GetMethod("TryGiveJob", BindingFlags.Instance | BindingFlags.NonPublic);
             * MethodInfo autoEquipMethod = typeof(Outfitter_JobGiver_OptimizeApparel).GetMethod("TryGiveJob", BindingFlags.Instance | BindingFlags.NonPublic);
             *
             * if (!Detours.TryDetourFromTo(coreMethod, autoEquipMethod))
             *  Log.Error("Could not Detour AutoEquip.");
             */

            // inject ITab into all humanlikes
            if (useApparelSense)
            {
                // get a list of all apparel in the game
                List <ThingDef> allApparel = DefDatabase <ThingDef> .AllDefsListForReading.Where(t => t.IsApparel)
                                             .ToList();

                // detach all existing categories under apparel
                foreach (ThingCategoryDef cat in apparelRoot.childCategories)
                {
                    cat.parent = null;
                }

                apparelRoot.childCategories = new List <ThingCategoryDef>();

                // loop over all apparel, adding categories where appropriate.
                foreach (ThingDef thing in allApparel)
                {
                    // create list of categories on thing if necessary (shouldn't ever be, but what the heck)
                    if (thing.thingCategories.NullOrEmpty())
                    {
                        thing.thingCategories = new List <ThingCategoryDef>();
                    }

                    // remove existing categories on thing
                    foreach (ThingCategoryDef cat in thing.thingCategories)
                    {
                        cat.childThingDefs.Remove(thing);
                    }

                    // add in new categories
                    ApparelProperties apparel = thing.apparel;

                    // categories based on bodyparts
                    foreach (BodyPartGroupDef bodyPart in apparel.bodyPartGroups)
                    {
                        // get or create category
                        ThingCategoryDef cat =
                            DefDatabase <ThingCategoryDef> .GetNamedSilentFail(GetCatName(bodyPart.label, "BP"));

                        if (cat == null)
                        {
                            cat = CreateCategory(bodyPart.label, "BP");
                        }

                        foreach (ApparelLayer layer in apparel.layers)
                        {
                            // get or create category
                            ThingCategoryDef childCat =
                                DefDatabase <ThingCategoryDef> .GetNamedSilentFail(
                                    GetChildCatName(bodyPart.label, layer.ToString(), "CC"));

                            if (childCat == null)
                            {
                                childCat = CreateChildCategory(cat, bodyPart.label, layer.ToString(), "CC");
                            }

                            // add category to thing, and thing to category. (Tynan, pls.)
                            thing.thingCategories.Add(childCat);
                            childCat.childThingDefs.Add(thing);
                        }
                    }

                    // categories based on tag (too messy)

                    //// categories based on tag (too messy)
                    // foreach ( string tag in apparel.tags )
                    // {
                    // // get or create category
                    // ThingCategoryDef cat = DefDatabase<ThingCategoryDef>.GetNamedSilentFail( GetCatName( tag, "BP" ) );
                    // if( cat == null )
                    // {
                    // cat = CreateCategory( tag, "BP" );
                    // }

                    // // add category to thing, and thing to category. (Tynan, pls.)
                    // thing.thingCategories.Add( cat );
                    // cat.childThingDefs.Add( thing );
                    // }
                }

                // set nest levels on new categories
                SetNestLevelRecursive(apparelRoot.treeNode, apparelRoot.treeNode.nestDepth);
            }

            return(true);
        }
Esempio n. 16
0
        public override bool Inject()
        {
            var thingsToReplaceITabOn = DefDatabase <ThingDef> .AllDefs.Where(thingDef => (
                                                                                  (thingDef.inspectorTabs != null) &&
                                                                                  (thingDef.inspectorTabs.Contains(typeof(RimWorld.ITab_Pawn_Prisoner)))
                                                                                  )).ToList();

            foreach (var thingDef in thingsToReplaceITabOn)
            {
                thingDef.inspectorTabs.Remove(typeof(RimWorld.ITab_Pawn_Prisoner));
                thingDef.inspectorTabs.Add(typeof(ITab_Pawn_Prisoner));
                thingDef.inspectorTabs.Add(typeof(ITab_Pawn_Slave));

                if (thingDef.inspectorTabsResolved != null)
                {
                    foreach (var iTab in thingDef.inspectorTabsResolved)
                    {
                        if (iTab is RimWorld.ITab_Pawn_Prisoner)
                        {
                            thingDef.inspectorTabsResolved.Remove(iTab);
                            break;
                        }
                    }
                    thingDef.inspectorTabsResolved.Add(ITabManager.GetSharedInstance(typeof(ITab_Pawn_Prisoner)));
                    thingDef.inspectorTabsResolved.Add(ITabManager.GetSharedInstance(typeof(ITab_Pawn_Slave)));
                }

                if (thingDef.comps == null)
                {
                    thingDef.comps = new List <CompProperties>();
                }
                if (!thingDef.HasComp(typeof(CompSlave)))
                {
                    var compProperties = new CompProperties();
                    compProperties.compClass = typeof(CompSlave);
                    thingDef.comps.Add(compProperties);
                }
            }

            // Allow prisoners to have a joy need
            var RW_Pawn_NeedsTracker_ShouldHaveNeed =
                typeof(Pawn_NeedsTracker).GetMethod("ShouldHaveNeed", BindingFlags.Instance | BindingFlags.NonPublic);
            var PI_Pawn_NeedsTracker_ShouldHaveNeed =
                typeof(_Pawn_NeedsTracker).GetMethod("_ShouldHaveNeed", BindingFlags.Static | BindingFlags.NonPublic);

            if (!Detours.TryDetourFromTo(RW_Pawn_NeedsTracker_ShouldHaveNeed, PI_Pawn_NeedsTracker_ShouldHaveNeed))
            {
                return(false);
            }

            // Disallow removing the collar
            var RW_Pawn_ApparelTracker_TryDrop = typeof(Pawn_ApparelTracker).GetMethods().First <MethodInfo>((arg) => (
                                                                                                                 (arg.Name == "TryDrop") &&
                                                                                                                 (arg.GetParameters().Count() == 4)
                                                                                                                 ));
            var PI_Pawn_ApparelTracker_TryDrop =
                typeof(_Pawn_ApparelTracker).GetMethod("_TryDrop", BindingFlags.Static | BindingFlags.NonPublic);

            if (!Detours.TryDetourFromTo(RW_Pawn_ApparelTracker_TryDrop, PI_Pawn_ApparelTracker_TryDrop))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 17
0
        internal static void                PreLoad()
        {
            // This is a pre-start sequence to hook some deeper level functions.
            // These functions can be hooked later but it would be after the sequence
            // of operations which call them is complete.

#if DEVELOPER
            // Open a log file for CCL specific output
            // https://www.youtube.com/watch?v=jyaLZHiJJnE
            if (CCL_Log.OpenStream() == null)
            {
                Log.Error(string.Format("Unable to open file stream for {0}!", Controller.Data.UnityObjectName));
            }
#endif

            // Log CCL version
            Version.Log();

            bool InjectionsOk  = true;
            var  stringBuilder = new StringBuilder();
            CCL_Log.CaptureBegin(stringBuilder);

            // Find all sub-controllers
            var subControllerClasses = typeof(SubController).AllSubclasses();
            var subControllerCount   = subControllerClasses.Count();
            if (subControllerCount == 0)
            {
                InjectionsOk = false;
                CCL_Log.Error(
                    "Unable to find sub-controllers",
                    "PreLoader"
                    );
            }

            // Create sub-controllers
            if (InjectionsOk)
            {
                var subControllers = new SubController[subControllerCount];
                for (int index = 0; index < subControllerCount; ++index)
                {
                    var subControllerType = subControllerClasses.ElementAt(index);
                    var subController     = (SubController)Activator.CreateInstance(subControllerType);
                    if (subController == null)
                    {
                        CCL_Log.Error(
                            string.Format("Unable to create sub-controller {0}", subControllerType.Name),
                            "PreLoader"
                            );
                        InjectionsOk = false;
                        break;
                    }
                    else
                    {
                        subControllers[index] = subController;
                    }
                }
                if (InjectionsOk)
                {
                    Controller.Data.SubControllers = subControllers;
                }
            }

            // Detour Verse.PlayDataLoader.LoadAllPlayData
            if (InjectionsOk)
            {
                MethodInfo Verse_PlayDataLoader_LoadAllPlayData = typeof(PlayDataLoader).GetMethod("LoadAllPlayData", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_PlayDataLoader_LoadAllPlayData   = typeof(Detour._PlayDataLoader).GetMethod("_LoadAllPlayData", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(Verse_PlayDataLoader_LoadAllPlayData, CCL_PlayDataLoader_LoadAllPlayData);
            }

            // Detour Verse.PlayDataLoader.ClearAllPlayData
            if (InjectionsOk)
            {
                MethodInfo Verse_PlayDataLoader_ClearAllPlayData = typeof(PlayDataLoader).GetMethod("ClearAllPlayData", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_PlayDataLoader_ClearAllPlayData   = typeof(Detour._PlayDataLoader).GetMethod("_ClearAllPlayData", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(Verse_PlayDataLoader_ClearAllPlayData, CCL_PlayDataLoader_ClearAllPlayData);
            }

            // Detour Verse.UIRoot_Entry.ShouldDoMainMenu_get
            if (InjectionsOk)
            {
                PropertyInfo Verse_UIRoot_Entry_ShouldDoMainMenu     = typeof(UIRoot_Entry).GetProperty("ShouldDoMainMenu", BindingFlags.Instance | BindingFlags.NonPublic);
                MethodInfo   Verse_UIRoot_Entry_ShouldDoMainMenu_get = Verse_UIRoot_Entry_ShouldDoMainMenu.GetGetMethod(true);
                MethodInfo   CCL_UIRoot_Entry_ShouldDoMainMenu_get   = typeof(Detour._UIRoot_Entry).GetMethod("_ShouldDoMainMenu_get", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(Verse_UIRoot_Entry_ShouldDoMainMenu_get, CCL_UIRoot_Entry_ShouldDoMainMenu_get);
            }

            // Detour RimWorld.MainMenuDrawer.MainMenuOnGUI
            if (InjectionsOk)
            {
                MethodInfo RimWorld_MainMenuDrawer_MainMenuOnGUI = typeof(MainMenuDrawer).GetMethod("MainMenuOnGUI", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_MainMenuDrawer_MainMenuOnGUI      = typeof(Detour._MainMenuDrawer).GetMethod("_MainMenuOnGUI", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimWorld_MainMenuDrawer_MainMenuOnGUI, CCL_MainMenuDrawer_MainMenuOnGUI);
            }

            // Detour RimWorld.MainMenuDrawer.DoMainMenuButtons
            if (InjectionsOk)
            {
                MethodInfo RimWorld_MainMenuDrawer_DoMainMenuButtons = typeof(MainMenuDrawer).GetMethod("DoMainMenuButtons", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_MainMenuDrawer_DoMainMenuButtons      = typeof(Detour._MainMenuDrawer).GetMethod("_DoMainMenuButtons", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimWorld_MainMenuDrawer_DoMainMenuButtons, CCL_MainMenuDrawer_DoMainMenuButtons);
            }

            // Detour RimWorld.VersionControl.DrawInfoInCorner
            if (InjectionsOk)
            {
                MethodInfo RimWorld_VersionControl_DrawInfoInCorner = typeof(VersionControl).GetMethod("DrawInfoInCorner", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_VersionControl_DrawInfoInCorner      = typeof(Detour._VersionControl).GetMethod("_DrawInfoInCorner", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimWorld_VersionControl_DrawInfoInCorner, CCL_VersionControl_DrawInfoInCorner);
            }

            // Detour Verse.PostLoadInitter.DoAllPostLoadInits

            /*
             * if( InjectionsOk )
             * {
             *  MethodInfo Verse_PostLoadInitter_DoAllPostLoadInits = typeof( PostLoadInitter ).GetMethod( "DoAllPostLoadInits", BindingFlags.Static | BindingFlags.Public );
             *  MethodInfo CCL_PostLoadInitter_DoAllPostLoadInits = typeof( Detour._PostLoadInitter ).GetMethod( "_DoAllPostLoadInits", BindingFlags.Static | BindingFlags.NonPublic );
             *  InjectionsOk &= Detours.TryDetourFromTo( Verse_PostLoadInitter_DoAllPostLoadInits, CCL_PostLoadInitter_DoAllPostLoadInits );
             * }
             */

            if (InjectionsOk)
            {
                LongEventHandler.ExecuteWhenFinished(CreateMonoBehaviour);
            }

            CCL_Log.CaptureEnd(
                stringBuilder,
                InjectionsOk ? "Initialized" : "Errors during injection"
                );
            CCL_Log.Trace(
                Verbosity.Injections,
                stringBuilder.ToString(),
                "PreLoader");

            initOk = InjectionsOk;
        }
Esempio n. 18
0
        static Bootstrap()
        {
            try
            {
                {
                    MethodInfo method1 = typeof(RimWorld.Building_CommsConsole).GetMethod("GetFloatMenuOptions", BindingFlags.Instance | BindingFlags.Public);
                    MethodInfo method2 = typeof(Building_CommsConsole_Detour).GetMethod("GetFloatMenuOptions", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 1");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(RimWorld.FloatMenuMakerMap).GetMethod("AddDraftedOrders", BindingFlags.Static | BindingFlags.NonPublic);
                    MethodInfo method2 = typeof(FloatMenuMakerMap_Detour).GetMethod("AddDraftedOrders", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 2");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(RimWorld.FloatMenuMakerMap).GetMethod("AddHumanlikeOrders", BindingFlags.Static | BindingFlags.NonPublic);
                    MethodInfo method2 = typeof(FloatMenuMakerMap_Detour).GetMethod("AddHumanlikeOrders", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 3");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(RimWorld.FloatMenuMakerMap).GetMethod("AddUndraftedOrders", BindingFlags.Static | BindingFlags.NonPublic);
                    MethodInfo method2 = typeof(FloatMenuMakerMap_Detour).GetMethod("AddUndraftedOrders", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 4");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(Verse.AI.ReservationUtility).GetMethod("CanReserve", BindingFlags.Static | BindingFlags.Public);
                    MethodInfo method2 = typeof(ReservationUtility_Detour).GetMethod("CanReserve", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 5");
                        return;
                    }
                }

                {
                    MethodInfo method1 = typeof(Verse.AI.ReservationUtility).GetMethod("CanReserveAndReach", BindingFlags.Static | BindingFlags.Public);
                    MethodInfo method2 = typeof(ReservationUtility_Detour).GetMethod("CanReserveAndReach", BindingFlags.Static | BindingFlags.Public);
                    if (!Detours.TryDetourFromTo(method1, method2))
                    {
                        Log.Error("EVERYTHING IS BROKEN 6");
                        return;
                    }
                }
            }
            catch (Exception)
            {
                Log.Error("something is seriously wrong");
            }
        }
Esempio n. 19
0
        private static void                 PreLoad()
        {
            // This is a pre-start sequence to hook some deeper level functions.
            // These functions can be hooked later but it would be after the sequence
            // of operations which call them is complete.

            // Log CCL version
            Version.Log();

            bool          InjectionsOk  = true;
            StringBuilder stringBuilder = new StringBuilder();

            CCL_Log.CaptureBegin(stringBuilder);

            // Find all sub-controllers
            var subControllerClasses = typeof(SubController).AllSubclasses();
            var subControllerCount   = subControllerClasses.Count();

            if (subControllerCount == 0)
            {
                InjectionsOk = false;
                CCL_Log.Error(
                    "Unable to find sub-controllers",
                    "PreLoader"
                    );
            }

            // Create sub-controllers
            if (InjectionsOk)
            {
                var subControllers = new SubController[subControllerCount];
                for (int index = 0; index < subControllerCount; ++index)
                {
                    var subControllerType = subControllerClasses.ElementAt(index);
                    var subController     = (SubController)Activator.CreateInstance(subControllerType);
                    if (subController == null)
                    {
                        CCL_Log.Error(
                            string.Format("Unable to create sub-controller {0}", subControllerType.Name),
                            "PreLoader"
                            );
                        InjectionsOk = false;
                        break;
                    }
                    else
                    {
                        subControllers[index] = subController;
                    }
                }
                if (InjectionsOk)
                {
                    Controller.Data.SubControllers = subControllers;
                }
            }

            // Detour Verse.PlayDataLoader.LoadAllPlayData
            if (InjectionsOk)
            {
                MethodInfo Verse_PlayDataLoader_LoadAllPlayData = typeof(PlayDataLoader).GetMethod("LoadAllPlayData", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_PlayDataLoader_LoadAllPlayData   = typeof(Detour._PlayDataLoader).GetMethod("_LoadAllPlayData", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(Verse_PlayDataLoader_LoadAllPlayData, CCL_PlayDataLoader_LoadAllPlayData);
            }

            // Detour Verse.PlayDataLoader.ClearAllPlayData
            if (InjectionsOk)
            {
                MethodInfo Verse_PlayDataLoader_ClearAllPlayData = typeof(PlayDataLoader).GetMethod("ClearAllPlayData", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_PlayDataLoader_ClearAllPlayData   = typeof(Detour._PlayDataLoader).GetMethod("_ClearAllPlayData", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(Verse_PlayDataLoader_ClearAllPlayData, CCL_PlayDataLoader_ClearAllPlayData);
            }

            // Detour Verse.UIRoot_Entry.ShouldShowMainMenuGUI_get
            if (InjectionsOk)
            {
                PropertyInfo Verse_UIRoot_Entry_ShouldShowMainMenuGUI     = typeof(UIRoot_Entry).GetProperty("ShouldShowMainMenuGUI", BindingFlags.Instance | BindingFlags.NonPublic);
                MethodInfo   Verse_UIRoot_Entry_ShouldShowMainMenuGUI_get = Verse_UIRoot_Entry_ShouldShowMainMenuGUI.GetGetMethod(true);
                MethodInfo   CCL_UIRoot_Entry_ShouldShowMainMenuGUI_get   = typeof(Detour._UIRoot_Entry).GetMethod("_ShouldShowMainMenuGUI_get", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(Verse_UIRoot_Entry_ShouldShowMainMenuGUI_get, CCL_UIRoot_Entry_ShouldShowMainMenuGUI_get);
            }

            // Detour RimWorld.MainMenuDrawer.MainMenuOnGUI
            if (InjectionsOk)
            {
                MethodInfo RimWorld_MainMenuDrawer_MainMenuOnGUI = typeof(MainMenuDrawer).GetMethod("MainMenuOnGUI", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_MainMenuDrawer_MainMenuOnGUI      = typeof(Detour._MainMenuDrawer).GetMethod("_MainMenuOnGUI", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimWorld_MainMenuDrawer_MainMenuOnGUI, CCL_MainMenuDrawer_MainMenuOnGUI);
            }

            // Detour RimWorld.MainMenuDrawer.DoMainMenuButtons
            if (InjectionsOk)
            {
                MethodInfo RimWorld_MainMenuDrawer_DoMainMenuButtons = typeof(MainMenuDrawer).GetMethod("DoMainMenuButtons", BindingFlags.Static | BindingFlags.Public);
                MethodInfo CCL_MainMenuDrawer_DoMainMenuButtons      = typeof(Detour._MainMenuDrawer).GetMethod("_DoMainMenuButtons", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimWorld_MainMenuDrawer_DoMainMenuButtons, CCL_MainMenuDrawer_DoMainMenuButtons);
            }

            // Detour RimWorld.BiomeDef.CommonalityOfAnimal
            if (InjectionsOk)
            {
                MethodInfo RimwWorld_BiomeDef_CommonalityOfAnimal = typeof(BiomeDef).GetMethod("CommonalityOfAnimal", BindingFlags.Instance | BindingFlags.Public);
                MethodInfo CCL_BiomeDef_CommonalityOfAnimal       = typeof(Detour._BiomeDef).GetMethod("_CommonalityOfAnimal", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimwWorld_BiomeDef_CommonalityOfAnimal, CCL_BiomeDef_CommonalityOfAnimal);
            }

            // Detour RimWorld.BiomeDef.CommonalityOfPlant
            if (InjectionsOk)
            {
                MethodInfo RimwWorld_BiomeDef_CommonalityOfPlant = typeof(BiomeDef).GetMethod("CommonalityOfPlant", BindingFlags.Instance | BindingFlags.Public);
                MethodInfo CCL_BiomeDef_CommonalityOfPlant       = typeof(Detour._BiomeDef).GetMethod("_CommonalityOfPlant", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimwWorld_BiomeDef_CommonalityOfPlant, CCL_BiomeDef_CommonalityOfPlant);
            }
            // Detour RimWorld.BiomeDef.MTBDaysOfDisease
            if (InjectionsOk)
            {
                MethodInfo RimWorld_BiomeDef_MTBDaysOfDisease = typeof(BiomeDef).GetMethod("MTBDaysOfDisease", BindingFlags.Instance | BindingFlags.Public);
                MethodInfo CCL_BiomeDef_MTBDaysOfDisease      = typeof(Detour._BiomeDef).GetMethod("_MTBDaysOfDisease", BindingFlags.Static | BindingFlags.NonPublic);
                InjectionsOk &= Detours.TryDetourFromTo(RimWorld_BiomeDef_MTBDaysOfDisease, CCL_BiomeDef_MTBDaysOfDisease);
            }

            // Detour Verse.PostLoadInitter.DoAllPostLoadInits

            /*
             * if( InjectionsOk )
             * {
             *  MethodInfo Verse_PostLoadInitter_DoAllPostLoadInits = typeof( PostLoadInitter ).GetMethod( "DoAllPostLoadInits", BindingFlags.Static | BindingFlags.Public );
             *  MethodInfo CCL_PostLoadInitter_DoAllPostLoadInits = typeof( Detour._PostLoadInitter ).GetMethod( "_DoAllPostLoadInits", BindingFlags.Static | BindingFlags.NonPublic );
             *  InjectionsOk &= Detours.TryDetourFromTo( Verse_PostLoadInitter_DoAllPostLoadInits, CCL_PostLoadInitter_DoAllPostLoadInits );
             * }
             */

            if (InjectionsOk)
            {
                var gameObject = new GameObject(Controller.Data.UnityObjectName);
                if (gameObject == null)
                {
                    InjectionsOk = false;
                    CCL_Log.Error(
                        "Unable to create GameObject",
                        "PreLoader"
                        );
                }
                else
                {
                    if (gameObject.AddComponent <Controller.MainMonoBehaviour>() == null)
                    {
                        InjectionsOk = false;
                        CCL_Log.Error(
                            "Unable to create MonoBehaviour",
                            "PreLoader"
                            );
                    }
                    else
                    {
                        UnityEngine.Object.DontDestroyOnLoad(gameObject);
                        Controller.Data.UnityObject = gameObject;
                    }
                }
            }

            if (InjectionsOk)
            {
                CCL_Log.Message(
                    "Queueing Library Initialization",
                    "PreLoader"
                    );
                LongEventHandler.QueueLongEvent(Initialize, "LibraryStartup", true, null);
            }

            CCL_Log.CaptureEnd(
                stringBuilder,
                InjectionsOk ? "Initialized" : "Errors during injection"
                );
            CCL_Log.Trace(
                Verbosity.Injections,
                stringBuilder.ToString(),
                "PreLoader");
        }