コード例 #1
0
        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.");
        }
コード例 #2
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;
            }
        }
コード例 #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);
        }
コード例 #4
0
        public void revertDetours()
        {
            if (DetourInited)
            {
                Log.Info("Reverting manual detours");
                Detours.Reverse();
                foreach (Detour d in Detours)
                {
                    RedirectionHelper.RevertRedirect(d.OriginalMethod, d.Redirect);
                }
                Detours.Clear();

                Log.Info("Reverting attribute-driven detours");
                AssemblyRedirector.Revert();

                Log.Info("Reverting Harmony detours");
                foreach (MethodBase m in HarmonyMethodStates.Keys)
                {
                    HarmonyInst.Unpatch(m, HarmonyPatchType.All, HARMONY_ID);
                }

                DetourInited = false;
                Log.Info("Reverting detours finished.");
            }
        }
コード例 #5
0
        public void LoadDetour(MethodInfo method)
        {
            // Setup variables
            DetourAttribute attribute = (DetourAttribute)Attribute.GetCustomAttribute(method, typeof(DetourAttribute));

            // Do checks
            if (attribute == null)
            {
                return;
            }
            if (!attribute.MethodFound)
            {
                return;
            }
            if (Detours.Count(a => a.Key.Method == attribute.Method) > 0)
            {
                return;
            }

            try
            {
                DetourWrapper wrapper = new DetourWrapper(attribute.Method, method, attribute);

                wrapper.Detour();

                Detours.Add(attribute, wrapper);
            }
            catch (Exception ex)
            {
                PointBlankLogging.LogError("Error detouring: " + method.Name, ex);
            }
        }
コード例 #6
0
ファイル: Bootstrap.cs プロジェクト: zorbathut/itsdangerous
        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");
            }
        }
コード例 #7
0
 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)));
 }
コード例 #8
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");
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: brownbelt/Sourcey-Jack
        static void Main(string[] args)
        {
            bool createdNew = false;

            System.Threading.Mutex m = new System.Threading.Mutex(false, "{BE450405-C3CF-45D3-A1F4-29F0C0A0E02D}", out createdNew);

            if (args.Length > 0)
            {
                try
                {
                    if (createdNew)
                    {
                        m.Dispose();
                        Process p = Process.Start(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

                        p.WaitForInputIdle(10000);
                    }

                    Thread.Sleep(10000);

                    string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SJackHook.dll");

                    List <string> argList = new List <string>();

                    for (int i = 1; i < args.Length; ++i)
                    {
                        if (args[i].Contains(" "))
                        {
                            argList.Add(String.Format("\"{0}\"", args[i]));
                        }
                        else
                        {
                            argList.Add(args[i]);
                        }
                    }

                    string cmdLine = argList.Count > 0 ? String.Join(" ", argList) : null;

                    Detours.CreateProcessWithDll(args[0], cmdLine, dllPath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    MessageBox.Show("Already a copy running");
                }
            }
        }
コード例 #10
0
 private void OnPluginUnloaded(PointBlankPlugin plugin)
 {
     foreach (KeyValuePair <DetourAttribute, DetourWrapper> kvp in Detours.Where(a => a.Key.Method.DeclaringType.Assembly == plugin.GetType().Assembly&& !a.Value.Local))
     {
         kvp.Value.Revert();
         Detours.Remove(kvp.Key);
     }
 }
コード例 #11
0
ファイル: Bootstrap.cs プロジェクト: fluffy-mods/RW_Outfitter
        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);
        }
コード例 #12
0
        private void OnPluginUnloaded(PointBlankPlugin plugin)
        {
            PluginWrapper wrapper = PM.Plugins.First(a => a.PluginClass == plugin);

            foreach (KeyValuePair <DetourAttribute, DetourWrapper> kvp in Detours.Where(a => a.Key.Method.DeclaringType.Assembly == wrapper.PluginAssembly && !a.Value.Local))
            {
                kvp.Value.Revert();
                Detours.Remove(kvp.Key);
            }
        }
コード例 #13
0
ファイル: MainWindow.xaml.cs プロジェクト: Evulpes/3PT
        public MainWindow()
        {
            InitializeComponent();
            detourSendTask = Detours.DetourWs2Send();

            detourSendTask.Start();

            PacketDataGrid.DataContext = Detours.packetTable.DefaultView;
            int me = 5;
        }
コード例 #14
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);
        }
コード例 #15
0
        private static bool DoDetour(Type rimworld, Type mod, string method)
        {
            MethodInfo RimWorld_A = rimworld.GetMethod(method, Detours.UniversalBindingFlags);
            MethodInfo ModTest_A  = mod.GetMethod(method, Detours.UniversalBindingFlags);

            if (!Detours.TryDetourFromToInt(RimWorld_A, ModTest_A))
            {
                return(false);
            }
            return(true);
        }
コード例 #16
0
 public void revertDetours()
 {
     if (LoadingExtension.Instance.DetourInited)
     {
         Log.Info("Revert detours");
         foreach (Detour d in Detours)
         {
             RedirectionHelper.RevertRedirect(d.OriginalMethod, d.Redirect);
         }
         LoadingExtension.Instance.DetourInited = false;
         Detours.Clear();
     }
 }
コード例 #17
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);
        }
コード例 #18
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;
            }
        }
コード例 #19
0
ファイル: Bootstrap.cs プロジェクト: zorbathut/oshacompliance
 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!");
         }
     }
 }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
0
        public override void Unload()
        {
            if (!Initialized)
            {
                return;
            }

            // Main code
            while (Detours.Count > 0)
            {
                DetourAttribute att = Detours.Keys.ElementAt(0);

                Detours[att].Revert();
                Detours.Remove(att);
            }

            // Set the variables
            Initialized = false;
        }
コード例 #23
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");
     }
 }
コード例 #24
0
        public override void Unload()
        {
            if (!Initialized)
            {
                return;
            }

            // Unload the events
            PointBlankPluginEvents.OnPluginLoaded   -= OnPluginLoaded;
            PointBlankPluginEvents.OnPluginUnloaded -= OnPluginUnloaded;

            // Main code
            while (Detours.Count > 0)
            {
                DetourAttribute att = Detours.Keys.ElementAt(0);

                Detours[att].Revert();
                Detours.Remove(att);
            }

            // Set the variables
            Initialized = false;
        }
コード例 #25
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string exe = textBoxExe.Text.Trim();

            if (UpdateMap())
            {
                if (String.IsNullOrEmpty(exe))
                {
                    MessageBox.Show(this, "Must specify an executable file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SJackHook.dll");
                        Detours.CreateProcessWithDll(exe, String.IsNullOrWhiteSpace(textBoxCmdLine.Text) ? null : textBoxCmdLine.Text, dllPath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }
コード例 #26
0
        private void btnInject_Click(object sender, EventArgs e)
        {
            if (UpdateMap())
            {
                if (listViewProcesses.SelectedItems.Count == 0)
                {
                    MessageBox.Show(this, "Must select a process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    int pid = (int)listViewProcesses.SelectedItems[0].Tag;

                    try
                    {
                        string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SJackHook.dll");
                        Detours.InjectDll(pid, dllPath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }
コード例 #27
0
        public void initDetours()
        {
            if (!LoadingExtension.Instance.DetourInited)
            {
                Log.Info("Init detours");
                bool detourFailed = false;

                Log.Info("Redirecting Vehicle AI Calculate Segment Calls (1)");
                try {
                    Detours.Add(new Detour(typeof(VehicleAI).GetMethod("CalculateSegmentPosition",
                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                       null,
                                                                       new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(PathUnit.Position),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(int),
                        typeof(Vector3).MakeByRefType(),
                        typeof(Vector3).MakeByRefType(),
                        typeof(float).MakeByRefType()
                    },
                                                                       null),
                                           typeof(CustomVehicleAI).GetMethod("CustomCalculateSegmentPosition")));
                } catch (Exception) {
                    Log.Error("Could not redirect VehicleAI::CalculateSegmentPosition (1).");
                    detourFailed = true;
                }


                Log.Info("Redirecting Vehicle AI Calculate Segment Calls (2)");
                try {
                    Detours.Add(new Detour(typeof(VehicleAI).GetMethod("CalculateSegmentPosition",
                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                       null,
                                                                       new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(Vector3).MakeByRefType(),
                        typeof(Vector3).MakeByRefType(),
                        typeof(float).MakeByRefType()
                    },
                                                                       null),
                                           typeof(CustomVehicleAI).GetMethod("CustomCalculateSegmentPositionPathFinder")));
                } catch (Exception) {
                    Log.Error("Could not redirect VehicleAI::CalculateSegmentPosition (2).");
                    detourFailed = true;
                }

                Log.Info("Redirecting TramBaseAI Calculate Segment Calls (2)");
                try {
                    Detours.Add(new Detour(typeof(TramBaseAI).GetMethod("CalculateSegmentPosition",
                                                                        BindingFlags.NonPublic | BindingFlags.Instance,
                                                                        null,
                                                                        new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(Vector3).MakeByRefType(),
                        typeof(Vector3).MakeByRefType(),
                        typeof(float).MakeByRefType()
                    },
                                                                        null),
                                           typeof(CustomTramBaseAI).GetMethod("CustomCalculateSegmentPositionPathFinder")));
                } catch (Exception) {
                    Log.Error("Could not redirect TramBaseAI::CalculateSegmentPosition (2).");
                    detourFailed = true;
                }

                Log.Info("Redirecting RoadBaseAI.SimulationStep for nodes");
                try {
                    Detours.Add(new Detour(typeof(RoadBaseAI).GetMethod("SimulationStep", new[] { typeof(ushort), typeof(NetNode).MakeByRefType() }),
                                           typeof(CustomRoadAI).GetMethod("CustomNodeSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect RoadBaseAI::SimulationStep.");
                    detourFailed = true;
                }

                Log.Info("Redirecting RoadBaseAI.SimulationStep for segments");
                try {
                    Detours.Add(new Detour(typeof(RoadBaseAI).GetMethod("SimulationStep", new[] { typeof(ushort), typeof(NetSegment).MakeByRefType() }),
                                           typeof(CustomRoadAI).GetMethod("CustomSegmentSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect RoadBaseAI::SimulationStep.");
                }

                Log.Info("Redirecting Human AI Calls");
                try {
                    Detours.Add(new Detour(typeof(HumanAI).GetMethod("CheckTrafficLights",
                                                                     BindingFlags.NonPublic | BindingFlags.Instance,
                                                                     null,
                                                                     new[] { typeof(ushort), typeof(ushort) },
                                                                     null),
                                           typeof(CustomHumanAI).GetMethod("CustomCheckTrafficLights")));
                } catch (Exception) {
                    Log.Error("Could not redirect HumanAI::CheckTrafficLights.");
                    detourFailed = true;
                }

                Log.Info("Redirecting CarAI Simulation Step Calls");
                try {
                    Detours.Add(new Detour(typeof(CarAI).GetMethod("SimulationStep",
                                                                   new[] {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Vector3)
                    }),
                                           typeof(CustomCarAI).GetMethod("TrafficManagerSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect CarAI::SimulationStep.");
                    detourFailed = true;
                }

                Log.Info("Redirecting PassengerCarAI Simulation Step Calls");
                try {
                    Detours.Add(new Detour(typeof(PassengerCarAI).GetMethod("SimulationStep",
                                                                            new[] { typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(Vector3) }),
                                           typeof(CustomPassengerCarAI).GetMethod("CustomSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect PassengerCarAI::SimulationStep.");
                    detourFailed = true;
                }

                Log.Info("Redirecting CargoTruckAI Simulation Step Calls");
                try {
                    Detours.Add(new Detour(typeof(CargoTruckAI).GetMethod("SimulationStep",
                                                                          new[] { typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(Vector3) }),
                                           typeof(CustomCargoTruckAI).GetMethod("CustomSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect CargoTruckAI::SimulationStep.");
                    detourFailed = true;
                }

                Log.Info("Redirecting TrainAI Simulation Step Calls");
                try {
                    Detours.Add(new Detour(typeof(TrainAI).GetMethod("SimulationStep",
                                                                     new[] {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Vector3)
                    }),
                                           typeof(CustomTrainAI).GetMethod("TrafficManagerSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect TrainAI::SimulationStep.");
                    detourFailed = true;
                }

                Log.Info("Redirection TramBaseAI::SimulationStep calls");
                try {
                    Detours.Add(new Detour(typeof(TramBaseAI).GetMethod("SimulationStep",
                                                                        BindingFlags.Public | BindingFlags.Instance,
                                                                        null,
                                                                        new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Vector3),
                    },
                                                                        null), typeof(CustomTramBaseAI).GetMethod("CustomSimulationStep")));
                } catch (Exception) {
                    Log.Error("Could not redirect TramBaseAI::SimulationStep");
                    detourFailed = true;
                }

                /*++i;
                 * Log._Debug("Redirecting Train AI Calculate Segment Calls");
                 * try {
                 *      LoadingExtension.Instance.OriginalMethods[i] = typeof(TrainAI).GetMethod("CalculateSegmentPosition",
                 *                      BindingFlags.NonPublic | BindingFlags.Instance,
                 *                      null,
                 *                      new[]
                 *                      {
                 *                              typeof (ushort),
                 *                              typeof (Vehicle).MakeByRefType(),
                 *                              typeof (PathUnit.Position),
                 *                              typeof (PathUnit.Position),
                 *                              typeof (uint),
                 *                              typeof (byte),
                 *                              typeof (PathUnit.Position),
                 *                              typeof (uint),
                 *                              typeof (byte),
                 *                              typeof (Vector3).MakeByRefType(),
                 *                              typeof (Vector3).MakeByRefType(),
                 *                              typeof (float).MakeByRefType()
                 *                      },
                 *                      null);
                 *      LoadingExtension.Instance.CustomMethods[i] = typeof(CustomTrainAI).GetMethod("TmCalculateSegmentPosition");
                 *      LoadingExtension.Instance.CustomRedirects[i] = RedirectionHelper.RedirectCalls(LoadingExtension.Instance.OriginalMethods[i], LoadingExtension.Instance.CustomMethods[i]);
                 * } catch (Exception) {
                 *      Log.Error("Could not redirect TrainAI::CalculateSegmentPosition (1)");
                 *      detourFailed = true;
                 * }*/

                Log.Info("Redirecting Car AI Calculate Segment Calls");
                try {
                    Detours.Add(new Detour(typeof(CarAI).GetMethod("CalculateSegmentPosition",
                                                                   BindingFlags.NonPublic | BindingFlags.Instance,
                                                                   null,
                                                                   new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(PathUnit.Position),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(int),
                        typeof(Vector3).MakeByRefType(),
                        typeof(Vector3).MakeByRefType(),
                        typeof(float).MakeByRefType()
                    },
                                                                   null),
                                           typeof(CustomCarAI).GetMethod("CustomCalculateSegmentPosition")));
                } catch (Exception) {
                    Log.Error("Could not redirect CarAI::CalculateSegmentPosition.");
                    detourFailed = true;
                }

                Log.Info("Redirection TramBaseAI Calculate Segment Position calls");
                try {
                    Detours.Add(new Detour(typeof(TramBaseAI).GetMethod("CalculateSegmentPosition",
                                                                        BindingFlags.NonPublic | BindingFlags.Instance,
                                                                        null,
                                                                        new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(PathUnit.Position),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(int),
                        typeof(Vector3).MakeByRefType(),
                        typeof(Vector3).MakeByRefType(),
                        typeof(float).MakeByRefType()
                    },
                                                                        null),
                                           typeof(CustomTramBaseAI).GetMethod("CustomCalculateSegmentPosition")));
                } catch (Exception) {
                    Log.Error("Could not redirect TramBaseAI::CalculateSegmentPosition");
                    detourFailed = true;
                }

                if (IsPathManagerCompatible)
                {
                    Log.Info("Redirection CarAI Calculate Segment Position calls for non-Traffic++");
                    try {
                        Detours.Add(new Detour(typeof(CarAI).GetMethod("CalculateSegmentPosition",
                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                       null,
                                                                       new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(PathUnit.Position),
                            typeof(uint),
                            typeof(byte),
                            typeof(Vector3).MakeByRefType(),
                            typeof(Vector3).MakeByRefType(),
                            typeof(float).MakeByRefType()
                        },
                                                                       null),
                                               typeof(CustomCarAI).GetMethod("CustomCalculateSegmentPositionPathFinder")));
                    } catch (Exception) {
                        Log.Error("Could not redirect CarAI::CalculateSegmentPosition");
                        detourFailed = true;
                    }

                    Log.Info("Redirection TrainAI Calculate Segment Position calls for non-Traffic++");
                    try {
                        Detours.Add(new Detour(typeof(TrainAI).GetMethod("CalculateSegmentPosition",
                                                                         BindingFlags.NonPublic | BindingFlags.Instance,
                                                                         null,
                                                                         new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(PathUnit.Position),
                            typeof(uint),
                            typeof(byte),
                            typeof(Vector3).MakeByRefType(),
                            typeof(Vector3).MakeByRefType(),
                            typeof(float).MakeByRefType()
                        },
                                                                         null),
                                               typeof(CustomTrainAI).GetMethod("TmCalculateSegmentPositionPathFinder")));
                    } catch (Exception) {
                        Log.Error("Could not redirect TrainAI::CalculateSegmentPosition (2)");
                        detourFailed = true;
                    }

                    Log.Info("Redirection AmbulanceAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(AmbulanceAI).GetMethod("StartPathFind",
                                                                             BindingFlags.NonPublic | BindingFlags.Instance,
                                                                             null,
                                                                             new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                             null),
                                               typeof(CustomAmbulanceAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect AmbulanceAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection BusAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(BusAI).GetMethod("StartPathFind",
                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                       null,
                                                                       new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                       null),
                                               typeof(CustomBusAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect BusAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection CarAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(CarAI).GetMethod("StartPathFind",
                                                                       BindingFlags.NonPublic | BindingFlags.Instance,
                                                                       null,
                                                                       new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                       null),
                                               typeof(CustomCarAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect CarAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection CargoTruckAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(CargoTruckAI).GetMethod("StartPathFind",
                                                                              BindingFlags.NonPublic | BindingFlags.Instance,
                                                                              null,
                                                                              new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                              null),
                                               typeof(CustomCargoTruckAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect CargoTruckAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection FireTruckAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(FireTruckAI).GetMethod("StartPathFind",
                                                                             BindingFlags.NonPublic | BindingFlags.Instance,
                                                                             null,
                                                                             new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                             null),
                                               typeof(CustomFireTruckAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect FireTruckAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection PassengerCarAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(PassengerCarAI).GetMethod("StartPathFind",
                                                                                BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                null,
                                                                                new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                                null),
                                               typeof(CustomPassengerCarAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect PassengerCarAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection PoliceCarAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(PoliceCarAI).GetMethod("StartPathFind",
                                                                             BindingFlags.NonPublic | BindingFlags.Instance,
                                                                             null,
                                                                             new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                             null),
                                               typeof(CustomPoliceCarAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect PoliceCarAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection TaxiAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(TaxiAI).GetMethod("StartPathFind",
                                                                        BindingFlags.NonPublic | BindingFlags.Instance,
                                                                        null,
                                                                        new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                        null),
                                               typeof(CustomTaxiAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect TaxiAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection TrainAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(TrainAI).GetMethod("StartPathFind",
                                                                         BindingFlags.NonPublic | BindingFlags.Instance,
                                                                         null,
                                                                         new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                         null),
                                               typeof(CustomTrainAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect TrainAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection CitizenAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(CitizenAI).GetMethod("StartPathFind",
                                                                           BindingFlags.NonPublic | BindingFlags.Instance,
                                                                           null,
                                                                           new[]
                        {
                            typeof(ushort),
                            typeof(CitizenInstance).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(VehicleInfo)
                        },
                                                                           null),
                                               typeof(CustomCitizenAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect CitizenAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection TransportLineAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(TransportLineAI).GetMethod("StartPathFind",
                                                                                 BindingFlags.Public | BindingFlags.Static,
                                                                                 null,
                                                                                 new[]
                        {
                            typeof(ushort),
                            typeof(NetSegment).MakeByRefType(),
                            typeof(ItemClass.Service),
                            typeof(VehicleInfo.VehicleType),
                            typeof(bool)
                        },
                                                                                 null),
                                               typeof(CustomTransportLineAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect TransportLineAI::StartPathFind");
                        detourFailed = true;
                    }

                    Log.Info("Redirection TramBaseAI::StartPathFind calls");
                    try {
                        Detours.Add(new Detour(typeof(TramBaseAI).GetMethod("StartPathFind",
                                                                            BindingFlags.NonPublic | BindingFlags.Instance,
                                                                            null,
                                                                            new[]
                        {
                            typeof(ushort),
                            typeof(Vehicle).MakeByRefType(),
                            typeof(Vector3),
                            typeof(Vector3),
                            typeof(bool),
                            typeof(bool)
                        },
                                                                            null),
                                               typeof(CustomTramBaseAI).GetMethod("CustomStartPathFind")));
                    } catch (Exception) {
                        Log.Error("Could not redirect TramBaseAI::StartPathFind");
                        detourFailed = true;
                    }
                }

                Log.Info("Redirection RoadBaseAI::SetTrafficLightState calls");
                try {
                    Detours.Add(new Detour(typeof(RoadBaseAI).GetMethod("SetTrafficLightState",
                                                                        BindingFlags.Public | BindingFlags.Static,
                                                                        null,
                                                                        new[]
                    {
                        typeof(ushort),
                        typeof(NetSegment).MakeByRefType(),
                        typeof(uint),
                        typeof(RoadBaseAI.TrafficLightState),
                        typeof(RoadBaseAI.TrafficLightState),
                        typeof(bool),
                        typeof(bool)
                    },
                                                                        null),
                                           typeof(CustomRoadAI).GetMethod("CustomSetTrafficLightState")));
                } catch (Exception) {
                    Log.Error("Could not redirect RoadBaseAI::SetTrafficLightState");
                    detourFailed = true;
                }

                Log.Info("Reverse-Redirection CustomTrainAI::CheckOverlap calls (1)");
                try {
                    Detours.Add(new Detour(typeof(CustomTrainAI).GetMethod("CheckOverlap",
                                                                           BindingFlags.NonPublic | BindingFlags.Static,
                                                                           null,
                                                                           new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Segment3),
                        typeof(ushort)
                    },
                                                                           null),
                                           typeof(TrainAI).GetMethod("CheckOverlap",
                                                                     BindingFlags.NonPublic | BindingFlags.Static,
                                                                     null,
                                                                     new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Segment3),
                        typeof(ushort)
                    },
                                                                     null)));
                } catch (Exception) {
                    Log.Error("Could not reverse-redirect CustomRoadBaseAI::CheckOverlap (1)");
                    detourFailed = true;
                }

                Log.Info("Reverse-Redirection CustomTrainAI::CheckOverlap calls (2)");
                try {
                    Detours.Add(new Detour(typeof(CustomTrainAI).GetMethod("CheckOverlap",
                                                                           BindingFlags.NonPublic | BindingFlags.Static,
                                                                           null,
                                                                           new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Segment3),
                        typeof(ushort),
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(bool).MakeByRefType(),
                        typeof(Vector3),
                        typeof(Vector3)
                    },
                                                                           null), typeof(TrainAI).GetMethod("CheckOverlap",
                                                                                                            BindingFlags.NonPublic | BindingFlags.Static,
                                                                                                            null,
                                                                                                            new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(Segment3),
                        typeof(ushort),
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(bool).MakeByRefType(),
                        typeof(Vector3),
                        typeof(Vector3)
                    },
                                                                                                            null)));
                } catch (Exception) {
                    Log.Error("Could not reverse-redirect CustomRoadBaseAI::CheckOverlap (2)");
                    detourFailed = true;
                }

                Log.Info("Redirection TrainAI::CheckNextLane calls");
                try {
                    Detours.Add(new Detour(typeof(TrainAI).GetMethod("CheckNextLane",
                                                                     BindingFlags.NonPublic | BindingFlags.Instance,
                                                                     null,
                                                                     new[]
                    {
                        typeof(ushort),
                        typeof(Vehicle).MakeByRefType(),
                        typeof(float).MakeByRefType(),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(PathUnit.Position),
                        typeof(uint),
                        typeof(byte),
                        typeof(Bezier3)
                    },
                                                                     null),
                                           typeof(CustomTrainAI).GetMethod("CustomCheckNextLane")));
                } catch (Exception) {
                    Log.Error("Could not redirect TrainAI::CheckNextLane");
                    detourFailed = true;
                }

                if (detourFailed)
                {
                    Log.Info("Detours failed");
                    UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", "Traffic Manager: President Edition detected an incompatibility with another mod! You can continue playing but it's NOT recommended. Traffic Manager will not work as expected.", true);
                }
                else
                {
                    Log.Info("Detours successful");
                }

                LoadingExtension.Instance.DetourInited = true;
            }
        }
コード例 #28
0
ファイル: Bootstrap.cs プロジェクト: zorbathut/imtheworkernow
        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");
            }
        }
コード例 #29
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");
        }
コード例 #30
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;
        }